更新脚本

main
Matthew 1 year ago
parent 6b54267f7e
commit 5ea6562483

@ -167,6 +167,13 @@ else
$fileName = empty($_GET['fn']) ? '' : $_GET['fn']; $fileName = empty($_GET['fn']) ? '' : $_GET['fn'];
$values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5, 'fileName' => $fileName)); $values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5, 'fileName' => $fileName));
} }
else if ($action == 'upd-ota')
{
$values['cmdName'] = 'yw_upd_ota';
$md5 = empty($_GET['md5']) ? '' : $_GET['md5'];
$fileName = empty($_GET['fn']) ? '' : $_GET['fn'];
$values['cmd'] = json_encode(array('url' => $_GET['url'], 'md5' => $md5, 'fileName' => $fileName));
}
else if ($action == 'start-frpc') else if ($action == 'start-frpc')
{ {
$values['cmdName'] = 'yw_cmd_start_frpc'; $values['cmdName'] = 'yw_cmd_start_frpc';

@ -84,7 +84,7 @@ if (count($conditions) > 0)
$conditionStr = ' WHERE ' . implode(' AND ', $conditions); $conditionStr = ' WHERE ' . implode(' AND ', $conditions);
} }
$sql = "SELECT t1.id, t1.cmdid,t1.`display_name`,t1.`protocol`,t1.bs_identifier AS `oid`,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,t4.comment"; $sql = "SELECT t1.id, t1.cmdid,t1.`display_name`,t1.`protocol`,t1.bs_identifier AS `oid`,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.last_ip,t4.in_maintain,t4.quick_hb,t4.mode_time,t4.comment";
$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 .= " 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; $sql .= " LEFT JOIN mntn_status AS t4 ON t1.id=t4.term_id " . $conditionStr;
if (empty($orderField)) if (empty($orderField))

@ -9,7 +9,7 @@ $db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database']
$result = array('res' => 0, 'data' => array()); $result = array('res' => 0, 'data' => array());
$sql = "SELECT `id`,`title`,file_name AS fileName,`path`,file_size AS fileSize,`md5`,create_time AS createTime,update_time AS updateTime"; $sql = "SELECT `id`,`title`,file_name AS fileName,`path`,file_size AS fileSize,`md5`,`type`,create_time AS createTime,update_time AS updateTime";
$sql .= " FROM mntn_upgrades WHERE `status`=1 OrDER BY `id` DESC"; $sql .= " FROM mntn_upgrades WHERE `status`=1 OrDER BY `id` DESC";
$stmt = $db->prepare($sql); $stmt = $db->prepare($sql);
$stmt->execute(); $stmt->execute();

@ -31,28 +31,30 @@ if ($action == 'del')
else if ($action == 'edt') else if ($action == 'edt')
{ {
$title = empty($reqData['title']) ? '' : $reqData['title']; $title = empty($reqData['title']) ? '' : $reqData['title'];
$id = empty($reqData['id']) ? 0 : intval($_PreqDataOST['id']); $id = empty($reqData['id']) ? 0 : intval($reqData['id']);
$termIds = empty($_POST['termIds']) ? array() : $reqData['termIds']; $cmdids = empty($_POST['cmdids']) ? array() : $reqData['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);
$cmdids = str_replace("'", "''", $cmdids);
$values = array('id' => $id, 'title' => $title); $values = array('id' => $id, 'title' => $title);
$sql = "UPDATE mntn_activities SET `title`=:title,`term_count`=:termCount WHERE `id`=:id LIMIT 1"; $sql = "UPDATE mntn_activities SET `title`=:title,`term_count`=:termCount WHERE `id`=:id LIMIT 1";
$stmt = $db->prepare($sql); $stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id, 'title' => $title, 'termCount' => count($termIds))); $stmt->execute(array('id' => $id, 'title' => $title, 'termCount' => count($cmdids)));
$sql = "DELETE FROM mntn_activity_terminals WHERE `activity_id`=:id"; $sql = "DELETE FROM mntn_activity_terminals WHERE `activity_id`=:id";
$stmt = $db->prepare($sql); $stmt = $db->prepare($sql);
$stmt->execute(array('id' => $id)); $stmt->execute(array('id' => $id));
$sql = "INSERT INTO mntn_activity_terminals(`activity_id`,`term_id`) VALUES(:id,:termId)"; $sql = "INSERT INTO mntn_activity_terminals(`activity_id`,`term_id`) SELECT :id AS activity_id,`id` FROM terminals WHERE `cmdid` IN('" . implode("','", $cmdids) . "')";
$stmt = $db->prepare($sql); $stmt = $db->prepare($sql);
foreach ($termIds as $termId) $stmt->execute(array('id' => $id));
{
$stmt->closeCursor();
$stmt->execute(array('id' => $id, 'termId' => $termId));
}
$result['data'][] = $id; $result['data'][] = $id;
} }
@ -87,6 +89,7 @@ else if ($action == 'new')
$result['data'][] = $id; $result['data'][] = $id;
} }
header ('Access-Control-Allow-Origin: *'); header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8'); header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE); echo json_encode($result, JSON_UNESCAPED_UNICODE);

@ -10,12 +10,13 @@ $db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database']
]); ]);
$title = empty($_POST['title']) ? '' : $_POST['title']; $title = empty($_POST['title']) ? '' : $_POST['title'];
$upgradeType = empty($_POST['upgradeType']) ? 0 : intval($_POST['upgradeType']);
if (isset($_FILES)) if (isset($_FILES))
{ {
$termIds = array(); // cmdid => id $termIds = array(); // cmdid => id
$paramTermId = isset($_GET['termId']) ? intval($_GET['termId']) : 0; $paramTermId = isset($_GET['termId']) ? intval($_GET['termId']) : 0;
$sql = "INSERT INTO mntn_upgrades(`title`,`file_name`,`path`,`file_size`,`md5`) VALUES(:title,:fileName,:path,:fileSize,:md5)"; $sql = "INSERT INTO mntn_upgrades(`title`,`file_name`,`path`,`file_size`,`md5`,`type`) VALUES(:title,:fileName,:path,:fileSize,:md5,:upgType)";
$stmt = $db->prepare($sql); $stmt = $db->prepare($sql);
$stmt2 = null; $stmt2 = null;
@ -36,7 +37,7 @@ if (isset($_FILES))
} }
$md5 = md5($dest); $md5 = md5($dest);
$item = array('fileName' => $file['name'], 'path' => $fileName, 'fileSize' => $file['size'], 'title' => $title, 'md5' => $md5); $item = array('fileName' => $file['name'], 'path' => $fileName, 'fileSize' => $file['size'], 'title' => $title, 'md5' => $md5, 'upgType' => $upgradeType);
$res = $stmt->execute($item); $res = $stmt->execute($item);
if (!$res) if (!$res)
{ {

@ -79,7 +79,7 @@ foreach ($rows as $row)
} }
$lineCondtion = $lineId ? ' WHERE t3.`id`=' . $lineId : ''; $lineCondtion = $lineId ? ' WHERE t3.`id`=' . $lineId : '';
$sql = "SELECT t1.id, t1.cmdid,t1.`display_name`,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name, FROM_UNIXTIME(t4.last_heartbeat) AS last_heartbeat,FROM_UNIXTIME(t4.boot_time) AS boot_time 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 = "SELECT t1.id, t1.cmdid,t1.`display_name`,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name, FROM_UNIXTIME(t4.last_heartbeat) AS last_heartbeat,last_heartbeat_ip,FROM_UNIXTIME(t4.boot_time) AS boot_time 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 terminal_status AS t4 ON t1.id=t4.term_id " . $lineCondtion . " ORDER BY t2.line_id,t1.cmdid"; $sql .= " LEFT JOIN terminal_status AS t4 ON t1.id=t4.term_id " . $lineCondtion . " ORDER BY t2.line_id,t1.cmdid";
$stmt = $db->query($sql); $stmt = $db->query($sql);
$rows = $stmt->fetchAll(); $rows = $stmt->fetchAll();

Loading…
Cancel
Save