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
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
23 * Provides an access control system to limit reponses to events based on
24 * the users who originate them.
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
32 class Phergie_Plugin_Acl extends Phergie_Plugin_Abstract
35 * Checks for permission settings and removes the plugin if none are set.
39 public function onLoad()
41 if (!$this->getConfig('acl.blacklist')
42 && !$this->getConfig('acl.whitelist')
44 $this->plugins->removePlugin($this);
49 * Checks permission settings and short-circuits event processing for
52 * @return bool FALSE to short-circuit event processing if the user is
53 * blacklisted, TRUE otherwise
55 public function preEvent()
57 // Ignore server responses
58 if ($this->event instanceof Phergie_Event_Response) {
62 // Ignore server-initiated events
63 if (!$this->event->isFromUser()) {
67 // Determine whether a whitelist or blacklist is being used
68 $list = $this->getConfig('acl.whitelist');
71 $list = $this->getConfig('acl.blacklist');
75 // Support host-specific lists
76 $host = $this->connection->getHost();
77 if (isset($list[$host])) {
81 // Short-circuit event processing if appropriate
82 $hostmask = $this->event->getHostmask();
83 foreach ($list as $pattern) {
84 if ($hostmask->matches($pattern)) {
89 // Allow event processing if appropriate