Unverified Commit 2983f06a authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #145 from jumpserver/dev

Dev
parents 1233b998 f510d762
......@@ -56,6 +56,7 @@ class Coco:
return self._task_handler
@staticmethod
@ignore_error
def load_extra_conf_from_server():
configs = app_service.load_config_from_server()
logger.debug("Loading config from server: {}".format(
......@@ -63,8 +64,17 @@ class Coco:
))
config.update(configs)
def keep_load_extra_conf(self):
def func():
while True:
self.load_extra_conf_from_server()
time.sleep(60*10)
thread = threading.Thread(target=func)
thread.start()
def bootstrap(self):
self.load_extra_conf_from_server()
self.keep_load_extra_conf()
self.keep_heartbeat()
self.monitor_sessions()
self.monitor_sessions_replay()
......
......@@ -92,8 +92,9 @@ class Config(dict):
"""
def __init__(self, root_path, defaults=None):
dict.__init__(self, defaults or {})
self.defaults = defaults or {}
self.root_path = root_path
super().__init__({})
def from_envvar(self, variable_name, silent=False):
"""Loads a configuration from an environment variable pointing to
......@@ -269,6 +270,21 @@ class Config(dict):
rv[key] = v
return rv
def __getitem__(self, item):
try:
value = super().__getitem__(item)
except KeyError:
value = None
if value is not None:
return value
value = os.environ.get(item, None)
if value is not None:
return value
return self.defaults.get(item)
def __getattr__(self, item):
return self.__getitem__(item)
def __repr__(self):
return '<%s %s>' % (self.__class__.__name__, dict.__repr__(self))
......@@ -302,6 +318,7 @@ default_config = {
'REPLAY_STORAGE': {'TYPE': 'server'},
'LANGUAGE_CODE': 'zh',
'SECURITY_MAX_IDLE_TIME': 60,
'ASSET_LIST_PAGE_SIZE': 'auto',
}
config = Config(root_path, default_config)
......
This diff is collapsed.
......@@ -10,7 +10,7 @@ from .config import config as app_config
def create_logger():
level = app_config['LOG_LEVEL']
log_dir = app_config.get('LOG_DIR')
log_dir = app_config['LOG_DIR']
log_path = os.path.join(log_dir, 'coco.log')
main_setting = {
'handlers': ['console', 'file'],
......
......@@ -360,6 +360,11 @@ class TelnetServer(BaseServer):
self.system_user = system_user
super(TelnetServer, self).__init__(chan=sock)
@property
def closed(self):
""" self.chan: socket object """
return getattr(self.chan, '_closed', False)
class Server(BaseServer):
"""
......
......@@ -63,6 +63,7 @@ class SSHServer:
return connection
def handle_connection(self, sock, addr):
logger.debug("Handle new connection from: {}".format(addr))
transport = paramiko.Transport(sock, gss_kex=False)
try:
transport.load_server_moduli()
......@@ -77,7 +78,7 @@ class SSHServer:
server = SSHInterface(connection)
try:
transport.start_server(server=server)
except paramiko.SSHException:
except (paramiko.SSHException, socket.timeout):
logger.warning("SSH negotiation failed")
return
except EOFError as e:
......
......@@ -294,7 +294,7 @@ def get_logger(file_name):
return logging.getLogger('coco.'+file_name)
def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0):
def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0, only_one_char=False):
"""实现了一个ssh input, 提示用户输入, 获取并返回
:return user input string
......@@ -303,6 +303,10 @@ def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0):
parser = TtyIOParser()
client.send(wrap_with_line_feed(prompt, before=before, after=after))
if only_one_char:
data = client.recv(1)
return data.decode()
while True:
data = client.recv(10)
if len(data) == 0:
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-31 11:49+0800\n"
"POT-Creation-Date: 2018-12-18 20:03+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,11 +16,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: coco/app.py:135
#: coco/app.py:145
msgid "Connect idle more than {} minutes, disconnect"
msgstr ""
#: coco/interactive.py:80
#: coco/interactive.py:84
#, python-brace-format
msgid ""
"\n"
......@@ -28,136 +28,127 @@ msgid ""
"{end}{R}{R}"
msgstr ""
#: coco/interactive.py:82
#: coco/interactive.py:86
#, python-brace-format
msgid ""
"{T}1) Enter {green}ID{end} directly login or enter {green}part IP, Hostname, "
"Comment{end} to search login(if unique).{R}"
msgstr ""
#: coco/interactive.py:83
#: coco/interactive.py:87
#, python-brace-format
msgid ""
"{T}2) Enter {green}/{end} + {green}IP, Hostname{end} or {green}Comment {end} "
"search, such as: /ip.{R}"
msgstr ""
#: coco/interactive.py:84
#: coco/interactive.py:88
#, python-brace-format
msgid "{T}3) Enter {green}p{end} to display the host you have permission.{R}"
msgstr ""
#: coco/interactive.py:85
#: coco/interactive.py:89
#, python-brace-format
msgid ""
"{T}4) Enter {green}g{end} to display the node that you have permission.{R}"
msgstr ""
#: coco/interactive.py:86
#: coco/interactive.py:90
#, python-brace-format
msgid ""
"{T}5) Enter {green}g{end} + {green}NodeID{end} to display the host under the "
"node, such as g1.{R}"
msgstr ""
#: coco/interactive.py:87
#: coco/interactive.py:91
#, python-brace-format
msgid "{T}6) Enter {green}s{end} Chinese-english switch.{R}"
msgstr ""
#: coco/interactive.py:88
#: coco/interactive.py:92
#, python-brace-format
msgid "{T}7) Enter {green}h{end} help.{R}"
msgstr ""
#: coco/interactive.py:89
#: coco/interactive.py:93
#, python-brace-format
msgid "{T}8) Enter {green}r{end} to refresh your assets and nodes.{R}"
msgstr ""
#: coco/interactive.py:90
#: coco/interactive.py:94
#, python-brace-format
msgid "{T}0) Enter {green}q{end} exit.{R}"
msgstr ""
#: coco/interactive.py:159
msgid "No"
msgstr ""
#: coco/interactive.py:166
msgid "Name"
#: coco/interactive.py:155
msgid "Terminal does not support login rdp, please use web terminal to access"
msgstr ""
#: coco/interactive.py:166
msgid "Assets"
#: coco/interactive.py:212
msgid "No Assets"
msgstr ""
#: coco/interactive.py:172
msgid "Total: {}"
#: coco/interactive.py:275
msgid "Tips: Enter the asset ID and log directly into the asset."
msgstr ""
#: coco/interactive.py:177
msgid "Node [ ID.Name(Asset) ]"
#: coco/interactive.py:276
msgid "Page up: P/p"
msgstr ""
#: coco/interactive.py:179
msgid "Enter g+NodeID to display the host under the node, such as g1."
#: coco/interactive.py:277
msgid "Page down: Enter|N/n"
msgstr ""
#: coco/interactive.py:186
msgid "There is no matched node, please re-enter"
#: coco/interactive.py:278
msgid "BACK: b/q"
msgstr ""
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "ID"
msgstr ""
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "Hostname"
msgstr ""
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "IP"
msgstr ""
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "LoginAs"
msgstr ""
#: coco/interactive.py:211
#: coco/interactive.py:313
msgid "Comment"
msgstr ""
#: coco/interactive.py:221
#: coco/interactive.py:322
msgid "Page: {}, Count: {}, Total Page: {}, Total Count: {}"
msgstr ""
#: coco/interactive.py:296
msgid "Select a login:: "
#: coco/interactive.py:394
msgid "No Nodes"
msgstr ""
#: coco/interactive.py:319
msgid ""
"Terminal does not support login Windows, please use web terminal to access"
#: coco/interactive.py:398
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr ""
#: coco/interactive.py:401
msgid "Tips: Enter the asset ID and log directly into the asset."
#: coco/interactive.py:400
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr ""
#: coco/interactive.py:402
msgid "Page up: P/p"
msgstr ""
#: coco/interactive.py:403
msgid "Page down: Enter|N/n"
#: coco/interactive.py:408
msgid "There is no matched node, please re-enter"
msgstr ""
#: coco/interactive.py:404
msgid "BACK: B/b"
#: coco/interactive.py:438
msgid "Select a login:: "
msgstr ""
#: coco/interactive.py:425
#: coco/interactive.py:461
msgid "No system user"
msgstr ""
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-31 11:49+0800\n"
"POT-Creation-Date: 2018-12-18 20:04+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,11 +16,11 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: coco/app.py:135
#: coco/app.py:145
msgid "Connect idle more than {} minutes, disconnect"
msgstr "空闲时间超过 {} 分钟,断开连接"
#: coco/interactive.py:80
#: coco/interactive.py:84
#, python-brace-format
msgid ""
"\n"
......@@ -30,7 +30,7 @@ msgstr ""
"\n"
"{T}{T}{title} {user}, 欢迎使用Jumpserver开源跳板机系统 {end}{R}{R}"
#: coco/interactive.py:82
#: coco/interactive.py:86
#, python-brace-format
msgid ""
"{T}1) Enter {green}ID{end} directly login or enter {green}part IP, Hostname, "
......@@ -39,7 +39,7 @@ msgstr ""
"{T}1) 输入 {green}ID{end} 直接登录 或 输入{green}部分 IP,主机名,备注{end} 进"
"行搜索登录(如果唯一).{R}"
#: coco/interactive.py:83
#: coco/interactive.py:87
#, python-brace-format
msgid ""
"{T}2) Enter {green}/{end} + {green}IP, Hostname{end} or {green}Comment {end} "
......@@ -48,127 +48,120 @@ msgstr ""
"{T}2) 输入 {green}/{end} + {green}IP, 主机名{end} or {green}备注 {end}搜索. "
"如: /ip{R}"
#: coco/interactive.py:84
#: coco/interactive.py:88
#, python-brace-format
msgid "{T}3) Enter {green}p{end} to display the host you have permission.{R}"
msgstr "{T}3) 输入 {green}p{end} 显示您有权限的主机.{R}"
#: coco/interactive.py:85
#: coco/interactive.py:89
#, python-brace-format
msgid ""
"{T}4) Enter {green}g{end} to display the node that you have permission.{R}"
msgstr "{T}4) 输入 {green}g{end} 显示您有权限的节点.{R}"
#: coco/interactive.py:86
#: coco/interactive.py:90
#, python-brace-format
msgid ""
"{T}5) Enter {green}g{end} + {green}NodeID{end} to display the host under the "
"node, such as g1.{R}"
msgstr "{T}5) 输入 {green}g{end} + {green}节点ID{end} 显示节点下主机. 如: g1{R}"
msgstr ""
"{T}5) 输入 {green}g{end} + {green}节点ID{end} 显示节点下主机. 如: g1{R}"
#: coco/interactive.py:87
#: coco/interactive.py:91
#, python-brace-format
msgid "{T}6) Enter {green}s{end} Chinese-english switch.{R}"
msgstr "{T}6) 输入 {green}s{end} 中/英文切换.{R}"
#: coco/interactive.py:88
#: coco/interactive.py:92
#, python-brace-format
msgid "{T}7) Enter {green}h{end} help.{R}"
msgstr "{T}7) 输入 {green}h{end} 帮助.{R}"
#: coco/interactive.py:89
#: coco/interactive.py:93
#, python-brace-format
msgid "{T}8) Enter {green}r{end} to refresh your assets and nodes.{R}"
msgstr "{T}0) 输入 {green}r{end} 刷新最新的机器和节点信息.{R}"
#: coco/interactive.py:90
#: coco/interactive.py:94
#, python-brace-format
msgid "{T}0) Enter {green}q{end} exit.{R}"
msgstr "{T}0) 输入 {green}q{end} 退出.{R}"
#: coco/interactive.py:159
msgid "No"
msgstr "无"
#: coco/interactive.py:166
msgid "Name"
msgstr "名称"
#: coco/interactive.py:155
msgid "Terminal does not support login rdp, please use web terminal to access"
msgstr "终端不支持登录windows, 请使用web terminal访问"
#: coco/interactive.py:166
msgid "Assets"
msgstr "资产"
#: coco/interactive.py:212
msgid "No Assets"
msgstr "没有资产"
#: coco/interactive.py:172
msgid "Total: {}"
msgstr "总共: {}"
#: coco/interactive.py:275
msgid "Tips: Enter the asset ID and log directly into the asset."
msgstr "提示: 输入资产ID,直接登录资产."
#: coco/interactive.py:177
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr "节点: [ ID.名称(资产数量) ]"
#: coco/interactive.py:276
msgid "Page up: P/p"
msgstr "上一页: P/p"
#: coco/interactive.py:179
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr "提示: 输入 g+节点ID 显示节点下主机. 如: g1"
#: coco/interactive.py:277
msgid "Page down: Enter|N/n"
msgstr "下一页: Enter|N/n"
#: coco/interactive.py:186
msgid "There is no matched node, please re-enter"
msgstr "没有匹配分组,请重新输入"
#: coco/interactive.py:278
msgid "BACK: b/q"
msgstr "返回: B/b"
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "ID"
msgstr ""
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "Hostname"
msgstr "主机名"
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "IP"
msgstr ""
#: coco/interactive.py:197
#: coco/interactive.py:299
msgid "LoginAs"
msgstr "登录用户"
#: coco/interactive.py:211
#: coco/interactive.py:313
msgid "Comment"
msgstr "备注"
#: coco/interactive.py:221
#: coco/interactive.py:322
msgid "Page: {}, Count: {}, Total Page: {}, Total Count: {}"
msgstr "页码: {}, 数量: {}, 总页数: {}, 总数量: {}"
#: coco/interactive.py:296
msgid "Select a login:: "
msgstr "选择一个登录:"
#: coco/interactive.py:319
msgid ""
"Terminal does not support login Windows, please use web terminal to access"
msgstr "终端不支持登录windows, 请使用web terminal访问"
#: coco/interactive.py:394
msgid "No Nodes"
msgstr "没有节点"
#: coco/interactive.py:401
msgid "Tips: Enter the asset ID and log directly into the asset."
msgstr "提示: 输入资产ID,直接登录资产."
#: coco/interactive.py:398
msgid "Node: [ ID.Name(Asset amount) ]"
msgstr "节点: [ ID.名称(资产数量) ]"
#: coco/interactive.py:402
msgid "Page up: P/p"
msgstr "上一页: P/p"
#: coco/interactive.py:400
msgid "Tips: Enter g+NodeID to display the host under the node, such as g1"
msgstr "提示: 输入 g+节点ID 显示节点下主机. 如: g1"
#: coco/interactive.py:403
msgid "Page down: Enter|N/n"
msgstr "下一页: Enter|N/n"
#: coco/interactive.py:408
msgid "There is no matched node, please re-enter"
msgstr "没有匹配分组,请重新输入"
#: coco/interactive.py:404
msgid "BACK: B/b"
msgstr "返回: B/b"
#: coco/interactive.py:438
msgid "Select a login:: "
msgstr "选择一个登录:"
#: coco/interactive.py:425
#: coco/interactive.py:461
msgid "No system user"
msgstr "没有系统用户"
#: coco/models.py:247
msgid "Command `{}` is forbidden ........"
msgstr ""
msgstr "命令 `{}` 是被禁止的 ..."
#: coco/proxy.py:89
msgid "No permission"
......@@ -182,5 +175,14 @@ msgstr "开始连接到 {}@{} {:.1f}"
msgid "Terminated by administrator"
msgstr "被管理员中断"
#~ msgid "No"
#~ msgstr "无"
#~ msgid "Name"
#~ msgstr "名称"
#~ msgid "Total: {}"
#~ msgstr "总共: {}"
#~ msgid "Total: {} Match: {}"
#~ msgstr "总共: {} 匹配: {}"
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