更新脚本

main
BlueMatthew 2 years ago
parent 2635a0f699
commit 0baec3b3ab

@ -39,10 +39,13 @@ if (!file_exists($dest))
die;
}
$parts = pathinfo($row['file_name']);
$fileName = $parts['filename'] . '_' . str_replace(array('-', ' ', ':'), '', $row['create_time']) . '.' . $parts['extension'];
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . $row['file_size']);
Header("Content-Disposition: attachment; filename=" . $row['file_name']);
Header("Content-Disposition: attachment; filename=" . $fileName);
readfile($dest);
exit();

@ -75,6 +75,9 @@ if (!$rows || count($rows) == 0)
exit();
}
$sql = "INSERT INTO mntn_cmd_history(`id`,term_id,`name`,`cmd`,`desc`,`status`,`create_time`,`publish_time`) SELECT `id`,`term_id`,`name`,`cmd`,`desc`,1,create_time,NOW() FROM mntn_cmds WHERE `id`=:id";
$stmt2 = $db->prepare($sql);
$sql = "DELETE FROM mntn_cmds WHERE id=:id";
$stmt = $db->prepare($sql);
@ -119,6 +122,7 @@ foreach ($rows as $row)
if (!$debugMode)
{
$stmt2->execute(array('id' => $row['id']));
$stmt->execute(array('id' => $row['id']));
}
}

@ -1,8 +1,9 @@
<?php
$keyMapper = array('i1服务器' => 'cma', '心跳间隔' => 'heartbeatDuration', 'i1' => 'i1Version', 'yw' => 'maintainVersion', '电池' => 'battery', '系统重启' => 'rebootTimes',
'i1重启' => 'i1RebootTimes', '收' => 'recv', '拍' => 'photoTimes', '成' => 'success', '败' => 'failure', '传' => 'uploads', '心跳累计' => 'numberOfHb',
'网络异常' => 'networkError', '信号1' => 'signature1', '信号2' => 'signature2', '卡1' => 'simcard1', '卡2' => 'simcard2', 'mcu' => 'mcu', 'ai' => 'aiVersion', 'cam' => 'cameraService');
'重启' => 'rebootTimes', 'i1重启' => 'i1RebootTimes', 'i1启' => 'i1RebootTimes', '收' => 'recv', '拍' => 'photoTimes', '成' => 'success', '败' => 'failure',
'传' => 'uploads', '心跳累计' => 'numberOfHb', '心跳' => 'numberOfHb', '网络异常' => 'networkError', '网络' => 'networkError', '信号1' => 'signature1', '信号2' => 'signature2',
'卡1' => 'simcard1', '卡2' => 'simcard2', 'mcu' => 'mcu', 'ai' => 'aiVersion', 'cam' => 'cameraService', '主板温度' => 'mainBoardTmp', '电池温度' => 'batteryTmp');
function parseCmd($content)
{
@ -22,7 +23,11 @@ function parseCmd($content)
}
$key = trim(substr($item, 0, $pos));
if (isset($keyMapper[$key]))
if ($key == 'i1' && strpos($item, ':', $pos + 1) !== false)
{
$key = 'cma';
}
else if (isset($keyMapper[$key]))
{
$key = $keyMapper[$key];
}

@ -1,37 +0,0 @@
<?php
include('config.inc.php');
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
]);
$result = array('res' => 0, 'data' => array());
$id = empty($_GET['id']) ? 0 : intval($_GET['id']);
$values = array('id' => $id);
$sql = "SELECT `id`,`path` FROM mntn_upgrades WHERE `id`=:id";
$stmt = $db->prepare($sql);
$stmt->execute($values);
$rows = $stmt->fetchAll();
$stmt = null;
$sql = "DELETE FROM mntn_upgrades WHERE `id`=:id LIMIT 1";
$stmt = $db->prepare($sql);
foreach ($rows as $row)
{
$dest = $config['upgrade_file_path'] . $row['path'];
if (unlink($dest))
{
$stmt->execute(array('id' => $row['id']));
$result['data'][] = $row['id'];
}
}
unset($item);
header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE);

@ -33,12 +33,16 @@ if ($action == 'cancel')
{
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$sql = "DELETE FROM mntn_cmds WHERE `id`=:cid LIMIT 1";
$sql = "DELETE FROM mntn_cmds WHERE `id`=:id LIMIT 1";
$stmt1 = $db->prepare($sql);
$res = $stmt1->execute(array('cid' => $id));
$sql = "INSERT INTO mntn_cmd_history(`id`,term_id,`name`,`cmd`,`desc`,`status`,`create_time`,`publish_time`) SELECT `id`,`term_id`,`name`,`cmd`,`desc`,2,create_time,NOW() FROM mntn_cmds WHERE `id`=:id";
$stmt2 = $db->prepare($sql);
$res2 = $stmt2->execute(array('id' => $id));
$res1 = $stmt1->execute(array('id' => $id));
header ('Sql: ' . $sql . $id);
if (!$res)
if (!$res2 || !$res1)
{
print_r($stmt1->errorInfo());
}
@ -133,7 +137,8 @@ else
{
$values['cmdName'] = 'upgrade';
$md5 = empty($_GET['md5']) ? '' : $_GET['md5'];
$values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5));
$fileName = empty($_GET['fn']) ? '' : $_GET['fn'];
$values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5, 'fileName' => $fileName));
}
else if ($action == 'start-frpc')
{

@ -0,0 +1,48 @@
<?php
include('config.inc.php');
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
]);
$result = array('res' => 0, 'data' => array());
$action = empty($_GET['act']) ? '' : $_GET['act'];
if ($action == 'list')
{
$sql = "SELECT `id`,`title`,term_count AS termCount,create_time AS createTime,update_time AS updateTime";
$sql .= " FROM mntn_activities";
$sql .= " WHERE `status`=1 ORDER BY `id` DESC";
$stmt = $db->prepare($sql);
$stmt->execute();
$result['data'] = $stmt->fetchAll();
$stmt = null;
}
else if ($action == 'detail')
{
$sql = "SELECT `id`,`title`,term_count AS termCount,create_time AS createTime,update_time AS updateTime";
$sql .= " FROM mntn_activities";
$sql .= " WHERE `id`=:id ORDER BY `id` DESC";
$stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id));
$result['data']['activity'] = $stmt->fetch();
$stmt = null;
$sql = "SELECT t1.`id` AS termId,t1.cmdid,t1.`display_name` AS displayName,t1.`protocol`,t2.`name` AS towerName,t3.`name` AS lineName";
$sql .= " FROM terminals AS t1 JOIN mntn_activity_terminals AS t2 ON t1.id=t2.term_id";
$sql .= " WHERE t2.activity_id=:id";
$stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id));
$result['data']['terms'] = $stmt->fetchAll();
$stmt = null;
}
header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE);

@ -42,7 +42,7 @@ if ($queryType == 'pending')
}
else
{
$sql = 'SELECT t1.cmdid,t1.`display_name` AS displayName,t2.`name` AS cmdName,t2.`cmd`,t2.`create_time` AS createTime,t2.publish_time AS publishTime, t2.term_id AS termId,t2.`id` FROM ' . $tableName . ' AS t2 JOIN terminals AS t1 ON t2.term_id=t1.`id` ORDER BY t2.`id` DESC LIMIT ' . (($page - 1) * $pageSize) . ',' . $pageSize;
$sql = 'SELECT t1.cmdid,t1.`display_name` AS displayName,t2.`name` AS cmdName,t2.`cmd`,t2.`status`,t2.`create_time` AS createTime,t2.publish_time AS publishTime, t2.term_id AS termId,t2.`id` FROM ' . $tableName . ' AS t2 JOIN terminals AS t1 ON t2.term_id=t1.`id` ORDER BY t2.`id` DESC LIMIT ' . (($page - 1) * $pageSize) . ',' . $pageSize;
}
$stmt = $db->prepare($sql);
$res = $stmt->execute();

@ -0,0 +1,19 @@
<?php
include('config.inc.php');
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
]);
$result = array('res' => 0, 'data' => array());
$stmt = $db->prepare("SELECT * FROM `protocols`");
$stmt->execute();
$result['data'] = $stmt->fetchAll();
$stmt = null;
header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE);

@ -14,7 +14,8 @@ $values = array();
$orderField = '';
// 筛选接口 与的关系 查询的字段分别是出厂ID(oid)、装置编号cmdid、CMA服务器cma、版本信息aiVersion、i1Version、maintainVersion、cameraService并且每个筛选条件后面都带checbox框 勾选上定义的值为1 未勾选定义的为0 然后点击搜索筛选
$filterFields = array('cmdid', 'oid', 'cma', 'version');
// true: if value is not set, will ignored
$filterFields = array('cmdid', 'oid', 'cma', 'version', 'activity', 'protocol', 'mntned');
$filters = array();
if (isset($_GET['fc']) && $_GET['fc'] == intval($_GET['fc']))
@ -22,7 +23,7 @@ if (isset($_GET['fc']) && $_GET['fc'] == intval($_GET['fc']))
$numberOfFilters = intval($_GET['fc']);
for ($idx = 1; $idx <= $numberOfFilters; $idx++)
{
if (empty($_GET['fn' . $idx]) || empty($_GET['fv' . $idx]) || !in_array($_GET['fn' . $idx], $filterFields))
if (empty($_GET['fn' . $idx]) || !isset($_GET['fv' . $idx]) || $_GET['fv' . $idx] == '' || !in_array($_GET['fn' . $idx], $filterFields))
{
continue;
}
@ -58,8 +59,25 @@ if (isset($filters['cmdid']))
$values['cmdid'] = '%' . $filters['cmdid']['val'] . '%';
}
if (isset($filters['activity']) && !empty($filters['activity']['val']))
{
$notClause = $filters['activity']['rev'] ? ' NOT ' : '';
$conditions[] = 't1.`id` ' . $notClause . ' IN (SELECT term_id FROM mntn_activity_terminals WHERE `activity_id`=:activityId)';
$values['activityId'] = $filters['activity']['val'];
}
if (isset($filters['protocol']) && !empty($filters['protocol']['val']))
{
$notClause = $filters['protocol']['rev'] ? '<>' : '=';
$conditions[] = 't1.`protocol`' . $notClause . ':protocol';
$values['protocol'] = $filters['protocol']['val'];
}
$conditions[] = "t4.`raw_report_time`<>0";
if (isset($filters['mntned']) && !empty($filters['mntned']['val']))
{
$notClause = (intval($filters['mntned']['val']) == 1) ? '<>' : '=';
$conditions[] = 't4.`raw_report_time`' . $notClause . '0';
}
// $conditions[] = "t4.`term_id` IN (SELECT term_id FROM mntn_activity_terminals WHERE `activity_id`=10001)";
$conditionStr = '';
if (count($conditions) > 0)
{
@ -89,7 +107,7 @@ foreach($rows as &$row)
$row['last_heartbeat_time'] = empty($row['last_heartbeat']) ? '' : substr($row['last_heartbeat'], 11);
if (empty($row['raw_report']))
{
$row['raw_report'] = $obj;
$row['raw_report'] = array();
}
else
{
@ -100,7 +118,7 @@ foreach($rows as &$row)
}
}
if (!empty($row['raw_report']['oid']) && empty($row['oid']))
if (!is_object($row['raw_report']) && !empty($row['raw_report']['oid']) && empty($row['oid']))
{
$row['oid'] = $row['raw_report']['oid'];
}
@ -150,7 +168,7 @@ unset($row);
$desc = false;
if (isset($_GET['asc']))
{
$desc = ($_GET['desc'] != 0);
$desc = ($_GET['asc'] != 0);
}
function cmp($a, $b)
@ -191,6 +209,7 @@ if (!empty($orderField))
usort($result['data'], 'cmp');
}
$result['termCount'] = count($result['data']);
header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8');

@ -0,0 +1,85 @@
<?php
include('config.inc.php');
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
]);
$result = array('res' => 0, 'data' => array());
$id = empty($_REQUEST['id']) ? 0 : intval($_REQUEST['id']);
$action = empty($_REQUEST['act']) ? '' : $_REQUEST['act'];
if ($action == 'del')
{
$values = array('id' => $id);
$sql = "DELETE FROM mntn_activity_terminals WHERE `activity_id`=:id";
$stmt = $db->prepare($sql);
$stmt->execute($values);
$stmt = null;
$sql = "DELETE FROM mntn_activities WHERE `id`=:id LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id));
}
else if ($action == 'edt')
{
$title = empty($_POST['title']) ? '' : $_POST['title'];
$id = empty($_POST['id']) ? 0 : intval($_POST['id']);
$termIds = empty($_POST['termIds']) ? array() : $_POST['termIds'];
$values = array('id' => $id, 'title' => $title);
$sql = "UPDATE mntn_activities SET `title`=:title,`term_count`=:termCount WHERE `id`=:id LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id, 'title' => $title, 'termCount' => count($termIds)));
$sql = "DELETE FROM mntn_activity_terminals WHERE `activity_id`=:id";
$stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id));
$sql = "INSERT INTO mntn_activity_terminals(`activity_id`,`term_id`) VALUES(:id,:termId)";
$stmt = $db->prepare($sql);
foreach ($termIds as $termId)
{
$stmt->closeCursor();
$stmt->execute(array('id' => $id, 'termId' => $termId));
}
$result['data'][] = $id;
}
else if ($action == 'new')
{
$title = empty($_POST['title']) ? '' : $_POST['title'];
$id = empty($_POST['id']) ? 0 : intval($_POST['id']);
$cmdids = isset($_POST['cmdids']) ? $_POST['cmdids'] : '';
$contents = str_replace("\r\n", "\n", $cmdids);
$contents = str_replace("\n\r", "\n", $contents);
$contents = str_replace("\r", "\n", $contents);
$cmdids = explode("\n", $contents);
$sql = "INSERT INTO mntn_activities(`title`,`term_count`) VALUES(:title,:termCount)";
$stmt = $db->prepare($sql);
$stmt->execute(array('title' => $title, 'termCount' => count($cmdids)));
$id = $db->lastInsertId();
if (!empty($cmdids))
{
$sql = "INSERT INTO mntn_activity_terminals(`activity_id`,`term_id`) SELECT :id,`id` FROM terminals WHERE `cmdid` IN('" . implode("','", $cmdids) . "')";
$stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id));
}
$result['data'][] = $id;
}
header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE);

@ -0,0 +1,53 @@
<?php
include('config.inc.php');
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
]);
$result = array('res' => 0, 'data' => array());
$id = empty($_GET['id']) ? 0 : intval($_GET['id']);
$action = empty($_GET['act']) ? '' : $_GET['act'];
if ($action == 'del')
{
$values = array('id' => $id);
$sql = "SELECT `id`,`path` FROM mntn_upgrades WHERE `id`=:id";
$stmt = $db->prepare($sql);
$stmt->execute($values);
$rows = $stmt->fetchAll();
$stmt = null;
$sql = "DELETE FROM mntn_upgrades WHERE `id`=:id LIMIT 1";
$stmt = $db->prepare($sql);
foreach ($rows as $row)
{
$dest = $config['upgrade_file_path'] . $row['path'];
if (unlink($dest))
{
$stmt->execute(array('id' => $row['id']));
$result['data'][] = $row['id'];
}
}
unset($item);
}
else if ($action == 'edt')
{
$title = empty($_GET['title']) ? '' : $_GET['title'];
$values = array('id' => $id, 'title' => $title);
$sql = "UPDATE mntn_upgrades SET `title`=:title WHERE `id`=:id LIMIT 1";
$stmt = $db->prepare($sql);
$stmt->execute($values);
$result['data'][] = $id;
}
header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE);

@ -22,7 +22,7 @@ if (isset($_FILES))
foreach ($_FILES as $file)
{
$extension = pathinfo($file['name'], PATHINFO_EXTENSION);
$fileName = date('Ymd') . '_' . uniqid('log_');
$fileName = date('Ymd') . '_' . uniqid('upd_');
if (!empty($extension))
{
$fileName .= '.' . $extension;

Loading…
Cancel
Save