commit 3eeefe4eff3d6241defa545de36f9eb61b3a2879 Author: HITSword Date: Tue Jan 7 17:39:37 2020 +0800 初始化版本 Signed-off-by: HITSword diff --git a/AMHScript b/AMHScript new file mode 100644 index 0000000..dc87c85 --- /dev/null +++ b/AMHScript @@ -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.*
|Nginx 1.14.0
|" /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; +} diff --git a/Class/medoo.php b/Class/medoo.php new file mode 100644 index 0000000..129f193 --- /dev/null +++ b/Class/medoo.php @@ -0,0 +1,1115 @@ + $value) + { + $this->$option = $value; + } + } + else + { + return false; + } + + if ( + isset($this->port) && + is_int($this->port * 1) + ) + { + $port = $this->port; + } + + $type = strtolower($this->database_type); + $is_port = isset($port); + + if (isset($options[ 'prefix' ])) + { + $this->prefix = $options[ 'prefix' ]; + } + + switch ($type) + { + case 'mariadb': + $type = 'mysql'; + + case 'mysql': + if ($this->socket) + { + $dsn = $type . ':unix_socket=' . $this->socket . ';dbname=' . $this->database_name; + } + else + { + $dsn = $type . ':host=' . $this->server . ($is_port ? ';port=' . $port : '') . ';dbname=' . $this->database_name; + } + + // Make MySQL using standard quoted identifier + $commands[] = 'SET SQL_MODE=ANSI_QUOTES'; + break; + + case 'pgsql': + $dsn = $type . ':host=' . $this->server . ($is_port ? ';port=' . $port : '') . ';dbname=' . $this->database_name; + break; + + case 'sybase': + $dsn = 'dblib:host=' . $this->server . ($is_port ? ':' . $port : '') . ';dbname=' . $this->database_name; + break; + + case 'oracle': + $dbname = $this->server ? + '//' . $this->server . ($is_port ? ':' . $port : ':1521') . '/' . $this->database_name : + $this->database_name; + + $dsn = 'oci:dbname=' . $dbname . ($this->charset ? ';charset=' . $this->charset : ''); + break; + + case 'mssql': + $dsn = strstr(PHP_OS, 'WIN') ? + 'sqlsrv:server=' . $this->server . ($is_port ? ',' . $port : '') . ';database=' . $this->database_name : + 'dblib:host=' . $this->server . ($is_port ? ':' . $port : '') . ';dbname=' . $this->database_name; + + // Keep MSSQL QUOTED_IDENTIFIER is ON for standard quoting + $commands[] = 'SET QUOTED_IDENTIFIER ON'; + break; + + case 'sqlite': + $dsn = $type . ':' . $this->database_file; + $this->username = null; + $this->password = null; + break; + } + + if ( + in_array($type, array('mariadb', 'mysql', 'pgsql', 'sybase', 'mssql')) && + $this->charset + ) + { + $commands[] = "SET NAMES '" . $this->charset . "'"; + } + + $this->pdo = new PDO( + $dsn, + $this->username, + $this->password, + $this->option + ); + + foreach ($commands as $value) + { + $this->pdo->exec($value); + } + } + catch (PDOException $e) { + throw new Exception($e->getMessage()); + } + } + + public function query($query) + { + if ($this->debug_mode) + { + echo $query; + + $this->debug_mode = false; + + return false; + } + + $this->logs[] = $query; + + return $this->pdo->query($query); + } + + public function exec($query) + { + if ($this->debug_mode) + { + echo $query; + + $this->debug_mode = false; + + return false; + } + + $this->logs[] = $query; + + return $this->pdo->exec($query); + } + + public function quote($string) + { + return $this->pdo->quote($string); + } + + protected function table_quote($table) + { + return '"' . $this->prefix . $table . '"'; + } + + protected function column_quote($string) + { + preg_match('/(\(JSON\)\s*|^#)?([a-zA-Z0-9_]*)\.([a-zA-Z0-9_]*)/', $string, $column_match); + + if (isset($column_match[ 2 ], $column_match[ 3 ])) + { + return '"' . $this->prefix . $column_match[ 2 ] . '"."' . $column_match[ 3 ] . '"'; + } + + return '"' . $string . '"'; + } + + protected function column_push(&$columns) + { + if ($columns == '*') + { + return $columns; + } + + if (is_string($columns)) + { + $columns = array($columns); + } + + $stack = array(); + + foreach ($columns as $key => $value) + { + if (is_array($value)) + { + $stack[] = $this->column_push($value); + } + else + { + preg_match('/([a-zA-Z0-9_\-\.]*)\s*\(([a-zA-Z0-9_\-]*)\)/i', $value, $match); + + if (isset($match[ 1 ], $match[ 2 ])) + { + $stack[] = $this->column_quote( $match[ 1 ] ) . ' AS ' . $this->column_quote( $match[ 2 ] ); + + $columns[ $key ] = $match[ 2 ]; + } + else + { + $stack[] = $this->column_quote( $value ); + } + } + } + + return implode($stack, ','); + } + + protected function array_quote($array) + { + $temp = array(); + + foreach ($array as $value) + { + $temp[] = is_int($value) ? $value : $this->pdo->quote($value); + } + + return implode($temp, ','); + } + + protected function inner_conjunct($data, $conjunctor, $outer_conjunctor) + { + $haystack = array(); + + foreach ($data as $value) + { + $haystack[] = '(' . $this->data_implode($value, $conjunctor) . ')'; + } + + return implode($outer_conjunctor . ' ', $haystack); + } + + protected function fn_quote($column, $string) + { + return (strpos($column, '#') === 0 && preg_match('/^[A-Z0-9\_]*\([^)]*\)$/', $string)) ? + + $string : + + $this->quote($string); + } + + protected function data_implode($data, $conjunctor, $outer_conjunctor = null) + { + $wheres = array(); + + foreach ($data as $key => $value) + { + $type = gettype($value); + + if ( + preg_match("/^(AND|OR)(\s+#.*)?$/i", $key, $relation_match) && + $type == 'array' + ) + { + $wheres[] = 0 !== count(array_diff_key($value, array_keys(array_keys($value)))) ? + '(' . $this->data_implode($value, ' ' . $relation_match[ 1 ]) . ')' : + '(' . $this->inner_conjunct($value, ' ' . $relation_match[ 1 ], $conjunctor) . ')'; + } + else + { + preg_match('/(#?)([\w\.\-]+)(\[(\>|\>\=|\<|\<\=|\!|\<\>|\>\<|\!?~)\])?/i', $key, $match); + $column = $this->column_quote($match[ 2 ]); + + if (isset($match[ 4 ])) + { + $operator = $match[ 4 ]; + + if ($operator == '!') + { + switch ($type) + { + case 'NULL': + $wheres[] = $column . ' IS NOT NULL'; + break; + + case 'array': + $wheres[] = $column . ' NOT IN (' . $this->array_quote($value) . ')'; + break; + + case 'integer': + case 'double': + $wheres[] = $column . ' != ' . $value; + break; + + case 'boolean': + $wheres[] = $column . ' != ' . ($value ? '1' : '0'); + break; + + case 'string': + $wheres[] = $column . ' != ' . $this->fn_quote($key, $value); + break; + } + } + + if ($operator == '<>' || $operator == '><') + { + if ($type == 'array') + { + if ($operator == '><') + { + $column .= ' NOT'; + } + + if (is_numeric($value[ 0 ]) && is_numeric($value[ 1 ])) + { + $wheres[] = '(' . $column . ' BETWEEN ' . $value[ 0 ] . ' AND ' . $value[ 1 ] . ')'; + } + else + { + $wheres[] = '(' . $column . ' BETWEEN ' . $this->quote($value[ 0 ]) . ' AND ' . $this->quote($value[ 1 ]) . ')'; + } + } + } + + if ($operator == '~' || $operator == '!~') + { + if ($type != 'array') + { + $value = array($value); + } + + $like_clauses = array(); + + foreach ($value as $item) + { + $item = strval($item); + $suffix = mb_substr($item, -1, 1); + + if (preg_match('/^(?!(%|\[|_])).+(?fn_quote($key, $item); + } + + $wheres[] = implode(' OR ', $like_clauses); + } + + if (in_array($operator, array('>', '>=', '<', '<='))) + { + if (is_numeric($value)) + { + $wheres[] = $column . ' ' . $operator . ' ' . $value; + } + elseif (strpos($key, '#') === 0) + { + $wheres[] = $column . ' ' . $operator . ' ' . $this->fn_quote($key, $value); + } + else + { + $wheres[] = $column . ' ' . $operator . ' ' . $this->quote($value); + } + } + } + else + { + switch ($type) + { + case 'NULL': + $wheres[] = $column . ' IS NULL'; + break; + + case 'array': + $wheres[] = $column . ' IN (' . $this->array_quote($value) . ')'; + break; + + case 'integer': + case 'double': + $wheres[] = $column . ' = ' . $value; + break; + + case 'boolean': + $wheres[] = $column . ' = ' . ($value ? '1' : '0'); + break; + + case 'string': + $wheres[] = $column . ' = ' . $this->fn_quote($key, $value); + break; + } + } + } + } + + return implode($conjunctor . ' ', $wheres); + } + + protected function where_clause($where) + { + $where_clause = ''; + + if (is_array($where)) + { + $where_keys = array_keys($where); + $where_AND = preg_grep("/^AND\s*#?$/i", $where_keys); + $where_OR = preg_grep("/^OR\s*#?$/i", $where_keys); + + $single_condition = array_diff_key($where, array_flip( + array('AND', 'OR', 'GROUP', 'ORDER', 'HAVING', 'LIMIT', 'LIKE', 'MATCH') + )); + + if ($single_condition != array()) + { + $condition = $this->data_implode($single_condition, ''); + + if ($condition != '') + { + $where_clause = ' WHERE ' . $condition; + } + } + + if (!empty($where_AND)) + { + $value = array_values($where_AND); + $where_clause = ' WHERE ' . $this->data_implode($where[ $value[ 0 ] ], ' AND'); + } + + if (!empty($where_OR)) + { + $value = array_values($where_OR); + $where_clause = ' WHERE ' . $this->data_implode($where[ $value[ 0 ] ], ' OR'); + } + + if (isset($where[ 'MATCH' ])) + { + $MATCH = $where[ 'MATCH' ]; + + if (is_array($MATCH) && isset($MATCH[ 'columns' ], $MATCH[ 'keyword' ])) + { + $where_clause .= ($where_clause != '' ? ' AND ' : ' WHERE ') . ' MATCH ("' . str_replace('.', '"."', implode($MATCH[ 'columns' ], '", "')) . '") AGAINST (' . $this->quote($MATCH[ 'keyword' ]) . ')'; + } + } + + if (isset($where[ 'GROUP' ])) + { + $where_clause .= ' GROUP BY ' . $this->column_quote($where[ 'GROUP' ]); + + if (isset($where[ 'HAVING' ])) + { + $where_clause .= ' HAVING ' . $this->data_implode($where[ 'HAVING' ], ' AND'); + } + } + + if (isset($where[ 'ORDER' ])) + { + $ORDER = $where[ 'ORDER' ]; + + if (is_array($ORDER)) + { + $stack = array(); + + foreach ($ORDER as $column => $value) + { + if (is_array($value)) + { + $stack[] = 'FIELD(' . $this->column_quote($column) . ', ' . $this->array_quote($value) . ')'; + } + else if ($value === 'ASC' || $value === 'DESC') + { + $stack[] = $this->column_quote($column) . ' ' . $value; + } + else if (is_int($column)) + { + $stack[] = $this->column_quote($value); + } + } + + $where_clause .= ' ORDER BY ' . implode($stack, ','); + } + else + { + $where_clause .= ' ORDER BY ' . $this->column_quote($ORDER); + } + } + + if (isset($where[ 'LIMIT' ])) + { + $LIMIT = $where[ 'LIMIT' ]; + + if (is_numeric($LIMIT)) + { + $where_clause .= ' LIMIT ' . $LIMIT; + } + + if ( + is_array($LIMIT) && + is_numeric($LIMIT[ 0 ]) && + is_numeric($LIMIT[ 1 ]) + ) + { + if ($this->database_type === 'pgsql') + { + $where_clause .= ' OFFSET ' . $LIMIT[ 0 ] . ' LIMIT ' . $LIMIT[ 1 ]; + } + else + { + $where_clause .= ' LIMIT ' . $LIMIT[ 0 ] . ',' . $LIMIT[ 1 ]; + } + } + } + } + else + { + if ($where != null) + { + $where_clause .= ' ' . $where; + } + } + + return $where_clause; + } + + protected function select_context($table, $join, &$columns = null, $where = null, $column_fn = null) + { + preg_match('/([a-zA-Z0-9_\-]*)\s*\(([a-zA-Z0-9_\-]*)\)/i', $table, $table_match); + + if (isset($table_match[ 1 ], $table_match[ 2 ])) + { + $table = $this->table_quote($table_match[ 1 ]); + + $table_query = $this->table_quote($table_match[ 1 ]) . ' AS ' . $this->table_quote($table_match[ 2 ]); + } + else + { + $table = $this->table_quote($table); + + $table_query = $table; + } + + $join_key = is_array($join) ? array_keys($join) : null; + + if ( + isset($join_key[ 0 ]) && + strpos($join_key[ 0 ], '[') === 0 + ) + { + $table_join = array(); + + $join_array = array( + '>' => 'LEFT', + '<' => 'RIGHT', + '<>' => 'FULL', + '><' => 'INNER' + ); + + foreach($join as $sub_table => $relation) + { + preg_match('/(\[(\<|\>|\>\<|\<\>)\])?([a-zA-Z0-9_\-]*)\s?(\(([a-zA-Z0-9_\-]*)\))?/', $sub_table, $match); + + if ($match[ 2 ] != '' && $match[ 3 ] != '') + { + if (is_string($relation)) + { + $relation = 'USING ("' . $relation . '")'; + } + + if (is_array($relation)) + { + // For ['column1', 'column2'] + if (isset($relation[ 0 ])) + { + $relation = 'USING ("' . implode($relation, '", "') . '")'; + } + else + { + $joins = array(); + + foreach ($relation as $key => $value) + { + $joins[] = ( + strpos($key, '.') > 0 ? + // For ['tableB.column' => 'column'] + $this->column_quote($key) : + + // For ['column1' => 'column2'] + $table . '."' . $key . '"' + ) . + ' = ' . + $this->table_quote(isset($match[ 5 ]) ? $match[ 5 ] : $match[ 3 ]) . '."' . $value . '"'; + } + + $relation = 'ON ' . implode($joins, ' AND '); + } + } + + $table_name = $this->table_quote($match[ 3 ]) . ' '; + + if (isset($match[ 5 ])) + { + $table_name .= 'AS ' . $this->table_quote($match[ 5 ]) . ' '; + } + + $table_join[] = $join_array[ $match[ 2 ] ] . ' JOIN ' . $table_name . $relation; + } + } + + $table_query .= ' ' . implode($table_join, ' '); + } + else + { + if (is_null($columns)) + { + if (is_null($where)) + { + if ( + is_array($join) && + isset($column_fn) + ) + { + $where = $join; + $columns = null; + } + else + { + $where = null; + $columns = $join; + } + } + else + { + $where = $join; + $columns = null; + } + } + else + { + $where = $columns; + $columns = $join; + } + } + + if (isset($column_fn)) + { + if ($column_fn == 1) + { + $column = '1'; + + if (is_null($where)) + { + $where = $columns; + } + } + else + { + if (empty($columns)) + { + $columns = '*'; + $where = $join; + } + + $column = $column_fn . '(' . $this->column_push($columns) . ')'; + } + } + else + { + $column = $this->column_push($columns); + } + + return 'SELECT ' . $column . ' FROM ' . $table_query . $this->where_clause($where); + } + + protected function data_map($index, $key, $value, $data, &$stack) + { + if (is_array($value)) + { + $sub_stack = array(); + + foreach ($value as $sub_key => $sub_value) + { + if (is_array($sub_value)) + { + $current_stack = $stack[ $index ][ $key ]; + + $this->data_map(false, $sub_key, $sub_value, $data, $current_stack); + + $stack[ $index ][ $key ][ $sub_key ] = $current_stack[ 0 ][ $sub_key ]; + } + else + { + $this->data_map(false, preg_replace('/^[\w]*\./i', "", $sub_value), $sub_key, $data, $sub_stack); + + $stack[ $index ][ $key ] = $sub_stack; + } + } + } + else + { + if ($index !== false) + { + $stack[ $index ][ $value ] = $data[ $value ]; + } + else + { + $stack[ $key ] = $data[ $key ]; + } + } + } + + public function select($table, $join, $columns = null, $where = null) + { + $column = $where == null ? $join : $columns; + + $is_single_column = (is_string($column) && $column !== '*'); + + $query = $this->query($this->select_context($table, $join, $columns, $where)); + + $stack = array(); + + $index = 0; + + if (!$query) + { + return false; + } + + if ($columns === '*') + { + return $query->fetchAll(PDO::FETCH_ASSOC); + } + + if ($is_single_column) + { + return $query->fetchAll(PDO::FETCH_COLUMN); + } + + while ($row = $query->fetch(PDO::FETCH_ASSOC)) + { + foreach ($columns as $key => $value) + { + if (is_array($value)) + { + $this->data_map($index, $key, $value, $row, $stack); + } + else + { + $this->data_map($index, $key, preg_replace('/^[\w]*\./i', "", $value), $row, $stack); + } + } + + $index++; + } + + return $stack; + } + + public function insert($table, $datas) + { + $lastId = array(); + + // Check indexed or associative array + if (!isset($datas[ 0 ])) + { + $datas = array($datas); + } + + foreach ($datas as $data) + { + $values = array(); + $columns = array(); + + foreach ($data as $key => $value) + { + $columns[] = preg_replace("/^(\(JSON\)\s*|#)/i", "", $key); + + switch (gettype($value)) + { + case 'NULL': + $values[] = 'NULL'; + break; + + case 'array': + preg_match("/\(JSON\)\s*([\w]+)/i", $key, $column_match); + + $values[] = isset($column_match[ 0 ]) ? + $this->quote(json_encode($value)) : + $this->quote(serialize($value)); + break; + + case 'boolean': + $values[] = ($value ? '1' : '0'); + break; + + case 'integer': + case 'double': + case 'string': + $values[] = $this->fn_quote($key, $value); + break; + } + } + + $this->exec('INSERT INTO ' . $this->table_quote($table) . ' (' . implode(', ', $columns) . ') VALUES (' . implode($values, ', ') . ')'); + + $lastId[] = $this->pdo->lastInsertId(); + } + + return count($lastId) > 1 ? $lastId : $lastId[ 0 ]; + } + + public function update($table, $data, $where = null) + { + $fields = array(); + + foreach ($data as $key => $value) + { + preg_match('/([\w]+)(\[(\+|\-|\*|\/)\])?/i', $key, $match); + + if (isset($match[ 3 ])) + { + if (is_numeric($value)) + { + $fields[] = $this->column_quote($match[ 1 ]) . ' = ' . $this->column_quote($match[ 1 ]) . ' ' . $match[ 3 ] . ' ' . $value; + } + } + else + { + $column = $this->column_quote(preg_replace("/^(\(JSON\)\s*|#)/i", "", $key)); + + switch (gettype($value)) + { + case 'NULL': + $fields[] = $column . ' = NULL'; + break; + + case 'array': + preg_match("/\(JSON\)\s*([\w]+)/i", $key, $column_match); + + $fields[] = $column . ' = ' . $this->quote( + isset($column_match[ 0 ]) ? json_encode($value) : serialize($value) + ); + break; + + case 'boolean': + $fields[] = $column . ' = ' . ($value ? '1' : '0'); + break; + + case 'integer': + case 'double': + case 'string': + $fields[] = $column . ' = ' . $this->fn_quote($key, $value); + break; + } + } + } + + return $this->exec('UPDATE ' . $this->table_quote($table) . ' SET ' . implode(', ', $fields) . $this->where_clause($where)); + } + + public function delete($table, $where) + { + return $this->exec('DELETE FROM ' . $this->table_quote($table) . $this->where_clause($where)); + } + + public function replace($table, $columns, $search = null, $replace = null, $where = null) + { + if (is_array($columns)) + { + $replace_query = array(); + + foreach ($columns as $column => $replacements) + { + foreach ($replacements as $replace_search => $replace_replacement) + { + $replace_query[] = $column . ' = REPLACE(' . $this->column_quote($column) . ', ' . $this->quote($replace_search) . ', ' . $this->quote($replace_replacement) . ')'; + } + } + + $replace_query = implode(', ', $replace_query); + $where = $search; + } + else + { + if (is_array($search)) + { + $replace_query = array(); + + foreach ($search as $replace_search => $replace_replacement) + { + $replace_query[] = $columns . ' = REPLACE(' . $this->column_quote($columns) . ', ' . $this->quote($replace_search) . ', ' . $this->quote($replace_replacement) . ')'; + } + + $replace_query = implode(', ', $replace_query); + $where = $replace; + } + else + { + $replace_query = $columns . ' = REPLACE(' . $this->column_quote($columns) . ', ' . $this->quote($search) . ', ' . $this->quote($replace) . ')'; + } + } + + return $this->exec('UPDATE ' . $this->table_quote($table) . ' SET ' . $replace_query . $this->where_clause($where)); + } + + public function get($table, $join = null, $columns = null, $where = null) + { + $column = $where == null ? $join : $columns; + + $is_single_column = (is_string($column) && $column !== '*'); + + $query = $this->query($this->select_context($table, $join, $columns, $where) . ' LIMIT 1'); + + if ($query) + { + $data = $query->fetchAll(PDO::FETCH_ASSOC); + + if (isset($data[ 0 ])) + { + if ($is_single_column) + { + return $data[ 0 ][ preg_replace('/^[\w]*\./i', "", $column) ]; + } + + if ($column === '*') + { + return $data[ 0 ]; + } + + $stack = array(); + + foreach ($columns as $key => $value) + { + if (is_array($value)) + { + $this->data_map(0, $key, $value, $data[ 0 ], $stack); + } + else + { + $this->data_map(0, $key, preg_replace('/^[\w]*\./i', "", $value), $data[ 0 ], $stack); + } + } + + return $stack[ 0 ]; + } + else + { + return false; + } + } + else + { + return false; + } + } + + public function has($table, $join, $where = null) + { + $column = null; + + $query = $this->query('SELECT EXISTS(' . $this->select_context($table, $join, $column, $where, 1) . ')'); + + if ($query) + { + return $query->fetchColumn() === '1'; + } + else + { + return false; + } + } + + public function count($table, $join = null, $column = null, $where = null) + { + $query = $this->query($this->select_context($table, $join, $column, $where, 'COUNT')); + + return $query ? 0 + $query->fetchColumn() : false; + } + + public function max($table, $join, $column = null, $where = null) + { + $query = $this->query($this->select_context($table, $join, $column, $where, 'MAX')); + + if ($query) + { + $max = $query->fetchColumn(); + + return is_numeric($max) ? $max + 0 : $max; + } + else + { + return false; + } + } + + public function min($table, $join, $column = null, $where = null) + { + $query = $this->query($this->select_context($table, $join, $column, $where, 'MIN')); + + if ($query) + { + $min = $query->fetchColumn(); + + return is_numeric($min) ? $min + 0 : $min; + } + else + { + return false; + } + } + + public function avg($table, $join, $column = null, $where = null) + { + $query = $this->query($this->select_context($table, $join, $column, $where, 'AVG')); + + return $query ? 0 + $query->fetchColumn() : false; + } + + public function sum($table, $join, $column = null, $where = null) + { + $query = $this->query($this->select_context($table, $join, $column, $where, 'SUM')); + + return $query ? 0 + $query->fetchColumn() : false; + } + + public function action($actions) + { + if (is_callable($actions)) + { + $this->pdo->beginTransaction(); + + $result = $actions($this); + + if ($result === false) + { + $this->pdo->rollBack(); + } + else + { + $this->pdo->commit(); + } + } + else + { + return false; + } + } + + public function debug() + { + $this->debug_mode = true; + + return $this; + } + + public function error() + { + return $this->pdo->errorInfo(); + } + + public function last_query() + { + return end($this->logs); + } + + public function log() + { + return $this->logs; + } + + public function info() + { + $output = array( + 'server' => 'SERVER_INFO', + 'driver' => 'DRIVER_NAME', + 'client' => 'CLIENT_VERSION', + 'version' => 'SERVER_VERSION', + 'connection' => 'CONNECTION_STATUS' + ); + + foreach ($output as $key => $value) + { + $output[ $key ] = $this->pdo->getAttribute(constant('PDO::ATTR_' . $value)); + } + + return $output; + } +} +?> \ No newline at end of file diff --git a/Controller/hyproxy.php b/Controller/hyproxy.php new file mode 100644 index 0000000..5d6d5d6 --- /dev/null +++ b/Controller/hyproxy.php @@ -0,0 +1,209 @@ + 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'); + } + +} \ No newline at end of file diff --git a/Model/hyproxys.php b/Model/hyproxys.php new file mode 100644 index 0000000..c3c02b4 --- /dev/null +++ b/Model/hyproxys.php @@ -0,0 +1,238 @@ + _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 diff --git a/View/hyproxy_cache.php b/View/hyproxy_cache.php new file mode 100644 index 0000000..e4177e8 --- /dev/null +++ b/View/hyproxy_cache.php @@ -0,0 +1,91 @@ + +
+ + +

' . $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 new file mode 100644 index 0000000..6d1448d --- /dev/null +++ b/View/hyproxy_cache_del.php @@ -0,0 +1,161 @@ + + + +
+ + +

' . $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 new file mode 100644 index 0000000..3330588 --- /dev/null +++ b/View/hyproxy_cache_index.php @@ -0,0 +1,163 @@ + + + +
+ + +

' . $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 new file mode 100644 index 0000000..15dd40c --- /dev/null +++ b/View/hyproxy_category.php @@ -0,0 +1,31 @@ + + + +

AMH » HYProxy

+
+ 反代列表 + 缓存设置 + 缓存索引 + 缓存删除 + +
\ No newline at end of file diff --git a/View/hyproxy_list.php b/View/hyproxy_list.php new file mode 100644 index 0000000..115d74f --- /dev/null +++ b/View/hyproxy_list.php @@ -0,0 +1,154 @@ + + + +
+ +

' . $notice . '

'; +?> +

HYProxy反向代理:

+
+ + + + + + + + + + + + $val) + { + ?> + + + + + + + +
ID域名最后修改管理
暂无绑定域名。
> > 管理 删除
+ +
+ + +
+
+

编辑反向代理网站:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
名称说明
绑定域名 + + *绑定的域名,不需加 http:// +
(e.g: amysql.com)
默认首页 + + *默认首页文件,用半角空格隔开 +
(e.g: index.php index.html index.htm)
后端域名 + * + + 被反代的域名;$host为nginx变量,等于绑定的域名. +
(e.g: nginx.org)
后端地址 + * + + 被反代的IP地址或域名 +
(e.g: http://123.123.123.123:8888)
+ 取消返回
+
+ + +
+
+

新增HYProxy反向代理网站:

+ + + + + + + + + + + + + + + + + + + +
名称说明
绑定域名 + *绑定的域名,不需加 http:// +
(e.g: amysql.com)
后端地址 + *被反代的IP地址或域名 +
(e.g: http://123.123.123.123:8888)
+
+
+ +
+

» SSH HYProxy

+ 1) 有步骤提示操作:
+ ssh执行命令: amh module HYProxy-1.0
+ 然后选择对应的操作选项进行管理。
+
+ 2) 或直接操作:
+
    +
  • HYProxy管理: amh module HYProxy-1.0 [info / install / admin / uninstall / status]
  • +
+ 3) HYProxy admin管理选项说明:
+ 执行 amh module HYProxy-1.0 admin 提示输入管理参数(例如, list、add,amysql.com,nginx.org等),可以不输入直接回车显示下面选项菜单。 +
    +
  • list: 列出反向代理网站列表 (ssh命令: amh module HYProxy-1.0 admin list)
  • +
  • make: 生成反向代理网站conf (ssh命令: amh module HYProxy-1.0 admin make,amysql.com)生成amysql.com的conf。不填域名生成所有
  • +
  • add: 新增反向代理网站 (ssh命令: amh module HYProxy-1.0 admin add,amysql.com,nginx.org) amysql,com为绑定域名,nginx.org为反代域名。
  • +
  • start: 启动反向代理网站 (ssh命令: amh module HYProxy-1.0 admin start,amysql.com) 启动amysql.com反代网站。
  • +
  • stop: 停止反向代理网站 (ssh命令: amh module HYProxy-1.0 admin stop,amysql.com) 停止amysql.com反代网站。
  • +
  • edit: 编辑反向代理网站 (ssh命令: amh module HYProxy-1.0 admin edit,amysql.com,参数名,参数值,参数值...) amysql.com为绑定域名,
    + 其它参数名与值可参考提示使用。
  • +
  • del: 删除反向代理网站 (ssh命令: amh module HYProxy-1.0 admin del,amysql.com) 删除绑定amysql.com反代网站。
  • +
+
+ + + + diff --git a/hyproxy-cli.php b/hyproxy-cli.php new file mode 100644 index 0000000..9f44b7a --- /dev/null +++ b/hyproxy-cli.php @@ -0,0 +1,274 @@ + '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); + } + } + } + } +} \ No newline at end of file diff --git a/hyproxy.sql b/hyproxy.sql new file mode 100644 index 0000000..8bad5b4 --- /dev/null +++ b/hyproxy.sql @@ -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 ; \ No newline at end of file