anon-ghost mode, and ghosts can't sign up for accounts
This commit is contained in:
parent
26e24c8988
commit
30b85f58db
6 changed files with 92 additions and 72 deletions
8
composer.lock
generated
8
composer.lock
generated
|
@ -388,12 +388,12 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/shish/microcrud.git",
|
"url": "https://github.com/shish/microcrud.git",
|
||||||
"reference": "6471a4c7445e872282f12d1de3730db55d5c06e2"
|
"reference": "7c917baa46f137c5e0f6bd4d9874b1c61014797e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/shish/microcrud/zipball/6471a4c7445e872282f12d1de3730db55d5c06e2",
|
"url": "https://api.github.com/repos/shish/microcrud/zipball/7c917baa46f137c5e0f6bd4d9874b1c61014797e",
|
||||||
"reference": "6471a4c7445e872282f12d1de3730db55d5c06e2",
|
"reference": "7c917baa46f137c5e0f6bd4d9874b1c61014797e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -429,7 +429,7 @@
|
||||||
"crud",
|
"crud",
|
||||||
"generator"
|
"generator"
|
||||||
],
|
],
|
||||||
"time": "2019-11-28T15:53:53+00:00"
|
"time": "2019-11-28T21:02:52+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "shish/microhtml",
|
"name": "shish/microhtml",
|
||||||
|
|
|
@ -13,6 +13,7 @@ abstract class Permissions
|
||||||
public const VIEW_IP = "view_ip"; # view IP addresses associated with things
|
public const VIEW_IP = "view_ip"; # view IP addresses associated with things
|
||||||
public const BAN_IP = "ban_ip";
|
public const BAN_IP = "ban_ip";
|
||||||
|
|
||||||
|
public const CREATE_USER = "create_user";
|
||||||
public const EDIT_USER_NAME = "edit_user_name";
|
public const EDIT_USER_NAME = "edit_user_name";
|
||||||
public const EDIT_USER_PASSWORD = "edit_user_password";
|
public const EDIT_USER_PASSWORD = "edit_user_password";
|
||||||
public const EDIT_USER_INFO = "edit_user_info"; # email address, etc
|
public const EDIT_USER_INFO = "edit_user_info"; # email address, etc
|
||||||
|
|
|
@ -83,6 +83,7 @@ new UserClass("base", null, [
|
||||||
Permissions::VIEW_IP => false, # view IP addresses associated with things
|
Permissions::VIEW_IP => false, # view IP addresses associated with things
|
||||||
Permissions::BAN_IP => false,
|
Permissions::BAN_IP => false,
|
||||||
|
|
||||||
|
Permissions::CREATE_USER => false,
|
||||||
Permissions::EDIT_USER_NAME => false,
|
Permissions::EDIT_USER_NAME => false,
|
||||||
Permissions::EDIT_USER_PASSWORD => false,
|
Permissions::EDIT_USER_PASSWORD => false,
|
||||||
Permissions::EDIT_USER_INFO => false, # email address, etc
|
Permissions::EDIT_USER_INFO => false, # email address, etc
|
||||||
|
@ -163,6 +164,7 @@ new UserClass("ghost", "base", [
|
||||||
// Anonymous users can't do anything by default, but
|
// Anonymous users can't do anything by default, but
|
||||||
// the admin might grant them some permissions
|
// the admin might grant them some permissions
|
||||||
new UserClass("anonymous", "base", [
|
new UserClass("anonymous", "base", [
|
||||||
|
Permissions::CREATE_USER => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
new UserClass("user", "base", [
|
new UserClass("user", "base", [
|
||||||
|
|
|
@ -21,10 +21,16 @@ class IPBanTable extends Table
|
||||||
) AS tbl1
|
) AS tbl1
|
||||||
";
|
";
|
||||||
|
|
||||||
$this->size = 10;
|
$this->size = 100;
|
||||||
|
$this->limit = 1000000;
|
||||||
$this->columns = [
|
$this->columns = [
|
||||||
new InetColumn("ip", "IP"),
|
new InetColumn("ip", "IP"),
|
||||||
new EnumColumn("mode", "Mode", ["Block"=>"block", "Firewall"=>"firewall", "Ghost"=>"ghost"]),
|
new EnumColumn("mode", "Mode", [
|
||||||
|
"Block"=>"block",
|
||||||
|
"Firewall"=>"firewall",
|
||||||
|
"Ghost"=>"ghost",
|
||||||
|
"Anon Ghost"=>"anon-ghost"
|
||||||
|
]),
|
||||||
new TextColumn("reason", "Reason"),
|
new TextColumn("reason", "Reason"),
|
||||||
new StringColumn("banner", "Banner"),
|
new StringColumn("banner", "Banner"),
|
||||||
new DateColumn("added", "Added"),
|
new DateColumn("added", "Added"),
|
||||||
|
@ -37,7 +43,7 @@ class IPBanTable extends Table
|
||||||
$this->create_url = make_link("ip_ban/create");
|
$this->create_url = make_link("ip_ban/create");
|
||||||
$this->delete_url = make_link("ip_ban/delete");
|
$this->delete_url = make_link("ip_ban/delete");
|
||||||
|
|
||||||
$this->table_attrs = ["class" => "sortable zebra"];
|
$this->table_attrs = ["class" => "zebra"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +125,7 @@ class IPBan extends Extension
|
||||||
$active_ban_id = null;
|
$active_ban_id = null;
|
||||||
if (isset($ips[$remote])) {
|
if (isset($ips[$remote])) {
|
||||||
$active_ban_id = $ips[$remote];
|
$active_ban_id = $ips[$remote];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
foreach ($networks as $range => $ban_id) {
|
foreach ($networks as $range => $ban_id) {
|
||||||
if (ip_in_range($remote, $range)) {
|
if (ip_in_range($remote, $range)) {
|
||||||
$active_ban_id = $ban_id;
|
$active_ban_id = $ban_id;
|
||||||
|
@ -129,7 +134,7 @@ class IPBan extends Extension
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an active ban is found, act on it
|
// If an active ban is found, act on it
|
||||||
if(!is_null($active_ban_id)) {
|
if (!is_null($active_ban_id)) {
|
||||||
$row = $database->get_row("SELECT * FROM bans WHERE id=:id", ["id"=>$active_ban_id]);
|
$row = $database->get_row("SELECT * FROM bans WHERE id=:id", ["id"=>$active_ban_id]);
|
||||||
|
|
||||||
$msg = $config->get_string("ipban_message");
|
$msg = $config->get_string("ipban_message");
|
||||||
|
@ -144,11 +149,18 @@ class IPBan extends Extension
|
||||||
$msg = str_replace('$CONTACT', "", $msg);
|
$msg = str_replace('$CONTACT', "", $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($row["mode"] == "ghost") {
|
if ($row["mode"] == "ghost") {
|
||||||
$b = new Block(null, $msg, "main", 0);
|
$b = new Block(null, $msg, "main", 0);
|
||||||
$b->is_content = false;
|
$b->is_content = false;
|
||||||
$page->add_block($b);
|
$page->add_block($b);
|
||||||
$event->user->class = $_shm_user_classes["ghost"];
|
$event->user->class = $_shm_user_classes["ghost"];
|
||||||
|
} elseif ($row["mode"] == "anon-ghost") {
|
||||||
|
if ($event->user->is_anonymous()) {
|
||||||
|
$b = new Block(null, $msg, "main", 0);
|
||||||
|
$b->is_content = false;
|
||||||
|
$page->add_block($b);
|
||||||
|
$event->user->class = $_shm_user_classes["ghost"];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
header("HTTP/1.0 403 Forbidden");
|
header("HTTP/1.0 403 Forbidden");
|
||||||
print "$msg";
|
print "$msg";
|
||||||
|
|
|
@ -397,7 +397,12 @@ class UserPage extends Extension
|
||||||
|
|
||||||
private function page_create()
|
private function page_create()
|
||||||
{
|
{
|
||||||
global $config, $page;
|
global $config, $page, $user;
|
||||||
|
if ($user->can(Permissions::CREATE_USER)) {
|
||||||
|
$this->theme->display_error(403, "Account creation blocked", "Account creation is currently disabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$config->get_bool("login_signup_enabled")) {
|
if (!$config->get_bool("login_signup_enabled")) {
|
||||||
$this->theme->display_signups_disabled($page);
|
$this->theme->display_signups_disabled($page);
|
||||||
} elseif (!isset($_POST['name'])) {
|
} elseif (!isset($_POST['name'])) {
|
||||||
|
|
|
@ -167,7 +167,7 @@ class UserPageTheme extends Themelet
|
||||||
|
|
||||||
public function display_login_block(Page $page)
|
public function display_login_block(Page $page)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config, $user;
|
||||||
$html = '
|
$html = '
|
||||||
'.make_form(make_link("user_admin/login"))."
|
'.make_form(make_link("user_admin/login"))."
|
||||||
<table style='width: 100%;' class='form'>
|
<table style='width: 100%;' class='form'>
|
||||||
|
@ -187,7 +187,7 @@ class UserPageTheme extends Themelet
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
";
|
";
|
||||||
if ($config->get_bool("login_signup_enabled")) {
|
if ($config->get_bool("login_signup_enabled") && $user->can(Permissions::CREATE_USER)) {
|
||||||
$html .= "<small><a href='".make_link("user_admin/create")."'>Create Account</a></small>";
|
$html .= "<small><a href='".make_link("user_admin/create")."'>Create Account</a></small>";
|
||||||
}
|
}
|
||||||
$page->add_block(new Block("Login", $html, "left", 90));
|
$page->add_block(new Block("Login", $html, "left", 90));
|
||||||
|
|
Reference in a new issue