function post_index() { $base = $this->getSblamBase(); $config = Server::getDefaultConfig(); $config['throttle']['enabled'] = '0'; // FIXME: this should be handled within plugins $config['linksleeve']['enabled'] = '0'; $config['dupes']['enabled'] = '0'; $sblam = new Sblam($config, $this->services); $num = !empty($_POST['num']) ? intval($_POST['num']) : 100; foreach ($this->services->getDB()->query("SELECT id FROM posts_meta WHERE spamscore IS NULL and spamcert IS NULL ORDER BY rand() LIMIT\n{$num}")->fetchAll(PDO::FETCH_ASSOC) as $r) { $score = $sblam->testPost($base->getPostById($r['id'])); $this->services->getDB()->prepareExecute("UPDATE posts_meta SET spamscore=?,spamcert=? WHERE id=?", array(round($score[0] * 100), round($score[1] * 100), $r['id'])); $this->services->getDB()->prepareExecute("UPDATE posts_data SET spamreason=? WHERE id=?", array($score[2], $r['id'])); } }
public static function init() { // retrieving API key self::$apiKey = Config::get('wmelon.sblam.apiKey'); // display notice if admin and no API key set if (Watermelon::$appType == Watermelon::Admin && (Watermelon::$segments == array() || Watermelon::$segments == array('blog')) && empty(self::$apiKey)) { Watermelon::displayNotice('Filtr antyspamowy nie będzie działał poprawnie dopóki nie zostanie <a href="$/options/#sblamOptions">skonfigurowany</a>'); } }
function getCheckIPResults() { $out = array(); foreach ($this->ips as $ip => $ipinfo) { list($reason, $scorefactor) = $ipinfo; $res = SblamURI::gethostbynamel($this->reverse($ip)); if ($res) { foreach ($res as $resip) { $tmp = $this->score($ip, $resip, $reason, $scorefactor); if ($tmp) { $out[] = $tmp; } } } } if (!count($out)) { return NULL; } $res = Sblam::sumResults($out); if ($res[0] > 1) { $res[0] = 1; } if ($res[1] > self::CERTAINITY_HIGH) { $res[1] = self::CERTAINITY_HIGH; } return $res; }
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]) : ''); }
public static function postComment($id, $type, $backPage) { if (empty($id) || empty($type) || empty($backPage)) { Watermelon::displayNoPageFoundError(); return; } if (!in_array($type, array('blogpost', 'page'))) { Watermelon::displayNoPageFoundError(); return; } //-- $model = new Comments_Model(); $backPage = base64_decode($backPage); $form = Form::validate('wmelon.comments.addComment', $backPage)->get(); // testing for spam and adding if (!Users::isLogged()) { // testing for spam $commentStatus = Sblam::test('content', 'name', 'email', 'website'); // remembering user's data $_SESSION['wmelon.comments.name'] = $form->name; $_SESSION['wmelon.comments.email'] = $form->email; $_SESSION['wmelon.comments.website'] = $form->website; // assigning "visibility token" (token user needs to have in session to see his own comments, even if not approved) if (isset($_SESSION['wmelon.comments.visibilityToken'])) { $visibilityToken = $_SESSION['wmelon.comments.visibilityToken']; } else { $visibilityToken = $form->name . $form->email . mt_rand(); $visibilityToken = md5($visibilityToken); $visibilityToken = substr($visibilityToken, 16); $_SESSION['wmelon.comments.visibilityToken'] = $visibilityToken; } // adding comment switch ($commentStatus) { case 0: case 1: case -1: $model->postComment($id, $type, $form->name, $form->email, $form->website, $form->content, false, $visibilityToken); Watermelon::displayNotice('Twój komentarz zostanie sprawdzony zanim zostanie publicznie pokazany'); break; case -2: $commentID = $model->postComment($id, $type, $form->name, $form->email, $form->website, $form->content, true, $visibilityToken); Watermelon::displaySuccessNotice('Dodano komentarz'); $backPage .= '#comment-' . $commentID; break; case 2: Watermelon::displayError('Filtr uznał twój komentarz za spam. ' . Sblam::reportLink()); break; } } else { $commentID = $model->postComment_logged($id, $type, $form->content); $backPage .= '#comment-' . $commentID; } SiteRedirect($backPage); }