2 rcs_id('$Id: spam_babycart.php,v 1.1 2004-12-04 12:58:26 rurban Exp $');
4 * $Id: spam_babycart.php,v 1.1 2004-12-04 12:58:26 rurban Exp $
5 * Author: Bob Apthorpe <apthorpe+babycart@cynistar.net>
6 * Proof-of-concept PHP fragment to flag blog/wiki spam
8 * URL: <http://www.cynistar.net/~apthorpe/code/babycart/babycart.html>
10 * cpan Blog::SpamAssassin
11 * copy contrib/babycart to /usr/local/bin/
14 function check_babycart(&$text, $ip, $user_id='') {
15 // $X_babycart = '/usr/bin/perl /home/apthorpe/pjx/babycart/babycart';
17 // $X_babycart = 'n:/bin/perl /usr/local/bin/babycart';
18 $X_babycart = '/usr/local/bin/babycart';
20 $comment = "IP: $ip\n";
21 $subject = $GLOBALS['request']->getArg('pagename');
22 $comment .= "SUBJECT: $subject\n";
23 $comment .= "END_COMMENT_METADATA\n";
26 $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
27 $process = proc_open($X_babycart, $descriptorspec, $pipes);
28 if (is_resource($process)) {
29 // $pipes now looks like this:
30 // 0 => writeable handle connected to child stdin
31 // 1 => readable handle connected to child stdout
32 // Any error output will be appended to $pipes[2]
34 // Send comment out for analysis
35 fwrite($pipes[0], $comment);
38 // Get response from stdout (should be one line)
40 while (!feof($pipes[1])) {
41 $response .= fgets($pipes[1], 1024);
45 // Get error from stderr (should be empty)
47 while (!feof($pipes[2])) {
48 $error .= fgets($pipes[2], 1024);
52 // It is important that you close any pipes before calling
53 // proc_close in order to avoid a deadlock
54 $return_value = proc_close($process);
56 // Interpret results and yield judgment
58 // print "Response: $response\n";
59 // split into status, note, score, rules...
61 if (substr($response,0,2) == 'OK')
65 0 - verdict (OK or SUSPICIOUS)
66 1 - note (additional info on verdict, whether tests ran, etc.)
67 2 - numeric score; anything greater than 5-7 is suspect
68 3 - comma-delimited list of rules hit (may be empty)
70 return explode(',', $response, 4);
73 trigger_error("Couldn't process $X_babycart.\n".$error, E_USER_WARNING);
74 return -1; // process error