X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/5015c85cb1789bbc2da53966fa37f7f29a1a7570..da6fa2d1fb2021fc6e1fec33c59f4a24b812dd30:/plugins/sql_auth/sql_auth.php
diff --git a/plugins/sql_auth/sql_auth.php b/plugins/sql_auth/sql_auth.php
index 6c9516d..8e2eb44 100644
--- a/plugins/sql_auth/sql_auth.php
+++ b/plugins/sql_auth/sql_auth.php
@@ -1,7 +1,7 @@
id) // doesn't exist, add it with full privileges
{
@@ -29,37 +35,66 @@ class sql_auth
public static function add_navbar(&$pages)
{
- session_start();
- $query = "SELECT * FROM INFORMATION_SCHEMA.TABLES
- WHERE TABLE_TYPE = 'BASE TABLE'
- AND TABLE_NAME = '".SQL_PREFIX."users'";
-
- $conn = sqlnew();
- $result = $conn->query($query);
- $notifs = 0;
- $link = "";
- if (!$result || !$result->fetchColumn())
+ $user = unreal_get_current_user();
+ if (!$user)
{
- ++$notifs;
- $link = "error.php?errno=1";
+ $pages = NULL;
+ return;
}
- $label = ($notifs) ? "$notifs" : "";
- $pages["Panel Access$label"] = "plugins/sql_auth/$link";
- if ($_SESSION['id'])
+ $pages["Panel Access"] = "plugins/sql_auth/";
+ if (isset($_SESSION['id']))
{
- $pages["Logout"] = "plugins/sql_auth/login.php?logout=true";
+ $pages["Logout"] = "login/?logout=true";
}
}
+ public static function add_footer_info($empty)
+ {
+ if (!($user = unreal_get_current_user()))
+ return;
+
+ else {
+ echo "Admin Panel v" . WEBPANEL_VERSION . "
";
+ }
+ }
+
+ /* pre-Header hook */
public static function session_start($n)
{
- session_start();
- if (!isset($_SESSION['id']))
+ if (!isset($_SESSION))
+ {
+ session_set_cookie_params(3600);
+ session_start();
+ }
+ do_log($_SESSION);
+ if (!isset($_SESSION['id']) || empty($_SESSION))
{
- header("Location: ".BASE_URL."plugins/sql_auth/login.php");
+ $secure = ($_SERVER['HTTPS'] == 'on') ? "https://" : "http://";
+ $current_url = "$secure$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
+ $tok = split($_SERVER['SCRIPT_FILENAME'], "/");
+ if ($check = security_check() && $tok[count($tok) - 1] !== "error.php") {
+ header("Location: " . BASE_URL . "plugins/sql_auth/error.php");
+ die();
+ }
+ header("Location: ".BASE_URL."login/?redirect=".urlencode($current_url));
+ die();
+ }
+ else
+ {
+ if (!unreal_get_current_user()->id) // user no longer exists
+ {
+ session_destroy();
+ header("Location: ".BASE_URL."login");
+ die();
+ }
+ // you'll be automatically logged out after one hour of inactivity
}
}
+ /**
+ * Create the tables we'll be using in the SQLdb
+ * @return void
+ */
public static function create_tables()
{
$conn = sqlnew();
@@ -81,6 +116,211 @@ class sql_auth
meta_value VARCHAR(255),
PRIMARY KEY (meta_id)
)");
+ $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "auth_settings (
+ id int AUTO_INCREMENT NOT NULL,
+ setting_key VARCHAR(255) NOT NULL,
+ setting_value VARCHAR(255),
+ PRIMARY KEY (id)
+ )");
+ $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "fail2ban (
+ id int AUTO_INCREMENT NOT NULL,
+ ip VARCHAR(255) NOT NULL,
+ count VARCHAR(255),
+ PRIMARY KEY (id)
+ )");
+ new AuthSettings();
+ }
+
+ /**
+ * Summary of add_overview_card
+ * @param mixed $stats
+ * @return void
+ */
+ public static function add_overview_card(object &$stats) : void
+ {
+ $num_of_panel_admins = sqlnew()->query("SELECT COUNT(*) FROM " . SQL_PREFIX . "users")->fetchColumn();
+ ?>
+
+