replace ipban page with microcrud
This commit is contained in:
parent
56bb03f01a
commit
a175405210
5 changed files with 153 additions and 82 deletions
|
@ -34,6 +34,7 @@
|
||||||
"google/recaptcha" : "~1.1",
|
"google/recaptcha" : "~1.1",
|
||||||
"dapphp/securimage" : "3.6.*",
|
"dapphp/securimage" : "3.6.*",
|
||||||
"shish/eventtracer-php" : "dev-master",
|
"shish/eventtracer-php" : "dev-master",
|
||||||
|
"shish/microcrud" : "dev-master",
|
||||||
"enshrined/svg-sanitize" : "0.8.*",
|
"enshrined/svg-sanitize" : "0.8.*",
|
||||||
|
|
||||||
"bower-asset/jquery" : "1.12.*",
|
"bower-asset/jquery" : "1.12.*",
|
||||||
|
|
125
composer.lock
generated
125
composer.lock
generated
|
@ -4,14 +4,14 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "771e83de94b5aef4631762f45a430fa8",
|
"content-hash": "1a344925ec0ffdb23fb554973ae897bd",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bower-asset/jquery",
|
"name": "bower-asset/jquery",
|
||||||
"version": "1.12.4",
|
"version": "1.12.4",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/jquery/jquery-dist.git",
|
"url": "git@github.com:jquery/jquery-dist.git",
|
||||||
"reference": "5e89585e0121e72ff47de177c5ef604f3089a53d"
|
"reference": "5e89585e0121e72ff47de177c5ef604f3089a53d"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
|
@ -339,6 +339,100 @@
|
||||||
"description": "An API to write JSON traces as used by the Chrome Trace Viewer",
|
"description": "An API to write JSON traces as used by the Chrome Trace Viewer",
|
||||||
"homepage": "https://github.com/shish/eventtracer-php",
|
"homepage": "https://github.com/shish/eventtracer-php",
|
||||||
"time": "2019-11-21T13:07:27+00:00"
|
"time": "2019-11-21T13:07:27+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "shish/microcrud",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/shish/microcrud.git",
|
||||||
|
"reference": "6e297d376904e34986320896f6a1c83b377a54cc"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/shish/microcrud/zipball/6e297d376904e34986320896f6a1c83b377a54cc",
|
||||||
|
"reference": "6e297d376904e34986320896f6a1c83b377a54cc",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-pdo": "*",
|
||||||
|
"php": ">=7.2",
|
||||||
|
"shish/microhtml": "dev-master"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "8.*"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"MicroCRUD\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Shish",
|
||||||
|
"email": "webmaster@shishnet.org",
|
||||||
|
"homepage": "http://shishnet.org",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A minimal CRUD generating library",
|
||||||
|
"homepage": "https://github.com/shish/microcrud",
|
||||||
|
"keywords": [
|
||||||
|
"crud",
|
||||||
|
"generator"
|
||||||
|
],
|
||||||
|
"time": "2019-11-24T13:37:36+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "shish/microhtml",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/shish/microhtml.git",
|
||||||
|
"reference": "ac1cd313555d81b7b45e162291eed8d0a8165511"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/shish/microhtml/zipball/ac1cd313555d81b7b45e162291eed8d0a8165511",
|
||||||
|
"reference": "ac1cd313555d81b7b45e162291eed8d0a8165511",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.2"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "8.*"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/microhtml.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Shish",
|
||||||
|
"email": "webmaster@shishnet.org",
|
||||||
|
"homepage": "http://shishnet.org",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A minimal HTML generating library",
|
||||||
|
"homepage": "https://github.com/shish/microhtml",
|
||||||
|
"keywords": [
|
||||||
|
"generator",
|
||||||
|
"html"
|
||||||
|
],
|
||||||
|
"time": "2019-11-24T02:10:21+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
@ -1018,12 +1112,12 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "f2eeaa3cdab29a70ba900d5f1c67f841adf028ea"
|
"reference": "cc8ddbe513adf9c360c203bf769fc9700289c5ae"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f2eeaa3cdab29a70ba900d5f1c67f841adf028ea",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/cc8ddbe513adf9c360c203bf769fc9700289c5ae",
|
||||||
"reference": "f2eeaa3cdab29a70ba900d5f1c67f841adf028ea",
|
"reference": "cc8ddbe513adf9c360c203bf769fc9700289c5ae",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1093,7 +1187,7 @@
|
||||||
"testing",
|
"testing",
|
||||||
"xunit"
|
"xunit"
|
||||||
],
|
],
|
||||||
"time": "2019-11-21T09:37:31+00:00"
|
"time": "2019-11-24T09:29:40+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/code-unit-reverse-lookup",
|
"name": "sebastian/code-unit-reverse-lookup",
|
||||||
|
@ -1810,31 +1904,29 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "webmozart/assert",
|
"name": "webmozart/assert",
|
||||||
"version": "1.5.0",
|
"version": "1.6.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/webmozart/assert.git",
|
"url": "https://github.com/webmozart/assert.git",
|
||||||
"reference": "88e6d84706d09a236046d686bbea96f07b3a34f4"
|
"reference": "573381c0a64f155a0d9a23f4b0c797194805b925"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4",
|
"url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925",
|
||||||
"reference": "88e6d84706d09a236046d686bbea96f07b3a34f4",
|
"reference": "573381c0a64f155a0d9a23f4b0c797194805b925",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^5.3.3 || ^7.0",
|
"php": "^5.3.3 || ^7.0",
|
||||||
"symfony/polyfill-ctype": "^1.8"
|
"symfony/polyfill-ctype": "^1.8"
|
||||||
},
|
},
|
||||||
|
"conflict": {
|
||||||
|
"vimeo/psalm": "<3.6.0"
|
||||||
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^4.8.36 || ^7.5.13"
|
"phpunit/phpunit": "^4.8.36 || ^7.5.13"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "1.3-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Webmozart\\Assert\\": "src/"
|
"Webmozart\\Assert\\": "src/"
|
||||||
|
@ -1856,13 +1948,14 @@
|
||||||
"check",
|
"check",
|
||||||
"validate"
|
"validate"
|
||||||
],
|
],
|
||||||
"time": "2019-08-24T08:43:50+00:00"
|
"time": "2019-11-24T13:36:37+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"stability-flags": {
|
"stability-flags": {
|
||||||
"shish/eventtracer-php": 20,
|
"shish/eventtracer-php": 20,
|
||||||
|
"shish/microcrud": 20,
|
||||||
"bower-asset/tablesorter": 20
|
"bower-asset/tablesorter": 20
|
||||||
},
|
},
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
|
|
|
@ -378,6 +378,10 @@ class Database
|
||||||
throw new SCoreException("Can't count tables for database type {$this->engine->name}");
|
throw new SCoreException("Can't count tables for database type {$this->engine->name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function raw_db(): PDO {
|
||||||
|
return $this->db;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockDatabase extends Database
|
class MockDatabase extends Database
|
||||||
|
|
|
@ -1,5 +1,35 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use MicroCRUD\{StringColumn,DateColumn,TextColumn,EnumColumn,Table};
|
||||||
|
|
||||||
|
class IPBanTable extends Table {
|
||||||
|
function __construct(\PDO $db, $token=null) {
|
||||||
|
parent::__construct($db, $token);
|
||||||
|
|
||||||
|
$this->table = "bans";
|
||||||
|
$this->base_query = "
|
||||||
|
SELECT *, users.name AS banner
|
||||||
|
FROM bans JOIN users ON banner_id=users.id
|
||||||
|
";
|
||||||
|
|
||||||
|
$this->size = 10;
|
||||||
|
$this->columns = [
|
||||||
|
new StringColumn("ip", "IP"),
|
||||||
|
new EnumColumn("mode", "Mode", ["Block"=>"block", "Firewall"=>"firewall"]),
|
||||||
|
new TextColumn("reason", "Reason"),
|
||||||
|
new StringColumn("banner", "Banner"),
|
||||||
|
new DateColumn("added", "Added"),
|
||||||
|
new DateColumn("expires", "Expires"),
|
||||||
|
];
|
||||||
|
$this->order_by = ["expires", "id"];
|
||||||
|
$this->flags = [
|
||||||
|
"all" => ["((expires > CURRENT_TIMESTAMP) OR (expires IS NULL))", null],
|
||||||
|
];
|
||||||
|
$this->create_url = "/ip_ban/create";
|
||||||
|
$this->delete_url = "/ip_ban/remove";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class RemoveIPBanEvent extends Event
|
class RemoveIPBanEvent extends Event
|
||||||
{
|
{
|
||||||
public $id;
|
public $id;
|
||||||
|
@ -47,7 +77,7 @@ class IPBan extends Extension
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
if ($event->page_matches("ip_ban")) {
|
if ($event->page_matches("ip_ban")) {
|
||||||
global $page, $user;
|
global $database, $page, $user;
|
||||||
if ($user->can(Permissions::BAN_IP)) {
|
if ($user->can(Permissions::BAN_IP)) {
|
||||||
if ($event->get_arg(0) == "create" && $user->check_auth_token()) {
|
if ($event->get_arg(0) == "create" && $user->check_auth_token()) {
|
||||||
if (isset($_POST['c_ip']) && isset($_POST['c_reason']) && isset($_POST['c_expires'])) {
|
if (isset($_POST['c_ip']) && isset($_POST['c_reason']) && isset($_POST['c_expires'])) {
|
||||||
|
@ -71,9 +101,9 @@ class IPBan extends Extension
|
||||||
$page->set_redirect(make_link("ip_ban/list"));
|
$page->set_redirect(make_link("ip_ban/list"));
|
||||||
}
|
}
|
||||||
} elseif ($event->get_arg(0) == "list") {
|
} elseif ($event->get_arg(0) == "list") {
|
||||||
$pageNum = isset($_GET["r__page"]) ? int_escape($_GET["r__page"]) : 1;
|
$t = new IPBanTable($database->raw_db(), $user->get_auth_token());
|
||||||
$bans = $this->get_bans(isset($_GET["r_all"]), $pageNum);
|
$table = $t->table($t->query());
|
||||||
$this->theme->display_bans($page, $bans);
|
$this->theme->display_bans($page, $table, $t->paginator());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->theme->display_permission_denied();
|
$this->theme->display_permission_denied();
|
||||||
|
|
|
@ -2,73 +2,16 @@
|
||||||
|
|
||||||
class IPBanTheme extends Themelet
|
class IPBanTheme extends Themelet
|
||||||
{
|
{
|
||||||
/*
|
public function display_bans(Page $page, $table, $paginator)
|
||||||
* Show all the bans
|
|
||||||
*
|
|
||||||
* $bans = an array of (
|
|
||||||
* 'ip' => the banned IP
|
|
||||||
* 'reason' => why the IP was banned
|
|
||||||
* 'added' => when the ban started
|
|
||||||
* 'expires' => when the ban will end
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
public function display_bans(Page $page, $bans)
|
|
||||||
{
|
{
|
||||||
global $database, $user;
|
|
||||||
$h_bans = "";
|
|
||||||
$prefix = ($database->get_driver_name() == DatabaseDriver::SQLITE ? "bans." : "");
|
|
||||||
foreach ($bans as $ban) {
|
|
||||||
$h_bans .= "
|
|
||||||
<tr>
|
|
||||||
<td width='12%'>{$ban[$prefix.'ip']}</td>
|
|
||||||
<td>{$ban[$prefix.'reason']}</td>
|
|
||||||
<td width='10%'>{$ban['banner']}</td>
|
|
||||||
<td width='10%'>".substr($ban[$prefix.'added'], 0, 10)."</td>
|
|
||||||
<td width='10%'>".substr($ban[$prefix.'expires'], 0, 10)."</td>
|
|
||||||
<td width='10%'>{$ban['mode']}</td>
|
|
||||||
".make_form(make_link("ip_ban/delete"))."
|
|
||||||
<td width='8%'>
|
|
||||||
<input type='hidden' name='d_id' value='{$ban[$prefix.'id']}'>
|
|
||||||
<input type='submit' value='Remove'>
|
|
||||||
</td>
|
|
||||||
</form>
|
|
||||||
</tr>
|
|
||||||
";
|
|
||||||
}
|
|
||||||
$today = date('Y-m-d');
|
$today = date('Y-m-d');
|
||||||
$html = "
|
$html = "
|
||||||
<a href='".make_link("ip_ban/list", "r__size=1000000")."'>Show All Active</a> /
|
<a href='".make_link("ip_ban/list", "r__size=1000000")."'>Show All Active</a> /
|
||||||
<a href='".make_link("ip_ban/list", "r_all=on&r__size=1000000")."'>Show EVERYTHING</a>
|
<a href='".make_link("ip_ban/list", "r_all=on&r__size=1000000")."'>Show EVERYTHING</a>
|
||||||
<p><table id='bans' class='sortable zebra'>
|
|
||||||
<thead>
|
$table
|
||||||
<tr><th>IP</th><th>Reason</th><th>By</th><th>From</th><th>Until</th><th>Type</th><th>Action</th></tr>
|
|
||||||
<tr>
|
$paginator
|
||||||
".make_form(make_link("ip_ban/list"), "GET")."
|
|
||||||
<td><input type='text' name='r_ip' value='".html_escape(@$_GET['r_ip'])."'></td>
|
|
||||||
<td><input type='text' name='r_reason' value='".html_escape(@$_GET['r_reason'])."'></td>
|
|
||||||
<td><input type='text' name='r_banner' value='".html_escape(@$_GET['r_banner'])."'></td>
|
|
||||||
<td><input type='text' name='r_added' value='".html_escape(@$_GET['r_added'])."'></td>
|
|
||||||
<td><input type='text' name='r_expires' value='".html_escape(@$_GET['r_expires'])."'></td>
|
|
||||||
<td><input type='text' name='r_mode' value='".html_escape(@$_GET['r_mode'])."'></td>
|
|
||||||
<td><input type='submit' value='Search'></td>
|
|
||||||
</form>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
$h_bans
|
|
||||||
<tfoot>
|
|
||||||
<tr id='add'>
|
|
||||||
".make_form(make_link("ip_ban/create"))."
|
|
||||||
<td><input type='text' name='c_ip' value='".html_escape(@$_GET['c_ip'])."'></td>
|
|
||||||
<td><input type='text' name='c_reason' value='".html_escape(@$_GET['c_reason'])."'></td>
|
|
||||||
<td>{$user->name}</td>
|
|
||||||
<td>{$today}</td>
|
|
||||||
<td><input type='text' name='c_expires' value='".html_escape(@$_GET['c_expires'])."'></td>
|
|
||||||
<td>block</td>
|
|
||||||
<td><input type='submit' value='Ban'></td>
|
|
||||||
</form>
|
|
||||||
</tr>
|
|
||||||
</tfoot>
|
|
||||||
</table>
|
|
||||||
";
|
";
|
||||||
$page->set_title("IP Bans");
|
$page->set_title("IP Bans");
|
||||||
$page->set_heading("IP Bans");
|
$page->set_heading("IP Bans");
|
||||||
|
|
Reference in a new issue