| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function br2nl($string) { |
|---|
| 4 |
$string = preg_replace("/(\r\n|\n|\r)/", "", $string); |
|---|
| 5 |
$string = preg_replace("/<br *\/?>/i", "\n", $string); |
|---|
| 6 |
return $string; |
|---|
| 7 |
} |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
function makePassword($length=8) |
|---|
| 11 |
{ |
|---|
| 12 |
$password = ""; |
|---|
| 13 |
$vowels = "aeiouy"; |
|---|
| 14 |
$consonants = "bcdfghjklmnprst"; |
|---|
| 15 |
$cn = strlen($consonants)-1; |
|---|
| 16 |
$vn = strlen($vowels)-1; |
|---|
| 17 |
|
|---|
| 18 |
$alt = mt_rand(0, 1); |
|---|
| 19 |
|
|---|
| 20 |
$len = mt_rand($length-3,$length); |
|---|
| 21 |
|
|---|
| 22 |
for ($i = 0; $i < $len; $i++) |
|---|
| 23 |
{ |
|---|
| 24 |
if ($alt == 1) { |
|---|
| 25 |
$password .= $consonants[ mt_rand(0,$cn) ]; |
|---|
| 26 |
$alt = 0; |
|---|
| 27 |
} |
|---|
| 28 |
else { |
|---|
| 29 |
$password .= $vowels[ mt_rand(0,$vn) ]; |
|---|
| 30 |
$alt = 1; |
|---|
| 31 |
} |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
for ($i = 0; $i < $length-$len; $i++) |
|---|
| 35 |
{ |
|---|
| 36 |
$password .= mt_rand(0,9); |
|---|
| 37 |
} |
|---|
| 38 |
return $password; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
$revision = "0"; |
|---|
| 42 |
function startElement($parser, $name, $attrs) |
|---|
| 43 |
{ |
|---|
| 44 |
global $revision; |
|---|
| 45 |
if ($attrs['REVISION']>$revision) $revision = $attrs['REVISION']; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
function endElement($parser, $name){} |
|---|
| 49 |
|
|---|
| 50 |
function getSVNRevision() |
|---|
| 51 |
{ |
|---|
| 52 |
global $revision; |
|---|
| 53 |
$xml_parser = xml_parser_create(); |
|---|
| 54 |
xml_set_element_handler($xml_parser, "startElement", "endElement"); |
|---|
| 55 |
$entriesfile = ".svn/entries"; |
|---|
| 56 |
if (is_link($_SERVER['SCRIPT_FILENAME'])) { |
|---|
| 57 |
$entriesfile = dirname(readlink($_SERVER['SCRIPT_FILENAME']))."/".$entriesfile; |
|---|
| 58 |
} |
|---|
| 59 |
if (!($fp = fopen($entriesfile, "r"))) { |
|---|
| 60 |
return "unknown - couldn't open SVN XML file."; |
|---|
| 61 |
} |
|---|
| 62 |
while(($data = fread($fp, 1024))) { |
|---|
| 63 |
if (!xml_parse($xml_parser, $data, feof($fp))) { |
|---|
| 64 |
return "unknown - couldn't parse SVN XML file"; |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
xml_parser_free($xml_parser); |
|---|
| 68 |
if ($revision=="0") return "unknown"; |
|---|
| 69 |
else return $revision; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
function checkSpamURLs($text) { |
|---|
| 79 |
$spam = false; |
|---|
| 80 |
|
|---|
| 81 |
while (ereg("http://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}",$text,$match)) { |
|---|
| 82 |
$matches[] = $match[0]; |
|---|
| 83 |
$text = ereg_replace($match[0],"",$text); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
$twoLevelTLD = file("/var/www/blog/two-level-tlds"); |
|---|
| 87 |
foreach($twoLevelTLD as $TLD) { |
|---|
| 88 |
$two_level_tlds[trim($TLD)] = true; |
|---|
| 89 |
} |
|---|
| 90 |
if (!$matches) |
|---|
| 91 |
return; |
|---|
| 92 |
|
|---|
| 93 |
foreach ($matches as $url) { |
|---|
| 94 |
|
|---|
| 95 |
$urlBits = explode(".",substr($url, 7)); |
|---|
| 96 |
|
|---|
| 97 |
$bitsURL = array_reverse($urlBits); |
|---|
| 98 |
|
|---|
| 99 |
if ($two_level_tlds[($bitsURL[1].".".$bitsURL[0])]) { |
|---|
| 100 |
$URLstoTest[] = ($bitsURL[2].".".$bitsURL[1].".".$bitsURL[0]); |
|---|
| 101 |
} else { |
|---|
| 102 |
$URLstoTest[] = ($bitsURL[1].".".$bitsURL[0]); |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
if (!$URLstoTest) |
|---|
| 106 |
return; |
|---|
| 107 |
|
|---|
| 108 |
foreach($URLstoTest as $url) { |
|---|
| 109 |
$result = gethostbyname($url.'.multi.surbl.org'); |
|---|
| 110 |
if ($result != $url.'.multi.surbl.org') { |
|---|
| 111 |
$spam = true; |
|---|
| 112 |
} |
|---|
| 113 |
elseif ($url == "blogspot.com") { |
|---|
| 114 |
$spam = true; |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
return $spam; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
function checkSpamLinkSleeve ($text) { |
|---|
| 121 |
|
|---|
| 122 |
require_once 'XML/RPC.php'; |
|---|
| 123 |
|
|---|
| 124 |
$params = array(new XML_RPC_Value($text, 'string')); |
|---|
| 125 |
$msg = new XML_RPC_Message('slv', $params); |
|---|
| 126 |
|
|---|
| 127 |
$cli = new XML_RPC_Client('/slv.php', 'http://www.linksleeve.org'); |
|---|
| 128 |
$resp = $cli->send($msg); |
|---|
| 129 |
|
|---|
| 130 |
if (!$resp) { |
|---|
| 131 |
echo 'Communication error: ' . $cli->errstr; |
|---|
| 132 |
return false; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
if (!$resp->faultCode()) { |
|---|
| 136 |
$val = $resp->value(); |
|---|
| 137 |
if($val->scalarval()=='1') { |
|---|
| 138 |
$spam = false; |
|---|
| 139 |
} |
|---|
| 140 |
else { |
|---|
| 141 |
$spam = true; |
|---|
| 142 |
} |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
else { |
|---|
| 146 |
echo 'Fault Code: ' . $resp->faultCode() . "\n"; |
|---|
| 147 |
echo 'Fault Reason: ' . $resp->faultString() . "\n"; |
|---|
| 148 |
} |
|---|
| 149 |
return $spam; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
function checkSpamIP($ip) { |
|---|
| 154 |
$spam = false; |
|---|
| 155 |
|
|---|
| 156 |
$ip = implode('.',array_reverse(explode('.',$ip))); |
|---|
| 157 |
|
|---|
| 158 |
$rbl = gethostbyname($ip.'.rbl-plus.mail-abuse.ja.net'); |
|---|
| 159 |
$scbl = gethostbynamel($ip.'.bl.spamcop.net'); |
|---|
| 160 |
$sorbs = gethostbynamel($ip.'.dnsbl.sorbs.net'); |
|---|
| 161 |
$sbl = gethostbynamel($ip.'.sbl.spamhaus.org'); |
|---|
| 162 |
$njabl = gethostbynamel($ip.'.dnsbl.njabl.org'); |
|---|
| 163 |
$opm = gethostbyname($ip.'.opm.blitzed.org'); |
|---|
| 164 |
$cbl = gethostbynamel($ip.'.cbl.abuseat.org'); |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
if ($cbl) { |
|---|
| 168 |
$spam = true; |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
if ($opm != $ip.".opm.blitzed.org") { |
|---|
| 173 |
|
|---|
| 174 |
$code = decbin(ip2long($opm)); |
|---|
| 175 |
|
|---|
| 176 |
if ($code[30]) |
|---|
| 177 |
$spam = true; |
|---|
| 178 |
|
|---|
| 179 |
if ($code[29]) |
|---|
| 180 |
$spam = true; |
|---|
| 181 |
|
|---|
| 182 |
if ($code[28]) |
|---|
| 183 |
$spam = true; |
|---|
| 184 |
|
|---|
| 185 |
if ($code[27]) |
|---|
| 186 |
$spam = true; |
|---|
| 187 |
|
|---|
| 188 |
if ($code[26]) |
|---|
| 189 |
$spam = true; |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
if ($rbl != $ip.".rbl-plus.mail-abuse.ja.net") { |
|---|
| 194 |
$code = decbin(ip2long($rbl)); |
|---|
| 195 |
|
|---|
| 196 |
if ($code[30]) |
|---|
| 197 |
$spam = true; |
|---|
| 198 |
|
|---|
| 199 |
if ($code[29]) |
|---|
| 200 |
|
|---|
| 201 |
//check for rss |
|---|
| 202 |
if ($code[28]) |
|---|
| 203 |
$spam = true; |
|---|
| 204 |
|
|---|
| 205 |
if ($code[27]) |
|---|
| 206 |
$spam = true; |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
if ($scbl) { |
|---|
| 211 |
$spam = true; |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
if ($sorbs) { |
|---|
| 216 |
foreach($sorbs as $result) { |
|---|
| 217 |
$result = explode('.',$result); |
|---|
| 218 |
|
|---|
| 219 |
if ($result[3] == 2) |
|---|
| 220 |
$spam = true; |
|---|
| 221 |
|
|---|
| 222 |
if ($result[3] == 3) |
|---|
| 223 |
$spam = true; |
|---|
| 224 |
|
|---|
| 225 |
if ($result[3] == 4) |
|---|
| 226 |
$spam = true; |
|---|
| 227 |
|
|---|
| 228 |
if ($result[3] == 5) |
|---|
| 229 |
$spam = true; |
|---|
| 230 |
|
|---|
| 231 |
if ($result[3] == 6) |
|---|
| 232 |
$spam = true; |
|---|
| 233 |
|
|---|
| 234 |
if ($result[3] == 7) |
|---|
| 235 |
$spam = true; |
|---|
| 236 |
|
|---|
| 237 |
if ($result[3] == 8) |
|---|
| 238 |
$spam = true; |
|---|
| 239 |
|
|---|
| 240 |
if ($result[3] == 9) |
|---|
| 241 |
$spam = true; |
|---|
| 242 |
|
|---|
| 243 |
if ($result[3] == 10) |
|---|
| 244 |
|
|---|
| 245 |
//check for badconf |
|---|
| 246 |
if ($result[3] == 11) |
|---|
| 247 |
$spam = true; |
|---|
| 248 |
|
|---|
| 249 |
if ($result[3] == 12) |
|---|
| 250 |
$spam = true; |
|---|
| 251 |
} |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
if ($njabl) { |
|---|
| 256 |
foreach($njabl as $result) { |
|---|
| 257 |
$result = explode('.',$result); |
|---|
| 258 |
|
|---|
| 259 |
if ($result[3] == 2) |
|---|
| 260 |
$spam = true; |
|---|
| 261 |
|
|---|
| 262 |
if ($result[3] == 3) { |
|---|
| 263 |
|
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
if ($result[3] == 4) |
|---|
| 267 |
$spam = true; |
|---|
| 268 |
|
|---|
| 269 |
if ($result[3] == 5) |
|---|
| 270 |
$spam = true; |
|---|
| 271 |
|
|---|
| 272 |
if ($result[3] == 8) |
|---|
| 273 |
$spam = true; |
|---|
| 274 |
|
|---|
| 275 |
if ($result[3] == 9) |
|---|
| 276 |
$spam = true; |
|---|
| 277 |
} |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
if($sbl) { |
|---|
| 282 |
$spam = true; |
|---|
| 283 |
} |
|---|
| 284 |
return $spam; |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
function checkSpam($ip, $text) { |
|---|
| 289 |
|
|---|
| 290 |
if (checkSpamLinkSleeve($text)) { |
|---|
| 291 |
$spam = true; |
|---|
| 292 |
|
|---|
| 293 |
} elseif (checkSpamURLs($text)) { |
|---|
| 294 |
$spam = true; |
|---|
| 295 |
|
|---|
| 296 |
} elseif (checkSpamIP($ip)) { |
|---|
| 297 |
$spam = true; |
|---|
| 298 |
|
|---|
| 299 |
} else { |
|---|
| 300 |
$spam = false; |
|---|
| 301 |
} |
|---|
| 302 |
return $spam; |
|---|
| 303 |
} |
|---|
| 304 |
|
|---|