Commit 4eaea983 authored by 广宏伟's avatar 广宏伟

Merged in dev (pull request #92)

Dev
parents 37cc25d9 80826161
......@@ -23,6 +23,9 @@ from werkzeug.utils import import_string
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
root_path = os.environ.get("COCO_PATH")
if not root_path:
root_path = BASE_DIR
class ConfigAttribute(object):
......@@ -270,11 +273,7 @@ class Config(dict):
return '<%s %s>' % (self.__class__.__name__, dict.__repr__(self))
root_path = os.environ.get("COCO_PATH")
if not root_path:
root_path = BASE_DIR
access_key_path = os.path.abspath(os.path.join(root_path, 'keys', '.access_key'))
default_config = {
'NAME': socket.gethostname(),
'CORE_HOST': 'http://127.0.0.1:8080',
......@@ -306,3 +305,9 @@ default_config = {
config = Config(root_path, default_config)
config.from_pyfile('conf.py')
try:
from conf import config as _conf
config.from_object(_conf)
except ImportError:
pass
......@@ -43,6 +43,7 @@ class SSHConnection:
if asset.domain:
sock = self.get_proxy_sock_v2(asset)
try:
try:
ssh.connect(
asset.ip, port=asset.port, username=system_user.username,
......@@ -51,6 +52,14 @@ class SSHConnection:
compress=True, auth_timeout=config['SSH_TIMEOUT'],
look_for_keys=False, sock=sock
)
except paramiko.AuthenticationException:
# 思科设备不支持秘钥登陆,提供秘钥,必然失败
ssh.connect(
asset.ip, port=asset.port, username=system_user.username,
password=system_user.password, timeout=config['SSH_TIMEOUT'],
compress=True, auth_timeout=config['SSH_TIMEOUT'],
look_for_keys=False, sock=sock, allow_agent=False,
)
transport = ssh.get_transport()
transport.set_keepalive(300)
except (paramiko.AuthenticationException,
......
......@@ -184,9 +184,10 @@ class ProxyNamespace(BaseNamespace):
connection = Connection.get_connection(request.sid)
if not connection:
return
for client in connection.clients:
clients_copy = list(connection.clients.keys())
for client_id in clients_copy:
try:
self.on_logout(client.id)
self.on_logout(client_id)
except Exception as e:
logger.warn(e)
Connection.remove_connection(connection.id)
......
......@@ -155,6 +155,8 @@ class InteractiveServer:
self.client.send(wr(_("Total: {}").format(len(self.nodes)), before=1))
def display_node_assets(self, _id):
if self.nodes is None:
self.get_user_nodes()
if _id > len(self.nodes) or _id <= 0:
msg = wr(warning(_("There is no matched node, please re-enter")))
self.client.send(msg)
......
......@@ -333,15 +333,11 @@ class WSProxy:
def closed(self):
return self.sock._closed
def session_close(self):
self.ws.on_logout(self.client_id)
def write(self, data):
self.proxy.send(data.encode())
def close(self):
self.proxy.close()
self.sock.close()
def __getattr__(self, item):
return getattr(self.sock, item)
......
......@@ -98,11 +98,11 @@ class SFTPServer(paramiko.SFTPServerInterface):
asset = self.hosts.get(host)
date_start = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " +0000",
data = {
"user": self.server.request.user.username,
"user": self.server.connection.user.username,
"asset": host,
"org_id": asset.org_id,
"system_user": su,
"remote_addr": self.server.request.addr[0],
"remote_addr": self.server.connection.addr[0],
"operate": operate,
"filename": filename or rpath,
"date_start": date_start,
......@@ -160,7 +160,11 @@ class SFTPServer(paramiko.SFTPServerInterface):
return attr
else:
sftp = self.get_host_sftp(host, su)
return sftp.stat(rpath)
try:
stat = sftp.stat(rpath)
return stat
except FileNotFoundError as e:
return paramiko.SFTPServer.convert_errno(e.errno)
def lstat(self, path):
host, su, rpath = self.parse_path(path)
......
......@@ -8,7 +8,7 @@ cffi==1.11.2
chardet==3.0.4
click==6.7
crcmod==1.7
cryptography==2.1.4
cryptography==2.3.1
docutils==0.14
dotmap==1.2.20
elasticsearch==6.1.1
......@@ -40,5 +40,5 @@ six==1.11.0
tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
eventlet==0.22.1
eventlet==0.24.1
Werkzeug==0.14.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment