Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geoban WIP #902

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"shish/microhtml" : "^2.0",
"shish/gqla" : "dev-main",
"enshrined/svg-sanitize" : "^0.15",
"geoip2/geoip2" : "^2.0",

"bower-asset/jquery" : "^1.12",
"bower-asset/jquery-timeago" : "^1.5",
Expand Down
249 changes: 248 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions ext/geoban/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

use GeoIp2\Database\Reader;

class GeoBan extends Extension
{
/** @var IPBanTheme */
protected $theme;

public function get_priority(): int
{
return 10;
}

public function onUserLogin(UserLoginEvent $event)
{

$t = microtime(true);
$reader = new Reader('data/GeoLite2-Country.mmdb');
$record = $reader->country($_SERVER["REMOTE_ADDR"]);
# print($record->country->isoCode . "\n"); // 'US'
# print($record->country->name . "\n"); // 'United States'
# print(microtime(true) - $t . "\n");

$banned = ["IE"];

if(in_array($record->country->isoCode, $banned)) {
header("HTTP/1.0 403 Forbidden");
print "This country is banned";
exit;
}
}
}