From b0f76185dfdca3531025e00ced2ec1cb3fd251d0 Mon Sep 17 00:00:00 2001 From: "MFDLABS Github As A Service WCKIE02-LAPP312 (Cage # 25123)" Date: Sun, 31 Oct 2021 13:53:18 +0000 Subject: [PATCH 1/5] OK Austin --- globals/config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/globals/config.php b/globals/config.php index 83fd24a..cb71217 100644 --- a/globals/config.php +++ b/globals/config.php @@ -5,6 +5,7 @@ This is extremely sensitive. Fuck u nsg + Fuck you too Austin :) */ try From f673cda5ef7e19f22981070604922bef45713096 Mon Sep 17 00:00:00 2001 From: "petko@mfdlabs.com" Date: Sun, 31 Oct 2021 13:59:42 +0000 Subject: [PATCH 2/5] Rename AssetType.php to AssetTypeHelper.php Because this is really just a helper not really AssetType itself --- .../Dependencies/Assets/{AssetType.php => AssetTypeHelper.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename globals/Dependencies/Assets/{AssetType.php => AssetTypeHelper.php} (99%) diff --git a/globals/Dependencies/Assets/AssetType.php b/globals/Dependencies/Assets/AssetTypeHelper.php similarity index 99% rename from globals/Dependencies/Assets/AssetType.php rename to globals/Dependencies/Assets/AssetTypeHelper.php index 186ee98..8e08054 100644 --- a/globals/Dependencies/Assets/AssetType.php +++ b/globals/Dependencies/Assets/AssetTypeHelper.php @@ -5,7 +5,7 @@ */ namespace Alphaland\Assets { - class AssetType + class AssetTypeHelper { public function IsPurchasable($id) { From ba9fec9d36bb184b86a8153ebe8acb8eb2f2b606 Mon Sep 17 00:00:00 2001 From: "petko@mfdlabs.com" Date: Sun, 31 Oct 2021 14:35:44 +0000 Subject: [PATCH 3/5] Update RccServiceHelper.php Fix it --- .../Dependencies/Grid/RccServiceHelper.php | 92 ++++++++++--------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/globals/Dependencies/Grid/RccServiceHelper.php b/globals/Dependencies/Grid/RccServiceHelper.php index 6e9e5cb..bcf5a8f 100644 --- a/globals/Dependencies/Grid/RccServiceHelper.php +++ b/globals/Dependencies/Grid/RccServiceHelper.php @@ -2,6 +2,8 @@ /* Alphaland 2021 + Nikita TODO: ALPHA-22 (Response Models for things that definitely have a known response (like specific SOAP actions)) + https://jira.mfdlabs.local/browse/ALPHA-22 */ namespace Alphaland\Grid { @@ -14,16 +16,15 @@ namespace Alphaland\Grid { $this->ServiceIp = $ServiceIp; } - private function soapCallService(string $name, array $arguments = []) + private function SoapCallService(string $name, array $arguments = []): mixed { - $soapcl = new \SoapClient($GLOBALS['RCCwsdl'], ["location" => "http://".$this->ServiceIp, "uri" => "http://roblox.com/", "exceptions" => false]); + $soapcl = new \SoapClient($GLOBALS['RCCwsdl'], ["location" => "http://" . $this->ServiceIp, "uri" => "http://roblox.com/", "exceptions" => false]); return $soapcl->{$name}($arguments); //thanks BrentDaMage didnt know u can do this } - private function verifyLuaValue($value) //mostly due to booleans, but maybe something will come up in the future + private function VerifyLuaValue(mixed $value): string //mostly due to booleans, but maybe something will come up in the future { - switch ($value) - { + switch ($value) { case is_bool(json_encode($value)) || $value == 1: return json_encode($value); default: @@ -31,10 +32,9 @@ namespace Alphaland\Grid { } } - private function getLuaType($value): string //currently only supports booleans, integers and strings + private function GetLuaType(string $value): string //currently only supports booleans, integers and strings { - switch ($value) - { + switch ($value) { case $value == "true" || $value == "false": //this is so gay but php hates me return "LUA_TBOOLEAN"; case !is_string($value) && !is_bool($value) && filter_var($value, FILTER_VALIDATE_INT): @@ -44,23 +44,23 @@ namespace Alphaland\Grid { } } - private function luaArguments(array $arguments=[]) //arguments for a script being executed + private function ConstructLuaArguments(array $arguments = []): array //arguments for a script being executed { if (!empty($arguments)) { - $luavalue = array("LuaValue"=>array()); - foreach ($arguments as $argument) { + $luavalue = array("LuaValue" => array()); + foreach ($arguments as $argument) { array_push($luavalue['LuaValue'], array( - "type" => $this->getLuaType($argument), - "value" => $this->verifyLuaValue($argument) + "type" => $this->GetLuaType($argument), + "value" => $this->VerifyLuaValue($argument) )); } return $luavalue; } } - private function soapJobTemplate(string $servicename, string $jobid, int $expiration, int $category, int $cores, string $scriptname, string $script, array $arguments=[]) + private function ConstructJobTemplate(string $servicename, string $jobid, int $expiration, int $category, int $cores, string $scriptname, string $script, array $arguments = []): mixed { - return $this->soapCallService( + return $this->SoapCallService( $servicename, array( "job" => array( @@ -72,83 +72,87 @@ namespace Alphaland\Grid { "script" => array( "name" => $scriptname, "script" => $script, - "arguments" => $this->luaArguments($arguments) + "arguments" => $this->ConstructLuaArguments($arguments) ) ) ); } - public function soapGetVersion() + public function GetVersion(): mixed { - return $this->soapCallService("GetVersion"); + return $this->SoapCallService("GetVersion"); } - public function soapHelloWorld() + public function HelloWorld(): mixed { - return $this->soapCallService("HelloWorld"); + return $this->SoapCallService("HelloWorld"); } - public function soapCloseAllJobs() + public function CloseAllJobs(): mixed { - return $this->soapCallService("CloseAllJobs"); + return $this->SoapCallService("CloseAllJobs"); } - public function soapCloseExpiredJobs() + public function CloseExpiredJobs(): mixed { - return $this->soapCallService("CloseExpiredJobs"); + return $this->SoapCallService("CloseExpiredJobs"); } - public function soapGetAllJobsEx() + public function GetAllJobsEx(): mixed { - return $this->soapCallService("GetAllJobsEx"); + return $this->SoapCallService("GetAllJobsEx"); } - public function soapGetStatus() + public function GetStatus(): mixed { - return $this->soapCallService("GetStatus"); + return $this->SoapCallService("GetStatus"); } - public function soapDiagEx(string $type, string $jobid) + public function DiagEx(string $type, string $jobid): mixed { - return $this->soapCallService("DiagEx", array("type" => $type, "jobID" => $jobid)); + return $this->SoapCallService("DiagEx", array("type" => $type, "jobID" => $jobid)); } - public function soapCloseJob(string $jobid) + // this doesn't return anything + // https://pastebin.com/raw/pr5NDBwC + public function CloseJob(string $jobid): mixed { - return $this->soapCallService("CloseJob", array("jobID" => $jobid)); + return $this->SoapCallService("CloseJob", array("jobID" => $jobid)); } - public function soapGetExpiration(string $jobid) + public function GetExpiration(string $jobid): mixed { - return $this->soapCallService("GetExpiration", array("jobID" => $jobid)); + return $this->SoapCallService("GetExpiration", array("jobID" => $jobid)); } - public function soapExecuteEx(string $jobid, string $scriptname, string $script, array $arguments=[]) + public function ExecuteEx(string $jobid, string $scriptname, string $script, array $arguments = []): mixed { - return $this->soapCallService("ExecuteEx", array( - "jobID" => $jobid, + return $this->SoapCallService( + "ExecuteEx", + array( + "jobID" => $jobid, "script" => array( "name" => $scriptname, "script" => $script, - "arguments" => $this->luaArguments($arguments) + "arguments" => $this->ConstructLuaArguments($arguments) ) ) ); } - public function soapRenewLease(string $jobid, int $expiration) + public function RenewLease(string $jobid, int $expiration): mixed { - return $this->soapCallService("RenewLease", array("jobID" => $jobid, "expirationInSeconds" => $expiration)); + return $this->SoapCallService("RenewLease", array("jobID" => $jobid, "expirationInSeconds" => $expiration)); } - public function soapOpenJobEx(string $jobid, int $expiration, string $scriptname, string $script, array $arguments=[]) + public function OpenJobEx(string $jobid, int $expiration, string $scriptname, string $script, array $arguments = []): mixed { - return $this->soapJobTemplate("OpenJobEx", $jobid, $expiration, 1, 3, $scriptname, $script, $arguments); + return $this->ConstructJobTemplate("OpenJobEx", $jobid, $expiration, 1, 3, $scriptname, $script, $arguments); } - public function soapBatchJobEx(string $jobid, int $expiration, string $scriptname, string $script, array $arguments=[]) + public function BatchJobEx(string $jobid, int $expiration, string $scriptname, string $script, array $arguments = []): mixed { - return $this->soapJobTemplate("BatchJobEx", $jobid, $expiration, 1, 3, $scriptname, $script, $arguments); + return $this->ConstructJobTemplate("BatchJobEx", $jobid, $expiration, 1, 3, $scriptname, $script, $arguments); } } } From c38db907baa1b2fff57fdb3c474b0a807e0255a1 Mon Sep 17 00:00:00 2001 From: "petko@mfdlabs.com" Date: Sun, 31 Oct 2021 14:55:53 +0000 Subject: [PATCH 4/5] Cleanup Activation.php Make it look better --- globals/Dependencies/Users/Activation.php | 45 ++++++++++++----------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/globals/Dependencies/Users/Activation.php b/globals/Dependencies/Users/Activation.php index ea125d9..10aaaee 100644 --- a/globals/Dependencies/Users/Activation.php +++ b/globals/Dependencies/Users/Activation.php @@ -6,54 +6,57 @@ namespace Alphaland\Users { + use Alphaland\Common\HashingUtiltity; use PDO; class Activation { - private function generateActivationCode() + + private static PDO $pdo = $GLOBALS['pdo']; + + private static function GenerateActivationCode(): string { $hash = ""; - while (true) { - $hash = genHash(32); + do { + $hash = HashingUtiltity::GenerateByteHash(32); - $keycheck = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `activationcode` = :ac"); - $keycheck->bindParam(":ac", $hash, PDO::PARAM_STR); - $keycheck->execute(); - if ($keycheck->rowCount() == 0) { - break; - } - } + $query = Activation::$pdo->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `activationcode` = :ac"); + $query->bindParam(":ac", $hash, PDO::PARAM_STR); + $query->execute(); + } while ($query->fetchColumn(0) != 0); + return $hash; } - public function getUserActivationCode(int $userid) + public static function GetUserActivationCode(int $userid): string { - $query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `uid` = :uid"); + $query = Activation::$pdo->prepare("SELECT `activationcode` FROM `alphaland_verification` WHERE `uid` = :uid"); $query->bindParam(":uid", $userid, PDO::PARAM_INT); $query->execute(); + if ($query->rowCount() == 1) { - return $query->fetch(PDO::FETCH_OBJ)->activationcode; + return (string)$query->fetch(PDO::FETCH_OBJ)->activationcode; } - return false; + return null; } - public function isUserActivated(int $userid) + public static function IsUserActivated(int $userid): bool { - $query = $GLOBALS['pdo']->prepare("SELECT * FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid"); + $query = Activation::$pdo->prepare("SELECT COUNT(*) FROM `alphaland_verification` WHERE `isactivated` = 1 AND `uid` = :uid"); $query->bindParam(":uid", $userid, PDO::PARAM_INT); $query->execute(); - if ($query->rowCount() > 0) { + if ($query->fetchColumn(0) > 0) { return true; } return false; } - public function setupUserActivation(int $userid) //this should be ran when the user first signs up + public static function SetupUserActivation(int $userid): bool //this should be ran when the user first signs up { - if (!$this->isUserActivated($userid)) { - $activationcode = $this->generateActivationCode(); + if (!Activation::IsUserActivated($userid)) { + $activationcode = Activation::GenerateActivationCode(); - $n = $GLOBALS['pdo']->prepare("INSERT INTO `alphaland_verification`(`activationcode`,`uid`) VALUES(:ac, :userid)"); + $n = Activation::$pdo->prepare("INSERT INTO `alphaland_verification`(`activationcode`,`uid`) VALUES(:ac, :userid)"); $n->bindParam(":ac", $activationcode, PDO::PARAM_STR); $n->bindParam(":userid", $userid, PDO::PARAM_INT); $n->execute(); From 45c36bdc7d1844eeb83a8ba070da8ea68acb7f68 Mon Sep 17 00:00:00 2001 From: "petko@mfdlabs.com" Date: Sun, 31 Oct 2021 14:56:18 +0000 Subject: [PATCH 5/5] Update Activation Dependencies --- globals/config.php | 6 ++++-- globals/userauth.php | 5 +++-- html/activate.php | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/globals/config.php b/globals/config.php index cb71217..8ce304d 100644 --- a/globals/config.php +++ b/globals/config.php @@ -8,6 +8,8 @@ Fuck you too Austin :) */ +use Alphaland\Users\Activation; + try { //php config @@ -126,8 +128,8 @@ try forceHttpsCloudflare(); } - $activated = new Alphaland\Users\Activation(); - $activated = $activated->isUserActivated($GLOBALS['user']->id); + // TODO: WebContextManager::CurrentUser instead of $GLOBALS['user']!! + $activated = Activation::IsUserActivated($GLOBALS['user']->id); $maintenance = checkIfUnderMaintenance(); $banned = checkIfBanned($GLOBALS['user']->id); diff --git a/globals/userauth.php b/globals/userauth.php index 7552668..9c352bf 100644 --- a/globals/userauth.php +++ b/globals/userauth.php @@ -5,6 +5,8 @@ User class */ +use Alphaland\Users\Activation; + class user { public $id = -1; public $name = ""; @@ -65,8 +67,7 @@ class user { // .. //activation stuff - $activated = new Alphaland\Users\Activation(); - $activated = $activated->isUserActivated($this->id); + $activated = Activation::IsUserActivated($this->id); if (!banned($this->id)) { diff --git a/html/activate.php b/html/activate.php index 62ff85a..e1450b8 100644 --- a/html/activate.php +++ b/html/activate.php @@ -1,11 +1,12 @@ isUserActivated($user->id)) { +use Alphaland\Users\Activation; + +if (Activation::IsUserActivated($user->id)) { redirect("/"); } -$activationcode = $activation->getUserActivationCode($user->id); +$activationcode = Activation::GetUserActivationCode($user->id); $body = '