Unverified Commit 5f8d1227 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #115 from jumpserver/dev

Dev
parents 83eb5d1b 4f53020d
...@@ -111,7 +111,9 @@ class ElFinderConnector: ...@@ -111,7 +111,9 @@ class ElFinderConnector:
func() func()
except Exception as e: except Exception as e:
self.response['error'] = '%s' % e self.response['error'] = '%s' % e
logger.error("Error occur ------------------------------")
logger.exception(e) logger.exception(e)
logger.error("Error end ------------------------------")
def get_request_data(self): def get_request_data(self):
data_source = {} data_source = {}
......
...@@ -88,7 +88,6 @@ class SFTPVolume(BaseVolume): ...@@ -88,7 +88,6 @@ class SFTPVolume(BaseVolume):
def list(self, target, name_only=False): def list(self, target, name_only=False):
""" Returns a list of files/directories in the target directory. """ """ Returns a list of files/directories in the target directory. """
path = self._path(target) path = self._path(target)
print("List {} {}".format(target, path))
with self.lock: with self.lock:
return self._list(path) return self._list(path)
...@@ -96,7 +95,6 @@ class SFTPVolume(BaseVolume): ...@@ -96,7 +95,6 @@ class SFTPVolume(BaseVolume):
""" Get the sub directory of directory """ Get the sub directory of directory
""" """
path = self._path(target) path = self._path(target)
print("Tree {} {}".format(target, path))
with self.lock: with self.lock:
infos = self._list(path) infos = self._list(path)
tree = list(filter(lambda x: x['mime'] == 'directory', infos)) tree = list(filter(lambda x: x['mime'] == 'directory', infos))
...@@ -107,7 +105,6 @@ class SFTPVolume(BaseVolume): ...@@ -107,7 +105,6 @@ class SFTPVolume(BaseVolume):
获取目录的父目录, 如果deep为0,则直到根 获取目录的父目录, 如果deep为0,则直到根
""" """
path = self._path(target).rstrip(self.path_sep) path = self._path(target).rstrip(self.path_sep)
print("Parents {} {}".format(target, path))
with self.lock: with self.lock:
return self._parents(path, depth=depth) return self._parents(path, depth=depth)
...@@ -173,7 +170,6 @@ class SFTPVolume(BaseVolume): ...@@ -173,7 +170,6 @@ class SFTPVolume(BaseVolume):
remote_path = self._remote_path(path) remote_path = self._remote_path(path)
try: try:
data = self.sftp.lstat(remote_path) data = self.sftp.lstat(remote_path)
print(data)
exist = True exist = True
except FileNotFoundError: except FileNotFoundError:
exist = False exist = False
...@@ -188,7 +184,6 @@ class SFTPVolume(BaseVolume): ...@@ -188,7 +184,6 @@ class SFTPVolume(BaseVolume):
def paste(self, targets, dest, cut): def paste(self, targets, dest, cut):
""" Moves/copies target files/directories from source to dest. """ """ Moves/copies target files/directories from source to dest. """
print("Paste {} {} {}".format(targets, dest, cut))
dest_parent_path = self._path(dest) dest_parent_path = self._path(dest)
added = [] added = []
removed = [] removed = []
...@@ -198,14 +193,12 @@ class SFTPVolume(BaseVolume): ...@@ -198,14 +193,12 @@ class SFTPVolume(BaseVolume):
dest_path = self._join(dest_parent_path, self._base_name(src_path)) dest_path = self._join(dest_parent_path, self._base_name(src_path))
if self.is_dir(src_path): if self.is_dir(src_path):
raise OSError("Copy folder unsupported now") raise OSError("Copy folder unsupported now")
print("Paste {} to => {}".format(src_path, dest_parent_path))
if self.is_exist(dest_path): if self.is_exist(dest_path):
print("Exist {}".format(dest_path))
continue continue
src_remote_path = self._remote_path(src_path) src_remote_path = self._remote_path(src_path)
dest_remote_path = self._remote_path(dest_path) dest_remote_path = self._remote_path(dest_path)
f = self.sftp.open(src_remote_path, mode='r')
try: try:
f = self.sftp.open(src_remote_path, mode='r')
attr = self.sftp.putfo(f, dest_remote_path) attr = self.sftp.putfo(f, dest_remote_path)
if cut: if cut:
removed.append(self.remove(target)) removed.append(self.remove(target))
......
...@@ -422,7 +422,7 @@ ...@@ -422,7 +422,7 @@
'minsLeft' : '剩余 $1 分钟', // from v2.1.17 added 13.11.2016 'minsLeft' : '剩余 $1 分钟', // from v2.1.17 added 13.11.2016
'openAsEncoding' : '使用所选编码重新打开', // from v2.1.19 added 2.12.2016 'openAsEncoding' : '使用所选编码重新打开', // from v2.1.19 added 2.12.2016
'saveAsEncoding' : '使用所选编码保存', // from v2.1.19 added 2.12.2016 'saveAsEncoding' : '使用所选编码保存', // from v2.1.19 added 2.12.2016
'selectFolder' : '选择目录', // from v2.1.20 added 13.12.2016 'selectFolder' : '选择目录(暂不支持)', // from v2.1.20 added 13.12.2016
'firstLetterSearch': '首字母搜索', // from v2.1.23 added 24.3.2017 'firstLetterSearch': '首字母搜索', // from v2.1.23 added 24.3.2017
'presets' : '预置', // from v2.1.25 added 26.5.2017 'presets' : '预置', // from v2.1.25 added 26.5.2017
'tooManyToTrash' : '项目太多,不能移动到回收站.', // from v2.1.25 added 9.6.2017 'tooManyToTrash' : '项目太多,不能移动到回收站.', // from v2.1.25 added 9.6.2017
......
...@@ -332,7 +332,6 @@ class BaseServer: ...@@ -332,7 +332,6 @@ class BaseServer:
return self._cmd_parser.parse_output(self.output_data) return self._cmd_parser.parse_output(self.output_data)
def _parse_input(self): def _parse_input(self):
print("Parse input: {}".format(self.input_data))
if not self.input_data: if not self.input_data:
return return
return self._cmd_parser.parse_input(self.input_data) return self._cmd_parser.parse_input(self.input_data)
......
...@@ -45,7 +45,7 @@ def convert_error(func): ...@@ -45,7 +45,7 @@ def convert_error(func):
class SFTPServer(paramiko.SFTPServerInterface): class SFTPServer(paramiko.SFTPServerInterface):
root = 'home' # Home or /tmp or other path, must exist on all server root = '/tmp' # Home or /tmp or other path, must exist on all server
def __init__(self, server, **kwargs): def __init__(self, server, **kwargs):
""" """
...@@ -73,6 +73,8 @@ class SFTPServer(paramiko.SFTPServerInterface): ...@@ -73,6 +73,8 @@ class SFTPServer(paramiko.SFTPServerInterface):
self.server.connection.user self.server.connection.user
) )
for asset in assets: for asset in assets:
if asset.protocol != 'ssh':
continue
value = {} value = {}
key = asset.hostname key = asset.hostname
if asset.org_id: if asset.org_id:
...@@ -96,7 +98,6 @@ class SFTPServer(paramiko.SFTPServerInterface): ...@@ -96,7 +98,6 @@ class SFTPServer(paramiko.SFTPServerInterface):
active_channels = [c for c in trans._channels.values() if not c.closed] active_channels = [c for c in trans._channels.values() if not c.closed]
if not active_channels: if not active_channels:
print("CLose transport")
trans.close() trans.close()
if proxy: if proxy:
proxy.close() proxy.close()
...@@ -414,6 +415,9 @@ class InternalSFTPClient(SFTPServer): ...@@ -414,6 +415,9 @@ class InternalSFTPClient(SFTPServer):
attr = super().lstat.__wrapped__(self, path) attr = super().lstat.__wrapped__(self, path)
return attr return attr
def rmdir(self, path):
return super().rmdir.__wrapped__(self, path)
def get_channel(self): def get_channel(self):
return FakeChannel.new() return FakeChannel.new()
...@@ -422,7 +426,13 @@ class InternalSFTPClient(SFTPServer): ...@@ -422,7 +426,13 @@ class InternalSFTPClient(SFTPServer):
def putfo(self, f, path, callback=None, confirm=True): def putfo(self, f, path, callback=None, confirm=True):
client, rpath = self.get_sftp_client_rpath(path) client, rpath = self.get_sftp_client_rpath(path)
return client.putfo(f, rpath, callback=callback, confirm=confirm) success = False
try:
attr = client.putfo(f, rpath, callback=callback, confirm=confirm)
success = True
return attr
finally:
self.create_ftp_log(path, 'Upload', success)
def close(self): def close(self):
return self.session_ended() return self.session_ended()
...@@ -13,6 +13,10 @@ import argparse ...@@ -13,6 +13,10 @@ import argparse
import time import time
import signal import signal
dirs = ('logs', 'keys')
for d in dirs:
os.makedirs(d, exist_ok=True)
from coco import Coco from coco import Coco
try: try:
...@@ -21,9 +25,6 @@ except ImportError: ...@@ -21,9 +25,6 @@ except ImportError:
print("Please prepare config file `cp conf_example.py conf.py`") print("Please prepare config file `cp conf_example.py conf.py`")
sys.exit(1) sys.exit(1)
dirs = ('logs', 'keys')
for d in dirs:
os.makedirs(d, exist_ok=True)
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DAEMON = False DAEMON = False
...@@ -119,7 +120,7 @@ if __name__ == '__main__': ...@@ -119,7 +120,7 @@ if __name__ == '__main__':
description=""" description="""
coco service control tools; coco service control tools;
Example: \r\n Example: \r\n
%(prog)s start -d; %(prog)s start -d;
""" """
......
...@@ -18,7 +18,7 @@ idna==2.6 ...@@ -18,7 +18,7 @@ idna==2.6
itsdangerous==0.24 itsdangerous==0.24
Jinja2==2.10 Jinja2==2.10
jmespath==0.9.3 jmespath==0.9.3
jms-storage==0.0.18 jms-storage==0.0.19
jumpserver-python-sdk==0.0.50 jumpserver-python-sdk==0.0.50
MarkupSafe==1.0 MarkupSafe==1.0
oss2==2.4.0 oss2==2.4.0
......
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