I WANT TO CRY
This commit is contained in:
parent
8017133abb
commit
c6f25ba0b9
@ -1,11 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
use LonaDB\LonaDB;
|
|
||||||
|
|
||||||
//TODO: Refactoring the eval action
|
|
||||||
|
|
||||||
|
|
||||||
return new class {
|
return new class {
|
||||||
public function run($LonaDB, $data, $client) : void {
|
public function run($LonaDB, $data, $client) : void {
|
||||||
//Check if user is root (only root is allowed to use eval)
|
//Check if user is root (only root is allowed to use eval)
|
||||||
@ -23,41 +17,41 @@ return new class {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
";
|
";
|
||||||
|
$success = true;
|
||||||
try {
|
try {
|
||||||
//Run the script
|
//Run the script
|
||||||
eval($evalFunction);
|
eval($evalFunction);
|
||||||
try {
|
try {
|
||||||
//Execute the function
|
//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 (Exception $e) {
|
||||||
//Catch errors
|
//Catch errors
|
||||||
$answer = $e->getMessage();
|
$result = $e->getMessage();
|
||||||
|
$success = false;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
//Catch errors
|
//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
|
//Run plugin event
|
||||||
$LonaDB->PluginManager->RunEvent($data['login']['name'], "eval", [ "content" => $data['function'] ]);
|
$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 {
|
private function Send ($client, $responseArray) : bool {
|
||||||
//Create response array
|
//Convert response array to JSON object
|
||||||
$response = json_encode(["success" => false, "err" => $error, "process" => $process]);
|
$response = json_encode($responseArray);
|
||||||
//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]);
|
|
||||||
//Send response and close socket
|
//Send response and close socket
|
||||||
socket_write($client, $response);
|
socket_write($client, $response);
|
||||||
socket_close($client);
|
socket_close($client);
|
||||||
|
//Return state
|
||||||
|
$bool = false;
|
||||||
|
if($responseArray['success']) $bool = true;
|
||||||
|
return $bool;
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -1,12 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return new class {
|
return new class {
|
||||||
public function run($LonaDB, $data, $client) : void {
|
public function run($LonaDB, $data, $client) : bool {
|
||||||
//Get function from FunctionManager
|
//Get function from FunctionManager
|
||||||
$function = $LonaDB->FunctionManager->GetFunction($data['name']);
|
$function = $LonaDB->FunctionManager->GetFunction($data['name']);
|
||||||
//Execute function
|
//Execute function
|
||||||
$function->Execute($LonaDB, $data, $client);
|
$response = $function->Execute($LonaDB, $data, $client);
|
||||||
//Run plugin event
|
//Run plugin event
|
||||||
$LonaDB->PluginManager->RunEvent($data['login']['name'], "functionExecute", [ "name" => $data['name'] ]);
|
$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
|
//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
|
//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 = "\$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 .= $temp;
|
||||||
$function .= "\n} \n};";
|
$function .= "\n} \n};";
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ class LonaFunction{
|
|||||||
$this->LonaDB->Logger->Load("Function '" . $this->Name . "' has been loaded");
|
$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
|
//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 username is root, check for the root password
|
||||||
if($name === "root" && $password === $this->LonaDB->config["root"]) return true;
|
if($name === "root" && $password === $this->LonaDB->config["root"]) return true;
|
||||||
//Check if the user exists
|
//Check if the user exists
|
||||||
if(!$this->CheckUsers($name)) return false;
|
if(!$this->CheckUser($name)) return false;
|
||||||
//Check if the password is correct
|
//Check if the password is correct
|
||||||
if($this->Users[$name]["password"] !== $password) return false;
|
if($this->Users[$name]["password"] !== $password) return false;
|
||||||
//All checks successfull
|
//All checks successfull
|
||||||
|
Loading…
Reference in New Issue
Block a user