Assembla home | Assembla project page
 

Changeset 142

Show
Ignore:
Timestamp:
03/09/08 02:51:37 (9 months ago)
Author:
Slynderdale
Message:

Adds a switch to the fromAdmin in AdminCommand?.php to check if for just the hostmask admin and not an operator Changes were made to the Set plugin to only allow hostmask admins to set and retrieve ini settings. Changes were made in Toogle so hostmask so only hostmask admins can disable/enable modules.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Plugin/Abstract/AdminCommand.php

    r141 r142  
    110110    * op. 
    111111    * 
     112    * @param bool $includeOps Include ops in the admin check 
    112113    * @return bool TRUE if the message originated from an authorized 
    113114    *              individual, FALSE otherwise 
    114115    */ 
    115     public function fromAdmin(
     116    public function fromAdmin($includeOps = true
    116117    { 
    117118        $class = $this->getName(); 
     
    121122            return true; 
    122123        } 
     124 
    123125        // Check if is op and ops are admins 
    124         $nick = $this->event->getNick(); 
    125         $source = $this->event->getSource(); 
    126         if ($this->ops[$class] && Phergie_Plugin_Users::isOp($nick, $source)) { 
    127             return true; 
     126        if ($includeOps) { 
     127            $nick = $this->event->getNick(); 
     128            $source = $this->event->getSource(); 
     129            if ($this->ops[$class] && Phergie_Plugin_Users::isOp($nick, $source)) { 
     130                return true; 
     131            } 
    128132        } 
    129133        return false; 
  • trunk/Phergie/Plugin/Set.php

    r129 r142  
    1616    public function onDoSet($var, $value, $tmp = null) 
    1717    { 
    18         $append = $var === '-a' || $var === 'append'; 
    19         // Got an append parameter, so we shift value/tmp down to var/value 
    20         if ($append) { 
    21                 $var = $value; 
    22                 $value = $tmp; 
    23         } elseif(!empty($tmp)) { 
    24                 $value .= ' '.$tmp; 
    25         } 
     18          if ($this->fromAdmin(false)) { 
     19            $append = $var === '-a' || $var === 'append'; 
     20            // Got an append parameter, so we shift value/tmp down to var/value 
     21            if ($append) { 
     22                $var = $value; 
     23                $value = $tmp; 
     24            } elseif(!empty($tmp)) { 
     25                $value .= ' '.$tmp; 
     26            } 
    2627 
    27         // Get ini file 
    28         $ini = PHERGIE_DIR . 'Phergie/' . (empty($_SERVER['argv'][1]) ? PHERGIE_INI : $_SERVER['argv'][1]); 
    29         $contents = file_get_contents($ini); 
    30         // Replace var/value 
    31         if (preg_match('#^\s*('.str_replace('.', '\\.', $var).'\s*=\s*)(.*)$#im', $contents, $m)) { 
    32                 $contents = preg_replace('#^\s*'.str_replace('.', '\\.', $var).'\s*=.*$#im', $var.' = '.$this->makeIniValue($value, $m[2], $append), $contents); 
    33                 $this->setIni($var, $this->parseIniValue($this->makeIniValue($value, $m[2], $append))); 
    34                 // Insert it if not set 
    35         } else { 
    36                 $contents .= "\r\n".$var.' = '.$this->makeIniValue($value); 
    37                 $this->setIni($var, $this->parseIniValue($value)); 
    38         } 
    39         // Save ini file 
    40         file_put_contents($ini, $contents); 
     28            // Get ini file 
     29            $ini = PHERGIE_DIR . 'Phergie/' . (empty($_SERVER['argv'][1]) ? PHERGIE_INI : $_SERVER['argv'][1]); 
     30            $contents = file_get_contents($ini); 
     31            // Replace var/value 
     32            if (preg_match('#^\s*('.str_replace('.', '\\.', $var).'\s*=\s*)(.*)$#im', $contents, $m)) { 
     33                $contents = preg_replace('#^\s*'.str_replace('.', '\\.', $var).'\s*=.*$#im', $var.' = '.$this->makeIniValue($value, $m[2], $append), $contents); 
     34                $this->setIni($var, $this->parseIniValue($this->makeIniValue($value, $m[2], $append))); 
     35            // Insert it if not set 
     36            } else { 
     37                $contents .= "\r\n".$var.' = '.$this->makeIniValue($value); 
     38                $this->setIni($var, $this->parseIniValue($value)); 
     39            } 
     40 
     41            // Save ini file 
     42            file_put_contents($ini, $contents); 
     43        } 
    4144    } 
    4245 
    4346        public function onDoGet($var) 
    4447        { 
    45                 $val = $this->getIni($var); 
    46                 $this->doPrivmsg($this->event->getSource(), $var.' = '.($val===null?'null':$val)); 
     48      if ($this->fromAdmin(false)) { 
     49                      $val = $this->getIni($var); 
     50                      $this->doPrivmsg($this->event->getSource(), $var.' = '.($val===null?'null':$val)); 
     51                  } 
    4752        } 
    4853 
  • trunk/Phergie/Plugin/Toggle.php

    r125 r142  
    1111class Phergie_Plugin_Toggle extends Phergie_Plugin_Abstract_AdminCommand 
    1212{ 
    13     public function onDoDisable($plugin) 
    14     { 
    15         if (($instance = $this->getPlugin($plugin)) && $instance != $this) { 
    16                 $instance->enabled = false; 
    17                 $this->doPrivmsg($this->event->getSource(), 'Disabled '.$plugin.'.'); 
    18         } else { 
    19                 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' is not loaded.'); 
    20         } 
    21     } 
     13        public function onDoDisable($plugin) 
     14        { 
     15                // Check to see if the admin is a hostmask admin only and not an op 
     16                if ($this->fromAdmin(false)) { 
     17                        if (($instance = $this->getPlugin($plugin)) && $instance != $this) { 
     18                                $instance->enabled = false; 
     19                                $this->doPrivmsg($this->event->getSource(), 'Disabled '.$plugin.'.'); 
     20                        } else { 
     21                                $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' is not loaded.'); 
     22                        } 
     23                } 
     24        } 
    2225 
    23     public function onDoEnable($plugin) 
    24     { 
    25         // Plugin is loaded already 
    26         if ($instance = $this->getPlugin($plugin)) { 
    27                 // Already enabled 
    28                 if ($instance->enabled) { 
    29                         $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' was already enabled.'); 
    30                 // Not yet enabled, enable 
    31                 } else { 
    32                         $instance->enabled = true; 
    33                         $this->doPrivmsg($this->event->getSource(), 'Enabled '.$plugin.'.'); 
    34                 } 
    35             // Plugin was not loaded, try to see if we can load it 
    36         } else { 
    37                         // Build loaded plugin list to pass to the checkDependencies method 
    38                         $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 
    39                         $plugins = array(); 
     26        public function onDoEnable($plugin) 
     27        { 
     28                // Check to see if the admin is a hostmask admin only and not an op 
     29                if ($this->fromAdmin(false)) { 
     30                        // Plugin is loaded already 
     31                        if ($instance = $this->getPlugin($plugin)) { 
     32                                // Already enabled 
     33                                if ($instance->enabled) { 
     34                                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' was already enabled.'); 
     35                                        // Not yet enabled, enable 
     36                                } else { 
     37                                        $instance->enabled = true; 
     38                                        $this->doPrivmsg($this->event->getSource(), 'Enabled '.$plugin.'.'); 
     39                                } 
     40                                // Plugin was not loaded, try to see if we can load it 
     41                        } else { 
     42                                // Build loaded plugin list to pass to the checkDependencies method 
     43                                $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 
     44                                $plugins = array(); 
    4045 
    41                         foreach ($iterator as $entry) { 
    42                                 if ($iterator->isFile()) { 
    43                                         $plugins[] = basename((string) $entry, '.php'); 
     46                                foreach ($iterator as $entry) { 
     47                                        if ($iterator->isFile()) { 
     48                                                $plugins[] = basename((string) $entry, '.php'); 
     49                                        } 
     50 
     51                                        if ($iterator->isFile() && strtolower((string) $entry) == strtolower($plugin).'.php') { 
     52                                                $target = (string) $entry; 
     53                                        } 
    4454                                } 
    4555 
    46                                 if ($iterator->isFile() && strtolower((string) $entry) == strtolower($plugin).'.php') { 
    47                                         $target = (string) $entry; 
     56                                foreach ($plugins as $k=>$p) { 
     57                                        if(!($this->getPlugin($p) instanceof Phergie_Plugin_Abstract_Base)) { 
     58                                                unset($plugins[$k]); 
     59                                        } 
     60                                } 
     61 
     62                                // Plugin file was found, check if it can be loaded 
     63                                if (isset($target)) { 
     64                                        require_once PHERGIE_DIR.'/Phergie/Plugin/'.$target; 
     65                                        $class = 'Phergie_Plugin_'.substr($target, 0, -4); 
     66                                        if (call_user_func(array($class, 'checkDependencies'), $this->client, $plugins)) { 
     67                                                $instance = new $class($this->client); 
     68                                                $this->client->addPlugin($instance); 
     69                                                $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' loaded.'); 
     70                                        } else { 
     71                                                $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' can not be loaded, missing dependencies.'); 
     72                                        } 
     73                                        // Plugin file not found 
     74                                } else { 
     75                                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not enable.'); 
    4876                                } 
    4977                        } 
     78                } 
     79        } 
    5080 
    51                         foreach ($plugins as $k=>$p) { 
    52                                 if(!($this->getPlugin($p) instanceof Phergie_Plugin_Abstract_Base)) { 
    53                                         unset($plugins[$k]); 
    54                                 } 
    55                         } 
     81        public function onDoMute($plugin) 
     82        { 
     83                if ($instance = $this->getPlugin($plugin)) { 
     84                        $instance->muted = true; 
     85                        $this->doPrivmsg($this->event->getSource(), 'Muted '.$plugin.'.'); 
     86                } else { 
     87                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not mute.'); 
     88                } 
     89        } 
    5690 
    57                         // Plugin file was found, check if it can be loaded 
    58                         if (isset($target)) { 
    59                                 require_once PHERGIE_DIR.'/Phergie/Plugin/'.$target; 
    60                             $class = 'Phergie_Plugin_'.substr($target, 0, -4); 
    61                             if (call_user_func(array($class, 'checkDependencies'), $this->client, $plugins)) { 
    62                                 $instance = new $class($this->client); 
    63                                 $this->client->addPlugin($instance); 
    64                                         $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' loaded.'); 
    65                             } else { 
    66                                         $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' can not be loaded, missing dependencies.'); 
    67                             } 
    68                         // Plugin file not found 
    69                 } else { 
    70                                 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not enable.'); 
    71                 } 
    72         } 
    73     } 
    74  
    75     public function onDoMute($plugin) 
    76     { 
    77         if ($instance = $this->getPlugin($plugin)) { 
    78                 $instance->muted = true; 
    79                 $this->doPrivmsg($this->event->getSource(), 'Muted '.$plugin.'.'); 
    80         } else { 
    81                 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not mute.'); 
    82         } 
    83     } 
    84  
    85     public function onDoUnmute($plugin) 
    86     { 
    87         if ($instance = $this->getPlugin($plugin)) { 
    88                 $instance->muted = false; 
    89                 $this->doPrivmsg($this->event->getSource(), 'Unmuted '.$plugin.'.'); 
    90         } else { 
    91                 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not unmute.'); 
    92         } 
    93     } 
     91        public function onDoUnmute($plugin) 
     92        { 
     93                if ($instance = $this->getPlugin($plugin)) { 
     94                        $instance->muted = false; 
     95                        $this->doPrivmsg($this->event->getSource(), 'Unmuted '.$plugin.'.'); 
     96                } else { 
     97                        $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not unmute.'); 
     98                } 
     99        } 
    94100}