From b49f4bf9493bd3718eaacb3d6c9d604294ff8780 Mon Sep 17 00:00:00 2001 From: HITSword Date: Fri, 17 Jan 2020 18:44:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HITSword --- AMHScript | 5 ++++- cli.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/AMHScript b/AMHScript index dbd3db2..9c1ba7e 100644 --- a/AMHScript +++ b/AMHScript @@ -73,7 +73,10 @@ function amh_module_admin() amh nginx reload; ;; edit) - echo "edit something"; + ParamName=$3 + ParamVal=$4 + php ${module_dir}cli.php --action='edit' --server_name=${domain} --field_name=${ParamName} --value=${ParamVal}; + amh nginx reload; ;; del) echo "del something"; diff --git a/cli.php b/cli.php index 0d4d4d8..37ceff1 100644 --- a/cli.php +++ b/cli.php @@ -49,7 +49,7 @@ echo amproxy_add($param['server_name'], $param['proxy_pass']); break; case 'edit': - //echo amproxy_edit($param['server_name'], $param['field_name'], $param['value']); + echo amproxy_edit($param['server_name'], $param['field_name'], $param['value']); break; case 'del': //echo amproxy_del($param['server_name']); @@ -128,4 +128,54 @@ } } return $res; + } + + /** + * 修改反向代理参数 + * @param $server_name + * @param string $field_name + * @param string $value + * @return string + */ + function hyproxy_edit($server_name, $field_name = '', $value = '') + { + if (empty($server_name)) { + return "[ERROR] The server_name is empty.\n";//不能为空 + } + if (empty($field_name)) { + return "[ERROR] The field_name is empty.\n";//不能为空 + } + $value = trim($value); + $res = ''; + global $medoo; + $table = 'module_hyproxy'; + $columns = '*'; + $where = array('server_name'=>trim($server_name)); + $proxy = $medoo->get($table, $columns, $where); + + if (empty($proxy)) { + return "[Error] $server_name AMProxy not exist!\n";//不存在 + } else { + if ($field_name=='proxy_pass') { + empty($value) && $value = 'http://'.$server_name; + if (!preg_match('/^http(s)?:\\/\\/.+/', $value)) { + $value = 'http://'.$value; + } + } + if ($field_name=='header_host') { + empty($value) && $value = '$host'; + } + $data = array( + $field_name => $value, + 'time' => time() + ); + $mysqlres = $medoo->update($table, $data, array('hyproxy_id'=>$proxy['hyproxy_id'])); + if ($mysqlres) { + $res = "[OK] $field_name parameters set success.\n"; + shell_exec("php "._HYPROXY."hyproxy-cli.php --action='make' --server_name=$server_name"); + } else { + $res = "[ERROR] $field_name parameters set error.\n"; + } + } + return $res; } \ No newline at end of file