Merge pull request #855 from midoks/dev

快捷连接ssh
This commit is contained in:
Mr Chen
2026-02-01 03:49:25 +08:00
committed by GitHub
16 changed files with 80 additions and 3 deletions
+1
View File
@@ -13,6 +13,7 @@ mw redis | 快捷连接Redis
mw valkey | 快捷连接valkey mw valkey | 快捷连接valkey
mw mongodb | 快捷连接MongoDB mw mongodb | 快捷连接MongoDB
mw pgdb | 快捷连接PostgreSQL mw pgdb | 快捷连接PostgreSQL
mw ssh | 快捷连接ssh
---------------------------------------- ----------------------------------------
mw open | 开启面板 mw open | 开启面板
mw close | 关闭面板 mw close | 关闭面板
+43 -1
View File
@@ -80,6 +80,7 @@ def mwcli(mw_input=0):
'(101) 关闭PHP52显示', '(101) 关闭PHP52显示',
'(200) 切换Linux系统软件源', '(200) 切换Linux系统软件源',
'(201) 简单速度测试', '(201) 简单速度测试',
'(202) SSH终端管理',
'(0) 取消' '(0) 取消'
] ]
cmd_list_num = len(cmd_list) cmd_list_num = len(cmd_list)
@@ -105,7 +106,7 @@ def mwcli(mw_input=0):
10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
100, 101, 100, 101,
200, 201 200, 201, 202
] ]
if not mw_input in nums: if not mw_input in nums:
print(raw_tip) print(raw_tip)
@@ -264,7 +265,48 @@ def mwcli(mw_input=0):
# os.system(INIT_CMD + " mirror") # os.system(INIT_CMD + " mirror")
elif mw_input == 201: elif mw_input == 201:
os.system('curl -Lso- bench.sh | bash') os.system('curl -Lso- bench.sh | bash')
elif mw_input == 202:
package = mw.getPanelDir()+'/plugins'
dst_plugin = mw.getServerDir() + "/webssh"
if not os.path.exists(dst_plugin):
mw.echoInfo("未安装!")
exit(1)
if not package in sys.path:
sys.path.append(package)
from webssh.index import App
obj = App()
data = obj.get_server_list()
data = json.loads(data)
if data['status']:
wlist = data['data']
wlist_len = len(wlist)
if wlist_len == 0:
mw.echoInfo("SSH终端管理,数据为空!")
exit(1)
if len(sys.argv) == 4:
pos = int(sys.argv[3])
if pos >= wlist_len:
mw.echoInfo("SSH终端管理,超过限制!")
exit(1)
dst_data = wlist[pos]
tmp_host = dst_data["host"]
info = obj.get_server_by_host_data(tmp_host)
pp_info = tmp_host+"|"+info["port"]+"|"+info['username']+"|"+info['password']+""
print(pp_info)
exit(0)
mw.echoInfo("请选择:")
for x in range(wlist_len):
dst_data = wlist[x]
tag = dst_data['host']
if dst_data['ps'] != "":
tag = dst_data['ps']
print(str(x) +") " + tag)
def open_ssh_port(): def open_ssh_port():
+7
View File
@@ -120,6 +120,11 @@ class App():
destr = mw.deDoubleCrypt('mdserver-web', rdata) destr = mw.deDoubleCrypt('mdserver-web', rdata)
return json.loads(destr) return json.loads(destr)
def get_server_by_host_data(self, host):
info_file = self.__host_dir + '/' + host + '/info.json'
info_data = self.getSshInfo(info_file)
return info_data
def get_server_by_host(self): def get_server_by_host(self):
args = self.getArgs() args = self.getArgs()
check = self.checkArgs(args, ['host']) check = self.checkArgs(args, ['host'])
@@ -152,9 +157,11 @@ class App():
if os.path.exists(self.__host_dir): if os.path.exists(self.__host_dir):
for name in os.listdir(self.__host_dir): for name in os.listdir(self.__host_dir):
info_file = self.__host_dir + '/' + name + '/info.json' info_file = self.__host_dir + '/' + name + '/info.json'
# print(info_file)
if not os.path.exists(info_file): if not os.path.exists(info_file):
continue continue
host_info = {} host_info = {}
try: try:
info_tmp = self.getSshInfo(info_file) info_tmp = self.getSshInfo(info_file)
+17 -1
View File
@@ -25,7 +25,7 @@ ERROR='[\033[31mERROR\033[0m]'
WORKING='[\033[34m*\033[0m]' WORKING='[\033[34m*\033[0m]'
PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
export LANG=en_US.UTF-8 export LANG=en_US.UTF-8
PANEL_DIR={$SERVER_PATH} PANEL_DIR={$SERVER_PATH}
@@ -631,6 +631,21 @@ mw_valkey(){
${CLIEXEC} ${CLIEXEC}
} }
mw_ssh(){
cd ${PANEL_DIR} && python3 panel_tools.py cli 202
if [[ "$?" == "0" ]]; then
POS=$(echo -e "\n${BLUE}└─ 选择登陆终端:${PLAIN}")
read -p "${POS}" INPUT
SSS=`cd ${PANEL_DIR} && python3 panel_tools.py cli 202 $INPUT`
# echo "info:$SSS"
# SSS="127.0.0.1|22|root|xx"
IFS='|' read -r SERVER_IP SERVER_PORT SERVER_USER SERVER_PASS <<< "$SSS"
echo "Attempting SSH connection to $SERVER_USER@$SERVER_IP:$SERVER_PORT"
sshpass -p "$SERVER_PASS" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -p "$SERVER_PORT" "$SERVER_USER@$SERVER_IP"
fi
}
mw_venv(){ mw_venv(){
cd ${PANEL_DIR} && source bin/activate cd ${PANEL_DIR} && source bin/activate
} }
@@ -755,6 +770,7 @@ case "$1" in
'redis') mw_redis;; 'redis') mw_redis;;
'valkey')mw_valkey;; 'valkey')mw_valkey;;
'mongodb') mw_mongodb;; 'mongodb') mw_mongodb;;
'ssh') mw_ssh;;
'venv') mw_update_venv;; 'venv') mw_update_venv;;
'clean_lib') mw_clean_lib;; 'clean_lib') mw_clean_lib;;
'list') mw_list;; 'list') mw_list;;
+1
View File
@@ -19,6 +19,7 @@ yum install -y bzip2
yum install -y bzip2-devel yum install -y bzip2-devel
yum install -y ncurses-compat-libs yum install -y ncurses-compat-libs
yum install -y numactl yum install -y numactl
yum install -y sshpass
SSH_PORT=`netstat -ntpl|grep sshd|grep -v grep | sed -n "1,1p" | awk '{print $4}' | awk -F : '{print $2}'` SSH_PORT=`netstat -ntpl|grep sshd|grep -v grep | sed -n "1,1p" | awk '{print $4}' | awk -F : '{print $2}'`
if [ "$SSH_PORT" == "" ];then if [ "$SSH_PORT" == "" ];then
+1
View File
@@ -27,6 +27,7 @@ yum install -y bzip2
yum install -y bzip2-devel yum install -y bzip2-devel
yum install -y ncurses-compat-libs yum install -y ncurses-compat-libs
yum install -y numactl yum install -y numactl
yum install -y sshpass
SSH_PORT=`netstat -ntpl|grep sshd|grep -v grep | sed -n "1,1p" | awk '{print $4}' | awk -F : '{print $2}'` SSH_PORT=`netstat -ntpl|grep sshd|grep -v grep | sed -n "1,1p" | awk '{print $4}' | awk -F : '{print $2}'`
if [ "$SSH_PORT" == "" ];then if [ "$SSH_PORT" == "" ];then
+1
View File
@@ -54,6 +54,7 @@ echo y | pacman -Sy libvpx
echo y | pacman -Sy libwebp echo y | pacman -Sy libwebp
echo y | pacman -Sy libxpm echo y | pacman -Sy libxpm
echo y | pacman -Syu freetype2 echo y | pacman -Syu freetype2
echo y | pacman -Syu sshpass
## gd end ## gd end
echo y | pacman -Syu icu echo y | pacman -Syu icu
+1 -1
View File
@@ -37,7 +37,7 @@ yum install -y bzip2
yum install -y bzip2-devel yum install -y bzip2-devel
yum install -y ncurses-compat-libs yum install -y ncurses-compat-libs
yum install -y numactl yum install -y numactl
yum install -y sshpass
# if [ -f /usr/sbin/iptables ];then # if [ -f /usr/sbin/iptables ];then
+1
View File
@@ -93,6 +93,7 @@ apt install -y dnsutils
apt install -y apache2-utils apt install -y apache2-utils
apt install -y numactl apt install -y numactl
apt install -y xxd apt install -y xxd
apt install -y sshpass
P_VER=`python3 -V | awk '{print $2}'` P_VER=`python3 -V | awk '{print $2}'`
if version_ge "$P_VER" "3.11.0" ;then if version_ge "$P_VER" "3.11.0" ;then
+1
View File
@@ -37,6 +37,7 @@ yum install -y bzip2
yum install -y bzip2-devel yum install -y bzip2-devel
yum install -y ncurses-compat-libs yum install -y ncurses-compat-libs
yum install -y numactl yum install -y numactl
yum install -y sshpass
# if [ -f /usr/sbin/iptables ];then # if [ -f /usr/sbin/iptables ];then
+1
View File
@@ -17,6 +17,7 @@ yum install -y wget curl lsof unzip
yum install -y expect yum install -y expect
yum install -y ncurses-compat-libs yum install -y ncurses-compat-libs
yum install -y numactl yum install -y numactl
yum install -y sshpass
dnf install crontabs -y dnf install crontabs -y
SSH_PORT=`netstat -ntpl|grep sshd|grep -v grep | sed -n "1,1p" | awk '{print $4}' | awk -F : '{print $2}'` SSH_PORT=`netstat -ntpl|grep sshd|grep -v grep | sed -n "1,1p" | awk '{print $4}' | awk -F : '{print $2}'`
+1
View File
@@ -65,6 +65,7 @@ pkg install -y bc
pkg install -y bzip2 pkg install -y bzip2
pkg install -y bzip2-devel pkg install -y bzip2-devel
pkg install -y numactl pkg install -y numactl
pkg install -y sshpass
# curl https://sh.rustup.rs -sSf | sh # curl https://sh.rustup.rs -sSf | sh
pkg install -y rust pkg install -y rust
+1
View File
@@ -58,6 +58,7 @@ zypper install -y libargon2-devel
zypper install -y net-tools-deprecated zypper install -y net-tools-deprecated
zypper install -y numactl zypper install -y numactl
zypper install -y sshpass
# zypper install -y php-config # zypper install -y php-config
+1
View File
@@ -43,6 +43,7 @@ $PKGMGR install -y p7zip-plugins
$PKGMGR install -y mmap-devel $PKGMGR install -y mmap-devel
$PKGMGR install -y libncurses* $PKGMGR install -y libncurses*
$PKGMGR install -y sshpass
echo "install remi source" echo "install remi source"
if [ "$VERSION_ID" == "9" ];then if [ "$VERSION_ID" == "9" ];then
+1
View File
@@ -27,6 +27,7 @@ yum install -y libzip-devel
yum install -y re2c yum install -y re2c
yum install -y ncurses-compat-libs yum install -y ncurses-compat-libs
yum install -y numactl yum install -y numactl
apt install -y sshpass
if [ -f /usr/sbin/iptables ];then if [ -f /usr/sbin/iptables ];then
+1
View File
@@ -59,6 +59,7 @@ apt install -y protobuf-compiler
apt install -y libboost-dev apt install -y libboost-dev
apt install -y liblz4-tool apt install -y liblz4-tool
apt install -y zstd apt install -y zstd
apt install -y sshpass
P_VER=`python3 -V | awk '{print $2}'` P_VER=`python3 -V | awk '{print $2}'`
if version_ge "$P_VER" "3.11.0" ;then if version_ge "$P_VER" "3.11.0" ;then