Unverified Commit 83eb5d1b authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #110 from jumpserver/dev

Dev
parents 1ecdcc2a eeeca2d8
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
from . import logger
from .app import Coco from .app import Coco
...@@ -12,10 +12,9 @@ import signal ...@@ -12,10 +12,9 @@ import signal
from .config import config from .config import config
from .sshd import SSHServer from .sshd import SSHServer
from .httpd import HttpServer from .httpd import HttpServer
from .logger import create_logger
from .tasks import TaskHandler from .tasks import TaskHandler
from .utils import get_logger, ugettext as _, ignore_error from .utils import get_logger, ugettext as _, ignore_error
from .ctx import app_service from .service import app_service
from .recorder import get_replay_recorder from .recorder import get_replay_recorder
from .session import Session from .session import Session
from .models import Connection from .models import Connection
...@@ -56,9 +55,6 @@ class Coco: ...@@ -56,9 +55,6 @@ class Coco:
self._task_handler = TaskHandler() self._task_handler = TaskHandler()
return self._task_handler return self._task_handler
def make_logger(self):
create_logger()
@staticmethod @staticmethod
def load_extra_conf_from_server(): def load_extra_conf_from_server():
configs = app_service.load_config_from_server() configs = app_service.load_config_from_server()
...@@ -68,8 +64,6 @@ class Coco: ...@@ -68,8 +64,6 @@ class Coco:
config.update(configs) config.update(configs)
def bootstrap(self): def bootstrap(self):
self.make_logger()
# app_service.initial()
self.load_extra_conf_from_server() self.load_extra_conf_from_server()
self.keep_heartbeat() self.keep_heartbeat()
self.monitor_sessions() self.monitor_sessions()
......
...@@ -10,7 +10,7 @@ import telnetlib ...@@ -10,7 +10,7 @@ import telnetlib
import paramiko import paramiko
from paramiko.ssh_exception import SSHException from paramiko.ssh_exception import SSHException
from .ctx import app_service from .service import app_service
from .config import config from .config import config
from .utils import get_logger, get_private_key_fingerprint from .utils import get_logger, get_private_key_fingerprint
...@@ -22,7 +22,8 @@ AUTO_LOGIN = 'auto' ...@@ -22,7 +22,8 @@ AUTO_LOGIN = 'auto'
class SSHConnection: class SSHConnection:
def get_system_user_auth(self, system_user): @staticmethod
def get_system_user_auth(system_user):
""" """
获取系统用户的认证信息,密码或秘钥 获取系统用户的认证信息,密码或秘钥
:return: system user have full info :return: system user have full info
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
from werkzeug.local import LocalProxy from werkzeug.local import LocalProxy
from functools import partial from functools import partial
from .config import config
from jms.service import AppService
stack = {} stack = {}
__db_sessions = [] __db_sessions = []
...@@ -18,7 +15,4 @@ def _find(name): ...@@ -18,7 +15,4 @@ def _find(name):
raise ValueError("Not found in stack: {}".format(name)) raise ValueError("Not found in stack: {}".format(name))
app_service = AppService(config)
app_service.initial()
current_app = LocalProxy(partial(_find, 'current_app')) current_app = LocalProxy(partial(_find, 'current_app'))
# app_service = LocalProxy(partial(_find, 'app_service'))
...@@ -4,7 +4,7 @@ from functools import wraps ...@@ -4,7 +4,7 @@ from functools import wraps
from flask import request, abort, redirect from flask import request, abort, redirect
from ..ctx import app_service from ..service import app_service
def login_required(func): def login_required(func):
......
...@@ -9,7 +9,7 @@ from flask import Flask, request ...@@ -9,7 +9,7 @@ from flask import Flask, request
from ..models import Connection, WSProxy from ..models import Connection, WSProxy
from ..proxy import ProxyServer from ..proxy import ProxyServer
from ..utils import get_logger from ..utils import get_logger
from ..ctx import app_service from ..service import app_service
from ..config import config from ..config import config
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
......
...@@ -9,7 +9,7 @@ from flask import request ...@@ -9,7 +9,7 @@ from flask import request
from ..models import Connection, WSProxy from ..models import Connection, WSProxy
from ..proxy import ProxyServer from ..proxy import ProxyServer
from ..utils import get_logger from ..utils import get_logger
from ..ctx import app_service from ..service import app_service
from .base import BaseNamespace from .base import BaseNamespace
from .utils import get_cached_volume from .utils import get_cached_volume
......
...@@ -12,7 +12,7 @@ from .utils import wrap_with_line_feed as wr, wrap_with_title as title, \ ...@@ -12,7 +12,7 @@ from .utils import wrap_with_line_feed as wr, wrap_with_title as title, \
wrap_with_warning as warning, is_obj_attr_has, is_obj_attr_eq, \ wrap_with_warning as warning, is_obj_attr_has, is_obj_attr_eq, \
sort_assets, ugettext as _, get_logger, net_input, format_with_zh, \ sort_assets, ugettext as _, get_logger, net_input, format_with_zh, \
item_max_length, size_of_str_with_zh, switch_lang item_max_length, size_of_str_with_zh, switch_lang
from .ctx import app_service from .service import app_service
from .proxy import ProxyServer from .proxy import ProxyServer
logger = get_logger(__file__) logger = get_logger(__file__)
......
...@@ -8,7 +8,7 @@ from collections import Iterable ...@@ -8,7 +8,7 @@ from collections import Iterable
from .utils import get_logger from .utils import get_logger
from .config import config from .config import config
from .ctx import app_service from .service import app_service
logger = get_logger(__file__) logger = get_logger(__file__)
......
...@@ -57,9 +57,9 @@ def create_logger(): ...@@ -57,9 +57,9 @@ def create_logger():
# 'engineio': main_setting, # 'engineio': main_setting,
} }
) )
dictConfig(config) dictConfig(config)
logger = logging.getLogger() logger = logging.getLogger()
return logger return logger
create_logger()
...@@ -236,17 +236,21 @@ class BaseServer: ...@@ -236,17 +236,21 @@ class BaseServer:
def s_filter_cmd_filter(self, data): def s_filter_cmd_filter(self, data):
if self._in_input_state: if self._in_input_state:
return data return data
if not self._input:
return data
for rule in self._cmd_filter_rules: for rule in self._cmd_filter_rules:
action, cmd = rule.match(self._input) action, cmd = rule.match(self._input)
if action == rule.ALLOW: if action == rule.ALLOW:
break break
elif action == rule.DENY: elif action == rule.DENY:
data = char.CLEAR_LINE_CHAR + b'\r\n' data = char.CLEAR_LINE_CHAR + b'\r'
msg = _("Command `{}` is forbidden ........").format(cmd) msg = _("Command `{}` is forbidden ........").format(cmd)
msg = wr(warning(msg.encode()), before=1, after=1) msg = wr(warning(msg.encode()), before=1, after=1)
self.output_data.append(msg) self.output_data.append(msg)
self.session.send_to_clients(msg) self.session.send_to_clients(msg)
self.session.put_command(self._input, msg.decode())
self.session.put_replay(msg) self.session.put_replay(msg)
self.input_data.clean()
break break
return data return data
...@@ -328,6 +332,7 @@ class BaseServer: ...@@ -328,6 +332,7 @@ 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)
......
...@@ -8,7 +8,7 @@ import time ...@@ -8,7 +8,7 @@ import time
from .session import Session from .session import Session
from .models import Server, TelnetServer from .models import Server, TelnetServer
from .connection import SSHConnection, TelnetConnection from .connection import SSHConnection, TelnetConnection
from .ctx import app_service from .service import app_service
from .config import config from .config import config
from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \ from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \
get_logger, net_input, ugettext as _ get_logger, net_input, ugettext as _
...@@ -39,6 +39,7 @@ class ProxyServer: ...@@ -39,6 +39,7 @@ class ProxyServer:
or (not password and not private_key): or (not password and not private_key):
prompt = "{}'s password: ".format(self.system_user.username) prompt = "{}'s password: ".format(self.system_user.username)
password = net_input(self.client, prompt=prompt, sensitive=True) password = net_input(self.client, prompt=prompt, sensitive=True)
private_key = None
self.system_user.password = password self.system_user.password = password
self.system_user.private_key = private_key self.system_user.private_key = private_key
......
...@@ -15,7 +15,7 @@ import jms_storage ...@@ -15,7 +15,7 @@ import jms_storage
from .config import config from .config import config
from .utils import get_logger, Singleton from .utils import get_logger, Singleton
from .struct import MemoryQueue from .struct import MemoryQueue
from .ctx import app_service from .service import app_service
logger = get_logger(__file__) logger = get_logger(__file__)
BUF_SIZE = 1024 BUF_SIZE = 1024
......
...@@ -8,7 +8,7 @@ import time ...@@ -8,7 +8,7 @@ import time
from .utils import get_logger, wrap_with_warning as warn, \ from .utils import get_logger, wrap_with_warning as warn, \
wrap_with_line_feed as wr, ugettext as _, ignore_error wrap_with_line_feed as wr, ugettext as _, ignore_error
from .ctx import app_service from .service import app_service
from .struct import SelectEvent from .struct import SelectEvent
from .recorder import get_recorder from .recorder import get_recorder
......
...@@ -9,7 +9,7 @@ from paramiko.sftp import SFTP_PERMISSION_DENIED, SFTP_NO_SUCH_FILE, \ ...@@ -9,7 +9,7 @@ from paramiko.sftp import SFTP_PERMISSION_DENIED, SFTP_NO_SUCH_FILE, \
from coco.utils import get_logger from coco.utils import get_logger
from .config import config from .config import config
from .ctx import app_service from .service import app_service
from .connection import SSHConnection from .connection import SSHConnection
CURRENT_DIR = os.path.dirname(__file__) CURRENT_DIR = os.path.dirname(__file__)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
from .ctx import app_service from .service import app_service
from .utils import get_logger from .utils import get_logger
from .session import Session from .session import Session
......
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