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)
This commit is contained in:
Nikita Petko 2021-12-31 06:14:13 +00:00 committed by Github Enterprise
parent 23f608e173
commit 8dd212314a
4 changed files with 100 additions and 19 deletions

View File

@ -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);

View File

@ -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();

View File

@ -1,9 +1,14 @@
<?php
// WARNING: This is deprecated over html_clientsettings/v1/GetSetting, please implement this new route into any clients
// as this endpoint will be removed in the future.
header('Content-Type: application/json');
header("Cache-Control: no-cache, no-store");
header("Pragma: no-cache");
header("Expires: -1");
header("Last-Modified: " . gmdate("D, d M Y H:i:s T") . " GMT");
$ws = $pdo->query("SELECT * FROM websettings WHERE id = 1")->fetch(PDO::FETCH_OBJ);
echo $ws->ClientAppSettings;

View File

@ -0,0 +1,58 @@
<?php
use Alphaland\Client\ClientSettingsApplications;
use Alphaland\Web\WebContextManager;
header("Content-Type: application/json; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: -1");
if ($_SERVER['REQUEST_METHOD'] !== 'GET')
{
die("{}");
}
if (!isset($_GET['key']))
{
die("{}");
}
$key = cleanInput($_GET['key']);
if (!ClientSettingsApplications::ApplicationExists($key))
{
// echo back empty json
die("{}");
}
if (!ClientSettingsApplications::ApplicationCanBeFetchedFromClientSettingsService($key))
{
// echo back empty json
die("{}");
}
$requiresIpWhitelist = ClientSettingsApplications::ApplicationRequiresIpWhitelist($key);
$requiresRccAuth = ClientSettingsApplications::ApplicationRequiresRccServiceAuthentication($key);
if ($requiresIpWhitelist && !WebContextManager::IsCurrentIpAddressWhitelisted())
{
http_response_code(403);
die("{}");
}
if ($requiresRccAuth && !WebContextManager::VerifyAccessKeyHeader())
{
http_response_code(403);
die("{}");
}
$settings = ClientSettingsApplications::FetchCombinedApplicationDependencies($key);
if (empty($settings))
{
die("{}");
}
echo json_encode($settings);