]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - common.php
Move to new style config, with config in config/ directory.
[irc/unrealircd/unrealircd-webpanel.git] / common.php
index 3b45630671635f50def5247525d1c8e29a9e6e28..ea488ea85d91528f4cb647f623265aff34fc6744 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 if (version_compare(PHP_VERSION, '8.0.0', '<'))
-       die("This webserver is PHP version ".PHP_VERSION." but we require at least PHP 8.0.0.<br>".
+       die("This webserver is using PHP version ".PHP_VERSION." but we require at least PHP 8.0.0.<br>".
            "If you already installed PHP8 but are still seeing this error, then it means ".
            "apache/nginx/.. is loading an older PHP version. Eg. on Debian/Ubuntu you need ".
            "<code>apt-get install libapache2-mod-php8.2</code> (or a similar version) and ".
@@ -8,8 +8,35 @@ if (version_compare(PHP_VERSION, '8.0.0', '<'))
            "You may also need to choose again the PHP module to load in apache via <code>a2enmod php8.2</code>");
 
 define('UPATH', dirname(__FILE__));
-require_once UPATH . "/config.php";
-if (!defined('BASE_URL')) die("You need to define BASE_URL in config.php (see config.php.sample for documentation)");
+
+function get_config($setting)
+{
+       GLOBAL $config;
+
+       $item = $config;
+       foreach(explode("::", $setting) as $x)
+       {
+               if (isset($item[$x]))
+                       $item = $item[$x];
+               else
+                       return NULL;
+       }
+       return $item;
+}
+
+/* Load config defaults */
+$config = Array();
+require_once UPATH . "/config/config.defaults.php";
+
+if (!file_exists(UPATH."/config/config.php") && file_exists(UPATH."/config.php"))
+{
+       require_once UPATH . "/config.php";
+       require_once UPATH . "/config/compat.php";
+} else {
+       require_once UPATH . "/config/config.php";
+}
+
+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");
@@ -42,19 +69,23 @@ $pages = [
                "IP WHOIS" => "tools/ip-whois.php",
        ],
        "Settings" => [
-               "Panel Access" => "settings",
                "Plugins" => "settings/plugins.php",
        ],
        
-       "News"         => "news.php",
+       "News" => "news.php",
 ];
-$user = unreal_get_current_user();
-if ($user)
+
+if (is_auth_provided())
 {
-       /* Add logout page, if logged in */
-       $pages["Logout"] = "login/?logout=true";
-}
+       $pages["Settings"]["Panel Access"] = "settings";
 
+       $user = unreal_get_current_user();
+       if ($user)
+       {
+               /* Add logout page, if logged in */
+               $pages["Logout"] = "login/?logout=true";
+       }
+}
 Hook::run(HOOKTYPE_NAVBAR, $pages);
 
 /* Example to add new menu item: