Compare commits

...

9 Commits

Author SHA1 Message Date
wangruidong
dfb6cc990b fix: ldap定时任务未执行 2024-05-07 10:27:20 +08:00
Aaron3S
4f287925f3 fix: 修复执行快捷命令时 local_connection 没有被正确设置 2024-04-23 19:06:53 +08:00
Bai
422478f9fb fix: Adhoc support mariadb with module of mysql 2024-04-23 18:56:49 +08:00
吴小白
a748a5f421 perf: 镜像添加 nc 命令 2024-04-23 16:53:07 +08:00
Bai
6f89fa245c fix: 修改配置 RECEPTOR_ENABLED=False 默认 2024-04-23 16:52:25 +08:00
Bai
31c5d9e717 fix: 修改配置 RECEPTOR_ENABLED 2024-04-23 15:02:40 +08:00
Aaron3S
a3a907e9bb feat: 修改 receptor 容器通信地址 2024-04-23 13:12:00 +08:00
Bai
361b367e30 perf: 优化 Web 资产详情时根据 autofill 类型返回对应的 spec_info 信息 2024-04-23 13:11:41 +08:00
jiangweidong
08bd628589 perf: 优化会话过期500问题 2024-04-23 13:11:15 +08:00
11 changed files with 54 additions and 12 deletions

View File

@@ -87,6 +87,7 @@ ARG TOOLS=" \
default-mysql-client \ default-mysql-client \
iputils-ping \ iputils-ping \
locales \ locales \
netcat-openbsd \
nmap \ nmap \
openssh-client \ openssh-client \
patch \ patch \

View File

@@ -22,6 +22,36 @@ class WebSpecSerializer(serializers.ModelSerializer):
'submit_selector', 'script' 'submit_selector', 'script'
] ]
def get_fields(self):
fields = super().get_fields()
if self.is_retrieve():
# 查看 Web 资产详情时
self.pop_fields_if_need(fields)
return fields
def is_retrieve(self):
try:
self.context.get('request').method and self.parent.instance.web
return True
except Exception:
return False
def pop_fields_if_need(self, fields):
fields_script = ['script']
fields_basic = ['username_selector', 'password_selector', 'submit_selector']
autofill = self.parent.instance.web.autofill
pop_fields_mapper = {
FillType.no: fields_script + fields_basic,
FillType.basic: fields_script,
FillType.script: fields_basic,
}
fields_pop = pop_fields_mapper.get(autofill, [])
for f in fields_pop:
fields.pop(f, None)
return fields
category_spec_serializer_map = { category_spec_serializer_map = {
'database': DatabaseSpecSerializer, 'database': DatabaseSpecSerializer,

View File

@@ -50,7 +50,10 @@ class MFASendCodeApi(AuthMixin, CreateAPIView):
mfa_type = serializer.validated_data['type'] mfa_type = serializer.validated_data['type']
if not username: if not username:
user = self.get_user_from_session() try:
user = self.get_user_from_session()
except errors.SessionEmptyError as e:
raise ValidationError({'error': e})
else: else:
user = self.get_user_from_db(username) user = self.get_user_from_db(username)

View File

@@ -617,9 +617,9 @@ class Config(dict):
'TICKET_APPLY_ASSET_SCOPE': 'all', 'TICKET_APPLY_ASSET_SCOPE': 'all',
# Ansible Receptor # Ansible Receptor
'ANSIBLE_RECEPTOR_ENABLED': True, 'RECEPTOR_ENABLED': False,
'ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST': 'jms_celery', 'ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST': 'jms_celery',
'ANSIBLE_RECEPTOR_TCP_LISTEN_ADDRESS': 'jms_receptor:7521' 'ANSIBLE_RECEPTOR_TCP_LISTEN_ADDRESS': 'receptor:7521'
} }

View File

@@ -232,6 +232,6 @@ FILE_UPLOAD_SIZE_LIMIT_MB = CONFIG.FILE_UPLOAD_SIZE_LIMIT_MB
TICKET_APPLY_ASSET_SCOPE = CONFIG.TICKET_APPLY_ASSET_SCOPE TICKET_APPLY_ASSET_SCOPE = CONFIG.TICKET_APPLY_ASSET_SCOPE
# Ansible Receptor # Ansible Receptor
ANSIBLE_RECEPTOR_ENABLED = CONFIG.ANSIBLE_RECEPTOR_ENABLED RECEPTOR_ENABLED = CONFIG.RECEPTOR_ENABLED
ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST = CONFIG.ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST = CONFIG.ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST
ANSIBLE_RECEPTOR_TCP_LISTEN_ADDRESS = CONFIG.ANSIBLE_RECEPTOR_TCP_LISTEN_ADDRESS ANSIBLE_RECEPTOR_TCP_LISTEN_ADDRESS = CONFIG.ANSIBLE_RECEPTOR_TCP_LISTEN_ADDRESS

View File

@@ -15,7 +15,7 @@ class _LazyRunnerInterface(LazyObject):
@staticmethod @staticmethod
def make_interface(): def make_interface():
runner_type = AnsibleReceptorRunner \ runner_type = AnsibleReceptorRunner \
if settings.ANSIBLE_RECEPTOR_ENABLED else AnsibleNativeRunner if settings.RECEPTOR_ENABLED else AnsibleNativeRunner
gateway_host = settings.ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST \ gateway_host = settings.ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST \
if settings.ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST else '127.0.0.1' if settings.ANSIBLE_RECEPTOR_GATEWAY_PROXY_HOST else '127.0.0.1'
return RunnerInterface(runner_type=runner_type, gateway_proxy_host=gateway_host) return RunnerInterface(runner_type=runner_type, gateway_proxy_host=gateway_host)

View File

@@ -14,8 +14,10 @@ __all__ = ['AdHocRunner', 'PlaybookRunner', 'SuperPlaybookRunner', 'UploadFileRu
class AdHocRunner: class AdHocRunner:
cmd_modules_choices = ('shell', 'raw', 'command', 'script', 'win_shell') cmd_modules_choices = ('shell', 'raw', 'command', 'script', 'win_shell')
need_local_connection_modules_choices = ("mysql", "postgresql", "sqlserver", "huawei")
def __init__(self, inventory, module, module_args='', pattern='*', project_dir='/tmp/', extra_vars=None, def __init__(self, inventory, job_module, module, module_args='', pattern='*', project_dir='/tmp/',
extra_vars=None,
dry_run=False, timeout=-1): dry_run=False, timeout=-1):
if extra_vars is None: if extra_vars is None:
extra_vars = {} extra_vars = {}
@@ -23,6 +25,7 @@ class AdHocRunner:
self.inventory = inventory self.inventory = inventory
self.pattern = pattern self.pattern = pattern
self.module = module self.module = module
self.job_module = job_module
self.module_args = module_args self.module_args = module_args
self.project_dir = project_dir self.project_dir = project_dir
self.cb = DefaultCallback() self.cb = DefaultCallback()
@@ -30,8 +33,7 @@ class AdHocRunner:
self.extra_vars = extra_vars self.extra_vars = extra_vars
self.dry_run = dry_run self.dry_run = dry_run
self.timeout = timeout self.timeout = timeout
# enable local connection self.envs = {}
self.extra_vars.update({"LOCAL_CONNECTION_ENABLED": "1"})
def check_module(self): def check_module(self):
if self.module not in self.cmd_modules_choices: if self.module not in self.cmd_modules_choices:
@@ -40,8 +42,13 @@ class AdHocRunner:
raise CommandInBlackListException( raise CommandInBlackListException(
"Command is rejected by black list: {}".format(self.module_args.split()[0])) "Command is rejected by black list: {}".format(self.module_args.split()[0]))
def set_local_connection(self):
if self.job_module in self.need_local_connection_modules_choices:
self.envs.update({"LOCAL_CONNECTION_ENABLED": "1"})
def run(self, verbosity=0, **kwargs): def run(self, verbosity=0, **kwargs):
self.check_module() self.check_module()
self.set_local_connection()
verbosity = get_ansible_log_verbosity(verbosity) verbosity = get_ansible_log_verbosity(verbosity)
if not os.path.exists(self.project_dir): if not os.path.exists(self.project_dir):
@@ -53,6 +60,7 @@ class AdHocRunner:
interface.run( interface.run(
timeout=self.timeout if self.timeout > 0 else None, timeout=self.timeout if self.timeout > 0 else None,
extravars=self.extra_vars, extravars=self.extra_vars,
envvars=self.envs,
host_pattern=self.pattern, host_pattern=self.pattern,
private_data_dir=self.project_dir, private_data_dir=self.project_dir,
inventory=self.inventory, inventory=self.inventory,

View File

@@ -67,6 +67,7 @@ class JMSPermedInventory(JMSInventory):
protocol_supported_modules_mapping = { protocol_supported_modules_mapping = {
'mysql': ['mysql'], 'mysql': ['mysql'],
'mariadb': ['mysql'],
'postgresql': ['postgresql'], 'postgresql': ['postgresql'],
'sqlserver': ['sqlserver'], 'sqlserver': ['sqlserver'],
'ssh': ['shell', 'python', 'win_shell', 'raw', 'huawei'], 'ssh': ['shell', 'python', 'win_shell', 'raw', 'huawei'],
@@ -77,7 +78,7 @@ class JMSPermedInventory(JMSInventory):
host['error'] = "Module {} is not suitable for this asset".format(self.module) host['error'] = "Module {} is not suitable for this asset".format(self.module)
return host return host
if protocol.name in ('mysql', 'postgresql', 'sqlserver'): if protocol.name in ('mariadb', 'mysql', 'postgresql', 'sqlserver'):
host['login_host'] = asset.address host['login_host'] = asset.address
host['login_port'] = protocol.port host['login_port'] = protocol.port
host['login_user'] = account.username host['login_user'] = account.username
@@ -333,6 +334,7 @@ class JobExecution(JMSOrgBaseModel):
runner = AdHocRunner( runner = AdHocRunner(
self.inventory_path, self.inventory_path,
self.job.module,
module, module,
timeout=self.current_job.timeout, timeout=self.current_job.timeout,
module_args=args, module_args=args,

View File

@@ -69,7 +69,6 @@ def import_ldap_user_periodic():
if not settings.AUTH_LDAP: if not settings.AUTH_LDAP:
return return
task_name = 'import_ldap_user_periodic' task_name = 'import_ldap_user_periodic'
disable_celery_periodic_task(task_name)
if not settings.AUTH_LDAP_SYNC_IS_PERIODIC: if not settings.AUTH_LDAP_SYNC_IS_PERIODIC:
return return

View File

@@ -120,7 +120,7 @@
function onError (responseText, responseJson, status) { function onError (responseText, responseJson, status) {
setTimeout(function () { setTimeout(function () {
toastr.error(responseJson.detail); toastr.error(responseJson.detail || responseJson.error);
}); });
}; };

View File

@@ -75,7 +75,6 @@ class ReceptorService:
print("\n- PID file is corrupted, starting Receptor...") print("\n- PID file is corrupted, starting Receptor...")
os.remove(self.pid_file) os.remove(self.pid_file)
os.environ.update({'LOCAL_CONNECTION_ENABLED': '1'})
os.environ.setdefault('ANSIBLE_LIBRARY', DEFAULT_ANSIBLE_MODULES_DIR) os.environ.setdefault('ANSIBLE_LIBRARY', DEFAULT_ANSIBLE_MODULES_DIR)
os.environ.update({'PYTHONPATH': APPS_DIR}) os.environ.update({'PYTHONPATH': APPS_DIR})
process = subprocess.Popen(self.receptor_command) process = subprocess.Popen(self.receptor_command)