@ -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');