diff --git a/app/controller/Api.php b/app/controller/Api.php
index 30128d5..1044606 100644
--- a/app/controller/Api.php
+++ b/app/controller/Api.php
@@ -197,6 +197,28 @@ class Api extends BaseController
return json($data);
}
+ //宝塔云监控获取最新版本
+ public function btm_latest_version(){
+ $data = [
+ 'version' => config_get('new_version_btm'),
+ 'description' => config_get('update_msg_btm'),
+ 'create_time' => config_get('update_date_btm')
+ ];
+ return json($data);
+ }
+
+ //宝塔云监控更新日志
+ public function btm_update_history(){
+ $data = [
+ [
+ 'version' => config_get('new_version_btm'),
+ 'description' => config_get('update_msg_btm'),
+ 'create_time' => config_get('update_date_btm')
+ ]
+ ];
+ return json($data);
+ }
+
//获取内测版更新日志
public function get_beta_logs(){
return json(['beta_ps'=>'当前暂无内测版', 'list'=>[]]);
@@ -259,11 +281,37 @@ class Api extends BaseController
//绑定账号
public function get_auth_token(){
- $userinfo = ['uid'=>1, 'username'=>'Administrator', 'address'=>'127.0.0.1', 'serverid'=>'1', 'access_key'=>random(32), 'secret_key'=>random(48), 'ukey'=>md5(time()), 'state'=>1];
+ if(!$_POST['data']) return json(['status'=>false, 'msg'=>'参数不能为空']);
+ $reqData = hex2bin($_POST['data']);
+ parse_str($reqData, $arr);
+ $serverid = $arr['serverid'];
+ $userinfo = ['uid'=>1, 'username'=>'Administrator', 'address'=>'127.0.0.1', 'serverid'=>$serverid, 'access_key'=>random(32), 'secret_key'=>random(48), 'ukey'=>md5(time()), 'state'=>1];
$data = bin2hex(urlencode(json_encode($userinfo)));
return json(['status'=>true, 'msg'=>'登录成功!', 'data'=>$data]);
}
+ //绑定账号新
+ public function authorization_login(){
+ if(!$_POST['data']) return json(['status'=>false, 'msg'=>'参数不能为空']);
+ $reqData = hex2bin($_POST['data']);
+ parse_str($reqData, $arr);
+ $serverid = $arr['serverid'];
+ $userinfo = ['uid'=>1, 'username'=>'Administrator', 'ip'=>'127.0.0.1', 'server_id'=>$serverid, 'access_key'=>random(32), 'secret_key'=>random(48)];
+ $data = bin2hex(urlencode(json_encode($userinfo)));
+ return json(['status'=>true, 'msg'=>'登录成功!', 'data'=>$data]);
+ }
+
+ //刷新授权信息
+ public function authorization_info(){
+ if(!$_POST['data']) return json(['status'=>false, 'msg'=>'参数不能为空']);
+ $reqData = hex2bin($_POST['data']);
+ parse_str($reqData, $arr);
+ $id = isset($arr['id'])&&$arr['id']>0?$arr['id']:1;
+ $userinfo = ['id'=>$id, 'product'=>$arr['product'], 'status'=>2, 'clients'=>9999, 'durations'=>0, 'end_time'=>strtotime('+10 year')];
+ $data = bin2hex(urlencode(json_encode($userinfo)));
+ return json(['status'=>true, 'data'=>$data]);
+ }
+
//一键部署列表
public function get_deplist(){
$os = input('post.os');
diff --git a/app/script/convert.sh b/app/script/convert.sh
index d8cd684..d4a6057 100644
--- a/app/script/convert.sh
+++ b/app/script/convert.sh
@@ -2,6 +2,7 @@
Linux_Version="7.9.7"
Windows_Version="7.8.0"
+Btm_Version="1.0.11"
FILES=(
public/install/src/panel6.zip
@@ -13,6 +14,9 @@ public/win/install/panel_update.py
public/win/panel/panel_${Windows_Version}.zip
public/win/panel/data/api.py
public/win/panel/data/setup.py
+public/install/src/bt-monitor-${Btm_Version}.zip
+public/install/install_btmonitor.sh
+public/install/update_btmonitor.sh
)
DIR=$1
diff --git a/app/view/admin/set.html b/app/view/admin/set.html
index 592c93d..96ee497 100644
--- a/app/view/admin/set.html
+++ b/app/view/admin/set.html
@@ -48,6 +48,19 @@
用于检测更新接口返回
+
+
+
+ 用于一键更新脚本获取最新版本号,以及检测更新接口。并确保已在/public/install/src/放置对应版本更新包
+
+
+
+
+
+
+
+
+
diff --git a/app/view/index/download.html b/app/view/index/download.html
index c68f3e4..0995a6f 100644
--- a/app/view/index/download.html
+++ b/app/view/index/download.html
@@ -50,7 +50,7 @@
Windows面板 {:config_get('new_version_win')}
-
支持Windows Server 2008 R2/2012/2016/2019,64位系统
+
支持Windows Server 2008 R2/2012/2016/2019/2022,64位系统
操作简单
使用方便
@@ -62,6 +62,22 @@
+ {if config_get('new_version_btm')}
+
+
+

+
+
+
+
{/if}
@@ -105,7 +121,7 @@
-
+
Windows面板{:config_get('new_version_win')}安装方法
@@ -121,10 +137,40 @@
-
注意:仅支持Windows Server 2008 R2/2012/2016/2019,64位系统(中文简体),且未安装其它环境
+
注意:仅支持Windows Server 2008 R2/2012/2016/2019/2022,64位系统(中文简体),且未安装其它环境
+ {if config_get('new_version_btm')}
+
+
+
+
堡塔云监控{:config_get('new_version_btm')}安装脚本
+
+
+ 使用 SSH 连接工具,如
+
PUTTY
+ 连接到您的 Linux 服务器后,根据系统执行相应命令开始安装:
+
+
+
堡塔云监控安装脚本
+
+
curl -sS {$siteurl}/install/install_btmonitor.sh -o /tmp/install_btmonitor.sh && bash /tmp/install_btmonitor.sh
+
复制
+
+
+
+
堡塔云监控更新脚本
+
+
curl {$siteurl}/install/update_btmonitor.sh|bash
+
复制
+
+
+
+
注意:推荐使用Chrome、火狐、edge浏览器,国产浏览器(极速模式)
+
+
+
{/if}
@@ -140,7 +186,7 @@
- Copyright © 2022 宝塔面板安装脚本
+ Copyright © {:date('Y')} 宝塔面板安装脚本
@@ -186,6 +232,10 @@
scrollTop('#instal-cloud');
});
+ $('#goInstallMonitor').click(function () {
+ scrollTop('#instal-monitor');
+ });
+
function GetRequest() {
var url = location.search;
//获取url中"?"符后的字串
diff --git a/install.sql b/install.sql
index a908d65..a778cc2 100644
--- a/install.sql
+++ b/install.sql
@@ -18,6 +18,9 @@ INSERT INTO `cloud_config` (`key`, `value`) VALUES
('new_version_win', '7.8.0'),
('update_msg_win', '暂无更新日志'),
('update_date_win', '2022-12-08'),
+('new_version_btm', '1.0.11'),
+('update_msg_btm', '暂无更新日志'),
+('update_date_btm', '2022-12-06'),
('updateall_type', '0'),
('syskey', 'UqP94LtI8eWAIgCP');
diff --git a/public/install/install_btmonitor.sh b/public/install/install_btmonitor.sh
new file mode 100644
index 0000000..0cdf2ae
--- /dev/null
+++ b/public/install/install_btmonitor.sh
@@ -0,0 +1,747 @@
+#!/bin/bash
+#########################
+
+# 广东堡塔安全技术有限公司
+# author: 赤井秀一
+# mail: 1021266737@qq.com
+
+#########################
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
+export PATH
+LANG=en_US.UTF-8
+
+Btapi_Url='http://www.example.com'
+
+Command_Exists() {
+ command -v "$@" >/dev/null 2>&1
+}
+
+monitor_path="/www/server/bt-monitor"
+run_bin="/www/server/bt-monitor/BT-MONITOR"
+if [ ! -d "/www/server" ];then
+ mkdir -p /www/server
+fi
+old_dir="/www/server/old_btmonitor"
+
+cd ~
+setup_path="/www"
+python_bin=$setup_path/server/bt-monitor/pyenv/bin/python
+cpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l)
+
+GetSysInfo(){
+ if [ -s "/etc/redhat-release" ];then
+ SYS_VERSION=$(cat /etc/redhat-release)
+ elif [ -s "/etc/issue" ]; then
+ SYS_VERSION=$(cat /etc/issue)
+ fi
+ SYS_INFO=$(uname -a)
+ SYS_BIT=$(getconf LONG_BIT)
+ MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
+ CPU_INFO=$(getconf _NPROCESSORS_ONLN)
+
+ echo -e ${SYS_VERSION}
+ echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
+ echo -e ${SYS_INFO}
+ echo -e "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
+}
+
+Red_Error(){
+ echo '=================================================';
+ printf '\033[1;31;40m%b\033[0m\n' "$@";
+ GetSysInfo
+ exit 1;
+}
+
+get_node_url(){
+ if [ ! -f /bin/curl ];then
+ if [ "${PM}" = "yum" ]; then
+ yum install curl -y
+ elif [ "${PM}" = "apt-get" ]; then
+ apt-get install curl -y
+ fi
+ fi
+
+ if [ -f "/www/node.pl" ];then
+ download_Url=$(cat /www/node.pl)
+ echo "Download node: $download_Url";
+ echo '---------------------------------------------';
+ return
+ fi
+
+ echo '---------------------------------------------';
+ echo "Selected download node...";
+ # nodes=(http://dg2.bt.cn http://dg1.bt.cn http://125.90.93.52:5880 http://36.133.1.8:5880 http://123.129.198.197 http://38.34.185.130 http://116.213.43.206:5880 http://128.1.164.196);
+ nodes=(http://dg2.bt.cn http://dg1.bt.cn http://125.90.93.52:5880 http://36.133.1.8:5880 http://123.129.198.197 http://116.213.43.206:5880 http://128.1.164.196);
+ tmp_file1=/dev/shm/net_test1.pl
+ tmp_file2=/dev/shm/net_test2.pl
+ [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
+ [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
+ touch $tmp_file1
+ touch $tmp_file2
+ for node in ${nodes[@]};
+ do
+ NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
+ RES=$(echo ${NODE_CHECK}|awk '{print $1}')
+ NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $2}')
+ TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $3 * 1000 - 500 }'|cut -d '.' -f 1)
+ if [ "${NODE_STATUS}" == "200" ];then
+ if [ $TIME_TOTAL -lt 100 ];then
+ if [ $RES -ge 1500 ];then
+ echo "$RES $node" >> $tmp_file1
+ fi
+ else
+ if [ $RES -ge 1500 ];then
+ echo "$TIME_TOTAL $node" >> $tmp_file2
+ fi
+ fi
+
+ i=$(($i+1))
+ if [ $TIME_TOTAL -lt 100 ];then
+ if [ $RES -ge 3000 ];then
+ break;
+ fi
+ fi
+ fi
+ done
+
+ NODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')
+ if [ -z "$NODE_URL" ];then
+ NODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')
+ if [ -z "$NODE_URL" ];then
+ NODE_URL='http://download.bt.cn';
+ fi
+ fi
+ rm -f $tmp_file1
+ rm -f $tmp_file2
+ download_Url=$NODE_URL
+ echo "Download node: $download_Url";
+ echo '---------------------------------------------';
+}
+
+Get_Versions(){
+ redhat_version_file="/etc/redhat-release"
+ deb_version_file="/etc/issue"
+ if [ -f $redhat_version_file ];then
+ os_type='el'
+ is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
+ if [ "$is_aliyunos" != "" ];then
+ return
+ fi
+ os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
+ if [ "${os_version}" = "5" ];then
+ os_version=""
+ fi
+ if [ -z "${os_version}" ];then
+ os_version=$(cat /etc/redhat-release |grep Stream|grep -oE 8)
+ fi
+ else
+ os_type='ubuntu'
+ os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
+ if [ "${os_version}" = "" ];then
+ os_type='debian'
+ os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
+ if [ "${os_version}" = "" ];then
+ os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
+ fi
+ if [ "${os_version}" = "8" ];then
+ os_version=""
+ fi
+ if [ "${is64bit}" = '32' ];then
+ os_version=""
+ fi
+ else
+ if [ "$os_version" = "14" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "12" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "19" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "21" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "20" ];then
+ os_version2004=$(cat /etc/issue|grep 20.04)
+ if [ -z "${os_version2004}" ];then
+ os_version=""
+ fi
+ fi
+ fi
+ fi
+}
+
+Install_Python_Lib(){
+ curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
+ pyenv_path="/www/server/bt-monitor"
+ if [ -f $pyenv_path/pyenv/bin/python ];then
+ is_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot)
+ $pyenv_path/pyenv/bin/python3.7 -V
+ if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then
+ chmod -R 700 $pyenv_path/pyenv/bin
+ is_package=$($python_bin -m psutil 2>&1|grep package)
+ if [ "$is_package" = "" ];then
+ wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -t 5 -T 10
+ $pyenv_path/pyenv/bin/pip install -U pip
+ $pyenv_path/pyenv/bin/pip install -U setuptools
+ $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
+ $pyenv_path/pyenv/bin/pip install -U flask==2.2.0
+ $pyenv_path/pyenv/bin/pip install flask_sock
+ $pyenv_path/pyenv/bin/pip install cachelib
+ $pyenv_path/pyenv/bin/pip install py7zr
+ $pyenv_path/pyenv/bin/pip install backports.lzma
+ fi
+ source $pyenv_path/pyenv/bin/activate
+ chmod -R 700 $pyenv_path/pyenv/bin
+ return
+ else
+ rm -rf $pyenv_path/pyenv
+ fi
+ fi
+
+ py_version="3.7.9"
+ if [ ! -d "$pyenv_path" ]; then
+ mkdir -p $pyenv_path
+ fi
+ echo "True" > /www/disk.pl
+ if [ ! -w /www/disk.pl ];then
+ Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!"
+ fi
+ os_type='el'
+ os_version='7'
+ is_export_openssl=0
+ Get_Versions
+
+ echo "OS: $os_type - $os_version"
+ is_aarch64=$(uname -a|grep aarch64)
+ if [ "$is_aarch64" != "" ];then
+ is64bit="aarch64"
+ fi
+
+ if [ -f "/www/server/bt-monitor/pymake.pl" ];then
+ os_version=""
+ rm -f /www/server/bt-monitor/pymake.pl
+ fi
+
+ if [[ $os_type =~ "debian" ]] || [[ $os_type =~ "ubuntu" ]]; then
+ isbtm="-btm"
+ fi
+
+ if [ "${os_version}" != "" ];then
+ pyenv_file="/www/pyenv.tar.gz"
+ wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}${isbtm}.tar.gz -t 5 -T 10
+ tmp_size=$(du -b $pyenv_file|awk '{print $1}')
+ if [ $tmp_size -lt 703460 ];then
+ rm -f $pyenv_file
+ echo "ERROR: Download python env fielded."
+ else
+ echo "Install python env..."
+ tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
+ chmod -R 700 $pyenv_path/pyenv/bin
+ rm -rf $pyenv_path/pyenv/bin/python
+ ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
+ $pyenv_path/pyenv/bin/python -m pip install --upgrade --force-reinstall pip
+ $pyenv_path/pyenv/bin/pip install -U flask==2.2.0
+ $pyenv_path/pyenv/bin/pip install flask_sock
+ $pyenv_path/pyenv/bin/pip install cachelib
+ $pyenv_path/pyenv/bin/pip install py7zr
+ $pyenv_path/pyenv/bin/pip install backports.lzma
+ if [ ! -f $pyenv_path/pyenv/bin/python ];then
+ rm -f $pyenv_file
+ Red_Error "ERROR: Install python env fielded." "ERROR: 下载堡塔云监控运行环境失败,请尝试重新安装!"
+ fi
+ $pyenv_path/pyenv/bin/python3.7 -V
+ if [ $? -eq 0 ];then
+ rm -f $pyenv_file
+ ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btmpip
+ ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btmpython
+ source $pyenv_path/pyenv/bin/activate
+ return
+ else
+ rm -f $pyenv_file
+ rm -rf $pyenv_path/pyenv
+ fi
+ fi
+ fi
+
+ cd /www
+ python_src='/www/python_src.tar.xz'
+ python_src_path="/www/Python-${py_version}"
+ wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -t 5 -T 10
+ tmp_size=$(du -b $python_src|awk '{print $1}')
+ if [ $tmp_size -lt 10703460 ];then
+ rm -f $python_src
+ Red_Error "ERROR: Download python source code fielded." "ERROR: 下载堡塔云监控运行环境失败,请尝试重新安装!"
+ fi
+ tar xvf $python_src
+ rm -f $python_src
+ cd $python_src_path
+ ./configure --prefix=$pyenv_path/pyenv
+ make -j$cpu_cpunt
+ make install
+ if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
+ rm -rf $python_src_path
+ Red_Error "ERROR: Make python env fielded." "ERROR: 编译堡塔云监控运行环境失败!"
+ fi
+ cd ~
+ rm -rf $python_src_path
+ wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -t 5 -T 10
+ wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -t 5 -T 10
+ ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
+ ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
+ ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btmpip
+ ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btmpython
+ chmod -R 700 $pyenv_path/pyenv/bin
+ $pyenv_path/pyenv/bin/pip install -U pip
+ $pyenv_path/pyenv/bin/pip install -U setuptools
+ $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
+ $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
+ $pyenv_path/pyenv/bin/pip install -U flask==2.2.0
+ $pyenv_path/pyenv/bin/pip install flask_sock
+ $pyenv_path/pyenv/bin/pip install cachelib
+ $pyenv_path/pyenv/bin/pip install py7zr
+ $pyenv_path/pyenv/bin/pip install backports.lzma
+ source $pyenv_path/pyenv/bin/activate
+
+ is_gevent=$($python_bin -m gevent 2>&1|grep -oE package)
+ is_psutil=$($python_bin -m psutil 2>&1|grep -oE package)
+ if [ "${is_gevent}" != "${is_psutil}" ];then
+ Red_Error "ERROR: psutil/gevent install failed!"
+ fi
+}
+
+Install_Monitor(){
+ ulimit -n 1000001
+ tee -a /etc/security/limits.conf << EOF
+* hard nofile 1000001
+* soft nofile 1000001
+root hard nofile 1000001
+root soft nofile 1000001
+EOF
+ sysctl -p
+ panelPort="806"
+
+ if [ ! -d "/etc/init.d" ];then
+ mkdir -p /etc/init.d
+ fi
+
+ if [ -f "/etc/init.d/btm" ]; then
+ /etc/init.d/btm stop
+ sleep 1
+ fi
+
+ version="1.0.2"
+ file_name="bt-monitor"
+ agent_src="bt-monitor.zip"
+
+ cd ~
+ version=`curl -sf ${Btapi_Url}/bt_monitor/latest_version |awk -F '\"version\"' '{print $2}'|awk -F ':' '{print $2}'|awk -F '"' '{print $2}'`
+ if [ -z $version ]; then
+ version="1.0.2"
+ fi
+ if [ "$re_install" == "1" ]; then
+ new_dir="/www/server/new_btmonitor"
+ if [ ! -d "$new_dir" ];then
+ mkdir -p $new_dir
+ fi
+ wget -O $agent_src ${Btapi_Url}/install/src/$file_name-$version.zip -t 5 -T 10
+ unzip -o $agent_src -d $new_dir/ > /dev/null
+ if [ ! -f $new_dir/BT-MONITOR ];then
+ ls -lh $agent_src
+ Red_Error "ERROR: Failed to download, please try install again!" "ERROR: 下载堡塔云监控失败,请尝试重新安装!"
+ fi
+
+ rm -rf $new_dir/config
+ rm -rf $new_dir/data
+ rm -rf $new_dir/ssl
+ \cp -r $new_dir/* $monitor_path/
+ rm -rf $new_dir
+ else
+ wget -O $agent_src ${Btapi_Url}/install/src/$file_name-$version.zip -t 5 -T 10
+ if [ ! -d "$monitor_path" ]; then
+ mkdir -p $monitor_path
+ fi
+ unzip -o $agent_src -d $monitor_path/ > /dev/null
+ if [ ! -f $run_bin ];then
+ ls -lh $agent_src
+ Red_Error "ERROR: Failed to download, please try install again!" "ERROR: 下载堡塔云监控失败,请尝试重新安装!"
+ fi
+ fi
+ rm -rf $agent_src
+ chmod +x $monitor_path/BT-MONITOR
+ chmod +x $monitor_path/tools.py
+ wget -O /etc/init.d/btm ${download_Url}/init/btmonitor.init -t 5 -T 10
+ # \cp -r $monitor_path/init.sh /etc/init.d/btm
+ chmod +x /etc/init.d/btm
+ ln -sf /etc/init.d/btm /usr/bin/btm
+
+ if [ ! -f /www/server/bt-monitor/data/user.json ]; then
+ echo "{\"uid\":1,\"username\":\"Administrator\",\"ip\":\"127.0.0.1\",\"server_id\":\"1\",\"access_key\":\"test\",\"secret_key\":\"123456\"}" > /www/server/bt-monitor/data/user.json
+ fi
+}
+
+Start_Monitor(){
+ /etc/init.d/btm start
+ if [ "$?" != "0" ]; then
+ echo "堡塔云监控启动失败!"
+ tail $monitor_path/logs/error.log
+ exit 1
+ fi
+
+ echo "正在初始化云监控..."
+ if [ "$re_install" == "1" ] || [ "$re_install" == "2" ]; then
+ user_pass=`$setup_path/server/bt-monitor/tools.py reset_pwd`
+ password=`echo $user_pass |awk '{print $3}'`
+ else
+ user_pass=`$monitor_path/tools.py create_admin`
+ password=`echo $user_pass |awk -F " " '{print $5}'`
+ for ((i=1; i<=5; i++));do
+ if [ -z "$password" ]; then
+ sleep 7
+ user_pass=`$monitor_path/tools.py create_admin`
+ password=`echo $user_pass |awk -F " " '{print $5}'`
+ else
+ i=5
+ fi
+ done
+ fi
+ c_path=$(cat /www/server/bt-monitor/config/config.json |awk -F '\"admin_path\"' '{print $2}'|awk -F ":" '{print $2}'|awk -F '"' '{print $2}')
+ adminpath=$(echo $c_path|awk -F ',' '{print $1}')
+
+ if [ -d "/usr/bin/btmonitoragent" ];then
+ rm -rf /usr/bin/btmonitoragent
+ fi
+
+ date_f=`date '+%Y%m%d_%H%M%S'`
+ md5_pl=`echo $date_f | md5sum | head -c 32`
+ token_pl=`cat $monitor_path/config/token.pl 2>&1`
+ if [ "$token_pl" == ' ' ] || [ ! -f $monitor_path/config/token.pl ]; then
+ echo "$md5_pl" > $monitor_path/config/token.pl
+ fi
+
+ echo "正在给本机安装云监控被控端,请等待..."
+ sleep 20
+ curl -sSO ${download_Url}/install/btmonitoragent.sh && sh btmonitoragent.sh https://127.0.0.1:806 $md5_pl
+}
+
+Set_Firewall(){
+ sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
+ if [ "${PM}" = "apt-get" ]; then
+ apt-get install -y ufw
+ if [ -f "/usr/sbin/ufw" ];then
+ ufw allow 22/tcp
+ ufw allow ${panelPort}/tcp
+ ufw allow ${sshPort}/tcp
+ ufw_status=`ufw status`
+ echo y|ufw enable
+ ufw default deny
+ ufw reload
+ fi
+ else
+ if [ -f "/etc/init.d/iptables" ];then
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
+ iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
+ iptables -A INPUT -s localhost -d localhost -j ACCEPT
+ iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
+ iptables -P INPUT DROP
+ service iptables save
+ sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
+ iptables_status=$(service iptables status | grep 'not running')
+ if [ "${iptables_status}" == '' ];then
+ service iptables restart
+ fi
+ else
+ AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")
+ [ "${AliyunCheck}" ] && return
+ yum install firewalld -y
+ [ "${Centos8Check}" ] && yum reinstall python3-six -y
+ systemctl enable firewalld
+ systemctl start firewalld
+ firewall-cmd --set-default-zone=public > /dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1
+ firewall-cmd --reload
+ fi
+ fi
+}
+
+Service_Add(){
+ if [ $Command_Exists systemctl ]; then
+ wget -O /usr/lib/systemd/system/btm.service ${download_Url}/init/systemd/btmonitor.service -t 5 -T 10
+ systemctl daemon-reload
+ systemctl enable btm
+ else
+ if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
+ chkconfig --add btm
+ chkconfig --level 2345 btm on
+ elif [ "${PM}" == "apt-get" ]; then
+ update-rc.d btm defaults
+ fi
+ fi
+}
+
+Service_Del(){
+ if [ $Command_Exists systemctl ]; then
+ rm -rf /usr/lib/systemd/system/btm.service
+ systemctl disable btm
+ else
+ if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
+ chkconfig --del btm
+ chkconfig --level 2345 btm off
+ elif [ "${PM}" == "apt-get" ]; then
+ update-rc.d btm remove
+ fi
+ fi
+}
+
+Get_Ip_Address(){
+ getIpAddress=""
+ getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
+ if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
+ isHosts=$(cat /etc/hosts|grep 'www.bt.cn')
+ if [ -z "${isHosts}" ];then
+ echo "" >> /etc/hosts
+ echo "116.213.43.206 www.bt.cn" >> /etc/hosts
+ getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
+ if [ -z "${getIpAddress}" ];then
+ sed -i "/bt.cn/d" /etc/hosts
+ fi
+ fi
+ fi
+
+ ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
+ if [ "${ipv4Check}" == "None" ];then
+ ipv6Address=$(echo ${getIpAddress}|tr -d "[]")
+ ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
+ if [ "${ipv6Check}" == "None" ]; then
+ getIpAddress="SERVER_IP"
+ else
+ echo "True" > ${setup_path}/server/bt-monitor/data/ipv6.pl
+ sleep 1
+ /etc/init.d/btm restart
+ fi
+ fi
+
+ if [ "${getIpAddress}" != "SERVER_IP" ];then
+ echo "${getIpAddress}" > ${setup_path}/server/bt-monitor/data/iplist.txt
+ fi
+ LOCAL_IP=$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v "^127\.|^255\.|^0\." | head -n 1)
+}
+
+System_Check(){
+ if [ -f "$monitor_path/BT-MONITOR" ] || [ -f "$monitor_path/tools.py" ] || [ -f "/etc/init.d/btm" ];then
+ Install_Check
+ elif [ -d "$old_dir" ];then
+ Rev_Install_Check
+ fi
+}
+
+Install_Check(){
+ echo -e "----------------------------------------------------"
+ echo -e "检测到已存在堡塔云监控系统,请按照选项选择安装方式!"
+ echo -e "1) 覆盖安装:保存原有监控配置及数据并安装堡塔云监控"
+ echo -e "\033[33m2) 全新安装:清空原有监控配置及数据并安装堡塔云监控\033[0m"
+ echo -e "----------------------------------------------------"
+ read -p "请输入对应选项[1|2]进行安装或输入任意内容退出安装: " yes;
+ if [ "$yes" == "1" ]; then
+ re_install="1"
+ echo "即将卸载并重装本机的堡塔云监控agent端..."
+ Uninstall_agent
+ elif [ "$yes" == "2" ]; then
+ Backup_Monitor
+ echo "即将卸载并重装本机的堡塔云监控agent端..."
+ Uninstall_agent
+ else
+ echo -e "------------"
+ echo "取消安装"
+ exit;
+ fi
+}
+
+Rev_Install_Check(){
+ echo -e "----------------------------------------------------"
+ echo -e "\033[33m检测到上一次卸载云监控时保留的旧数据,请按照选项选择安装方式!\033[0m"
+ echo -e "1) 还原以前的备份并安装堡塔云监控系统!"
+ echo -e "2) 不使用原有备份,全新安装堡塔云监控系统!"
+ echo -e "----------------------------------------------------"
+ read -p "请输入对应选项[1|2]进行安装或输入任意内容退出安装: " yes;
+ if [ "$yes" == "1" ]; then
+ re_install="2"
+ echo "开始安装堡塔云监控并还原数据..."
+ elif [ "$yes" == "2" ]; then
+ echo "开始全新安装堡塔云监控..."
+ else
+ echo -e "------------"
+ echo "取消安装"
+ exit;
+ fi
+}
+
+Backup_Monitor(){
+ if [ -f "/etc/init.d/btm" ]; then
+ /etc/init.d/btm stop
+ sleep 1
+ fi
+ if [ ! -d "$old_dir" ];then
+ mkdir -p $old_dir
+ fi
+ mv $monitor_path/data $old_dir/data
+ mv $monitor_path/config $old_dir/config
+ mv $monitor_path/ssl $old_dir/ssl
+}
+
+Reinstall_Monitor(){
+ rm -rf $monitor_path/data
+ rm -rf $monitor_path/config
+ rm -rf $monitor_path/ssl
+ mv $old_dir/data $monitor_path/data
+ mv $old_dir/config $monitor_path/config
+ mv $old_dir/ssl $monitor_path/ssl
+ rm -rf $old_dir
+}
+
+is64bit=$(getconf LONG_BIT)
+if [ "${is64bit}" != '64' ];then
+ Red_Error "抱歉, 堡塔云监控不支持32位系统, 请使用64位系统!";
+fi
+
+Get_Pack_Manager(){
+ if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
+ PM="yum"
+ elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
+ PM="apt-get"
+ fi
+}
+
+Install_RPM_Pack(){
+ yumPacks="wget curl unzip gcc gcc-c++ make libcurl-devel openssl-devel xz-devel python-backports-lzma xz"
+ yum install -y ${yumPacks}
+
+ for yumPack in ${yumPacks}
+ do
+ rpmPack=$(rpm -q ${yumPack})
+ packCheck=$(echo ${rpmPack}|grep not)
+ if [ "${packCheck}" ]; then
+ yum install ${yumPack} -y
+ fi
+ done
+}
+
+Install_Deb_Pack(){
+ debPacks="wget curl unzip gcc g++ make libcurl4-openssl-dev libssl-dev liblzma-dev xz-utils libffi-dev libbz2-dev libsqlite3-dev libreadline-dev libgdbm-dev python3-bsddb3 tk-dev ncurses-dev uuid-dev";
+ apt-get install -y $debPacks --force-yes
+
+ for debPack in ${debPacks}
+ do
+ packCheck=$(dpkg -l ${debPack})
+ if [ "$?" -ne "0" ] ;then
+ apt-get install -y $debPack
+ fi
+ done
+}
+
+Install_Main(){
+ startTime=`date +%s`
+ System_Check
+ Get_Pack_Manager
+ get_node_url
+
+ if [ $PM = "yum" ]; then
+ Install_RPM_Pack
+ else
+ Install_Deb_Pack
+ fi
+ Install_Python_Lib
+ Install_Monitor
+ Set_Firewall
+ Get_Ip_Address
+ Service_Add
+ if [ "$re_install" == "2" ]; then
+ Reinstall_Monitor
+ fi
+ Start_Monitor
+}
+
+Uninstall_Monitor(){
+ pkill BT-MONITOR
+ /etc/init.d/btm stop
+
+ Service_Del
+
+ rm -rf $monitor_path
+ rm -rf /usr/bin/btm
+ rm -rf /etc/init.d/btm
+
+ echo -e "堡塔云监控Server端卸载成功!"
+}
+
+Uninstall_agent(){
+ get_node_url
+ if [ -f "/tmp/btmonitoragent.sh" ];then
+ rm -rf /tmp/btmonitoragent.sh
+ fi
+ curl -o /tmp/btmonitoragent.sh -sSO ${download_Url}/install/btmonitoragent.sh && bash /tmp/btmonitoragent.sh uninstall
+}
+
+action="${1}"
+if [ "$action" == "uninstall" ];then
+ echo -e "----------------------------------------------------"
+ echo -e "\033[33m检测到您正在卸载堡塔云监控系统,请按照选项选择卸载方式!\033[0m"
+ echo -e "1) 备份数据后卸载:保存原有监控配置及数据并卸载堡塔云监控"
+ echo -e "2) 完全卸载:清空原有监控配置及数据并卸载堡塔云监控"
+ echo -e "----------------------------------------------------"
+ read -p "请输入对应选项[1|2]进行卸载或输入任意内容退出卸载: " yes;
+ if [ "$yes" == "1" ]; then
+ Backup_Monitor
+ echo -e "----------------------------------------------------"
+ echo -e "\033[33m已备份原有监控数据至: ${old_dir}\033[0m"
+ elif [ "$yes" == "2" ]; then
+ echo "正在清空堡塔云监控数据..."
+ else
+ echo -e "------------"
+ echo "取消卸载"
+ exit;
+ fi
+ Uninstall_agent
+ Uninstall_Monitor
+ exit 0
+else
+echo "
++----------------------------------------------------------------------
+| Bt-Monitor FOR CentOS/Ubuntu/Debian
++----------------------------------------------------------------------
+| Copyright © 2015-2099 BT-SOFT(http://www.bt.cn) All rights reserved.
++----------------------------------------------------------------------
+| The Monitor URL will be http://SERVER_IP:806 when installed.
++----------------------------------------------------------------------
+"
+while [ "$go" != 'y' ] && [ "$go" != 'n' ]
+do
+ read -p "Do you want to install Bt-Monitor to the $setup_path directory now?(y/n): " go;
+done
+
+ if [ "$go" == 'n' ];then
+ exit;
+ fi
+ Install_Main
+ #curl -o /dev/null -fsSL --connect-time 10 "https://www.bt.cn/api/wpanel/SetupCountCloud?cloud_type=1&token=$md5_pl"
+fi
+echo -e "=================================================================="
+echo -e "\033[32m堡塔云监控安装完成! Installed successfully!\033[0m"
+echo -e "=================================================================="
+echo "外网访问地址: https://${getIpAddress}:${panelPort}${adminpath}"
+echo "内网访问地址: https://${LOCAL_IP}:${panelPort}${adminpath}"
+echo -e "username: admin"
+echo -e "password: $password"
+echo -e "\033[33mIf you cannot access the Monitor,\033[0m"
+echo -e "\033[33mrelease the following Monitor port [${panelPort}] in the security group\033[0m"
+echo -e "\033[33m若无法访问堡塔云监控,请检查防火墙/安全组是否有放行[${panelPort}]端口\033[0m"
+echo -e "=================================================================="
+
+endTime=`date +%s`
+((outTime=($endTime-$startTime)/60))
+echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"
diff --git a/public/install/src/bt-monitor-1.0.11.zip b/public/install/src/bt-monitor-1.0.11.zip
new file mode 100644
index 0000000..05278a2
Binary files /dev/null and b/public/install/src/bt-monitor-1.0.11.zip differ
diff --git a/public/install/update_btmonitor.sh b/public/install/update_btmonitor.sh
new file mode 100644
index 0000000..b34b9a4
--- /dev/null
+++ b/public/install/update_btmonitor.sh
@@ -0,0 +1,436 @@
+#!/bin/bash
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
+export PATH
+LANG=en_US.UTF-8
+
+Btapi_Url='http://www.example.com'
+
+monitor_path="/www/server/bt-monitor"
+run_bin="/www/server/bt-monitor/BT-MONITOR"
+is64bit=$(getconf LONG_BIT)
+
+if [ ! -d $monitor_path ]; then
+ echo "没有安装云监控,请执行下面的命令安装堡塔云监控!"
+ echo "curl -sSO http://download.bt.cn/install/install_btmonitor.sh && bash install_btmonitor.sh"
+ exit 1
+fi
+
+cd ~
+setup_path="/www"
+
+if [ -f "/etc/init.d/btm" ]; then
+ /etc/init.d/btm stop
+ sleep 1
+fi
+
+get_node_url(){
+ if [ ! -f /bin/curl ];then
+ if [ "${PM}" = "yum" ]; then
+ yum install curl -y
+ elif [ "${PM}" = "apt-get" ]; then
+ apt-get install curl -y
+ fi
+ fi
+
+ if [ -f "/www/node.pl" ];then
+ download_Url=$(cat /www/node.pl)
+ echo "Download node: $download_Url";
+ echo '---------------------------------------------';
+ return
+ fi
+
+ echo '---------------------------------------------';
+ echo "Selected download node...";
+ # nodes=(http://dg2.bt.cn http://dg1.bt.cn http://125.90.93.52:5880 http://36.133.1.8:5880 http://123.129.198.197 http://38.34.185.130 http://116.213.43.206:5880 http://128.1.164.196);
+ nodes=(http://dg2.bt.cn http://dg1.bt.cn http://125.90.93.52:5880 http://36.133.1.8:5880 http://123.129.198.197 http://116.213.43.206:5880);
+ tmp_file1=/dev/shm/net_test1.pl
+ tmp_file2=/dev/shm/net_test2.pl
+ [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
+ [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
+ touch $tmp_file1
+ touch $tmp_file2
+ for node in ${nodes[@]};
+ do
+ NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
+ RES=$(echo ${NODE_CHECK}|awk '{print $1}')
+ NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $2}')
+ TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $3 * 1000 - 500 }'|cut -d '.' -f 1)
+ if [ "${NODE_STATUS}" == "200" ];then
+ if [ $TIME_TOTAL -lt 100 ];then
+ if [ $RES -ge 1500 ];then
+ echo "$RES $node" >> $tmp_file1
+ fi
+ else
+ if [ $RES -ge 1500 ];then
+ echo "$TIME_TOTAL $node" >> $tmp_file2
+ fi
+ fi
+
+ i=$(($i+1))
+ if [ $TIME_TOTAL -lt 100 ];then
+ if [ $RES -ge 3000 ];then
+ break;
+ fi
+ fi
+ fi
+ done
+
+ NODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')
+ if [ -z "$NODE_URL" ];then
+ NODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')
+ if [ -z "$NODE_URL" ];then
+ NODE_URL='http://download.bt.cn';
+ fi
+ fi
+ rm -f $tmp_file1
+ rm -f $tmp_file2
+ download_Url=$NODE_URL
+ echo "Download node: $download_Url";
+ echo '---------------------------------------------';
+}
+
+Get_Versions(){
+ redhat_version_file="/etc/redhat-release"
+ deb_version_file="/etc/issue"
+ if [ -f $redhat_version_file ];then
+ os_type='el'
+ is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
+ if [ "$is_aliyunos" != "" ];then
+ return
+ fi
+ os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
+ if [ "${os_version}" = "5" ];then
+ os_version=""
+ fi
+ if [ -z "${os_version}" ];then
+ os_version=$(cat /etc/redhat-release |grep Stream|grep -oE 8)
+ fi
+ else
+ os_type='ubuntu'
+ os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
+ if [ "${os_version}" = "" ];then
+ os_type='debian'
+ os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
+ if [ "${os_version}" = "" ];then
+ os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
+ fi
+ if [ "${os_version}" = "8" ];then
+ os_version=""
+ fi
+ if [ "${is64bit}" = '32' ];then
+ os_version=""
+ fi
+ else
+ if [ "$os_version" = "14" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "12" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "19" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "21" ];then
+ os_version=""
+ fi
+ if [ "$os_version" = "20" ];then
+ os_version2004=$(cat /etc/issue|grep 20.04)
+ if [ -z "${os_version2004}" ];then
+ os_version=""
+ fi
+ fi
+ fi
+ fi
+}
+
+Install_Python_Lib(){
+ curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
+ pyenv_path="/www/server/bt-monitor"
+ if [ -f $pyenv_path/pyenv/bin/python ];then
+ is_ssl=$($python_bin -c "import ssl" 2>&1|grep cannot)
+ $pyenv_path/pyenv/bin/python3.7 -V
+ if [ $? -eq 0 ] && [ -z "${is_ssl}" ];then
+ chmod -R 700 $pyenv_path/pyenv/bin
+ is_package=$($python_bin -m psutil 2>&1|grep package)
+ if [ "$is_package" = "" ];then
+ wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -t 5 -T 10
+ $pyenv_path/pyenv/bin/pip install -U pip
+ $pyenv_path/pyenv/bin/pip install -U setuptools
+ $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
+ $pyenv_path/pyenv/bin/pip install -U flask==2.2.0
+ $pyenv_path/pyenv/bin/pip install flask_sock
+ $pyenv_path/pyenv/bin/pip install cachelib
+ $pyenv_path/pyenv/bin/pip install py7zr
+ $pyenv_path/pyenv/bin/pip install backports.lzma
+ fi
+ source $pyenv_path/pyenv/bin/activate
+ chmod -R 700 $pyenv_path/pyenv/bin
+ return
+ else
+ rm -rf $pyenv_path/pyenv
+ fi
+ fi
+
+ py_version="3.7.9"
+ if [ ! -d "$pyenv_path" ]; then
+ mkdir -p $pyenv_path
+ fi
+ echo "True" > /www/disk.pl
+ if [ ! -w /www/disk.pl ];then
+ Red_Error "ERROR: Install python env fielded." "ERROR: /www目录无法写入,请检查目录/用户/磁盘权限!"
+ fi
+ os_type='el'
+ os_version='7'
+ is_export_openssl=0
+ Get_Versions
+
+ echo "OS: $os_type - $os_version"
+ is_aarch64=$(uname -a|grep aarch64)
+ if [ "$is_aarch64" != "" ];then
+ is64bit="aarch64"
+ fi
+
+ if [ -f "/www/server/bt-monitor/pymake.pl" ];then
+ os_version=""
+ rm -f /www/server/bt-monitor/pymake.pl
+ fi
+
+ if [[ $os_type =~ "debian" ]] || [[ $os_type =~ "ubuntu" ]]; then
+ isbtm="-btm"
+ fi
+
+ if [ "${os_version}" != "" ];then
+ pyenv_file="/www/pyenv.tar.gz"
+ wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}${isbtm}.tar.gz -t 5 -T 10
+ tmp_size=$(du -b $pyenv_file|awk '{print $1}')
+ if [ $tmp_size -lt 703460 ];then
+ rm -f $pyenv_file
+ echo "ERROR: Download python env fielded."
+ else
+ echo "Install python env..."
+ tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
+ chmod -R 700 $pyenv_path/pyenv/bin
+ rm -rf $pyenv_path/pyenv/bin/python
+ ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
+ $pyenv_path/pyenv/bin/python -m pip install --upgrade --force-reinstall pip
+ $pyenv_path/pyenv/bin/pip install -U flask==2.2.0
+ $pyenv_path/pyenv/bin/pip install flask_sock
+ $pyenv_path/pyenv/bin/pip install cachelib
+ $pyenv_path/pyenv/bin/pip install py7zr
+ $pyenv_path/pyenv/bin/pip install backports.lzma
+ if [ ! -f $pyenv_path/pyenv/bin/python ];then
+ rm -f $pyenv_file
+ Red_Error "ERROR: Install python env fielded." "ERROR: 下载堡塔云监控运行环境失败,请尝试重新安装!"
+ fi
+ $pyenv_path/pyenv/bin/python3.7 -V
+ if [ $? -eq 0 ];then
+ rm -f $pyenv_file
+ ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btmpip
+ ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btmpython
+ source $pyenv_path/pyenv/bin/activate
+ return
+ else
+ rm -f $pyenv_file
+ rm -rf $pyenv_path/pyenv
+ fi
+ fi
+ fi
+
+ cd /www
+ python_src='/www/python_src.tar.xz'
+ python_src_path="/www/Python-${py_version}"
+ wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -t 5 -T 10
+ tmp_size=$(du -b $python_src|awk '{print $1}')
+ if [ $tmp_size -lt 10703460 ];then
+ rm -f $python_src
+ Red_Error "ERROR: Download python source code fielded." "ERROR: 下载堡塔云监控运行环境失败,请尝试重新安装!"
+ fi
+ tar xvf $python_src
+ rm -f $python_src
+ cd $python_src_path
+ ./configure --prefix=$pyenv_path/pyenv
+ make -j$cpu_cpunt
+ make install
+ if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
+ rm -rf $python_src_path
+ Red_Error "ERROR: Make python env fielded." "ERROR: 编译堡塔云监控运行环境失败!"
+ fi
+ cd ~
+ rm -rf $python_src_path
+ wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -t 5 -T 10
+ wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -t 5 -T 10
+ ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
+ ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
+ ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btmpip
+ ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btmpython
+ chmod -R 700 $pyenv_path/pyenv/bin
+ $pyenv_path/pyenv/bin/pip install -U pip
+ $pyenv_path/pyenv/bin/pip install -U setuptools
+ $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
+ $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
+ $pyenv_path/pyenv/bin/pip install -U flask==2.2.0
+ $pyenv_path/pyenv/bin/pip install flask_sock
+ $pyenv_path/pyenv/bin/pip install cachelib
+ $pyenv_path/pyenv/bin/pip install py7zr
+ $pyenv_path/pyenv/bin/pip install backports.lzma
+ source $pyenv_path/pyenv/bin/activate
+
+ is_gevent=$($python_bin -m gevent 2>&1|grep -oE package)
+ is_psutil=$($python_bin -m psutil 2>&1|grep -oE package)
+ if [ "${is_gevent}" != "${is_psutil}" ];then
+ Red_Error "ERROR: psutil/gevent install failed!"
+ fi
+}
+
+Install_Monitor(){
+ version="1.0.2"
+ file_name="bt-monitor"
+ agent_src="bt-monitor.zip"
+
+ cd ~
+ version=`curl -sf ${Btapi_Url}/bt_monitor/latest_version |awk -F '\"version\"' '{print $2}'|awk -F ':' '{print $2}'|awk -F '"' '{print $2}'`
+ if [ -z $version ]; then
+ version="1.0.2"
+ fi
+ new_dir="/www/server/new_btmonitor"
+ if [ ! -d "$new_dir" ];then
+ mkdir -p $new_dir
+ fi
+ if [ ! -z "$action" ]; then
+ # 例如:sh update_btmonitor.sh /root/demo.zip
+ if [[ "$action" =~ "zip" ]]; then
+ version="指定版本"
+ unzip -o $action -d $new_dir/
+ else
+ wget -O $agent_src ${Btapi_Url}/install/src/$file_name-$version.zip -t 5 -T 10
+ unzip -o $agent_src -d $new_dir/ > /dev/null
+ fi
+ else
+ wget -O $agent_src ${Btapi_Url}/install/src/$file_name-$version.zip -t 5 -T 10
+ unzip -o $agent_src -d $new_dir/ > /dev/null
+ fi
+ if [ ! -f $new_dir/BT-MONITOR ];then
+ ls -lh $agent_src
+ Red_Error "ERROR: Failed to download, please try install again!" "ERROR: 下载堡塔云监控失败,请尝试重新安装!"
+ fi
+
+ rm -rf $new_dir/config
+ rm -rf $new_dir/data
+ rm -rf $new_dir/ssl
+ \cp -r $new_dir/* $monitor_path/
+ rm -rf $agent_src
+ rm -rf $new_dir
+ chmod +x $monitor_path/BT-MONITOR
+ chmod +x $monitor_path/tools.py
+ wget -O /etc/init.d/btm ${download_Url}/init/btmonitor.init -t 5 -T 10
+ chmod +x /etc/init.d/btm
+ ln -sf /etc/init.d/btm /usr/bin/btm
+
+ if [ ! -f /www/server/bt-monitor/data/user.json ]; then
+ echo "{\"uid\":1,\"username\":\"Administrator\",\"ip\":\"127.0.0.1\",\"server_id\":\"1\",\"access_key\":\"test\",\"secret_key\":\"123456\"}" > /www/server/bt-monitor/data/user.json
+ fi
+}
+
+Service_Add(){
+ if [ $Command_Exists systemctl ]; then
+ wget -O /usr/lib/systemd/system/btm.service ${download_Url}/init/systemd/btmonitor.service -t 5 -T 10
+ systemctl daemon-reload
+ systemctl enable btm
+ else
+ if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
+ chkconfig --add btm
+ chkconfig --level 2345 btm on
+ elif [ "${PM}" == "apt-get" ]; then
+ update-rc.d btm defaults
+ fi
+ fi
+}
+
+Start_Monitor(){
+ /etc/init.d/btm start
+ if [ "$?" != "0" ]; then
+ echo "堡塔云监控启动失败!"
+ tail $monitor_path/logs/error.log
+ exit 1
+ fi
+ echo "已成功升级到[$version]${Ver}";
+}
+
+GetSysInfo(){
+ if [ -s "/etc/redhat-release" ];then
+ SYS_VERSION=$(cat /etc/redhat-release)
+ elif [ -s "/etc/issue" ]; then
+ SYS_VERSION=$(cat /etc/issue)
+ fi
+ SYS_INFO=$(uname -a)
+ SYS_BIT=$(getconf LONG_BIT)
+ MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
+ CPU_INFO=$(getconf _NPROCESSORS_ONLN)
+
+ echo -e ${SYS_VERSION}
+ echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
+ echo -e ${SYS_INFO}
+ echo -e "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
+}
+
+Red_Error(){
+ echo '=================================================';
+ printf '\033[1;31;40m%b\033[0m\n' "$@";
+ GetSysInfo
+ exit 1;
+}
+
+Install_RPM_Pack(){
+ yumPacks="wget curl unzip gcc gcc-c++ make libcurl-devel openssl-devel xz-devel python-backports-lzma xz"
+ yum install -y ${yumPacks}
+
+ for yumPack in ${yumPacks}
+ do
+ rpmPack=$(rpm -q ${yumPack})
+ packCheck=$(echo ${rpmPack}|grep not)
+ if [ "${packCheck}" ]; then
+ yum install ${yumPack} -y
+ fi
+ done
+}
+
+Install_Deb_Pack(){
+ apt-get update -y
+ debPacks="wget curl unzip gcc g++ make libcurl4-openssl-dev libssl-dev liblzma-dev xz-utils libffi-dev libbz2-dev libsqlite3-dev libreadline-dev libgdbm-dev python3-bsddb3 tk-dev ncurses-dev uuid-dev";
+ apt-get install -y $debPacks --force-yes
+
+ for debPack in ${debPacks}
+ do
+ packCheck=$(dpkg -l ${debPack})
+ if [ "$?" -ne "0" ] ;then
+ apt-get install -y $debPack
+ fi
+ done
+}
+
+Get_Pack_Manager(){
+ if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
+ PM="yum"
+ elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
+ PM="apt-get"
+ fi
+}
+
+Update_Monitor(){
+ Get_Pack_Manager
+ get_node_url
+ if [ $PM = "yum" ]; then
+ Install_RPM_Pack
+ else
+ Install_Deb_Pack
+ fi
+ if [ "$action" == "update_py" ]; then
+ Install_Python_Lib
+ fi
+ Install_Monitor
+ Service_Add
+ Start_Monitor
+}
+
+action=${1}
+Update_Monitor
\ No newline at end of file
diff --git a/public/static/css/download.css b/public/static/css/download.css
index c2bd2ef..f6fd84a 100644
--- a/public/static/css/download.css
+++ b/public/static/css/download.css
@@ -331,10 +331,6 @@ canvas {
color: #20a53a;
}
-.d4 {
- background-color: #edf6ef;
-}
-
.d4 .desc {
margin-bottom: 16px;
line-height: 30px;
@@ -375,7 +371,7 @@ canvas {
animation: flap-right 0.75s linear infinite;
}
-/* װű */
+/* ��װ�ű� */
.layui-layer .install-code {
display: flex;
flex-wrap: wrap;
diff --git a/public/static/images/bt_monitor.png b/public/static/images/bt_monitor.png
new file mode 100644
index 0000000..b427f71
Binary files /dev/null and b/public/static/images/bt_monitor.png differ
diff --git a/route/app.php b/route/app.php
index d4c9b78..f51b2a0 100644
--- a/route/app.php
+++ b/route/app.php
@@ -15,6 +15,14 @@ Route::post('/panel/get_unbinding', 'api/return_success');
Route::post('/bt_cert', 'api/return_error');
Route::post('/Auth/GetAuthToken', 'api/get_auth_token');
Route::post('/Auth/GetBindCode', 'api/return_error');
+Route::any('/bt_monitor/update_history', 'api/btm_update_history');
+Route::any('/bt_monitor/latest_version', 'api/btm_latest_version');
+
+Route::group('authorization', function () {
+ Route::post('/login', 'api/authorization_login');
+ Route::post('/info', 'api/authorization_info');
+ Route::miss('api/return_error');
+});
Route::group('api', function () {
Route::any('/panel/get_soft_list', 'api/get_plugin_list');
diff --git a/wiki/btmonitor.md b/wiki/btmonitor.md
new file mode 100644
index 0000000..0365cc9
--- /dev/null
+++ b/wiki/btmonitor.md
@@ -0,0 +1,42 @@
+# 宝塔云监控安装包修改记录
+
+查询最新版本号:https://api.bt.cn/bt_monitor/latest_version
+
+安装包下载链接:http://download.bt.cn/install/src/bt-monitor-版本号.zip
+
+- 删除core/include/c_loader/PluginLoader.so,将btmonitor/PluginLoader.py复制到这个文件夹
+
+- 批量解密源码:执行 php think decrypt all <源码根目录>
+
+ 极少数文件解密失败是正常现象可无视
+
+- 全局搜索替换 https://api.bt.cn => http://www.example.com
+
+- 全局搜索替换 https://www.bt.cn/api/ => http://www.example.com/api/(需排除/panel/get_ip_info)
+
+- core/public.py 在
+
+ ```python
+ def GetConfigValue(key):
+ ```
+
+ 这一行下面加上
+
+ ```python
+ if key == 'home': return 'http://www.example.com'
+ ```
+
+ def write_request_log(reques = None): 这一行下面加上 return
+
+- core/basic_monitor.py
+
+ 在 def report_module_logs(self): 这一行下面加上 return
+
+- modules/configModule/main.py
+
+ http://download.bt.cn => http://www.example.com
+
+- update/update_btmonitor.sh 修改Install_Monitor方法内的download_Url变量
+
+- init.sh http://download.bt.cn => http://www.example.com
+
diff --git a/wiki/files/btmonitor/PluginLoader.py b/wiki/files/btmonitor/PluginLoader.py
new file mode 100644
index 0000000..2b1840e
--- /dev/null
+++ b/wiki/files/btmonitor/PluginLoader.py
@@ -0,0 +1,64 @@
+#coding: utf-8
+import os,sys,json
+import core.include.public as public
+
+#执行模块方法(模块名,方法名,参数)
+def module_run(module_name, def_name, def_args):
+ if not module_name or not def_name: return public.returnMsg(False,'模块名称和模块方法名称不能为空!')
+ if not path_check(module_name) or not path_check(def_name): return public.returnMsg(False,'模块名或方法名不能包含特殊符号!')
+
+ panel_path = public.get_panel_path()
+ filename = "{}/modules/{}Module/{}Module.py".format(panel_path,module_name,module_name)
+ if not os.path.exists(filename):
+ filename = "{}/modules/{}Module/main.py".format(panel_path,module_name)
+ if not os.path.exists(filename):
+ filename = "{}/plugin/{}/main.py".format(panel_path,module_name)
+ if not os.path.exists(filename):
+ filename = "{}/plugin/{}Module/{}Plugin.py".format(panel_path,module_name,module_name)
+ if not os.path.exists(filename):
+ return public.returnMsg(False,'指定模块或插件不存在')
+
+ _obj = public.get_script_object(filename)
+ if not _obj: return public.returnMsg(False,'模块加载失败: %s' % module_name)
+ if hasattr(_obj, "items") and hasattr(_obj, "setdefault"):
+ return _obj
+
+ class_name = "main"
+ if not hasattr(_obj, class_name):
+ return public.returnMsg(False,'找不到入口类: %s' % class_name)
+
+ class_obj = getattr(_obj,class_name, None)
+ if not class_obj:
+ return public.returnMsg(False,'获取入口类失败' % module_name)
+
+ try:
+ class_func = class_obj()
+ except:
+ return public.returnMsg(False,'模块入口实例化失败' % module_name)
+
+ if not hasattr(class_func, def_name):
+ return public.returnMsg(False,'在[%s]模块中找不到[%s]方法' % (class_name,def_name))
+
+ def_func = getattr(class_func, def_name, None)
+ if not def_func:
+ return public.returnMsg(False,'获取方法失败')
+
+ if 'module_get_object' in def_args:
+ return def_func
+
+ result = def_func(def_args)
+ return result
+
+#获取指定模块对象(文件全路径)
+def get_module(filename):
+ if not filename: return public.returnMsg(False,'模块路径不能为空!')
+ if "./" in filename: return public.returnMsg(False,'模块路径不能为相对路径')
+ return public.get_script_object(filename)
+
+#检查路径是否合法
+def path_check(path):
+ list = ["./","..",",",";",":","?","'","\"","<",">","|","\\","\n","\r","\t","\b","\a","\f","\v","*","%","&","$","#","@","!","~","`","^","(",")","+","=","{","}","[","]"]
+ for i in path:
+ if i in list:
+ return False
+ return True
diff --git a/wiki/files/PluginLoader.py b/wiki/files/linux/PluginLoader.py
similarity index 100%
rename from wiki/files/PluginLoader.py
rename to wiki/files/linux/PluginLoader.py
diff --git a/wiki/files/bt.js b/wiki/files/linux/bt.js
similarity index 100%
rename from wiki/files/bt.js
rename to wiki/files/linux/bt.js
diff --git a/wiki/update.md b/wiki/update.md
index 065e19d..d4d7044 100644
--- a/wiki/update.md
+++ b/wiki/update.md
@@ -8,7 +8,7 @@
- 将class文件夹里面所有的.so文件删除
-- 将PluginLoader.py复制到class文件夹
+- 将linux/PluginLoader.py复制到class文件夹
- 批量解密模块文件:执行 php think decrypt classdir <面板class文件夹路径>