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

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

Generated on Fri Dec 13 2013 17:56:49 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1