ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_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  {
97  self::$_instance = new self();
98  }
99 
100  return self::$_instance;
101  }
102 
110  protected function read()
111  {
112  global $ilSetting;
113 
114  $this->setHost($ilSetting->get('proxy_host'));
115  $this->setPort($ilSetting->get('proxy_port'));
116  $this->isActive((bool)$ilSetting->get('proxy_status'));
117  }
118 
128  public function isActive($status = null)
129  {
130  if(null === $status)
131  {
132  return (bool)$this->isActive;
133  }
134 
135  $this->isActive = (bool)$status;
136 
137  return $this;
138  }
139 
149  public function setHost($host)
150  {
151  $this->host = $host;
152 
153  return $this;
154  }
155 
164  public function getHost()
165  {
166  return $this->host;
167  }
168 
178  public function setPort($port)
179  {
180  $this->port = $port;
181 
182  return $this;
183  }
184 
193  public function getPort()
194  {
195  return $this->port;
196  }
197 
206  public function save()
207  {
208  global $ilSetting;
209 
210  $ilSetting->set('proxy_host', $this->getHost());
211  $ilSetting->set('proxy_port', $this->getPort());
212  $ilSetting->set('proxy_status', (int)$this->isActive());
213 
214  return $this;
215  }
216 
226  public function checkConnection()
227  {
228  global $DIC;
229 
230  $errno = null;
231  $errstr = null;
232 
233  set_error_handler(function ($severity, $message, $file, $line)
234  {
235  throw new ErrorException($message, $severity, $severity, $file, $line);
236  });
237 
238  try
239  {
240  $host = $this->getHost();
241  if(strspn($host, '.0123456789') != strlen($host) && strstr($host, '/') === false)
242  {
243  $host = gethostbyname($host);
244  }
245  $port = $this->getPort() % 65536;
246 
247  if(!fsockopen($host, $port, $errno, $errstr, self::CONNECTION_CHECK_TIMEOUT))
248  {
249  restore_error_handler();
250  throw new ilProxyException(strlen($errstr) ? $errstr : $DIC->language()->txt('proxy_not_connectable'));
251  }
252  restore_error_handler();
253  }
254  catch(Exception $e)
255  {
256  restore_error_handler();
257  throw new ilProxyException(strlen($errstr) ? $errstr : $DIC->language()->txt('proxy_not_connectable'));
258  }
259 
260  return $this;
261  }
262 }
263 ?>
read()
Fetches data from database.
class ilProxySettings
getHost()
Getter for host.
isActive($status=null)
Getter/Setter for status.
Class for proxy related exception handling in ILIAS.
checkConnection()
Verifies the proxy server connection.
setPort($port)
Setter for port.
__construct()
Constructor.
save()
Saves the current data in database.
getPort()
Getter for port.
global $ilSetting
Definition: privfeed.php:17
setHost($host)
Setter for host.
global $DIC
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static _getInstance()
Getter for unique instance.