[Phpfreechat-svn] SF.net SVN: phpfreechat: [562] trunk/src
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2006-06-11 21:22:29
|
Revision: 562 Author: kerphi Date: 2006-06-11 14:22:17 -0700 (Sun, 11 Jun 2006) ViewCVS: http://svn.sourceforge.net/phpfreechat/?rev=562&view=rev Log Message: ----------- - add the "noflood" proxy : don't allow flooders - fix the proxy chaine generation Modified Paths: -------------- trunk/src/pfccommand.class.php trunk/src/pfcglobalconfig.class.php Added Paths: ----------- trunk/src/proxys/noflood.class.php Modified: trunk/src/pfccommand.class.php =================================================================== --- trunk/src/pfccommand.class.php 2006-06-09 11:21:03 UTC (rev 561) +++ trunk/src/pfccommand.class.php 2006-06-11 21:22:17 UTC (rev 562) @@ -69,30 +69,40 @@ $cmd = NULL; $cmd_name = strtolower($name); $cmd_classname = "pfcCommand_".$name; - $cmd_filename = dirname(__FILE__)."/commands/".$cmd_name.".class.php"; - if (file_exists($cmd_filename)) require_once($cmd_filename); + if (!class_exists($cmd_classname)) + { + $cmd_filename = dirname(__FILE__)."/commands/".$cmd_name.".class.php"; + if (file_exists($cmd_filename)) require_once($cmd_filename); + } if (class_exists($cmd_classname)) { $cmd =& new $cmd_classname(); $cmd->name = $cmd_name; - // instanciate the proxy chains - // @todo instanciate the whole chain (from the 'proxys' parameter array) - $proxy = NULL; - $proxy_name = strtolower($c->proxys[0]); - $proxy_classname = "pfcProxyCommand_" . $proxy_name; - $proxy_filename = dirname(__FILE__)."/proxys/".$proxy_name.".class.php"; - if (file_exists($proxy_filename)) require_once($proxy_filename); - if (class_exists($proxy_classname)) + // instanciate the proxys chaine + $firstproxy =& $cmd; + for($i = count($c->proxys)-1; $i >= 0; $i--) { - $proxy =& new $proxy_classname(); - $proxy->name = $cmd_name; - $proxy->proxyname = $proxy_name; - $proxy->linkTo($cmd); + $proxy_name = strtolower($c->proxys[$i]); + $proxy_classname = "pfcProxyCommand_" . $proxy_name; + if (!class_exists($proxy_classname)) + { + // try to include the proxy class file + $proxy_filename = dirname(__FILE__)."/proxys/".$proxy_name.".class.php"; + if (file_exists($proxy_filename)) require_once($proxy_filename); + } + if (class_exists($proxy_classname)) + { + // instanciate the proxy + $proxy =& new $proxy_classname(); + $proxy->name = $cmd_name; + $proxy->proxyname = $proxy_name; + $proxy->linkTo($firstproxy); + $firstproxy =& $proxy; + } } - // return the proxy, not the command (the proxy will forward the request to the real command) - return $proxy; + return $firstproxy; } return $cmd; } Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2006-06-09 11:21:03 UTC (rev 561) +++ trunk/src/pfcglobalconfig.class.php 2006-06-11 21:22:17 UTC (rev 562) @@ -37,7 +37,9 @@ var $isadmin = false; // these parameters are static (cached) - var $proxys = array("auth"); + var $proxys = array("auth", "noflood"); + var $proxys_cfg = array("auth" => array(), + "noflood" => array("limit"=>10,"delay"=>5)); var $title = ""; // default is _pfc("My Chat") var $channels = array(); // the default joined channels when opening the chat var $frozen_channels = array(); // by default allow users to create there own channels Added: trunk/src/proxys/noflood.class.php =================================================================== --- trunk/src/proxys/noflood.class.php (rev 0) +++ trunk/src/proxys/noflood.class.php 2006-06-11 21:22:17 UTC (rev 562) @@ -0,0 +1,71 @@ +<?php +/** + * noflood.class.php + * + * Copyright © 2006 Stephane Gully <ste...@gm...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ +require_once dirname(__FILE__)."/../pfci18n.class.php"; +require_once dirname(__FILE__)."/../pfcuserconfig.class.php"; +require_once dirname(__FILE__)."/../pfcproxycommand.class.php"; + +/** + * pfcProxyCommand_noflood + * this proxy will protect the chat from flooders + * @author Stephane Gully <ste...@gm...> + */ +class pfcProxyCommand_noflood extends pfcProxyCommand +{ + function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid) + { + $c =& $this->c; + $u =& $this->u; + + $cmdtocheck = array("send", "nick", "me", "notice"); + if ( in_array($this->name, $cmdtocheck) ) + { + $container =& $c->getContainerInstance(); + $nickid = $container->getNickId($sender); + $isadmin = $container->getMeta("isadmin", "nickname", $nickid); + $lastfloodtime = $container->getMeta("floodtime", "nickname", $nickid); + $nbflood = $container->getMeta("nbflood", "nickname", $nickid); + $floodtime = time(); + + if ($floodtime - $lastfloodtime <= $c->proxys_cfg[$this->proxyname]["delay"]) + $nbflood++; + else + $nbflood = 0; + + if ($nbflood>$c->proxys_cfg[$this->proxyname]["limit"]) + { + // kick the flooder + $msg = _pfc("you are a flooder"); + $xml_reponse->addScript("alert('".addslashes($msg)."');"); + return; + } + + if ($nbflood == 0) + $container->setMeta($floodtime, "floodtime", "nickname", $nickid); + $container->setMeta($nbflood, "nbflood", "nickname", $nickid); + } + + // forward the command to the next proxy or to the final command + $this->next->run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid); + } +} + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |