ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilHTTPS Class Reference

HTTPS. More...

+ Collaboration diagram for ilHTTPS:

Public Member Functions

 ilHTTPS ()
 use ilHTTPS::getInstance() More...
 
 checkPort ()
 check if current port usage is right: if https should be used than redirection is done, to http otherwise. More...
 
 __readProtectedScripts ()
 
 isDetected ()
 check if https is detected More...
 
 __readProtectedClasses ()
 
 _checkHTTPS ()
 static method to check if https connections are possible for this server public More...
 
 _checkHTTP ()
 static method to check if http connections are possible for this server More...
 
 enableSecureCookies ()
 enable secure cookies More...
 

Static Public Member Functions

static getInstance ()
 Get https instance. More...
 

Data Fields

const PROTOCOL_HTTP = 1
 
const PROTOCOL_HTTPS = 2
 
 $enabled = false
 
 $protected_scripts = array()
 
 $automaticHTTPSDetectionEnabled = false
 
 $headerName = false
 
 $headerValue = false
 

Protected Member Functions

 shouldSwitchProtocol ($to_protocol)
 

Static Private Attributes

static $instance = null
 

Detailed Description

HTTPS.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 13 of file class.ilHTTPS.php.

Member Function Documentation

◆ __readProtectedClasses()

ilHTTPS::__readProtectedClasses ( )

Definition at line 160 of file class.ilHTTPS.php.

Referenced by ilHTTPS().

161  {
162  $this->protected_classes[] = 'ilstartupgui';
163  $this->protected_classes[] = 'ilaccountregistrationgui';
164  $this->protected_classes[] = 'ilpurchasebmfgui';
165  $this->protected_classes[] = 'ilpurchasepaypal';
166  $this->protected_classes[] = 'ilshopshoppingcartgui';
167  $this->protected_classes[] = 'ilpurchasebillgui';
168  $this->protected_classes[] = 'ilpersonalsettingsgui';
169  }
+ Here is the caller graph for this function:

◆ __readProtectedScripts()

ilHTTPS::__readProtectedScripts ( )

Definition at line 114 of file class.ilHTTPS.php.

Referenced by ilHTTPS().

115  {
116  $this->protected_scripts[] = 'login.php';
117  $this->protected_scripts[] = 'index.php';
118  $this->protected_scripts[] = 'payment.php';
119  $this->protected_scripts[] = 'register.php';
120  // BEGIN WebDAV Use SSL for WebDAV.
121  $this->protected_scripts[] = 'webdav.php';
122  // END WebDAV Use SSL for WebDAV.
123  $this->protected_scripts[] = 'shib_login.php';
124 
125  return true;
126  }
+ Here is the caller graph for this function:

◆ _checkHTTP()

ilHTTPS::_checkHTTP ( )

static method to check if http connections are possible for this server

public

Returns
boolean

Definition at line 194 of file class.ilHTTPS.php.

195  {
196  $port = 80;
197 
198  if(($sp = fsockopen($_SERVER["SERVER_NAME"],$port,$errno,$error)) === false)
199  {
200  return false;
201  }
202  fclose($sp);
203  return true;
204  }

◆ _checkHTTPS()

ilHTTPS::_checkHTTPS ( )

static method to check if https connections are possible for this server public

Returns
boolean

Definition at line 176 of file class.ilHTTPS.php.

Referenced by ilSecuritySettings\validate().

177  {
178  // only check standard port in the moment
179  $port = 443;
180 
181  if(($sp = fsockopen($_SERVER["SERVER_NAME"],$port,$errno,$error)) === false)
182  {
183  return false;
184  }
185  fclose($sp);
186  return true;
187  }
+ Here is the caller graph for this function:

◆ checkPort()

ilHTTPS::checkPort ( )

check if current port usage is right: if https should be used than redirection is done, to http otherwise.

Returns
unknown

Definition at line 95 of file class.ilHTTPS.php.

References exit, and shouldSwitchProtocol().

96  {
97  // if https is enabled for scripts or classes, check for redirection
98  if ($this->enabled)
99  {
100  if($this->shouldSwitchProtocol(self::PROTOCOL_HTTPS))
101  {
102  header("location: https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
103  exit;
104  }
105  if($this->shouldSwitchProtocol(self::PROTOCOL_HTTP))
106  {
107  header("location: http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
108  exit;
109  }
110  }
111  return true;
112  }
exit
Definition: login.php:54
shouldSwitchProtocol($to_protocol)
+ Here is the call graph for this function:

◆ enableSecureCookies()

ilHTTPS::enableSecureCookies ( )

enable secure cookies

public

Parameters

Definition at line 213 of file class.ilHTTPS.php.

References $ilLog, IL_COOKIE_PATH, and isDetected().

214  {
215  global $ilLog,$ilClientIniFile;
216 
217  $secure_disabled = $ilClientIniFile->readVariable('session','disable_secure_cookies');
218  if(!$secure_disabled and !$this->enabled and $this->isDetected() and !session_id())
219  {
220  #$ilLog->write(__CLASS__.': Enabled secure cookies');
221 
222  // session_set_cookie_params() supports 5th parameter
223  // only for php version 5.2.0 and above
224  if( version_compare(PHP_VERSION, '5.2.0', '>=') )
225  {
226  // PHP version >= 5.2.0
227  session_set_cookie_params(
228  IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, true, IL_COOKIE_HTTPONLY
229  );
230  }
231  else
232  {
233  // PHP version < 5.2.0
234  session_set_cookie_params(
235  IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, true
236  );
237  }
238  }
239  return true;
240  }
const IL_COOKIE_PATH
Definition: index.php:6
isDetected()
check if https is detected
+ Here is the call graph for this function:

◆ getInstance()

static ilHTTPS::getInstance ( )
static

Get https instance.

Returns

Definition at line 51 of file class.ilHTTPS.php.

References ilHTTPS().

Referenced by ilUtil\deliverData(), and ilUtil\deliverFile().

52  {
53  if(self::$instance)
54  {
55  return self::$instance;
56  }
57  return self::$instance = new ilHTTPS();
58  }
ilHTTPS()
use ilHTTPS::getInstance()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ilHTTPS()

ilHTTPS::ilHTTPS ( )

use ilHTTPS::getInstance()

Returns

Definition at line 31 of file class.ilHTTPS.php.

References $ilSetting, __readProtectedClasses(), and __readProtectedScripts().

Referenced by getInstance().

32  {
33  global $ilSetting;
34 
35  if($this->enabled = (bool) $ilSetting->get('https'))
36  {
37  $this->__readProtectedScripts();
38  $this->__readProtectedClasses();
39  }
40  if ($this->automaticHTTPSDetectionEnabled = (bool) $ilSetting->get("ps_auto_https_enabled"))
41  {
42  $this->headerName = $ilSetting->get("ps_auto_https_headername");
43  $this->headerValue = $ilSetting->get("ps_auto_https_headervalue");
44  }
45  }
__readProtectedScripts()
__readProtectedClasses()
global $ilSetting
Definition: privfeed.php:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDetected()

ilHTTPS::isDetected ( )

check if https is detected

Returns
boolean true, if https is detected by protocol or by automatic detection, if enabled, false otherwise

Definition at line 133 of file class.ilHTTPS.php.

Referenced by enableSecureCookies().

134  {
135  if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
136  return true;
137 
138  if ($this->automaticHTTPSDetectionEnabled)
139  {
140  $headerName = "HTTP_".str_replace("-","_",$this->headerName);
141  /* echo $headerName;
142  echo $_SERVER[$headerName];*/
143  if (strcasecmp($_SERVER[$headerName],$this->headerValue)==0)
144  {
145  $_SERVER["HTTPS"] = "on";
146  return true;
147  }
148  /*
149  if(isset($_SERVER[$this->headerName]) && (strcasecmp($_SERVER[$this->headerName],$this->headerValue) == 0))
150  {
151  $_SERVER['HTTPS'] = 'on';
152  return true;
153  }
154  */
155  }
156 
157  return false;
158  }
+ Here is the caller graph for this function:

◆ shouldSwitchProtocol()

ilHTTPS::shouldSwitchProtocol (   $to_protocol)
protected
Parameters
bool$to_protocol
Returns
bool

Definition at line 64 of file class.ilHTTPS.php.

References $_GET.

Referenced by checkPort().

65  {
66  switch($to_protocol)
67  {
68  case self::PROTOCOL_HTTP:
69  $should_switch_to_http = (
70  !in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) &&
71  !in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
72  ) && $_SERVER['HTTPS'] == 'on';
73 
74  return $should_switch_to_http;
75  break;
76 
77  case self::PROTOCOL_HTTPS:
78  $should_switch_to_https = (
79  in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) ||
80  in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
81  ) && $_SERVER['HTTPS'] != 'on';
82 
83  return $should_switch_to_https;
84  break;
85  }
86 
87  return false;
88  }
$_GET["client_id"]
+ Here is the caller graph for this function:

Field Documentation

◆ $automaticHTTPSDetectionEnabled

ilHTTPS::$automaticHTTPSDetectionEnabled = false

Definition at line 23 of file class.ilHTTPS.php.

◆ $enabled

ilHTTPS::$enabled = false

Definition at line 20 of file class.ilHTTPS.php.

◆ $headerName

ilHTTPS::$headerName = false

Definition at line 24 of file class.ilHTTPS.php.

◆ $headerValue

ilHTTPS::$headerValue = false

Definition at line 25 of file class.ilHTTPS.php.

◆ $instance

ilHTTPS::$instance = null
staticprivate

Definition at line 18 of file class.ilHTTPS.php.

◆ $protected_scripts

ilHTTPS::$protected_scripts = array()

Definition at line 21 of file class.ilHTTPS.php.

◆ PROTOCOL_HTTP

const ilHTTPS::PROTOCOL_HTTP = 1

Definition at line 15 of file class.ilHTTPS.php.

◆ PROTOCOL_HTTPS

const ilHTTPS::PROTOCOL_HTTPS = 2

Definition at line 16 of file class.ilHTTPS.php.


The documentation for this class was generated from the following file: