From 2d293c81c9af33e6778cb3b5fc0c4b3bf71162fd Mon Sep 17 00:00:00 2001 From: Ario Date: Sun, 15 Sep 2019 00:20:35 +0200 Subject: [PATCH] config --- include/init.inc.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/include/init.inc.php b/include/init.inc.php index cf4ad93..df6f374 100755 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -59,6 +59,20 @@ foreach ($query as $res) { $_config[$res['cfg']] = trim($res['val']); } +// current hostname +$hostname = (!empty($_SERVER['HTTPS']) ? 'https' : 'http')."://".san_host($_SERVER['HTTP_HOST']); +// set the hostname to the current one +if ($hostname != $_config['hostname'] && $_SERVER['HTTP_HOST'] != "localhost" && $_SERVER['HTTP_HOST'] != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) { + $db->run("UPDATE config SET val=:hostname WHERE cfg='hostname' LIMIT 1", [":hostname" => $hostname]); + $_config['hostname'] = $hostname; +} + +// Getting extra configs from the database +$query = $db->run("SELECT cfg, val FROM config"); +foreach ($query as $res) { + $_config[$res['cfg']] = trim($res['val']); +} + // nothing is allowed while in maintenance if ($_config['maintenance'] == 1) { api_err("under-maintenance"); @@ -93,13 +107,7 @@ if ($_config['testnet'] == true) { $_config['coin'] .= "-testnet"; } -// current hostname -$hostname = (!empty($_SERVER['HTTPS']) ? 'https' : 'http')."://".san_host($_SERVER['HTTP_HOST']); -// set the hostname to the current one -if ($hostname != $_config['hostname'] && $_SERVER['HTTP_HOST'] != "localhost" && $_SERVER['HTTP_HOST'] != "127.0.0.1" && $_SERVER['hostname'] != '::1' && php_sapi_name() !== 'cli' && ($_config['allow_hostname_change'] != false || empty($_config['hostname']))) { - $db->run("UPDATE config SET val=:hostname WHERE cfg='hostname' LIMIT 1", [":hostname" => $hostname]); - $_config['hostname'] = $hostname; -} + if (empty($_config['hostname']) || $_config['hostname'] == "http://" || $_config['hostname'] == "https://") { api_err("Invalid hostname"); }