]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/Phergie/Plugin/Acl.php
9738df60e052b0651f2477560b2c12646ed20135
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / Phergie / Plugin / Acl.php
1 <?php
2 /**
3  * Phergie 
4  *
5  * PHP version 5
6  *
7  * LICENSE
8  *
9  * This source file is subject to the new BSD license that is bundled
10  * with this package in the file LICENSE.
11  * It is also available through the world-wide-web at this URL:
12  * http://phergie.org/license
13  *
14  * @category  Phergie 
15  * @package   Phergie_Plugin_Acl
16  * @author    Phergie Development Team <team@phergie.org>
17  * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18  * @license   http://phergie.org/license New BSD License
19  * @link      http://pear.phergie.org/package/Phergie_Plugin_Acl
20  */
21
22 /**
23  * Provides an access control system to limit reponses to events based on 
24  * the users who originate them.
25  *
26  * @category Phergie 
27  * @package  Phergie_Plugin_Acl
28  * @author   Phergie Development Team <team@phergie.org>
29  * @license  http://phergie.org/license New BSD License
30  * @link     http://pear.phergie.org/package/Phergie_Plugin_Acl
31  */
32 class Phergie_Plugin_Acl extends Phergie_Plugin_Abstract
33 {
34     /**
35      * Checks for permission settings and removes the plugin if none are set.
36      *
37      * @return void
38      */
39     public function onLoad()
40     {
41         if (!$this->getConfig('acl.blacklist')
42             && !$this->getConfig('acl.whitelist')
43         ) {
44             $this->plugins->removePlugin($this);
45         }
46     }
47
48     /**
49      * Checks permission settings and short-circuits event processing for 
50      * blacklisted users.
51      *
52      * @return bool FALSE to short-circuit event processing if the user is 
53      *         blacklisted, TRUE otherwise
54      */
55     public function preEvent()
56     {
57         // Ignore server responses
58         if ($this->event instanceof Phergie_Event_Response) {
59             return true;
60         }
61
62         // Ignore server-initiated events
63         if (!$this->event->isFromUser()) {
64             return true;
65         }
66
67         // Determine whether a whitelist or blacklist is being used
68         $list = $this->getConfig('acl.whitelist');
69         $matches = true;
70         if (!$list) {
71             $list = $this->getConfig('acl.blacklist');
72             $matches = false;
73         }
74
75         // Support host-specific lists 
76         $host = $this->connection->getHost();
77         if (isset($list[$host])) {
78             $list = $list[$host];
79         }
80
81         // Short-circuit event processing if appropriate 
82         $hostmask = $this->event->getHostmask();
83         foreach ($list as $pattern) {
84             if ($hostmask->matches($pattern)) {
85                 return $matches;
86             }
87         }
88
89         // Allow event processing if appropriate 
90         return !$matches;
91     }
92 }