Commit e6e1a489 authored by ibuler's avatar ibuler

[Update] 文案改为中文,并且禁止登陆windows的机器

parent 24da12cc
......@@ -129,7 +129,6 @@ class InteractiveServer:
input_data.append(data)
def dispatch(self, opt):
print(repr(opt))
if opt is None:
return self._sentinel
elif opt.startswith("/"):
......@@ -183,7 +182,7 @@ class InteractiveServer:
self.get_user_asset_groups()
if len(self.asset_groups) == 0:
self.client.send(warning(_("Nothing")))
self.client.send(warning(_("")))
return
fake_group = AssetGroup(name=_("Name"), assets_amount=_("Assets"), comment=_("Comment"))
......@@ -197,11 +196,11 @@ class InteractiveServer:
self.client.send(title(header.format(fake_group, "ID")))
for index, group in enumerate(self.asset_groups, 1):
self.client.send(wr(line.format(group, index)))
self.client.send(wr(_("Total: {}").format(len(self.asset_groups)), before=1))
self.client.send(wr(_("总共: {}").format(len(self.asset_groups)), before=1))
def display_group_assets(self, _id):
if _id > len(self.asset_groups) or _id <= 0:
self.client.send(wr(warning("No matched group, select again")))
self.client.send(wr(warning("没有匹配分组,请重新输入")))
self.display_asset_groups()
return
......@@ -223,7 +222,7 @@ class InteractiveServer:
self.client.send(wr(title(header.format(fake_asset, "ID"))))
for index, asset in enumerate(self.search_result, 1):
self.client.send(wr(line.format(asset, index)))
self.client.send(wr(_("Total: {} Matched: {}").format(
self.client.send(wr(_("总共: {} 匹配: {}").format(
len(self.assets), len(self.search_result)), before=1)
)
......@@ -265,7 +264,7 @@ class InteractiveServer:
return None
while True:
self.client.send(wr(_("Choose one to login: "), after=1))
self.client.send(wr(_("选择一个登陆: "), after=1))
self.display_system_users(system_users)
opt = self.get_option("ID> ")
if opt.isdigit() and len(system_users) > int(opt):
......@@ -284,14 +283,18 @@ class InteractiveServer:
def search_and_proxy(self, opt):
self.search_assets(opt)
if self.search_result and len(self.search_result) == 1:
self.proxy(self.search_result[0])
asset = self.search_result[0]
if asset.platform == "Windows":
self.client.send(warning(_("终端不支持登录windows, 请使用web terminal访问")))
return
self.proxy(asset)
else:
self.display_search_result()
def proxy(self, asset):
system_user = self.choose_system_user(asset.system_users_granted)
if system_user is None:
self.client.send(_("No user"))
self.client.send(_("没有系统用户"))
return
forwarder = ProxyServer(self.app, self.client)
forwarder.proxy(asset, system_user)
......
......@@ -92,7 +92,7 @@ class ProxyServer:
timeout=TIMEOUT, compress=True, auth_timeout=10,
look_for_keys=False
)
except (paramiko.AuthenticationException, paramiko.BadAuthenticationType):
except (paramiko.AuthenticationException, paramiko.BadAuthenticationType, SSHException):
admins = self.app.config['ADMINS'] or 'administrator'
self.client.send(warning(wr(
"Authenticate with server failed, contact {}".format(admins),
......
......@@ -28,6 +28,7 @@ class Session:
self._command_recorder = command_recorder
self._replay_recorder = replay_recorder
self.server.set_session(self)
self.date_last_active = datetime.datetime.utcnow()
def add_watcher(self, watcher, silent=False):
"""
......@@ -129,6 +130,8 @@ class Session:
logger.info(msg)
self.close()
break
self.date_last_active = datetime.datetime.utcnow()
for watcher in [self.client] + self._watchers + self._sharers:
watcher.send(data)
elif sock == self.client:
......@@ -171,6 +174,7 @@ class Session:
"login_from": "ST",
"remote_addr": self.client.addr[0],
"is_finished": True if self.stop_evt.is_set() else False,
"date_last_active": self.date_last_active.strftime("%Y-%m-%d %H:%M:%S") + " +0000",
"date_start": self.date_created.strftime("%Y-%m-%d %H:%M:%S") + " +0000",
"date_end": self.date_end.strftime("%Y-%m-%d %H:%M:%S") + " +0000" if self.date_end else None
}
......
......@@ -289,4 +289,17 @@ def get_logger(file_name):
return logging.getLogger('coco.'+file_name)
zh_pattern = re.compile(u'[\u4e00-\u9fa5]+')
def len_display(s):
length = 0
for i in s:
if zh_pattern.match(i):
length += 2
else:
length += 1
return length
ugettext = _gettext()
......@@ -30,5 +30,5 @@ tornado==4.5.2
urllib3==1.22
wcwidth==0.1.7
werkzeug==0.12.2
jumpserver-python-sdk==0.0.30
jumpserver-python-sdk==0.0.31
jms-es-sdk
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