ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilProxySettings.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Services/Http/exceptions/class.ilProxyException.php';
5
14{
16
26 protected static $_instance = null;
27
37 protected $host = '';
38
48 protected $post = '';
49
59 protected $isActive = false;
60
68 protected function __construct()
69 {
70 $this->read();
71 }
72
80 private function __clone()
81 {
82 }
83
93 public static function _getInstance()
94 {
95 if (null === self::$_instance) {
96 self::$_instance = new self();
97 }
98
99 return self::$_instance;
100 }
101
109 protected function read()
110 {
111 global $ilSetting;
112
113 $this->setHost($ilSetting->get('proxy_host'));
114 $this->setPort($ilSetting->get('proxy_port'));
115 $this->isActive((bool) $ilSetting->get('proxy_status'));
116 }
117
127 public function isActive($status = null)
128 {
129 if (null === $status) {
130 return (bool) $this->isActive;
131 }
132
133 $this->isActive = (bool) $status;
134
135 return $this;
136 }
137
147 public function setHost($host)
148 {
149 $this->host = $host;
150
151 return $this;
152 }
153
162 public function getHost()
163 {
164 return $this->host;
165 }
166
176 public function setPort($port)
177 {
178 $this->port = $port;
179
180 return $this;
181 }
182
191 public function getPort()
192 {
193 return $this->port;
194 }
195
204 public function save()
205 {
206 global $ilSetting;
207
208 $ilSetting->set('proxy_host', $this->getHost());
209 $ilSetting->set('proxy_port', $this->getPort());
210 $ilSetting->set('proxy_status', (int) $this->isActive());
211
212 return $this;
213 }
214
224 public function checkConnection()
225 {
226 global $DIC;
227
228 $errno = null;
229 $errstr = null;
230
231 set_error_handler(function ($severity, $message, $file, $line) {
232 throw new ErrorException($message, $severity, $severity, $file, $line);
233 });
234
235 try {
236 $host = $this->getHost();
237 if (strspn($host, '.0123456789') != strlen($host) && strstr($host, '/') === false) {
238 $host = gethostbyname($host);
239 }
240 $port = $this->getPort() % 65536;
241
242 if (!fsockopen($host, $port, $errno, $errstr, self::CONNECTION_CHECK_TIMEOUT)) {
243 restore_error_handler();
244 throw new ilProxyException(strlen($errstr) ? $errstr : $DIC->language()->txt('proxy_not_connectable'));
245 }
246 restore_error_handler();
247 } catch (Exception $e) {
248 restore_error_handler();
249 throw new ilProxyException(strlen($errstr) ? $errstr : $DIC->language()->txt('proxy_not_connectable'));
250 }
251
252 return $this;
253 }
254}
An exception for terminatinating execution or to throw for unit testing.
Class for proxy related exception handling in ILIAS.
class ilProxySettings
static _getInstance()
Getter for unique instance.
checkConnection()
Verifies the proxy server connection.
__construct()
Constructor.
getHost()
Getter for host.
read()
Fetches data from database.
setHost($host)
Setter for host.
getPort()
Getter for port.
save()
Saves the current data in database.
isActive($status=null)
Getter/Setter for status.
setPort($port)
Setter for port.
catch(Exception $e) $message
global $ilSetting
Definition: privfeed.php:17
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7