X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/9c64340180025055174a4f55bcdb09e8ecd0575b..fdc0088faa6bc7498d0e39b2457c2e758b10e6d8:/plugins/sql_auth/sql_auth.php
diff --git a/plugins/sql_auth/sql_auth.php b/plugins/sql_auth/sql_auth.php
index b0aa003..122d0f2 100644
--- a/plugins/sql_auth/sql_auth.php
+++ b/plugins/sql_auth/sql_auth.php
@@ -1,7 +1,6 @@
id) // doesn't exist, add it with full privileges
{
- create_new_user(["user_name" => SQL_DEFAULT_USER['username'], "user_pass" => SQL_DEFAULT_USER['password']]);
+ $user = [];
+ $user['user_name'] = SQL_DEFAULT_USER['username'];
+ $user['user_pass'] = SQL_DEFAULT_USER['password'];
+ $user['err'] = "";
+ create_new_user($user);
}
}
}
- public static function add_navbar(&$pages)
+
+ public static function add_footer_info($empty)
{
- if (!unreal_get_current_user()->id)
- {
- $pages = NULL;
+ if (!($user = unreal_get_current_user()))
return;
- }
- $pages["Panel Access"] = "plugins/sql_auth/";
- if (isset($_SESSION['id']))
- {
- $pages["Logout"] = "plugins/sql_auth/login.php?logout=true";
+
+ else {
+ echo "Admin Panel v" . WEBPANEL_VERSION . "
";
}
}
+ /* pre-Header hook */
public static function session_start($n)
{
+ if (!isset($_SESSION))
+ {
+ session_set_cookie_params(3600);
+ session_start();
+ }
do_log($_SESSION);
if (!isset($_SESSION['id']) || empty($_SESSION))
{
+ $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();
}
- session_destroy();
- header("Location: ".BASE_URL."plugins/sql_auth/login.php");
+ header("Location: ".BASE_URL."login/?redirect=".urlencode($current_url));
die();
}
else
@@ -62,10 +75,10 @@ class sql_auth
if (!unreal_get_current_user()->id) // user no longer exists
{
session_destroy();
- header("Location: ".BASE_URL."plugins/sql_auth/login.php");
+ header("Location: ".BASE_URL."login");
die();
}
- session_start();
+ // you'll be automatically logged out after one hour of inactivity
}
}
@@ -100,49 +113,155 @@ class sql_auth
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
+ /* We convert $u with a full user as an object ;D*/
+ public static function get_user(&$u)
+ {
+ $id = $u['id'];
+ $name = $u['name'];
+ $conn = sqlnew();
+
+ if ($id)
+ {
+ $prep = $conn->prepare("SELECT * FROM " . SQL_PREFIX . "users WHERE user_id = :id LIMIT 1");
+ $prep->execute(["id" => strtolower($id)]);
+ }
+ elseif ($name)
+ {
+ $prep = $conn->prepare("SELECT * FROM " . SQL_PREFIX . "users WHERE LOWER(user_name) = :name LIMIT 1");
+ $prep->execute(["name" => strtolower($name)]);
+ }
+ $data = NULL;
+ $obj = (object) [];
+ if ($prep)
+ $data = $prep->fetchAll();
+ if (isset($data[0]) && $data = $data[0])
+ {
+ $obj->id = $data['user_id'];
+ $obj->username = $data['user_name'];
+ $obj->passhash = $data['user_pass'];
+ $obj->first_name = $data['user_fname'] ?? NULL;
+ $obj->last_name = $data['user_lname'] ?? NULL;
+ $obj->created = $data['created'];
+ $obj->bio = $data['user_bio'];
+ $obj->user_meta = (new PanelUser_Meta($obj->id))->list;
+ }
+ $u['object'] = $obj;
+ }
+
+ public static function get_usermeta(&$u)
{
- $num_of_panel_admins = sqlnew()->query("SELECT COUNT(*) FROM " . SQL_PREFIX . "users")->fetchColumn();
- ?>
-
-