perf: add xrdp rdp7 port 3390

pull/10880/head
Eric 2023-06-30 18:09:39 +08:00
parent 6b7df10d50
commit 6001175629
8 changed files with 120 additions and 5 deletions

View File

@ -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',],
}
]
}

View File

@ -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'],

View File

@ -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),
]

View File

@ -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))

View File

@ -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

View File

@ -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'),
),
]

View File

@ -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

View File

@ -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',
]