Google Safe Browsing batch server, client
PHP Shell
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin-sample
lib
phpunit
schema
COPYING
NOTES.md
README.md
runtests.sh

README.md

This implements a toolkit for implementing the Google Safe Browsing API v2

The lib directory contains the pieces you'll need to assemble to match your enivroment:

lib/GSB_Client.php The client to test if a URL is blacklisted
lib/GSB_Exception.php An empty class to namespace our exceptions
lib/GSB_Logger.php A really simple logger. Ideally you'd subclass to modify for your environment
lib/GSB_Request.php All network (http) calls are here
lib/GSB_Storage.php Every database query is here, wrapper up in a function
lib/GSB_Updater.php Updates the local GSB database
lib/GSB_URL.php URL cannonicalization

bin-sample shows how this might be done. You'll want to rewrite these for match your environment:

bin-sample/intro.php common code for both lookup and updater
bin-sample/lookup.php CLI to test a URL
bin-sample/update.php code to update the local GSB database
bin-sample/cron.sh shows how update might be run periodicially

The URL lookup and the local database update shares common code:

$api = 'YOUR-API-KEY-HERE';
$gsblists = array('goog-malware-shavar', 'googpub-phish-shavar');

// make a PDO object, 2nd line is just good practice
$dbh = new PDO('mysql:host=127.0.0.1;dbname=gsb', 'root');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// create the pieces.  Subclass, over-ride for your environment
$storage = new GSB_StoreDB($dbh);
$network = new GSB_Request($api);
$logger  = new GSB_Logger(5);

To make URL checker:

// make the client with the pieces, and test
$client  = new GSB_Client($storage, $network, $logger);
$client->lookup('A URL');

To make a database updater:

$x = new GSB_Updater($storage, $network, $logger);
$x->downloadData($gsblists, FALSE);
$storage->fullhash_delete_old();