• 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 
00069         function _isActive()
00070         {
00071                 global $ilias;
00072 
00073                 return (bool) $ilias->getSetting("chat_active");
00074         }
00075 
00076 
00077         // SET/GET
00078     function setInternalIp($ip)
00079     {
00080         $this->internal_ip = $ip;
00081     }
00082     function getInternalIp()
00083     {
00084         return $this->internal_ip;
00085     }
00086     function setExternalIp($ip)
00087     {
00088         $this->external_ip = $ip;
00089     }
00090     function getExternalIp()
00091     {
00092         return $this->external_ip ? $this->external_ip : $this->internal_ip;
00093     }
00094         function setPort($port)
00095         {
00096                 $this->port = $port;
00097         }
00098         function getPort()
00099         {
00100                 return $this->port;
00101         }
00102         function setModeratorPassword($a_passwd)
00103         {
00104                 $this->moderator = $a_passwd;
00105         }
00106         function getModeratorPassword()
00107         {
00108                 return $this->moderator;
00109         }
00110         function setLogfile($logfile)
00111         {
00112                 $this->logfile = $logfile;
00113         }
00114         function getLogfile()
00115         {
00116                 return $this->logfile;
00117         }
00118         function setLogLevel($loglevel)
00119         {
00120                 $this->loglevel = $loglevel;
00121         }
00122         function getLogLevel()
00123         {
00124                 return $this->loglevel;
00125         }
00126         function setAllowedHosts($hosts)
00127         {
00128                 $this->hosts = $hosts;
00129         }
00130         function getAllowedHosts()
00131         {
00132                 return $this->hosts;
00133         }
00134 
00135         function getErrorMessage()
00136         {
00137                 return $this->error_message;
00138         }
00139         function setActiveStatus($status)
00140         {
00141                 $this->active = $status;
00142         }
00143         function getActiveStatus()
00144         {
00145                 return $this->active;
00146         }
00147         function getNic()
00148         {
00149                 return substr($this->nic,0,6);
00150         }
00151 
00152         function validate()
00153         {
00154                 $this->error_message = "";
00155 
00156         if(!$this->getInternalIp())
00157         {
00158             $this->error_message .= $this->lng->txt("chat_add_internal_ip");
00159         }
00160         if(!$this->getExternalIp())
00161         {
00162             $this->error_message .= $this->lng->txt("chat_add_external_ip");
00163         }
00164                 if(!$this->getPort())
00165                 {
00166                         if($this->error_message)
00167                         {
00168                                 $this->error_message .= "<br />";
00169                         }
00170                         $this->error_message .= $this->lng->txt("chat_add_port");
00171                 }
00172                 if(!$this->getModeratorPassword())
00173                 {
00174                         if($this->error_message)
00175                         {
00176                                 $this->error_message .= "<br />";
00177                         }
00178                         $this->error_message .= $this->lng->txt("chat_add_moderator_password");
00179                 }
00180                 if(!$this->getAllowedHosts())
00181                 {
00182                         if($this->error_message)
00183                         {
00184                                 $this->error_message .= "<br />";
00185                         }
00186                         $this->error_message .= $this->lng->txt("chat_add_allowed_hosts");
00187                 }
00188 
00189                 if($this->getAllowedHosts())
00190                 {
00191                         $this->__parseAllowedHosts();
00192                 }
00193 
00194                 return $this->error_message ? false : true;
00195         }
00196         function update()
00197         {
00198         $this->ilias->setSetting("chat_internal_ip",$this->getInternalIp());
00199         $this->ilias->setSetting("chat_external_ip",$this->getExternalIp());
00200                 $this->ilias->setSetting("chat_port",$this->getPort());
00201                 $this->ilias->setSetting("chat_logfile",$this->getLogfile());
00202                 $this->ilias->setSetting("chat_loglevel",$this->getLogLevel());
00203                 $this->ilias->setSetting("chat_hosts",$this->getAllowedHosts());
00204                 $this->ilias->setSetting("chat_moderator_password",$this->getModeratorPassword());
00205 
00206                 return $this->__writeConfigFile();
00207         }
00208         function updateStatus()
00209         {
00210                 $this->ilias->setSetting("chat_active",$this->getActiveStatus());
00211         }
00212 
00213         function read()
00214         {
00215         $this->internal_ip = $this->ilias->getSetting("chat_internal_ip");
00216         $this->external_ip = $this->ilias->getSetting("chat_external_ip");
00217                 $this->port = $this->ilias->getSetting("chat_port");
00218                 $this->moderator = $this->ilias->getSetting("chat_moderator_password");
00219                 $this->loglevel = $this->ilias->getSetting("chat_loglevel");
00220                 $this->logfile = $this->ilias->getSetting("chat_logfile");
00221                 $this->hosts = $this->ilias->getSetting("chat_hosts");
00222                 $this->active = $this->ilias->getSetting("chat_active");
00223                 $this->nic = $this->ilias->getSetting("nic_key");
00224         }
00225 
00226         function isAlive()
00227         {
00228         if($this->getInternalIp() and $this->getPort())
00229         {
00230             if( $sp = @fsockopen($this->getInternalIp(),$this->getPort(), $errno, $errstr, 100))
00231                         {
00232                                 fclose($sp);
00233                                 return true;
00234                         }
00235                         return false;
00236                 }
00237                 return false;
00238         }
00239 
00240         //PRIVATE
00241         function __parseAllowedHosts()
00242         {
00243                 $hosts_arr2 = array();
00244                 $hosts_arr = explode(',',$this->getAllowedHosts());
00245 
00246                 for($i = 0;$i < count($hosts_arr); ++$i)
00247                 {
00248                         if(trim($hosts_arr[$i]))
00249                         {
00250                                 $hosts_arr2[] = trim($hosts_arr[$i]);
00251                         }
00252                 }
00253                 $this->setAllowedHosts(implode(',',$hosts_arr2));
00254 
00255                 return true;
00256         }
00257         function __writeConfigFile()
00258         {
00259                 if(!@is_dir(ilUtil::getDataDir().'/chat'))
00260                 {
00261                         ilUtil::makeDir(ilUtil::getDataDir().'/chat');
00262                 }               
00263                 if(!($fp = @fopen(ilUtil::getDataDir().'/chat/server.ini',"w")))
00264                 {
00265                         $this->error_message = ilUtil::getDataDir().'/chat/server.ini ' .$this->lng->txt("chat_no_write_perm");
00266                         return false;
00267                 }
00268                 $content =  "LogLevel = ".$this->getLogLevel()."\n";
00269                 if($this->getLogfile())
00270                 {
00271                         $content .= "LogFile = ".$this->getLogfile()."\n";
00272                 }
00273         $content .= "IpAddress = ".$this->getInternalIp()."\n";
00274         $content .= "ExternalIpAddress = ".$this->getExternalIp()."\n";
00275                 $content .= "Port = ".$this->getPort()."\n";
00276                 $content .= "ModeratorPassword = ".$this->getModeratorPassword()."\n";
00277                 $content .= "HeaderFileName = ".ILIAS_ABSOLUTE_PATH."/chat/templates/default/header.html\n";
00278                 $content .= "FooterFileName = ".ILIAS_ABSOLUTE_PATH."/chat/templates/default/footer.html\n";
00279                 $content .= "Authentication = 1\n";
00280                 $content .= "ConnectionsFrom = ".$this->getAllowedHosts()."\n";
00281 
00282                 if(!@fwrite($fp,$content))
00283                 {
00284                         $this->error_message = ilUtil::getDataDir().'/chat/server.ini '.$this->lng->txt("chat_no_write_perm");
00285                         fclose($fp);
00286                         
00287                         return false;
00288 
00289                 }
00290                 fclose($fp);
00291                 return true;
00292         }
00293         
00294 } // END class.ilObjChatServer
00295 ?>

Generated on Fri Dec 13 2013 11:57:53 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1