diff --git a/maintain/index.php b/maintain/index.php index c5a3434..7aedda6 100644 --- a/maintain/index.php +++ b/maintain/index.php @@ -91,15 +91,6 @@ foreach ($rows as $row) { if (!empty($cmdData['url'])) { - $pos = strpos($cmdData['url'], '?'); - if ($pos !== false) - { - $cmdData['url'] .= '?termId=' . urlencode($row['term_id']); - } - else - { - $cmdData['url'] .= '&termId=' . urlencode($row['term_id']); - } $result['isUpgrade'] = 1; $result['sj'] = 1; $result['url'] = $cmdData['url']; @@ -107,6 +98,22 @@ foreach ($rows as $row) } else { + if ($row['name'] == 'upload-logs') + { + if (!empty($cmdData['url'])) + { + $pos = strpos($cmdData['url'], '?'); + if ($pos !== false) + { + $cmdData['url'] .= '?termId=' . urlencode($row['term_id']); + } + else + { + $cmdData['url'] .= '&termId=' . urlencode($row['term_id']); + } + } + } + $result['cmd'] = $row['name']; if (!empty($row['cmd'])) { diff --git a/maintain/web/api/doAction.php b/maintain/web/api/doAction.php index 078d639..9f4d3ae 100644 --- a/maintain/web/api/doAction.php +++ b/maintain/web/api/doAction.php @@ -7,17 +7,18 @@ $db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'] \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" ]); + $action = isset($_GET['act']) ? $_GET['act'] : ''; $termId = isset($_GET['termId']) ? intval($_GET['termId']) : 0; $termIdsStr = isset($_GET['termIds']) ? $_GET['termIds'] : ''; -$mntnMode = isset($_GET['mntn']) ? intval($_GET['mntn']) : 0; -$quickHeartbeat = isset($_GET['quickhb']) ? intval($_GET['quickhb']) : 0; if (!$termId && !$termIdsStr) { exit(); } +$result = array('code' => 0, 'data' => array()); + $termIds = array(); if (!empty($termIdsStr)) { @@ -28,127 +29,155 @@ else $termIds[] = $termId; } -$sql = "DELETE FROM mntn_cmds WHERE term_id=:termid AND `name`=:cmdName"; -$stmt1 = $db->prepare($sql); +if ($action == 'mntn') +{ + $mntnMode = isset($_GET['mntn']) ? intval($_GET['mntn']) : 0; + // $quickHeartbeat = isset($_GET['quickhb']) ? intval($_GET['quickhb']) : 0; -$sql = "INSERT INTO mntn_cmds(term_id,`name`,`cmd`,`desc`) VALUES(:termId,:cmdName,:cmd,:cmdDesc)"; -$stmt2 = $db->prepare($sql); + // header("qhb:" . $quickHeartbeat); + header("mntn:" . $mntnMode); -$sql = "UPDATE mntn_status SET `quick_hb`=:qhb,`in_maintain`=:mntn,`mode_time`=CURRENT_TIMESTAMP() WHERE term_id=:termId"; -$stmt3 = $db->prepare($sql); + $sql = "UPDATE mntn_status SET `in_maintain`=:mntn,`mode_time`=CURRENT_TIMESTAMP() WHERE term_id=:termId"; + $stmt3 = $db->prepare($sql); -header("qhb:" . $quickHeartbeat); -header("mntn:" . $mntnMode); + foreach($termIds as $termId) + { + $res = $stmt3->execute(array('termId' => $termId, 'mntn' => $mntnMode)); + if (!$res) + { + print_r($stmt3->errorInfo()); + } -$result = array('code' => 0, 'data' => array()); -foreach($termIds as $termId) + $result['data'][] = $termId; + } +} +else if ($action == 'quickhb') { - $termId = intval($termId); + $quickHeartbeat = isset($_GET['quickhb']) ? intval($_GET['quickhb']) : 0; - $values = array('termId' => $termId, 'cmd' => '', 'cmdDesc' => '', 'cmdName' => ''); + header("qhb:" . $quickHeartbeat); - if ($action == 'reset') - { - $values['cmdName'] = 'yw_cmd_android_reboot'; - } - else if ($action == 'reset-mcu') - { - $values['cmdName'] = 'yw_cmd_mcu_reboot'; - } - else if ($action == 'upload-logs') - { - $values['cmdName'] = 'yw_cmd_upload_i1_zip_log'; - $values['cmd'] = json_encode(array('url' => $_GET['url'])); - } - else if ($action == 'set-cma') - { - $values['cmdName'] = 'i1_cmd_set_i1_server_ip_port'; - $values['cmd'] = json_encode(array('value_str' => $_GET['ip'], 'value_int' => intval($_GET['port']))); - } - else if ($action == 'set-mntn-svr') - { - $values['cmdName'] = 'i1_cmd_set_xy_yw_ip_port'; - $values['cmd'] = json_encode(array('value_str' => $_GET['ip'], 'value_int' => intval($_GET['port']))); - } - else if ($action == 'set-hb') - { - $values['cmdName'] = 'i1_cmd_set_i1_heart_beat_time'; - $values['cmd'] = json_encode(array('value_int' => intval($_GET['hb']))); - } - else if ($action == 'upload-logs') - { - $values['cmdName'] = 'yw_cmd_upload_i1_zip_log'; - $values['cmd'] = json_encode(array('url' => intval($_GET['url']))); - } - else if ($action == 'upgrade') - { - $values['cmdName'] = 'upgrade'; - $md5 = empty($_GET['md5']) ? '' : $_GET['md5']; - $values['cmd'] = json_encode(array('url' => intval($_GET['url']), 'md5' => $md5)); - } - else if ($action == 'start-frpc') - { - $values['cmdName'] = 'yw_cmd_start_frpc'; - // $frpc['cmd_state'] = 1; - $frpc['server_addr'] = empty($_GET['server_addr']) ? '' : $_GET['server_addr']; - $frpc['server_port'] = empty($_GET['server_port']) ? '0' : intval($_GET['server_port']) . ''; - $frpc['frpc_type'] = empty($_GET['frpc_type']) ? '' : $_GET['frpc_type']; - $frpc['type'] = empty($_GET['type']) ? '' : $_GET['type']; - $frpc['local_ip'] = empty($_GET['local_ip']) ? '' : $_GET['local_ip']; - $frpc['local_port'] = empty($_GET['local_port']) ? '0' : intval($_GET['local_port']) . ''; - $frpc['remote_port'] = empty($_GET['remote_port']) ? '0' : intval($_GET['local_port']) . ''; - - $frpc_str = json_encode($frpc); - - $values['cmd'] = json_encode(array('frpc' => $frpc)); - } - else if ($action == 'stop-frpc') - { - $values['cmdName'] = 'yw_cmd_stop_frpc'; - } - else if ($action == 'stop-aging-test') - { - $values['cmdName'] = 'i1_cmd_stop_aging_test'; - } - else - { - // continue; - } + $sql = "UPDATE mntn_status SET `quick_hb`=:qhb,`mode_time`=CURRENT_TIMESTAMP() WHERE term_id=:termId"; + $stmt3 = $db->prepare($sql); - $res = $stmt3->execute(array('termId' => $termId, 'mntn' => $mntnMode, 'qhb' => $quickHeartbeat)); - if (!$res) + foreach($termIds as $termId) { - print_r($stmt3->errorInfo()); + $res = $stmt3->execute(array('termId' => $termId, 'qhb' => $quickHeartbeat)); + if (!$res) + { + print_r($stmt3->errorInfo()); + } + + $result['data'][] = $termId; } +} +else +{ + $sql = "DELETE FROM mntn_cmds WHERE term_id=:termid AND `name`=:cmdName"; + $stmt1 = $db->prepare($sql); - if (!empty($action)) + $sql = "INSERT INTO mntn_cmds(term_id,`name`,`cmd`,`desc`) VALUES(:termId,:cmdName,:cmd,:cmdDesc)"; + $stmt2 = $db->prepare($sql); + + + foreach($termIds as $termId) { - $res = $stmt1->execute(array('termid' => $termId, 'cmdName' => $values['cmdName'])); - if (!$res) + $termId = intval($termId); + + $values = array('termId' => $termId, 'cmd' => '', 'cmdDesc' => '', 'cmdName' => ''); + + if ($action == 'reset') { - // print_r($stmt1->errorInfo()); + $values['cmdName'] = 'yw_cmd_android_reboot'; + } + else if ($action == 'reset-mcu') + { + $values['cmdName'] = 'yw_cmd_mcu_reboot'; + } + else if ($action == 'upload-logs') + { + $values['cmdName'] = 'yw_cmd_upload_i1_zip_log'; + $values['cmd'] = json_encode(array('url' => $_GET['url'])); + } + else if ($action == 'set-cma') + { + $values['cmdName'] = 'i1_cmd_set_i1_server_ip_port'; + $values['cmd'] = json_encode(array('value_str' => $_GET['ip'], 'value_int' => intval($_GET['port']))); + } + else if ($action == 'set-mntn') + { + $values['cmdName'] = 'i1_cmd_set_xy_yw_ip_port'; + $values['cmd'] = json_encode(array('value_str' => $_GET['ip'], 'value_int' => intval($_GET['port']))); + } + else if ($action == 'set-hb') + { + $values['cmdName'] = 'i1_cmd_set_i1_heart_beat_time'; + $values['cmd'] = json_encode(array('value_int' => intval($_GET['hb']))); + } + else if ($action == 'upgrade') + { + $values['cmdName'] = 'upgrade'; + $md5 = empty($_GET['md5']) ? '' : $_GET['md5']; + $values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5)); + } + else if ($action == 'start-frpc') + { + $values['cmdName'] = 'yw_cmd_start_frpc'; + // $frpc['cmd_state'] = 1; + $frpc['server_addr'] = empty($_GET['server_addr']) ? '' : $_GET['server_addr']; + $frpc['server_port'] = empty($_GET['server_port']) ? '0' : intval($_GET['server_port']) . ''; + $frpc['frpc_type'] = empty($_GET['frpc_type']) ? '' : $_GET['frpc_type']; + $frpc['type'] = empty($_GET['type']) ? '' : $_GET['type']; + $frpc['local_ip'] = empty($_GET['local_ip']) ? '' : $_GET['local_ip']; + $frpc['local_port'] = empty($_GET['local_port']) ? '0' : intval($_GET['local_port']) . ''; + $frpc['remote_port'] = empty($_GET['remote_port']) ? '0' : intval($_GET['remote_port']) . ''; + + $frpc_str = json_encode($frpc); + + $values['cmd'] = json_encode(array('frpc' => $frpc)); + } + else if ($action == 'stop-frpc') + { + $values['cmdName'] = 'yw_cmd_stop_frpc'; + } + else if ($action == 'stop-aging-test') + { + $values['cmdName'] = 'i1_cmd_stop_aging_test'; + } + else + { + // continue; } - $res = $stmt2->execute($values); - - if (!$res) + if (!empty($action)) { - // print_r($stmt2->errorInfo()); + $res = $stmt1->execute(array('termid' => $termId, 'cmdName' => $values['cmdName'])); + if (!$res) + { + // print_r($stmt1->errorInfo()); + } + + $res = $stmt2->execute($values); + + if (!$res) + { + // print_r($stmt2->errorInfo()); + } } - } - if ($res) - { - $result['data'][] = $termId; + if ($res) + { + $result['data'][] = $termId; + } + + // i1_cmd_set_i1_server_ip_port //参数 value_str:ip value_int:port + // i1_cmd_set_xy_yw_ip_port //参数 value_str:ip value_int:port + // i1_cmd_set_i1_heart_beat_time ////参数 value_int:心跳间隔 + } - - // i1_cmd_set_i1_server_ip_port //参数 value_str:ip value_int:port - // i1_cmd_set_xy_yw_ip_port //参数 value_str:ip value_int:port - // i1_cmd_set_i1_heart_beat_time ////参数 value_int:心跳间隔 +} - -} header ('Content-type: application/json; charset=utf-8'); diff --git a/maintain/web/api/queryTerms.php b/maintain/web/api/queryTerms.php index cc7bde0..fd2fd7f 100644 --- a/maintain/web/api/queryTerms.php +++ b/maintain/web/api/queryTerms.php @@ -27,13 +27,14 @@ if (!empty($_GET['cmdid'])) $values['cmdid'] = '%' . $_GET['cmdid'] . '%'; } +$conditions[] = "t4.`raw_report_time`<>0"; $conditionStr = ''; if (count($conditions) > 0) { $conditionStr = ' WHERE ' . implode($conditions, ' AND '); } -$sql = "SELECT t1.id, t1.cmdid,t1.`display_name`,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name, t4.last_raw_report AS raw_report,FROM_UNIXTIME(t4.raw_report_time) AS last_heartbeat,t4.in_maintain,t4.quick_hb,t4.mode_time"; +$sql = "SELECT t1.id, t1.cmdid,t1.`display_name`,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name, t4.last_raw_report AS raw_report,t4.raw_report_time AS last_heartbeat_ts,FROM_UNIXTIME(t4.raw_report_time) AS last_heartbeat,t4.in_maintain,t4.quick_hb,t4.mode_time"; $sql .= " FROM terminals AS t1 JOIN towers AS t2 ON t1.tower_id=t2.id JOIN `lines` AS t3 ON t2.line_id=t3.id"; $sql .= " LEFT JOIN mntn_status AS t4 ON t1.id=t4.term_id " . $conditionStr . " ORDER BY t2.line_id,t2.`order`,t1.cmdid"; $stmt = $db->prepare($sql); diff --git a/maintain/web/index.html b/maintain/web/index.html index 18270fe..54ec9b3 100644 --- a/maintain/web/index.html +++ b/maintain/web/index.html @@ -14,6 +14,12 @@ + @@ -197,12 +203,21 @@ $.getJSON(urlTarget, params, function(result) { - $('#term-cnt').text("装置数量:" + result.data.length); var tableResult = $('#tbody-result')[0]; + var dt = new Date(); + var ts = dt.getTime() / 1000; + var mntn_status = $('#mntn-status').val(); + var terminalCnt = 0; for (var idx = 0; idx < result.data.length; idx++) { var item = result.data[idx]; + var status_online = (ts - item.last_heartbeat_ts <= 720); + if (((mntn_status == 2) && status_online) || ((mntn_status == 1) && !status_online)) + { + continue; + } + terminalCnt++; var msgsObj = {}; if ('msgs' in item.raw_report) { @@ -228,12 +243,12 @@ } var td3 = '' + item.cmdid + ''; - var td4 = (item.in_maintain == 0) ? '否' : '是'; - var td5 = (item.quick_hb == 0) ? '否' : '是'; + var td4 = ''; + var td5 = ''; var td6 = ConvertProtocolName(item.protocol); // var hbDetailUrl = "hb.html?term_id=" + item.id + "&cmdid=" + item.cmdid + "&st=" + startTime + "&et=" + endTime; - var td7 = item.last_heartbeat_time; + var td7 = '' + item.last_heartbeat_time + ''; var td8 = (('numberOfHb' in msgsObj) ? msgsObj.numberOfHb : ''); var td9 = (('heartbeatDuration' in msgsObj) ? msgsObj.heartbeatDuration : ''); var td10 = ('recv' in msgsObj) ? msgsObj.recv : ''; @@ -254,6 +269,8 @@ var td20 = ('cma' in msgsObj) ? msgsObj.cma : ''; var td21 = (('simcard1' in msgsObj) ? ('' + msgsObj.simcard1 + '') : '') + '
' + (('simcard2' in msgsObj) ? ('' + msgsObj.simcard2 + '') : ''); + var td22 = ('oid' in item.raw_report) ? item.raw_report.oid : ''; + var version = ''; if ('i1Version' in msgsObj) { @@ -276,18 +293,29 @@ { version += '  MCU:' + msgsObj.mcu; } - var td22 = version; + var td23 = version; // "安徽欣影ds2-2x/4x,yw:0829_4.2.502, i1:ahxy_0829_4.2.502, cam:4.2.1, ai:1.1.0_1, i1服务器:47.96.238.157:6891 ,心跳间隔:1 , // 电池:6.3V\/0.2V\/87% ,系统重启:1 ,i1重启:13 ,收:10:52 ,拍:48\/44 ,成:44 ,败:0 ,传:44 , // 心跳累计:142 ,网络异常:139 ,信号1:4\/99 ,信号2:4\/99 ,卡1:898604F5122380159566,卡2: ,mcu:MTK_MCU_V3.2.5 Aug 9 2023" - var tr = AppendTable(tableResult, td1, td2, td3, td4, td5, td6, td7, td8, td9, td10, td11, td12, td13, td14, td15, td16, td17, td18, td19, td20, td21, td22); - if ((item.in_maintain != 0) || (item.quick_hb != 0)) + var tr = AppendTable(tableResult, td1, td2, td3, td4, td5, td6, td7, td8, td9, td10, td11, td12, td13, td14, td15, td16, td17, td18, td19, td20, td21, td22, td23); + if (item.in_maintain != 0) { - tr.classList.add("in_maintain"); + tr.cells[3].classList.add("in_maintain"); } + + if (item.quick_hb != 0) + { + tr.cells[4].classList.add("in_maintain"); + } + + + } + + $('#term-cnt').text("装置数量:" + terminalCnt); + }); } @@ -332,6 +360,54 @@ } } + function UpdateMaintainMode(src, termId) { + var params = {'act': 'mntn'}; + params['mntn'] = $(src).prop('checked') ? 1 : 0; + var urlTarget = 'api/doAction.php'; + params['termId'] = termId; + + $.getJSON(urlTarget, params, function(result) { + + for (var idx = 0; idx < result.data.length; idx++) + { + if (result.data[idx] == termId) + { + if (params['mntn'] == 1) { + src.parentNode.classList.add("in_maintain"); + } else { + src.parentNode.classList.remove("in_maintain"); + } + } + // $("#cmdid-" + result.data[idx]).addClass("sent"); + } + + }); + } + + function UpdateQuickHbMode(src, termId) { + var params = {'act': 'quickhb'}; + params['quickhb'] = $(src).prop('checked') ? 1 : 0; + var urlTarget = 'api/doAction.php'; + params['termId'] = termId; + + $.getJSON(urlTarget, params, function(result) { + + for (var idx = 0; idx < result.data.length; idx++) + { + if (result.data[idx] == termId) + { + if (params['quickhb'] == 1) { + src.parentNode.classList.add("in_maintain"); + } else { + src.parentNode.classList.remove("in_maintain"); + } + } + // $("#cmdid-" + result.data[idx]).addClass("sent"); + } + + }); + } + $('#btn-send').click(function() { var act = $('#act').val(); if ((act == null || act == '') && !$('#mntn-mode').prop('checked') && !$('#quick-hb-mode').prop('checked')) { @@ -419,7 +495,7 @@ params['remote_port'] = $('#frpc-remote-port').val(); if (params['remote_port'] == null || params['remote_port'] == '') { alert('请输入Remote Port。'); - $('#frpc-local-ip').focus(); + $('#frpc-remote-port').focus(); return; } params['frpc_type'] = $('#frpc-type').val(); diff --git a/maintain/web/styles/style.css b/maintain/web/styles/style.css index 5f9bc9a..ccb61a2 100644 --- a/maintain/web/styles/style.css +++ b/maintain/web/styles/style.css @@ -200,12 +200,23 @@ TD.merged-dark color: green; } -tr.in_maintain +tr.in_maintain, +td.in_maintain { background-color: red; } -tr.in_maintain td +td.in_maintain { color: yellow; } + +.online-hb +{ + color: green; +} + +.offline-hb +{ + color: gray; +} \ No newline at end of file
+ +   @@ -53,7 +59,6 @@ -     运维模式 快心跳模式       @@ -141,6 +146,7 @@ 重启次数 CMA服务器 SIM卡出厂Id 版本