Browse Source

bans.php: format

pull/116/head
Zankaria 2 months ago
parent
commit
ef936d60a9
  1. 51
      inc/bans.php

51
inc/bans.php

@ -12,12 +12,14 @@ class Bans {
return $ipstr; return $ipstr;
} }
if (strlen($ipstart) != strlen($ipend)) if (strlen($ipstart) != strlen($ipend)) {
return '???'; // What the fuck are you doing, son? return '???'; // What the fuck are you doing, son?
}
$range = CIDR::range_to_cidr(inet_ntop($ipstart), inet_ntop($ipend)); $range = CIDR::range_to_cidr(inet_ntop($ipstart), inet_ntop($ipend));
if ($range !== false) if ($range !== false) {
return $range; return $range;
}
return '???'; return '???';
} }
@ -101,12 +103,12 @@ class Bans {
list($ipstart, $ipend) = self::calc_cidr($mask); list($ipstart, $ipend) = self::calc_cidr($mask);
} elseif (preg_match('@^[:a-z\d]+/\d+$@i', $mask)) { } elseif (preg_match('@^[:a-z\d]+/\d+$@i', $mask)) {
list($ipv6, $bits) = explode('/', $mask); list($ipv6, $bits) = explode('/', $mask);
if ($bits > 128) if ($bits > 128) {
return false; return false;
}
list($ipstart, $ipend) = self::calc_cidr($mask); list($ipstart, $ipend) = self::calc_cidr($mask);
} else { } elseif (($ipstart = @inet_pton($mask)) === false) {
if (($ipstart = @inet_pton($mask)) === false)
return false; return false;
} }
@ -135,8 +137,9 @@ class Bans {
if ($ban['expires'] && ($ban['seen'] || !$config['require_ban_view']) && $ban['expires'] < time()) { if ($ban['expires'] && ($ban['seen'] || !$config['require_ban_view']) && $ban['expires'] < time()) {
self::delete($ban['id']); self::delete($ban['id']);
} else { } else {
if ($ban['post']) if ($ban['post']) {
$ban['post'] = json_decode($ban['post'], true); $ban['post'] = json_decode($ban['post'], true);
}
$ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend'])); $ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
$ban_list[] = $ban; $ban_list[] = $ban;
} }
@ -151,7 +154,9 @@ class Bans {
ORDER BY `created` DESC") or error(db_error()); ORDER BY `created` DESC") or error(db_error());
$bans = $query->fetchAll(PDO::FETCH_ASSOC); $bans = $query->fetchAll(PDO::FETCH_ASSOC);
if ($board_access && $board_access[0] == '*') $board_access = false; if ($board_access && $board_access[0] == '*') {
$board_access = false;
}
$out ? fputs($out, "[") : print("["); $out ? fputs($out, "[") : print("[");
@ -205,23 +210,24 @@ class Bans {
} }
$out ? fputs($out, "]") : print("]"); $out ? fputs($out, "]") : print("]");
} }
static public function seen($ban_id) { static public function seen($ban_id) {
$query = query("UPDATE ``bans`` SET `seen` = 1 WHERE `id` = " . (int)$ban_id) or error(db_error()); query("UPDATE ``bans`` SET `seen` = 1 WHERE `id` = " . (int)$ban_id) or error(db_error());
rebuildThemes('bans'); rebuildThemes('bans');
} }
static public function purge() { static public function purge() {
$query = query("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < " . time() . " AND `seen` = 1") or error(db_error()); query("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < " . time() . " AND `seen` = 1") or error(db_error());
rebuildThemes('bans'); rebuildThemes('bans');
} }
static public function delete($ban_id, $modlog = false, $boards = false, $dont_rebuild = false) { static public function delete($ban_id, $modlog = false, $boards = false, $dont_rebuild = false) {
global $config; global $config;
if ($boards && $boards[0] == '*') $boards = false; if ($boards && $boards[0] == '*') {
$boards = false;
}
if ($modlog) { if ($modlog) {
$query = query("SELECT `ipstart`, `ipend`, `board` FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error()); $query = query("SELECT `ipstart`, `ipend`, `board` FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error());
@ -230,8 +236,9 @@ class Bans {
return false; return false;
} }
if ($boards !== false && !in_array($ban['board'], $boards)) if ($boards !== false && !in_array($ban['board'], $boards)) {
error($config['error']['noaccess']); error($config['error']['noaccess']);
}
$mask = self::range_to_string(array($ban['ipstart'], $ban['ipend'])); $mask = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
@ -241,7 +248,9 @@ class Bans {
query("DELETE FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error()); query("DELETE FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error());
if (!$dont_rebuild) rebuildThemes('bans'); if (!$dont_rebuild) {
rebuildThemes('bans');
}
return true; return true;
} }
@ -259,10 +268,11 @@ class Bans {
$query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ipstart, :ipend, :time, :expires, :board, :mod, :reason, 0, :post)"); $query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ipstart, :ipend, :time, :expires, :board, :mod, :reason, 0, :post)");
$query->bindValue(':ipstart', $range[0]); $query->bindValue(':ipstart', $range[0]);
if ($range[1] !== false && $range[1] != $range[0]) if ($range[1] !== false && $range[1] != $range[0]) {
$query->bindValue(':ipend', $range[1]); $query->bindValue(':ipend', $range[1]);
else } else {
$query->bindValue(':ipend', null, PDO::PARAM_NULL); $query->bindValue(':ipend', null, PDO::PARAM_NULL);
}
$query->bindValue(':mod', $mod_id); $query->bindValue(':mod', $mod_id);
$query->bindValue(':time', time()); $query->bindValue(':time', time());
@ -271,8 +281,9 @@ class Bans {
$reason = escape_markup_modifiers($reason); $reason = escape_markup_modifiers($reason);
markup($reason); markup($reason);
$query->bindValue(':reason', $reason); $query->bindValue(':reason', $reason);
} else } else {
$query->bindValue(':reason', null, PDO::PARAM_NULL); $query->bindValue(':reason', null, PDO::PARAM_NULL);
}
if ($length) { if ($length) {
if (is_int($length) || ctype_digit($length)) { if (is_int($length) || ctype_digit($length)) {
@ -285,16 +296,18 @@ class Bans {
$query->bindValue(':expires', null, PDO::PARAM_NULL); $query->bindValue(':expires', null, PDO::PARAM_NULL);
} }
if ($ban_board) if ($ban_board) {
$query->bindValue(':board', $ban_board); $query->bindValue(':board', $ban_board);
else } else {
$query->bindValue(':board', null, PDO::PARAM_NULL); $query->bindValue(':board', null, PDO::PARAM_NULL);
}
if ($post) { if ($post) {
$post['board'] = $board['uri']; $post['board'] = $board['uri'];
$query->bindValue(':post', json_encode($post)); $query->bindValue(':post', json_encode($post));
} else } else {
$query->bindValue(':post', null, PDO::PARAM_NULL); $query->bindValue(':post', null, PDO::PARAM_NULL);
}
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));

Loading…
Cancel
Save