ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilHTTPS Class Reference

HTTPS. More...

+ Collaboration diagram for ilHTTPS:

Public Member Functions

 __construct ()
 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 ()
 
 _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...
 
static _checkHTTPS ()
 static method to check if https connections are possible for this server public More...
 

Data Fields

const PROTOCOL_HTTP = 1
 
const PROTOCOL_HTTPS = 2
 

Protected Member Functions

 shouldSwitchProtocol ($to_protocol)
 

Protected Attributes

 $enabled = false
 
 $protected_classes = array()
 
 $protected_scripts = array()
 
 $automaticHTTPSDetectionEnabled = false
 
 $headerName = false
 
 $headerValue = false
 

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.

Constructor & Destructor Documentation

◆ __construct()

ilHTTPS::__construct ( )

use ilHTTPS::getInstance()

Returns

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

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

34  {
36 
37  if($this->enabled = (bool)$ilSetting->get('https'))
38  {
39  $this->__readProtectedScripts();
40  $this->__readProtectedClasses();
41  }
42 
43  if ($this->automaticHTTPSDetectionEnabled = (bool)$ilIliasIniFile->readVariable('https', "auto_https_detect_enabled"))
44  {
45  $this->headerName = $ilIliasIniFile->readVariable('https', "auto_https_detect_header_name");
46  $this->headerValue = $ilIliasIniFile->readVariable('https', "auto_https_detect_header_value");
47  }
48  }
__readProtectedScripts()
__readProtectedClasses()
global $ilSetting
Definition: privfeed.php:17
$ilIliasIniFile
+ Here is the call graph for this function:

Member Function Documentation

◆ __readProtectedClasses()

ilHTTPS::__readProtectedClasses ( )

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

Referenced by __construct().

163  {
164  $this->protected_classes[] = 'ilstartupgui';
165  $this->protected_classes[] = 'ilaccountregistrationgui';
166  $this->protected_classes[] = 'ilpersonalsettingsgui';
167  }
+ Here is the caller graph for this function:

◆ __readProtectedScripts()

ilHTTPS::__readProtectedScripts ( )

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

Referenced by __construct().

118  {
119  $this->protected_scripts[] = 'login.php';
120  $this->protected_scripts[] = 'index.php';
121  $this->protected_scripts[] = 'register.php';
122  // BEGIN WebDAV Use SSL for WebDAV.
123  $this->protected_scripts[] = 'webdav.php';
124  // END WebDAV Use SSL for WebDAV.
125  $this->protected_scripts[] = 'shib_login.php';
126 
127  return true;
128  }
+ 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 192 of file class.ilHTTPS.php.

References $_SERVER, and $error.

193  {
194  $port = 80;
195 
196  if(($sp = fsockopen($_SERVER["SERVER_NAME"],$port,$errno,$error)) === false)
197  {
198  return false;
199  }
200  fclose($sp);
201  return true;
202  }
$error
Definition: Error.php:17
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

◆ _checkHTTPS()

static ilHTTPS::_checkHTTPS ( )
static

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

Returns
boolean

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

References $_SERVER, and $error.

Referenced by ilSecuritySettings\validate().

175  {
176  // only check standard port in the moment
177  $port = 443;
178 
179  if(($sp = fsockopen($_SERVER["SERVER_NAME"],$port,$errno,$error)) === false)
180  {
181  return false;
182  }
183  fclose($sp);
184  return true;
185  }
$error
Definition: Error.php:17
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
+ 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 98 of file class.ilHTTPS.php.

References $_SERVER, exit, header, and shouldSwitchProtocol().

99  {
100  // if https is enabled for scripts or classes, check for redirection
101  if ($this->enabled)
102  {
103  if($this->shouldSwitchProtocol(self::PROTOCOL_HTTPS))
104  {
105  header("location: https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
106  exit;
107  }
108  if($this->shouldSwitchProtocol(self::PROTOCOL_HTTP))
109  {
110  header("location: http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
111  exit;
112  }
113  }
114  return true;
115  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
Add a drawing to the header
Definition: 04printing.php:69
shouldSwitchProtocol($to_protocol)
+ Here is the call graph for this function:

◆ enableSecureCookies()

ilHTTPS::enableSecureCookies ( )

enable secure cookies

public

Parameters

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

References $ilLog, IL_COOKIE_PATH, and isDetected().

212  {
213  global $ilLog,$ilClientIniFile;
214 
215  $secure_disabled = $ilClientIniFile->readVariable('session','disable_secure_cookies');
216  if(!$secure_disabled and !$this->enabled and $this->isDetected() and !session_id())
217  {
218  #$ilLog->write(__CLASS__.': Enabled secure cookies');
219  session_set_cookie_params(
220  IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, true, IL_COOKIE_HTTPONLY
221  );
222  }
223  return true;
224  }
const IL_COOKIE_PATH(isset($_GET["client_id"]))
Definition: index.php:26
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 54 of file class.ilHTTPS.php.

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

55  {
56  if(self::$instance)
57  {
58  return self::$instance;
59  }
60  return self::$instance = new ilHTTPS();
61  }
HTTPS.
+ 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 135 of file class.ilHTTPS.php.

References $_SERVER, and $headerName.

Referenced by enableSecureCookies().

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

◆ shouldSwitchProtocol()

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

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

References $_GET, and $_SERVER.

Referenced by checkPort().

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

Field Documentation

◆ $automaticHTTPSDetectionEnabled

ilHTTPS::$automaticHTTPSDetectionEnabled = false
protected

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

◆ $enabled

ilHTTPS::$enabled = false
protected

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

◆ $headerName

ilHTTPS::$headerName = false
protected

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

Referenced by isDetected().

◆ $headerValue

ilHTTPS::$headerValue = false
protected

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

◆ $instance

ilHTTPS::$instance = null
staticprivate

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

◆ $protected_classes

ilHTTPS::$protected_classes = array()
protected

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

◆ $protected_scripts

ilHTTPS::$protected_scripts = array()
protected

Definition at line 23 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: