diff --git a/IsAliveCheck.php b/IsAliveCheck.php index 4b4b3d8..11f9bd6 100644 --- a/IsAliveCheck.php +++ b/IsAliveCheck.php @@ -7,6 +7,7 @@ Alphaland 2021 //vars use Alphaland\Web\WebContextManager; +use Alphaland\Web\WebsiteSettings; $thumbalive = false; $gamealive = false; @@ -19,18 +20,14 @@ function checkThumb($override) { if (!$GLOBALS['thumbalive'] or $override) //to prevent flooding mysql calls { - $GLOBALS['thumbalive'] = true; - $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET isThumbnailerAlive = 1"); - $set->execute(); + WebsiteSettings::UpdateSetting('isThumbnailerAlive', true); } } else //thumb arbiter offline { if ($GLOBALS['thumbalive'] or $override) //to prevent flooding mysql calls { - $GLOBALS['thumbalive'] = false; - $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET isThumbnailerAlive = 0"); - $set->execute(); + WebsiteSettings::UpdateSetting('isThumbnailerAlive', false); } } } @@ -42,18 +39,14 @@ function checkGame($override) { if (!$GLOBALS['gamealive'] or $override) //to prevent flooding mysql calls { - $GLOBALS['gamealive'] = true; - $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET IsGameServerAlive = 1"); - $set->execute(); + WebsiteSettings::UpdateSetting('IsGameServerAlive', true); } } else //gameserver arbiter offline { if ($GLOBALS['gamealive'] or $override) //to prevent flooding mysql calls { - $GLOBALS['gamealive'] = false; - $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET IsGameServerAlive = 0"); - $set->execute(); + WebsiteSettings::UpdateSetting('IsGameServerAlive', false); } } } diff --git a/globals/Dependencies/Games/Game.php b/globals/Dependencies/Games/Game.php index b60c084..21d014c 100644 --- a/globals/Dependencies/Games/Game.php +++ b/globals/Dependencies/Games/Game.php @@ -8,6 +8,7 @@ namespace Alphaland\Games { use Alphaland\Assets\Asset; use Alphaland\Grid\RccServiceHelper; + use Alphaland\Web\WebsiteSettings; use Exception; use PDO; @@ -230,12 +231,7 @@ namespace Alphaland\Games { public static function ArbiterOnline() //the main portion of this check is now a background script { - $check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM websettings WHERE isGameServerAlive = 1"); - $check->execute(); - if ($check->fetchColumn() > 0) { - return true; - } - return false; + return WebsiteSettings::GetSetting("isGameServerAlive"); } public static function PersonalBuildRankToName($rank) diff --git a/globals/Dependencies/Web/WebContextManager.php b/globals/Dependencies/Web/WebContextManager.php index 1d23d5a..5201449 100644 --- a/globals/Dependencies/Web/WebContextManager.php +++ b/globals/Dependencies/Web/WebContextManager.php @@ -14,7 +14,7 @@ namespace Alphaland\Web { public static function IsCurrentIpAddressWhitelisted() { $currentIp = WebContextManager::GetCurrentIPAddress(); - $ipWhitelist = explode(";", $GLOBALS['ws']->webservice_whitelist); + $ipWhitelist = explode(";", WebsiteSettings::GetSetting("webservice_whitelist", "127.0.0.0/8;192.168.0.0/16;10.0.0.0/8")); return in_array($currentIp, $ipWhitelist); } @@ -26,13 +26,10 @@ namespace Alphaland\Web { public static function IsUnderMaintenance(bool $status = false) { - $query = $GLOBALS['pdo']->prepare("SELECT * FROM `websettings` WHERE `maintenance` = 1"); - $query->execute(); + $isUnderMaintenance = WebsiteSettings::GetSetting('maintenance'); - if ($query->rowCount() > 0) { - if ($status) { - return true; - } + if ($isUnderMaintenance === true) { + if ($status) return true; return !WebContextManager::CanBypassMaintenance(); } return false; @@ -56,13 +53,8 @@ namespace Alphaland\Web { if (!empty($accesskey)) { - if(WebContextManager::IsCurrentIpAddressWhitelisted()) - { - if($accesskey == $GLOBALS['ws']->webservice_key) - { - return true; - } - } + if(WebContextManager::IsCurrentIpAddressWhitelisted()) + return $accesskey == WebsiteSettings::GetSetting('webservice_key', null); } return false; } diff --git a/globals/Dependencies/Web/WebsiteSettings.php b/globals/Dependencies/Web/WebsiteSettings.php index 293c723..eea4010 100644 --- a/globals/Dependencies/Web/WebsiteSettings.php +++ b/globals/Dependencies/Web/WebsiteSettings.php @@ -15,7 +15,7 @@ namespace Alphaland\Web { use PDO; - /* public static */ class WebsiteSettings + class WebsiteSettings { // default return if no settings are found // because there may be a NULL value in the database @@ -84,7 +84,7 @@ namespace Alphaland\Web { */ public static function GetSetting(string $name, $default = null) { - $query = $GLOBALS['pdo']->prepare("SELECT `value`, `type` FROM `websettings` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT `value`, `type` FROM `websettings_v2` WHERE `name` = :name"); $query->bindParam(':name', $name); if (!$query->execute()) { @@ -99,24 +99,6 @@ namespace Alphaland\Web { return self::ConvertStringToValue($result['value'], $result['type']); } - /** - * Gets or sets the value of a website setting. - * - * @param string $name The name of the setting. - * @param mixed $value The value of the setting. - * @param string $type The type of the setting. - * - * @return mixed The value of the setting. - */ - public static function GetOrCreateSetting(string $name, $value = null, string $type = null) - { - if (!self::SettingExists($name)) { - self::UpdateSetting($name, $value, $type); - } - - return self::GetSetting($name); - } - /** * Sets a website setting. * @@ -151,9 +133,9 @@ namespace Alphaland\Web { $query = null; if ($remote === self::DOES_NOT_EXIST) { - $query = $GLOBALS['pdo']->prepare("INSERT INTO `websettings` (`name`, `value`, `type`) VALUES (:name, :value, :type)"); + $query = $GLOBALS['pdo']->prepare("INSERT INTO `websettings_v2` (`name`, `value`, `type`) VALUES (:name, :value, :type)"); } else { - $query = $GLOBALS['pdo']->prepare("UPDATE `websettings` SET `value` = :value, `type` = :type WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("UPDATE `websettings_v2` SET `value` = :value, `type` = :type WHERE `name` = :name"); } if (gettype($value) === 'NULL') { @@ -179,7 +161,7 @@ namespace Alphaland\Web { */ public static function DeleteSetting(string $name): bool { - $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings_v2` WHERE `name` = :name"); $query->bindParam(':name', $name); return $query->execute(); @@ -192,7 +174,7 @@ namespace Alphaland\Web { */ public static function GetAllSettings(): array { - $query = $GLOBALS['pdo']->prepare("SELECT `name`, `value`, `type` FROM `websettings`"); + $query = $GLOBALS['pdo']->prepare("SELECT `name`, `value`, `type` FROM `websettings_v2`"); if (!$query->execute()) { return []; @@ -218,7 +200,7 @@ namespace Alphaland\Web { */ public static function SettingExists(string $name): bool { - $query = $GLOBALS['pdo']->prepare("SELECT `name` FROM `websettings` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT `name` FROM `websettings_v2` WHERE `name` = :name"); $query->bindParam(':name', $name); if (!$query->execute()) { @@ -237,7 +219,7 @@ namespace Alphaland\Web { */ public static function DeleteAllSettings(): bool { - $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings`"); + $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings_v2`"); return $query->execute(); } diff --git a/globals/config.php b/globals/config.php index 587b0e9..8ea3153 100644 --- a/globals/config.php +++ b/globals/config.php @@ -41,7 +41,7 @@ try $siteName = "Alphaland"; //site name $domain = "alphaland.cc"; $url = "https://www.".$domain; //site URL - $ws = $pdo->query("SELECT * FROM websettings WHERE id = 1")->fetch(PDO::FETCH_OBJ); //websettings + //websettings $clientUserAgent = "Roblox/WinInet"; $ROBLOXAssetAPI = "https://assetdelivery.roblox.com/v1/asset/?id="; $ROBLOXProductInfoAPI = "https://api.roblox.com/marketplace/productinfo?assetId="; @@ -124,6 +124,7 @@ try include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Administration/SignupKey.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Economy/EconomyHelper.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Groups/Group.php"; + include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Web/WebsiteSettings.php"; //authenticator $authenticator = new PHPGangsta_GoogleAuthenticator(); diff --git a/globals/functions.php b/globals/functions.php index e24f10f..5c66b31 100644 --- a/globals/functions.php +++ b/globals/functions.php @@ -12,6 +12,7 @@ use Alphaland\Moderation\Filter; use Alphaland\Users\Render as UsersRender; use Alphaland\Users\User; use Alphaland\Web\WebContextManager; +use Alphaland\Web\WebsiteSettings; //safe generation utilities @@ -1528,14 +1529,7 @@ function rewardUserBadge($UserID, $BadgeID, $PlaceID) function isThumbnailerAlive() //the main portion of this check is now a background script { - $check = $GLOBALS['pdo']->prepare("SELECT * FROM websettings WHERE isThumbnailerAlive = 1"); - $check->execute(); - - if ($check->rowCount() > 0) - { - return true; - } - return false; + return WebsiteSettings::GetSetting("isThumbnailerAlive"); } function verifyLuaValue($value) //mostly due to booleans, but maybe something will come up in the future @@ -2536,22 +2530,18 @@ function userPlaceVisits($userid) function enableMaintenance($custom) { - if (!empty($custom)) { - $setmaintenance = $GLOBALS['pdo']->prepare("UPDATE websettings SET maintenance = 1, maintenance_text = :t"); - $setmaintenance->bindParam(":t", $custom, PDO::PARAM_STR); - $setmaintenance->execute(); - } else { - $setmaintenance = $GLOBALS['pdo']->prepare("UPDATE websettings SET maintenance = 1"); - $setmaintenance->execute(); - } + if (!empty($custom)) + WebsiteSettings::UpdateSetting("maintenance_text", $custom); + + WebsiteSettings::UpdateSetting("maintenance", true); soapCloseAllJobs($GLOBALS['gamesArbiter']); } function disableMaintenance() { - $setmaintenance = $GLOBALS['pdo']->prepare("UPDATE websettings SET maintenance = 0, maintenance_text = ''"); - $setmaintenance->execute(); + WebsiteSettings::UpdateSetting("maintenance", false); + WebsiteSettings::UpdateSetting("maintenance_text", ""); } function setUserRank($rank, $userid) @@ -3005,43 +2995,36 @@ function getNav() function fetchAnnouncement() { - $announcementquery = $GLOBALS['pdo']->prepare("SELECT * FROM websettings"); - $announcementquery->execute(); - $announcementquery = $announcementquery->fetch(PDO::FETCH_OBJ); - $announcement = cleanOutput($announcementquery->announcement); //clean output - if (empty($announcementquery->announcement)) + $announcement = WebsiteSettings::GetSetting("announcement"); + + if (empty($announcement)) return ""; + + $cleanAnnouncement = cleanOutput($announcement); //clean output + + $announcement_color = WebsiteSettings::GetSetting("announcement_color"); + + $html = ""; + + switch ($announcement_color) { - return ""; - } - else - { - $html = ""; - if ($announcementquery->announcement_color == "red") - { - $html = "
"; - } - elseif ($announcementquery->announcement_color == "blue") - { - $html = ""; - } - elseif ($announcementquery->announcement_color == "green") - { - $html = ""; - } - return $html; + case "red": + $html = ""; + break; + case "green": + $html = ""; + break; + case "blue": + default: + $html = ""; + break; } + + return $html; } function canRegister() { - $check = $GLOBALS['pdo']->prepare("SELECT * FROM websettings WHERE registration = 1"); - $check->execute(); - - if($check->rowCount() > 0) - { - return true; - } - return false; + return WebsiteSettings::GetSetting("registration", false); } function adminPanelStats() { diff --git a/html/asset/index.php b/html/asset/index.php index 30faa95..0dd27ad 100644 --- a/html/asset/index.php +++ b/html/asset/index.php @@ -32,10 +32,6 @@ function ReturnAsset($hash, $assettypeid) //this determines which cdn to grab an ReturnAssetFromHash($hash); } } - -$websettings = $pdo->prepare("SELECT * FROM websettings"); -$websettings->execute(); -$websettings = $websettings->fetch(PDO::FETCH_OBJ); if ($id) { diff --git a/html/download.php b/html/download.php index 0e05914..04328f6 100644 --- a/html/download.php +++ b/html/download.php @@ -1,8 +1,13 @@ AlphalandVersion."-AlphalandLauncher.exe"; + $loc = $GLOBALS['setupHtmlPath'].$alphalandVersion."-AlphalandLauncher.exe"; header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=AlphalandLauncher.exe"); echo file_get_contents($loc); @@ -10,7 +15,7 @@ if (isset($_POST['SubmitClient'])) if (isset($_POST['SubmitStudio'])) { - $loc = $GLOBALS['setupHtmlPath'].$ws->AlphalandStudioVersion."-AlphalandStudioLauncher.exe"; + $loc = $GLOBALS['setupHtmlPath'].$alphalandStudioVersion."-AlphalandStudioLauncher.exe"; header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=AlphalandStudioLauncher.exe"); echo file_get_contents($loc); diff --git a/html/maintenance.php b/html/maintenance.php index 75be226..08028a7 100644 --- a/html/maintenance.php +++ b/html/maintenance.php @@ -1,25 +1,12 @@ prepare("SELECT * FROM websettings"); -$websettings->execute(); -$websettings = $websettings->fetch(PDO::FETCH_OBJ); - -$status = ''; -if (!empty($websettings->maintenance_text)) -{ - $status = $websettings->maintenance_text; //use custom text -} -else -{ - $status = $websettings->default_maintenance_text; //default maintenance text -} +$maintenance_text = WebsiteSettings::GetSetting('maintenance_text') ?? WebsiteSettings::GetSetting("default_maintenance_text"); $body = <<
-