ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilHTTPS.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
15 const PROTOCOL_HTTP = 1;
16 const PROTOCOL_HTTPS = 2;
17
18 private static $instance = null;
19
20 var $enabled = false;
21 var $protected_scripts = array();
22
24 var $headerName = false;
25 var $headerValue = false;
26
31 function __construct()
32 {
34
35 if($this->enabled = (bool)$ilSetting->get('https'))
36 {
39 }
40
41 if ($this->automaticHTTPSDetectionEnabled = (bool)$ilIliasIniFile->readVariable('https', "auto_https_detect_enabled"))
42 {
43 $this->headerName = $ilIliasIniFile->readVariable('https', "auto_https_detect_header_name");
44 $this->headerValue = $ilIliasIniFile->readVariable('https', "auto_https_detect_header_value");
45 }
46 }
47
52 public static function getInstance()
53 {
54 if(self::$instance)
55 {
56 return self::$instance;
57 }
58 return self::$instance = new ilHTTPS();
59 }
60
65 protected function shouldSwitchProtocol($to_protocol)
66 {
67 switch($to_protocol)
68 {
70 $should_switch_to_http = (
71 !in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) &&
72 !in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
73 ) && $_SERVER['HTTPS'] == 'on';
74
75 return $should_switch_to_http;
76 break;
77
79 $should_switch_to_https = (
80 in_array(basename($_SERVER['SCRIPT_NAME']), $this->protected_scripts) ||
81 in_array(strtolower($_GET['cmdClass']), $this->protected_classes)
82 ) && $_SERVER['HTTPS'] != 'on';
83
84 return $should_switch_to_https;
85 break;
86 }
87
88 return false;
89 }
90
96 function checkPort()
97 {
98 // if https is enabled for scripts or classes, check for redirection
99 if ($this->enabled)
100 {
101 if($this->shouldSwitchProtocol(self::PROTOCOL_HTTPS))
102 {
103 header("location: https://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
104 exit;
105 }
106 if($this->shouldSwitchProtocol(self::PROTOCOL_HTTP))
107 {
108 header("location: http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
109 exit;
110 }
111 }
112 return true;
113 }
114
116 {
117 $this->protected_scripts[] = 'login.php';
118 $this->protected_scripts[] = 'index.php';
119 $this->protected_scripts[] = 'payment.php';
120 $this->protected_scripts[] = 'register.php';
121 // BEGIN WebDAV Use SSL for WebDAV.
122 $this->protected_scripts[] = 'webdav.php';
123 // END WebDAV Use SSL for WebDAV.
124 $this->protected_scripts[] = 'shib_login.php';
125
126 return true;
127 }
128
134 public function isDetected ()
135 {
136 if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
137 return true;
138
139 if ($this->automaticHTTPSDetectionEnabled)
140 {
141 $headerName = "HTTP_".str_replace("-","_", strtoupper($this->headerName));
142 /* echo $headerName;
143 echo $_SERVER[$headerName];*/
144 if (strcasecmp($_SERVER[$headerName],$this->headerValue)==0)
145 {
146 $_SERVER["HTTPS"] = "on";
147 return true;
148 }
149 /*
150 if(isset($_SERVER[$this->headerName]) && (strcasecmp($_SERVER[$this->headerName],$this->headerValue) == 0))
151 {
152 $_SERVER['HTTPS'] = 'on';
153 return true;
154 }
155 */
156 }
157
158 return false;
159 }
160
162 {
163 $this->protected_classes[] = 'ilstartupgui';
164 $this->protected_classes[] = 'ilaccountregistrationgui';
165 $this->protected_classes[] = 'ilpurchasebmfgui';
166 $this->protected_classes[] = 'ilpurchasepaypal';
167 $this->protected_classes[] = 'ilshopshoppingcartgui';
168 $this->protected_classes[] = 'ilpurchasebillgui';
169 $this->protected_classes[] = 'ilpersonalsettingsgui';
170 }
171
177 function _checkHTTPS()
178 {
179 // only check standard port in the moment
180 $port = 443;
181
182 if(($sp = fsockopen($_SERVER["SERVER_NAME"],$port,$errno,$error)) === false)
183 {
184 return false;
185 }
186 fclose($sp);
187 return true;
188 }
195 function _checkHTTP()
196 {
197 $port = 80;
198
199 if(($sp = fsockopen($_SERVER["SERVER_NAME"],$port,$errno,$error)) === false)
200 {
201 return false;
202 }
203 fclose($sp);
204 return true;
205 }
206
214 public function enableSecureCookies()
215 {
216 global $ilLog,$ilClientIniFile;
217
218 $secure_disabled = $ilClientIniFile->readVariable('session','disable_secure_cookies');
219 if(!$secure_disabled and !$this->enabled and $this->isDetected() and !session_id())
220 {
221 #$ilLog->write(__CLASS__.': Enabled secure cookies');
222 session_set_cookie_params(
223 IL_COOKIE_EXPIRE, IL_COOKIE_PATH, IL_COOKIE_DOMAIN, true, IL_COOKIE_HTTPONLY
224 );
225 }
226 return true;
227 }
228}
229?>
$_GET["client_id"]
HTTPS.
_checkHTTPS()
static method to check if https connections are possible for this server @access public
static $instance
checkPort()
check if current port usage is right: if https should be used than redirection is done,...
_checkHTTP()
static method to check if http connections are possible for this server
static getInstance()
Get https instance.
isDetected()
check if https is detected
__readProtectedClasses()
enableSecureCookies()
enable secure cookies
shouldSwitchProtocol($to_protocol)
$automaticHTTPSDetectionEnabled
__readProtectedScripts()
const PROTOCOL_HTTPS
__construct()
@deprected use ilHTTPS::getInstance()
const PROTOCOL_HTTP
exit
Definition: login.php:54
global $ilSetting
Definition: privfeed.php:40
const IL_COOKIE_PATH
Definition: index.php:6
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
global $ilIliasIniFile