ILIAS  release_7 Revision v7.30-3-g800a261c036
ilHTTPS Class Reference

HTTPS. More...

+ Collaboration diagram for ilHTTPS:

Public Member Functions

 __construct ()
 @deprected 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 @access 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 ( )

@deprected use ilHTTPS::getInstance()

Returns

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

34 {
36
37 if ($this->enabled = (bool) $ilSetting->get('https')) {
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 }
__readProtectedClasses()
__readProtectedScripts()
$ilIliasIniFile
Definition: imgupload.php:16
global $ilSetting
Definition: privfeed.php:17

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

+ Here is the call graph for this function:

Member Function Documentation

◆ __readProtectedClasses()

ilHTTPS::__readProtectedClasses ( )

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

153 {
154 $this->protected_classes[] = 'ilstartupgui';
155 $this->protected_classes[] = 'ilaccountregistrationgui';
156 $this->protected_classes[] = 'ilpersonalsettingsgui';
157 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ __readProtectedScripts()

ilHTTPS::__readProtectedScripts ( )

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

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 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ _checkHTTP()

ilHTTPS::_checkHTTP ( )

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

@access public

Returns
boolean

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

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

References $_SERVER.

◆ _checkHTTPS()

static ilHTTPS::_checkHTTPS ( )
static

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

Returns
boolean

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

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 }

References $_SERVER.

Referenced by ilSecuritySettings\validate().

+ 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.

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 }
shouldSwitchProtocol($to_protocol)
exit
Definition: login.php:29

References $_SERVER, exit, and shouldSwitchProtocol().

+ Here is the call graph for this function:

◆ enableSecureCookies()

ilHTTPS::enableSecureCookies ( )

enable secure cookies

@access public

Parameters

return

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

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

References IL_COOKIE_PATH, and isDetected().

+ 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.

53 {
54 if (self::$instance) {
55 return self::$instance;
56 }
57 return self::$instance = new ilHTTPS();
58 }
HTTPS.
static $instance

References $instance.

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

+ 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.

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 }

References $_SERVER, and $headerName.

Referenced by enableSecureCookies().

+ 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.

65 {
66 switch ($to_protocol) {
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
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"]
const PROTOCOL_HTTPS
const PROTOCOL_HTTP

References $_GET, $_SERVER, PROTOCOL_HTTP, and PROTOCOL_HTTPS.

Referenced by checkPort().

+ 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.

Referenced by getInstance().

◆ $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.

Referenced by shouldSwitchProtocol().

◆ PROTOCOL_HTTPS

const ilHTTPS::PROTOCOL_HTTPS = 2

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

Referenced by shouldSwitchProtocol().


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