diff --git a/IsAliveCheck.php b/IsAliveCheck.php index 11f9bd6..4b4b3d8 100644 --- a/IsAliveCheck.php +++ b/IsAliveCheck.php @@ -7,7 +7,6 @@ Alphaland 2021 //vars use Alphaland\Web\WebContextManager; -use Alphaland\Web\WebsiteSettings; $thumbalive = false; $gamealive = false; @@ -20,14 +19,18 @@ function checkThumb($override) { if (!$GLOBALS['thumbalive'] or $override) //to prevent flooding mysql calls { - WebsiteSettings::UpdateSetting('isThumbnailerAlive', true); + $GLOBALS['thumbalive'] = true; + $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET isThumbnailerAlive = 1"); + $set->execute(); } } else //thumb arbiter offline { if ($GLOBALS['thumbalive'] or $override) //to prevent flooding mysql calls { - WebsiteSettings::UpdateSetting('isThumbnailerAlive', false); + $GLOBALS['thumbalive'] = false; + $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET isThumbnailerAlive = 0"); + $set->execute(); } } } @@ -39,14 +42,18 @@ function checkGame($override) { if (!$GLOBALS['gamealive'] or $override) //to prevent flooding mysql calls { - WebsiteSettings::UpdateSetting('IsGameServerAlive', true); + $GLOBALS['gamealive'] = true; + $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET IsGameServerAlive = 1"); + $set->execute(); } } else //gameserver arbiter offline { if ($GLOBALS['gamealive'] or $override) //to prevent flooding mysql calls { - WebsiteSettings::UpdateSetting('IsGameServerAlive', false); + $GLOBALS['gamealive'] = false; + $set = $GLOBALS['pdo']->prepare("UPDATE websettings SET IsGameServerAlive = 0"); + $set->execute(); } } } diff --git a/globals/Dependencies/Games/Game.php b/globals/Dependencies/Games/Game.php index 297f97b..833c45d 100644 --- a/globals/Dependencies/Games/Game.php +++ b/globals/Dependencies/Games/Game.php @@ -8,7 +8,6 @@ namespace Alphaland\Games { use Alphaland\Assets\Asset; use Alphaland\Grid\RccServiceHelper; - use Alphaland\Web\WebsiteSettings; use Exception; use PDO; @@ -231,7 +230,12 @@ namespace Alphaland\Games { public static function ArbiterOnline() //the main portion of this check is now a background script { - return WebsiteSettings::GetSetting("isGameServerAlive"); + $check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM websettings WHERE isGameServerAlive = 1"); + $check->execute(); + if ($check->fetchColumn() > 0) { + return true; + } + return false; } public static function RemovePersonalBuildServerRank(int $placeid, int $userid) diff --git a/globals/Dependencies/Web/WebContextManager.php b/globals/Dependencies/Web/WebContextManager.php index 44da04e..ca6f0e0 100644 --- a/globals/Dependencies/Web/WebContextManager.php +++ b/globals/Dependencies/Web/WebContextManager.php @@ -15,7 +15,7 @@ namespace Alphaland\Web { public static function IsCurrentIpAddressWhitelisted() { $currentIp = WebContextManager::GetCurrentIPAddress(); - $ipWhitelist = explode(";", WebsiteSettings::GetSetting("webservice_whitelist", "127.0.0.0/8;192.168.0.0/16;10.0.0.0/8")); + $ipWhitelist = explode(";", $GLOBALS['ws']->webservice_whitelist); return IpHelper::IsIpInCidrNetmaskOrRangeList($currentIp, $ipWhitelist); } @@ -27,10 +27,13 @@ namespace Alphaland\Web { public static function IsUnderMaintenance(bool $status = false) { - $isUnderMaintenance = WebsiteSettings::GetSetting('maintenance'); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM `websettings` WHERE `maintenance` = 1"); + $query->execute(); - if ($isUnderMaintenance === true) { - if ($status) return true; + if ($query->rowCount() > 0) { + if ($status) { + return true; + } return !WebContextManager::CanBypassMaintenance(); } return false; @@ -54,8 +57,13 @@ namespace Alphaland\Web { if (!empty($accesskey)) { - if(WebContextManager::IsCurrentIpAddressWhitelisted()) - return $accesskey == WebsiteSettings::GetSetting('webservice_key', null); + if(WebContextManager::IsCurrentIpAddressWhitelisted()) + { + if($accesskey == $GLOBALS['ws']->webservice_key) + { + return true; + } + } } return false; } diff --git a/globals/Dependencies/Web/WebsiteSettings.php b/globals/Dependencies/Web/WebsiteSettings.php index 7226eab..aee1a37 100644 --- a/globals/Dependencies/Web/WebsiteSettings.php +++ b/globals/Dependencies/Web/WebsiteSettings.php @@ -14,7 +14,7 @@ namespace Alphaland\Web { use PDO; - class WebsiteSettings + /* public static */ 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_v2` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT `value`, `type` FROM `websettings` WHERE `name` = :name"); $query->bindParam(':name', $name); if (!$query->execute()) { @@ -99,6 +99,24 @@ 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. * @@ -133,9 +151,9 @@ namespace Alphaland\Web { $query = null; if ($remote === self::DOES_NOT_EXIST) { - $query = $GLOBALS['pdo']->prepare("INSERT INTO `websettings_v2` (`name`, `value`, `type`) VALUES (:name, :value, :type)"); + $query = $GLOBALS['pdo']->prepare("INSERT INTO `websettings` (`name`, `value`, `type`) VALUES (:name, :value, :type)"); } else { - $query = $GLOBALS['pdo']->prepare("UPDATE `websettings_v2` SET `value` = :value, `type` = :type WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("UPDATE `websettings` SET `value` = :value, `type` = :type WHERE `name` = :name"); } if (gettype($value) === 'NULL') { @@ -161,7 +179,7 @@ namespace Alphaland\Web { */ public static function DeleteSetting(string $name): bool { - $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings_v2` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings` WHERE `name` = :name"); $query->bindParam(':name', $name); return $query->execute(); @@ -174,7 +192,7 @@ namespace Alphaland\Web { */ public static function GetAllSettings(): array { - $query = $GLOBALS['pdo']->prepare("SELECT `name`, `value`, `type` FROM `websettings_v2`"); + $query = $GLOBALS['pdo']->prepare("SELECT `name`, `value`, `type` FROM `websettings`"); if (!$query->execute()) { return []; @@ -200,7 +218,7 @@ namespace Alphaland\Web { */ public static function SettingExists(string $name): bool { - $query = $GLOBALS['pdo']->prepare("SELECT `name` FROM `websettings_v2` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT `name` FROM `websettings` WHERE `name` = :name"); $query->bindParam(':name', $name); if (!$query->execute()) { @@ -219,7 +237,7 @@ namespace Alphaland\Web { */ public static function DeleteAllSettings(): bool { - $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings_v2`"); + $query = $GLOBALS['pdo']->prepare("DELETE FROM `websettings`"); return $query->execute(); } diff --git a/globals/config.php b/globals/config.php index affb3de..3b1183e 100644 --- a/globals/config.php +++ b/globals/config.php @@ -42,7 +42,7 @@ try $siteName = "Alphaland"; //site name $domain = "alphaland.cc"; $url = "https://www.".$domain; //site URL - //websettings + $ws = $pdo->query("SELECT * FROM websettings WHERE id = 1")->fetch(PDO::FETCH_OBJ); //websettings $clientUserAgent = "Roblox/WinInet"; $ROBLOXAssetAPI = "https://assetdelivery.roblox.com/v1/asset/?id="; $ROBLOXProductInfoAPI = "https://api.roblox.com/marketplace/productinfo?assetId="; diff --git a/globals/functions.php b/globals/functions.php index 5c57ff7..544eca5 100644 --- a/globals/functions.php +++ b/globals/functions.php @@ -12,7 +12,6 @@ use Alphaland\Games\Game; use Alphaland\Moderation\Filter; use Alphaland\Users\Render as UsersRender; use Alphaland\Web\WebContextManager; -use Alphaland\Web\WebsiteSettings; //safe generation utilities @@ -1496,7 +1495,14 @@ function rewardUserBadge($UserID, $BadgeID, $PlaceID) function isThumbnailerAlive() //the main portion of this check is now a background script { - return WebsiteSettings::GetSetting("isThumbnailerAlive"); + $check = $GLOBALS['pdo']->prepare("SELECT * FROM websettings WHERE isThumbnailerAlive = 1"); + $check->execute(); + + if ($check->rowCount() > 0) + { + return true; + } + return false; } function verifyLuaValue($value) //mostly due to booleans, but maybe something will come up in the future @@ -2376,18 +2382,22 @@ function userPlaceVisits($userid) function enableMaintenance($custom) { - if (!empty($custom)) - WebsiteSettings::UpdateSetting("maintenance_text", $custom); - - WebsiteSettings::UpdateSetting("maintenance", true); + 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(); + } soapCloseAllJobs($GLOBALS['gamesArbiter']); } function disableMaintenance() { - WebsiteSettings::UpdateSetting("maintenance", false); - WebsiteSettings::UpdateSetting("maintenance_text", ""); + $setmaintenance = $GLOBALS['pdo']->prepare("UPDATE websettings SET maintenance = 0, maintenance_text = ''"); + $setmaintenance->execute(); } function setUserRank($rank, $userid) @@ -2841,36 +2851,43 @@ function getNav() function fetchAnnouncement() { - $announcement = WebsiteSettings::GetSetting("announcement"); - - if (empty($announcement)) return ""; - - $cleanAnnouncement = cleanOutput($announcement); //clean output - - $announcement_color = WebsiteSettings::GetSetting("announcement_color"); - - $html = ""; - - switch ($announcement_color) + $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)) { - case "red": - $html = ""; - break; - case "green": - $html = ""; - break; - case "blue": - default: - $html = ""; - break; + return ""; + } + else + { + $html = ""; + if ($announcementquery->announcement_color == "red") + { + $html = ""; + } + elseif ($announcementquery->announcement_color == "blue") + { + $html = ""; + } + elseif ($announcementquery->announcement_color == "green") + { + $html = ""; + } + return $html; } - - return $html; } function canRegister() { - return WebsiteSettings::GetSetting("registration", false); + $check = $GLOBALS['pdo']->prepare("SELECT * FROM websettings WHERE registration = 1"); + $check->execute(); + + if($check->rowCount() > 0) + { + return true; + } + return false; } function adminPanelStats() { diff --git a/html/asset/index.php b/html/asset/index.php index 0dd27ad..30faa95 100644 --- a/html/asset/index.php +++ b/html/asset/index.php @@ -32,6 +32,10 @@ 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 04328f6..0e05914 100644 --- a/html/download.php +++ b/html/download.php @@ -1,13 +1,8 @@ AlphalandVersion."-AlphalandLauncher.exe"; header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=AlphalandLauncher.exe"); echo file_get_contents($loc); @@ -15,7 +10,7 @@ if (isset($_POST['SubmitClient'])) if (isset($_POST['SubmitStudio'])) { - $loc = $GLOBALS['setupHtmlPath'].$alphalandStudioVersion."-AlphalandStudioLauncher.exe"; + $loc = $GLOBALS['setupHtmlPath'].$ws->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 08028a7..75be226 100644 --- a/html/maintenance.php +++ b/html/maintenance.php @@ -1,12 +1,25 @@ 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 +} $body = << @@ -41,8 +54,8 @@ body {
-

{$maintenance_text}

+

{$status}

EOT; -echo $body; +echo $body; \ No newline at end of file diff --git a/html_admin/announcements.php b/html_admin/announcements.php index 7b55122..859ae23 100644 --- a/html_admin/announcements.php +++ b/html_admin/announcements.php @@ -1,7 +1,6 @@ prepare('UPDATE websettings SET announcement = "", announcement_color = ""'); + $setsecmd5->execute(); } else { @@ -47,8 +47,10 @@ if (isset($_POST['setannouncement'])) { $color = "red"; } - WebsiteSettings::UpdateSetting('announcement', $_POST['setannouncement']); - WebsiteSettings::UpdateSetting('announcement_color', $color); + $setsecmd5 = $pdo->prepare("UPDATE websettings SET announcement = :m, announcement_color = :c"); + $setsecmd5->bindParam(":m", $_POST['setannouncement'], PDO::PARAM_STR); + $setsecmd5->bindParam(":c", $color, PDO::PARAM_STR); + $setsecmd5->execute(); } } } diff --git a/html_admin/client-deployer-upload.php b/html_admin/client-deployer-upload.php index 3e14354..0bd3d48 100644 --- a/html_admin/client-deployer-upload.php +++ b/html_admin/client-deployer-upload.php @@ -1,7 +1,6 @@ AlphalandVersion; } else if ($deploytype == "studio") { - $previousdeployversion = WebsiteSettings::GetSetting("AlphalandStudioVersion"); + $previousdeployversion = $ws->AlphalandStudioVersion; } //deploy type specific stuff @@ -169,13 +168,17 @@ if ($pass) { //update in db if ($deploytype == "client") { - WebsiteSettings::UpdateSetting("AlphalandVersion", $newgameversion); - WebsiteSettings::UpdateSetting("security_version", $gamesecurityversion); - WebsiteSettings::UpdateSetting("md5_hash", $gamemd5hash); - WebsiteSettings::UpdateSetting("GameFileVersion", $gamefileversion); + $updatewebsettings = $pdo->prepare("UPDATE websettings SET AlphalandVersion = :av, security_version = :sv, md5_hash = :mh, GameFileVersion = :gv"); + $updatewebsettings->bindParam(":av", $newgameversion, PDO::PARAM_STR); + $updatewebsettings->bindParam(":sv", $gamesecurityversion, PDO::PARAM_STR); + $updatewebsettings->bindParam(":mh", $gamemd5hash, PDO::PARAM_STR); + $updatewebsettings->bindParam(":gv", $gamefileversion, PDO::PARAM_STR); + $updatewebsettings->execute(); } else if ($deploytype == "studio") { - WebsiteSettings::UpdateSetting("AlphalandStudioVersion", $newgameversion); - WebsiteSettings::UpdateSetting("StudioFileVersion", $gamefileversion); + $updatewebsettings = $pdo->prepare("UPDATE websettings SET AlphalandStudioVersion = :asv, StudioFileVersion = :sfv"); + $updatewebsettings->bindParam(":asv", $newgameversion, PDO::PARAM_STR); + $updatewebsettings->bindParam(":sfv", $gamefileversion, PDO::PARAM_STR); + $updatewebsettings->execute(); } //output the new version diff --git a/html_admin/client-deployer.php b/html_admin/client-deployer.php index 183b380..9e3a6c6 100644 --- a/html_admin/client-deployer.php +++ b/html_admin/client-deployer.php @@ -1,11 +1,10 @@ IsOwner())) { +if(!($user->IsOwner())) { if ($user->IsAdmin()) { WebContextManager::Redirect("/"); } @@ -14,14 +13,11 @@ if (!($user->IsOwner())) { adminPanelStats(); -$securityVersion = WebsiteSettings::GetSetting('security_version'); -$md5Hash = WebsiteSettings::GetSetting('md5_hash'); -$gameFileVersion = WebsiteSettings::GetSetting('GameFileVersion'); -$studioFileVersion = WebsiteSettings::GetSetting('StudioFileVersion'); - - -$body = << + {$alert}
Network Security Key Generator
MAKE SURE TO DEPLOY RCC WITH UPDATED KEY
@@ -34,7 +30,7 @@ $body = <<Game Security Version
- +
Generated Security Key
@@ -79,19 +75,19 @@ $body = <<Game Executable Security Version
- +
Game Executable MD5 Hash
- +
Game Executable Version (separated by '.')
- +
Game Launcher File Version (separated by ',') Ex:1, 2, 3, 4
@@ -136,7 +132,7 @@ $body = <<Studio Executable Version (separated by '.')
- +
Studio Launcher File Version (separated by ',')
@@ -206,8 +202,8 @@ $body = <<pagetitle = ""; +$ph->pagetitle = ""; $ph->navbar = ""; $ph->body = $body; $ph->footer = ""; -$ph->output(); +$ph->output(); \ No newline at end of file diff --git a/html_admin/configuration.php b/html_admin/configuration.php index ef0c360..5f83bad 100644 --- a/html_admin/configuration.php +++ b/html_admin/configuration.php @@ -1,7 +1,6 @@ prepare("SELECT * FROM websettings WHERE maintenance = 1"); +$maintenancequery->execute(); + +$status = $pdo->prepare("SELECT * FROM websettings WHERE maintenance = 1"); +$status->execute(); + +$websettings = $pdo->prepare("SELECT * FROM websettings"); +$websettings->execute(); +$websettings = $websettings->fetch(PDO::FETCH_OBJ); ////end db queries ////Third party web queries @@ -122,31 +127,43 @@ if (isset($_POST['clearcachesubmit'])) if (isset($_POST['submitwskey'])) { $key = genHash(16); - WebsiteSettings::UpdateSetting("webservice_key", $key); + $setwskey = $pdo->prepare("UPDATE websettings SET webservice_key = :k"); + $setwskey->bindParam(":k", $key, PDO::PARAM_STR); + $setwskey->execute(); WebContextManager::Redirect("configuration"); } if (isset($_POST['setwsipwhitelist'])) { - WebsiteSettings::UpdateSetting("webservice_whitelist", $_POST['setwsipwhitelist']); + $setwsip = $pdo->prepare("UPDATE websettings SET webservice_whitelist = :w"); + $setwsip->bindParam(":w", $_POST['setwsipwhitelist'], PDO::PARAM_STR); + $setwsip->execute(); WebContextManager::Redirect("configuration"); } if (isset($_POST['cachingon'])) { - WebsiteSettings::UpdateSetting("avatarCaching", true); + $setapprovals = $pdo->prepare("UPDATE websettings SET avatarCaching = 1"); + $setapprovals->execute(); WebContextManager::Redirect("configuration"); } if (isset($_POST['cachingoff'])) { - WebsiteSettings::UpdateSetting("avatarCaching", false); + $setapprovals = $pdo->prepare("UPDATE websettings SET avatarCaching = 0"); + $setapprovals->execute(); WebContextManager::Redirect("configuration"); } -$maintenancestatus = 'OFF'; -if ($isUnderMaitenance === true) +$maintenancestatus = ""; +if ($maintenancequery->rowCount() > 0) +{ $maintenancestatus = 'ON'; +} +else +{ + $maintenancestatus = 'OFF'; +} $developmentmodestatus = ""; if ($devmode) @@ -219,7 +236,7 @@ $body = <<
- +
@@ -245,7 +262,7 @@ $body = <<
-
Current Backend Whitelisted IP's:
{$ipWhitelist}
+
Current Backend Whitelisted IP's:
{$websettings->webservice_whitelist}

diff --git a/html_clientsettings/Setting/QuietGet/WindowsBootstrapperSettings.php b/html_clientsettings/Setting/QuietGet/WindowsBootstrapperSettings.php index 313884f..8905833 100644 --- a/html_clientsettings/Setting/QuietGet/WindowsBootstrapperSettings.php +++ b/html_clientsettings/Setting/QuietGet/WindowsBootstrapperSettings.php @@ -1,7 +1,3 @@ GameFileVersion.'", "ValidateInstalledExeVersion": "True", "ShowInstallSuccessPrompt": "True"}'; \ No newline at end of file diff --git a/html_setup/BootstrapperSettings.php b/html_setup/BootstrapperSettings.php index 313884f..8905833 100644 --- a/html_setup/BootstrapperSettings.php +++ b/html_setup/BootstrapperSettings.php @@ -1,7 +1,3 @@ GameFileVersion.'", "ValidateInstalledExeVersion": "True", "ShowInstallSuccessPrompt": "True"}'; \ No newline at end of file diff --git a/html_setup/version.php b/html_setup/version.php index 666dc30..8f9067f 100644 --- a/html_setup/version.php +++ b/html_setup/version.php @@ -1,5 +1,3 @@ AlphalandVersion; \ No newline at end of file diff --git a/html_setup/versionQTStudio.php b/html_setup/versionQTStudio.php index 4cf93a0..3fe5b0f 100644 --- a/html_setup/versionQTStudio.php +++ b/html_setup/versionQTStudio.php @@ -1,5 +1,3 @@ AlphalandStudioVersion; \ No newline at end of file diff --git a/html_versioncompatibility/GetAllowedMD5Hashes.php b/html_versioncompatibility/GetAllowedMD5Hashes.php index 3a448e7..25be55b 100644 --- a/html_versioncompatibility/GetAllowedMD5Hashes.php +++ b/html_versioncompatibility/GetAllowedMD5Hashes.php @@ -1,7 +1,6 @@ array( - WebsiteSettings::GetSetting("md5_hash"), + $ws->md5_hash ) ), JSON_UNESCAPED_SLASHES); diff --git a/html_versioncompatibility/GetAllowedSecurityKeys.php b/html_versioncompatibility/GetAllowedSecurityKeys.php index d9b8ae7..4d72faa 100644 --- a/html_versioncompatibility/GetAllowedSecurityKeys.php +++ b/html_versioncompatibility/GetAllowedSecurityKeys.php @@ -1,7 +1,6 @@ array( - WebsiteSettings::GetSetting("security_version"), + $ws->security_version ) ), JSON_UNESCAPED_SLASHES); \ No newline at end of file