ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatServerConfig.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
34  var $ilias;
35  var $lng;
36 
39  var $port;
41  var $ssl_port;
43  var $logfile;
44  var $loglevel;
45  var $hosts;
46  var $active;
47  var $nic;
48 
50 
51 
58  function ilChatServerConfig()
59  {
60  global $ilias,$lng;
61 
62  $this->ilias =& $ilias;
63  $this->lng =& $lng;
64  $this->lng->loadLanguageModule("chat");
65 
66  $this->read();
67  }
68 
69 
70  function _isActive()
71  {
72  global $ilias;
73 
74  return (bool) $ilias->getSetting("chat_active");
75  }
76 
77 
78  // SET/GET
79  function setInternalIp($ip)
80  {
81  $this->internal_ip = $ip;
82  }
83  function getInternalIp()
84  {
85  return $this->internal_ip;
86  }
87  function setExternalIp($ip)
88  {
89  $this->external_ip = $ip;
90  }
91  function getExternalIp()
92  {
93  return $this->external_ip ? $this->external_ip : $this->internal_ip;
94  }
95  function setPort($port)
96  {
97  $this->port = $port;
98  }
99  function getPort()
100  {
101  return $this->port;
102  }
103  function setSSLStatus($ssl_status = 0)
104  {
105  $this->ssl_status = $ssl_status;
106  }
107  function getSSLStatus()
108  {
109  return $this->ssl_status;
110  }
112  {
113  $this->ssl_port = $ssl_port;
114  }
115  function getSSLPort()
116  {
117  return $this->ssl_port;
118  }
119  function setModeratorPassword($a_passwd)
120  {
121  $this->moderator = $a_passwd;
122  }
124  {
125  return $this->moderator;
126  }
128  {
129  $this->logfile = $logfile;
130  }
131  function getLogfile()
132  {
133  return $this->logfile;
134  }
136  {
137  $this->loglevel = $loglevel;
138  }
139  function getLogLevel()
140  {
141  return $this->loglevel;
142  }
144  {
145  $this->hosts = $hosts;
146  }
147  function getAllowedHosts()
148  {
149  return $this->hosts;
150  }
151 
152  function getErrorMessage()
153  {
154  return $this->error_message;
155  }
156  function setActiveStatus($status)
157  {
158  $this->active = $status;
159  }
160  function getActiveStatus()
161  {
162  return $this->active;
163  }
164  function getNic()
165  {
166  return substr($this->nic,0,6);
167  }
168 
169  function validate()
170  {
171  $this->error_message = "";
172 
173  if(!$this->getInternalIp())
174  {
175  $this->error_message .= $this->lng->txt("chat_add_internal_ip");
176  }
177  if(!$this->getExternalIp())
178  {
179  if($this->error_message)
180  {
181  $this->error_message .= "<br />";
182  }
183  $this->error_message .= $this->lng->txt("chat_add_external_ip");
184  }
185  if(!$this->getPort())
186  {
187  if($this->error_message)
188  {
189  $this->error_message .= "<br />";
190  }
191  $this->error_message .= $this->lng->txt("chat_add_port");
192  }
193  if($this->getSSLStatus() && !$this->getSSLPort())
194  {
195  if($this->error_message)
196  {
197  $this->error_message .= "<br />";
198  }
199  $this->error_message .= $this->lng->txt("chat_add_ssl_port");
200  }
201  if(!$this->getModeratorPassword())
202  {
203  if($this->error_message)
204  {
205  $this->error_message .= "<br />";
206  }
207  $this->error_message .= $this->lng->txt("chat_add_moderator_password");
208  }
209  if(!$this->getAllowedHosts())
210  {
211  if($this->error_message)
212  {
213  $this->error_message .= "<br />";
214  }
215  $this->error_message .= $this->lng->txt("chat_add_allowed_hosts");
216  }
217 
218  if($this->getAllowedHosts())
219  {
220  $this->__parseAllowedHosts();
221  }
222 
223  return $this->error_message ? false : true;
224  }
225  function update()
226  {
227  $this->ilias->setSetting("chat_internal_ip",$this->getInternalIp());
228  $this->ilias->setSetting("chat_external_ip",$this->getExternalIp());
229  $this->ilias->setSetting("chat_port",$this->getPort());
230  $this->ilias->setSetting("chat_ssl_status",$this->getSSLStatus());
231  $this->ilias->setSetting("chat_ssl_port",$this->getSSLPort());
232  $this->ilias->setSetting("chat_logfile",$this->getLogfile());
233  $this->ilias->setSetting("chat_loglevel",$this->getLogLevel());
234  $this->ilias->setSetting("chat_hosts",$this->getAllowedHosts());
235  $this->ilias->setSetting("chat_moderator_password",$this->getModeratorPassword());
236 
237  return $this->__writeConfigFile();
238  }
239  function updateStatus()
240  {
241  $this->ilias->setSetting("chat_active",$this->getActiveStatus());
242  }
243 
244  function read()
245  {
246  $this->internal_ip = $this->ilias->getSetting("chat_internal_ip");
247  $this->external_ip = $this->ilias->getSetting("chat_external_ip");
248  $this->port = $this->ilias->getSetting("chat_port");
249  $this->ssl_status = $this->ilias->getSetting("chat_ssl_status");
250  $this->ssl_port = $this->ilias->getSetting("chat_ssl_port");
251  $this->moderator = $this->ilias->getSetting("chat_moderator_password");
252  $this->loglevel = $this->ilias->getSetting("chat_loglevel");
253  $this->logfile = $this->ilias->getSetting("chat_logfile");
254  $this->hosts = $this->ilias->getSetting("chat_hosts");
255  $this->active = $this->ilias->getSetting("chat_active");
256  $this->nic = $this->ilias->getSetting("nic_key");
257  }
258 
259  function isAlive()
260  {
261  if($this->getInternalIp() and $this->getPort())
262  {
263  if( $sp = @fsockopen($this->getInternalIp(),$this->getPort(), $errno, $errstr, 100))
264  {
265  fclose($sp);
266  return true;
267  }
268  return false;
269  }
270  return false;
271  }
272 
273  //PRIVATE
275  {
276  $hosts_arr2 = array();
277  $hosts_arr = explode(',',$this->getAllowedHosts());
278 
279  for($i = 0;$i < count($hosts_arr); ++$i)
280  {
281  if(trim($hosts_arr[$i]))
282  {
283  $hosts_arr2[] = trim($hosts_arr[$i]);
284  }
285  }
286  $this->setAllowedHosts(implode(',',$hosts_arr2));
287 
288  return true;
289  }
290  function __writeConfigFile()
291  {
292  if(!@is_dir(ilUtil::getDataDir().'/chat'))
293  {
295  }
296  if(!($fp = @fopen(ilUtil::getDataDir().'/chat/server.ini',"w")))
297  {
298  $this->error_message = ilUtil::getDataDir().'/chat/server.ini ' .$this->lng->txt("chat_no_write_perm");
299  return false;
300  }
301  $content = "LogLevel = ".$this->getLogLevel()."\n";
302  if($this->getLogfile())
303  {
304  $content .= "LogFile = ".$this->getLogfile()."\n";
305  }
306  $content .= "IpAddress = ".$this->getInternalIp()."\n";
307  $content .= "ExternalIpAddress = ".$this->getExternalIp()."\n";
308  $content .= "Port = ".$this->getPort()."\n";
309  #$content .= "SSLStatus = ".($this->getSSLStatus() ? $this->getSSLStatus() : 0)."\n";
310  #$content .= "SSLPort = ".$this->getSSLPort()."\n";
311  $content .= "ModeratorPassword = ".$this->getModeratorPassword()."\n";
312  $content .= "HeaderFileName = ".ILIAS_ABSOLUTE_PATH."/Modules/Chat/templates/default/header.html\n";
313  $content .= "FooterFileName = ".ILIAS_ABSOLUTE_PATH."/Modules/Chat/templates/default/footer.html\n";
314  $content .= "Authentication = 1\n";
315  $content .= "ConnectionsFrom = ".$this->getAllowedHosts()."\n";
316 
317  if(!@fwrite($fp,$content))
318  {
319  $this->error_message = ilUtil::getDataDir().'/chat/server.ini '.$this->lng->txt("chat_no_write_perm");
320  fclose($fp);
321 
322  return false;
323 
324  }
325  fclose($fp);
326  return true;
327  }
328 
329 } // END class.ilObjChatServer
330 ?>