From 5a3b977f1b93d59593aee7d5d846f9c48b8992f1 Mon Sep 17 00:00:00 2001 From: HITSword Date: Thu, 9 Jan 2020 17:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HITSword --- Controller/hyproxy.php | 358 +++++++++++++------------ Model/hyproxys.php | 496 ++++++++++++++++++----------------- View/hyproxy_cache.php | 184 ++++++------- View/hyproxy_cache_del.php | 316 +++++++++++----------- View/hyproxy_cache_index.php | 325 ++++++++++++----------- View/hyproxy_category.php | 62 ++--- View/hyproxy_list.php | 36 ++- 7 files changed, 892 insertions(+), 885 deletions(-) diff --git a/Controller/hyproxy.php b/Controller/hyproxy.php index 5d6d5d6..df2046d 100644 --- a/Controller/hyproxy.php +++ b/Controller/hyproxy.php @@ -1,209 +1,203 @@ indexs) return; - $this -> _class('Functions'); - $this -> indexs = $this -> _model('indexs'); - $this -> hyproxys = $this -> _model('hyproxys'); - } + function AmysqlModelBase() + { + if ($this -> indexs) { + return; + } + $this -> _class('Functions'); + $this -> indexs = $this -> _model('indexs'); + $this -> hyproxys = $this -> _model('hyproxys'); + } - function IndexAction(){ - $this -> hyproxy_list(); - } + function IndexAction() + { + $this -> hyproxy_list(); + } // 反代列表 - function hyproxy_list(){ - $this -> title = '反代列表 - HYProxy'; // 面板模块标题 - $this -> AmysqlModelBase(); - Functions::CheckLogin(); // 面板登录检查函数 + function hyproxy_list() + { + $this -> title = '反代列表 - HYProxy'; // 面板模块标题 + $this -> AmysqlModelBase(); + Functions::CheckLogin(); // 面板登录检查函数 - $this -> status = 'error'; - // 状态 - if (isset($_GET['run'])) { - $run_name = $_GET['run']; - $run_zh = array( - 'start' => '启动', - 'stop' => '停止' - ); - if ( !empty($run_name) && isset($run_zh[$_GET['g']]) ) { - $g = $_GET['g']; - $result = $this->hyproxys->hyproxy_run($run_name, $g); - $this->status = $result['status']; - $this->notice = $result['notice']; - } - } - // 缓存状态 - if (isset($_GET['run_cache'])) { - $run_name = $_GET['run_cache']; - $run_zh = array( - '1' => '启动', - '0' => '停止' - ); - if (!empty($run_name) && isset($run_zh[$_GET['g']])) { - $g = $_GET['g']; - $result = $this->hyproxys->hyproxy_run_cache($run_name, $g); - $this->status = $result['status']; - $this->notice = $result['notice']; - } - } - // 删除 - if (isset($_GET['del'])) { - $del_name = $_GET['del']; - if (!empty($del_name)) { - $result = $this->hyproxys->hyproxy_del($del_name); - $this->status = $result['status']; - $this->notice = $result['notice']; - } - } - // 管理 - if (isset($_GET['admin'])) { - if (isset($_POST['edit'])) { - $result = $this->hyproxys->hyproxy_edit(); - $this->status = $result['status']; - $this->notice = $result['notice']; - } - $name = $_GET['admin']; - $this->hyproxy_get = $this->hyproxys->hyproxy_get($name); - } + $this -> status = 'error'; + // 状态 + if (isset($_GET['run'])) { + $run_name = $_GET['run']; + $run_zh = array( + 'start' => '启动', + 'stop' => '停止' + ); + if (!empty($run_name) && isset($run_zh[$_GET['g']])) { + $g = $_GET['g']; + $result = $this->hyproxys->hyproxy_run($run_name, $g); + $this->status = $result['status']; + $this->notice = $result['notice']; + } + } + // 缓存状态 + if (isset($_GET['run_cache'])) { + $run_name = $_GET['run_cache']; + $run_zh = array( + '1' => '启动', + '0' => '停止' + ); + if (!empty($run_name) && isset($run_zh[$_GET['g']])) { + $g = $_GET['g']; + $result = $this->hyproxys->hyproxy_run_cache($run_name, $g); + $this->status = $result['status']; + $this->notice = $result['notice']; + } + } + // 删除 + if (isset($_GET['del'])) { + $del_name = $_GET['del']; + if (!empty($del_name)) { + $result = $this->hyproxys->hyproxy_del($del_name); + $this->status = $result['status']; + $this->notice = $result['notice']; + } + } + // 管理 + if (isset($_GET['admin'])) { + if (isset($_POST['edit'])) { + $result = $this->hyproxys->hyproxy_edit(); + $this->status = $result['status']; + $this->notice = $result['notice']; + } + $name = $_GET['admin']; + $this->hyproxy_get = $this->hyproxys->hyproxy_get($name); + } - // 新增 - if (isset($_POST['submit'])) { - $server_name = $_POST['server_name']; - $proxy_pass = $_POST['proxy_pass']; - if (!empty($server_name) && !empty($proxy_pass)) { - $result = $this->hyproxys->hyproxy_add($server_name, $proxy_pass); - $this->status = $result['status']; - $this->notice = $result['notice']; - } else { - $this->notice = '请填写完整数据。'; - } - } + // 新增 + if (isset($_POST['submit'])) { + $server_name = $_POST['server_name']; + $proxy_pass = $_POST['proxy_pass']; + if (!empty($server_name) && !empty($proxy_pass)) { + $result = $this->hyproxys->hyproxy_add($server_name, $proxy_pass); + $this->status = $result['status']; + $this->notice = $result['notice']; + } else { + $this->notice = '请填写完整数据。'; + } + } - $this -> indexs -> log_insert($this -> notice); - $this -> hyproxy_list = $this -> hyproxys -> hyproxy_list(); - $this -> _view('hyproxy_list'); - } + $this -> indexs -> log_insert($this -> notice); + $this -> hyproxy_list = $this -> hyproxys -> hyproxy_list(); + $this -> _view('hyproxy_list'); + } // ********************************************************* // 缓存设置 - function hyproxy_cache(){ - $this -> title = '缓存设置 - HYProxy - AMH'; - $this -> AmysqlModelBase(); - Functions::CheckLogin(); - - // 保存 - if (isset($_POST['save'])) + function hyproxy_cache() { - $this -> status = 'error'; - $field = array('levels', 'keys_zone', 'max_size', 'valid', 'inactive'); - foreach ($field as $key=>$val) - { - if (!isset($_POST[$val]) || empty($_POST[$val])) - { - $error = true; - break; - } - } - if (isset($error)) - $this -> notice = '请填写完整数据。'; - else - { - if ($this -> hyproxys -> save_hyproxy_cache()) - { - $this -> status = 'success'; - $this -> notice = 'HYProxy 缓存设置成功。'; - } - else - $this -> notice = 'HYProxy 缓存设置失败。'; - } + $this -> title = '缓存设置 - HYProxy - AMH'; + $this -> AmysqlModelBase(); + Functions::CheckLogin(); + // 保存 + if (isset($_POST['save'])) { + $this -> status = 'error'; + $field = array('levels', 'keys_zone', 'max_size', 'valid', 'inactive'); + foreach ($field as $key => $val) { + if (!isset($_POST[$val]) || empty($_POST[$val])) { + $error = true; + break; + } + } + if (isset($error)) { + $this -> notice = '请填写完整数据。'; + } else { + if ($this -> hyproxys -> save_hyproxy_cache()) { + $this -> status = 'success'; + $this -> notice = 'HYProxy 缓存设置成功。'; + } else { + $this -> notice = 'HYProxy 缓存设置失败。'; + } + } + } + + $this -> indexs -> log_insert($this -> notice); + $this -> hyproxy_cache = $this -> hyproxys -> get_hyproxy_cache(); + $this -> _view('hyproxy_cache'); } - $this -> indexs -> log_insert($this -> notice); - $this -> hyproxy_cache = $this -> hyproxys -> get_hyproxy_cache(); - $this -> _view('hyproxy_cache'); - } - // ********************************************************* // 缓存索引 - function hyproxy_cache_index(){ - $this -> title = '缓存索引 - HYProxy - AMH'; - $this -> AmysqlModelBase(); - Functions::CheckLogin(); - - if (isset($_POST['post_submit'])) + function hyproxy_cache_index() { - if ($this -> hyproxys -> create_hyproxy_cache_index()) - { - $this -> status = 'success'; - $this -> notice = 'HYProxy 创建缓存索引成功。'; - } - else - { - $this -> status = 'error'; - $this -> notice = 'HYProxy 创建缓存索引失败。'; - } - } + $this -> title = '缓存索引 - HYProxy - AMH'; + $this -> AmysqlModelBase(); + Functions::CheckLogin(); - $this -> indexs -> log_insert($this -> notice); - $this -> hyproxy_cache_index = $this -> hyproxys -> get_hyproxy_cache_index(); - $this -> _view('hyproxy_cache_index'); - } + if (isset($_POST['post_submit'])) { + if ($this -> hyproxys -> create_hyproxy_cache_index()) { + $this -> status = 'success'; + $this -> notice = 'HYProxy 创建缓存索引成功。'; + } else { + $this -> status = 'error'; + $this -> notice = 'HYProxy 创建缓存索引失败。'; + } + } + + $this -> indexs -> log_insert($this -> notice); + $this -> hyproxy_cache_index = $this -> hyproxys -> get_hyproxy_cache_index(); + $this -> _view('hyproxy_cache_index'); + } // ********************************************************* // 缓存删除 - function hyproxy_cache_del(){ - $this -> title = '缓存删除 - HYProxy - AMH'; - $this -> AmysqlModelBase(); - Functions::CheckLogin(); - - // 删除缓存 - if (isset($_POST['post_delete'])) + function hyproxy_cache_del() { - if ($this -> hyproxys -> hyproxy_cache_delete()) - { - $this -> status = 'success'; - $this -> notice = 'HYProxy 缓存删除成功。'; - } - else - { - $this -> status = 'error'; - $this -> notice = 'HYProxy 缓存删除失败。'; - } + $this -> title = '缓存删除 - HYProxy - AMH'; + $this -> AmysqlModelBase(); + Functions::CheckLogin(); + + // 删除缓存 + if (isset($_POST['post_delete'])) { + if ($this -> hyproxys -> hyproxy_cache_delete()) { + $this -> status = 'success'; + $this -> notice = 'HYProxy 缓存删除成功。'; + } else { + $this -> status = 'error'; + $this -> notice = 'HYProxy 缓存删除失败。'; + } + } + + // 取得域名列表与缓存文件类型 + $hyproxy_cache_index = $this -> hyproxys -> get_hyproxy_cache_index(); + foreach ($hyproxy_cache_index as $key => $val) { + $cache_host[] = $key; + foreach ($val as $k => $v) { + $cache_type[$k] = $k; + } + } + + // 缓存列表 + $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; + $page_sum = 20; + $hyproxy_cache_list = $this -> hyproxys -> get_hyproxy_cache_list($page, $page_sum); + $total_page = ceil($hyproxy_cache_list['sum'] / $page_sum); + $page_list = Functions::page('AccountLog', $hyproxy_cache_list['sum'], $total_page, $page); // 分页列表 + $this -> page = $page; + $this -> total_page = $total_page; + $this -> page_list = $page_list; + $this -> hyproxy_cache_list = $hyproxy_cache_list; + + $this -> cache_host = $cache_host; + $this -> cache_type = $cache_type; + + $this -> indexs -> log_insert($this -> notice); + $this -> _view('hyproxy_cache_del'); } - - // 取得域名列表与缓存文件类型 - $hyproxy_cache_index = $this -> hyproxys -> get_hyproxy_cache_index(); - foreach ($hyproxy_cache_index as $key=>$val) - { - $cache_host[] = $key; - foreach ($val as $k=>$v) - $cache_type[$k] = $k; - } - - // 缓存列表 - $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; - $page_sum = 20; - $hyproxy_cache_list = $this -> hyproxys -> get_hyproxy_cache_list($page, $page_sum); - $total_page = ceil($hyproxy_cache_list['sum'] / $page_sum); - $page_list = Functions::page('AccountLog', $hyproxy_cache_list['sum'], $total_page, $page); // 分页列表 - $this -> page = $page; - $this -> total_page = $total_page; - $this -> page_list = $page_list; - $this -> hyproxy_cache_list = $hyproxy_cache_list; - - $this -> cache_host = $cache_host; - $this -> cache_type = $cache_type; - - $this -> indexs -> log_insert($this -> notice); - $this -> _view('hyproxy_cache_del'); - } - -} \ No newline at end of file +} diff --git a/Model/hyproxys.php b/Model/hyproxys.php index c3c02b4..c40f979 100644 --- a/Model/hyproxys.php +++ b/Model/hyproxys.php @@ -1,238 +1,258 @@ - _all($sql); - } - // 取得反代网站 - function hyproxy_get($name){//OK - $sql = "SELECT * FROM module_hyproxy WHERE `server_name` = '$name'"; - return $this -> _row($sql); - } - // 增加反代网站 - function hyproxy_add($server_name, $proxy_pass){//OK - $server_name = trim($server_name); - $proxy_pass = trim($proxy_pass); - $proxy = $this->hyproxy_get($server_name); - if ($proxy) { - return array( 'status' => 'error' , 'notice' => '绑定域名已存在,请删除旧记录或更换域名。' ); - } 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', - 'header_host' => '$host', - 'proxy_pass' => $proxy_pass, - 'proxy_cache' => 1, - 'status' => 'start', - 'time' => time() - ); - $res = $this -> _insert('module_hyproxy', $data); - if ($res) { - $cmd = "amh module HYProxy-1.0 admin make,$server_name"; - $cmd = Functions::trim_cmd($cmd); - shell_exec($cmd); - return array( 'status' => 'success' , 'notice' => $server_name.' : HYProxy域名增加成功。' ); - }else { - return array( 'status' => 'error' , 'notice' => $server_name.' : HYProxy域名增加失败。' ); - } - } - } - // 编辑反代网站 - function hyproxy_edit(){//OK - $server_name = trim($_POST['server_name']); - if ($_POST['index']!=$_POST['index_hidden']) {//默认首页 - $data['index'] = empty($_POST['index']) ? 'index.php index.html index.htm' : trim($_POST['index']); - } - if ($_POST['header_host']!=$_POST['header_host_hidden']) {//Host头 - $data['header_host'] = empty($_POST['header_host']) ? '$host' : trim($_POST['header_host']); - } - if ($_POST['proxy_pass']!=$_POST['proxy_pass_hidden']) {//后端地址 - $data['proxy_pass'] = trim($_POST['proxy_pass']); - empty($data['proxy_pass']) && $data['proxy_pass'] = 'http://'.$server_name; - if(!preg_match('/^http(s)?:\\/\\/.+/',$data['proxy_pass'])){ - $data['proxy_pass'] = 'http://'.$data['proxy_pass']; - } - } - $data['time'] = time();//时间戳 - $where = sprintf("WHERE `server_name` = '%s'",$server_name);//查询条件 - $res = $this -> _update('module_hyproxy',$data,$where); - - if ($res) { - $cmd = "amh module HYProxy-1.0 admin make,$server_name"; - $cmd = Functions::trim_cmd($cmd); - shell_exec($cmd); - return array( 'status' => 'success' , 'notice' => $server_name.' : HYProxy域名修改成功。' ); - }else { - return array( 'status' => 'error' , 'notice' => $server_name.' : HYProxy域名修改失败。' ); - } - } - // 删除反代网站 - function hyproxy_del($del_name){//OK - $del_name = trim($del_name); - $cmd = "amh module HYProxy-1.0 admin del,$del_name"; - $cmd = Functions::trim_cmd($cmd); - $result = $this->hyclear_result(shell_exec($cmd)); - if (strpos($result, '[ERROR]') === false){ - return array( 'status' => 'success' , 'notice' => $del_name.' : HYProxy域名删除成功。' ); - }else{ - return array( 'status' => 'error' , 'notice' => $del_name.' : HYProxy域名删除失败。' ); - } - } - // 状态 - function hyproxy_run($run_name, $g){//OK - $run_zh = array( - 'start' => '启动', - 'stop' => '停止' - ); - $data['status'] = $g; - $data['time'] = time();//时间戳 - $where = sprintf("WHERE `server_name` = '%s'",$run_name);//查询条件 - $res = $this -> _update('module_hyproxy',$data,$where); - - if ($res) { - $cmd = "amh module HYProxy-1.0 admin make,$run_name"; - $cmd = Functions::trim_cmd($cmd); - shell_exec($cmd); - return array( 'status' => 'success' , 'notice' => $run_name . ' : HYProxy域名' . $run_zh[$g] . '成功。' ); - }else { - return array( 'status' => 'error' , 'notice' => $run_name . ' : HYProxy域名' . $run_zh[$g] . '失败。' ); - } - } - // 缓存状态 - function hyproxy_run_cache($run_name, $g){//OK - $run_zh = array( - '1' => '启动', - '0' => '停止' - ); - $data['proxy_cache'] = $g; - $data['time'] = time();//时间戳 - $where = sprintf("WHERE `server_name` = '%s'",$run_name);//查询条件 - $res = $this -> _update('module_hyproxy',$data,$where); - - if ($res) { - $cmd = "amh module HYProxy-1.0 admin make,$run_name"; - $cmd = Functions::trim_cmd($cmd); - shell_exec($cmd); - return array( 'status' => 'success' , 'notice' => $run_name . ' : HYProxy域名缓存' . $run_zh[$g] . '成功。' ); - }else { - return array( 'status' => 'error' , 'notice' => $run_name . ' : HYProxy域名缓存' . $run_zh[$g] . '失败。' ); - } - } - - // ********************************************************* - // 取得缓存 - function get_hyproxy_cache(){ - $name = trim($name); - $cmd = "amh cat_nginx"; - $cmd = Functions::trim_cmd($cmd); - $result = trim(shell_exec($cmd), "\n"); - $result = Functions::trim_result($result); - preg_match("/hyproxy_cache levels=(.*)keys_zone=hyproxy:(.*)inactive=(.*)max_size=(.*);/", $result, $arr); - preg_match("/proxy_cache_valid 200 304(.*);/", $result, $arr2); - $data['levels'] = $arr[1]; - $data['keys_zone'] = $arr[2]; - $data['inactive'] = $arr[3]; - $data['max_size'] = $arr[4]; - $data['valid'] = $arr2[1]; - foreach ($data as $key=>$val) - $data[$key] = trim($val); - return $data; - } - - // 保存缓存 - function save_hyproxy_cache(){ - $run_name = trim($run_name); - $cmd = "amh module HYProxy-1.0 admin cache,{$_POST['levels']},{$_POST['keys_zone']},{$_POST['max_size']},{$_POST['valid']},{$_POST['inactive']}"; - $cmd = Functions::trim_cmd($cmd); - exec($cmd, $tmp, $status); - Return !$status; - } - - - // ********************************************************* - // 取得缓存索引 - function get_hyproxy_cache_index(){ - // $sql = "SELECT count(*) FROM module_hyproxy GROUP BY hyproxy_type "; - $sql = "SELECT * FROM module_hyproxy_cache"; - $result = $this -> _query($sql); - while ($rs = mysql_fetch_assoc($result)) - { - $url_info = parse_url($rs['hyproxy_key']); - if (isset($url_info['host']) && !empty($url_info['host'])) - { - ++$data[$url_info['host']]['all']['sum']; - $data[$url_info['host']]['all']['size'] += $rs['hyproxy_size']; - - ++$data[$url_info['host']][$rs['hyproxy_type']]['sum']; - $data[$url_info['host']][$rs['hyproxy_type']]['size'] += $rs['hyproxy_size']; - } - } - Return $data; - } - - // 创建缓存索引 - function create_hyproxy_cache_index(){ - $val = (int)$_POST['cache_index_time_val']; - $type = array('1' => 60*24, '2' => 60, '3' => 1); - $area = array('1' => '-', '2' => '+'); - $val = isset($type[$_POST['cache_index_time_type']]) ? $val * $type[$_POST['cache_index_time_type']] : $val * $type[1]; // 时间类型 - $val = isset($area[$_POST['cache_index_time_type']]) ? $area[$_POST['cache_index_time_area']] . $val : '-' . $val; // 时间范围 - $mode = $_POST['cache_index_time_mode'] == '2' ? 'truncate' : ''; - - $cmd = "amh module HYProxy-1.0 admin cache-index,$val,$mode"; - $cmd = Functions::trim_cmd($cmd); - exec($cmd, $tmp, $status); - Return !$status; - } - - // ********************************************************* - // 取得缓存列表 - function get_hyproxy_cache_list($page = 1, $page_sum = 20){ - $where = ''; - - if (isset($_GET['cache_key']) && !empty($_GET['cache_key'])) - { - $_GET['cache_key'] = trim($_GET['cache_key']); - $where .= " AND hyproxy_key LIKE '{$_GET['cache_key']}'"; - } - - if (isset($_GET['cache_type']) && $_GET['cache_type'] != 'all') - $where .= " AND hyproxy_type LIKE '{$_GET['cache_type']}'"; - - $limit = ' LIMIT ' . ($page-1)*$page_sum . ' , ' . $page_sum; - $sql = "SELECT * FROM module_hyproxy_cache WHERE 1 $where"; - $sum = $this -> _sum($sql); - - $sql = "SELECT * FROM module_hyproxy_cache WHERE 1 $where $limit"; - Return array('data' => $this -> _all($sql), 'sum' => $sum); - } - - // 删除缓存 - function hyproxy_cache_delete() - { - $url_param = (isset($_POST['cache_key']) && !empty($_POST['cache_key'])) ? $_POST['cache_key'] : '-all'; - $file_type = (isset($_POST['cache_type']) && !empty($_POST['cache_type']) && $_POST['cache_type'] != 'all') ? $_POST['cache_type'] : '-all'; - $cmd = "amh module HYProxy-1.0 admin cache-delete,$url_param,$file_type"; - $cmd = Functions::trim_cmd($cmd); - exec($cmd, $tmp, $status); - Return !$status; - } -} \ No newline at end of file + _all($sql); + } + // 取得反代网站 + function hyproxy_get($name) + { +//OK + $sql = "SELECT * FROM module_hyproxy WHERE `server_name` = '$name'"; + return $this -> _row($sql); + } + // 增加反代网站 + function hyproxy_add($server_name, $proxy_pass) + { +//OK + $server_name = trim($server_name); + $proxy_pass = trim($proxy_pass); + $proxy = $this->hyproxy_get($server_name); + if ($proxy) { + return array( 'status' => 'error' , 'notice' => '绑定域名已存在,请删除旧记录或更换域名。' ); + } 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', + 'header_host' => '$host', + 'proxy_pass' => $proxy_pass, + 'proxy_cache' => 1, + 'status' => 'start', + 'time' => time() + ); + $res = $this -> _insert('module_hyproxy', $data); + if ($res) { + $cmd = "amh module HYProxy-1.0 admin make,$server_name"; + $cmd = Functions::trim_cmd($cmd); + shell_exec($cmd); + return array( 'status' => 'success' , 'notice' => $server_name.' : HYProxy域名增加成功。' ); + } else { + return array( 'status' => 'error' , 'notice' => $server_name.' : HYProxy域名增加失败。' ); + } + } + } + // 编辑反代网站 + function hyproxy_edit() + { +//OK + $server_name = trim($_POST['server_name']); + if ($_POST['index']!=$_POST['index_hidden']) {//默认首页 + $data['index'] = empty($_POST['index']) ? 'index.php index.html index.htm' : trim($_POST['index']); + } + if ($_POST['header_host']!=$_POST['header_host_hidden']) {//Host头 + $data['header_host'] = empty($_POST['header_host']) ? '$host' : trim($_POST['header_host']); + } + if ($_POST['proxy_pass']!=$_POST['proxy_pass_hidden']) {//后端地址 + $data['proxy_pass'] = trim($_POST['proxy_pass']); + empty($data['proxy_pass']) && $data['proxy_pass'] = 'http://'.$server_name; + if (!preg_match('/^http(s)?:\\/\\/.+/', $data['proxy_pass'])) { + $data['proxy_pass'] = 'http://'.$data['proxy_pass']; + } + } + $data['time'] = time();//时间戳 + $where = sprintf("WHERE `server_name` = '%s'", $server_name);//查询条件 + $res = $this -> _update('module_hyproxy', $data, $where); + + if ($res) { + $cmd = "amh module HYProxy-1.0 admin make,$server_name"; + $cmd = Functions::trim_cmd($cmd); + shell_exec($cmd); + return array( 'status' => 'success' , 'notice' => $server_name.' : HYProxy域名修改成功。' ); + } else { + return array( 'status' => 'error' , 'notice' => $server_name.' : HYProxy域名修改失败。' ); + } + } + // 删除反代网站 + function hyproxy_del($del_name) + { +//OK + $del_name = trim($del_name); + $cmd = "amh module HYProxy-1.0 admin del,$del_name"; + $cmd = Functions::trim_cmd($cmd); + $result = $this->hyclear_result(shell_exec($cmd)); + if (strpos($result, '[ERROR]') === false) { + return array( 'status' => 'success' , 'notice' => $del_name.' : HYProxy域名删除成功。' ); + } else { + return array( 'status' => 'error' , 'notice' => $del_name.' : HYProxy域名删除失败。' ); + } + } + // 状态 + function hyproxy_run($run_name, $g) + { +//OK + $run_zh = array( + 'start' => '启动', + 'stop' => '停止' + ); + $data['status'] = $g; + $data['time'] = time();//时间戳 + $where = sprintf("WHERE `server_name` = '%s'", $run_name);//查询条件 + $res = $this -> _update('module_hyproxy', $data, $where); + + if ($res) { + $cmd = "amh module HYProxy-1.0 admin make,$run_name"; + $cmd = Functions::trim_cmd($cmd); + shell_exec($cmd); + return array( 'status' => 'success' , 'notice' => $run_name . ' : HYProxy域名' . $run_zh[$g] . '成功。' ); + } else { + return array( 'status' => 'error' , 'notice' => $run_name . ' : HYProxy域名' . $run_zh[$g] . '失败。' ); + } + } + // 缓存状态 + function hyproxy_run_cache($run_name, $g) + { +//OK + $run_zh = array( + '1' => '启动', + '0' => '停止' + ); + $data['proxy_cache'] = $g; + $data['time'] = time();//时间戳 + $where = sprintf("WHERE `server_name` = '%s'", $run_name);//查询条件 + $res = $this -> _update('module_hyproxy', $data, $where); + + if ($res) { + $cmd = "amh module HYProxy-1.0 admin make,$run_name"; + $cmd = Functions::trim_cmd($cmd); + shell_exec($cmd); + return array( 'status' => 'success' , 'notice' => $run_name . ' : HYProxy域名缓存' . $run_zh[$g] . '成功。' ); + } else { + return array( 'status' => 'error' , 'notice' => $run_name . ' : HYProxy域名缓存' . $run_zh[$g] . '失败。' ); + } + } + + // ********************************************************* + // 取得缓存 + function get_hyproxy_cache() + { + $name = trim($name); + $cmd = "amh cat_nginx"; + $cmd = Functions::trim_cmd($cmd); + $result = trim(shell_exec($cmd), "\n"); + $result = Functions::trim_result($result); + preg_match("/hyproxy_cache levels=(.*)keys_zone=hyproxy:(.*)inactive=(.*)max_size=(.*);/", $result, $arr); + preg_match("/proxy_cache_valid 200 304(.*);/", $result, $arr2); + $data['levels'] = $arr[1]; + $data['keys_zone'] = $arr[2]; + $data['inactive'] = $arr[3]; + $data['max_size'] = $arr[4]; + $data['valid'] = $arr2[1]; + foreach ($data as $key => $val) { + $data[$key] = trim($val); + } + return $data; + } + + // 保存缓存 + function save_hyproxy_cache() + { + $run_name = trim($run_name); + $cmd = "amh module HYProxy-1.0 admin cache,{$_POST['levels']},{$_POST['keys_zone']},{$_POST['max_size']},{$_POST['valid']},{$_POST['inactive']}"; + $cmd = Functions::trim_cmd($cmd); + exec($cmd, $tmp, $status); + return !$status; + } + + + // ********************************************************* + // 取得缓存索引 + function get_hyproxy_cache_index() + { + // $sql = "SELECT count(*) FROM module_hyproxy GROUP BY hyproxy_type "; + $sql = "SELECT * FROM module_hyproxy_cache"; + $result = $this -> _query($sql); + while ($rs = mysql_fetch_assoc($result)) { + $url_info = parse_url($rs['hyproxy_key']); + if (isset($url_info['host']) && !empty($url_info['host'])) { + ++$data[$url_info['host']]['all']['sum']; + $data[$url_info['host']]['all']['size'] += $rs['hyproxy_size']; + + ++$data[$url_info['host']][$rs['hyproxy_type']]['sum']; + $data[$url_info['host']][$rs['hyproxy_type']]['size'] += $rs['hyproxy_size']; + } + } + return $data; + } + + // 创建缓存索引 + function create_hyproxy_cache_index() + { + $val = (int)$_POST['cache_index_time_val']; + $type = array('1' => 60*24, '2' => 60, '3' => 1); + $area = array('1' => '-', '2' => '+'); + $val = isset($type[$_POST['cache_index_time_type']]) ? $val * $type[$_POST['cache_index_time_type']] : $val * $type[1]; // 时间类型 + $val = isset($area[$_POST['cache_index_time_type']]) ? $area[$_POST['cache_index_time_area']] . $val : '-' . $val; // 时间范围 + $mode = $_POST['cache_index_time_mode'] == '2' ? 'truncate' : ''; + + $cmd = "amh module HYProxy-1.0 admin cache-index,$val,$mode"; + $cmd = Functions::trim_cmd($cmd); + exec($cmd, $tmp, $status); + return !$status; + } + + // ********************************************************* + // 取得缓存列表 + function get_hyproxy_cache_list($page = 1, $page_sum = 20) + { + $where = ''; + + if (isset($_GET['cache_key']) && !empty($_GET['cache_key'])) { + $_GET['cache_key'] = trim($_GET['cache_key']); + $where .= " AND hyproxy_key LIKE '{$_GET['cache_key']}'"; + } + + if (isset($_GET['cache_type']) && $_GET['cache_type'] != 'all') { + $where .= " AND hyproxy_type LIKE '{$_GET['cache_type']}'"; + } + + $limit = ' LIMIT ' . ($page-1)*$page_sum . ' , ' . $page_sum; + $sql = "SELECT * FROM module_hyproxy_cache WHERE 1 $where"; + $sum = $this -> _sum($sql); + + $sql = "SELECT * FROM module_hyproxy_cache WHERE 1 $where $limit"; + return array('data' => $this -> _all($sql), 'sum' => $sum); + } + + // 删除缓存 + function hyproxy_cache_delete() + { + $url_param = (isset($_POST['cache_key']) && !empty($_POST['cache_key'])) ? $_POST['cache_key'] : '-all'; + $file_type = (isset($_POST['cache_type']) && !empty($_POST['cache_type']) && $_POST['cache_type'] != 'all') ? $_POST['cache_type'] : '-all'; + $cmd = "amh module HYProxy-1.0 admin cache-delete,$url_param,$file_type"; + $cmd = Functions::trim_cmd($cmd); + exec($cmd, $tmp, $status); + return !$status; + } +} diff --git a/View/hyproxy_cache.php b/View/hyproxy_cache.php index e4177e8..79feaf8 100644 --- a/View/hyproxy_cache.php +++ b/View/hyproxy_cache.php @@ -1,91 +1,93 @@ - -
- - -

' . $notice . '

'; -?> -

反代缓存设置:

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
名称说明
缓存数据目录 -/home/hyproxy_cache -缓存数据保存的位置
数据目录层次(levels) * -缓存数据目录层次
允许使用1或2 / 最大3层 -
(e.g: 1:2)
-
区域内存大小(keys_zone) * -设置缓存区域内存大小 -
(e.g: 20m)
-
磁盘空间大小(max_size) * -限制缓存磁盘空间大小 -
(e.g: 2g)
-
缓存文件有效时间(valid) * -设置缓存文件有效时间
-超过设定时间即重新请求 -
(e.g: 12h)
-
缓存文件删除时间(inactive) * -缓存文件无新访问之后删除时间
-
(e.g: 10d)
-
- -
-
- - - -
-

» SSH HYProxy 缓存设置

-cache: 设置缓存 (ssh命令: amh module HYProxy-1.0 admin cache,levels,keys_zone,max_size,valid,inactive)
-cache 参数说明:
-
    -
  • levels: 缓存数据目录层次,最多可为3层。示例值: 1:2:2
  • -
  • keys_zone: 缓存区域内存大小。示例值: 20m
  • -
  • max_size: 限制缓存磁盘空间大小。示例值:2g
  • -
  • valid: 设置缓存文件有效时间,超过设定时间即重新请求。示例值:12h
  • -
  • inactive: 缓存文件删除时间,超过设置的时间内如无新访问请求缓存将自动删除。示例值: 10d
  • -
-start-cache: 域名开启缓存 (ssh命令: amh module HYProxy-1.0 admin start-cache,amysql.com) 启动amysql.com反代网站缓存。
-stop-cache: 域名停止缓存 (ssh命令: amh module HYProxy-1.0 admin stop-cache,amysql.com) 停止amysql.com反代网站缓存。
- -
- - - - + +
+ + +

' . $notice . '

'; +} +?> +

反代缓存设置:

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
名称说明
缓存数据目录 +/home/hyproxy_cache +缓存数据保存的位置
数据目录层次(levels) * +缓存数据目录层次
允许使用1或2 / 最大3层 +
(e.g: 1:2)
+
区域内存大小(keys_zone) * +设置缓存区域内存大小 +
(e.g: 20m)
+
磁盘空间大小(max_size) * +限制缓存磁盘空间大小 +
(e.g: 2g)
+
缓存文件有效时间(valid) * +设置缓存文件有效时间
+超过设定时间即重新请求 +
(e.g: 12h)
+
缓存文件删除时间(inactive) * +缓存文件无新访问之后删除时间
+
(e.g: 10d)
+
+ +
+
+ + + +
+

» SSH HYProxy 缓存设置

+cache: 设置缓存 (ssh命令: amh module HYProxy-1.0 admin cache,levels,keys_zone,max_size,valid,inactive)
+cache 参数说明:
+
    +
  • levels: 缓存数据目录层次,最多可为3层。示例值: 1:2:2
  • +
  • keys_zone: 缓存区域内存大小。示例值: 20m
  • +
  • max_size: 限制缓存磁盘空间大小。示例值:2g
  • +
  • valid: 设置缓存文件有效时间,超过设定时间即重新请求。示例值:12h
  • +
  • inactive: 缓存文件删除时间,超过设置的时间内如无新访问请求缓存将自动删除。示例值: 10d
  • +
+start-cache: 域名开启缓存 (ssh命令: amh module HYProxy-1.0 admin start-cache,amysql.com) 启动amysql.com反代网站缓存。
+stop-cache: 域名停止缓存 (ssh命令: amh module HYProxy-1.0 admin stop-cache,amysql.com) 停止amysql.com反代网站缓存。
+ +
+ + + + diff --git a/View/hyproxy_cache_del.php b/View/hyproxy_cache_del.php index 6d1448d..2586a8d 100644 --- a/View/hyproxy_cache_del.php +++ b/View/hyproxy_cache_del.php @@ -1,161 +1,155 @@ - - - -
- - -

' . $notice . '

'; -?> - -
-

搜索查看缓存与删除

-
- - -索引域名   - -网址匹配 (可使用%通配符)   -文件类型   - - -
-
- - -
- - - - - - - - - - - - - $val) - { - ?> - - - - - - - - - - - - - -
编号缓存文件网址状态码文件类型大小 / MB创建时间
没找到缓存索引数据。
-
-删除当前搜索结果(缓存索引&缓存文件) 项 - - - - -
-
-
页 - 记录 » 页码
- - -
-

» SSH HYProxy 缓存删除

-cache-delete: 缓存删除 (ssh命令: amh module HYProxy-1.0 admin cache-delete,url-param,file-type)
-cache-delete 参数说明:
-
    -
  • url-param: 网址匹配参数,可使用%通配符进行匹配删除。预设参数值有: -all (使用-all即匹配所有网址)
  • -
  • file-type: 缓存文件类型匹配参数,可匹配text/html、image/gif等相关文件类型进行删除。预设参数值有: -all (使用-all即匹配所有文件类型)
  • -
- -
-
- - - - - + + + +
+ + +

' . $notice . '

'; +} +?> + +
+

搜索查看缓存与删除

+
+ + +索引域名   + +网址匹配 (可使用%通配符)   +文件类型   + + +
+
+ + +
+ + + + + + + + + + + + + $val) { + ?> + + + + + + + + + + + + + +
编号缓存文件网址状态码文件类型大小 / MB创建时间
没找到缓存索引数据。
+
+删除当前搜索结果(缓存索引&缓存文件) 项 + + + + +
+
+
页 - 记录 » 页码
+ + +
+

» SSH HYProxy 缓存删除

+cache-delete: 缓存删除 (ssh命令: amh module HYProxy-1.0 admin cache-delete,url-param,file-type)
+cache-delete 参数说明:
+
    +
  • url-param: 网址匹配参数,可使用%通配符进行匹配删除。预设参数值有: -all (使用-all即匹配所有网址)
  • +
  • file-type: 缓存文件类型匹配参数,可匹配text/html、image/gif等相关文件类型进行删除。预设参数值有: -all (使用-all即匹配所有文件类型)
  • +
+ +
+
+ + + + + diff --git a/View/hyproxy_cache_index.php b/View/hyproxy_cache_index.php index 3330588..da9b1f2 100644 --- a/View/hyproxy_cache_index.php +++ b/View/hyproxy_cache_index.php @@ -1,163 +1,162 @@ - - - -
- - -

' . $notice . '

'; -?> -

反代缓存索引:

- - - - - - - -$val) -{ - $file_sum += $val['all']['sum']; - $file_size += $val['all']['size']; - ++$host_sum; -?> - - - - - - - - - - - - - -
索引域名总缓存数量总使用空间
主页 总缓存文件 总使用空间 MB
- - - - - - -$v) -{ - if($k != 'all') - { -?> - - - - - - -
缓存文件类型缓存数量使用空间
缓存文件 使用空间 MB
-
共索引域名 个: - 全部缓存文件 个 / - 全部缓存文件已用 MB
- -

-
-

建立缓存索引:

- - - - - - - - - - - - - - -
时间单位时间范围使用模式
- - - - - -
- - -
- - -
-

» SSH HYProxy 缓存索引

-cache-index: 设置缓存 (ssh命令: amh module HYProxy-1.0 admin cache-index,cmin,mode)
-cache-index 参数说明:
-
    -
  • cmin: 索引缓存文件使用的时间,单位为分钟。可使用:+分钟 / -分钟
  • -
  • +分钟: 索引N分钟之前的缓存数据。
  • -
  • -分钟: 索引N分钟之内的缓存数据。
  • -
  • mode: 索引数据模式,可选参数。可用值:truncate (清空模式,清空旧索引数据后再建立索引) -
- -
- - - - + + + +
+ + +

' . $notice . '

'; +} +?> +

反代缓存索引:

+ + + + + + + + $val) { + $file_sum += $val['all']['sum']; + $file_size += $val['all']['size']; + ++$host_sum; + ?> + + + + + + + + + + + + + +
索引域名总缓存数量总使用空间
主页 总缓存文件 总使用空间 MB
+ + + + + + + $v) { + if ($k != 'all') { + ?> + + + + + + +
缓存文件类型缓存数量使用空间
缓存文件 使用空间 MB
+
共索引域名 个: + 全部缓存文件 个 / + 全部缓存文件已用 MB
+ +

+
+

建立缓存索引:

+ + + + + + + + + + + + + + +
时间单位时间范围使用模式
+ + + + + +
+ + +
+ + +
+

» SSH HYProxy 缓存索引

+cache-index: 设置缓存 (ssh命令: amh module HYProxy-1.0 admin cache-index,cmin,mode)
+cache-index 参数说明:
+
    +
  • cmin: 索引缓存文件使用的时间,单位为分钟。可使用:+分钟 / -分钟
  • +
  • +分钟: 索引N分钟之前的缓存数据。
  • +
  • -分钟: 索引N分钟之内的缓存数据。
  • +
  • mode: 索引数据模式,可选参数。可用值:truncate (清空模式,清空旧索引数据后再建立索引) +
+ +
+ + + + diff --git a/View/hyproxy_category.php b/View/hyproxy_category.php index 15dd40c..2b3554d 100644 --- a/View/hyproxy_category.php +++ b/View/hyproxy_category.php @@ -1,31 +1,31 @@ - - - -

AMH » HYProxy

-
- 反代列表 - 缓存设置 - 缓存索引 - 缓存删除 - -
\ No newline at end of file + + + +

AMH » HYProxy

+
+ 反代列表 + 缓存设置 + 缓存索引 + 缓存删除 + +
diff --git a/View/hyproxy_list.php b/View/hyproxy_list.php index 115d74f..c4e67ee 100644 --- a/View/hyproxy_list.php +++ b/View/hyproxy_list.php @@ -4,8 +4,10 @@

' . $notice . '

'; -?> + if (!empty($notice)) { + echo '

' . $notice . '

'; + } + ?>

HYProxy反向代理:

@@ -15,30 +17,26 @@ - + - $val) - { - ?> + $val) { + ?> - +
最后修改 管理
暂无绑定域名。
> > 管理 删除

@@ -93,7 +91,7 @@ - +
@@ -124,7 +122,7 @@
- +

» SSH HYProxy

1) 有步骤提示操作: