return FALSE;
}
-function read_config()
+function read_config_file()
{
GLOBAL $config;
}
}
+function read_config_db()
+{
+ GLOBAL $config;
+
+ $merge = DbSettings::get();
+ /* DB settings overwrite config.php keys: */
+ $config = array_merge($config, $merge);
+}
+
function config_is_file_item($name)
{
// TODO: move 'unrealircd' and 'plugins' probably ;)
if (($name == "unrealircd") ||
($name == "plugins") ||
- ($name == "mysql"))
+ ($name == "mysql") ||
+ ($name == "base_url"))
{
return true;
}
* without having the DB settings read. (And it also
* serves no purpose)
*/
+ return true;
}
// XXX: handle unsetting of config items :D - explicit unset function ?
foreach($db_settings as $k=>$v)
{
+ echo "Writing $k => $v<br>\n";
$ret = DbSettings::set($k, $v);
if (!$ret)
return $ret;
}
/* Now read the config, and redirect to install screen if we don't have it */
-if (!read_config())
+if (!read_config_file())
{
if (page_requires_no_config())
{
}
}
-if (!get_config("base_url")) die("You need to define the base_url in config/config.php");
require_once "Classes/class-hook.php";
if (!is_dir(UPATH . "/vendor"))
die("The vendor/ directory is missing. Most likely the admin forgot to run 'composer install'\n");
require_once UPATH . "/Classes/class-paneluser.php";
require_once UPATH . "/plugins.php";
+/* Now that plugins are loaded, read config from DB */
+read_config_db();
+
+/* And a check... */
+if (!get_config("base_url")) die("The base_url was not found in your config. Setup went wrong?");
+
$pages = [
"Overview" => "",
"Users" => "users",
<?php
class DbSettings {
- function get()
+ public static function get()
{
$conn = sqlnew();
$query = "SELECT * FROM " . get_config("mysql::table_prefix") . "settings";
$list = [];
while ($row = $result->fetch())
{
- $list[$row['setting_key']] = $row['setting_value'];
+ $list[$row['setting_key']] = unserialize($row['setting_value']);
}
return $list;
}
- function set($key, $val) : int
+ public static function set($key, $val) : int
{
$conn = sqlnew();
- $stmt = $conn->prepare("SELECT * FROM " . get_config("mysql::table_prefix") . "settings WHERE option_name = :name LIMIT 1");
+ $stmt = $conn->prepare("SELECT * FROM " . get_config("mysql::table_prefix") . "settings WHERE setting_key = :name LIMIT 1");
$stmt->execute(["name" => $key]);
if ($stmt->rowCount()) // if it already exists update it
- $stmt = $conn->prepare("UPDATE " . get_config("mysql::table_prefix") . "settings SET option_value = :value WHERE option_name = :name");
+ $stmt = $conn->prepare("UPDATE " . get_config("mysql::table_prefix") . "settings SET setting_value = :value WHERE setting_key = :name");
else // otherwise create it
- $stmt = $conn->prepare("INSERT INTO " . get_config("mysql::table_prefix") . "settings (option_name, option_value) VALUES (:name, :value)");
+ $stmt = $conn->prepare("INSERT INTO " . get_config("mysql::table_prefix") . "settings (setting_key, setting_value) VALUES (:name, :value)");
// make sure it's there/correct
- $stmt->execute(["name" => $key, "value" => $val]);
- $stmt = $conn->prepare("SELECT * FROM " . get_config("mysql::table_prefix") . "settings WHERE option_name = :name LIMIT 1");
+ $stmt->execute(["name" => $key, "value" => serialize($val)]);
+ $stmt = $conn->prepare("SELECT * FROM " . get_config("mysql::table_prefix") . "settings WHERE setting_key = :name LIMIT 1");
$stmt->execute(["name" => $key]);
return $stmt->rowCount(); // return 1 or 0 bool-like int
}
if (!empty($c))
$conn->query("ALTER TABLE `".get_config("mysql::table_prefix")."user_meta` CHANGE `meta_value` `meta_value` VARCHAR(5000) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NULL DEFAULT NULL");
-
- new DbSettings();
-
-
/* make sure everything went well */
$tables = ["users", "user_meta", "fail2ban", "settings"];
$errors = 0; // counter
}
/* First, write only the config file */
- write_file_config();
+ write_config_file();
if ($auth_method == "sql_auth")
if (!sql_auth::create_tables())