Unverified Commit a8320a5c authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Dev (#231)

* [Bugfix] 修改使用资产属性protocol和port的方式 (#224)

* [Bugfix] 修改使用资产属性protocol和port的方式

* [Update] windows支持通过ssh协议登录

* [Update] 修改依赖版本号

* [Update] telnet连接使用telnet_port

* [Update] 修改依赖版本号

* [update] change user content format

* [Update] 修改依赖版本号

* [Update] 修改依赖版本号
parent bb11874f
......@@ -112,7 +112,7 @@ class SSHConnection:
try:
try:
ssh.connect(
asset.ip, port=asset.port, username=system_user.username,
asset.ip, port=asset.ssh_port, username=system_user.username,
password=system_user.password, pkey=system_user.private_key,
timeout=config['SSH_TIMEOUT'],
compress=False, auth_timeout=config['SSH_TIMEOUT'],
......@@ -121,7 +121,7 @@ class SSHConnection:
except paramiko.AuthenticationException:
# 思科设备不支持秘钥登陆,提供秘钥,必然失败
ssh.connect(
asset.ip, port=asset.port, username=system_user.username,
asset.ip, port=asset.ssh_port, username=system_user.username,
password=system_user.password, timeout=config['SSH_TIMEOUT'],
compress=False, auth_timeout=config['SSH_TIMEOUT'],
look_for_keys=False, sock=sock, allow_agent=False,
......@@ -142,7 +142,7 @@ class SSHConnection:
logger.error("Connect {}@{}:{} auth failed, password: \
{}, key: {}".format(
system_user.username, asset.ip, asset.port,
system_user.username, asset.ip, asset.ssh_port,
password_short, key_fingerprint,
))
error += '\r\n' + str(e) if error else str(e)
......@@ -230,7 +230,7 @@ class SSHConnection:
transport = ssh.get_transport()
transport.set_keepalive(20)
sock = transport.open_channel(
'direct-tcpip', (asset.ip, asset.port), ('127.0.0.1', 0)
'direct-tcpip', (asset.ip, asset.ssh_port), ('127.0.0.1', 0)
)
break
except Exception as e:
......@@ -272,7 +272,7 @@ class TelnetConnection:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(10)
try:
self.sock.connect((self.asset.ip, self.asset.port))
self.sock.connect((self.asset.ip, self.asset.telnet_port))
except Exception as e:
msg = 'Connect telnet server failed. \r\n{}'.format(e)
logger.error(msg)
......
......@@ -152,13 +152,6 @@ class InteractiveServer:
assets = self.search_assets(opt)
if assets and len(assets) == 1:
asset = assets[0]
if asset.protocol == "rdp" \
or asset.platform.lower().startswith("windows"):
self.client.send_unicode(warning(
_("Terminal does not support login rdp, "
"please use web terminal to access"))
)
return
self.proxy(asset)
else:
self.display_assets_paging(assets)
......@@ -437,6 +430,11 @@ class InteractiveServer:
if system_user is None:
self.client.send_unicode(_("No system user"))
return
if system_user.protocol.lower() == 'rdp':
msg = _('Terminal does not support login through RDP protocol. '
'please use web terminal to access')
self.client.send_unicode(warning(msg))
return
forwarder = ProxyServer(self.client, asset, system_user)
forwarder.proxy()
......
......@@ -45,9 +45,10 @@ class ProxyServer:
self.system_user.private_key = private_key
def check_protocol(self):
if self.asset.protocol != self.system_user.protocol:
msg = 'System user <{}> and asset <{}> protocol are inconsistent.'.format(
self.system_user.name, self.asset.hostname
if not self.asset.has_protocol(self.system_user.protocol):
msg = _('Asset {} do not contain system user {} protocol {}')
msg = msg.format(
self.asset.hostname, self.system_user.name, self.system_user.protocol
)
self.client.send_unicode(warning(wr(msg, before=1, after=0)))
return False
......@@ -113,7 +114,7 @@ class ProxyServer:
self.get_system_user_username_if_need()
self.get_system_user_auth_or_manual_set()
self.send_connecting_message()
logger.info("Connect to {}:{} ...".format(self.asset.hostname, self.asset.port))
logger.info("Connect to {}:{} ...".format(self.asset.hostname, self.asset.ssh_port))
if not self.validate_permission():
msg = _('No permission')
self.client.send_unicode(warning(wr(msg, before=2, after=0)))
......
......@@ -128,7 +128,8 @@ class Session:
"org_id": self.server.asset.org_id,
"input": _input,
"output": _output,
"user": self.client.user.username,
"user": "{} ({})".format(self.client.user.name,
self.client.user.username),
"asset": self.server.asset.hostname,
"system_user": self.server.system_user.username,
"timestamp": time.time(),
......@@ -226,7 +227,8 @@ class Session:
def to_json(self):
return {
"id": self.id,
"user": self.client.user.username,
"user": "{} ({})".format(self.client.user.name,
self.client.user.username),
"asset": self.server.asset.hostname,
"org_id": self.server.asset.org_id,
"system_user": self.server.system_user.username,
......
......@@ -80,7 +80,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
self.server.connection.user, cache_policy='1',
)
for asset in assets:
if asset.protocol != 'ssh':
if not asset.has_protocol('ssh'):
continue
value = {}
key = asset.hostname
......@@ -185,7 +185,8 @@ class SFTPServer(paramiko.SFTPServerInterface):
asset = self.hosts.get(host)['asset']
date_start = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " +0000",
data = {
"user": self.server.connection.user.username,
"user": "{} ({})".format(self.server.connection.user.name,
self.server.connection.user.username),
"asset": host,
"org_id": asset.org_id,
"system_user": su,
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-03-06 14:51+0800\n"
"POT-Creation-Date: 2019-06-17 15:37+0800\n"
"PO-Revision-Date: 2018-08-10 10:42+0800\n"
"Last-Translator: BaiJiangjie <bugatti_it@163.com>\n"
"Language-Team: Language locale/en/LC\n"
......@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: coco/app.py:182
#: coco/app.py:172
msgid "Connect idle more than {} minutes, disconnect"
msgstr ""
......@@ -83,82 +83,84 @@ msgstr ""
msgid "{T}0) Enter {green}q{end} exit.{R}"
msgstr ""
#: coco/interactive.py:158
msgid "Terminal does not support login rdp, please use web terminal to access"
msgstr ""
#: coco/interactive.py:169
#: coco/interactive.py:162
msgid "Refresh done"
msgstr ""
#: coco/interactive.py:211
#: coco/interactive.py:204
msgid "No Assets"
msgstr ""
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "ID"
msgstr ""
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "Hostname"
msgstr ""
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "IP"
msgstr ""
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "LoginAs"
msgstr ""
#: coco/interactive.py:280
#: coco/interactive.py:273
msgid "Comment"
msgstr ""
#: coco/interactive.py:290
#: coco/interactive.py:283
msgid "Page: {}, Count: {}, Total Page: {}, Total Count: {}"
msgstr ""
#: coco/interactive.py:296
#: coco/interactive.py:289
msgid "Tips: Enter the asset ID and log directly into the asset."
msgstr ""
#: coco/interactive.py:298
#: coco/interactive.py:291
msgid "Page up: P/p"
msgstr ""
#: coco/interactive.py:299
#: coco/interactive.py:292
msgid "Page down: Enter|N/n"
msgstr ""
#: coco/interactive.py:300
#: coco/interactive.py:293
msgid "BACK: b/q"
msgstr ""
#: coco/interactive.py:371
#: coco/interactive.py:364
msgid "No Nodes"
msgstr ""
#: coco/interactive.py:375
#: coco/interactive.py:368
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr ""
#: coco/interactive.py:377
#: coco/interactive.py:370
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr ""
#: coco/interactive.py:385
#: coco/interactive.py:378
msgid "There is no matched node, please re-enter"
msgstr ""
#: coco/interactive.py:415
#: coco/interactive.py:408
msgid "Select a login:: "
msgstr ""
#: coco/interactive.py:438
#: coco/interactive.py:431
msgid "No system user"
msgstr ""
#: coco/interactive.py:434
msgid ""
"Terminal does not support login through RDP protocol. please use web "
"terminal to access"
msgstr ""
#: coco/models.py:252
msgid ""
"Warning: Failed to load filter rule, please press Ctrl + D to exit retry."
......@@ -168,15 +170,19 @@ msgstr ""
msgid "Command `{}` is forbidden ........"
msgstr ""
#: coco/proxy.py:76
#: coco/proxy.py:49
msgid "Asset {} do not contain system user {} protocol {}"
msgstr ""
#: coco/proxy.py:78
msgid "Connect with api server failed"
msgstr ""
#: coco/proxy.py:104
#: coco/proxy.py:119
msgid "No permission"
msgstr ""
#: coco/proxy.py:147
#: coco/proxy.py:170
msgid "Connecting to {}@{} {:.1f}"
msgstr ""
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-03-06 14:51+0800\n"
"POT-Creation-Date: 2019-06-17 15:37+0800\n"
"PO-Revision-Date: 2018-08-10 10:42+0800\n"
"Last-Translator: BaiJiangjie <bugatti_it@163.com>\n"
"Language-Team: Language locale/zh\n"
......@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: coco/app.py:182
#: coco/app.py:172
msgid "Connect idle more than {} minutes, disconnect"
msgstr "空闲时间超过 {} 分钟,断开连接"
......@@ -90,82 +90,84 @@ msgstr "{T}8) 输入 {green}r{end} 刷新最新的机器和节点信息.{R}"
msgid "{T}0) Enter {green}q{end} exit.{R}"
msgstr "{T}0) 输入 {green}q{end} 退出.{R}"
#: coco/interactive.py:158
msgid "Terminal does not support login rdp, please use web terminal to access"
msgstr "终端不支持登录windows, 请使用web terminal访问"
#: coco/interactive.py:169
#: coco/interactive.py:162
msgid "Refresh done"
msgstr "刷新完成"
#: coco/interactive.py:211
#: coco/interactive.py:204
msgid "No Assets"
msgstr "没有资产"
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "ID"
msgstr ""
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "Hostname"
msgstr "主机名"
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "IP"
msgstr ""
#: coco/interactive.py:266
#: coco/interactive.py:259
msgid "LoginAs"
msgstr "登录用户"
#: coco/interactive.py:280
#: coco/interactive.py:273
msgid "Comment"
msgstr "备注"
#: coco/interactive.py:290
#: coco/interactive.py:283
msgid "Page: {}, Count: {}, Total Page: {}, Total Count: {}"
msgstr "页码: {}, 数量: {}, 总页数: {}, 总数量: {}"
#: coco/interactive.py:296
#: coco/interactive.py:289
msgid "Tips: Enter the asset ID and log directly into the asset."
msgstr "提示: 输入资产ID,直接登录资产."
#: coco/interactive.py:298
#: coco/interactive.py:291
msgid "Page up: P/p"
msgstr "上一页: P/p"
#: coco/interactive.py:299
#: coco/interactive.py:292
msgid "Page down: Enter|N/n"
msgstr "下一页: Enter|N/n"
#: coco/interactive.py:300
#: coco/interactive.py:293
msgid "BACK: b/q"
msgstr "返回: B/b"
#: coco/interactive.py:371
#: coco/interactive.py:364
msgid "No Nodes"
msgstr "没有节点"
#: coco/interactive.py:375
#: coco/interactive.py:368
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr "节点: [ ID.名称(资产数量) ]"
#: coco/interactive.py:377
#: coco/interactive.py:370
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr "提示: 输入 g+节点ID 显示节点下主机. 如: g1"
#: coco/interactive.py:385
#: coco/interactive.py:378
msgid "There is no matched node, please re-enter"
msgstr "没有匹配分组,请重新输入"
#: coco/interactive.py:415
#: coco/interactive.py:408
msgid "Select a login:: "
msgstr "选择一个登录:"
#: coco/interactive.py:438
#: coco/interactive.py:431
msgid "No system user"
msgstr "没有系统用户"
#: coco/interactive.py:434
msgid ""
"Terminal does not support login through RDP protocol. please use web "
"terminal to access"
msgstr "终端不支持通过RDP协议登录, 请使用web terminal访问"
#: coco/models.py:252
msgid ""
"Warning: Failed to load filter rule, please press Ctrl + D to exit retry."
......@@ -175,15 +177,19 @@ msgstr "警告: 加载过滤规则失败,请按 Ctrl + D 退出重试."
msgid "Command `{}` is forbidden ........"
msgstr "命令 `{}` 是被禁止的 ..."
#: coco/proxy.py:76
#: coco/proxy.py:49
msgid "Asset {} do not contain system user {} protocol {}"
msgstr "资产 {} 不包含系统用户 {} 协议 {}"
#: coco/proxy.py:78
msgid "Connect with api server failed"
msgstr ""
#: coco/proxy.py:104
#: coco/proxy.py:119
msgid "No permission"
msgstr "没有权限"
#: coco/proxy.py:147
#: coco/proxy.py:170
msgid "Connecting to {}@{} {:.1f}"
msgstr "开始连接到 {}@{} {:.1f}"
......
......@@ -19,7 +19,7 @@ itsdangerous==0.24
Jinja2==2.10.1
jmespath==0.9.3
jms-storage==0.0.23
jumpserver-python-sdk==0.0.59
jumpserver-python-sdk==0.0.63
MarkupSafe==1.0
oss2==2.4.0
paramiko==2.4.2
......
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