mirror of https://github.com/jumpserver/jumpserver
perf: 添加 terminal 的 migrate
parent
0f2c769e8d
commit
df091f0ee1
|
@ -146,7 +146,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer, ResourceLabelsMixin, Writa
|
||||||
fields_unexport = ['auto_config']
|
fields_unexport = ['auto_config']
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'auto_config': {'label': _('Auto info')},
|
'auto_config': {'label': _('Auto info')},
|
||||||
'name': {'label': _("Name")},
|
'name': {'label': _("Name"), 'initial': 'Asset name'},
|
||||||
'address': {'label': _('Address')},
|
'address': {'label': _('Address')},
|
||||||
'nodes_display': {'label': _('Node path')},
|
'nodes_display': {'label': _('Node path')},
|
||||||
'nodes': {'allow_empty': True, 'label': _("Nodes")},
|
'nodes': {'allow_empty': True, 'label': _("Nodes")},
|
||||||
|
|
|
@ -4,10 +4,10 @@ from django.db.models import Count, Q
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from assets.models.gateway import Gateway
|
||||||
from common.serializers import ResourceLabelsMixin
|
from common.serializers import ResourceLabelsMixin
|
||||||
from common.serializers.fields import ObjectRelatedField
|
from common.serializers.fields import ObjectRelatedField
|
||||||
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
||||||
from assets.models.gateway import Gateway
|
|
||||||
from .gateway import GatewayWithAccountSecretSerializer
|
from .gateway import GatewayWithAccountSecretSerializer
|
||||||
from ..models import Domain
|
from ..models import Domain
|
||||||
|
|
||||||
|
@ -16,7 +16,10 @@ __all__ = ['DomainSerializer', 'DomainWithGatewaySerializer', 'DomainListSeriali
|
||||||
|
|
||||||
class DomainSerializer(ResourceLabelsMixin, BulkOrgResourceModelSerializer):
|
class DomainSerializer(ResourceLabelsMixin, BulkOrgResourceModelSerializer):
|
||||||
gateways = ObjectRelatedField(
|
gateways = ObjectRelatedField(
|
||||||
many=True, required=False, label=_('Gateway'), queryset=Gateway.objects
|
many=True, required=False, label=_('Gateway'), queryset=Gateway.objects,
|
||||||
|
help_text=_(
|
||||||
|
"A gateway is a network proxy for a zone, and when connecting assets within the zone, "
|
||||||
|
"the connection is routed through the gateway.")
|
||||||
)
|
)
|
||||||
assets_amount = serializers.IntegerField(label=_('Assets amount'), read_only=True)
|
assets_amount = serializers.IntegerField(label=_('Assets amount'), read_only=True)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"AccessIP": "Ip whitelist",
|
"AccessIP": "Ip whitelist",
|
||||||
"AccessKey": "Access key",
|
"AccessKey": "Access key",
|
||||||
"Account": "Account",
|
"Account": "Account",
|
||||||
|
"NoPermissionInGlobal": "No permission in GLOBAL",
|
||||||
"AccountTemplateList": "Account templates",
|
"AccountTemplateList": "Account templates",
|
||||||
"AccountBackup": "Backup accounts",
|
"AccountBackup": "Backup accounts",
|
||||||
"AccountBackupCreate": "Create account backup",
|
"AccountBackupCreate": "Create account backup",
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
# Generated by Django 2.2.5 on 2019-11-25 01:31
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def get_storage_data(s):
|
||||||
|
from common.utils import signer
|
||||||
|
import json
|
||||||
|
|
||||||
|
value = s.value
|
||||||
|
encrypted = s.encrypted
|
||||||
|
if encrypted:
|
||||||
|
value = signer.unsign(value)
|
||||||
|
try:
|
||||||
|
value = json.loads(value)
|
||||||
|
except:
|
||||||
|
value = {}
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def get_setting(apps, schema_editor, key):
|
||||||
|
model = apps.get_model("settings", "Setting")
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
setting = model.objects.using(db_alias).filter(name=key)
|
||||||
|
if not setting:
|
||||||
|
return
|
||||||
|
return setting[0]
|
||||||
|
|
||||||
|
|
||||||
|
def init_storage_data(model):
|
||||||
|
model.objects.update_or_create(
|
||||||
|
name="null",
|
||||||
|
type="null",
|
||||||
|
is_default=False,
|
||||||
|
defaults={
|
||||||
|
"name": "null",
|
||||||
|
"type": "null",
|
||||||
|
"comment": "Do not save",
|
||||||
|
"meta": "{}",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
model.objects.update_or_create(
|
||||||
|
name="default",
|
||||||
|
type="server",
|
||||||
|
is_default=True,
|
||||||
|
defaults={
|
||||||
|
"name": "default",
|
||||||
|
"type": "server",
|
||||||
|
"comment": "Store locally",
|
||||||
|
"meta": "{}",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_command_storage(apps, schema_editor):
|
||||||
|
model = apps.get_model("terminal", "CommandStorage")
|
||||||
|
init_storage_data(model)
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_replay_storage(apps, schema_editor):
|
||||||
|
model = apps.get_model("terminal", "ReplayStorage")
|
||||||
|
init_storage_data(model)
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_endpoints(apps, schema_editor):
|
||||||
|
Endpoint = apps.get_model("terminal", "Endpoint")
|
||||||
|
# migrate default
|
||||||
|
default_data = {
|
||||||
|
"id": "00000000-0000-0000-0000-000000000001",
|
||||||
|
"name": "Default",
|
||||||
|
"host": "",
|
||||||
|
"https_port": 0,
|
||||||
|
"http_port": 0,
|
||||||
|
"created_by": "System",
|
||||||
|
}
|
||||||
|
Endpoint.objects.create(**default_data)
|
||||||
|
|
||||||
|
if not settings.TERMINAL_RAZOR_ENABLED:
|
||||||
|
return
|
||||||
|
# migrate xrdp
|
||||||
|
xrdp_addr = settings.TERMINAL_RDP_ADDR
|
||||||
|
if ":" in xrdp_addr:
|
||||||
|
host, rdp_port = xrdp_addr.strip().split(":")
|
||||||
|
else:
|
||||||
|
host, rdp_port = xrdp_addr, 3389
|
||||||
|
host = host.strip()
|
||||||
|
if host in ["localhost", "127.0.0.1"]:
|
||||||
|
host = ""
|
||||||
|
if not host:
|
||||||
|
return
|
||||||
|
if isinstance(rdp_port, str) and rdp_port.isdigit():
|
||||||
|
rdp_port = int(rdp_port)
|
||||||
|
elif isinstance(rdp_port, int) and (0 <= rdp_port <= 65535):
|
||||||
|
rdp_port = rdp_port
|
||||||
|
else:
|
||||||
|
rdp_port = 3389
|
||||||
|
xrdp_data = {
|
||||||
|
"name": "Razor",
|
||||||
|
"host": host,
|
||||||
|
"https_port": 0,
|
||||||
|
"http_port": 0,
|
||||||
|
"ssh_port": 0,
|
||||||
|
"rdp_port": rdp_port,
|
||||||
|
"mysql_port": 0,
|
||||||
|
"mariadb_port": 0,
|
||||||
|
"postgresql_port": 0,
|
||||||
|
"created_by": "System",
|
||||||
|
}
|
||||||
|
xrdp_endpoint = Endpoint.objects.create(**xrdp_data)
|
||||||
|
|
||||||
|
EndpointRule = apps.get_model("terminal", "EndpointRule")
|
||||||
|
xrdp_rule_data = {
|
||||||
|
"name": "Razor",
|
||||||
|
"ip_group": ["*"],
|
||||||
|
"priority": 20,
|
||||||
|
"endpoint": xrdp_endpoint,
|
||||||
|
"created_by": "System",
|
||||||
|
}
|
||||||
|
EndpointRule.objects.create(**xrdp_rule_data)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("settings", "0001_initial"),
|
||||||
|
("terminal", "0002_auto_20171228_0025"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(migrate_command_storage),
|
||||||
|
migrations.RunPython(migrate_replay_storage),
|
||||||
|
migrations.RunPython(migrate_endpoints),
|
||||||
|
]
|
|
@ -165,6 +165,12 @@ class UserSerializer(RolesSerializerMixin, ResourceLabelsMixin, CommonBulkModelS
|
||||||
fields_only_root_org = ["orgs_roles"]
|
fields_only_root_org = ["orgs_roles"]
|
||||||
disallow_self_update_fields = ["is_active", "system_roles", "org_roles"]
|
disallow_self_update_fields = ["is_active", "system_roles", "org_roles"]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
|
"name": {
|
||||||
|
"help_text": _("Fullname of user"),
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"help_text": _("Login username"),
|
||||||
|
},
|
||||||
"password": {
|
"password": {
|
||||||
"write_only": True,
|
"write_only": True,
|
||||||
"required": False,
|
"required": False,
|
||||||
|
|
Loading…
Reference in New Issue