]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - plugins/sql_auth/sql_auth.php
Get rid of setup.php, being integrated in new all-in-one install page.
[irc/unrealircd/unrealircd-webpanel.git] / plugins / sql_auth / sql_auth.php
index bf911eb96b46848c3d7c560416dc0e7dffa2d299..a01b3cce4dbace075c4c78cb286f9d0b1089675f 100644 (file)
@@ -27,22 +27,6 @@ class sql_auth
                Hook::func(HOOKTYPE_PRE_OVERVIEW_CARD, 'sql_auth::add_pre_overview_card');
                AuthModLoaded::$status = 1;
 
-               if (defined('SQL_DEFAULT_USER')) // we've got a default account
-               {
-                       $lkup = new PanelUser(SQL_DEFAULT_USER['username']);
-
-                       if (!$lkup->id) // doesn't exist, add it with full privileges
-                       {
-                               $user = [];
-                               $user['user_name'] = SQL_DEFAULT_USER['username'];
-                               $user['user_pass'] = SQL_DEFAULT_USER['password'];
-                               $user['err'] = "";
-                               create_new_user($user);
-                       }
-                       $lkup = new PanelUser(SQL_DEFAULT_USER['username']);
-                       if (!user_can($lkup, PERMISSION_MANAGE_USERS))
-                               $lkup->add_permission(PERMISSION_MANAGE_USERS);
-               }
        }
 
 
@@ -60,15 +44,13 @@ class sql_auth
        {
                if (defined('SQL_DEFAULT_USER'))
                        Message::Fail("Warning: SQL_DEFAULT_USER is set in config.php. You should remove that item now, as it is only used during installation.");
+               if (defined('DEFAULT_USER'))
+                       Message::Fail("Warning: DEFAULT_USER is set in config.php. You should remove that item now, as it is only used during installation.");
        }
 
        /* pre-Header hook */
        public static function session_start($n)
        {
-               $current_page = $_SERVER['REQUEST_URI'];
-               if (str_ends_with($current_page,"setup.php"))
-                       return;
-
                if (!isset($_SESSION))
                {
                        session_set_cookie_params(3600);
@@ -79,10 +61,10 @@ class sql_auth
                        
                        $tok = split($_SERVER['SCRIPT_FILENAME'], "/");
                        if ($check = security_check() && $tok[count($tok) - 1] !== "error.php") {
-                               header("Location: " . BASE_URL . "plugins/sql_auth/error.php");
+                               header("Location: " . get_config("base_url") . "plugins/sql_auth/error.php");
                                die();
                        }
-                       header("Location: ".BASE_URL."login/?redirect=".urlencode($current_page));
+                       header("Location: ".get_config("base_url")."login/?redirect=".urlencode($current_page));
                        die();
                }
                else
@@ -90,7 +72,7 @@ class sql_auth
                        if (!unreal_get_current_user()) // user no longer exists
                        {
                                session_destroy();
-                               header("Location: ".BASE_URL."login");
+                               header("Location: ".get_config("base_url")."login");
                                die();
                        }
                        // you'll be automatically logged out after one hour of inactivity
@@ -109,10 +91,10 @@ class sql_auth
                if (str_ends_with($script,"setup.php"))
                        return;
                $conn = sqlnew();
-               $stmt = $conn->query("SHOW TABLES LIKE '".SQL_PREFIX."%'");
-               if ($stmt->rowCount() < 5)
+               $stmt = $conn->query("SHOW TABLES LIKE '".get_config("mysql::table_prefix")."%'");
+               if ($stmt->rowCount() < 4)
                {
-                       header("Location: ".BASE_URL."plugins/sql_auth/setup.php");
+                       header("Location: ".get_config("base_url")."plugins/sql_auth/setup.php");
                        die();
                }
        }
@@ -126,12 +108,12 @@ class sql_auth
 
                if ($id)
                {
-                       $prep = $conn->prepare("SELECT * FROM " . SQL_PREFIX . "users WHERE user_id = :id LIMIT 1");
+                       $prep = $conn->prepare("SELECT * FROM " . get_config("mysql::table_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 = $conn->prepare("SELECT * FROM " . get_config("mysql::table_prefix") . "users WHERE LOWER(user_name) = :name LIMIT 1");
                        $prep->execute(["name" => strtolower($name)]);
                }
                $data = NULL;
@@ -160,7 +142,7 @@ class sql_auth
                $conn = sqlnew();
                if (isset($id))
                {
-                       $prep = $conn->prepare("SELECT * FROM " . SQL_PREFIX . "user_meta WHERE user_id = :id");
+                       $prep = $conn->prepare("SELECT * FROM " . get_config("mysql::table_prefix") . "user_meta WHERE user_id = :id");
                        $prep->execute(["id" => $id]);
                }
                foreach ($prep->fetchAll() as $row)
@@ -174,12 +156,12 @@ class sql_auth
                $meta = $meta['meta'];
                $conn = sqlnew();
                /* check if it exists first, update it if it does */
-               $query = "SELECT * FROM " . SQL_PREFIX . "user_meta WHERE user_id = :id AND meta_key = :key";
+               $query = "SELECT * FROM " . get_config("mysql::table_prefix") . "user_meta WHERE user_id = :id AND meta_key = :key";
                $stmt = $conn->prepare($query);
                $stmt->execute(["id" => $meta['id'], "key" => $meta['key']]);
                if ($stmt->rowCount()) // it exists, update instead of insert
                {
-                       $query = "UPDATE " . SQL_PREFIX . "user_meta SET meta_value = :value WHERE user_id = :id AND meta_key = :key";
+                       $query = "UPDATE " . get_config("mysql::table_prefix") . "user_meta SET meta_value = :value WHERE user_id = :id AND meta_key = :key";
                        $stmt = $conn->prepare($query);
                        $stmt->execute($meta);
                        if ($stmt->rowCount())
@@ -189,7 +171,7 @@ class sql_auth
 
                else
                {
-                       $query = "INSERT INTO " . SQL_PREFIX . "user_meta (user_id, meta_key, meta_value) VALUES (:id, :key, :value)";
+                       $query = "INSERT INTO " . get_config("mysql::table_prefix") . "user_meta (user_id, meta_key, meta_value) VALUES (:id, :key, :value)";
                        $stmt = $conn->prepare($query);
                        $stmt->execute($meta);
                        if ($stmt->rowCount())
@@ -200,7 +182,7 @@ class sql_auth
        public static function del_usermeta(&$u)
        {
                $conn = sqlnew();
-               $query = "DELETE FROM " . SQL_PREFIX . "user_meta WHERE user_id = :id AND meta_key = :key";
+               $query = "DELETE FROM " . get_config("mysql::table_prefix") . "user_meta WHERE user_id = :id AND meta_key = :key";
                $stmt = $conn->prepare($query);
                $stmt->execute($u['meta']);
                if ($stmt->rowCount())
@@ -216,7 +198,7 @@ class sql_auth
                $user_bio = $u['user_bio'] ?? NULL;
                $user_email = $u['user_email'] ?? NULL;
                $conn = sqlnew();
-               $prep = $conn->prepare("INSERT INTO " . SQL_PREFIX . "users (user_name, user_pass, user_fname, user_lname, user_bio, user_email, created) VALUES (:name, :pass, :fname, :lname, :user_bio, :user_email, :created)");
+               $prep = $conn->prepare("INSERT INTO " . get_config("mysql::table_prefix") . "users (user_name, user_pass, user_fname, user_lname, user_bio, user_email, created) VALUES (:name, :pass, :fname, :lname, :user_bio, :user_email, :created)");
                $prep->execute(["name" => $username, "pass" => $password, "fname" => $first_name, "lname" => $last_name, "user_bio" => $user_bio, "user_email" => $user_email, "created" => date("Y-m-d H:i:s")]);
                if ($prep->rowCount())
                        $u['success'] = true;
@@ -227,7 +209,7 @@ class sql_auth
        public static function get_user_list(&$list)
        {
                $conn = sqlnew();
-               $result = $conn->query("SELECT user_id FROM " . SQL_PREFIX . "users");
+               $result = $conn->query("SELECT user_id FROM " . get_config("mysql::table_prefix") . "users");
                if (!$result) // impossible
                {
                        die("Something went wrong.");
@@ -244,7 +226,7 @@ class sql_auth
        public static function user_delete(&$u)
        {
                $user = $u['user'];
-               $query = "DELETE FROM " . SQL_PREFIX . "users WHERE user_id = :id";
+               $query = "DELETE FROM " . get_config("mysql::table_prefix") . "users WHERE user_id = :id";
                $conn = sqlnew();
                $stmt = $conn->prepare($query);
                $stmt->execute(["id" => $user->id]);
@@ -297,7 +279,7 @@ class sql_auth
                        
                        if (!$value)
                                continue;
-                       $query = "UPDATE " . SQL_PREFIX . "users SET $value=:value WHERE user_id = :id";
+                       $query = "UPDATE " . get_config("mysql::table_prefix") . "users SET $value=:value WHERE user_id = :id";
                        $stmt = $conn->prepare($query);
                        $stmt->execute(["value" => $val, "id" => $user->id]);
 
@@ -325,10 +307,9 @@ function security_check()
 
 function dnsbl_check($ip)
 {
-
-       if (!defined('DNSBL'))
+       $dnsbl_lookup = get_config("dnsbl");
+       if (!$dnsbl_lookup)
                return;
-       $dnsbl_lookup = DNSBL;
 
        // clear variable just in case
        $listed = NULL;