Ejemplo n.º 1
0
 /** Loads the rights database.
  * This function loads the rights database from a file, either previously saved or written manually.
  * 
  * \param $filename The file in which the database will be loaded.
  * 
  * \return TRUE.
  */
 public function loadRights($filename)
 {
     $contents = file_get_contents($filename);
     $this->rights = Leelabot::parseINIStringRecursive($contents);
     if (!$this->rights) {
         $this->rights = array();
     }
     return TRUE;
 }
Ejemplo n.º 2
0
 /** Loads data from .cfg files into a directory, recursively.
  * This function loads configuration from all .ini files in the given folder. It also loads the configurations found in all sub-directories.
  * The files are proceeded as .ini files, but adds a useful feature to them : multi-level sections. Using the '.', users will be able to
  * define more than one level of configuration (useful for data ordering). It does not parses the UNIX hidden directories.
  * 
  * \param $dir The directory to analyze.
  * \return The configuration if it loaded successfully, FALSE otherwise.
  */
 public static function parseCFGDirRecursive($dir)
 {
     if (!($dirContent = scandir($dir))) {
         return FALSE;
     }
     $finalConfig = array();
     $cfgdata = '';
     foreach ($dirContent as $file) {
         if (is_file($dir . '/' . $file) && pathinfo($file, PATHINFO_EXTENSION) == 'cfg') {
             $cfgdata .= "\n" . file_get_contents($dir . '/' . $file);
         } elseif (is_dir($dir . '/' . $file) && !in_array($file, array('.', '..')) && $file[0] != '.') {
             if ($fileConf = Leelabot::parseCFGDirRecursive($dir . '/' . $file)) {
                 $finalConfig = array_merge($finalConfig, $fileConf);
             } else {
                 Leelabot::message('Parse error in $0 directory.', array($dir), E_WARNING);
                 return FALSE;
             }
         }
     }
     $finalConfig = array_merge($finalConfig, Leelabot::parseINIStringRecursive($cfgdata));
     return $finalConfig;
 }
Ejemplo n.º 3
0
 /** Loads the banlist.
  * This function takes the file pointed by Banlist parameter from the config and loads the banlist from it. It also indexes IPs
  * for a more efficient and less time-eating search for bans.
  * 
  * \return TRUE if the banlist loaded correctly, FALSE otherwise.
  */
 public function loadBanlist()
 {
     $contents = file_get_contents($this->_banlistLocation);
     if ($contents === FALSE) {
         Leelabot::message('Can\'t load banlist : $0', array(Leelabot::lastError()), E_WARNING);
         return FALSE;
     }
     $this->_banlist = Leelabot::parseINIStringRecursive($contents);
     if (!$this->_banlist) {
         $this->_banlist = array();
     }
     $this->_bannedIP = array();
     foreach ($this->_banlist as $banID => $ban) {
         if (isset($ban['IP'])) {
             if (!isset($this->_bannedIP[$ban['IP']])) {
                 $this->_bannedIP[$ban['IP']] = array();
             }
             $this->_bannedIP[$ban['IP']][] = $banID;
         }
     }
     $this->_bannedGUID = array();
     foreach ($this->_banlist as $banID => $ban) {
         foreach ($ban['GUIDList'] as $guid) {
             if (!isset($this->_bannedGUID[$guid])) {
                 $this->_bannedGUID[$guid] = array();
             }
             $this->_bannedGUID[$guid][] = $banID;
         }
     }
     return TRUE;
 }