ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilHTTPS Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilHTTPS:

Public Member Functions

 __construct ()
 
 isDetected ()
 check if https is detected More...
 
 checkHTTPS (int $port=443)
 
 enableSecureCookies ()
 
 checkProtocolAndRedirectIfNeeded ()
 

Data Fields

const SETTINGS_GROUP_SERVER = 'server'
 
const SETTING_HTTP_PATH = 'http_path'
 
const SETTINGS_GROUP_HTTPS = 'https'
 
const SETTING_AUTO_HTTPS_DETECT_ENABLED = "auto_https_detect_enabled"
 
const SETTING_AUTO_HTTPS_DETECT_HEADER_NAME = "auto_https_detect_header_name"
 
const SETTING_AUTO_HTTPS_DETECT_HEADER_VALUE = "auto_https_detect_header_value"
 
const SETTING_FORCED = 'forced'
 

Protected Attributes

const PROTOCOL_HTTP = 1
 
const PROTOCOL_HTTPS = 2
 
bool $enabled = false
 
array $protected_classes = []
 
array $protected_scripts = []
 
bool $automatic_detection = false
 
string $header_name = null
 
string $header_value = null
 
ilIniFile $ilias_ini
 
ilIniFile $client_ini
 

Private Member Functions

 readProtectedScripts ()
 
 readProtectedClasses ()
 
 shouldSwitchProtocol ($to_protocol)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilHTTPS

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
     Find usages: (((DIC|GLOBALS)\[['"]https.*)|(global .* $https))

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

Constructor & Destructor Documentation

◆ __construct()

ilHTTPS::__construct ( )

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

References $DIC, readProtectedClasses(), and readProtectedScripts().

46  {
47  global $DIC;
48  $this->ilias_ini = $DIC->iliasIni();
49  $this->client_ini = $DIC->clientIni();
50 
51  if ($this->enabled = (bool) $this->ilias_ini->readVariable(
52  self::SETTINGS_GROUP_HTTPS,
53  self::SETTING_FORCED
54  )) {
55  $this->readProtectedScripts();
56  $this->readProtectedClasses();
57  }
58 
59  if ($this->automatic_detection = (bool) $this->ilias_ini->readVariable(
60  self::SETTINGS_GROUP_HTTPS,
61  self::SETTING_AUTO_HTTPS_DETECT_ENABLED
62  )) {
63  $this->header_name = $this->ilias_ini->readVariable(
64  self::SETTINGS_GROUP_HTTPS,
65  self::SETTING_AUTO_HTTPS_DETECT_HEADER_NAME
66  );
67  $this->header_value = $this->ilias_ini->readVariable(
68  self::SETTINGS_GROUP_HTTPS,
69  self::SETTING_AUTO_HTTPS_DETECT_HEADER_VALUE
70  );
71  }
72  }
global $DIC
Definition: feed.php:28
readProtectedScripts()
readProtectedClasses()
+ Here is the call graph for this function:

Member Function Documentation

◆ checkHTTPS()

ilHTTPS::checkHTTPS ( int  $port = 443)

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

References $_SERVER.

116  : bool
117  {
118  if (($sp = fsockopen($_SERVER["SERVER_NAME"], $port, $errno, $error)) === false) {
119  return false;
120  }
121  fclose($sp);
122  return true;
123  }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10

◆ checkProtocolAndRedirectIfNeeded()

ilHTTPS::checkProtocolAndRedirectIfNeeded ( )

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

References $_SERVER, exit, and shouldSwitchProtocol().

144  : bool
145  {
146  // if https is enabled for scripts or classes, check for redirection
147  if ($this->enabled) {
148  if ($this->shouldSwitchProtocol(self::PROTOCOL_HTTPS)) {
149  header("location: https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
150  exit;
151  }
152  if ($this->shouldSwitchProtocol(self::PROTOCOL_HTTP)) {
153  header("location: http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
154  exit;
155  }
156  }
157  return true;
158  }
exit
Definition: login.php:28
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
shouldSwitchProtocol($to_protocol)
+ Here is the call graph for this function:

◆ enableSecureCookies()

ilHTTPS::enableSecureCookies ( )

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

References IL_COOKIE_PATH, and isDetected().

125  : void
126  {
127  $secure_disabled = (bool) $this->client_ini->readVariable('session', 'disable_secure_cookies');
128  if (!$secure_disabled && !$this->enabled && $this->isDetected() && !session_id()) {
129  if (!defined('IL_COOKIE_SECURE')) {
130  define('IL_COOKIE_SECURE', true);
131  }
132 
133  session_set_cookie_params([
134  'lifetime' => IL_COOKIE_EXPIRE,
135  'path' => IL_COOKIE_PATH,
136  'domain' => IL_COOKIE_DOMAIN,
137  'secure' => IL_COOKIE_SECURE,
138  'httponly' => true,
139  'samesite' => (strtolower(session_get_cookie_params()['samesite'] ?? '')) === 'strict' ? session_get_cookie_params()['samesite'] : 'Lax'
140  ]);
141  }
142  }
isDetected()
check if https is detected
const IL_COOKIE_PATH(isset($_GET["client_id"]))
Definition: metadata.php:64
+ Here is the call graph for this function:

◆ isDetected()

ilHTTPS::isDetected ( )

check if https is detected

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

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

References $_SERVER.

Referenced by enableSecureCookies().

88  : bool
89  {
90  if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === "on") {
91  return true;
92  }
93 
94  if ($this->automatic_detection) {
95  $header_name = "HTTP_" . str_replace("-", "_", strtoupper($this->header_name));
96  /* echo $header_name;
97  echo $_SERVER[$header_name];*/
98  if (isset($_SERVER[$header_name])) {
99  if (strcasecmp($_SERVER[$header_name], $this->header_value) === 0) {
100  $_SERVER["HTTPS"] = "on";
101  return true;
102  }
103  }
104  }
105 
106  return false;
107  }
string $header_name
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
+ Here is the caller graph for this function:

◆ readProtectedClasses()

ilHTTPS::readProtectedClasses ( )
private

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

Referenced by __construct().

109  : void
110  {
111  $this->protected_classes[] = 'ilstartupgui';
112  $this->protected_classes[] = 'ilaccountregistrationgui';
113  $this->protected_classes[] = 'ilpersonalsettingsgui';
114  }
+ Here is the caller graph for this function:

◆ readProtectedScripts()

ilHTTPS::readProtectedScripts ( )
private

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

Referenced by __construct().

74  : void
75  {
76  $this->protected_scripts[] = 'login.php';
77  $this->protected_scripts[] = 'index.php';
78  $this->protected_scripts[] = 'register.php';
79  $this->protected_scripts[] = 'webdav.php';
80  $this->protected_scripts[] = 'shib_login.php';
81  }
+ Here is the caller graph for this function:

◆ shouldSwitchProtocol()

ilHTTPS::shouldSwitchProtocol (   $to_protocol)
private

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

References $_GET, and $_SERVER.

Referenced by checkProtocolAndRedirectIfNeeded().

160  : bool
161  {
162  switch ($to_protocol) {
163  case self::PROTOCOL_HTTP:
164  return (
165  !in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) &&
166  !in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
167  ) && $_SERVER['HTTPS'] === 'on';
168 
169  case self::PROTOCOL_HTTPS:
170  return (
171  in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) ||
172  in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
173  ) && $_SERVER['HTTPS'] !== 'on';
174  }
175 
176  return false;
177  }
$_GET['client_id']
Definition: saml1-acs.php:21
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
+ Here is the caller graph for this function:

Field Documentation

◆ $automatic_detection

bool ilHTTPS::$automatic_detection = false
protected

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

◆ $client_ini

ilIniFile ilHTTPS::$client_ini
protected

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

◆ $enabled

bool ilHTTPS::$enabled = false
protected

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

◆ $header_name

string ilHTTPS::$header_name = null
protected

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

◆ $header_value

string ilHTTPS::$header_value = null
protected

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

◆ $ilias_ini

ilIniFile ilHTTPS::$ilias_ini
protected

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

◆ $protected_classes

array ilHTTPS::$protected_classes = []
protected

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

◆ $protected_scripts

array ilHTTPS::$protected_scripts = []
protected

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

◆ PROTOCOL_HTTP

const ilHTTPS::PROTOCOL_HTTP = 1
protected

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

◆ PROTOCOL_HTTPS

const ilHTTPS::PROTOCOL_HTTPS = 2
protected

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

◆ SETTING_AUTO_HTTPS_DETECT_ENABLED

const ilHTTPS::SETTING_AUTO_HTTPS_DETECT_ENABLED = "auto_https_detect_enabled"

◆ SETTING_AUTO_HTTPS_DETECT_HEADER_NAME

const ilHTTPS::SETTING_AUTO_HTTPS_DETECT_HEADER_NAME = "auto_https_detect_header_name"

◆ SETTING_AUTO_HTTPS_DETECT_HEADER_VALUE

const ilHTTPS::SETTING_AUTO_HTTPS_DETECT_HEADER_VALUE = "auto_https_detect_header_value"

◆ SETTING_FORCED

const ilHTTPS::SETTING_FORCED = 'forced'

◆ SETTING_HTTP_PATH

const ilHTTPS::SETTING_HTTP_PATH = 'http_path'

◆ SETTINGS_GROUP_HTTPS

const ilHTTPS::SETTINGS_GROUP_HTTPS = 'https'

◆ SETTINGS_GROUP_SERVER

const ilHTTPS::SETTINGS_GROUP_SERVER = 'server'

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