Signed-off-by: HITSword <admin@huayizhiyun.com>
master
HITSword 2020-01-17 17:50:39 +08:00
parent 083a5d8d65
commit d8e7f8d5d7
2 changed files with 88 additions and 2 deletions

View File

@ -24,7 +24,8 @@ function amh_module_install()
echo '[Error] HYProxy 未安装.'; echo '[Error] HYProxy 未安装.';
exit; exit;
fi; fi;
touch ./InstallComplete cd /root/amh/modules/AMProxy-2.0;
touch ./InstallComplete;
amh_module_status; amh_module_status;
fi; fi;
} }
@ -58,7 +59,7 @@ function amh_module_admin()
case $action in case $action in
list) list)
echo "list something"; php ${module_dir}cli.php --action='list';
;; ;;
start) start)
echo "start something"; echo "start something";

85
cli.php 100644
View File

@ -0,0 +1,85 @@
<?php
/**
* AMPorxy CLI 文件
* 依赖HYProxy-1.0插件
*/
if (PHP_SAPI !== "cli") {
header('HTTP/1.1 404 Not Found');
header("status: 404 Not Found");
die();
}
define('DS', DIRECTORY_SEPARATOR); // 目录分隔符
define('AMH_ROOT', '/home/wwwroot/index/web' . DS); // AHM根目录
define('AMH_AMYSQL', AMH_ROOT . 'Amysql' . DS); // 系统目录
define('_HYPROXY', dirname(__FILE__). '/../HYProxy-1.0' . DS); // HYProxy插件根目录
define('_HYCONF', '/usr/local/nginx/conf/hyproxy' . DS); // HYProxy Nginx conf目录
define('_HYLOGS', '/home/hyproxy_logs' . DS); // HYProxy Nginx logs目录
define('_HYBAKS', '/home/hyproxy_backup' . DS); // HYProxy Backup目录
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::',//字段内容
'bak_name::',//备份名称
);
$param = getopt('', $opt);
switch ($param['action']) {
case 'list':
echo amproxy_list($param['proxy_status']);
break;
case 'add':
//echo amproxy_add($param['server_name'], $param['proxy_pass']);
break;
case 'edit':
//echo amproxy_edit($param['server_name'], $param['field_name'], $param['value']);
break;
case 'del':
//echo amproxy_del($param['server_name']);
break;
default:
echo '无效操作';
}
/**
* 【完成】
* 反向代理列表
* @param $proxy_status = start,stop
* @return string
*/
function amproxy_list($proxy_status = null)
{
global $medoo;
$table = 'module_hyproxy';
$columns = array('server_name','status');
$where = !empty($proxy_status) ? array('status'=>$proxy_status) : '';
$where['ORDER'] = "status";
$list = $medoo->select($table, $columns, $where);
$res = '';
foreach ($list as $row) {
$status = '[Stop]';
if ($row['status']=='start') {
$status = '[Running]';
}
$res.=sprintf("%s %s\n", $row['server_name'], $status);
}
return $res;
}