--- /dev/null
+<?php
+
+function sqlnew()
+{
+ $host = SQL_IP;
+ $user = SQL_USERNAME;
+ $pass = SQL_PASSWORD;
+ $db = SQL_DATABASE;
+ $charset = 'utf8mb4';
+
+ $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
+ $options = [
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+ PDO::ATTR_EMULATE_PREPARES => false,
+ ];
+ try {
+ $pdo = new PDO($dsn, $user, $pass, $options);
+ } catch (\PDOException $e) {
+ throw new \PDOException($e->getMessage(), (int)$e->getCode());
+ }
+ return $pdo;
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+require_once "../../common.php";
+require_once "../../header.php";
+
+if (!isset($_GET) || !isset($_GET['errno']))
+{
+ Message::Fail("Uh oh! Something went wrong. We don't know anything else.");
+}
+elseif ($_GET['errno'] == 1)
+{
+ Message::Fail("Looks like your SQL tables haven't been set up yet",
+ "SQL_Auth needs to create tables for users and permissions. Is that okay?<br>",
+ "<form method=\"post\" action=\"index.php\">
+ <button type=\"submit\" id=\"sql_setup\" name=\"sql_setup\" class=\"text-right btn btn-primary\" value=\"add_tables\">Yes, set up tables</button>
+ </form>");
+ ?>
+
+ <?php
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+$conn = NULL;
+
+require_once "../../common.php";
+require_once "../../header.php";
+do_log($_POST);
+
+if (isset($_POST))
+{
+ $p = $_POST;
+ if (isset($p['sql_setup']))
+ {
+ if ($p['sql_setup'] == "add_tables")
+ {
+ $conn = sqlnew();
+ $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "users (
+ user_id int AUTO_INCREMENT NOT NULL,
+ user_name VARCHAR(255) NOT NULL,
+ user_pass VARCHAR(255) NOT NULL,
+
+ user_fname VARCHAR(255),
+ user_lname VARCHAR(255),
+ user_bio VARCHAR(255),
+ created VARCHAR(255),
+ PRIMARY KEY (user_id)
+ )");
+ $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "user_meta (
+ meta_id int AUTO_INCREMENT NOT NULL,
+ user_id int NOT NULL,
+ meta_key VARCHAR(255) NOT NULL,
+ meta_value VARCHAR(255),
+ PRIMARY KEY (meta_id)
+ )");
+
+ }
+ }
+}
+
+
+
+$conn = sqlnew();
+$count = $conn->query("SELECT count(*) FROM ".SQL_PREFIX."users")->fetchColumn();
+?>
+<div class="mt-5">
+ <div class="card text-center" style="width: 18rem;">
+ <div class="card-header bg-warning">
+ <div class="row">
+ <div class="col">
+ <i class="fa fa-screwdriver-wrench fa-3x"></i>
+ </div>
+ <div class="col">
+ <h3 class="display-4"><?php echo $count; ?></h3>
+ </div>
+ </div>
+ </div>
+ <div class="card-body">
+ <div class="row">
+ <div class="col">
+ <h6>Panel Admins</h6>
+ </div>
+ <div class="col"> <a class="btn btn-primary" href="<?php echo BASE_URL; ?>users">View</a></div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
\ No newline at end of file
--- /dev/null
+<?php
+
+require_once "SQL/sql.php";
+class sql_auth
+{
+ public $name = "SQL_Auth";
+ 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');
+ }
+
+ public static function add_navbar(&$pages)
+ {
+ $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;
+ if (!$result || !$result->fetchColumn())
+ {
+ ++$notifs;
+ $link = "error.php?errno=1";
+ }
+ $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";
+ }
+
+
+}
\ No newline at end of file