From 8dd212314af90d7a018b49c3e1f0b86bb1940480 Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Fri, 31 Dec 2021 06:14:13 +0000 Subject: [PATCH] Everything ClientSettings! Updated client settings to do binary comparison when finding application buckets etc (this will allow case sensitive naming, like ABC and abc are 2 different buckets) Added a message to ClientAppSettings.php, please read it and implement what it says onto said clients Added GetSetting.php, like roblox's https://clientsettings.api.roblox.com/v1/GetSetting?key=applicationName (503 for apiKey failure) --- .../Dependencies/Client/ClientSettings.php | 55 ++++++++++++------ globals/config.php | 1 + .../Setting/QuietGet/ClientAppSettings.php | 5 ++ html_clientsettings/v1/GetSetting.php | 58 +++++++++++++++++++ 4 files changed, 100 insertions(+), 19 deletions(-) create mode 100644 html_clientsettings/v1/GetSetting.php diff --git a/globals/Dependencies/Client/ClientSettings.php b/globals/Dependencies/Client/ClientSettings.php index 6dda81f..0a1a1dd 100644 --- a/globals/Dependencies/Client/ClientSettings.php +++ b/globals/Dependencies/Client/ClientSettings.php @@ -115,7 +115,7 @@ namespace Alphaland\Client { public static function ApplicationExists(string $applicationName) { // get the application - $query = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `clientsettings_applications` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `clientsettings_applications` WHERE BINARY `name` = :name"); $query->bindParam(':name', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -134,7 +134,7 @@ namespace Alphaland\Client { public static function ApplicationRequiresIpWhitelist(string $applicationName) { // get the application - $query = $GLOBALS['pdo']->prepare("SELECT `requires_ip_whitelist` FROM `clientsettings_applications` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT `requires_ip_whitelist` FROM `clientsettings_applications` WHERE BINARY `name` = :name"); $query->bindParam(':name', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -154,7 +154,7 @@ namespace Alphaland\Client { public static function ApplicationRequiresRccServiceAuthentication(string $applicationName) { // get the application - $query = $GLOBALS['pdo']->prepare("SELECT `requires_rcc_service_authentication` FROM `clientsettings_applications` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT `requires_rcc_service_authentication` FROM `clientsettings_applications` WHERE BINARY `name` = :name"); $query->bindParam(':name', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -173,7 +173,7 @@ namespace Alphaland\Client { public static function GetApplication(string $applicationName) { // get the application - $query = $GLOBALS['pdo']->prepare("SELECT * FROM `clientsettings_applications` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM `clientsettings_applications` WHERE BINARY `name` = :name"); $query->bindParam(':name', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -193,7 +193,8 @@ namespace Alphaland\Client { $deps = array_map('trim', $deps); } } - // return the application + // special case here, because we want to make it return the dependencies as an array to prevent further processing down the line + // the null coalesce to null is to prevent undefined index errors return array( 'id' => $data['id'] ?? null, 'name' => $data['name'] ?? null, @@ -214,7 +215,11 @@ namespace Alphaland\Client { * @param bool $canBeFetchedFromClientsettingsService True if the ClientSettings Application can be fetched from the Clientsettings Service, false otherwise. * @param array $dependencies An array of ClientSettings Application Names that are dependencies of this ClientSettings Application. */ - public static function CreateApplication(string $applicationName, bool $requiresIpWhitelist = false, bool $requiresRccServiceAuthentication = false, bool $canBeFetchedFromClientSettingsService = true, array $dependencies = []) + public static function CreateApplication(string $applicationName, + bool $requiresIpWhitelist = false, + bool $requiresRccServiceAuthentication = false, + bool $canBeFetchedFromClientSettingsService = true, + array $dependencies = []) { // check if the application already exists if (self::ApplicationExists($applicationName)) { @@ -249,7 +254,11 @@ namespace Alphaland\Client { * @param bool $canBeFetchedFromClientSettingsService The canBeFetchedFromClientSettingsService flag. * @param array $dependencies The dependencies. */ - public static function UpdateApplication(string $applicationName, bool $requiresIpWhitelist = false, bool $requiresRccServiceAuthentication = false, bool $canBeFetchedFromClientSettingsService = true, array $dependencies = []) + public static function UpdateApplication(string $applicationName, + bool $requiresIpWhitelist = false, + bool $requiresRccServiceAuthentication = false, + bool $canBeFetchedFromClientSettingsService = true, + array $dependencies = []) { // check if the application exists if (!self::ApplicationExists($applicationName)) { @@ -260,7 +269,7 @@ namespace Alphaland\Client { $dependencies = implode(',', $dependencies); // update the application - $query = $GLOBALS['pdo']->prepare("UPDATE `clientsettings_applications` SET `requires_ip_whitelist` = :requires_ip_whitelist, `requires_rcc_service_authentication` = :requires_rcc_service_authentication, `can_be_fetched_from_clientsettings_service` = :can_be_fetched_from_clientsettings_service, `dependencies` = :dependencies WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("UPDATE `clientsettings_applications` SET `requires_ip_whitelist` = :requires_ip_whitelist, `requires_rcc_service_authentication` = :requires_rcc_service_authentication, `can_be_fetched_from_clientsettings_service` = :can_be_fetched_from_clientsettings_service, `dependencies` = :dependencies WHERE BINARY `name` = :name"); $query->bindParam(':name', $applicationName, PDO::PARAM_STR); $query->bindParam(':requires_ip_whitelist', $requiresIpWhitelist, PDO::PARAM_BOOL); $query->bindParam(':requires_rcc_service_authentication', $requiresRccServiceAuthentication, PDO::PARAM_BOOL); @@ -280,7 +289,11 @@ namespace Alphaland\Client { * @param bool $canBeFetchedFromClientSettingsService Whether the application can be fetched from the ClientSettings Service. * @param array $dependencies The dependencies of the application. */ - public static function CreateOrUpdateApplication(string $applicationName, bool $requiresIpWhitelist = false, bool $requiresRccServiceAuthentication = false, bool $canBeFetchedFromClientSettingsService = true, array $dependencies = []) + public static function CreateOrUpdateApplication(string $applicationName, + bool $requiresIpWhitelist = false, + bool $requiresRccServiceAuthentication = false, + bool $canBeFetchedFromClientSettingsService = true, + array $dependencies = []) { // check if the application exists if (self::ApplicationExists($applicationName)) { @@ -299,7 +312,11 @@ namespace Alphaland\Client { * @param bool $canBeFetchedFromClientSettingsService Whether the application can be fetched from the ClientSettings Service. * @param array $dependencies The dependencies of the application. */ - public static function GetOrCreateApplication(string $applicationName, bool $requiresIpWhitelist = false, bool $requiresRccServiceAuthentication = false, bool $canBeFetchedFromClientSettingsService = true, array $dependencies = []) + public static function GetOrCreateApplication(string $applicationName, + bool $requiresIpWhitelist = false, + bool $requiresRccServiceAuthentication = false, + bool $canBeFetchedFromClientSettingsService = true, + array $dependencies = []) { // check if the application exists if (!self::ApplicationExists($applicationName)) { @@ -320,7 +337,7 @@ namespace Alphaland\Client { public static function GetApplicationDependencies(string $applicationName): array { // get the application - $query = $GLOBALS['pdo']->prepare("SELECT `dependencies` FROM `clientsettings_applications` WHERE `name` = :application"); + $query = $GLOBALS['pdo']->prepare("SELECT `dependencies` FROM `clientsettings_applications` WHERE BINARY `name` = :application"); $query->bindParam(':application', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -344,7 +361,7 @@ namespace Alphaland\Client { } // get the application - $query = $GLOBALS['pdo']->prepare("SELECT `dependencies` FROM `clientsettings_applications` WHERE `name` = :application"); + $query = $GLOBALS['pdo']->prepare("SELECT `dependencies` FROM `clientsettings_applications` WHERE BINARY `name` = :application"); $query->bindParam(':application', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -365,7 +382,7 @@ namespace Alphaland\Client { public static function ApplicationHasDependency(string $applicationName, string $dependencyName): bool { // with the dependencies containing $dependencyName, we can check if the application has the dependency - $query = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `clientsettings_applications` WHERE `name` = :application AND `dependencies` LIKE :dependency"); + $query = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM `clientsettings_applications` WHERE BINARY `name` = :application AND `dependencies` LIKE :dependency"); $query->bindParam(':application', $applicationName, PDO::PARAM_STR); $query->bindParam(':dependency', '%' . $dependencyName . '%', PDO::PARAM_STR); @@ -398,7 +415,7 @@ namespace Alphaland\Client { public static function FetchCombinedApplicationDependencies(string $applicationName, bool $recursive = true) { // get the application - $query = $GLOBALS['pdo']->prepare("SELECT `dependencies` FROM `clientsettings_applications` WHERE `name` = :application"); + $query = $GLOBALS['pdo']->prepare("SELECT `dependencies` FROM `clientsettings_applications` WHERE BINARY `name` = :application"); $query->bindParam(':application', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -442,7 +459,7 @@ namespace Alphaland\Client { public static function DeleteApplicationAndSettings(string $applicationName) { // delete the application - $query = $GLOBALS['pdo']->prepare("DELETE FROM `clientsettings_applications` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("DELETE FROM `clientsettings_applications` WHERE BINARY `name` = :name"); $query->bindParam(':name', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -461,7 +478,7 @@ namespace Alphaland\Client { public static function ApplicationCanBeFetchedFromClientSettingsService(string $applicationName) { // get the application - $query = $GLOBALS['pdo']->prepare("SELECT `can_be_fetched_from_clientsettings_service` FROM `clientsettings_applications` WHERE `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT `can_be_fetched_from_clientsettings_service` FROM `clientsettings_applications` WHERE BINARY `name` = :name"); $query->bindParam(':name', $applicationName, PDO::PARAM_STR); $query->execute(); @@ -645,7 +662,7 @@ namespace Alphaland\Client { throw new Error("The application '$applicationName' does not exist."); } - $query = $GLOBALS['pdo']->prepare("UPDATE `clientsettings` SET `value` = :value, `kind` = :kind WHERE `application` = :application AND `name` = :name"); + $query = $GLOBALS['pdo']->prepare("UPDATE `clientsettings` SET `value` = :value, `kind` = :kind WHERE `application` = :application AND BINARY `name` = :name"); $query->bindParam(':application', $applicationId, PDO::PARAM_INT); $query->bindParam(':name', $settingName, PDO::PARAM_STR); $query->bindParam(':value', $value, PDO::PARAM_STR); @@ -724,7 +741,7 @@ namespace Alphaland\Client { } // get the setting - $query = $GLOBALS['pdo']->prepare("SELECT * FROM `clientsettings` WHERE `application` = :application AND `name` = :name"); + $query = $GLOBALS['pdo']->prepare("SELECT * FROM `clientsettings` WHERE `application` = :application AND BINARY `name` = :name"); $query->bindParam(':application', $applicationId, PDO::PARAM_INT); $query->bindParam(':name', $name, PDO::PARAM_STR); @@ -844,7 +861,7 @@ namespace Alphaland\Client { } // delete the setting - $query = $GLOBALS['pdo']->prepare("DELETE FROM `clientsettings` WHERE `application` = :application AND `name` = :name"); + $query = $GLOBALS['pdo']->prepare("DELETE FROM `clientsettings` WHERE `application` = :application AND BINARY `name` = :name"); $query->bindParam(':application', $applicationId, PDO::PARAM_INT); $query->bindParam(':name', $name, PDO::PARAM_STR); diff --git a/globals/config.php b/globals/config.php index cb3638d..f98bfb5 100644 --- a/globals/config.php +++ b/globals/config.php @@ -126,6 +126,7 @@ try include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Groups/Group.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Web/WebsiteSettings.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Web/IpRange.php"; + include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Client/ClientSettings.php"; //authenticator $authenticator = new PHPGangsta_GoogleAuthenticator(); diff --git a/html_clientsettings/Setting/QuietGet/ClientAppSettings.php b/html_clientsettings/Setting/QuietGet/ClientAppSettings.php index 3ca092b..f2fed52 100644 --- a/html_clientsettings/Setting/QuietGet/ClientAppSettings.php +++ b/html_clientsettings/Setting/QuietGet/ClientAppSettings.php @@ -1,9 +1,14 @@ query("SELECT * FROM websettings WHERE id = 1")->fetch(PDO::FETCH_OBJ); + echo $ws->ClientAppSettings; \ No newline at end of file diff --git a/html_clientsettings/v1/GetSetting.php b/html_clientsettings/v1/GetSetting.php new file mode 100644 index 0000000..b01dc21 --- /dev/null +++ b/html_clientsettings/v1/GetSetting.php @@ -0,0 +1,58 @@ +