493 lines
14 KiB
PHP
493 lines
14 KiB
PHP
<?php
|
|
include( "config.php" );
|
|
include( "session.php" );
|
|
date_default_timezone_set('PRC');
|
|
ini_set( 'default_socket_timeout', 2 );
|
|
$result = ( object )array( 'error' => '' );
|
|
|
|
if ( isset( $_GET[ 'func' ] ) )
|
|
call_user_func( $_GET[ 'func' ] );
|
|
else
|
|
exit;
|
|
echo json_encode( $result , JSON_UNESCAPED_UNICODE);
|
|
|
|
function setPasswd() {
|
|
global $result;
|
|
|
|
$old = $_POST[ 'old' ];
|
|
$new1 = $_POST[ 'new1' ];
|
|
$new2 = $_POST[ 'new2' ];
|
|
$json_string = file_get_contents( '/link/config/passwd.json' );
|
|
$data = json_decode( $json_string, true );
|
|
if ( $data[ 0 ][ "passwd" ] != md5( $old ) ) {
|
|
$result->error = "<cn>原密码错误</cn><en>Original password wrong</en>";
|
|
return;
|
|
}
|
|
|
|
if ( $new1 != $new2 ) {
|
|
$result->error = "<cn>密码不一致</cn><en>Password inconformity</en>";
|
|
return;
|
|
}
|
|
|
|
$data[ 0 ][ "passwd" ] = md5( $new1 );
|
|
|
|
$json = json_encode( $data );
|
|
file_put_contents( '/link/config/passwd.json', $json );
|
|
$result->result = "<cn>修改密码成功</cn><en>Save password success</en>";
|
|
}
|
|
|
|
function getTime() {
|
|
global $result;
|
|
$result->result = date( "Y-m-d H:i:s", intval( time() ) );
|
|
}
|
|
|
|
function delRes() {
|
|
exec( 'rm /link/res/'. $_POST[ 'file' ] );
|
|
}
|
|
|
|
function setTime() {
|
|
exec( "/link/bin/rtc -s time " . $_POST[ 'time' ]. " '".$_POST[ 'time2' ]."'" );
|
|
exec( "/link/bin/rtc -g time" );
|
|
global $result;
|
|
$result->result = "/link/bin/rtc -s time " . $_POST[ 'time' ];
|
|
}
|
|
|
|
function reboot() {
|
|
exec( '/link/shell/reboot.sh' );
|
|
}
|
|
|
|
function resetCfg() {
|
|
exec( '/link/shell/reset.sh' );
|
|
}
|
|
|
|
function setNDI() {
|
|
global $result;
|
|
$json_string = file_get_contents( '/link/config/ndi.json' );
|
|
$data = json_decode( $json_string, true );
|
|
$data[ "ndi" ] = $_POST[ 'ndi' ];
|
|
$json = json_encode( $data , JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
|
file_put_contents( '/link/config/ndi.json', $json );
|
|
}
|
|
|
|
function setNetwork() {
|
|
global $result;
|
|
$json_string = file_get_contents( '/link/config/net.json' );
|
|
$data = json_decode( $json_string, true );
|
|
$data[ "ip" ] = $_POST[ 'ip' ];
|
|
$data[ 'mask' ] = $_POST[ 'mask' ];
|
|
$data[ 'gateway' ] = $_POST[ 'gateway' ];
|
|
$data[ 'dns' ] = $_POST[ 'dns' ];
|
|
if(isset($_POST[ 'dhcp' ]))
|
|
{
|
|
$data[ 'dhcp' ] = ($_POST[ 'dhcp' ]=="true");
|
|
}
|
|
$result->mask = $data[ 'mask' ];
|
|
$result->data = $data;
|
|
$json = json_encode( $data );
|
|
file_put_contents( '/link/config/net.json', $json );
|
|
exec( '/link/shell/setNetwork.sh' );
|
|
}
|
|
|
|
function setNetwork2() {
|
|
global $result;
|
|
$json_string = file_get_contents( '/link/config/net2.json' );
|
|
$data = json_decode( $json_string, true );
|
|
$data[ "ip" ] = $_POST[ 'ip' ];
|
|
$data[ 'mask' ] = $_POST[ 'mask' ];
|
|
$data[ 'gateway' ] = $_POST[ 'gateway' ];
|
|
$data[ 'dns' ] = $_POST[ 'dns' ];
|
|
if(isset($_POST[ 'dhcp' ]))
|
|
{
|
|
$data[ 'dhcp' ] = ($_POST[ 'dhcp' ]=="true");
|
|
}
|
|
$result->mask = $data[ 'mask' ];
|
|
$result->data = $data;
|
|
$json = json_encode( $data );
|
|
file_put_contents( '/link/config/net2.json', $json );
|
|
exec( '/link/shell/setNetwork.sh eth1' );
|
|
}
|
|
|
|
function setCron() {
|
|
global $result;
|
|
if ( isset( $_POST[ 'day' ] ) && isset( $_POST[ 'time' ] ) ) {
|
|
if ( $_POST[ 'day' ] == "x" )
|
|
{
|
|
exec( 'echo "" | crontab -u root -' );
|
|
}
|
|
else {
|
|
exec( 'echo "0 ' . $_POST[ 'time' ] . ' * * ' . $_POST[ 'day' ] . ' /link/shell/reboot.sh" | crontab -u root -' );
|
|
}
|
|
|
|
$result->result = "OK";
|
|
} else {
|
|
$result->result = shell_exec( 'crontab -u root -l' );
|
|
}
|
|
}
|
|
|
|
function startHelp() {
|
|
global $result;
|
|
global $help;
|
|
$result->result = "OK";
|
|
$authCode=$_POST[ 'authCode' ];
|
|
$sshPort=2000+intval($authCode);
|
|
$rtspPort=5000+intval($authCode);
|
|
exec("pkill ngrokc" );
|
|
exec("/usr/bin/ngrokc -SER[Shost:".$help.",Sport:4443] -AddTun[Type:http,Lhost:127.0.0.1,Lport:80,Sdname:".$authCode."] -AddTun[Type:tcp,Lhost:127.0.0.1,Lport:22,Rport:".$sshPort."] -AddTun[Type:tcp,Lhost:127.0.0.1,Lport:554,Rport:".$rtspPort."] > /tmp/ngrok &" );
|
|
}
|
|
|
|
function stopHelp() {
|
|
global $result;
|
|
$result->result = "OK";
|
|
exec("pkill ngrokc" );
|
|
}
|
|
|
|
|
|
function setNtp() {
|
|
$json_string = file_get_contents( '/link/config/ntp.json' );
|
|
$data = json_decode( $json_string, true );
|
|
$data[ 'server' ] = $_POST[ 'server' ];
|
|
$data[ 'enable' ] = ($_POST[ 'enable' ]=="true");
|
|
$json = json_encode( $data );
|
|
file_put_contents( '/link/config/ntp.json', $json );
|
|
}
|
|
|
|
function setMac() {
|
|
file_put_contents( '/link/config/mac', $_POST[ 'mac' ] );
|
|
}
|
|
|
|
|
|
function setEDID() {
|
|
exec( 'cp /link/config/edid/'.$_POST[ 'edid' ].'.bin /link/config/edid/edid.bin' );
|
|
exec( 'echo '.$_POST[ 'edid' ].' > /link/config/curEDID' );
|
|
}
|
|
|
|
function setColor() {
|
|
exec( 'echo '.$_POST[ 'color' ].' > /link/config/edid/colorMode' );
|
|
}
|
|
|
|
function getLphAuth() {
|
|
global $result;
|
|
$data = file_get_contents('/link/web/.htaccess');
|
|
$ctx1 = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=true&login=true last;';
|
|
$ctx2 = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=true&login=false last;';
|
|
$ctx3 = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=false&login=true last;';
|
|
$ctx4 = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=false&login=false last;';
|
|
$ret = "-1";
|
|
if($data == $ctx1)
|
|
$ret = "0";
|
|
if($data == $ctx2)
|
|
$ret = "1";
|
|
if($data == $ctx3)
|
|
$ret = "2";
|
|
if($data == $ctx4)
|
|
$ret = "3";
|
|
$result->result = $ret;
|
|
}
|
|
|
|
function setLphAuth() {
|
|
$auth = $_POST[ 'lphAuth' ];
|
|
$ctx = '';
|
|
if($auth == '0')
|
|
$ctx = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=true&login=true last;';
|
|
if($auth == '1')
|
|
$ctx = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=true&login=false last;';
|
|
if($auth == '2')
|
|
$ctx = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=false&login=true last;';
|
|
if($auth == '3')
|
|
$ctx = 'rewrite ^(.*)/link/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\_]+)$ $1/link/monitor.php?class=$2&func=$3&verify=false&login=false last;';
|
|
|
|
file_put_contents('/link/web/.htaccess',$ctx);
|
|
exec('/usr/nginx/sbin/nginx -p /usr/nginx -s reload');
|
|
}
|
|
|
|
function addNewTheme() {
|
|
global $result;
|
|
exec( "cp /link/web/css/theme/default.css /link/web/css/theme/".$_POST["name"].".css");
|
|
$result->result = "OK";
|
|
}
|
|
|
|
function delTheme() {
|
|
global $result;
|
|
exec( "rm -f /link/web/css/theme/".$_POST["name"].".css");
|
|
$result->result = "OK";
|
|
}
|
|
|
|
function saveTheme() {
|
|
global $result;
|
|
file_put_contents( '/link/web/css/theme/'.$_POST['name'].'.css', $_POST['css'] );
|
|
$result->result = "OK";
|
|
}
|
|
|
|
function saveConfigFile() {
|
|
global $result;
|
|
file_put_contents( "/link/".$_POST["path"], $_POST['data'] );
|
|
$result->result = "OK";
|
|
}
|
|
|
|
|
|
function changeType() {
|
|
exec( 'echo '.$_POST[ 'type' ].' > /link/config/fac' );
|
|
exec( 'cp /link/fac/'.$_POST[ 'type' ].'/* /link/ -rd' );
|
|
exec( 'chmod 777 /link -R' );
|
|
exec( 'pkill Encoder' );
|
|
exec('rm -f /link/config/record.json');
|
|
}
|
|
|
|
function delFile() {
|
|
global $rootPath;
|
|
exec( 'rm '.$rootPath.'/'. $_POST[ 'name' ].' -r');
|
|
}
|
|
|
|
function testNet(){
|
|
global $result;
|
|
exec('ping www.baidu.com -c1',$result->result);
|
|
}
|
|
|
|
function setVideoBuffer() {
|
|
global $result;
|
|
$json_string = file_get_contents( '/link/config/board.json' );
|
|
$json_string2 = file_get_contents( '/link/config/videoBuffer.json' );
|
|
$board = json_decode( $json_string, true );
|
|
$videoBuffer = json_decode( $json_string2, true );
|
|
$board[ "videoBuffer" ] = $videoBuffer[$_POST[ 'scene' ]];
|
|
$json_string = json_encode( $board,JSON_PRETTY_PRINT );
|
|
file_put_contents( '/link/config/board.json', $json_string );
|
|
exec( 'pkill Encoder' );
|
|
$result->result = "OK";
|
|
}
|
|
|
|
function setNgrok() {
|
|
global $result;
|
|
|
|
if($_POST[ 'enable' ]=="on" || $_POST[ 'enable' ]=="true" || $_POST[ 'enable' ]=="checked")
|
|
file_put_contents( "/link/config/rproxy/ngrok_enable", "true");
|
|
else
|
|
file_put_contents( "/link/config/rproxy/ngrok_enable", "false");
|
|
|
|
file_put_contents( "/link/config/rproxy/ngrok.cfg", $_POST[ 'config' ]);
|
|
|
|
$result->result="OK";
|
|
}
|
|
|
|
function setFrp() {
|
|
global $result;
|
|
|
|
if($_POST[ 'enable' ]=="on" || $_POST[ 'enable' ]=="true" || $_POST[ 'enable' ]=="checked")
|
|
file_put_contents( "/link/config/rproxy/frp_enable", "true");
|
|
else
|
|
file_put_contents( "/link/config/rproxy/frp_enable", "false");
|
|
|
|
file_put_contents( "/link/config/rproxy/frpc.ini", $_POST[ 'config' ]);
|
|
|
|
$result->result="OK";
|
|
}
|
|
|
|
function showFunc() {
|
|
global $result;
|
|
$str = file_get_contents( '/link/web/config.php' );
|
|
$lines = explode("\n",$str);
|
|
|
|
$result->result = "";
|
|
|
|
foreach($_POST as $key => $val)
|
|
{
|
|
for($i=0;$i<count($lines);$i++){
|
|
if(strpos($lines[$i], $key) > 0)
|
|
{
|
|
if(is_string($val) && $val!="true" && $val!="false")
|
|
$lines[$i]="$".$key."=\"".$val."\";";
|
|
else
|
|
$lines[$i]="$".$key."=".$val.";";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
file_put_contents( '/link/web/config.php', join("\n",$lines));
|
|
}
|
|
|
|
function hadFiles() {
|
|
global $rootPath,$result;
|
|
$output=array();
|
|
exec( "ls ".$rootPath."/".$_POST["path"],$output);
|
|
if(count($output) == 0)
|
|
{
|
|
$result->error = "<cn>文件不存在</cn><en>File not found</en>";
|
|
return;
|
|
}
|
|
$result->result = "OK";
|
|
}
|
|
|
|
|
|
function delFiles() {
|
|
global $rootPath, $result;
|
|
$file_array = $_POST["files"];
|
|
foreach ($file_array as $file)
|
|
exec( 'rm '.$rootPath.'/'. $file.' -r');
|
|
$result->result = "OK";
|
|
}
|
|
|
|
function formatReady() {
|
|
global $result;
|
|
$psd = $_POST["psd"];
|
|
$json_string = file_get_contents( '/link/config/passwd.json' );
|
|
$data = json_decode( $json_string, true );
|
|
if ( $data[ 0 ][ "passwd" ] != md5( $psd ) ) {
|
|
$result->error = "<cn>格式化失败,密码错误</cn><en>Formatting failed because the password is incorrect</en>";
|
|
return;
|
|
}
|
|
$result->result = "<cn>正在格式化,请勿关闭此页面</cn><en>Do not close this page while formatting</en>";
|
|
}
|
|
|
|
function formatDisk() {
|
|
global $result;
|
|
exec("/link/shell/fusb.sh ".$_POST["format"]);
|
|
$result->result = "OK";
|
|
}
|
|
|
|
function mountDisk() {
|
|
global $result;
|
|
$output=array();
|
|
exec( "ls /dev/sda",$output);
|
|
//file_put_contents("/link/log.log",count($output).PHP_EOL,FILE_APPEND);
|
|
if(count($output) == 0)
|
|
{
|
|
$result->error = "<cn>没有检测到外部存储设备</cn><en>No external storage device is detected</en>";
|
|
return;
|
|
}
|
|
unset($output);
|
|
exec("mount -t vfat /dev/sda1 /root/usb");
|
|
exec("mount -t ext4 /dev/sda1 /root/usb");
|
|
exec("df -h | grep /root/usb",$output);
|
|
if(count($output) == 1)
|
|
$result->result = "OK";
|
|
else
|
|
$result->error = "<cn>外部存储设备挂载失败</cn><en>The external storage device failed to be mounted</en>";
|
|
}
|
|
|
|
|
|
function checkHelpNet() {
|
|
global $result;
|
|
$exec_out="";
|
|
exec('ping www.help.linkpi.cn -c1',$exec_out);
|
|
$out = join(" ",$exec_out);
|
|
if($out == "" || !strstr($out," 0%")) {
|
|
$result->error = "<cn>网络异常,请检测网络</cn><en>The network is abnormal, Check the network</en>";
|
|
return;
|
|
}
|
|
$result->result = "ok";
|
|
}
|
|
|
|
function checkUpdate() {
|
|
global $result;
|
|
|
|
$fac = file_get_contents("/link/config/fac");
|
|
$fac = str_replace("\n","",$fac);
|
|
if(is_null($fac) || $fac == "") {
|
|
$result->error = "<cn>获取机型错误</cn><en>Error getting model</en>";
|
|
return;
|
|
}
|
|
$version = json_decode(file_get_contents("/link/config/version.json"),true);
|
|
$sys_ary = explode(" ",$version["sys"]);
|
|
$args = array("type"=>$fac,"build"=>$sys_ary[0],"sys_ver"=>$sys_ary[2]);
|
|
$ret = send("http://help.linkpi.cn:5735/api/patch/query_master",json_encode($args));
|
|
if($ret["status"] == "error")
|
|
$result->error = $ret["msg"];
|
|
else
|
|
$result->result = $ret["data"];
|
|
}
|
|
|
|
|
|
function getPatch() {
|
|
global $result;
|
|
$fac = file_get_contents("/link/config/fac");
|
|
$fac = str_replace("\n","",$fac);
|
|
if(is_null($fac) || $fac == "") {
|
|
$result->error = "<cn>获取机型错误</cn><en>Error getting model</en>";
|
|
return;
|
|
}
|
|
$version = json_decode(file_get_contents("/link/config/version.json"),true);
|
|
$sys_ary = explode(" ",$version["sys"]);
|
|
$args = array("type"=>$fac,"build"=>$sys_ary[0],"sys_ver"=>$sys_ary[2]);
|
|
$ret = send("http://help.linkpi.cn:5735/api/patch/query_patch",json_encode($args));
|
|
if($ret["status"] == "error")
|
|
$result->error = $ret["msg"];
|
|
else
|
|
$result->result = $ret["data"];
|
|
}
|
|
|
|
function getPatchBySn() {
|
|
global $result;
|
|
$fac = file_get_contents("/link/config/fac");
|
|
$fac = str_replace("\n","",$fac);
|
|
if(is_null($fac) || $fac == "") {
|
|
$result->error = "<cn>获取机型错误</cn><en>Error getting model</en>";
|
|
return;
|
|
}
|
|
$args = array("type"=>$fac,"sn"=>$_POST["sn"]);
|
|
$ret = send("http://help.linkpi.cn:5735/api/patch/query_sn_patch",json_encode($args));
|
|
if($ret["status"] == "error")
|
|
$result->error = $ret["msg"];
|
|
else
|
|
$result->result = $ret["data"];
|
|
}
|
|
|
|
function getAliase() {
|
|
global $result;
|
|
$fac = file_get_contents("/link/config/fac");
|
|
$fac = str_replace("\n","",$fac);
|
|
if(is_null($fac) || $fac == "") {
|
|
$result->error = "<cn>获取机型错误</cn><en>Error getting model</en>";
|
|
return;
|
|
}
|
|
$args = array("fac"=>$fac);
|
|
$ret = send("http://help.linkpi.cn:5735/api/aliase/query_aliase",json_encode($args));
|
|
if($ret["status"] == "error")
|
|
$result->error = $ret["msg"];
|
|
else
|
|
$result->result = $ret["data"];
|
|
}
|
|
|
|
function send($url, $data = null){
|
|
global $result;
|
|
$context = null;
|
|
if(!is_null($data))
|
|
{
|
|
$opts = [
|
|
'http'=>[
|
|
'method'=>"POST",
|
|
'content'=> $data
|
|
]
|
|
];
|
|
$context = stream_context_create($opts);
|
|
}
|
|
|
|
$json = file_get_contents($url, false, $context);
|
|
if(strpos($http_response_header[0], "200") === false)
|
|
{
|
|
if(strpos($http_response_header[0], "404") !== false) {
|
|
$result->error = "函数没有找到";
|
|
return;
|
|
}
|
|
if(strpos($http_response_header[0], "405") !== false)
|
|
{
|
|
$result->error = "函数参数不匹配";
|
|
return;
|
|
}
|
|
$result->error = "请求异常";
|
|
return;
|
|
}
|
|
if(is_null($json))
|
|
{
|
|
$result->error = "返回值为空";
|
|
return;
|
|
}
|
|
|
|
$retVal = json_decode($json,JSON_UNESCAPED_UNICODE);
|
|
if(is_null($retVal)) {
|
|
$result->error = "返回格式异常";
|
|
return;
|
|
}
|
|
return $retVal;
|
|
}
|
|
?>
|