commit
3eeefe4eff
|
|
@ -0,0 +1,313 @@
|
|||
#!/bin/bash
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin;
|
||||
module_dir="/root/amh/modules/HYProxy-1.0/";
|
||||
|
||||
#info
|
||||
function amh_module_info()
|
||||
{
|
||||
echo 'AMH-ModuleName: HYProxy-1.0';
|
||||
echo 'AMH-ModuleDescription: HYProxy 反向代理模块。';
|
||||
echo 'AMH-ModuleButton: 安装/卸载';
|
||||
echo 'AMH-ModuleDate: 2018-09-15';
|
||||
echo 'AMH-ModuleAdmin: ./index.php?c=hyproxy';
|
||||
echo 'AMH-ModuleWebSite: http://www.huayizhiyun.com';
|
||||
echo 'AMH-ModuleScriptBy: HITSword.';
|
||||
}
|
||||
|
||||
#install
|
||||
function amh_module_install()
|
||||
{
|
||||
if amh_module_status ; then
|
||||
exit;
|
||||
else
|
||||
for module_name in `ls /root/amh/modules/ | grep 'HYProxy' | grep -v 'HYProxy-1.0'`; do
|
||||
#amh module $module_name uninstall force;
|
||||
#amh module $module_name delete y;
|
||||
rm -rf /root/amh/modules/$module_name;
|
||||
done;
|
||||
#install PDO_MYSQL module and set InnoDB_Engine On
|
||||
amh module download PDO_MYSQL-1.0.2;
|
||||
amh module PDO_MYSQL-1.0.2 install force;
|
||||
amh SetParam mysql InnoDB_Engine On;
|
||||
#install nginx module
|
||||
Cpunum=`cat /proc/cpuinfo |grep 'processor'|wc -l`;
|
||||
nginx_configure=`/usr/local/nginx/sbin/nginx -V 2> /tmp/nginx_configure && cat /tmp/nginx_configure | grep 'configure arguments' | cut -d: -f2 && rm -f /tmp/nginx_configure`;
|
||||
new_nginx_configure=$nginx_configure;
|
||||
#if ! echo "$new_nginx_configure" | grep 'with-ipv6' > /dev/null; then
|
||||
#new_nginx_configure="${new_nginx_configure} --with-ipv6";
|
||||
#fi;
|
||||
if ! echo "$new_nginx_configure" | grep 'with-http_stub_status_module' > /dev/null; then
|
||||
new_nginx_configure="${new_nginx_configure} --with-http_stub_status_module";
|
||||
fi;
|
||||
if ! echo "$new_nginx_configure" | grep 'add-module=/usr/local/ngx_cache_purge-2.3' > /dev/null; then
|
||||
new_nginx_configure="${new_nginx_configure} --add-module=/usr/local/ngx_cache_purge-2.3";
|
||||
fi;
|
||||
|
||||
if [ "$nginx_configure" != "$new_nginx_configure" ]; then
|
||||
cd /usr/local/;
|
||||
wget http://soft.huayizhiyun.com/manage/amh/nginx/nginx-1.14.0.tar.gz;
|
||||
tar -zxf nginx-1.14.0.tar.gz;
|
||||
wget http://soft.huayizhiyun.com/manage/amh/nginx/ngx_cache_purge-2.3.tar.gz;
|
||||
tar -zxf ngx_cache_purge-2.3.tar.gz;
|
||||
|
||||
cd nginx-1.14.0;
|
||||
./configure $new_nginx_configure;
|
||||
make -j $Cpunum;
|
||||
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-old;
|
||||
\cp -a ./objs/nginx /usr/local/nginx/sbin/;
|
||||
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`;
|
||||
cd /usr/local/;
|
||||
rm -rf nginx-1.14.0 nginx-1.14.0.tar.gz /usr/local/nginx/sbin/nginx-old;
|
||||
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`;
|
||||
sed -i "s|Nginx.*<br />|Nginx 1.14.0 <br />|" /home/wwwroot/index/web/View/index.php;
|
||||
fi;
|
||||
|
||||
MysqlPass=`cat /home/wwwroot/index/web/Amysql/Config.php | awk '{ FS="\047Password\047] = \047"; RS="\047;" } { print $2}' | sed '/^$/d'`;
|
||||
cd /root/amh/modules/HYProxy-1.0;
|
||||
\cp Controller/hyproxy.php /home/wwwroot/index/web/Controller/hyproxy.php;
|
||||
\cp Model/hyproxys.php /home/wwwroot/index/web/Model/hyproxys.php;
|
||||
\cp View/{hyproxy_category.php,hyproxy_list.php,hyproxy_cache.php,hyproxy_cache_index.php,hyproxy_cache_del.php} /home/wwwroot/index/web/View/;
|
||||
mkdir -p /usr/local/nginx/conf/hyproxy;
|
||||
|
||||
sed -i "/include hyproxy/d" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "s/server_names_hash_bucket_size 128/server_names_hash_bucket_size 512/g" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "/include hyproxy/d" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "/include vhost/a\ \tinclude hyproxy/*.conf;" /usr/local/nginx/conf/nginx.conf;
|
||||
mysql -uroot -p$MysqlPass < ./hyproxy.sql && touch ./InstallComplete && amh module HYProxy-1.0 admin cache,1:2:2,256m,10g,4h,1d;
|
||||
|
||||
amh nginx reload;
|
||||
amh_module_status;
|
||||
fi;
|
||||
}
|
||||
|
||||
#admin
|
||||
function amh_module_admin()
|
||||
{
|
||||
if amh_module_status ; then
|
||||
param_list=${1//,/ };
|
||||
set -- $param_list;
|
||||
action=$1;
|
||||
domain=$2;
|
||||
|
||||
if [ "$action" == '' ]; then
|
||||
echo "[Notice] HYProxy management, please select: (1~4)"
|
||||
select action in 'list' 'make' 'add' 'start' 'stop' 'edit' 'del' 'start-cache' 'stop-cache' 'cache' 'cache-index' 'cache-delete'; do
|
||||
break;
|
||||
done;
|
||||
fi;
|
||||
|
||||
if [ "$action" == 'list' ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='list' --proxy_status='start';
|
||||
php ${module_dir}hyproxy-cli.php --action='list' --proxy_status='stop';
|
||||
exit;
|
||||
elif [ "$action" == 'make' ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='make' --server_name=${domain};
|
||||
nginx -t
|
||||
amh nginx reload
|
||||
exit;
|
||||
elif [ "$action" == 'cache' ] ; then
|
||||
levels=$2;
|
||||
keys_zone=$3;
|
||||
max_size=$4;
|
||||
valid=$5;
|
||||
inactive=$6;
|
||||
[ "$levels" == '' ] && read -p "[Notice] Please input levels (e.g: 1:2):" levels && [ "$levels" == '' ] && levels='1:2:2';
|
||||
[ "$keys_zone" == '' ] && read -p "[Notice] Please input keys_zone (e.g: 10m):" keys_zone && [ "$keys_zone" == '' ] && keys_zone='10m';
|
||||
[ "$max_size" == '' ] && read -p "[Notice] Please input max_size (e.g: 2g):" max_size && [ "$max_size" == '' ] && max_size='2g';
|
||||
[ "$valid" == '' ] && read -p "[Notice] Please input valid (e.g: 12h):" valid && [ "$valid" == '' ] && valid='12h';
|
||||
[ "$inactive" == '' ] && read -p "[Notice] Please input inactive (e.g: 10d):" inactive && [ "$inactive" == '' ] && inactive='10d';
|
||||
sed -i "/proxy_/d" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "/fastcgi_intercept_errors/a\ \tproxy_cache_path \/home\/hyproxy_cache levels=$levels keys_zone=hyproxy:$keys_zone inactive=$inactive max_size=$max_size;" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "/fastcgi_intercept_errors/a\ \tproxy_temp_path \/home\/hyproxy_cache_tmp;" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "/fastcgi_intercept_errors/a\ \tproxy_cache_key \$scheme:\/\/\$host\$request_uri;" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "/fastcgi_intercept_errors/a\ \tproxy_cache_valid 200 304 $valid;" /usr/local/nginx/conf/nginx.conf;
|
||||
kill -HUP `cat /usr/local/nginx/logs/nginx.pid` && echo "[OK] HYProxy cache-param save success." && exit;
|
||||
elif [ "$action" == 'cache-index' ] ; then
|
||||
MysqlPass=`cat /home/wwwroot/index/web/Amysql/Config.php | awk '{ FS="\047Password\047] = \047"; RS="\047;" } { print $2}' | sed '/^$/d'`;
|
||||
cmin=$2;
|
||||
mode=$3;
|
||||
[ "$cmin" == '' ] && read -p "[Notice] Please input cmin value(e.g: +10):" cmin && [ "$cmin" == '' ] && cmin='+10';
|
||||
[ ! -d /home/hyproxy_cache ] && echo "[Error] hyproxy_cache dir not exist!" && exit 1;
|
||||
cd /home/hyproxy_cache;
|
||||
i=0;
|
||||
cmin=${cmin//;/} && cmin=${cmin// /};
|
||||
rm -f ./cache-index.sql;
|
||||
for line in `find ./ -type f -cmin $cmin`; do
|
||||
echo $line;
|
||||
text=`head -18 $line`;
|
||||
key=`echo "$text" | grep 'KEY:' | awk '{print $2}'`;
|
||||
http_s=`echo "$text" | grep 'HTTP/' | awk '{print $2}'`;
|
||||
type=`echo "$text" | grep 'Content-Type:' | awk '{print $2}'`;
|
||||
[ "$type" != '' ] && type=${type:0:$((${#type}-1))};
|
||||
size=`echo "$text" | grep 'Content-Length:' | awk '{printf("%.3f", $2/1024/1024)}'`;
|
||||
time=`stat $line | grep 'Change' | awk '{print $2" "$3}' | cut -d '.' -f 1`;
|
||||
echo "('$line','$key','$http_s','$type','$size','$time')," >> ./cache-index.sql;
|
||||
i=$[i+1];
|
||||
done;
|
||||
[ "$mode" == 'truncate' ] && mysql -uroot -p${MysqlPass} -B -N -e "TRUNCATE TABLE amh.module_hyproxy_cache";
|
||||
[ ! -f "./cache-index.sql" ] && echo '[OK] No data found.' && exit;
|
||||
sed -i "1i REPLACE INTO amh.module_hyproxy_cache (hyproxy_file,hyproxy_key,hyproxy_http_s,hyproxy_type,hyproxy_size,hyproxy_time) VALUES " ./cache-index.sql;
|
||||
sed -i "$ s/),/)\;/" ./cache-index.sql;
|
||||
mysql -uroot -p$MysqlPass < ./cache-index.sql && echo "[OK] HYProxy cache-index success. ($i row)" ;
|
||||
rm -f ./cache-index.sql;
|
||||
elif [ "$action" == 'cache-delete' ] ; then
|
||||
MysqlPass=`cat /home/wwwroot/index/web/Amysql/Config.php | awk '{ FS="\047Password\047] = \047"; RS="\047;" } { print $2}' | sed '/^$/d'`;
|
||||
url_param=$2;
|
||||
file_type=$3;
|
||||
[ "$url_param" == '' ] && read -p "[Notice] Please input url-param (e.g: amysql.com/images/):" url_param
|
||||
[ "$file_type" == '' ] && read -p "[Notice] Please input file-type (e.g: image/jpeg):" file_type
|
||||
|
||||
sqls="SELECT hyproxy_file FROM amh.module_hyproxy_cache WHERE 1";
|
||||
sqld="DELETE FROM amh.module_hyproxy_cache WHERE 1";
|
||||
sql_furl=${sql_furl//;/} && sql_furl=${sql_furl// /};
|
||||
sql_ftype=${sql_ftype//;/} && sql_ftype=${sql_ftype// /};
|
||||
[ "$url_param" != '-all' ] && sql_furl=" AND hyproxy_key LIKE '$url_param' ";
|
||||
[ "$file_type" != '-all' ] && sql_ftype=" AND hyproxy_type LIKE '$file_type' ";
|
||||
i=0;
|
||||
for line in `mysql -uroot -p${MysqlPass} -B -N -e "$sqls $sql_furl $sql_ftype"`; do
|
||||
( echo "$line" | grep '\.\.' || [ "$line" == '' ] ) && echo '[Error] Error data.' && exit 1;
|
||||
echo $line;
|
||||
rm -f "/home/hyproxy_cache/${line}" && i=$[i+1];
|
||||
done;
|
||||
mysql -uroot -p${MysqlPass} -B -N -e "$sqld $sql_furl $sql_ftype" && echo "[OK] HYProxy cache-delete success. ($i row)" ;
|
||||
else
|
||||
if [ "$action" != 'list' ] && [ "$action" != 'cache' ] ; then
|
||||
[ "$domain" == '' ] && read -p "[Notice] please input domain(e.g amysql.com):" domain
|
||||
[ "$domain" == '' ] && amh module HYProxy-1.0 admin $action;
|
||||
fi;
|
||||
domain_conf="/usr/local/nginx/conf/hyproxy/$domain.conf";
|
||||
|
||||
if [ "$action" == 'add' ]; then
|
||||
[ -f "$domain_conf" ] && echo "[Error] $domain HYProxy is exist!" && exit 1;
|
||||
proxy_pass=$3;
|
||||
if [ "$proxy_pass" == '' ]; then
|
||||
read -p "[Notice] please input proxy_pass(e.g nginx.org):" proxy_pass
|
||||
[ "$proxy_pass" == '' ] && amh module HYProxy-1.0 admin $action;
|
||||
fi;
|
||||
php ${module_dir}hyproxy-cli.php --action='add' --server_name=${domain} --proxy_pass=${proxy_pass};
|
||||
nginx -t
|
||||
amh nginx reload
|
||||
elif [ "$action" == 'edit' ]; then
|
||||
ParamName=$3;
|
||||
i=0;
|
||||
for line in $*; do
|
||||
i=$[$i+1];
|
||||
[ "$i" -gt 3 ] && ParamVal="$ParamVal$line";
|
||||
##get value
|
||||
done;
|
||||
|
||||
HYProxy[0]='header_host|nginx.org';
|
||||
HYProxy[1]='proxy_pass|http://nginx.org';
|
||||
|
||||
i=0;
|
||||
HYProxyParamList='';
|
||||
HYProxyParamListEG='';
|
||||
for line in ${HYProxy[*]}; do
|
||||
OldIFS=$IFS;
|
||||
IFS='|';
|
||||
set -- $line;
|
||||
i=$[$i+1];
|
||||
HYProxyParamList[$i]="$1";
|
||||
HYProxyParamListEG[$i]="$2";
|
||||
IFS=$OldIFS;
|
||||
done;
|
||||
|
||||
if [ "$ParamName" == '' ]; then
|
||||
echo "[Notice] $domain proxy parameter set, please select: (1~$i)"
|
||||
select ParamName in ${HYProxyParamList[*]}; do break; done;
|
||||
fi;
|
||||
|
||||
for((;i>0;i--));do
|
||||
if [ "${HYProxyParamList[$i]}" == "$ParamName" ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='edit' --server_name=${domain} --field_name=${ParamName} --value=${ParamVal};
|
||||
amh nginx reload;
|
||||
exit;
|
||||
fi;
|
||||
done;
|
||||
amh module HYProxy-1.0 admin $action,$domain;
|
||||
|
||||
elif [ "$action" == 'del' ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='del' --server_name=${domain}
|
||||
rm -f "$domain_conf" && echo "[OK] successfully delete $domain HYProxy.";
|
||||
amh nginx reload;
|
||||
elif [ "$action" == 'start' ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='edit' --server_name=${domain} --field_name='status' --value='start';
|
||||
amh nginx reload;
|
||||
elif [ "$action" == 'stop' ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='edit' --server_name=${domain} --field_name='status' --value='stop';
|
||||
amh nginx reload;
|
||||
elif [ "$action" == 'start-cache' ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='edit' --server_name=${domain} --field_name='proxy_cache' --value='1';
|
||||
amh nginx reload;
|
||||
elif [ "$action" == 'stop-cache' ]; then
|
||||
php ${module_dir}hyproxy-cli.php --action='edit' --server_name=${domain} --field_name='proxy_cache' --value='0';
|
||||
amh nginx reload;
|
||||
elif [ "$action" == 'cat' ]; then
|
||||
[ ! -f "$domain_conf" ] && echo "[Error] $domain HYProxy not exist!" && exit 1;
|
||||
cat "$domain_conf";
|
||||
else
|
||||
amh module HYProxy-1.0 admin;
|
||||
exit;
|
||||
fi;
|
||||
fi;
|
||||
else
|
||||
exit;
|
||||
fi;
|
||||
}
|
||||
|
||||
#uninstall
|
||||
function amh_module_uninstall()
|
||||
{
|
||||
if amh_module_status ; then
|
||||
|
||||
#uninstall nginx modules
|
||||
Cpunum=`cat /proc/cpuinfo |grep 'processor'|wc -l`;
|
||||
nginx_configure=`/usr/local/nginx/sbin/nginx -V 2> /tmp/nginx_configure && cat /tmp/nginx_configure | grep 'configure arguments' | cut -d: -f2 && rm -f /tmp/nginx_configure`;
|
||||
new_nginx_configure=$nginx_configure;
|
||||
if echo "$new_nginx_configure" | grep 'add-module=/usr/local/ngx_cache_purge-2.3' > /dev/null; then
|
||||
new_nginx_configure=`echo $new_nginx_configure | sed "s|--add-module=/usr/local/ngx_cache_purge-2.3||"`;
|
||||
fi;
|
||||
|
||||
if [ "$nginx_configure" != "$new_nginx_configure" ]; then
|
||||
cd /usr/local/;
|
||||
wget http://soft.huayizhiyun.com/manage/amh/nginx/nginx-1.14.0.tar.gz;
|
||||
tar -zxf nginx-1.14.0.tar.gz;
|
||||
cd nginx-1.14.0;
|
||||
./configure $new_nginx_configure;
|
||||
make -j $Cpunum;
|
||||
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-old;
|
||||
\cp -a ./objs/nginx /usr/local/nginx/sbin/;
|
||||
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`;
|
||||
cd /usr/local/;
|
||||
rm -rf nginx-1.14.0 nginx-1.14.0.tar.gz /usr/local/nginx/sbin/nginx-old;
|
||||
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`;
|
||||
fi;
|
||||
|
||||
MysqlPass=`cat /home/wwwroot/index/web/Amysql/Config.php | awk '{ FS="\047Password\047] = \047"; RS="\047;" } { print $2}' | sed '/^$/d'`;
|
||||
cd /usr/local/;
|
||||
rm -rf ngx_cache_purge-2.3 ngx_cache_purge-2.3.tar.gz;
|
||||
rm -rf /usr/local/nginx/conf/hyproxy /home/hyproxy_cache /home/hyproxy_cache_tmp;
|
||||
rm -f /home/wwwroot/index/web/Controller/hyproxy.php /home/wwwroot/index/web/Model/hyproxys.php /home/wwwroot/index/web/View/{hyproxy_category.php,hyproxy_list.php,hyproxy_cache.php,hyproxy_cache_index.php,hyproxy_cache_del.php};
|
||||
sed -i "/include hyproxy/d" /usr/local/nginx/conf/nginx.conf;
|
||||
sed -i "/proxy_/d" /usr/local/nginx/conf/nginx.conf;
|
||||
rm -f /root/amh/modules/HYProxy-1.0/InstallComplete;
|
||||
mysql -uroot -p${MysqlPass} -B -N -e "DROP TABLE amh.module_hyproxy;DROP TABLE amh.module_hyproxy_cache" ;
|
||||
|
||||
amh nginx reload;
|
||||
echo '[OK] HYProxy Uninstall successful.';
|
||||
else
|
||||
exit;
|
||||
fi;
|
||||
}
|
||||
|
||||
#status //ok
|
||||
function amh_module_status()
|
||||
{
|
||||
if [ -f "/root/amh/modules/HYProxy-1.0/InstallComplete" ]; then
|
||||
echo '[OK] HYProxy is already installed.';
|
||||
return 0;
|
||||
else
|
||||
echo '[Notice] HYProxy is not installed.';
|
||||
return 1;
|
||||
fi;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
class hyproxy extends AmysqlController {
|
||||
|
||||
public $indexs = null;
|
||||
public $hyproxys = null;
|
||||
public $notice = null;
|
||||
|
||||
// 载入数据模型(Model)
|
||||
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 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);
|
||||
}
|
||||
|
||||
// 新增
|
||||
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');
|
||||
}
|
||||
|
||||
// *********************************************************
|
||||
// 缓存设置
|
||||
function hyproxy_cache(){
|
||||
$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');
|
||||
}
|
||||
|
||||
|
||||
// *********************************************************
|
||||
// 缓存索引
|
||||
function hyproxy_cache_index(){
|
||||
$this -> title = '缓存索引 - HYProxy - AMH';
|
||||
$this -> AmysqlModelBase();
|
||||
Functions::CheckLogin();
|
||||
|
||||
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']))
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
|
||||
class hyproxys extends AmysqlModel{
|
||||
function hyclear_result($str){
|
||||
$str = Functions::trim_result($str);
|
||||
$str = str_replace(array('[OK] HYProxy is already installed.', '[OK] Nginx reload','[HYProxy-1.0 admin]'), '', $str);
|
||||
$arr = explode("\n", $str); //分割为数组,每行为一个数组元素
|
||||
$arr = array_filter(array_map('trim',$arr)); //去除数组中的空元素
|
||||
return implode(PHP_EOL,$arr); //用换行符连结数组为字符串
|
||||
}
|
||||
|
||||
// 反代列表
|
||||
function hyproxy_list($args=''){//OK
|
||||
//TODO
|
||||
//$server_name = $args['server_name'];域名搜索
|
||||
//$status;//状态搜索start/stop
|
||||
//分页
|
||||
$sql = "SELECT * FROM module_hyproxy ORDER BY hyproxy_id ASC";
|
||||
return $this -> _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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
<?php include('header.php'); ?>
|
||||
<div id="body">
|
||||
<?php include('hyproxy_category.php'); ?>
|
||||
|
||||
<?php
|
||||
if (!empty($notice)) echo '<div style="margin:5px 2px;width:500px;"><p id="' . $status . '">' . $notice . '</p></div>';
|
||||
?>
|
||||
<p>反代缓存设置:</p>
|
||||
<form action="./index.php?c=hyproxy&a=hyproxy_cache" method="POST" >
|
||||
<table border="0" cellspacing="1" id="STable" style="width:720px;">
|
||||
<tr>
|
||||
<th>名称</th>
|
||||
<th>值</th>
|
||||
<th>说明</th>
|
||||
</tr>
|
||||
|
||||
<td>缓存数据目录</td>
|
||||
<td style="padding:8px">
|
||||
/home/hyproxy_cache
|
||||
</td>
|
||||
<td>缓存数据保存的位置</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>数据目录层次(levels)</td>
|
||||
<td><input type="text" name="levels" class="input_text" value="<?php echo $hyproxy_cache['levels'];?>" /> <font class="red">*</font>
|
||||
</td>
|
||||
<td>缓存数据目录层次<br />允许使用1或2 / 最大3层
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: 1:2)</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>区域内存大小(keys_zone)</td>
|
||||
<td><input type="text" name="keys_zone" class="input_text" value="<?php echo $hyproxy_cache['keys_zone'];?>" /> <font class="red">*</font>
|
||||
</td>
|
||||
<td>设置缓存区域内存大小
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: 20m)</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>磁盘空间大小(max_size)</td>
|
||||
<td><input type="text" name="max_size" class="input_text" value="<?php echo $hyproxy_cache['max_size'];?>" /> <font class="red">*</font>
|
||||
</td>
|
||||
<td>限制缓存磁盘空间大小
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: 2g)</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>缓存文件有效时间(valid)</td>
|
||||
<td><input type="text" name="valid" class="input_text" value="<?php echo $hyproxy_cache['valid'];?>" /> <font class="red">*</font>
|
||||
</td>
|
||||
<td>设置缓存文件有效时间<br />
|
||||
超过设定时间即重新请求
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: 12h)</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>缓存文件删除时间(inactive)</td>
|
||||
<td><input type="text" name="inactive" class="input_text" value="<?php echo $hyproxy_cache['inactive'];?>" /> <font class="red">*</font>
|
||||
</td>
|
||||
<td>缓存文件无新访问之后删除时间<br />
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: 10d)</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr><th colspan="3" style="padding:10px;text-align:left;">
|
||||
<button type="submit" class="primary button" name="save"><span class="check icon"></span>保存</button>
|
||||
</th></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<div id="notice_message" style="width:880px;">
|
||||
<h3>» SSH HYProxy 缓存设置</h3>
|
||||
cache: 设置缓存 (ssh命令: amh module HYProxy-1.0 admin cache,levels,keys_zone,max_size,valid,inactive)<br />
|
||||
cache 参数说明: <br />
|
||||
<ul>
|
||||
<li>levels: 缓存数据目录层次,最多可为3层。示例值: 1:2:2</li>
|
||||
<li>keys_zone: 缓存区域内存大小。示例值: 20m</li>
|
||||
<li>max_size: 限制缓存磁盘空间大小。示例值:2g</li>
|
||||
<li>valid: 设置缓存文件有效时间,超过设定时间即重新请求。示例值:12h</li>
|
||||
<li>inactive: 缓存文件删除时间,超过设置的时间内如无新访问请求缓存将自动删除。示例值: 10d</li>
|
||||
</ul>
|
||||
start-cache: 域名开启缓存 (ssh命令: amh module HYProxy-1.0 admin start-cache,amysql.com) 启动amysql.com反代网站缓存。<br />
|
||||
stop-cache: 域名停止缓存 (ssh命令: amh module HYProxy-1.0 admin stop-cache,amysql.com) 停止amysql.com反代网站缓存。<br />
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php include('footer.php'); ?>
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
<?php include('header.php'); ?>
|
||||
<style>
|
||||
#STable td.object_list_last {
|
||||
background:url("View/images/Listbj.gif") repeat-x scroll left top white;
|
||||
padding:8px;
|
||||
text-align:right;
|
||||
line-height:18px;
|
||||
color:#607993;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
var cache_host;
|
||||
var cache_key;
|
||||
var cache_host_js = <?php echo json_encode($cache_host);?>;
|
||||
window.onload = function ()
|
||||
{
|
||||
cache_host = G('cache_host');
|
||||
cache_key = G('cache_key');
|
||||
cache_host.onchange = function ()
|
||||
{
|
||||
|
||||
for (var k in cache_host_js)
|
||||
{
|
||||
var reg = new RegExp('http://' + cache_host_js[k], "gmi");
|
||||
cache_key.value = cache_key.value.replace(reg,'');
|
||||
}
|
||||
if (cache_host.value != '')
|
||||
cache_key.value = 'http://' + cache_host.value + cache_key.value + (cache_key.value == '' ? '%' : '');
|
||||
cache_key.value = cache_key.value == '%' ? '' : cache_key.value;
|
||||
}
|
||||
}
|
||||
var cache_delete_submit = function ()
|
||||
{
|
||||
if (!confirm('删除当前搜索结果(缓存索引&缓存文件) <?php echo $hyproxy_cache_list['sum'];?> 项吗?'))
|
||||
return false;
|
||||
G('cache_delete_button').innerHTML = '删除缓存中…';
|
||||
G('cache_delete_button').disabled = true;
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
<div id="body">
|
||||
<?php include('hyproxy_category.php'); ?>
|
||||
|
||||
<?php
|
||||
if (!empty($notice)) echo '<div style="margin:5px 2px;width:500px;"><p id="' . $status . '">' . $notice . '</p></div>';
|
||||
?>
|
||||
|
||||
<div>
|
||||
<p>搜索查看缓存与删除</p>
|
||||
<form action="" method="GET">
|
||||
<input type="hidden" value="hyproxy_cache_del" name="a"/>
|
||||
<input type="hidden" value="hyproxy" name="c"/>
|
||||
索引域名 <select name="cache_host" id="cache_host" style="width:180px;">
|
||||
<?php if (is_array($cache_host))
|
||||
{
|
||||
foreach ($cache_host as $key=>$val)
|
||||
{
|
||||
?>
|
||||
<option value="<?php echo $val;?>"><?php echo $val;?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<option value="">所有</option>
|
||||
</select>
|
||||
<script>G('cache_host').value = '<?php echo isset($_GET['cache_host']) ? $_GET['cache_host'] : '';?>';</script>
|
||||
网址匹配 (可使用%通配符) <input type="text" name="cache_key" id="cache_key" class="input_text" value="<?php echo isset($_GET['cache_key']) ? $_GET['cache_key'] : '';?>" style="width:250px;"/>
|
||||
文件类型 <select name="cache_type" id="cache_type" style="width:180px;">
|
||||
<?php if (is_array($cache_type))
|
||||
{
|
||||
foreach ($cache_type as $key=>$val)
|
||||
{
|
||||
if($val != 'all') {
|
||||
?>
|
||||
<option value="<?php echo $val;?>"><?php echo $val;?></option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<option value="all">所有</option>
|
||||
</select>
|
||||
<script>G('cache_type').value = '<?php echo isset($_GET['cache_type']) ? $_GET['cache_type'] : all;?>';</script>
|
||||
<button type="submit" class="primary button" >搜索</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#STable td {
|
||||
text-align:left;
|
||||
padding-left:10px;
|
||||
}
|
||||
</style>
|
||||
<div id="HYProxy_list">
|
||||
<table border="0" cellspacing="1" id="STable" style="width:1150px;">
|
||||
<tr>
|
||||
<th>编号</th>
|
||||
<th>缓存文件</th>
|
||||
<th width="380">网址</th>
|
||||
<th>状态码</th>
|
||||
<th>文件类型</th>
|
||||
<th>大小 / MB</th>
|
||||
<th>创建时间</th>
|
||||
</tr>
|
||||
<?php
|
||||
if(!is_array($hyproxy_cache_list['data']) || count($hyproxy_cache_list['data']) < 1)
|
||||
{
|
||||
?>
|
||||
<tr><td colspan="7" style="padding:10px;text-align:center;">没找到缓存索引数据。</td></tr>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
$k = 0;
|
||||
foreach ($hyproxy_cache_list['data'] as $key=>$val)
|
||||
{
|
||||
?>
|
||||
<tr>
|
||||
<th class="i"><?php echo $val['hyproxy_id'];?></th>
|
||||
<td><?php echo $val['hyproxy_file'];?></td>
|
||||
<td><a href="<?php echo $val['hyproxy_key'];?>" target="_blank"><?php echo $val['hyproxy_key'];?></a></td>
|
||||
<td><?php echo $val['hyproxy_http_s'];?></td>
|
||||
<td><?php echo $val['hyproxy_type'];?></td>
|
||||
<td><?php echo !empty($val['hyproxy_size']) ? $val['hyproxy_size'] : 0;?></td>
|
||||
<td><?php echo $val['hyproxy_time'];?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="7" class="object_list_last">
|
||||
<form action="" method="POST" onsubmit="return cache_delete_submit()">
|
||||
删除当前搜索结果(缓存索引&缓存文件) <?php echo $hyproxy_cache_list['sum'];?> 项
|
||||
<button type="submit" class="primary button" id="cache_delete_button"> 确认删除</button>
|
||||
<input type="hidden" name="post_delete" value="y"/>
|
||||
<input type="hidden" value="<?php echo $_GET['cache_type'];?>" name="cache_type"/>
|
||||
<input type="hidden" value="<?php echo $_GET['cache_key'];?>" name="cache_key"/>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="page_list">总<?php echo $total_page;?>页 - <?php echo $hyproxy_cache_list['sum'];?>记录 » 页码 <?php echo htmlspecialchars_decode($page_list);?> </div>
|
||||
<button type="button" class="primary button" onclick="WindowLocation('/index.php?c=hyproxy&a=hyproxy_cache_del')"><span class="home icon"></span> 返回列表</button>
|
||||
|
||||
<div id="notice_message" style="width:880px;">
|
||||
<h3>» SSH HYProxy 缓存删除</h3>
|
||||
cache-delete: 缓存删除 (ssh命令: amh module HYProxy-1.0 admin cache-delete,url-param,file-type)<br />
|
||||
cache-delete 参数说明: <br />
|
||||
<ul>
|
||||
<li>url-param: 网址匹配参数,可使用%通配符进行匹配删除。预设参数值有: -all (使用-all即匹配所有网址)</li>
|
||||
<li>file-type: 缓存文件类型匹配参数,可匹配text/html、image/gif等相关文件类型进行删除。预设参数值有: -all (使用-all即匹配所有文件类型)</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php include('footer.php'); ?>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
<?php include('header.php'); ?>
|
||||
<style>
|
||||
#STable td.object_list {
|
||||
background:url("View/images/Listbj01.gif") repeat-x scroll left top white;
|
||||
padding:20px;
|
||||
}
|
||||
#STable td.object_list_last {
|
||||
background:url("View/images/Listbj.gif") repeat-x scroll left top white;
|
||||
padding:8px;
|
||||
text-align:right;
|
||||
line-height:18px;
|
||||
color:#607993;
|
||||
}
|
||||
#STable td.object_list_last font{
|
||||
font-size:14px;
|
||||
}
|
||||
#STable td.object_name, #STable th.object_name {
|
||||
text-align:left;
|
||||
padding-left:22px;
|
||||
}
|
||||
#STable .Object_list {
|
||||
width:930px;
|
||||
background:none;
|
||||
border:1px solid #E7E7E7;
|
||||
}
|
||||
#STable .Object_list td {
|
||||
border-bottom:1px solid #E0E0E0;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
var cache_index_submit = function ()
|
||||
{
|
||||
G('cache_index_button').innerHTML = '创建索引中…';
|
||||
G('cache_index_button').disabled = true;
|
||||
}
|
||||
</script>
|
||||
<div id="body">
|
||||
<?php include('hyproxy_category.php'); ?>
|
||||
|
||||
<?php
|
||||
if (!empty($notice)) echo '<div style="margin:5px 2px;width:500px;"><p id="' . $status . '">' . $notice . '</p></div>';
|
||||
?>
|
||||
<p>反代缓存索引:</p>
|
||||
<table border="0" cellspacing="1" id="STable" style="width:720px;">
|
||||
<tr>
|
||||
<th>索引域名</th>
|
||||
<th>总缓存数量</th>
|
||||
<th>总使用空间</th>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$host_sum = 0;
|
||||
$file_sum = 0;
|
||||
$file_size = 0;
|
||||
foreach ($hyproxy_cache_index as $key=>$val)
|
||||
{
|
||||
$file_sum += $val['all']['sum'];
|
||||
$file_size += $val['all']['size'];
|
||||
++$host_sum;
|
||||
?>
|
||||
<tr>
|
||||
<td><a href="http://<?php echo $key;?>" class="button" target="_blank"><span class="home icon"></span>主页</a> <?php echo $key;?></td>
|
||||
<td style="padding:8px">总缓存文件 <b><?php echo $val['all']['sum'];?></b> 个</td>
|
||||
<td>总使用空间 <b><?php echo $val['all']['size'];?></b> MB</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3" class="object_list">
|
||||
<table border="0" cellspacing="0" id="STable" style="width:580px;" class="Object_list">
|
||||
<tr>
|
||||
<th class="object_name">缓存文件类型</th>
|
||||
<th>缓存数量</th>
|
||||
<th>使用空间</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($val as $k=>$v)
|
||||
{
|
||||
if($k != 'all')
|
||||
{
|
||||
?>
|
||||
<tr>
|
||||
<td class="object_name"><?php echo $k;?></td>
|
||||
<td style="padding:8px">缓存文件 <b><?php echo $v['sum'];?></b> 个</td>
|
||||
<td>使用空间 <b><?php echo $v['size'];?></b> MB</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="3" class="object_list_last"><font>共索引域名 <b><?php echo $host_sum;?></b> 个: </font>
|
||||
全部缓存文件 <b><?php echo $file_sum;?></b> 个 /
|
||||
全部缓存文件已用 <b><?php echo $file_size;?></b> MB</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br /><br />
|
||||
<form action="./index.php?c=hyproxy&a=hyproxy_cache_index" method="POST" id="cache_index_form" onsubmit="return cache_index_submit()">
|
||||
<p>建立缓存索引:</p>
|
||||
<table border="0" cellspacing="1" id="STable" style="width:560px;">
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>时间单位</th>
|
||||
<th>时间范围</th>
|
||||
<th>使用模式</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type="text" name="cache_index_time_val" class="input_text" value="<?php echo isset($_POST['cache_index_time_val']) ? $_POST['cache_index_time_val'] : 2;?>" style="width:50px;"/></td>
|
||||
<td><select name="cache_index_time_type" id="cache_index_time_type" style="width:110px;">
|
||||
<option value="1">天</option>
|
||||
<option value="2">小时</option>
|
||||
<option value="3">分钟</option>
|
||||
</select>
|
||||
<script>
|
||||
G('cache_index_time_type').value = '<?php echo isset($_POST['cache_index_time_type']) ? $_POST['cache_index_time_type'] : 1;?>';
|
||||
</script>
|
||||
</td>
|
||||
<td><select name="cache_index_time_area" id="cache_index_time_area" style="width:110px;">
|
||||
<option value="1">之内</option>
|
||||
<option value="2">之外</option>
|
||||
</select>
|
||||
<script>
|
||||
G('cache_index_time_area').value = '<?php echo isset($_POST['cache_index_time_area']) ? $_POST['cache_index_time_area'] : 1;?>';
|
||||
</script>
|
||||
</td>
|
||||
<td><select name="cache_index_time_mode" id="cache_index_time_mode" style="width:110px;">
|
||||
<option value="1">更新与追加</option>
|
||||
<option value="2">清空后重建</option>
|
||||
</select>
|
||||
<script>
|
||||
G('cache_index_time_mode').value = '<?php echo isset($_POST['cache_index_time_mode']) ? $_POST['cache_index_time_mode'] : 1;?>';
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<input type="hidden" name="post_submit" value="y"/>
|
||||
<button type="submit" class="primary button" id="cache_index_button"><span class="check icon"></span>建立索引</button>
|
||||
</form>
|
||||
|
||||
|
||||
<div id="notice_message" style="width:880px;">
|
||||
<h3>» SSH HYProxy 缓存索引</h3>
|
||||
cache-index: 设置缓存 (ssh命令: amh module HYProxy-1.0 admin cache-index,cmin,mode)<br />
|
||||
cache-index 参数说明: <br />
|
||||
<ul>
|
||||
<li>cmin: 索引缓存文件使用的时间,单位为分钟。可使用:+分钟 / -分钟</li>
|
||||
<li>+分钟: 索引N分钟之前的缓存数据。</li>
|
||||
<li>-分钟: 索引N分钟之内的缓存数据。</li>
|
||||
<li>mode: 索引数据模式,可选参数。可用值:truncate (清空模式,清空旧索引数据后再建立索引)
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php include('footer.php'); ?>
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php !defined('_Amysql') && exit; ?>
|
||||
<style>
|
||||
#HYProxy_list input.input_text {
|
||||
width: 292px;
|
||||
}
|
||||
#HYProxy_list textarea {
|
||||
display:inline;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
if(!WindowLocation){
|
||||
var WindowLocation = function (url){
|
||||
window.location = url;
|
||||
}
|
||||
var WindowOpen = function (url){
|
||||
window.open(url);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<h2>AMH » HYProxy</h2>
|
||||
<div id="category">
|
||||
<a href="index.php?c=hyproxy&a=hyproxy_list" id="hyproxy_list" >反代列表</a>
|
||||
<a href="index.php?c=hyproxy&a=hyproxy_cache" id="hyproxy_cache">缓存设置</a>
|
||||
<a href="index.php?c=hyproxy&a=hyproxy_cache_index" id="hyproxy_cache_index">缓存索引</a>
|
||||
<a href="index.php?c=hyproxy&a=hyproxy_cache_del" id="hyproxy_cache_del">缓存删除</a>
|
||||
<script>
|
||||
var action = '<?php echo $_GET['a'];?>';
|
||||
var action_dom = G(action) ? G(action) : G('hyproxy_list');
|
||||
action_dom.className = 'activ';
|
||||
</script>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
<?php include('header.php'); ?>
|
||||
<!-- 载入面板头部文件 -->
|
||||
|
||||
<div id="body">
|
||||
<?php include('hyproxy_category.php'); ?>
|
||||
<?php
|
||||
if (!empty($notice)) echo '<div style="margin:5px 2px;width:500px;"><p id="' . $status . '">' . $notice . '</p></div>';
|
||||
?>
|
||||
<p>HYProxy反向代理:</p>
|
||||
<div id="HYProxy_list">
|
||||
<table border="0" cellspacing="1" id="STable" style="width:850px;">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>域名</th>
|
||||
<th>最后修改</th>
|
||||
<th>管理</th>
|
||||
</tr>
|
||||
<?php
|
||||
if(!is_array($hyproxy_list) || count($hyproxy_list) < 1)
|
||||
{
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="4" style="padding:10px;">暂无绑定域名。</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($hyproxy_list as $key=>$val)
|
||||
{
|
||||
?>
|
||||
<tr>
|
||||
<th class="i"><?php echo $val['hyproxy_id'];?></th>
|
||||
<td><a href="http://<?php echo $val['server_name'];?>" target="_blank"><?php echo $val['server_name'];?></a></td>
|
||||
<td><?php echo date("Y-m-d H:i:s", $val['time']);?></td>
|
||||
<td><a href="index.php?c=hyproxy&run=<?php echo $val['server_name'];?>&g=<?php echo $val['status'] != 'stop' ? 'stop' : 'start';?>" > <span <?php echo $val['status'] != 'stop' ? 'class="run_start"' : 'class="run_stop"';?>><?php echo $val['status'] != 'stop' ? '运行中' : '已停止' ;?></span> </a> <a href="index.php?c=hyproxy&run_cache=<?php echo $val['server_name'];?>&g=<?php echo $val['proxy_cache'] != '0' ? '0' : '1';?>" > <span <?php echo $val['proxy_cache'] != '0' ? 'class="run_start"' : 'class="run_stop"';?>><?php echo $val['proxy_cache'] != '0' ? '有缓存' : '没缓存' ;?></span> </a> <a href="./index.php?c=hyproxy&admin=<?php echo $val['server_name'];?>" class="button"><span class="cog icon"></span> 管理</a> <a href="./index.php?c=hyproxy&del=<?php echo $val['server_name'];?>" class="button" onClick="return confirm('确认删除域名:<?php echo $val['server_name'];?>?');"><span class="cross icon"></span> 删除</a> </td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<button type="button" class="primary button" onClick="WindowLocation('/index.php?c=hyproxy')"><span class="home icon"></span> 返回列表</button>
|
||||
<br />
|
||||
<!-------------------------------------------------------------------------------------------------------->
|
||||
<?php if (isset($_GET['admin'])) { ?>
|
||||
<br />
|
||||
<form action="./index.php?c=hyproxy&admin=<?php echo $_GET['admin'];?>" method="POST" >
|
||||
<p>编辑反向代理网站:</p>
|
||||
<table border="0" cellspacing="1" id="STable" style="width:720px;">
|
||||
<tr>
|
||||
<th>名称</th>
|
||||
<th>值</th>
|
||||
<th>说明</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>绑定域名</td>
|
||||
<td><input type="text" name="" class="input_text disabled" disabled="" value="<?php echo $hyproxy_get['server_name'];?>" />
|
||||
<input type="hidden" name="server_name" value="<?php echo $hyproxy_get['server_name'];?>" />
|
||||
<font class="red">*</font></td>
|
||||
<td>绑定的域名,不需加 http://
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: amysql.com)</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>默认首页</td>
|
||||
<td><input type="text" name="index" class="input_text" value="<?php echo $hyproxy_get['index'];?>" />
|
||||
<input type="hidden" name="index_hidden" value="<?php echo $hyproxy_get['index'];?>" />
|
||||
<font class="red">*</font></td>
|
||||
<td>默认首页文件,用半角空格隔开
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: index.php index.html index.htm)</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>后端域名</td>
|
||||
<td><input type="text" name="header_host" class="input_text" value="<?php echo $hyproxy_get['header_host'];?>" />
|
||||
<font class="red">*</font>
|
||||
<input type="hidden" name="header_host_hidden" class="input_text" value="<?php echo $hyproxy_get['header_host'];?>" />
|
||||
</td>
|
||||
<td>被反代的域名;$host为nginx变量,等于绑定的域名.
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: nginx.org)</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>后端地址</td>
|
||||
<td><input type="text" name="proxy_pass" class="input_text" value="<?php echo $hyproxy_get['proxy_pass'];?>" />
|
||||
<font class="red">*</font>
|
||||
<input type="hidden" name="proxy_pass_hidden" class="input_text" value="<?php echo $hyproxy_get['proxy_pass'];?>" />
|
||||
</td>
|
||||
<td>被反代的IP地址或域名
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: http://123.123.123.123:8888)</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="3" style="padding:10px;text-align:left;"> <button type="submit" class="primary button" name="edit"><span class="check icon"></span>保存</button>
|
||||
<a href="./index.php?c=hyproxy">取消返回</a> </th>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php }else { ?>
|
||||
<!-------------------------------------------------------------------------------------------------------->
|
||||
<br />
|
||||
<form action="./index.php?c=hyproxy" method="POST" >
|
||||
<p>新增HYProxy反向代理网站:</p>
|
||||
<table border="0" cellspacing="1" id="STable" style="width:660px;">
|
||||
<tr>
|
||||
<th>名称</th>
|
||||
<th>值</th>
|
||||
<th>说明</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>绑定域名</td>
|
||||
<td><input type="text" name="server_name" class="input_text" />
|
||||
<font class="red">*</font></td>
|
||||
<td>绑定的域名,不需加 http://
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: amysql.com)</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>后端地址</td>
|
||||
<td><input type="text" name="proxy_pass" class="input_text" />
|
||||
<font class="red">*</font></td>
|
||||
<td>被反代的IP地址或域名
|
||||
<div style="font-size:11px;color:#848484;margin:5px;">(e.g: http://123.123.123.123:8888)</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="3" style="padding:10px;text-align:left;"> <button type="submit" class="primary button" name="submit"><span class="check icon"></span>保存</button></th>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div id="notice_message" style="width:880px;">
|
||||
<h3>» SSH HYProxy</h3>
|
||||
1) 有步骤提示操作: <br />
|
||||
ssh执行命令: amh module HYProxy-1.0<br />
|
||||
然后选择对应的操作选项进行管理。<br />
|
||||
<br />
|
||||
2) 或直接操作: <br />
|
||||
<ul>
|
||||
<li>HYProxy管理: amh module HYProxy-1.0 [info / install / admin / uninstall / status]</li>
|
||||
</ul>
|
||||
3) HYProxy admin管理选项说明: <br />
|
||||
执行 amh module HYProxy-1.0 admin 提示输入管理参数(例如, list、add,amysql.com,nginx.org等),可以不输入直接回车显示下面选项菜单。
|
||||
<ul>
|
||||
<li>list: 列出反向代理网站列表 (ssh命令: amh module HYProxy-1.0 admin list)</li>
|
||||
<li>make: 生成反向代理网站conf (ssh命令: amh module HYProxy-1.0 admin make,amysql.com)生成amysql.com的conf。不填域名生成所有</li>
|
||||
<li>add: 新增反向代理网站 (ssh命令: amh module HYProxy-1.0 admin add,amysql.com,nginx.org) amysql,com为绑定域名,nginx.org为反代域名。</li>
|
||||
<li>start: 启动反向代理网站 (ssh命令: amh module HYProxy-1.0 admin start,amysql.com) 启动amysql.com反代网站。</li>
|
||||
<li>stop: 停止反向代理网站 (ssh命令: amh module HYProxy-1.0 admin stop,amysql.com) 停止amysql.com反代网站。</li>
|
||||
<li>edit: 编辑反向代理网站 (ssh命令: amh module HYProxy-1.0 admin edit,amysql.com,参数名,参数值,参数值...) amysql.com为绑定域名,<br />
|
||||
其它参数名与值可参考提示使用。</li>
|
||||
<li>del: 删除反向代理网站 (ssh命令: amh module HYProxy-1.0 admin del,amysql.com) 删除绑定amysql.com反代网站。</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include('footer.php'); ?>
|
||||
<!-- 载入面板底部文件 -->
|
||||
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
/*
|
||||
* HYPorxy CLI 文件
|
||||
* 依赖PDO 、InnoDB
|
||||
* 需要安装PDO_MYSQL-1.0.2插件
|
||||
* 需要打开InnoDB支持
|
||||
*/
|
||||
if (PHP_SAPI !== "cli") {
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header("status: 404 Not Found");
|
||||
die();
|
||||
}
|
||||
define ('AMH_ROOT', '/home/wwwroot/index/web' . DIRECTORY_SEPARATOR); // AHM根目录
|
||||
define ('AMH_Amysql', AMH_ROOT . 'Amysql' . DIRECTORY_SEPARATOR); // 系统目录
|
||||
define ('_HYProxy', dirname(__FILE__) . DIRECTORY_SEPARATOR); // HYProxy插件根目录
|
||||
define ('_HYCONF', '/usr/local/nginx/conf/hyproxy' . DIRECTORY_SEPARATOR); // HY Nginx conf目录
|
||||
|
||||
require_once(AMH_Amysql . 'Config.php'); //加载配置参数
|
||||
require_once(_HYProxy . 'Class/medoo.php'); //加载medoo数据库类库
|
||||
|
||||
$HYConfig = array(
|
||||
'database_type' => 'mysql',
|
||||
'database_name' => $Config['DBname'],
|
||||
'server' => 'localhost',
|
||||
'username' => $Config['User'],
|
||||
'password' => $Config['Password'],
|
||||
'charset' => 'utf8'
|
||||
);
|
||||
$medoo = new medoo($HYConfig);
|
||||
|
||||
$opt = array(
|
||||
'action:',
|
||||
'proxy_status::',//状态
|
||||
'server_name::',//域名
|
||||
'proxy_pass::',//后端
|
||||
'field_name::',//字段名
|
||||
'value::',//字段内容
|
||||
);
|
||||
$param = getopt('', $opt);
|
||||
//print_r($param);
|
||||
switch ($param['action']) {
|
||||
case 'list':
|
||||
echo hyproxy_list($param['proxy_status']);
|
||||
break;
|
||||
case 'make':
|
||||
echo hyproxy_make($param['server_name']);
|
||||
break;
|
||||
case 'add':
|
||||
echo hyproxy_add($param['server_name'],$param['proxy_pass']);
|
||||
break;
|
||||
case 'edit':
|
||||
echo hyproxy_edit($param['server_name'],$param['field_name'],$param['value']);
|
||||
break;
|
||||
case 'del':
|
||||
echo hyproxy_del($param['server_name']);
|
||||
break;
|
||||
default:
|
||||
echo 'error action';
|
||||
}
|
||||
|
||||
function hyproxy_list($proxy_status){//done 列出站点列表ID,域名,状态
|
||||
global $medoo;
|
||||
empty($proxy_status) && $proxy_status = 'start';
|
||||
|
||||
$table = 'module_hyproxy';
|
||||
$columns = array('hyproxy_id','server_name','status');
|
||||
$where = array('status'=>$proxy_status);
|
||||
$data = $medoo->select($table,$columns,$where);
|
||||
$res = '';
|
||||
foreach ($data as &$value) {
|
||||
$res.=sprintf("%d,%s,%s\n",$value['hyproxy_id'],$value['server_name'],$value['status']);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function hyproxy_make($server_name){//done
|
||||
global $medoo;
|
||||
$table = 'module_hyproxy';
|
||||
$columns = '*';
|
||||
$where = '';
|
||||
if (!empty($server_name)) {//指定域名
|
||||
$where = array('server_name'=>trim($server_name));
|
||||
}
|
||||
$data = $medoo->select($table,$columns,$where);
|
||||
$res = '';
|
||||
if (empty($data)) {
|
||||
$res = "[ERROR] The server_name does not exist.\n";
|
||||
} else {
|
||||
if (empty($server_name)) {
|
||||
hy_deldir(_HYCONF);//删除所有
|
||||
}
|
||||
foreach ($data as &$value) {
|
||||
if (!empty($value['proxy_cache'])) {
|
||||
$nginx = sprintf('server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name %s;
|
||||
index %s;
|
||||
|
||||
location / {
|
||||
default_type text/html;
|
||||
proxy_cache hyproxy;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host %s;
|
||||
proxy_pass %s;
|
||||
if ($http_Cache_Control = "no-cache") {
|
||||
rewrite ^(.*)$ /purge$1 last;
|
||||
}
|
||||
}
|
||||
|
||||
location ~ /purge(/.*){
|
||||
proxy_cache_purge hyproxy $scheme://$host$1$is_args$args;
|
||||
}
|
||||
}',$value['server_name'],$value['index'],$value['header_host'],$value['proxy_pass']);
|
||||
} else {
|
||||
$nginx = sprintf('server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name %s;
|
||||
index %s;
|
||||
|
||||
location / {
|
||||
default_type text/html;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host %s;
|
||||
proxy_pass %s;
|
||||
}
|
||||
}',$value['server_name'],$value['index'],$value['header_host'],$value['proxy_pass']);
|
||||
}
|
||||
if ($value['status']=='start') {
|
||||
$filebytes = file_put_contents(_HYCONF.$value['server_name'].'.conf', $nginx); //写入内容
|
||||
} else {
|
||||
$filebytes = unlink(_HYCONF.$value['server_name'].'.conf');//删除
|
||||
}
|
||||
|
||||
if($filebytes){
|
||||
$res.=sprintf("[OK] %s conf make is done.\n",$value['server_name']);
|
||||
}else{
|
||||
$res.=sprintf("[ERROR] %s conf make is error.\n",$value['server_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function hyproxy_add($server_name,$proxy_pass=''){//done
|
||||
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] The server_name 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] Proxy add success.\n";
|
||||
$res.= hyproxy_make($server_name);
|
||||
}else {
|
||||
$res = "[ERROR] Proxy add error.\n";
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function hyproxy_edit($server_name,$field_name='',$value=''){//done
|
||||
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] The server_name is 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] Proxy edit success.\n";
|
||||
$res.= hyproxy_make($server_name);
|
||||
}else {
|
||||
$res = "[ERROR] Proxy edit error.\n";
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function hyproxy_del($server_name){
|
||||
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 (empty($proxy)) {
|
||||
return "[ERROR] The server_name is not exist.\n";//不存在
|
||||
} else {
|
||||
$mysqlres = $medoo->delete($table, $where);
|
||||
if ($mysqlres) {
|
||||
$res = "[OK] Proxy del success.\n";
|
||||
}else {
|
||||
$res = "[ERROR] Proxy del error.\n";
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function hy_deldir($path) {
|
||||
//如果是目录则继续
|
||||
if (is_dir($path)) {
|
||||
//扫描一个文件夹内的所有文件夹和文件并返回数组
|
||||
$p = scandir($path);
|
||||
foreach ($p as $val) {
|
||||
//排除目录中的.和..
|
||||
if ($val != "." && $val != "..") {
|
||||
//如果是目录则递归子目录,继续操作
|
||||
if (is_dir($path . $val)) {
|
||||
//子目录中操作删除文件夹和文件
|
||||
deldir($path . $val . '/');
|
||||
//目录清空后删除空文件夹
|
||||
@rmdir($path . $val . '/');
|
||||
} else {
|
||||
//如果是文件直接删除
|
||||
unlink($path . $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
use amh;
|
||||
CREATE TABLE IF NOT EXISTS `module_hyproxy` (
|
||||
`hyproxy_id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`server_name` varchar(255) NOT NULL,
|
||||
`index` varchar(255) NOT NULL,
|
||||
`header_host` varchar(255) NOT NULL,
|
||||
`proxy_pass` varchar(255) NOT NULL,
|
||||
`proxy_cache` int(1) NOT NULL,
|
||||
`status` varchar(16) NOT NULL,
|
||||
`time` int(10) NOT NULL,
|
||||
PRIMARY KEY (`hyproxy_id`),
|
||||
UNIQUE KEY `server_name` (`server_name`),
|
||||
KEY `proxy_pass` (`proxy_pass`),
|
||||
KEY `status` (`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `module_hyproxy_cache` (
|
||||
`hyproxy_id` int(10) NOT NULL AUTO_INCREMENT,
|
||||
`hyproxy_file` varchar(45) NOT NULL,
|
||||
`hyproxy_key` varchar(300) NOT NULL,
|
||||
`hyproxy_http_s` varchar(5) NOT NULL,
|
||||
`hyproxy_type` varchar(30) NOT NULL,
|
||||
`hyproxy_size` varchar(10) NOT NULL,
|
||||
`hyproxy_time` datetime NOT NULL,
|
||||
PRIMARY KEY (`hyproxy_id`),
|
||||
UNIQUE KEY `file` (`hyproxy_file`),
|
||||
KEY `key` (`hyproxy_key`),
|
||||
KEY `http_s` (`hyproxy_http_s`),
|
||||
KEY `type` (`hyproxy_type`),
|
||||
KEY `size` (`hyproxy_size`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
||||
Loading…
Reference in New Issue