web2all/safebrowsingv4
Composer 安装命令:
composer require web2all/safebrowsingv4
包简介
Google safebrowsing client in PHP using the update API
关键字:
README 文档
README
This is a google safebrowsing client (update API V4) written in PHP. For information see the google documentation https://developers.google.com/safe-browsing/v4/update-api.
In short the update API keeps track of a local database of hashcodes which is updated using the update API v4 protocol. Any urls will be checked against the local database. When possible matches are found, more hashes will be retrieved from the google service.
URLs which are checked are NEVER sent to google, only a hash will be submitted to google. This is the big advantage compared to the Lookup API v4. An additional advantage is less network traffic as initial checks are done against a local database of hash prefixes and the bulk of the checks does not require a roundtrip to the google service.
Disadvantage of the Update service compared to the Lookup service is that a local cache/data storage is required and the client must update it periodically. So the client must run as a daemon (or scheduled) to keep the local database up-to-date.
The web2all/safebrowsingv4 is no longer actively maintained.
What is in this package
This package contains the google safebrowsing Update API V4 protocol implementation. But it only includes a reference implementation for the local storage (for storing the hash prefix database).
This reference implementation is file-based and just an example, it is not suited for production use.
For an example of a mysql storage backend implementation of this safebrowsing client, see the web2all/safebrowsingv4-sqlstorage package.
Usage
Install using composer (eg. composer create-project web2all/safebrowsingv4).
Go to google and request a new API key, see https://developers.google.com/safe-browsing/v4/get-started.
For tests run:
vendor/bin/phpunit tests
To test the safebrowsing client using the example file storage backend create a sample php script:
ini_set ( "memory_limit", "712M");
require_once('vendor/autoload.php');
$storage = new GoogleSafeBrowsing_Example_FileStorage('/writeable/dir/storage/');
$updater = new GoogleSafeBrowsing_Updater('YOUR-GOOGLE-KEY', $storage);
$current_lists=$updater->getLists();
$changed=false;
$ensure_lists='MALWARE/ANY_PLATFORM/URL,SOCIAL_ENGINEERING/ANY_PLATFORM/URL,UNWANTED_SOFTWARE/ANY_PLATFORM/URL,POTENTIALLY_HARMFUL_APPLICATION/ANDROID/URL,POTENTIALLY_HARMFUL_APPLICATION/IOS/URL';
foreach(explode(',',$ensure_lists) as $list){
if(!isset($current_lists[$list])){
$current_lists[$list]='';
echo "add list $list\n";
$changed=true;
}
}
if($changed){
$updater->setLists($current_lists);
}
$updater->run();
the above script will create a local hash prefix database in '/writeable/dir/storage/' and will keep it uptodate. You would want to run such a script in the background. The initial run will need to download all prefixes. It is also pretty memory hungry, an initial run, or when all lists are reset could require 600Mb.
Once above script runs, you can do lookups like this:
require_once('vendor/autoload.php');
$storage = new GoogleSafeBrowsing_Example_FileStorage('/writeable/dir/storage/');
$api=new GoogleSafeBrowsing_API('YOUR-GOOGLE-KEY');
$lookup=new GoogleSafeBrowsing_Lookup($api, $storage);
if(isset($argv[1])){
$url=$argv[1];
}else{
die('no url given');
}
echo "Looking up: $url\n";
$lists=$lookup->lookup($url);
if(!$lists){
echo "NOT LISTED\n";
}else{
echo implode(',',$lists)."\n";
}
Warning
Do not use the included FileStorage example storage backend in production! It is not efficeient, its just an implementation example. If you must, use web2all/safebrowsingv4-sqlstorage which can be used with mysql. Or implement you own storage backend by implementing the GoogleSafeBrowsing_Lookup_IStorage and GoogleSafeBrowsing_Updater_IStorage interfaces.
See also
web2all/safebrowsingv4-sqlstoragehttps://github.com/web2all/safebrowsingv4-sqlstorage for a SQL based storage implementation.
License
Web2All safebrowsingv4 is open-sourced software licensed under the MIT license (https://opensource.org/licenses/MIT).
web2all/safebrowsingv4 适用场景与选型建议
web2all/safebrowsingv4 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.64k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2017 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google」 「safebrowsing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 web2all/safebrowsingv4 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 web2all/safebrowsingv4 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 web2all/safebrowsingv4 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel package to allow you to easily integrate the Google Safebrowing API into your application.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Google Recaptcha Package For PHP front and backend.
Google safebrowsing SQL storage implementation
Yandex SafeBrowsing API simple implementation
统计信息
- 总下载量: 3.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 31
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-21