• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

chat/classes/class.ilChatServerConfig.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00033 class ilChatServerConfig
00034 {
00035         var $ilias;
00036         var $lng;
00037 
00038     var $internal_ip;
00039     var $external_ip;
00040         var $port;
00041         var $moderator;
00042         var $logfile;
00043         var $loglevel;
00044         var $hosts;
00045         var $active;
00046         var $nic;
00047 
00048         var $error_message;
00049 
00050         
00057         function ilChatServerConfig()
00058         {
00059                 global $ilias,$lng;
00060 
00061                 $this->ilias =& $ilias;
00062                 $this->lng =& $lng;
00063                 $this->lng->loadLanguageModule("chat");
00064 
00065                 $this->read();
00066         }
00067 
00068         // SET/GET
00069     function setInternalIp($ip)
00070     {
00071         $this->internal_ip = $ip;
00072     }
00073     function getInternalIp()
00074     {
00075         return $this->internal_ip;
00076     }
00077     function setExternalIp($ip)
00078     {
00079         $this->external_ip = $ip;
00080     }
00081     function getExternalIp()
00082     {
00083         return $this->external_ip ? $this->external_ip : $this->internal_ip;
00084     }
00085         function setPort($port)
00086         {
00087                 $this->port = $port;
00088         }
00089         function getPort()
00090         {
00091                 return $this->port;
00092         }
00093         function setModeratorPassword($a_passwd)
00094         {
00095                 $this->moderator = $a_passwd;
00096         }
00097         function getModeratorPassword()
00098         {
00099                 return $this->moderator;
00100         }
00101         function setLogfile($logfile)
00102         {
00103                 $this->logfile = $logfile;
00104         }
00105         function getLogfile()
00106         {
00107                 return $this->logfile;
00108         }
00109         function setLogLevel($loglevel)
00110         {
00111                 $this->loglevel = $loglevel;
00112         }
00113         function getLogLevel()
00114         {
00115                 return $this->loglevel;
00116         }
00117         function setAllowedHosts($hosts)
00118         {
00119                 $this->hosts = $hosts;
00120         }
00121         function getAllowedHosts()
00122         {
00123                 return $this->hosts;
00124         }
00125 
00126         function getErrorMessage()
00127         {
00128                 return $this->error_message;
00129         }
00130         function setActiveStatus($status)
00131         {
00132                 $this->active = $status;
00133         }
00134         function getActiveStatus()
00135         {
00136                 return $this->active;
00137         }
00138         function getNic()
00139         {
00140                 return substr($this->nic,0,6);
00141         }
00142 
00143         function validate()
00144         {
00145                 $this->error_message = "";
00146 
00147         if(!$this->getInternalIp())
00148         {
00149             $this->error_message .= $this->lng->txt("chat_add_internal_ip");
00150         }
00151         if(!$this->getExternalIp())
00152         {
00153             $this->error_message .= $this->lng->txt("chat_add_external_ip");
00154         }
00155                 if(!$this->getPort())
00156                 {
00157                         if($this->error_message)
00158                         {
00159                                 $this->error_message .= "<br />";
00160                         }
00161                         $this->error_message .= $this->lng->txt("chat_add_port");
00162                 }
00163                 if(!$this->getModeratorPassword())
00164                 {
00165                         if($this->error_message)
00166                         {
00167                                 $this->error_message .= "<br />";
00168                         }
00169                         $this->error_message .= $this->lng->txt("chat_add_moderator_password");
00170                 }
00171                 if(!$this->getAllowedHosts())
00172                 {
00173                         if($this->error_message)
00174                         {
00175                                 $this->error_message .= "<br />";
00176                         }
00177                         $this->error_message .= $this->lng->txt("chat_add_allowed_hosts");
00178                 }
00179 
00180                 if($this->getAllowedHosts())
00181                 {
00182                         $this->__parseAllowedHosts();
00183                 }
00184 
00185                 return $this->error_message ? false : true;
00186         }
00187         function update()
00188         {
00189         $this->ilias->setSetting("chat_internal_ip",$this->getInternalIp());
00190         $this->ilias->setSetting("chat_external_ip",$this->getExternalIp());
00191                 $this->ilias->setSetting("chat_port",$this->getPort());
00192                 $this->ilias->setSetting("chat_logfile",$this->getLogfile());
00193                 $this->ilias->setSetting("chat_loglevel",$this->getLogLevel());
00194                 $this->ilias->setSetting("chat_hosts",$this->getAllowedHosts());
00195                 $this->ilias->setSetting("chat_moderator_password",$this->getModeratorPassword());
00196 
00197                 return $this->__writeConfigFile();
00198         }
00199         function updateStatus()
00200         {
00201                 $this->ilias->setSetting("chat_active",$this->getActiveStatus());
00202         }
00203 
00204         function read()
00205         {
00206         $this->internal_ip = $this->ilias->getSetting("chat_internal_ip");
00207         $this->external_ip = $this->ilias->getSetting("chat_external_ip");
00208                 $this->port = $this->ilias->getSetting("chat_port");
00209                 $this->moderator = $this->ilias->getSetting("chat_moderator_password");
00210                 $this->loglevel = $this->ilias->getSetting("chat_loglevel");
00211                 $this->logfile = $this->ilias->getSetting("chat_logfile");
00212                 $this->hosts = $this->ilias->getSetting("chat_hosts");
00213                 $this->active = $this->ilias->getSetting("chat_active");
00214                 $this->nic = $this->ilias->getSetting("nic_key");
00215         }
00216 
00217         function isAlive()
00218         {
00219         if($this->getInternalIp() and $this->getPort())
00220         {
00221             if( $sp = @fsockopen($this->getInternalIp(),$this->getPort(), $errno, $errstr, 100))
00222                         {
00223                                 fclose($sp);
00224                                 return true;
00225                         }
00226                         return false;
00227                 }
00228                 return false;
00229         }
00230 
00231         //PRIVATE
00232         function __parseAllowedHosts()
00233         {
00234                 $hosts_arr2 = array();
00235                 $hosts_arr = explode(',',$this->getAllowedHosts());
00236 
00237                 for($i = 0;$i < count($hosts_arr); ++$i)
00238                 {
00239                         if(trim($hosts_arr[$i]))
00240                         {
00241                                 $hosts_arr2[] = trim($hosts_arr[$i]);
00242                         }
00243                 }
00244                 $this->setAllowedHosts(implode(',',$hosts_arr2));
00245 
00246                 return true;
00247         }
00248         function __writeConfigFile()
00249         {
00250                 if(!($fp = @fopen($a_path."./chat/chatserver/server.ini","w")))
00251                 {
00252                         $this->error_message = "./chat/chatserver/server.ini ".$this->lng->txt("chat_no_write_perm");
00253                         return false;
00254                 }
00255                 $content =  "LogLevel = ".$this->getLogLevel()."\n";
00256                 if($this->getLogfile())
00257                 {
00258                         $content .= "LogFile = ".$this->getLogfile()."\n";
00259                 }
00260         $content .= "IpAddress = ".$this->getInternalIp()."\n";
00261         $content .= "ExternalIpAddress = ".$this->getExternalIp()."\n";
00262                 $content .= "Port = ".$this->getPort()."\n";
00263                 $content .= "ModeratorPassword = ".$this->getModeratorPassword()."\n";
00264                 $content .= "HeaderFileName = ".ILIAS_ABSOLUTE_PATH."/chat/templates/default/header.html\n";
00265                 $content .= "FooterFileName = ".ILIAS_ABSOLUTE_PATH."/chat/templates/default/footer.html\n";
00266                 $content .= "Authentication = 1\n";
00267                 $content .= "ConnectionsFrom = ".$this->getAllowedHosts()."\n";
00268 
00269                 if(!@fwrite($fp,$content))
00270                 {
00271                         $this->error_message = ILIAS_ABSOLUTE_PATH."/chat/chatserver/server.ini ".$this->lng->txt("chat_no_write_perm");
00272                         fclose($fp);
00273                         
00274                         return false;
00275 
00276                 }
00277                 fclose($fp);
00278                 return true;
00279         }
00280         
00281 } // END class.ilObjChatServer
00282 ?>

Generated on Fri Dec 13 2013 09:06:33 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1