ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  $this->__readProtectedScripts();
39  $this->__readProtectedClasses();
40  }
41 
42  if ($this->automaticHTTPSDetectionEnabled = (bool) $ilIliasIniFile->readVariable('https', "auto_https_detect_enabled")) {
43  $this->headerName = $ilIliasIniFile->readVariable('https', "auto_https_detect_header_name");
44  $this->headerValue = $ilIliasIniFile->readVariable('https', "auto_https_detect_header_value");
45  }
46  }
$ilIliasIniFile
Definition: imgupload.php:16
__readProtectedScripts()
__readProtectedClasses()
global $ilSetting
Definition: privfeed.php:17
+ Here is the call graph for this function:

Member Function Documentation

◆ __readProtectedClasses()

ilHTTPS::__readProtectedClasses ( )

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

Referenced by __construct().

153  {
154  $this->protected_classes[] = 'ilstartupgui';
155  $this->protected_classes[] = 'ilaccountregistrationgui';
156  $this->protected_classes[] = 'ilpersonalsettingsgui';
157  }
+ Here is the caller graph for this function:

◆ __readProtectedScripts()

ilHTTPS::__readProtectedScripts ( )

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

Referenced by __construct().

111  {
112  $this->protected_scripts[] = 'login.php';
113  $this->protected_scripts[] = 'index.php';
114  $this->protected_scripts[] = 'register.php';
115  $this->protected_scripts[] = 'webdav.php';
116  $this->protected_scripts[] = 'shib_login.php';
117 
118  return true;
119  }
+ 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 181 of file class.ilHTTPS.php.

References $_SERVER.

182  {
183  $port = 80;
184 
185  if (($sp = fsockopen($_SERVER["SERVER_NAME"], $port, $errno, $error)) === false) {
186  return false;
187  }
188  fclose($sp);
189  return true;
190  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10

◆ _checkHTTPS()

static ilHTTPS::_checkHTTPS ( )
static

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

Returns
boolean

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

References $_SERVER.

Referenced by ilSecuritySettings\validate().

165  {
166  // only check standard port in the moment
167  $port = 443;
168 
169  if (($sp = fsockopen($_SERVER["SERVER_NAME"], $port, $errno, $error)) === false) {
170  return false;
171  }
172  fclose($sp);
173  return true;
174  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
+ 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 94 of file class.ilHTTPS.php.

References $_SERVER, exit, and shouldSwitchProtocol().

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

◆ enableSecureCookies()

ilHTTPS::enableSecureCookies ( )

enable secure cookies

public

Parameters

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

References IL_COOKIE_PATH, and isDetected().

200  {
201  global $ilClientIniFile;
202 
203  $secure_disabled = $ilClientIniFile->readVariable('session', 'disable_secure_cookies');
204  if (!$secure_disabled && !$this->enabled && $this->isDetected() && !session_id()) {
205  if (!defined('IL_COOKIE_SECURE')) {
206  define('IL_COOKIE_SECURE', true);
207  }
208 
209  session_set_cookie_params([
210  'lifetime' => IL_COOKIE_EXPIRE,
211  'path' => IL_COOKIE_PATH,
212  'domain' => IL_COOKIE_DOMAIN,
213  'secure' => true,
214  'httponly' => IL_COOKIE_HTTPONLY,
215  ]);
216  }
217 
218  return true;
219  }
isDetected()
check if https is detected
const IL_COOKIE_PATH(isset($_GET["client_id"]))
Definition: metadata.php:47
+ Here is the call graph for this function:

◆ getInstance()

static ilHTTPS::getInstance ( )
static

Get https instance.

Returns

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

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

53  {
54  if (self::$instance) {
55  return self::$instance;
56  }
57  return self::$instance = new ilHTTPS();
58  }
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 126 of file class.ilHTTPS.php.

References $_SERVER, and $headerName.

Referenced by enableSecureCookies().

127  {
128  if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
129  return true;
130  }
131 
132  if ($this->automaticHTTPSDetectionEnabled) {
133  $headerName = "HTTP_" . str_replace("-", "_", strtoupper($this->headerName));
134  /* echo $headerName;
135  echo $_SERVER[$headerName];*/
136  if (strcasecmp($_SERVER[$headerName], $this->headerValue) == 0) {
137  $_SERVER["HTTPS"] = "on";
138  return true;
139  }
140  /*
141  if(isset($_SERVER[$this->headerName]) && (strcasecmp($_SERVER[$this->headerName],$this->headerValue) == 0))
142  {
143  $_SERVER['HTTPS'] = 'on';
144  return true;
145  }
146  */
147  }
148 
149  return false;
150  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
+ 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, and $_SERVER.

Referenced by checkPort().

65  {
66  switch ($to_protocol) {
67  case self::PROTOCOL_HTTP:
68  $should_switch_to_http = (
69  !in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) &&
70  !in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
71  ) && $_SERVER['HTTPS'] == 'on';
72 
73  return $should_switch_to_http;
74  break;
75 
76  case self::PROTOCOL_HTTPS:
77  $should_switch_to_https = (
78  in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) ||
79  in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
80  ) && $_SERVER['HTTPS'] != 'on';
81 
82  return $should_switch_to_https;
83  break;
84  }
85 
86  return false;
87  }
$_GET["client_id"]
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
+ 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: