mirror of
https://gitlab.com/ruany/litebans-php.git
synced 2025-05-23 16:32:45 +00:00
Refactor, fix active=1 with pgsql
This commit is contained in:
parent
6ab6d09db9
commit
636f33205a
96
check.php
96
check.php
@ -1,48 +1,64 @@
|
||||
<?php
|
||||
if (isset($_POST['name'], $_POST['table'])) {
|
||||
$name = $_POST['name'];
|
||||
// validate user input
|
||||
if (strlen($name) > 16 || !preg_match("/^[0-9a-zA-Z_]{1,16}$/", $name)) {
|
||||
echo "Invalid name.";
|
||||
return;
|
||||
}
|
||||
require './includes/page.php';
|
||||
$page = new Page();
|
||||
$history = $page->settings->table_history;
|
||||
require_once './includes/page.php';
|
||||
|
||||
$stmt = $page->conn->prepare("SELECT name,uuid FROM $history WHERE name=? ORDER BY date LIMIT 1");
|
||||
if ($stmt->execute(array($name))) {
|
||||
if ($row = $stmt->fetch()) {
|
||||
$name = $row['name'];
|
||||
$uuid = $row['uuid'];
|
||||
}
|
||||
}
|
||||
if (!isset($uuid)) {
|
||||
$name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
|
||||
echo "$name has not joined before.<br>";
|
||||
return;
|
||||
}
|
||||
$table = $page->settings->table_bans;
|
||||
|
||||
$stmt = $page->conn->prepare("SELECT * FROM $table WHERE (uuid=? AND active=1) LIMIT 1");
|
||||
if ($stmt->execute(array($uuid))) {
|
||||
if (!($row = $stmt->fetch())) {
|
||||
echo "$name is not banned.<br>";
|
||||
class Check {
|
||||
public function run($name) {
|
||||
// validate user input
|
||||
if (strlen($name) > 16 || !preg_match("/^[0-9a-zA-Z_]{1,16}$/", $name)) {
|
||||
$this->println("Invalid name.");
|
||||
return;
|
||||
}
|
||||
$banner = $page->get_banner_name($row);
|
||||
$reason = $page->clean($row['reason']);
|
||||
$time = $page->millis_to_date($row['time']);
|
||||
$until = $page->millis_to_date($row['until']);
|
||||
echo "$name is banned!<br>";
|
||||
echo "Banned by: $banner<br>";
|
||||
echo "Reason: $reason<br>";
|
||||
echo "Banned on: $time<br>";
|
||||
if ($row['until'] > 0) {
|
||||
echo "Banned until: $until<br>";
|
||||
} else {
|
||||
echo "Banned permanently.<br>";
|
||||
$page = new Page(false);
|
||||
$history = $page->settings->table_history;
|
||||
|
||||
try {
|
||||
$stmt = $page->conn->prepare("SELECT name,uuid FROM $history WHERE name=? ORDER BY date LIMIT 1");
|
||||
if ($stmt->execute(array($name))) {
|
||||
if ($row = $stmt->fetch()) {
|
||||
$name = $row['name'];
|
||||
$uuid = $row['uuid'];
|
||||
}
|
||||
}
|
||||
if (!isset($uuid)) {
|
||||
$name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
|
||||
$this->println("$name has not joined before.");
|
||||
return;
|
||||
}
|
||||
$table = $page->settings->table_bans;
|
||||
|
||||
$stmt = $page->conn->prepare("SELECT * FROM $table WHERE (uuid=? AND active=" . Settings::$TRUE . ") LIMIT 1");
|
||||
if ($stmt->execute(array($uuid))) {
|
||||
if (!($row = $stmt->fetch())) {
|
||||
$this->println("$name is not banned.");
|
||||
return;
|
||||
}
|
||||
$banner = $page->get_banner_name($row);
|
||||
$reason = $page->clean($row['reason']);
|
||||
$time = $page->millis_to_date($row['time']);
|
||||
$until = $page->millis_to_date($row['until']);
|
||||
|
||||
$this->println("$name is banned!");
|
||||
$this->println("Banned by: $banner");
|
||||
$this->println("Reason: $reason");
|
||||
$this->println("Banned on: $time");
|
||||
if ($row['until'] > 0) {
|
||||
$this->println("Banned until: $until");
|
||||
} else {
|
||||
$this->println("Banned permanently.");
|
||||
}
|
||||
}
|
||||
} catch (PDOException $ex) {
|
||||
die($ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function println($line) {
|
||||
echo "$line<br>";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['name'], $_POST['table'])) {
|
||||
$check = new Check();
|
||||
$check->run($_POST['name']);
|
||||
}
|
||||
?>
|
||||
|
@ -1,17 +1,18 @@
|
||||
<?php
|
||||
require './includes/head.php';
|
||||
require './includes/header.php';
|
||||
require_once './includes/settings.php';
|
||||
|
||||
class Page {
|
||||
public function __construct() {
|
||||
public function __construct($header = true) {
|
||||
if ($header) {
|
||||
require_once './includes/head.php';
|
||||
require_once './includes/header.php';
|
||||
}
|
||||
require_once './includes/settings.php';
|
||||
$settings = new Settings();
|
||||
$this->conn = $settings->conn;
|
||||
$this->settings = $settings;
|
||||
$this->uuid_name_cache = array();
|
||||
$this->time = microtime(true);
|
||||
$this->page = 1;
|
||||
|
||||
if (isset($_GET['page'])) {
|
||||
$page = $_GET['page']; // user input
|
||||
if (filter_var($page, FILTER_VALIDATE_INT)) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
final class Settings {
|
||||
public static $TRUE = "1", $FALSE = "0";
|
||||
|
||||
public function __construct($connect = true) {
|
||||
// Server name, shown on the main page and on the header
|
||||
$this->name = 'LiteBans';
|
||||
@ -41,11 +43,19 @@ final class Settings {
|
||||
|
||||
$driver = 'mysql';
|
||||
|
||||
/*** End of configuration ***/
|
||||
|
||||
$this->active_query = "";
|
||||
if (!$this->show_inactive_bans) {
|
||||
$this->active_query = "WHERE active=1";
|
||||
|
||||
if ($driver === "pgsql") {
|
||||
Settings::$TRUE = "B'1'";
|
||||
Settings::$FALSE = "B'0'";
|
||||
}
|
||||
|
||||
if (!$this->show_inactive_bans) {
|
||||
$this->active_query = "WHERE active=" . Settings::$TRUE;
|
||||
}
|
||||
$this->driver = $driver;
|
||||
if ($connect) {
|
||||
$dsn = "$driver:dbname=$database;host=$host;port=$port";
|
||||
if ($driver === 'mysql') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user