From 6001175629b09c5e639f7fa2afaf6bd7076e9250 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 30 Jun 2023 18:09:39 +0800 Subject: [PATCH] perf: add xrdp rdp7 port 3390 --- apps/assets/const/host.py | 8 ++- apps/assets/const/protocol.py | 9 +++ .../migrations/0120_auto_20230630_1555.py | 69 +++++++++++++++++++ apps/authentication/api/connection_token.py | 5 +- apps/terminal/connect_methods.py | 8 +++ .../migrations/0064_endpoint_rdp7_port.py | 20 ++++++ apps/terminal/models/component/endpoint.py | 4 ++ apps/terminal/serializers/endpoint.py | 2 +- 8 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 apps/assets/migrations/0120_auto_20230630_1555.py create mode 100644 apps/terminal/migrations/0064_endpoint_rdp7_port.py diff --git a/apps/assets/const/host.py b/apps/assets/const/host.py index afb92a447..60205ff2c 100644 --- a/apps/assets/const/host.py +++ b/apps/assets/const/host.py @@ -33,10 +33,10 @@ class HostTypes(BaseType): def _get_protocol_constrains(cls) -> dict: return { '*': { - 'choices': ['ssh', 'telnet', 'vnc', 'rdp'] + 'choices': ['ssh', 'telnet', 'vnc', 'rdp', 'rdp7'] }, cls.WINDOWS: { - 'choices': ['rdp', 'ssh', 'vnc', 'winrm'] + 'choices': ['rdp', 'rdp7', 'ssh', 'vnc', 'winrm'] } } @@ -116,6 +116,10 @@ class HostTypes(BaseType): 'required': True } } + }, + { + 'name': 'Windows-RDP7', + '_protocols': ['rdp7',], } ] } diff --git a/apps/assets/const/protocol.py b/apps/assets/const/protocol.py index e66dde209..e0c6ad25e 100644 --- a/apps/assets/const/protocol.py +++ b/apps/assets/const/protocol.py @@ -10,6 +10,7 @@ __all__ = ['Protocol'] class Protocol(ChoicesMixin, models.TextChoices): ssh = 'ssh', 'SSH' rdp = 'rdp', 'RDP' + rdp7 = 'rdp7', 'RDP7' telnet = 'telnet', 'Telnet' vnc = 'vnc', 'VNC' winrm = 'winrm', 'WinRM' @@ -69,6 +70,14 @@ class Protocol(ChoicesMixin, models.TextChoices): # } } }, + cls.rdp7: { + 'port': 3390, + 'secret_types': ['password'], + 'setting': { + 'console': False, + 'security': 'any', + } + }, cls.vnc: { 'port': 5900, 'secret_types': ['password'], diff --git a/apps/assets/migrations/0120_auto_20230630_1555.py b/apps/assets/migrations/0120_auto_20230630_1555.py new file mode 100644 index 000000000..6c303fdd7 --- /dev/null +++ b/apps/assets/migrations/0120_auto_20230630_1555.py @@ -0,0 +1,69 @@ +# Generated by Django 3.2.17 on 2023-06-30 07:55 + +import json + +from django.db import migrations + +platform_json_data = """{ + "category": "host", + "type": "windows", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Windows-RDP7", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_shell_type": "cmd", + "ansible_connection": "ssh" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ping_method": "win_ping", + "gather_facts_method": "gather_facts_windows", + "gather_accounts_method": "gather_accounts_windows", + "verify_account_method": "verify_account_windows", + "change_secret_method": "change_secret_local_windows", + "push_account_method": "push_account_local_windows" + }, + "protocols": [ + { + "name": "rdp7", + "port": 3390, + "setting": { + "console": false, + "security": "any" + }, + "primary": true, + "required": false, + "default": false + } + ] +}""" + + +def create_rdp7_internal_platform(apps, *args): + platform_cls = apps.get_model('assets', 'Platform') + platform_automation_cls = apps.get_model('assets', 'PlatformAutomation') + platform_data = json.loads(platform_json_data) + protocols = platform_data.pop('protocols') + automation_data = platform_data.pop('automation', {}) + rdp7_obj = platform_cls.objects.create(**platform_data) + for p in protocols: + rdp7_obj.protocols.create(**p) + platform_automation_cls.objects.create(platform=rdp7_obj, **automation_data) + + +class Migration(migrations.Migration): + dependencies = [ + ('assets', '0119_assets_add_default_node'), + ] + + operations = [ + migrations.RunPython(create_rdp7_internal_platform), + ] diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index 23344c9fb..149ecc791 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -75,8 +75,9 @@ class RDPFileClientProtocolURLMixin: rdp_options['screen mode id:i'] = '2' if full_screen else '1' # 设置 RDP Server 地址 - endpoint = self.get_smart_endpoint(protocol='rdp', asset=token.asset) - rdp_options['full address:s'] = f'{endpoint.host}:{endpoint.rdp_port}' + endpoint = self.get_smart_endpoint(protocol=token.protocol, asset=token.asset) + protocol_port = endpoint.get_protocol_port(token.protocol, 3389) + rdp_options['full address:s'] = f'{endpoint.host}:{protocol_port}' # 设置用户名 rdp_options['username:s'] = '{}|{}'.format(token.user.username, str(token.id)) diff --git a/apps/terminal/connect_methods.py b/apps/terminal/connect_methods.py index a4901b93c..c3446a630 100644 --- a/apps/terminal/connect_methods.py +++ b/apps/terminal/connect_methods.py @@ -22,6 +22,7 @@ class WebMethod(TextChoices): Protocol.ssh: [cls.web_cli, cls.web_sftp], Protocol.telnet: [cls.web_cli], Protocol.rdp: [cls.web_gui], + Protocol.rdp7: [cls.web_gui], Protocol.vnc: [cls.web_gui], Protocol.mysql: [cls.web_cli], @@ -67,6 +68,7 @@ class NativeClient(TextChoices): 'windows': [cls.putty], }, Protocol.rdp: [cls.mstsc], + Protocol.rdp7: [cls.mstsc], Protocol.mysql: [cls.db_client], Protocol.mariadb: [cls.db_client], Protocol.redis: [cls.db_client], @@ -214,6 +216,12 @@ class ConnectMethodUtil: 'support': [Protocol.rdp], 'match': 'map' }, + TerminalType.xrdp: { + 'web_methods': [], + 'listen': [Protocol.rdp7], + 'support': [Protocol.rdp7], + 'match': 'map' + }, } return protocols diff --git a/apps/terminal/migrations/0064_endpoint_rdp7_port.py b/apps/terminal/migrations/0064_endpoint_rdp7_port.py new file mode 100644 index 000000000..d76719287 --- /dev/null +++ b/apps/terminal/migrations/0064_endpoint_rdp7_port.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.17 on 2023-06-30 09:04 + +import common.db.fields +import django.core.validators +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('terminal', '0063_auto_20230621_1133'), + ] + + operations = [ + migrations.AddField( + model_name='endpoint', + name='rdp7_port', + field=common.db.fields.PortField(default=3390, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(65535)], verbose_name='RDP7 port'), + ), + ] diff --git a/apps/terminal/models/component/endpoint.py b/apps/terminal/models/component/endpoint.py index f19f72949..1295e3efd 100644 --- a/apps/terminal/models/component/endpoint.py +++ b/apps/terminal/models/component/endpoint.py @@ -16,6 +16,7 @@ class Endpoint(JMSBaseModel): http_port = PortField(default=80, verbose_name=_('HTTP port')) ssh_port = PortField(default=2222, verbose_name=_('SSH port')) rdp_port = PortField(default=3389, verbose_name=_('RDP port')) + rdp7_port = PortField(default=3390, verbose_name=_('RDP7 port')) mysql_port = PortField(default=33061, verbose_name=_('MySQL port')) mariadb_port = PortField(default=33062, verbose_name=_('MariaDB port')) postgresql_port = PortField(default=54320, verbose_name=_('PostgreSQL port')) @@ -42,6 +43,9 @@ class Endpoint(JMSBaseModel): port = getattr(self, f'{protocol}_port', 0) return port + def get_protocol_port(self, protocol, default=0): + return getattr(self, f'{protocol}_port', default) + def is_default(self): return str(self.id) == self.default_id diff --git a/apps/terminal/serializers/endpoint.py b/apps/terminal/serializers/endpoint.py index 82de09fce..aafd68aca 100644 --- a/apps/terminal/serializers/endpoint.py +++ b/apps/terminal/serializers/endpoint.py @@ -26,7 +26,7 @@ class EndpointSerializer(BulkModelSerializer): model = Endpoint fields_mini = ['id', 'name'] fields_small = [ - 'host', 'https_port', 'http_port', 'ssh_port', 'rdp_port', + 'host', 'https_port', 'http_port', 'ssh_port', 'rdp_port', 'rdp7_port', 'mysql_port', 'mariadb_port', 'postgresql_port', 'redis_port', 'oracle_port_range', 'oracle_port', ]