Exemplo n.º 1
0
 function process(ServerRequest $req)
 {
     $starttime = microtime(true);
     $data = $req->getData();
     if ($data['ip'] == '127.0.0.1' && $req->isDefaultAccount()) {
         throw new ServerException('Brak klucza API', 403);
     }
     $fs = isset($data['fields']) ? explode("\n", strtolower($data['fields'])) : array();
     $postdata = array();
     foreach ($data as $key => $val) {
         if (substr($key, 0, 5) === 'POST_') {
             $postdata[strtolower(substr($key, 5))] = $val;
         }
         if (substr($key, 0, 6) === 'field_') {
             $fs[substr($key, 6)] = $val;
         }
     }
     list($content, $author, $email, $url) = $this->findFields($postdata, $fs);
     /* short-circuit filtering for testing */
     if (preg_match('!^[^a-z]*to\\s+jest\\s+test\\s+(sblam|spam)[ua]?[^a-z]*$!i', $content)) {
         $req->returnResult(1);
         return;
     }
     $p = $this->postFromFields($data, $postdata, $content, $author, $email, $url, $req->getIPs());
     if (!$req->storeData($p)) {
         dieerr(500, "Awaria bazy danych");
     }
     $config = $req->customizeConfig($this->config);
     $sblam = new Sblam($config, $this->services);
     $rawresult = $sblam->testPost($p);
     list($score, $cert, $reason) = $rawresult;
     $endtime = microtime(true);
     if ($content == '' && $author == '') {
         $req->returnResult(1);
     } else {
         if ($cert < 0.45 || abs($score) < 0.38) {
             $req->returnResult($score > 0 ? 1 : -1);
         } else {
             $req->returnResult($score > 0 ? 2 : -2);
         }
     }
     set_time_limit(25);
     $rawresult = $sblam->reportResult($p, $rawresult);
     $req->storeResult($score, $cert, $reason, $endtime - $starttime, empty($p->bayesadded) ? 0 : 6, isset($rawresult[3]) ? Sblam::formatProfiling($rawresult[3]) : '');
 }