ssh连接优化

pull/109/head
Mr Chen 6 years ago
parent 26ed8a9b57
commit 7f536f8d93
  1. 14
      route/__init__.py

@ -241,9 +241,7 @@ def clear_ssh():
PLIST=`who | grep localhost | awk '{print $2}'` PLIST=`who | grep localhost | awk '{print $2}'`
for i in $PLIST for i in $PLIST
do do
echo $i ps -t /dev/$i |grep -v TTY |awk '{print $1}' | xargs kill -9
echo "ps -t /dev/${i} |grep -v TTY |awk '{print $1}' | xargs kill -9"
ps -t /dev/${i} |grep -v TTY |awk '{print $1}' | xargs kill -9
done done
''' '''
if not public.isAppleSystem(): if not public.isAppleSystem():
@ -252,7 +250,7 @@ done
def connect_ssh(): def connect_ssh():
print 'connect_ssh ....' # print 'connect_ssh ....'
clear_ssh() clear_ssh()
global shell, ssh global shell, ssh
if not os.path.exists('/root/.ssh/authorized_keys') or not os.path.exists('/root/.ssh/id_rsa') or not os.path.exists('/root/.ssh/id_rsa.pub'): if not os.path.exists('/root/.ssh/authorized_keys') or not os.path.exists('/root/.ssh/id_rsa') or not os.path.exists('/root/.ssh/id_rsa.pub'):
@ -283,7 +281,7 @@ def get_input_data(data):
@socketio.on('webssh') @socketio.on('webssh')
def webssh(msg): def webssh(msg):
print 'webssh ...' # print 'webssh ...'
if not isLogined(): if not isLogined():
emit('server_response', {'data': '会话丢失,请重新登陆面板!\r\n'}) emit('server_response', {'data': '会话丢失,请重新登陆面板!\r\n'})
return None return None
@ -305,7 +303,8 @@ def webssh(msg):
recv = shell.recv(4096) recv = shell.recv(4096)
emit('server_response', {'data': recv.decode("utf-8")}) emit('server_response', {'data': recv.decode("utf-8")})
except Exception as ex: except Exception as ex:
print 'webssh:' + str(ex) pass
# print 'webssh:' + str(ex)
@socketio.on('connect_event') @socketio.on('connect_event')
@ -325,7 +324,8 @@ def connected_msg(msg):
# print recv.decode("utf-8") # print recv.decode("utf-8")
emit('server_response', {'data': recv.decode("utf-8")}) emit('server_response', {'data': recv.decode("utf-8")})
except Exception as e: except Exception as e:
print 'connected_msg:' + str(e) pass
# print 'connected_msg:' + str(e)
# @socketio.on('panel') # @socketio.on('panel')

Loading…
Cancel
Save