From a01cf0b232663a52e77ac9bfb92635546d41f468 Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Fri, 19 Aug 2022 17:06:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BE=E5=A4=87=E6=9A=82?= =?UTF-8?q?=E5=81=9C/=E7=BB=A7=E7=BB=AD=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EdgeManager/EController/ECommand.php | 70 +++++++++++++++++----------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/EdgeManager/EController/ECommand.php b/EdgeManager/EController/ECommand.php index 6892e27..9ee124f 100644 --- a/EdgeManager/EController/ECommand.php +++ b/EdgeManager/EController/ECommand.php @@ -11,44 +11,57 @@ class ECommand { $command2API = [ 'server_restart' => '/Admin/ServerCloseAndRestart', 'server_close' => '/Admin/ServerClose', + 'device_stop' => '/Edge/DeviceStopRequest', + 'device_continue' => 'Edge/DeviceContinueRequest' ]; - if (str_starts_with($this -> post -> command, 'server')) { - $res = pg_query($this -> dbconn, sprintf( - "SELECT url, port - FROM hf_mes_scada_edgeserver_controller_server - WHERE id = '%s'", - $this -> post -> server_id - )); - $server_info = pg_fetch_row($res); - + $res = pg_query($this -> dbconn, sprintf( + "SELECT url, port + FROM hf_mes_scada_edgeserver_controller_server + WHERE id = '%s'", + $this -> post -> server_id + )); + $server_info = pg_fetch_row($res); + + if (str_starts_with($this -> post -> command, 'server')) $ch = curl_init( $server_info[0] . ":" . $server_info[1] . $command2API[$this -> post -> command] ); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); - curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt( - $ch, - CURLOPT_USERPWD, - $this -> post -> username + else if (str_starts_with($this -> post -> command, 'device')) + $ch = curl_init( + $server_info[0] . ":" - . $this -> post -> password + . $server_info[1] + . $command2API[$this -> post -> command] + . '?data=' + . $this -> post -> device_id + ); + else + return; + + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt( + $ch, + CURLOPT_USERPWD, + $this -> post -> username + . ":" + . $this -> post -> password + ); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + $return = curl_exec($ch); + curl_close($ch); + if ($return) { + pg_update( + $this -> dbconn, + "hf_mes_scada_edgeserver_controller_server", + ['updated' => false], + ['id' => $this -> post -> server_id] ); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - $return = curl_exec($ch); - curl_close($ch); - if ($return) { - pg_update( - $this -> dbconn, - "hf_mes_scada_edgeserver_controller_server", - ['updated' => false], - ['id' => $this -> post -> server_id] - ); - } } pg_insert( @@ -56,6 +69,7 @@ class ECommand { 'hf_mes_scada_edgeserver_controller_command', [ 'server_id' => $this -> post -> server_id, + 'device_id' => $this -> post -> server_id ?? NULL, 'command' => $this -> post -> command, 'success' => $return ],