]>
Commit | Line | Data |
---|---|---|
ea27475b VP |
1 | <?php |
2 | ||
3 | require_once "SQL/sql.php"; | |
4d634d0a VP |
4 | require_once "SQL/user.php"; |
5 | ||
ea27475b VP |
6 | class sql_auth |
7 | { | |
b44a2e97 | 8 | public $name = "SQLAuth"; |
ea27475b VP |
9 | public $author = "Valware"; |
10 | public $version = "1.0"; | |
11 | public $description = "Provides a User Auth and Management Panel with an SQL backend"; | |
12 | ||
13 | function __construct() | |
14 | { | |
b44a2e97 VP |
15 | Hook::func(HOOKTYPE_NAVBAR, 'sql_auth::add_navbar'); |
16 | Hook::func(HOOKTYPE_PRE_HEADER, 'sql_auth::session_start'); | |
4d634d0a VP |
17 | |
18 | if (defined('SQL_DEFAULT_USER')) // we've got a default account | |
19 | { | |
20 | $lkup = new SQLA_User(SQL_DEFAULT_USER['username']); | |
21 | ||
22 | if (!$lkup->id) // doesn't exist, add it with full privileges | |
23 | { | |
24 | create_new_user(["user_name" => SQL_DEFAULT_USER['username'], "user_pass" => SQL_DEFAULT_USER['password']]); | |
25 | } | |
26 | } | |
ea27475b VP |
27 | } |
28 | ||
29 | public static function add_navbar(&$pages) | |
30 | { | |
b44a2e97 | 31 | session_start(); |
ea27475b VP |
32 | $query = "SELECT * FROM INFORMATION_SCHEMA.TABLES |
33 | WHERE TABLE_TYPE = 'BASE TABLE' | |
34 | AND TABLE_NAME = '".SQL_PREFIX."users'"; | |
35 | ||
36 | $conn = sqlnew(); | |
37 | $result = $conn->query($query); | |
38 | $notifs = 0; | |
b44a2e97 | 39 | $link = ""; |
ea27475b VP |
40 | if (!$result || !$result->fetchColumn()) |
41 | { | |
42 | ++$notifs; | |
43 | $link = "error.php?errno=1"; | |
44 | } | |
45 | $label = ($notifs) ? "<span class=\"position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger\">$notifs</span>" : ""; | |
a3151e7c | 46 | $pages["Panel Access$label"] = "plugins/sql_auth/$link"; |
b44a2e97 VP |
47 | if ($_SESSION['id']) |
48 | { | |
49 | $pages["Logout"] = "plugins/sql_auth/login.php?logout=true"; | |
50 | } | |
ea27475b VP |
51 | } |
52 | ||
b44a2e97 VP |
53 | public static function session_start($n) |
54 | { | |
55 | session_start(); | |
56 | if (!isset($_SESSION['id'])) | |
57 | { | |
58 | header("Location: ".BASE_URL."plugins/sql_auth/login.php"); | |
59 | } | |
60 | } | |
ea27475b VP |
61 | |
62 | } |