1<?php
2/**
3 * identify.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 */
22
23require_once(dirname(__FILE__)."/../pfccommand.class.php");
24
25/**
26 * pfcCommand_identify
27 * this command will identify the user admin rights
28 * @author Stephane Gully <stephane.gully@gmail.com>
29 */
30class pfcCommand_identify extends pfcCommand
31{
32  var $usage = "/identify {password}";
33
34  function run(&$xml_reponse, $p)
35  {
36    $clientid    = $p["clientid"];
37    $param       = $p["param"];
38    $sender      = $p["sender"];
39    $recipient   = $p["recipient"];
40    $recipientid = $p["recipientid"];
41
42    $c =& pfcGlobalConfig::Instance();
43    $u =& pfcUserConfig::Instance();
44
45    $password = trim($param);
46    $isadmin = false;
47
48//     $xml_reponse->script("alert('sender=".$sender."');");
49//     $xml_reponse->script("alert('password=".$password."');");
50//     $xml_reponse->script("alert('admins=".var_export($c->admins, true)."');");
51
52    if( isset($c->admins[$sender]) &&
53	$c->admins[$sender] == $password )
54      $isadmin = true;
55
56    $msg   = "";
57    if ($isadmin)
58    {
59      // ok the current user is an admin, just save the isadmin flag in the metadata
60      $ct =& pfcContainer::Instance();
61      $ct->setUserMeta($u->nickid, 'isadmin', $isadmin);
62      $this->forceWhoisReload($u->nickid);
63
64      $msg .= _pfc("Succesfully identified");
65      $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ok', '".$msg."');");
66    }
67    else
68    {
69      $msg .= _pfc("Identification failure");
70      $xml_reponse->script("pfc.handleResponse('".$this->name."', 'ko', '".$msg."');");
71    }
72  }
73}
74
75?>