From db1f164e62781c99b7cb8365ab841bb80ea12cd9 Mon Sep 17 00:00:00 2001 From: Marvin Date: Sat, 7 Jul 2018 11:12:28 +0200 Subject: [PATCH 01/17] Added new Config class to replace $GLOBALS['config'] --- web/exportbans.php | 3 +- web/includes/Config.php | 32 +++++++++++++++ web/includes/admin.php | 2 +- web/includes/page-builder.php | 2 +- web/includes/sb-callback.php | 20 ++++----- web/includes/system-functions.php | 8 ++-- web/init.php | 17 ++++---- web/pages/admin.bans.php | 4 +- web/pages/admin.bans.search.php | 2 +- web/pages/admin.comms.search.php | 2 +- web/pages/admin.edit.admindetails.php | 2 +- web/pages/admin.edit.admingroup.php | 2 +- web/pages/admin.edit.adminservers.php | 2 +- web/pages/admin.edit.ban.php | 2 +- web/pages/admin.edit.comms.php | 2 +- web/pages/admin.settings.php | 58 +++++++++++++-------------- web/pages/header.php | 6 +-- web/pages/page.banlist.php | 20 ++++----- web/pages/page.commslist.php | 8 ++-- web/pages/page.home.php | 6 +-- web/pages/page.login.php | 2 +- web/pages/page.protest.php | 4 +- web/pages/page.submit.php | 2 +- web/version.json | 6 +-- 24 files changed, 123 insertions(+), 91 deletions(-) create mode 100644 web/includes/Config.php diff --git a/web/exportbans.php b/web/exportbans.php index 50cc28cb0..143a93e28 100644 --- a/web/exportbans.php +++ b/web/exportbans.php @@ -1,7 +1,6 @@ HasAccess(ADMIN_OWNER) && !$exportpublic) { +if (!$userbank->HasAccess(ADMIN_OWNER) && !Config::getBool('config.exportpublic')) { echo "Don't have access to this feature."; } else if (!isset($_GET['type'])) { echo "You have to specify the type. Only follow links!"; diff --git a/web/includes/Config.php b/web/includes/Config.php new file mode 100644 index 000000000..81d6d016e --- /dev/null +++ b/web/includes/Config.php @@ -0,0 +1,32 @@ +query("SELECT * FROM `:prefix_settings`"); + foreach(self::$dbh->resultset() as $data) { + $config[$data['setting']] = $data['value']; + } + return $config; + } +} diff --git a/web/includes/admin.php b/web/includes/admin.php index 981230f1e..2740fd020 100644 --- a/web/includes/admin.php +++ b/web/includes/admin.php @@ -255,7 +255,7 @@ $banTabMenu = new CTabsMenu(); if ($userbank->HasAccess(ADMIN_OWNER|ADMIN_ADD_BAN)) { $banTabMenu->addMenuItem("Add a ban", 0); - if ($GLOBALS['config']['config.enablegroupbanning']==1) { + if (Config::getBool('config.enablegroupbanning')) { $banTabMenu->addMenuItem("Group ban", 4); } } diff --git a/web/includes/page-builder.php b/web/includes/page-builder.php index 9915ab44a..dea61ae67 100644 --- a/web/includes/page-builder.php +++ b/web/includes/page-builder.php @@ -76,7 +76,7 @@ $page = TEMPLATES_PATH . "/page.home.php"; break; default: - switch ($GLOBALS['config']['config.defaultpage']) { + switch (Config::get('config.defaultpage')) { case 1: RewritePageTitle("Ban List"); $page = TEMPLATES_PATH . "/page.banlist.php"; diff --git a/web/includes/sb-callback.php b/web/includes/sb-callback.php index a8a7a395f..6b52a7c3c 100644 --- a/web/includes/sb-callback.php +++ b/web/includes/sb-callback.php @@ -360,7 +360,7 @@ function RemoveGroup($gid, $type) $query0 = $GLOBALS['db']->Execute("DELETE FROM `" . DB_PREFIX . "_srvgroups_overrides` WHERE group_id = $gid"); } - if(isset($GLOBALS['config']['config.enableadminrehashing']) && $GLOBALS['config']['config.enableadminrehashing'] == 1) + if(Config::getBool('config.enableadminrehashing')) { // rehash the settings out of the database on all servers $serveraccessq = $GLOBALS['db']->GetAll("SELECT sid FROM ".DB_PREFIX."_servers WHERE enabled = 1;"); @@ -586,7 +586,7 @@ function RemoveAdmin($aid) $delquery = $GLOBALS['db']->Execute(sprintf("DELETE FROM `%s_admins` WHERE aid = %d LIMIT 1", DB_PREFIX, $aid)); if($delquery) { - if(isset($GLOBALS['config']['config.enableadminrehashing']) && $GLOBALS['config']['config.enableadminrehashing'] == 1) + if(Config::getBool('config.enableadminrehashing')) { // rehash the admins for the servers where this admin was on $serveraccessq = $GLOBALS['db']->GetAll("SELECT s.sid FROM `".DB_PREFIX."_servers` s @@ -1173,7 +1173,7 @@ function AddAdmin($mask, $srv_mask, $a_name, $a_steam, $a_email, $a_password, $a if(!empty($server)) $GLOBALS['db']->Execute($addtosrv,array($aid, $server_admin_group_int, '-1', substr($server, 1))); } - if(isset($GLOBALS['config']['config.enableadminrehashing']) && $GLOBALS['config']['config.enableadminrehashing'] == 1) + if(Config::getBool('config.enableadminrehashing')) { // rehash the admins on the servers $serveraccessq = $GLOBALS['db']->GetAll("SELECT s.sid FROM `".DB_PREFIX."_servers` s @@ -1770,7 +1770,7 @@ function AddBan($nickname, $type, $steam, $ip, $length, $dfile, $dname, $reason, $GLOBALS['db']->Execute("UPDATE `".DB_PREFIX."_submissions` SET archiv = '3', archivedby = '".$userbank->GetAid()."' WHERE SteamId = ?;", array($steam)); - $kickit = isset($GLOBALS['config']['config.enablekickit']) && $GLOBALS['config']['config.enablekickit'] == "1"; + $kickit = Config::getBool('config.enablekickit'); if ($kickit) { $objResponse->addScript("ShowKickBox('".((int)$type==0?$steam:$ip)."', '".(int)$type."');"); } else { @@ -1999,7 +1999,7 @@ function EditAdminPerms($aid, $web_flags, $srv_flags) // Update server stuff $GLOBALS['db']->Execute("UPDATE `".DB_PREFIX."_admins` SET `srv_flags` = ?, `immunity` = ? WHERE `aid` = $aid", array($srv_flags, $immunity)); - if(isset($GLOBALS['config']['config.enableadminrehashing']) && $GLOBALS['config']['config.enableadminrehashing'] == 1) + if(Config::getBool('config.enableadminrehashing')) { // rehash the admins on the servers $serveraccessq = $GLOBALS['db']->GetAll("SELECT s.sid FROM `".DB_PREFIX."_servers` s @@ -2118,7 +2118,7 @@ function EditGroup($gid, $web_flags, $srv_flags, $type, $name, $overrides, $newO } } - if(isset($GLOBALS['config']['config.enableadminrehashing']) && $GLOBALS['config']['config.enableadminrehashing'] == 1) + if(Config::getBool('config.enableadminrehashing')) { // rehash the settings out of the database on all servers $serveraccessq = $GLOBALS['db']->GetAll("SELECT sid FROM ".DB_PREFIX."_servers WHERE enabled = 1;"); @@ -2613,7 +2613,7 @@ function RehashAdmins($server, $do=0) function GroupBan($groupuri, $isgrpurl="no", $queue="no", $reason="", $last="") { $objResponse = new xajaxResponse(); - if($GLOBALS['config']['config.enablegroupbanning']==0) + if(!Config::getBool('config.enablegroupbanning')) return $objResponse; global $userbank, $username; if(!$userbank->HasAccess(ADMIN_OWNER|ADMIN_ADD_BAN)) @@ -2653,7 +2653,7 @@ function BanMemberOfGroup($grpurl, $queue, $reason, $last) { set_time_limit(0); $objResponse = new xajaxResponse(); - if ($GLOBALS['config']['config.enablegroupbanning'] == 0 || !defined('STEAMAPIKEY') || STEAMAPIKEY == '') { + if (!Config::getBool('config.enablegroupbanning') || !defined('STEAMAPIKEY') || STEAMAPIKEY == '') { return $objResponse; } global $userbank, $username; @@ -2746,7 +2746,7 @@ function GetGroups($friendid) { set_time_limit(0); $objResponse = new xajaxResponse(); - if($GLOBALS['config']['config.enablegroupbanning']==0 || !is_numeric($friendid)) + if(!Config::getBool('config.enablegroupbanning') || !is_numeric($friendid)) return $objResponse; global $userbank, $username; if(!$userbank->HasAccess(ADMIN_OWNER|ADMIN_ADD_BAN)) @@ -2825,7 +2825,7 @@ function BanFriends($friendid, $name) global $userbank, $username; $objResponse = new xajaxResponse(); $name = filter_var($name, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); - if ($GLOBALS['config']['config.enablefriendsbanning'] == 0 || !is_numeric($friendid)) { + if (!Config::getBool('config.enablefriendsbanning') || !is_numeric($friendid)) { return $objResponse; } diff --git a/web/includes/system-functions.php b/web/includes/system-functions.php index 5a585e61e..5769ec35b 100644 --- a/web/includes/system-functions.php +++ b/web/includes/system-functions.php @@ -86,7 +86,7 @@ function AddTab($title, $url, $desc, $active=false) $tabs['title'] = $title; $tabs['url'] = $url; $tabs['desc'] = $desc; - if ($_GET['p'] == "default" && $title == $tab_arr[intval($GLOBALS['config']['config.defaultpage'])]) { + if ($_GET['p'] == "default" && $title == $tab_arr[intval(Config::get('config.defaultpage'))]) { $tabs['active'] = true; $GLOBALS['pagetitle'] = $title; } else { @@ -111,13 +111,13 @@ function BuildPageTabs() AddTab("Dashboard", "index.php?p=home", "This page shows an overview of your bans and servers."); AddTab("Servers", "index.php?p=servers", "All of your servers and their status can be viewed here"); AddTab("Bans", "index.php?p=banlist", "All of the bans in the database can be viewed from here."); - if ($GLOBALS['config']['config.enablecomms'] == "1") { + if (Config::getBool('config.enablecomms')) { AddTab("Comms", "index.php?p=commslist", "All of the communication bans (such as chat gags and voice mutes) in the database can be viewed from here."); } - if ($GLOBALS['config']['config.enablesubmit']=="1") { + if (Config::getBool('config.enablesubmit')) { AddTab("Report a Player", "index.php?p=submit", "You can submit a demo or screenshot of a suspected cheater here. It will then be up for review by one of the admins"); } - if ($GLOBALS['config']['config.enableprotest']=="1") { + if (Config::getBool('config.enableprotest')) { AddTab("Appeal a Ban", "index.php?p=protest", "Here you can appeal your ban. And prove your case as to why you should be unbanned."); } if ($userbank->is_admin()) { diff --git a/web/init.php b/web/init.php index ec2ef0041..b9477ac00 100644 --- a/web/init.php +++ b/web/init.php @@ -164,10 +164,6 @@ $mysql_server_info = $GLOBALS['db']->ServerInfo(); $GLOBALS['db_version'] = $mysql_server_info['version']; -$debug = $GLOBALS['db']->Execute("SELECT value FROM `".DB_PREFIX."_settings` WHERE setting = 'config.debug';"); -if ($debug->fields['value']=="1") { - define("DEVELOPER_MODE", true); -} require_once(INCLUDES_PATH.'/SteamID/bootstrap.php'); \SteamID\SteamID::init($GLOBALS['PDO']); @@ -175,6 +171,9 @@ require_once(INCLUDES_PATH.'/Log.php'); Log::init($GLOBALS['PDO']); +require_once(INCLUDES_PATH.'/Config.php'); +Config::init($GLOBALS['PDO']); + // --------------------------------------------------- // Setup our custom error handler // --------------------------------------------------- @@ -301,9 +300,11 @@ function sbError($errno, $errstr, $errfile, $errline) $res->MoveNext(); } -define('SB_BANS_PER_PAGE', $GLOBALS['config']['banlist.bansperpage']); -define('MIN_PASS_LENGTH', $GLOBALS['config']['config.password.minlength']); -$dateformat = !empty($GLOBALS['config']['config.dateformat'])?$GLOBALS['config']['config.dateformat']:"m-d-y H:i"; +define("DEVELOPER_MODE", Config::getBool('config.debug')); +define('SB_BANS_PER_PAGE', Config::get('banlist.bansperpage')); +define('MIN_PASS_LENGTH', Config::get('config.password.minlength')); + +$dateformat = (Config::getBool('config.dateformat')) ? Config::get('config.dateformat') : 'm-d-y H:i'; // --------------------------------------------------- // Setup our templater @@ -312,7 +313,7 @@ function sbError($errno, $errstr, $errfile, $errline) global $theme, $userbank; -$theme_name = isset($GLOBALS['config']['config.theme'])?$GLOBALS['config']['config.theme']:'default'; +$theme_name = (Config::getBool('config.theme')) ? Config::get('config.theme') : 'default'; if (defined("IS_UPDATE")) { $theme_name = "default"; } diff --git a/web/pages/admin.bans.php b/web/pages/admin.bans.php index 62cbfac27..a76e6faf1 100644 --- a/web/pages/admin.bans.php +++ b/web/pages/admin.bans.php @@ -106,7 +106,7 @@ // Add Ban echo ''; @@ -731,7 +731,7 @@ echo '