]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
More towards the sql_auth
authorValerie Pond <redacted>
Tue, 17 Jan 2023 19:54:51 +0000 (19:54 +0000)
committerValerie Pond <redacted>
Tue, 17 Jan 2023 19:54:51 +0000 (19:54 +0000)
Classes/class-hook.php
Classes/class-message.php
header.php
plugins/sql_auth/login.php [moved from login.php with 75% similarity]
plugins/sql_auth/sql_auth.php

index 84c06b93b0fb03243ca88dabb2e8024b07fe4cb8..a5e1220dd2c0f43083277c00ecd75251610802c3 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 define('HOOKTYPE_NAVBAR', 100); /* The Hook for the navigation bar */
+define('HOOKTYPE_PRE_HEADER', 101); /* The hook for pre-header */
 
 /** 
  *  Class for "Hook"
index c37415b83eb214823e5118eb2a80ae21c85cd0d6..835f4a78d2f1925bc485c672429f5ef97e14e3c1 100644 (file)
@@ -5,7 +5,7 @@ class Message
        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';">&times;</span>
                <?php
                        for ($i = 0; isset($message[$i]); $i++)
@@ -20,7 +20,7 @@ class Message
        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';">&times;</span>
                <?php
                        for ($i = 0; isset($message[$i]); $i++)
@@ -35,7 +35,7 @@ class Message
        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';">&times;</span>
                <?php
                        for ($i = 0; isset($message[$i]); $i++)
index 0401f295d90156472c898b0582f3bce9c262da1c..e5be052559d1b1edd99e6faed1d01f76e0fd7c53 100644 (file)
@@ -1,3 +1,4 @@
+<?php $arr = []; Hook::run(HOOKTYPE_PRE_HEADER, $arr); ?>
 <!DOCTYPE html>
 <head>
  <!-- Latest compiled and minified CSS -->
similarity index 75%
rename from login.php
rename to plugins/sql_auth/login.php
index 3704ea476fb88a95b6ef67903b507e060f1c4d4d..e731203892ad3adb8656e23ffabbd45f3ad52812 100644 (file)
--- a/login.php
@@ -1,10 +1,24 @@
 
-<?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
@@ -33,7 +47,7 @@ if (!empty($_POST))
 <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>
@@ -53,7 +67,11 @@ if (!empty($_POST))
         </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>
@@ -63,11 +81,11 @@ if (!empty($_POST))
             </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
index c3bef72ccc51bee822f851f91f1453e9115e7025..83b1e6fc2d0a3bcc3b03ee172c57f297db00de93 100644 (file)
@@ -3,18 +3,20 @@
 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'";
@@ -22,6 +24,7 @@ class sql_auth
                $conn = sqlnew();
                $result = $conn->query($query);
                $notifs = 0;
+               $link = "";
                if (!$result || !$result->fetchColumn())
                {
                        ++$notifs;
@@ -29,7 +32,19 @@ class sql_auth
                }
                $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