/mod/chat/pfc/src/proxies/auth.class.php

https://github.com/masuman/elgg-1 · PHP · 116 lines · 78 code · 8 blank · 30 comment · 13 complexity · 98bb07eb64c80cc9333c90d923648b91 MD5 · raw file

  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. */
  22. require_once dirname(__FILE__)."/../pfci18n.class.php";
  23. require_once dirname(__FILE__)."/../pfcuserconfig.class.php";
  24. require_once dirname(__FILE__)."/../pfcproxycommand.class.php";
  25. /**
  26. * pfcProxyCommand_auth
  27. *
  28. * @author Stephane Gully <stephane.gully@gmail.com>
  29. */
  30. class pfcProxyCommand_auth extends pfcProxyCommand
  31. {
  32. function run(&$xml_reponse, $p)
  33. {
  34. $clientid = $p["clientid"];
  35. $param = $p["param"];
  36. $sender = $p["sender"];
  37. $recipient = $p["recipient"];
  38. $recipientid = $p["recipientid"];
  39. $c =& pfcGlobalConfig::Instance();
  40. $u =& pfcUserConfig::Instance();
  41. // do not allow someone to run a command if he is not online
  42. if ( !$u->isOnline() &&
  43. $this->name != 'error' &&
  44. $this->name != 'connect' &&
  45. $this->name != 'update' )
  46. {
  47. $cmdp = $p;
  48. $cmdp["param"] = _pfc("Your must be connected to send a message");
  49. $cmd =& pfcCommand::Factory("error");
  50. $cmd->run($xml_reponse, $cmdp);
  51. return false;
  52. }
  53. // protect admin commands
  54. $admincmd = array("kick", "ban", "unban", "op", "deop", "debug", "rehash");
  55. if ( in_array($this->name, $admincmd) )
  56. {
  57. $container =& pfcContainer::Instance();
  58. $nickid = $u->nickid;
  59. $isadmin = $container->getUserMeta($nickid, 'isadmin');
  60. if (!$isadmin)
  61. {
  62. $xml_reponse->script("alert('".addslashes(_pfc("You are not allowed to run '%s' command", $this->name))."');");
  63. return false;
  64. }
  65. }
  66. // channels protection
  67. if ($this->name == "join" ||
  68. $this->name == "join2")
  69. {
  70. $container =& pfcContainer::Instance();
  71. $channame = $param;
  72. // check the user is not listed in the banished channel list
  73. $chan = pfcCommand_join::GetRecipient($channame);
  74. $chanid = pfcCommand_join::GetRecipientId($channame);
  75. $banlist = $container->getChanMeta($chan, 'banlist_nickid');
  76. if ($banlist == NULL) $banlist = array(); else $banlist = unserialize($banlist);
  77. $nickid = $u->nickid;
  78. if (in_array($nickid,$banlist))
  79. {
  80. // the user is banished, show a message and don't forward the /join command
  81. $msg = _pfc("Can't join %s because you are banished", $param);
  82. $xml_reponse->script("pfc.handleResponse('".$this->proxyname."', 'ban', '".addslashes($msg)."');");
  83. return false;
  84. }
  85. if (count($c->frozen_channels)>0)
  86. {
  87. if (!in_array($channame,$c->frozen_channels))
  88. {
  89. // the user is banished, show a message and don't forward the /join command
  90. $msg = _pfc("Can't join %s because the channels list is restricted", $param);
  91. $xml_reponse->script("pfc.handleResponse('".$this->proxyname."', 'frozen', '".addslashes($msg)."');");
  92. return false;
  93. }
  94. }
  95. }
  96. // forward the command to the next proxy or to the final command
  97. $p["clientid"] = $clientid;
  98. $p["param"] = $param;
  99. $p["sender"] = $sender;
  100. $p["recipient"] = $recipient;
  101. $p["recipientid"] = $recipientid;
  102. return $this->next->run($xml_reponse, $p);
  103. }
  104. }
  105. ?>