From b079b0f9548eeee63cb1c58a68414e7cac75dd6e Mon Sep 17 00:00:00 2001
From: ruan <2369127-ruany@users.noreply.gitlab.com>
Date: Sat, 10 Aug 2024 23:36:27 +0200
Subject: [PATCH] Support Content Security Policy (CSP)
---
check.php | 6 +++---
error/tables-not-found.php | 20 --------------------
history.php | 2 +-
inc/css/custom.css | 4 ++++
inc/database.php | 18 ++++++++++--------
inc/footer.php | 2 +-
inc/header.php | 10 +---------
inc/init.php | 12 ------------
inc/js/form.js | 20 ++++++++++++++++++++
inc/js/redirect.js | 4 ++++
inc/js/table.js | 15 +++++++++++++++
inc/page.php | 35 +++++++++++++++++++++++++----------
12 files changed, 84 insertions(+), 64 deletions(-)
delete mode 100644 inc/init.php
create mode 100644 inc/js/form.js
create mode 100644 inc/js/redirect.js
create mode 100644 inc/js/table.js
diff --git a/check.php b/check.php
index 0ac761f..b3a0ed7 100644
--- a/check.php
+++ b/check.php
@@ -35,7 +35,7 @@ class Check {
if (!isset($uuid)) {
if (filter_var($name, FILTER_VALIDATE_FLOAT)) {
echo "
";
- redirect($page->link("info.php?type=$type&id=$name"));
+ $page->redirect($page->link("info.php?type=$type&id=$name"), true, false);
return;
}
$name = htmlspecialchars($name, ENT_QUOTES);
@@ -50,9 +50,9 @@ class Check {
}
echo "
";
- redirect($page->link($href));
+ $page->redirect($page->link($href), true, false);
} catch (PDOException $ex) {
- $page->db->handle_error($page->settings, $ex);
+ $page->db->handle_error($page, $ex);
}
}
diff --git a/error/tables-not-found.php b/error/tables-not-found.php
index d69fda1..70eb8ea 100644
--- a/error/tables-not-found.php
+++ b/error/tables-not-found.php
@@ -41,26 +41,6 @@
- Ensure that you are using the latest version of LiteBans.
- Database tables:");
- $db = new Database($settings, true, false);
- try {
- $st = $db->conn->query("SELECT * FROM " . $settings->table['bans'] . " LIMIT 1;");
- $st->fetch();
- $st->closeCursor();
- } catch (PDOException $e) {
- $st = $db->conn->query("SHOW TABLES;");
- $st->execute();
- $rows = $st->fetchAll(PDO::FETCH_ASSOC);
-
- foreach ($rows as $row) {
- foreach ($row as $k => $v) {
- echo("
- $v");
- }
- }
- $st->closeCursor();
- }
- ?>
Try Again
diff --git a/history.php b/history.php
index 7b322e7..12fe10a 100644
--- a/history.php
+++ b/history.php
@@ -266,5 +266,5 @@ try {
$page->print_footer();
} catch (PDOException $ex) {
- $page->db->handle_error($page->settings, $ex);
+ $page->db->handle_error($page, $ex);
}
diff --git a/inc/css/custom.css b/inc/css/custom.css
index 64b15bb..a7cc42e 100644
--- a/inc/css/custom.css
+++ b/inc/css/custom.css
@@ -71,6 +71,10 @@ tr.hover {
text-align: left;
}
+.litebans-check-btn {
+ margin-left: 5px;
+}
+
.litebans-check-form {
margin-left: 15px;
}
diff --git a/inc/database.php b/inc/database.php
index 30c4761..a1271b2 100644
--- a/inc/database.php
+++ b/inc/database.php
@@ -4,15 +4,16 @@
class Database {
public static $TRUE = "1", $FALSE = "0";
- public function __construct(Settings $settings, $connect, $verify) {
+ public function __construct(Page $page, $connect, $verify) {
if ($connect) {
- $this->connect($settings, $verify);
+ $this->connect($page, $verify);
} else {
$this->conn = null;
}
}
- function connect(Settings $cfg, $verify = true) {
+ function connect(Page $page, $verify = true) {
+ $cfg = $page->settings;
$driver = $cfg->driver;
$host = $cfg->host;
$port = $cfg->port;
@@ -41,7 +42,7 @@ class Database {
}
if ($username === "" && $password === "") {
- redirect("error/unconfigured.php");
+ $page->redirect("error/unconfigured.php");
}
$dsn = "$driver:dbname=$database;host=$host;port=$port";
@@ -84,7 +85,8 @@ class Database {
* @param $e Exception
* @throws Exception
*/
- function handle_error(Settings $cfg, Exception $e) {
+ function handle_error(Page $page, Exception $e) {
+ $cfg = $page->settings;
if ($cfg->error_throw) throw $e;
$message = 'Database error: ' . $e->getMessage();
@@ -92,7 +94,7 @@ class Database {
if (strstr($message, "Access denied for user")) {
$param = "";
if ($cfg->error_reporting) $param = "?error=" . base64_encode($e->getMessage());
- redirect("error/access-denied.php$param");
+ $page->redirect("error/access-denied.php$param");
}
if (strstr($message, "Base table or view not found:") || strstr($message, "Unknown column")) {
try {
@@ -100,9 +102,9 @@ class Database {
$st->fetch();
$st->closeCursor();
} catch (PDOException $e) {
- redirect("error/tables-not-found.php");
+ $page->redirect("error/tables-not-found.php");
}
- redirect("error/outdated-plugin.php");
+ $page->redirect("error/outdated-plugin.php");
}
}
if (!$cfg->error_reporting) $message = "Database error";
diff --git a/inc/footer.php b/inc/footer.php
index 482c29f..b7b3ce1 100644
--- a/inc/footer.php
+++ b/inc/footer.php
@@ -1,3 +1,3 @@
-"; ?>
+