node configure增改接近完成,删除后端还没做

This commit is contained in:
Yu Sun
2022-07-07 01:27:45 +08:00
parent 331a941941
commit e018f19f09
189 changed files with 25627 additions and 9 deletions

49
EdgeManager.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
require_once __DIR__ . '/vendor/autoload.php';
use EdgeManager\EDataCapture\{ EDataCapture, ENodeConfigure };
$options = getopt('h::', ['server_name:', 'user:', 'password:', 'help::']);
init_db($options['server_name'], $options['user'], $options['password']);
$worker = new Worker('http://0.0.0.0:1818');
$worker -> name = 'CaptureWorker';
$worker -> onWorkerStart = function(Worker $worker) {
global $options, $dbconn;
$dbconn = pg_connect(sprintf( "host=%s dbname=scada user=%s password=%s",
$options['server_name'], $options['user'], $options['password']));
};
$worker -> onMessage = function(TcpConnection $connection, Request $request) {
global $options, $dbconn;
$post = $request -> post();
if (isset($post['action']) and str_contains($post['action'], 'node')) {
$action = $post['action'];
unset($post['action']);
$enode_configure = new ENodeConfigure($dbconn, $post = $post);
$res = $enode_configure -> $action();
if ($res)
$connection -> send(json_encode(array ('code' => 0,
'msg' => 'Set threshold success')));
}
$get = $request -> get();
if (isset($get['query']) and $get['query'] == 'nodes') {
$enode_configure = new ENodeConfigure($dbconn, $get = $get);
$nodes = $enode_configure -> get_nodes();
if (is_null($nodes))
$connection -> send(json_encode(array('code' => 1, 'msg' => 'no node data')));
else
$connection -> send(json_encode(array('code' => 0, 'data' => $nodes)));
}
};
Worker::runAll();