2007-04-19 18:22:38 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC 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 BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-04-19 18:22:38 +00:00
|
|
|
|
|
|
|
function akismet_check($user, $post) {
|
|
|
|
$config = get_config();
|
2007-04-24 16:04:04 +00:00
|
|
|
$key = parse_config($config, "<akismet_key>");
|
2008-07-04 20:06:31 +00:00
|
|
|
if (!$key) {
|
|
|
|
return true;
|
2007-04-19 18:22:38 +00:00
|
|
|
}
|
2008-07-04 20:06:31 +00:00
|
|
|
|
|
|
|
$master_url = parse_config($config, "<master_url>");
|
2007-04-19 18:22:38 +00:00
|
|
|
$master_url = urlencode($master_url);
|
|
|
|
$response = akismet_request("key=$key&blog=$master_url", "rest.akismet.com", "/1.1/verify-key");
|
|
|
|
if ("valid" == $response[1] ) {
|
|
|
|
$post = urlencode($post);
|
|
|
|
$ip = urlencode($_SERVER['REMOTE_ADDR']);
|
|
|
|
$referrer = urlencode($_SERVER['HTTP_REFERER']);
|
2007-11-12 22:28:17 +00:00
|
|
|
$author = urlencode($user->name);
|
2007-04-19 18:22:38 +00:00
|
|
|
$useragent = urlencode($_SERVER['HTTP_USER_AGENT']);
|
|
|
|
|
|
|
|
$request = "blog=$master_url";
|
|
|
|
$request .= "&user_ip=$ip";
|
|
|
|
$request .= "&user_agent=$useragent";
|
|
|
|
$request .= "&referrer=$referrer";
|
|
|
|
$request .= "&comment_author=$author";
|
|
|
|
$request .= "&comment_content=$post";
|
|
|
|
|
|
|
|
$response = akismet_request($request, "$key.rest.akismet.com", "/1.1/comment-check");
|
|
|
|
|
|
|
|
if ("true" == $response[1]) { // Akismet says it's spam
|
2008-10-09 18:28:55 +00:00
|
|
|
return false;
|
2007-04-19 18:22:38 +00:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return true; // invalid key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function akismet_request($request, $host, $path, $port = 80) {
|
|
|
|
$http_request = "POST $path HTTP/1.0\r\n";
|
|
|
|
$http_request .= "Host: $host\r\n";
|
|
|
|
$http_request .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
|
|
|
|
$http_request .= "Content-Length: " . strlen($request) . "\r\n";
|
|
|
|
$http_request .= "User-Agent: BOINC | Akismet 1.1\r\n";
|
|
|
|
$http_request .= "\r\n";
|
|
|
|
$http_request .= $request;
|
|
|
|
|
|
|
|
$response = '';
|
|
|
|
if( false !== ( $fs = @fsockopen($host, $port, $errno, $errstr, 3) ) ) {
|
|
|
|
fwrite($fs, $http_request);
|
|
|
|
while ( !feof($fs) )
|
|
|
|
$response .= fgets($fs, 1160); // One TCP-IP packet
|
|
|
|
fclose($fs);
|
|
|
|
$response = explode("\r\n\r\n", $response, 2);
|
|
|
|
}
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2007-11-12 22:28:17 +00:00
|
|
|
?>
|