コード例 #1
0
ファイル: WAFPHP.php プロジェクト: sdgdsffdsfff/WAFPHP
 public function quit($checkResult = false)
 {
     $this->Log->debug(__METHOD__, sprintf('system running use time %fs,RAM %s', Common::click(), Common::convertUnit(Common::RAMClick())));
     $resultMsg = $this->resultMsg;
     if (self::$init !== null && self::$quit === null) {
         self::$quit = true;
         spl_autoload_unregister(array($this, 'autoLoad'));
         // 开启debug时将系统debug信息写入log
         if (Common::getConfig('debug_level', $this->config)) {
             $this->Log->writeLog();
         }
         // 清理Model所占资源
         if (is_object($this->Model)) {
             $this->Model->quit();
         }
         // 注销register_shutdown_function,避免影响其他程序
         $this->registerShutdown->unRegister();
     }
 }
コード例 #2
0
ファイル: Robot.class.php プロジェクト: ZoaChou/WAFPHP
 public function run($config, $client)
 {
     $startTime = Common::click();
     // 脚本开始执行时间
     $startRAM = Common::RAMclick();
     // 脚本结束执行时间
     $this->config = $config;
     $this->client = $client;
     $this->wafPHP = WAFPHP::getInstance();
     // 检测是否存在有效的白名单标识
     if ($this->checkWhiteFlag()) {
         Common::Log()->info(__METHOD__, sprintf('Session[%s] was in white list', $this->client['session']));
         return true;
     }
     // 若关闭ajax类型请求的挑战则当请求为ajax类型时直接返回
     if (Common::getConfig('challenge_ajax', $this->config) && Common::isAjax(Common::getConfig('ajax_flag', $this->config))) {
         // 避免验证码模式的Ajax请求被绕过
         if (!isset($this->client['post'][Challenge\VerifyCodeChallenge::CODE_CHALLENGE_FLAG])) {
             Common::Log()->info(__METHOD__, sprintf('The client was ajax request'));
             return true;
         }
     }
     // 当前IP达到指定开启挑战访问次数前直接返回
     $visitTimes = intval(Common::M()->get($this->client['ip'], self::IP_VISIT_TIMES_FLAG));
     $startChallengeTimes = Common::getConfig('ip_start_challenge_times', $this->config);
     if ($visitTimes < $startChallengeTimes) {
         $visitTimes++;
         Common::M()->set($this->client['ip'], $visitTimes, Common::getConfig('ip_start_challenge_lifetime', $this->config), self::IP_VISIT_TIMES_FLAG);
         Common::Log()->info(__METHOD__, sprintf('The client ip[%s] was overlook', $this->client['ip']));
         return true;
     }
     // 根据配置启用相应挑战模块
     $challengeType = Common::getConfig('challenge_model', $this->config);
     switch ($challengeType) {
         case 'js':
             $this->jsChallenge();
             break;
         case 'code':
             $this->CodeChallenge();
             break;
         case 'code-cn':
             $this->CodeChallenge(true);
             break;
         case 'proof-of-work':
             $this->ProofOfWorkChallenge();
             break;
         default:
             die('Undefined challenge model');
     }
     $startRAM = Common::click();
     // 脚本开始执行内存
     $endRAM = Common::RAMclick();
     // 脚本结束执行内存
     Common::Log()->debug(__METHOD__, sprintf('Running robot detection with type %s use time %fs,RAM %s', $challengeType, $endRAM - $startTime, $endRAM - $startRAM));
     return true;
 }