ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
24  protected static $_instance = null;
25 
35  protected $host = '';
36 
46  protected $post = '';
47 
57  protected $isActive = false;
58 
66  protected function __construct()
67  {
68  $this->read();
69  }
70 
78  private function __clone()
79  {
80  }
81 
91  public static function _getInstance()
92  {
93  if(null === self::$_instance)
94  {
95  self::$_instance = new self();
96  }
97 
98  return self::$_instance;
99  }
100 
108  protected function read()
109  {
110  global $ilSetting;
111 
112  $this->setHost($ilSetting->get('proxy_host'));
113  $this->setPort($ilSetting->get('proxy_port'));
114  $this->isActive((bool)$ilSetting->get('proxy_status'));
115  }
116 
126  public function isActive($status = null)
127  {
128  if(null === $status)
129  {
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  require_once 'Services/PEAR/lib/Net/Socket.php';
227 
228  $socket = new Net_Socket();
229  $socket->setErrorHandling(PEAR_ERROR_RETURN);
230  $response = $socket->connect($this->getHost(), $this->getPort());
231  if(!is_bool($response))
232  {
233  global $lng;
234  throw new ilProxyException(strlen($response) ? $response : $lng->txt('proxy_not_connectable'));
235  }
236 
237  return $this;
238  }
239 }
240 ?>