#!/usr/bin/php
<?php
include "settings.php";
include "mysql.class.php";
$database = new MySqlDatabase(MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD,
MYSQL_HOST, MYSQL_ERROR_LOG);
function hex2bin($str) {
$bin = "";
$i = 0;
do {
$bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
$i += 2;
} while ($i < strlen($str));
return $bin;
}
$url = "http://sb.google.com/safebrowsing/update?version=";
$database->sql("SELECT `name`,`version` FROM `google_safe_api`");
$data = array();
while($row = $database->get_row()){
$data[] = "{$row['name']}:1:{$row['version']}";
}
$url .= implode(',', $data);
$handle = @fopen($url, "r");
if ($handle) {
while (!feof($handle)) {
$row = substr(fgets($handle, 4096), 0, -1); // remove newline
if(preg_match('`\[([a-z-]+) \d+.(\d+) update\]`',$row,$match)) {
$type = $match[1];
$database->sql("UPDATE `google_safe_api` SET `version` = '{$match[2]}' WHERE `name` = '{$match[1]}'");
} else if(preg_match('`\[([a-z-]+) \d+.(\d+)\]`',$row,$match)) {
$type = $match[1];
$database->sql("DELETE FROM `hashes` WHERE `type` = '{$match[1]}'");
$database->sql("UPDATE `google_safe_api` SET `version` = '{$match[2]}' WHERE `name` = '$type'");
} else if(preg_match('`\+(\S+)`',$row,$match)) {
$value = $database->excape(hex2bin($match[1]));
$database->sql("INSERT INTO `hashes` (`hash`,`type`) VALUES ('$value', '$type')");
} else if(preg_match('`-([\S]+)`',$row,$match)) {
$value = $database->excape(hex2bin($match[1]));
$database->sql("DELETE FROM `hashes` WHERE `hash` = '$value'");
}
}
fclose($handle);
}
?>
Update Complete.