1<?php
2/**
3 * auth.class.php
4 *
5 * Copyright © 2006 Stephane Gully <stephane.gully@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, 51 Franklin St, Fifth Floor,
20 * Boston, MA  02110-1301  USA
21 */
22require_once dirname(__FILE__)."/../pfci18n.class.php";
23require_once dirname(__FILE__)."/../pfcuserconfig.class.php";
24require_once dirname(__FILE__)."/../pfcproxycommand.class.php";
25
26/**
27 * pfcProxyCommand_auth
28 *
29 * @author Stephane Gully <stephane.gully@gmail.com>
30 */
31class pfcProxyCommand_auth extends pfcProxyCommand
32{
33  function run(&$xml_reponse, $p)
34  {
35    $clientid    = $p["clientid"];
36    $param       = $p["param"];
37    $sender      = $p["sender"];
38    $recipient   = $p["recipient"];
39    $recipientid = $p["recipientid"];
40
41    $c =& pfcGlobalConfig::Instance();
42    $u =& pfcUserConfig::Instance();
43
44
45    // do not allow someone to run a command if he is not online
46    if ( !$u->isOnline() &&
47         $this->name != 'error' &&
48         $this->name != 'connect' &&
49         $this->name != 'update' )
50    {
51      $cmdp = $p;
52      $cmdp["param"] = _pfc("Your must be connected to send a message");
53      $cmd =& pfcCommand::Factory("error");
54      $cmd->run($xml_reponse, $cmdp);
55      return false;
56    }
57
58
59    // protect admin commands
60    $admincmd = array("kick", "ban", "unban", "op", "deop", "debug", "rehash");
61    if ( in_array($this->name, $admincmd) )
62    {
63      $container =& pfcContainer::Instance();
64      $nickid = $u->nickid;
65      $isadmin = $container->getUserMeta($nickid, 'isadmin');
66      if (!$isadmin)
67      {
68        $xml_reponse->script("alert('".addslashes(_pfc("You are not allowed to run '%s' command", $this->name))."');");
69        return false;
70      }
71    }
72
73    // channels protection
74    if ($this->name == "join" ||
75        $this->name == "join2")
76    {
77      $container   =& pfcContainer::Instance();
78      $channame    = $param;
79
80      // check the user is not listed in the banished channel list
81      $chan        = pfcCommand_join::GetRecipient($channame);
82      $chanid      = pfcCommand_join::GetRecipientId($channame);
83      $banlist     = $container->getChanMeta($chan, 'banlist_nickid');
84      if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist);
85      $nickid = $u->nickid;
86      if (in_array($nickid,$banlist))
87      {
88        // the user is banished, show a message and don't forward the /join command
89        $msg = _pfc("Can't join %s because you are banished", $param);
90        $xml_reponse->script("pfc.handleResponse('".$this->proxyname."', 'ban', '".addslashes($msg)."');");
91        return false;
92      }
93
94      if (count($c->frozen_channels)>0)
95      {
96        if (!in_array($channame,$c->frozen_channels))
97        {
98          // the user is banished, show a message and don't forward the /join command
99          $msg = _pfc("Can't join %s because the channels list is restricted", $param);
100          $xml_reponse->script("pfc.handleResponse('".$this->proxyname."', 'frozen', '".addslashes($msg)."');");
101          return false;
102        }
103      }
104    }
105
106    // forward the command to the next proxy or to the final command
107    $p["clientid"]    = $clientid;
108    $p["param"]       = $param;
109    $p["sender"]      = $sender;
110    $p["recipient"]   = $recipient;
111    $p["recipientid"] = $recipientid;
112    return $this->next->run($xml_reponse, $p);
113  }
114}
115
116?>
117