Merge branch 'master' of http://118.195.187.246:10030/ysun/EdgeManager
This commit is contained in:
@@ -323,12 +323,6 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
|||||||
'code' => 0,
|
'code' => 0,
|
||||||
'data' => $devices
|
'data' => $devices
|
||||||
)));
|
)));
|
||||||
} else if ($get['query'] === 'all_devices') {
|
|
||||||
$all_devices = EConfigure::get_all_devices($dbconn);
|
|
||||||
$connection -> send(json_encode(array(
|
|
||||||
'code' => 0,
|
|
||||||
'data' => $all_devices
|
|
||||||
)));
|
|
||||||
} else {
|
} else {
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
'code' => 1,
|
'code' => 1,
|
||||||
|
|||||||
@@ -11,44 +11,58 @@ class ECommand {
|
|||||||
$command2API = [
|
$command2API = [
|
||||||
'server_restart' => '/Admin/ServerCloseAndRestart',
|
'server_restart' => '/Admin/ServerCloseAndRestart',
|
||||||
'server_close' => '/Admin/ServerClose',
|
'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(
|
||||||
$res = pg_query($this -> dbconn, sprintf(
|
"SELECT url, port
|
||||||
"SELECT url, port
|
FROM hf_mes_scada_edgeserver_controller_server
|
||||||
FROM hf_mes_scada_edgeserver_controller_server
|
WHERE id = '%s'",
|
||||||
WHERE id = '%s'",
|
$this -> post -> server_id
|
||||||
$this -> post -> server_id
|
));
|
||||||
));
|
$server_info = pg_fetch_row($res);
|
||||||
$server_info = pg_fetch_row($res);
|
|
||||||
|
|
||||||
|
if (str_starts_with($this -> post -> command, 'server')) {
|
||||||
$ch = curl_init(
|
$ch = curl_init(
|
||||||
$server_info[0]
|
$server_info[0]
|
||||||
. ":"
|
. ":"
|
||||||
. $server_info[1]
|
. $server_info[1]
|
||||||
. $command2API[$this -> post -> command]
|
. $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_POST, 1);
|
||||||
curl_setopt(
|
} else if (str_starts_with($this -> post -> command, 'device')) {
|
||||||
$ch,
|
$ch = curl_init(
|
||||||
CURLOPT_USERPWD,
|
$server_info[0]
|
||||||
$this -> post -> username
|
|
||||||
. ":"
|
. ":"
|
||||||
. $this -> post -> password
|
. $server_info[1]
|
||||||
|
. $command2API[$this -> post -> command]
|
||||||
|
. '?data='
|
||||||
|
. $this -> post -> device_name
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 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(
|
pg_insert(
|
||||||
@@ -56,6 +70,7 @@ class ECommand {
|
|||||||
'hf_mes_scada_edgeserver_controller_command',
|
'hf_mes_scada_edgeserver_controller_command',
|
||||||
[
|
[
|
||||||
'server_id' => $this -> post -> server_id,
|
'server_id' => $this -> post -> server_id,
|
||||||
|
'device_name' => $this -> post -> server_id ?? NULL,
|
||||||
'command' => $this -> post -> command,
|
'command' => $this -> post -> command,
|
||||||
'success' => $return
|
'success' => $return
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -162,28 +162,4 @@ class EConfigure {
|
|||||||
));
|
));
|
||||||
return pg_fetch_all($res);
|
return pg_fetch_all($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get_all_devices() {
|
|
||||||
$res = pg_query(
|
|
||||||
"SELECT server_id,
|
|
||||||
server.name AS server_name,
|
|
||||||
url, port,
|
|
||||||
device.name AS device_name,
|
|
||||||
conf -> '@DeviceType' AS device_type
|
|
||||||
FROM hf_mes_scada_edgeserver_controller_server server,
|
|
||||||
hf_mes_scada_edgeserver_controller_device device
|
|
||||||
WHERE (conf -> '@DeviceType') IS NOT NULL
|
|
||||||
AND server.id = server_id;"
|
|
||||||
);
|
|
||||||
$server_devices = pg_fetch_all($res);
|
|
||||||
|
|
||||||
$all_devices = [];
|
|
||||||
foreach ($server_devices as $device) {
|
|
||||||
if (!isset($all_devices[$device['server_id']]))
|
|
||||||
$all_devices[$device['server_id']] = array_slice($device, 0, 4);
|
|
||||||
$all_devices[$device['server_id']]['devices'][] = array_slice($device, -2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $all_devices;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function init_db($server_name, $port, $user, $password) {
|
|||||||
pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_command (
|
pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_command (
|
||||||
id serial8 primary key,
|
id serial8 primary key,
|
||||||
server_id serial2 references hf_mes_scada_edgeserver_controller_server(id),
|
server_id serial2 references hf_mes_scada_edgeserver_controller_server(id),
|
||||||
device_id text,
|
device_name text,
|
||||||
command text,
|
command text,
|
||||||
create_date timestamp NOT NULL DEFAULT NOW(),
|
create_date timestamp NOT NULL DEFAULT NOW(),
|
||||||
success bool
|
success bool
|
||||||
|
|||||||
Reference in New Issue
Block a user