summaryrefslogtreecommitdiffstats
path: root/apis/debugrequest.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'apis/debugrequest.inc.php')
-rw-r--r--apis/debugrequest.inc.php76
1 files changed, 60 insertions, 16 deletions
diff --git a/apis/debugrequest.inc.php b/apis/debugrequest.inc.php
index 54ebffb2..bb7533d4 100644
--- a/apis/debugrequest.inc.php
+++ b/apis/debugrequest.inc.php
@@ -1,24 +1,68 @@
<?php
-$debug_settings = Property::getRemoteDebugConfig();
-if ($debug_settings["enabled"] !== true) {
- http_response_code(403);
- exit;
+
+function handleRequest() {
+ define("DEBUG_SETTINGS", Property::getRemoteDebugConfig());
+ define("DEBUG_REQUEST", explode(":", file_get_contents("php://input"), 2));
+ if (!checkEnabled() || !checkValid()) {
+ http_response_code(403);
+ exit(1);
+ }
+ $task = runRelayTask();
+ waitForRelay($task);
+ exit(0);
}
-$debug_request = explode(":", file_get_contents("php://input"), 2);
+function waitForRelay($task) {
+ while(true) {
+ $status = Taskmanager::status();
+ if($status["statusCode"] == "TASK_ERROR") {
+ http_response_code(500);
+ exit(1);
+ }
+ elseif ($status["listenPort"] != -1) {
+ echo "PORT=$status['listenPort']";
+ Property::addToList("DispatchedRelay", $task["id"]);
+ break;
+ }
+ }
+}
-$uuid = $debug_request[0];
-$port = 5900 + $debug_request[1];
+function runRelayTask() {
+ $data = array("ip" => constant("DEBUG_SETTINGS")["debugServer"], "port" => constant("DEBUG_SETTINGS")["port"]);
+ return Taskmanager::submit("RemoteDebug", $data);
+}
-$validclient = Database::queryFirst("SELECT machineuuid, clientip FROM machine WHERE machineuuid = :uuid AND clientip = :ip", array(":uuid" => "$debug_request[0]", ":ip" => $_SERVER["REMOTE_ADDR"]));
+function checkEnabled() {
+ return constant("DEBUG_SETTINGS")["enabled"];
+}
-if ($validclient == false) {
- http_response_code(400);
-} else {
- http_response_code(200);
- $data = array("hosts" => array($_SERVER["REMOTE_ADDR"], $debug_settings["debugServer"]),
- "ports" => array($port, intval($debug_settings["port"])), "descs" => array("bwlpclient", "debugserver"));
- $taskstruct = Taskmanager::submit('DispatchRelay', $data);
- Property::addToList("DispatchedRelay", $taskstruct['id']);
+function checkValid() {
+ return Database::queryFirst("SELECT machineuuid, clientip FROM machine WHERE machineuuid = :uuid AND clientip = :ip",
+ array(":uuid" => constant("DEBUG_REQUEST"[0], ":ip" => $_SERVER["REMOTE_ADDR"])));
}
+handleRequest();
+
+// $debug_settings = Property::getRemoteDebugConfig();
+// if ($debug_settings["enabled"] !== true) {
+// http_response_code(403);
+// exit;
+// }
+
+// $debug_request = explode(":", file_get_contents("php://input"), 2);
+
+// $uuid = $debug_request[0];
+// $port = 5900 + $debug_request[1];
+
+// $validclient = Database::queryFirst("SELECT machineuuid, clientip FROM machine WHERE machineuuid = :uuid AND clientip = :ip", array(":uuid" => "$debug_request[0]", ":ip" => $_SERVER["REMOTE_ADDR"]));
+
+// if ($validclient == false) {
+// http_response_code(400);
+// } else {
+// http_response_code(200);
+// $data = array("hosts" => array($_SERVER["REMOTE_ADDR"], $debug_settings["debugServer"]),
+// "ports" => array($port, intval($debug_settings["port"])), "descs" => array("bwlpclient", "debugserver"));
+// $taskstruct = Taskmanager::submit('DispatchRelay', $data);
+// Property::addToList("DispatchedRelay", $taskstruct['id']);
+// }
+