|
|
|
<?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'"
|
|
|
|
]);
|
|
|
|
|
|
|
|
$body = @file_get_contents('php://input');
|
|
|
|
$debugMode = isset($_GET['dbg']) && ($_GET['dbg'] != 0);
|
|
|
|
|
|
|
|
header ('Content-type: application/json; charset=utf-8');
|
|
|
|
$result = array('yw' => 0, 'kxt' => 0, 'sj' => 0, 'isUpgrade' => 0);
|
|
|
|
|
|
|
|
// error_log($body);
|
|
|
|
|
|
|
|
$request = json_decode($body, true);
|
|
|
|
if ($debugMode)
|
|
|
|
{
|
|
|
|
$request['id'] = 'XY-SIMULATOR-0001';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$debugMode && !$request)
|
|
|
|
{
|
|
|
|
// $res = $stmt10->execute(array('termId' => 0, 'cmdName' => 'err1_' . time(), 'cmd' => '', 'cmdDesc' => ''));
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = 'SELECT `id` FROM terminals WHERE cmdid=:cmdid';
|
|
|
|
$stmt = $db->prepare($sql);
|
|
|
|
if (!$stmt->execute(array('cmdid' => $request['id'])))
|
|
|
|
{
|
|
|
|
// $res = $stmt10->execute(array('termId' => 0, 'cmdName' => 'err2_' . time(), 'cmd' => '', 'cmdDesc' => ''));
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$term = $stmt->fetch();
|
|
|
|
if (!$term)
|
|
|
|
{
|
|
|
|
// $res = $stmt10->execute(array('termId' => 0, 'cmdName' => 'err3_' . time(), 'cmd' => '', 'cmdDesc' => ''));
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = $db->prepare("SELECT in_maintain,quick_hb FROM mntn_status WHERE term_id=:termid");
|
|
|
|
$stmt->execute(array('termid' => $term['id']));
|
|
|
|
$termStatus = $stmt->fetch();
|
|
|
|
$stmt = null;
|
|
|
|
$result['yw'] = (isset($termStatus['in_maintain']) && ($termStatus['in_maintain'] != 0)) ? 1 : 0;
|
|
|
|
$result['kxt'] = (isset($termStatus['quick_hb']) && ($termStatus['quick_hb'] != 0)) ? 1 : 0;
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM mntn_cmds WHERE term_id=:termid ORDER BY id LIMIT 1";
|
|
|
|
$stmt = $db->prepare($sql);
|
|
|
|
if (!$stmt->execute(array('termid' => $term['id'])))
|
|
|
|
{
|
|
|
|
// $res = $stmt10->execute(array('termId' => 0, 'cmdName' => 'err4_' . time(), 'cmd' => print_r($stmt->errorInfo(), true), 'cmdDesc' => ''));
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = $db->prepare("INSERT INTO mntn_raw_reports(term_id, content) VALUES(:termid,:content)");
|
|
|
|
$stmt->execute(array('termid' => $term['id'], 'content' => $body));
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM mntn_cmds WHERE term_id=:termid ORDER BY id LIMIT 1";
|
|
|
|
$stmt = $db->prepare($sql);
|
|
|
|
if (!$stmt->execute(array('termid' => $term['id'])))
|
|
|
|
{
|
|
|
|
// $res = $stmt10->execute(array('termId' => 0, 'cmdName' => 'err5_' . time(), 'cmd' => print_r($stmt->errorInfo(), true), 'cmdDesc' => ''));
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$rows = $stmt->fetchAll();
|
|
|
|
if (!$rows || count($rows) == 0)
|
|
|
|
{
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "DELETE FROM mntn_cmds WHERE id=:id";
|
|
|
|
$stmt = $db->prepare($sql);
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($rows as $row)
|
|
|
|
{
|
|
|
|
// kxt: quick heartbeat
|
|
|
|
$cmdData = empty($row['cmd']) ? array() : json_decode($row['cmd'], true);
|
|
|
|
|
|
|
|
if ($row['name'] == 'upgrade')
|
|
|
|
{
|
|
|
|
if (!empty($cmdData['url']))
|
|
|
|
{
|
|
|
|
$result['isUpgrade'] = 1;
|
|
|
|
$result['sj'] = 1;
|
|
|
|
$result['url'] = $cmdData['url'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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']))
|
|
|
|
{
|
|
|
|
$result = array_merge($result, $cmdData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$debugMode)
|
|
|
|
{
|
|
|
|
$stmt->execute(array('id' => $row['id']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// {"kxt":1,"yw":1,"sj":1,"cmd"."*,"isUpgrade":1, "url":"http://180.166.218.222:40011/ds yunWei_0826value str".vv4.2.50.apk,NN"value int:2}
|
|
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|