Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 class ilSecuritySettings
00035 {
00036 public static $SECURITY_SETTINGS_ERR_CODE_AUTO_HTTPS = 1;
00037 public static $SECURITY_SETTINGS_ERR_CODE_HTTP_NOT_AVAILABLE = 2;
00038 public static $SECURITY_SETTINGS_ERR_CODE_HTTPS_NOT_AVAILABLE = 3;
00039
00040 private static $instance = null;
00041 private $db;
00042 private $settings;
00043
00044 private $https_header_enable;
00045 private $https_header_name;
00046 private $https_header_value;
00047 private $https_enable;
00048
00056 private function __construct()
00057 {
00058 global $ilSetting,$ilDB;
00059
00060 $this->db = $ilDB;
00061 $this->settings = $ilSetting;
00062
00063 $this->read();
00064 }
00065
00073 public function _getInstance()
00074 {
00075 if(is_object(self::$instance))
00076 {
00077 return self::$instance;
00078 }
00079 return self::$instance = new ilSecuritySettings();
00080 }
00081
00082 public function getSecuritySettingsRefId()
00083 {
00084 return $this->ref_id;
00085 }
00086
00093 public function setAutomaticHTTPSEnabled($varname)
00094 {
00095 $this->https_header_enable = $varname;
00096 }
00097
00098
00104 public function setAutomaticHTTPSHeaderName($varname)
00105 {
00106 $this->https_header_name = $varname;
00107 }
00108
00114 public function setAutomaticHTTPSHeaderValue($varname)
00115 {
00116 $this->https_header_value = $varname;
00117 }
00118
00124 public function getAutomaticHTTPSHeaderName()
00125 {
00126 return $this->https_header_name;
00127 }
00128
00134 public function getAutomaticHTTPSHeaderValue()
00135 {
00136 return $this->https_header_value;
00137 }
00138
00144 public function isAutomaticHTTPSEnabled()
00145 {
00146 return $this->https_header_enable;
00147 }
00148
00154 public function setHTTPSEnabled ($value)
00155 {
00156 $this->https_enable = $value;
00157 }
00158
00159
00165 public function isHTTPSEnabled ()
00166 {
00167 return $this->https_enable;
00168 }
00174 public function save()
00175 {
00176 $this->settings->set('ps_auto_https_enabled',(bool) $this->isAutomaticHTTPSEnabled());
00177 $this->settings->set('ps_auto_https_headername',(string) $this->getAutomaticHTTPSHeaderName());
00178 $this->settings->set('ps_auto_https_headervalue',(string) $this->getAutomaticHTTPSHeaderValue());
00179 $this->settings->set('https',(string) $this->isHTTPSEnabled());
00180 }
00188 private function read()
00189 {
00190 global $ilDB;
00191
00192 $query = "SELECT object_reference.ref_id FROM object_reference,tree,object_data ".
00193 "WHERE tree.parent = ".$ilDB->quote(SYSTEM_FOLDER_ID)." ".
00194 "AND object_data.type = 'ps' ".
00195 "AND object_reference.ref_id = tree.child ".
00196 "AND object_reference.obj_id = object_data.obj_id";
00197 $res = $this->db->query($query);
00198 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00199 $this->ref_id = $row["ref_id"];
00200
00201 $this->https_header_enable = (bool) $this->settings->get('ps_auto_https_enabled',false);
00202 $this->https_header_name = (string) $this->settings->get('ps_auto_https_headername',"ILIAS_HTTPS_ENABLED");
00203 $this->https_header_value = (string) $this->settings->get('ps_auto_https_headervalue',"1");
00204 $this->https_enable = (boolean) $this->settings->get('https', false);
00205 }
00206
00212 public function validate() {
00213 if ($this->isAutomaticHTTPSEnabled() &&
00214 (strlen($this->getAutomaticHTTPSHeaderName()) == 0 ||
00215 strlen($this->getAutomaticHTTPSHeaderValue()) == 0)
00216 )
00217 {
00218 return ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_AUTO_HTTPS;
00219 }
00220 include_once './classes/class.ilHTTPS.php';
00221
00222 if ($this->isHTTPSEnabled())
00223 {
00224 if(!ilHTTPS::_checkHTTPS())
00225 {
00226 return ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_HTTPS_NOT_AVAILABLE;
00227 }
00228 } elseif(!ilHTTPS::_checkHTTP())
00229 {
00230 return ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_HTTP_NOT_AVAILABLE;
00231 }
00232
00233 return 0;
00234 }
00235
00236
00237 }
00238 ?>