1
|
|
|
<?php |
2
|
|
|
// This file is part of BOINC. |
3
|
|
|
// http://boinc.berkeley.edu |
4
|
|
|
// Copyright (C) 2008 University of California |
5
|
|
|
// |
6
|
|
|
// BOINC is free software; you can redistribute it and/or modify it |
7
|
|
|
// under the terms of the GNU Lesser General Public License |
8
|
|
|
// as published by the Free Software Foundation, |
9
|
|
|
// either version 3 of the License, or (at your option) any later version. |
10
|
|
|
// |
11
|
|
|
// BOINC is distributed in the hope that it will be useful, |
12
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
14
|
|
|
// See the GNU Lesser General Public License for more details. |
15
|
|
|
// |
16
|
|
|
// You should have received a copy of the GNU Lesser General Public License |
17
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
function akismet_check($user, $post) { |
20
|
|
|
$master_url = master_url(); |
21
|
|
|
$config = get_config(); |
22
|
|
|
$key = parse_config($config, "<akismet_key>"); |
23
|
|
|
if (!$key) { |
24
|
|
|
return true; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$master_url_enc = urlencode($master_url); |
|
|
|
|
28
|
|
|
$response = akismet_request("key=$key&blog=$master_url_enc", "rest.akismet.com", "/1.1/verify-key"); |
29
|
|
|
if ("valid" == $response[1] ) { |
30
|
|
|
$post = urlencode($post); |
31
|
|
|
$ip = urlencode($_SERVER['REMOTE_ADDR']); |
32
|
|
|
$referrer = urlencode($_SERVER['HTTP_REFERER']); |
33
|
|
|
$author = urlencode($user->name); |
34
|
|
|
$useragent = urlencode($_SERVER['HTTP_USER_AGENT']); |
35
|
|
|
|
36
|
|
|
$request = "blog=$master_url_enc"; |
37
|
|
|
$request .= "&user_ip=$ip"; |
38
|
|
|
$request .= "&user_agent=$useragent"; |
39
|
|
|
$request .= "&referrer=$referrer"; |
40
|
|
|
$request .= "&comment_author=$author"; |
41
|
|
|
$request .= "&comment_content=$post"; |
42
|
|
|
|
43
|
|
|
$response = akismet_request($request, "$key.rest.akismet.com", "/1.1/comment-check"); |
44
|
|
|
|
45
|
|
|
if ("true" == $response[1]) { // Akismet says it's spam |
46
|
|
|
return false; |
47
|
|
|
} else { |
48
|
|
|
return true; |
49
|
|
|
} |
50
|
|
|
} else { |
51
|
|
|
return true; // invalid key |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function akismet_request($request, $host, $path, $port = 80) { |
56
|
|
|
$http_request = "POST $path HTTP/1.0\r\n"; |
57
|
|
|
$http_request .= "Host: $host\r\n"; |
58
|
|
|
$http_request .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"; |
59
|
|
|
$http_request .= "Content-Length: " . strlen($request) . "\r\n"; |
60
|
|
|
$http_request .= "User-Agent: BOINC | Akismet 1.1\r\n"; |
61
|
|
|
$http_request .= "\r\n"; |
62
|
|
|
$http_request .= $request; |
63
|
|
|
|
64
|
|
|
$response = ''; |
65
|
|
|
if( false !== ( $fs = @fsockopen($host, $port, $errno, $errstr, 3) ) ) { |
66
|
|
|
fwrite($fs, $http_request); |
67
|
|
|
while ( !feof($fs) ) |
68
|
|
|
$response .= fgets($fs, 1160); // One TCP-IP packet |
69
|
|
|
fclose($fs); |
70
|
|
|
$response = explode("\r\n\r\n", $response, 2); |
71
|
|
|
} |
72
|
|
|
return $response; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
?> |
76
|
|
|
|