<?php
define('HOOKTYPE_NAVBAR', 100); /* The Hook for the navigation bar */
+define('HOOKTYPE_PRE_HEADER', 101); /* The hook for pre-header */
/**
* Class for "Hook"
static function Fail(...$message)
{
?>
- <div class="alert alert-short alert-danger fade show" role="alert">
+ <div class="alert alert-danger fade show" role="alert">
<span class="closebtn text-right" onclick="this.parentElement.style.display='none';">×</span>
<?php
for ($i = 0; isset($message[$i]); $i++)
static function Success(...$message)
{
?>
- <div class="alert alert-short alert-success fade show" role="alert">
+ <div class="alert alert-success fade show" role="alert">
<span class="closebtn text-right" onclick="this.parentElement.style.display='none';">×</span>
<?php
for ($i = 0; isset($message[$i]); $i++)
static function Info(...$message)
{
?>
- <div class="alert alert-short alert-info fade show" role="alert">
+ <div class="alert alert-info fade show" role="alert">
<span class="closebtn text-right" onclick="this.parentElement.style.display='none';">×</span>
<?php
for ($i = 0; isset($message[$i]); $i++)
+<?php $arr = []; Hook::run(HOOKTYPE_PRE_HEADER, $arr); ?>
<!DOCTYPE html>
<head>
<!-- Latest compiled and minified CSS -->
-<?php include "common.php";
+<?php include "../../common.php";
+$logout = false;
+if (!empty($_GET['logout']))
+{
+ if (!isset($_SESSION['id']))
+ $failmsg = "Nothing to logout from";
+ else {
+ session_destroy();
+ $logout = true;
+ }
+}
if (!empty($_POST))
{
if ($_POST['username'] && $_POST['password'])
{
+ session_start([
+ 'cookie_lifetime' => 86400,
+ ]);
+ $_SESSION['id'] = $_POST['username'];
/* insert magic hacks here */
header('Location: ' . BASE_URL);
} else
<link rel="icon" type="image/x-icon" href="<?php echo BASE_URL; ?>img/favicon.ico">
<link href="<?php echo BASE_URL; ?>css/unrealircd-admin.css" rel="stylesheet">
</head><div class="text-center">
-<a href="<?php echo BASE_URL; ?>login.php"><button type="button" style="margin:0; top:50%; position: absolute;" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#loginModaltitle">
+<a href="<?php echo BASE_URL; ?>plugins/sql_auth/login.php"><button type="button" style="margin:0; top:50%; position: absolute;" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#loginModaltitle">
Login to continue
</button></a>
</div>
</div>
<div class="modal-body">
<div class="form-group">
- <?php if (isset($failmsg)) Message::Fail($failmsg); ?>
+ <?php
+ if (isset($failmsg)) Message::Fail($failmsg);
+ if ($logout)
+ Message::Success("You have been logged out");
+ ?>
<label for="username">Username / Nick:</label>
<input style="width:90%;" type="text" class="form-control" name="username" id="username" >
</div>
</div>
</div>
<div class="modal-footer">
- <a class="btn btn-secondary" href="/">Cancel</a>
+ <a class="btn btn-secondary" href="#">Cancel</a>
<button type="submit" class="btn btn-primary">Log-In</button>
</div>
</div>
</div>
</div>
</form>
-<?php require_once "footer.php";
\ No newline at end of file
+<?php require_once "../../footer.php";
\ No newline at end of file
require_once "SQL/sql.php";
class sql_auth
{
- public $name = "SQL_Auth";
+ public $name = "SQLAuth";
public $author = "Valware";
public $version = "1.0";
public $description = "Provides a User Auth and Management Panel with an SQL backend";
function __construct()
{
- Hook::func(HOOKTYPE_NAVBAR, 'sql_auth::add_navbar');
+ Hook::func(HOOKTYPE_NAVBAR, 'sql_auth::add_navbar');
+ Hook::func(HOOKTYPE_PRE_HEADER, 'sql_auth::session_start');
}
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())
{
++$notifs;
}
$label = ($notifs) ? "<span class=\"position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger\">$notifs</span>" : "";
$pages["SQL Auth$label"] = "plugins/sql_auth/$link";
+ if ($_SESSION['id'])
+ {
+ $pages["Logout"] = "plugins/sql_auth/login.php?logout=true";
+ }
}
+ public static function session_start($n)
+ {
+ session_start();
+ if (!isset($_SESSION['id']))
+ {
+ header("Location: ".BASE_URL."plugins/sql_auth/login.php");
+ }
+ }
}
\ No newline at end of file