parent
f81df14fde
commit
e4877e246d
|
|
@ -69,6 +69,9 @@
|
||||||
case 'restore':
|
case 'restore':
|
||||||
echo hyproxy_restore($param['bak_name']);
|
echo hyproxy_restore($param['bak_name']);
|
||||||
break;
|
break;
|
||||||
|
case 'amproxy_bak' :
|
||||||
|
echo hyproxy_amproxy_bak();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
echo 'error action';
|
echo 'error action';
|
||||||
}
|
}
|
||||||
|
|
@ -359,6 +362,55 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备份AMProxy的反向代理
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function hyproxy_amproxy_bak()
|
||||||
|
{
|
||||||
|
$dir = '/usr/local/nginx/conf/proxy/';
|
||||||
|
if (is_dir($dir)) {
|
||||||
|
$list = scandir($dir);
|
||||||
|
foreach ($list as $row) {
|
||||||
|
unset($conf, $data);
|
||||||
|
//排除目录中的.和..
|
||||||
|
if ($row != "." && $row != ".." && is_file($dir.$row)) {
|
||||||
|
$conf = file_get_contents($dir.$row);
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'server_name' => trim(hy_get_body($conf, 'server_name', ';', 1)),
|
||||||
|
'index' => 'index.php index.html index.htm',//index是保留字段
|
||||||
|
'header_host' => '$host',
|
||||||
|
'proxy_pass' => trim(hy_get_body($conf, 'proxy_pass', ';', 1)),
|
||||||
|
'proxy_cache' => 1,
|
||||||
|
'status' => 'start',
|
||||||
|
'time' => time()
|
||||||
|
);
|
||||||
|
if (trim(hy_get_body($conf, 'proxy_set_header Host ', ';', 1)) != $data['server_name']) {
|
||||||
|
$data['header_host'] = trim(hy_get_body($conf, 'proxy_set_header Host ', ';', 1));
|
||||||
|
}
|
||||||
|
$proxy[] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($proxy)) {
|
||||||
|
if (!is_dir(_HYBAKS)) {
|
||||||
|
mkdir(_HYBAKS, 0755);
|
||||||
|
}
|
||||||
|
$filebytes = false;
|
||||||
|
$filename = _HYBAKS . 'AMProxy' .date("Y-m-d-H:i:s") . '.bak';
|
||||||
|
$filebytes = file_put_contents($filename, json_encode($proxy));//写入内容
|
||||||
|
if ($filebytes) {
|
||||||
|
$res="[OK] AMProxy proxy backup success.\n";
|
||||||
|
} else {
|
||||||
|
$res="[ERROR] AMProxy proxy backup error.\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$res = '[ERROR] No AMProxy.';
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除目录和子目录
|
* 删除目录和子目录
|
||||||
* @param $path
|
* @param $path
|
||||||
|
|
@ -426,3 +478,33 @@
|
||||||
}
|
}
|
||||||
return $conf;
|
return $conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输入始末关键词提取主要内容
|
||||||
|
* @param $str string 提取前内容
|
||||||
|
* @param $start string 开始关键词
|
||||||
|
* @param $end string 结束关键词
|
||||||
|
* @param $option int 选项 1:不包含前后关键词 2:包含前关键词 3:包含后关键词 其他(默认):包含前后关键词
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function hy_get_body($str, $start, $end, $option)
|
||||||
|
{
|
||||||
|
$str_array=explode($start, $str);
|
||||||
|
$tem=$str_array[1];
|
||||||
|
if (empty($end)) {
|
||||||
|
return $tem;
|
||||||
|
} else {
|
||||||
|
$str_array=explode($end, $tem);
|
||||||
|
if ($option==1) {
|
||||||
|
return $str_array[0];
|
||||||
|
}
|
||||||
|
if ($option==2) {
|
||||||
|
return $start.$str_array[0];
|
||||||
|
}
|
||||||
|
if ($option==3) {
|
||||||
|
return $str_array[0].$end;
|
||||||
|
} else {
|
||||||
|
return $start.$str_array[0].$end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue