diff --git a/conf/config.inc.php b/conf/config.inc.php index 6473fda..c50dbee 100644 --- a/conf/config.inc.php +++ b/conf/config.inc.php @@ -3,6 +3,8 @@ $config['img_root'] = '/home/xymp/photos/'; $config['video_root'] = '/home/xymp/videos/'; $config['term_logs_root'] = '/home/xymp/termLogs/'; +$config['upgrade_file_path'] = "D:/Workspace/Github/xymp_web/uploads/"; +$config['upgrade_root'] = "http://localhost/upgrades/"; $config['tmp_dir'] = '/home/xymp/tmp/'; $config['host'] = 'localhost'; $config['database'] = 'xymp'; diff --git a/maintain/web/api/queryRawData.php b/maintain/web/api/queryRawData.php index c08b0aa..b9554d0 100644 --- a/maintain/web/api/queryRawData.php +++ b/maintain/web/api/queryRawData.php @@ -2,18 +2,51 @@ include('config.inc.php'); +$result = array('res' => 0, 'data' => array()); + +$termId = isset($_GET['termId']) ? intval($_GET['termId']) : 0; +if (empty($termId)) +{ + echo json_encode($result); + exit; +} + +$values = array('tid' => $termId); + +$page = isset($_GET['p']) ? intval($_GET['p']) : 1; +$pageSize = isset($_GET['ps']) ? intval($_GET['ps']) : 20; +if ($pageSize <= 0) $pageSize = 20; + $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()); +$sql = 'SELECT COUNT(*) AS cnt FROM mntn_raw_reports WHERE `term_id`=:tid'; +$stmt = $db->prepare($sql); +$res = $stmt->execute($values); +$row = $stmt->fetch(); +$stmt = null; +if (!$row) +{ + header ('SqlCnt: ' . $sql); + echo json_encode($result); + exit; +} +$numberOfRows = $row['cnt']; +$numberOfPages = ceil(($numberOfRows + $pageSize - 1) / $pageSize); +if ($page > $numberOfPages) +{ + $page = $numberOfPages; +} + +$result['page'] = array('page' => 1, 'pageSize' => $pageSize, "totalPages" => $numberOfPages, "totalRecords" => $numberOfRows); -$sql = "SELECT t1.cmdid,t1.`display_name`,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name, t4.`id`,t4.term_id,t4.file_name,t4.`path`,t4.file_size,t4.create_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 .= " JOIN mntn_uploads AS t4 ON t1.id=t4.term_id ORDER BY t4.`id` DESC"; +$sql = 'SELECT t1.cmdid,t1.`display_name` AS displayName,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name, t4.`id`,t4.term_id,t4.content,t4.`id`,t4.`ip`,FROM_UNIXTIME(t4.create_time) AS createTime'; +$sql .= ' FROM mntn_raw_reports AS t4 JOIN terminals AS t1 ON t4.term_id=t1.`id` JOIN towers AS t2 ON t1.tower_id=t2.id JOIN `lines` AS t3 ON t2.line_id=t3.id'; +$sql .= ' WHERE t4.`term_id`=:tid ORDER BY t4.`id` DESC LIMIT ' . (($page - 1) * $pageSize) . ',' . $pageSize; $stmt = $db->prepare($sql); -$stmt->execute(); +$stmt->execute($values); $result['data'] = $stmt->fetchAll(); $stmt = null; diff --git a/maintain/web/api/queryUpgrades.php b/maintain/web/api/queryUpgrades.php new file mode 100644 index 0000000..8316dc4 --- /dev/null +++ b/maintain/web/api/queryUpgrades.php @@ -0,0 +1,27 @@ + \PDO::FETCH_ASSOC, + \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'" + ]); + +$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 .= " FROM mntn_upgrades WHERE `status`=1 OrDER BY `id` DESC"; +$stmt = $db->prepare($sql); +$stmt->execute(); + +$result['data'] = $stmt->fetchAll(); +$stmt = null; +foreach ($result['data'] as &$item) +{ + $item['path'] = $config['upgrade_root'] . $item['path']; +} +unset($item); + +header ('Access-Control-Allow-Origin: *'); +header ('Content-type: application/json; charset=utf-8'); +echo json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/maintain/web/api/uploadFile.php b/maintain/web/api/uploadFile.php new file mode 100644 index 0000000..baf53c4 --- /dev/null +++ b/maintain/web/api/uploadFile.php @@ -0,0 +1,57 @@ + 1, 'data' => array()); + +$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'" + ]); + + $title = empty($_POST['title']) ? '' : $_POST['title']; +if (isset($_FILES)) +{ + $termIds = array(); // cmdid => id + $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)"; + $stmt = $db->prepare($sql); + $stmt2 = null; + + foreach ($_FILES as $file) + { + $extension = pathinfo($file['name'], PATHINFO_EXTENSION); + $fileName = date('Ymd') . '_' . uniqid('log_'); + if (!empty($extension)) + { + $fileName .= '.' . $extension; + } + $dest = $config['upgrade_file_path'] . $fileName; + + if (!move_uploaded_file($file['tmp_name'], $dest)) + { + // error_log("move_uploaded_file failed: " . $dest); + continue; + } + + $md5 = md5($dest); + $item = array('fileName' => $file['name'], 'path' => $fileName, 'fileSize' => $file['size'], 'title' => $title, 'md5' => $md5); + $res = $stmt->execute($item); + if (!$res) + { + // error_log(print_r($stmt->errorInfo(), true)); + } + else + { + $item['id'] = $db->lastInsertId(); + $item['path'] = $config['upgrade_root'] . $item['path']; + $result['data'][] = $item; + } + } +} + +$result['res'] = 0; + +header ('Content-type: application/json; charset=utf-8'); +echo json_encode($result, JSON_UNESCAPED_UNICODE); diff --git a/maintain/web/upload.html b/maintain/web/upload.html new file mode 100644 index 0000000..9e7ab69 --- /dev/null +++ b/maintain/web/upload.html @@ -0,0 +1,87 @@ + + + + 日志 + + + + + + + + + + + + + + +
+ 返回首页 + + +
+
+
+
+ + + +
+
+
+ + + + +