diff --git a/scripts/init.d/mw.tpl b/scripts/init.d/mw.tpl index a6bd7cb0a..748e227ea 100755 --- a/scripts/init.d/mw.tpl +++ b/scripts/init.d/mw.tpl @@ -245,4 +245,7 @@ case "$1" in echo -e "\033[33mrelease the following port (${show_panel_ip}888|80|443|22) in the security group.\033[0m" echo -e "==================================================================" ;; + *) + cd $mw_path && python3 $mw_path/tools.py cli $1 + ;; esac diff --git a/scripts/install.sh b/scripts/install.sh index 3962e1e2f..36f454d6e 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -83,10 +83,13 @@ fi echo "use system version: ${OSNAME}" cd /www/server/mdserver-web && bash scripts/install/${OSNAME}.sh -chmod +x /www/server/mdserver-web/mw-cli -if [ ! -e /usr/bin/mw-cli ]; then - ln -s /www/server/mdserver-web/mw-cli /usr/bin/mw-cli + +if [ ! -e /usr/bin/mw ]; then + if [ -f /etc/init.d/mw ];then + ln -s /etc/init.d/mw /usr/bin/mw + fi fi + endTime=`date +%s` ((outTime=(${endTime}-${startTime})/60)) echo -e "Time consumed:\033[32m $outTime \033[0mMinute!" diff --git a/scripts/install_dev.sh b/scripts/install_dev.sh index 4f1a8f498..919435e1f 100755 --- a/scripts/install_dev.sh +++ b/scripts/install_dev.sh @@ -71,15 +71,12 @@ if [ $OSNAME != "macos" ];then fi echo "use system version: ${OSNAME}" - - -# cd /www/server/mdserver-web && bash ./scripts/install/debian.sh cd /www/server/mdserver-web && bash scripts/install/${OSNAME}.sh -# curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/install/${OSNAME}.sh | bash -chmod +x /www/server/mdserver-web/mw-cli -if [ ! -e /usr/bin/mw-cli ]; then - ln -s /www/server/mdserver-web/mw-cli /usr/bin/mw-cli +if [ ! -e /usr/bin/mw ]; then + if [ -f /etc/init.d/mw ];then + ln -s /etc/init.d/mw /usr/bin/mw + fi fi endTime=`date +%s` diff --git a/scripts/update.sh b/scripts/update.sh index cd10fd095..72010bc78 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -67,6 +67,12 @@ rm -rf /tmp/mdserver-web-master echo "use system version: ${OSNAME}" cd /www/server/mdserver-web && bash scripts/update/${OSNAME}.sh +if [ ! -e /usr/bin/mw ]; then + if [ ! -f /usr/bin/mw ];then + ln -s /etc/init.d/mw /usr/bin/mw + fi +fi + endTime=`date +%s` ((outTime=($endTime-$startTime)/60)) echo -e "Time consumed:\033[32m $outTime \033[0mMinute!" \ No newline at end of file diff --git a/scripts/update_dev.sh b/scripts/update_dev.sh index 82219145f..df4f21c10 100755 --- a/scripts/update_dev.sh +++ b/scripts/update_dev.sh @@ -65,9 +65,13 @@ rm -rf /tmp/mdserver-web-dev #pip uninstall public echo "use system version: ${OSNAME}" -# cd /www/server/mdserver-web && bash ./scripts/install/debian.sh cd /www/server/mdserver-web && bash scripts/update/${OSNAME}.sh -# curl -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update/${OSNAME}.sh | bash + +if [ ! -e /usr/bin/mw ]; then + if [ ! -f /usr/bin/mw ];then + ln -s /etc/init.d/mw /usr/bin/mw + fi +fi endTime=`date +%s` ((outTime=($endTime-$startTime)/60)) diff --git a/tools.py b/tools.py index bf4e22dd8..567f3ba09 100755 --- a/tools.py +++ b/tools.py @@ -14,6 +14,69 @@ import db # p = "/usr/local/lib/" + info[0].strip() + "/site-packages" # sys.path.append(p) +INIT_DIR = "/etc/init.d" +if mw.isAppleSystem(): + INIT_DIR = mw.getRunDir() + "/scripts/init.d" + +INIT_CMD = INIT_DIR + "/mw" + + +def mwcli(mw_input=0): + raw_tip = "=======================================================" + if not mw_input: + print("===============mdserver-web cli tools==================") + print("(1) 重启面板服务") + print("(2) 停止面板服务") + print("(3) 启动面板服务") + print("(4) 重载面板服务") + print("(10) 查看面板默认信息") + print("(11) 修改面板密码") + print("(12) 修改面板用户名") + print("(13) 显示面板错误日志") + print("(0) 取消") + print(raw_tip) + try: + mw_input = input("请输入命令编号:") + if sys.version_info[0] == 3: + mw_input = int(mw_input) + except: + mw_input = 0 + + nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 29] + if not mw_input in nums: + print(raw_tip) + print("已取消!") + exit() + + if mw_input == 1: + os.system(INIT_CMD + " restart") + elif mw_input == 2: + os.system(INIT_CMD + " stop") + elif mw_input == 3: + os.system(INIT_CMD + " start") + elif mw_input == 4: + os.system(INIT_CMD + " reload") + elif mw_input == 10: + os.system(INIT_CMD + " default") + elif mw_input == 11: + if sys.version_info[0] == 2: + input_pwd = raw_input("请输入新的面板密码:") + else: + input_pwd = input("请输入新的面板密码:") + if len(input_pwd.strip()) < 5: + print("|-错误,密码长度不能小于5位") + return + set_panel_pwd(input_pwd.strip(), True) + elif mw_input == 12: + if sys.version_info[0] == 2: + input_user = raw_input("请输入新的面板用户名(>3位):") + else: + input_user = input("请输入新的面板用户名(>3位):") + set_panel_username(input_user.strip()) + elif mw_input == 13: + os.system('tail -100 ' + mw.getRunDir() + '/logs/error.log') + def set_panel_pwd(password, ncli=False): # 设置面板密码 @@ -60,15 +123,23 @@ def getServerIp(): if __name__ == "__main__": - type = sys.argv[1] - if type == 'panel': + method = sys.argv[1] + if method == 'panel': set_panel_pwd(sys.argv[2]) - elif type == 'username': + elif method == 'username': if len(sys.argv) > 2: set_panel_username(sys.argv[2]) else: set_panel_username() - elif type == 'getServerIp': + elif method == 'getServerIp': getServerIp() + elif method == "cli": + clinum = 0 + try: + if len(sys.argv) > 2: + clinum = int(sys.argv[2]) if sys.argv[2][:6] else sys.argv[2] + except: + clinum = sys.argv[2] + mwcli(clinum) else: print('ERROR: Parameter error')