在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):antonioribeiro/firewall开源软件地址(OpenSource Url):https://github.com/antonioribeiro/firewall开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Firewall 2.2PurposeThis a "soft-firewall" package. Its purpose is to help people prevent unauthorized access to routes by IP address. It is able to keep track of IPs, countries and hosts (dynamic ip), and redirect non-authorized users to, for instance, a "Coming Soon" page, while letting whitelisted IPs to have access to the entire site. It is now also able to detect and block attacks (too many requests) from single IPs or whole countries. This package can prevent some headaches and help you block some access to your apps, but cannot replace firewalls and appliances, for attacks at the network level, you'll still need a real firewall. Features
ConceptsBlacklistAll IP addresses in those lists will no be able to access routes filtered by the blacklist filter. WhitelistThose IP addresses, ranges or countries can
Attack DetectionFirewall is able to detect simple attacks to your page, by counting requests from the same IP or country. Just enable it on your 'slack' => [
'webhook_url' => env('SLACK_WEBHOOK_URL'),
], and add the route notification method to your user model: /**
* Route notifications for the Slack channel.
*
* @return string
*/
public function routeNotificationForSlack()
{
return config('services.slack.webhook_url');
} IPs listsIPs (white and black) lists can be stored in array, files and database. Initially database access to lists is disabled, so, to test your Firewall configuration you can publish the config file and edit the 'blacklist' => array(
'127.0.0.1',
'192.168.17.0/24'
'127.0.0.1/255.255.255.255'
'10.0.0.1-10.0.0.255'
'172.17.*.*'
'country:br'
'/usr/bin/firewall/blacklisted.txt',
), The file (for instance
Redirecting non-whitelisted IP addressesNon-whitelisted IP addresses can be blocked or redirected. To configure redirection you'll have to publish the 'redirect_non_whitelisted_to' => 'coming/soon', Artisan CommandsYou have access to the following commands: Global
When database is enabled
Those are results from
FacadeYou can also use the $whitelisted = Firewall::isWhitelisted('10.17.12.1');
$blacklisted = Firewall::isBlacklisted('10.0.0.3');
Firewall::whitelist('192.168.1.1');
Firewall::blacklist('10.17.12.1', true); /// true = force in case IP is whitelisted
Firewall::blacklist('127.0.0.0-127.0.0.255');
Firewall::blacklist('200.212.331.0/28');
Firewall::blacklist('country:br');
if (Firewall::whichList($ip) !== false) // returns false, 'whitelist' or 'blacklist'
{
Firewall::remove($ip);
} Return a blocking access response: return Firewall::blockAccess(); Suspicious events will be (if you wish) logged, so
Blocking Whole CountriesYou can block a country by, instead of an ip address, pass
You will have to add this requirement to your
or
You need to enable country search on your firewall.php config file: 'enable_country_search' => true, And you can schedule this command to update your cities GeoIp database regularly:
You can find those codes here: isocodes Session BlockingYou can block users from accessing some pages only for the current session, by using those methods: Firewall::whitelistOnSession($ip);
Firewall::blacklistOnSession($ip);
Firewall::removeFromSession($ip); Playground & Bootstrap AppClick here to see it working and in case you need a help figuring out things, try this repository. InstallationCompatible with
InstallingRequire the Firewall package using Composer:
PragmaRX\Firewall\Vendor\Laravel\ServiceProvider::class, 'Firewall' => PragmaRX\Firewall\Vendor\Laravel\Facade::class, Add middlewares to your app/Http/Kernel.php protected $routeMiddleware = [
...
'fw-only-whitelisted' => \PragmaRX\Firewall\Middleware\FirewallWhitelist::class,
'fw-block-blacklisted' => \PragmaRX\Firewall\Middleware\FirewallBlacklist::class,
'fw-block-attacks' => \PragmaRX\Firewall\Middleware\BlockAttacks::class,
]; or protected $middlewareGroups = [
'web' => [
...
],
'api' => [
...
],
'firewall' => [
\PragmaRX\Firewall\Middleware\FirewallBlacklist::class,
\PragmaRX\Firewall\Middleware\BlockAttacks::class,
],
]; Then you can use them in your routes: Route::group(['middleware' => 'fw-block-blacklisted'], function ()
{
Route::get('/', 'HomeController@index');
}); Or you could use both. In the following example the allow group will give free access to the 'coming soon' page and block or just redirect non-whitelisted IP addresses to another, while still blocking access to the blacklisted ones. Route::group(['middleware' => 'fw-block-blacklisted'], function ()
{
Route::get('coming/soon', function()
{
return "We are about to launch, please come back in a few days.";
});
Route::group(['middleware' => 'fw-only-whitelisted'], function ()
{
Route::get('/', 'HomeController@index');
});
}); Note: You can add other middleware you have already created to the new groups by simply
adding it to the Migrate your database
Warning: If you already have a Firewall package installed and migrated, you need to update your migration name, in the To publish the configuration file you'll have to: Laravel 4
Laravel 5
TODO
AuthorLicenseFirewall is licensed under the BSD 3-Clause License - see the ContributingPull requests and issues are more than welcome. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论