添加反向代理

Signed-off-by: HITSword <admin@huayizhiyun.com>
This commit is contained in:
HITSword
2020-01-17 18:18:04 +08:00
parent d8e7f8d5d7
commit 635d3f23e6
2 changed files with 50 additions and 2 deletions
+47 -1
View File
@@ -46,7 +46,7 @@
echo amproxy_list($param['proxy_status']);
break;
case 'add':
//echo amproxy_add($param['server_name'], $param['proxy_pass']);
echo amproxy_add($param['server_name'], $param['proxy_pass']);
break;
case 'edit':
//echo amproxy_edit($param['server_name'], $param['field_name'], $param['value']);
@@ -82,4 +82,50 @@
$res.=sprintf("%s %s\n", $row['server_name'], $status);
}
return $res;
}
/**
* 新建反向代理
* @param $server_name
* @param string $proxy_pass
* @return string
*/
function amproxy_add($server_name, $proxy_pass = '')
{
if (empty($server_name)) {
return "[ERROR] The server_name is empty.\n";//不能为空
}
$res = '';
global $medoo;
$table = 'module_hyproxy';
$columns = '*';
$where = array('server_name'=>trim($server_name));
$proxy = $medoo->get($table, $columns, $where);
if ($proxy) {
return "[Error] $server_name AMProxy is exist!\n";//已存在
} else {
empty($proxy_pass) && $proxy_pass = 'http://'.$server_name;
if (!preg_match('/^http(s)?:\\/\\/.+/', $proxy_pass)) {
$proxy_pass = 'http://'.$proxy_pass;
}
$data = array(
'server_name' => $server_name,
'`index`' => 'index.php index.html index.htm',//index是保留字段
'header_host' => '$host',
'proxy_pass' => $proxy_pass,
'proxy_cache' => 1,
'status' => 'start',
'time' => time()
);
$mysqlres = $medoo->insert($table, $data);
if ($mysqlres) {
$res = "[OK] successfully create $server_name AMProxy.\n";
shell_exec("php "._HYPROXY."hyproxy-cli.php --action='make' --server_name=$server_name");
} else {
$res = "[ERROR] error create $server_name AMProxy.\n";
}
}
return $res;
}