diff --git a/check.php b/check.php
index 3d6cfe4..be8dd5b 100644
--- a/check.php
+++ b/check.php
@@ -1,48 +1,64 @@
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.
";
- 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.
";
+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!
";
- echo "Banned by: $banner
";
- echo "Reason: $reason
";
- echo "Banned on: $time
";
- if ($row['until'] > 0) {
- echo "Banned until: $until
";
- } else {
- echo "Banned permanently.
";
+ $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
";
+ }
+}
+
+if (isset($_POST['name'], $_POST['table'])) {
+ $check = new Check();
+ $check->run($_POST['name']);
}
?>
diff --git a/includes/page.php b/includes/page.php
index 124742b..4f54841 100644
--- a/includes/page.php
+++ b/includes/page.php
@@ -1,17 +1,18 @@
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)) {
diff --git a/includes/settings.php b/includes/settings.php
index d6e627f..9e229e5 100644
--- a/includes/settings.php
+++ b/includes/settings.php
@@ -1,6 +1,8 @@
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') {