Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ $ composer require samcleaver/phpgsb
3. Look at listupdater.php and lookup.php example files for basic methods on using the system.
4. If you choose to use listupdater.php as-is then set it as a cron job/scheduled task to run every minute. *(It won't actually update every minute but is required incase of backoff procedures and timeouts)*

5. Optional: set up a simple REST service based on lookup.fastcgi.php, FastCGI and a web server. E.g., configure an Nginx/FastCGI combo to point at the phpGSB directory, and see usage URL examples inside lookup.fastcgi.php. Works relatively well, tested on 100s of lookups/second.

## FAQ

* **When I do a lookup, phpGSB says the URL is safe but I know it's not.**
Expand Down
53 changes: 53 additions & 0 deletions lookup.fastcgi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
phpGSB - PHP Google Safe Browsing Implementation
Released under New BSD License (see LICENSE)
Copyright (c) 2010-2012, Sam Cleaver (Beaver6813, Beaver6813.com)
All rights reserved.

LOOKUP EXAMPLES - via Nginx Fastcgi on localhost:
//Should return false (not phishing or malware)
http://localhost/phpGSB/lookup.fastcgi.php?domain=http://www.google.com
{"status":"success","data":{}}

//Should return true, malicious URL
http://localhost/phpGSB/lookup.fastcgi.php?domain=http://www.gumblar.cn
{"status":"success","data":{"list_name":"gsb"}}

Feel free to throw in some more details into the output JSON!

*/
require("phpgsb.class.php");
$phpgsb = new phpGSB("DATABASE_NAME","DATABASE_USERNAME","DATABASE_PASSWORD");
//Obtain an API key from: http://code.google.com/apis/safebrowsing/key_signup.html
$phpgsb->apikey = "API_KEY_HERE";
$phpgsb->usinglists = array('googpub-phish-shavar','goog-malware-shavar');
$url = $_GET["domain"];

if ( $parts = parse_url($url) ) {
if ( !isset($parts["scheme"]) )
{
$url = "http://$url";
}
}

$result['status'] = "fail";
$result['data'] = (object) null;
if ($url === null || $url === "" || !filter_var($url, FILTER_VALIDATE_URL)) {
http_response_code(400);
print json_encode($result);
return;
}

$checkres = $phpgsb->doLookup($url);
if ($checkres === true) {
$result['status'] ="success";
$list["list_name"] = "gsb";
$result['data'] = $list;
} else if ($checkres === false) {
$result['status'] ="success";
$result['data'] = (object) null;
}
print json_encode($result);
$phpgsb->close();
?>