I WANT TO CRY
This commit is contained in:
parent
8017133abb
commit
c6f25ba0b9
@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
use LonaDB\LonaDB;
|
||||
|
||||
//TODO: Refactoring the eval action
|
||||
|
||||
|
||||
return new class {
|
||||
public function run($LonaDB, $data, $client) : void {
|
||||
//Check if user is root (only root is allowed to use eval)
|
||||
@ -23,41 +17,41 @@ return new class {
|
||||
}
|
||||
};
|
||||
";
|
||||
$success = true;
|
||||
try {
|
||||
//Run the script
|
||||
eval($evalFunction);
|
||||
try {
|
||||
//Execute the function
|
||||
$answer = $functions[$functionName]->Execute($LonaDB);
|
||||
//$result will be the returned variable from the eval script
|
||||
$result = $functions[$functionName]->Execute($LonaDB);
|
||||
} catch (Exception $e) {
|
||||
//Catch errors
|
||||
$answer = $e->getMessage();
|
||||
$result = $e->getMessage();
|
||||
$success = false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//Catch errors
|
||||
$answer = $e->getMessage();
|
||||
$result = $e->getMessage();
|
||||
$success = false;
|
||||
}
|
||||
//Send response and close socket
|
||||
$this->sendSuccessResponse($client, $answer, $data['process']);
|
||||
// Remove the function from the $functions array
|
||||
unset($functions[$functionName]);
|
||||
//Run plugin event
|
||||
$LonaDB->PluginManager->RunEvent($data['login']['name'], "eval", [ "content" => $data['function'] ]);
|
||||
// Remove the function from the $functions array
|
||||
unset($functions[$functionName]);
|
||||
//Send response
|
||||
return $this->Send($client, ["success" => $success, "result" => $result, "process" => $process]);;
|
||||
}
|
||||
|
||||
private function sendErrorResponse($client, $error, $process): void {
|
||||
//Create response array
|
||||
$response = json_encode(["success" => false, "err" => $error, "process" => $process]);
|
||||
//Send response and close socket
|
||||
socket_write($client, $response);
|
||||
socket_close($client);
|
||||
}
|
||||
|
||||
private function sendSuccessResponse($client, $response, $process): void {
|
||||
//Create response array
|
||||
$response = json_encode(["success" => true, "response" => $response, "process" => $process]);
|
||||
private function Send ($client, $responseArray) : bool {
|
||||
//Convert response array to JSON object
|
||||
$response = json_encode($responseArray);
|
||||
//Send response and close socket
|
||||
socket_write($client, $response);
|
||||
socket_close($client);
|
||||
//Return state
|
||||
$bool = false;
|
||||
if($responseArray['success']) $bool = true;
|
||||
return $bool;
|
||||
}
|
||||
};
|
@ -1,12 +1,26 @@
|
||||
<?php
|
||||
|
||||
return new class {
|
||||
public function run($LonaDB, $data, $client) : void {
|
||||
public function run($LonaDB, $data, $client) : bool {
|
||||
//Get function from FunctionManager
|
||||
$function = $LonaDB->FunctionManager->GetFunction($data['name']);
|
||||
//Execute function
|
||||
$function->Execute($LonaDB, $data, $client);
|
||||
$response = $function->Execute($LonaDB, $data, $client);
|
||||
//Run plugin event
|
||||
$LonaDB->PluginManager->RunEvent($data['login']['name'], "functionExecute", [ "name" => $data['name'] ]);
|
||||
//Send response
|
||||
return $this->Send($client, ["success" => true, "result" => $response, "process" => $data["process"]]);
|
||||
}
|
||||
|
||||
private function Send ($client, $responseArray) : bool {
|
||||
//Convert response array to JSON object
|
||||
$response = json_encode($responseArray);
|
||||
//Send response and close socket
|
||||
socket_write($client, $response);
|
||||
socket_close($client);
|
||||
//Return state
|
||||
$bool = false;
|
||||
if($responseArray['success']) $bool = true;
|
||||
return $bool;
|
||||
}
|
||||
};
|
||||
|
@ -35,7 +35,7 @@ class LonaFunction{
|
||||
//We are using an array because overwriting/defining a function inside eval didn't work for us
|
||||
//Our workaround is creating a class instance with a run function which is our Lona function
|
||||
$function = "\$this->functions['" . $this->Name . "'] = new class {\n";
|
||||
$function .= "public function run(\$LonaDB, \$data, \$server, \$fd) {\n";
|
||||
$function .= "public function run(\$LonaDB, \$data) {\n";
|
||||
$function .= $temp;
|
||||
$function .= "\n} \n};";
|
||||
|
||||
@ -45,8 +45,8 @@ class LonaFunction{
|
||||
$this->LonaDB->Logger->Load("Function '" . $this->Name . "' has been loaded");
|
||||
}
|
||||
|
||||
public function Execute(LonaDB $LonaDB, array $data, $server, $fd) : mixed {
|
||||
public function Execute(LonaDB $LonaDB, array $data, $client) : mixed {
|
||||
//Run function
|
||||
return $this->functions[$this->Name]->run($LonaDB, $data, $server, $fd);
|
||||
return $this->functions[$this->Name]->run($LonaDB, $data);
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ class UserManager{
|
||||
//If username is root, check for the root password
|
||||
if($name === "root" && $password === $this->LonaDB->config["root"]) return true;
|
||||
//Check if the user exists
|
||||
if(!$this->CheckUsers($name)) return false;
|
||||
if(!$this->CheckUser($name)) return false;
|
||||
//Check if the password is correct
|
||||
if($this->Users[$name]["password"] !== $password) return false;
|
||||
//All checks successfull
|
||||
|
Loading…
Reference in New Issue
Block a user