This commit is contained in:
Austin 2021-10-31 21:38:49 -04:00
commit c1f467b613
6 changed files with 85 additions and 73 deletions

View File

@ -5,7 +5,7 @@
*/ */
namespace Alphaland\Assets { namespace Alphaland\Assets {
class AssetType class AssetTypeHelper
{ {
public function IsPurchasable($id) public function IsPurchasable($id)
{ {

View File

@ -2,6 +2,8 @@
/* /*
Alphaland 2021 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 { namespace Alphaland\Grid {
@ -14,16 +16,15 @@ namespace Alphaland\Grid {
$this->ServiceIp = $ServiceIp; $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 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: case is_bool(json_encode($value)) || $value == 1:
return json_encode($value); return json_encode($value);
default: 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 case $value == "true" || $value == "false": //this is so gay but php hates me
return "LUA_TBOOLEAN"; return "LUA_TBOOLEAN";
case !is_string($value) && !is_bool($value) && filter_var($value, FILTER_VALIDATE_INT): 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)) { if (!empty($arguments)) {
$luavalue = array("LuaValue"=>array()); $luavalue = array("LuaValue" => array());
foreach ($arguments as $argument) { foreach ($arguments as $argument) {
array_push($luavalue['LuaValue'], array( array_push($luavalue['LuaValue'], array(
"type" => $this->getLuaType($argument), "type" => $this->GetLuaType($argument),
"value" => $this->verifyLuaValue($argument) "value" => $this->VerifyLuaValue($argument)
)); ));
} }
return $luavalue; 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, $servicename,
array( array(
"job" => array( "job" => array(
@ -72,83 +72,87 @@ namespace Alphaland\Grid {
"script" => array( "script" => array(
"name" => $scriptname, "name" => $scriptname,
"script" => $script, "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( return $this->SoapCallService(
"ExecuteEx",
array(
"jobID" => $jobid, "jobID" => $jobid,
"script" => array( "script" => array(
"name" => $scriptname, "name" => $scriptname,
"script" => $script, "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);
} }
} }
} }

View File

@ -6,54 +6,57 @@
namespace Alphaland\Users { namespace Alphaland\Users {
use Alphaland\Common\HashingUtiltity;
use PDO; use PDO;
class Activation class Activation
{ {
private function generateActivationCode()
private static PDO $pdo = $GLOBALS['pdo'];
private static function GenerateActivationCode(): string
{ {
$hash = ""; $hash = "";
while (true) { do {
$hash = genHash(32); $hash = HashingUtiltity::GenerateByteHash(32);
$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);
$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;
}
}
return $hash; 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->bindParam(":uid", $userid, PDO::PARAM_INT);
$query->execute(); $query->execute();
if ($query->rowCount() == 1) { 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->bindParam(":uid", $userid, PDO::PARAM_INT);
$query->execute(); $query->execute();
if ($query->rowCount() > 0) { if ($query->fetchColumn(0) > 0) {
return true; return true;
} }
return false; 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)) { if (!Activation::IsUserActivated($userid)) {
$activationcode = $this->generateActivationCode(); $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(":ac", $activationcode, PDO::PARAM_STR);
$n->bindParam(":userid", $userid, PDO::PARAM_INT); $n->bindParam(":userid", $userid, PDO::PARAM_INT);
$n->execute(); $n->execute();

View File

@ -5,8 +5,11 @@
This is extremely sensitive. This is extremely sensitive.
Fuck u nsg Fuck u nsg
Fuck you too Austin :)
*/ */
use Alphaland\Users\Activation;
try try
{ {
//php config //php config
@ -125,8 +128,8 @@ try
forceHttpsCloudflare(); forceHttpsCloudflare();
} }
$activated = new Alphaland\Users\Activation(); // TODO: WebContextManager::CurrentUser instead of $GLOBALS['user']!!
$activated = $activated->isUserActivated($GLOBALS['user']->id); $activated = Activation::IsUserActivated($GLOBALS['user']->id);
$maintenance = checkIfUnderMaintenance(); $maintenance = checkIfUnderMaintenance();
$banned = checkIfBanned($GLOBALS['user']->id); $banned = checkIfBanned($GLOBALS['user']->id);

View File

@ -5,6 +5,8 @@
User class User class
*/ */
use Alphaland\Users\Activation;
class user { class user {
public $id = -1; public $id = -1;
public $name = ""; public $name = "";
@ -65,8 +67,7 @@ class user {
// .. // ..
//activation stuff //activation stuff
$activated = new Alphaland\Users\Activation(); $activated = Activation::IsUserActivated($this->id);
$activated = $activated->isUserActivated($this->id);
if (!banned($this->id)) if (!banned($this->id))
{ {

View File

@ -1,11 +1,12 @@
<?php <?php
$activation = new Alphaland\Users\Activation();
if ($activation->isUserActivated($user->id)) { use Alphaland\Users\Activation;
if (Activation::IsUserActivated($user->id)) {
redirect("/"); redirect("/");
} }
$activationcode = $activation->getUserActivationCode($user->id); $activationcode = Activation::GetUserActivationCode($user->id);
$body = ' $body = '
<div class="container-fluid" style="display: flex;justify-content: center;align-items: center;text-align: center;min-height: 100vh;"> <div class="container-fluid" style="display: flex;justify-content: center;align-items: center;text-align: center;min-height: 100vh;">