mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Added new fields to udsactor registration and better config values check on udstunnel
This commit is contained in:
parent
1c301d890d
commit
62540b2773
@ -78,6 +78,16 @@ class BlockAccess(Exception):
|
||||
|
||||
# Helpers
|
||||
def fixIdsList(idsList: typing.List[str]) -> typing.List[str]:
|
||||
"""
|
||||
Params:
|
||||
idsList: List of ids to fix
|
||||
|
||||
Returns:
|
||||
List of ids with both upper and lower case
|
||||
|
||||
Comment:
|
||||
Due to database case sensitiveness, we need to check for both upper and lower case
|
||||
"""
|
||||
return list(set([i.upper() for i in idsList] + [i.lower() for i in idsList]))
|
||||
|
||||
|
||||
@ -201,6 +211,8 @@ class Register(ActorV3Action):
|
||||
- run_once_command: comand to run just once after the actor is started. The actor will stop after this.
|
||||
The command is responsible to restart the actor.
|
||||
- log_level: log level for the actor
|
||||
- certificate: server certificate used to connect to the actor [optional, only for some kind of actors like LinuxApps]
|
||||
- comms_url: url to connect to the actor [optional, only for some kind of actors like LinuxApps]
|
||||
|
||||
"""
|
||||
|
||||
@ -223,24 +235,34 @@ class Register(ActorV3Action):
|
||||
actorToken.post_command = self._params['post_command']
|
||||
actorToken.runonce_command = self._params['run_once_command']
|
||||
actorToken.log_level = self._params['log_level']
|
||||
if 'certificate' in self._params:
|
||||
actorToken.certificate = self._params['certificate']
|
||||
if 'comms_url' in self._params:
|
||||
actorToken.comms_url = self._params['comms_url']
|
||||
actorToken.stamp = getSqlDatetime()
|
||||
actorToken.save()
|
||||
logger.info('Registered actor %s', self._params)
|
||||
except Exception: # Not found, create a new token
|
||||
actorToken = ActorToken.objects.create(
|
||||
username=self._user.pretty_name,
|
||||
ip_from=self._request.ip,
|
||||
ip=self._params['ip'],
|
||||
ip_version=self._request.ip_version,
|
||||
hostname=self._params['hostname'],
|
||||
mac=self._params['mac'],
|
||||
pre_command=self._params['pre_command'],
|
||||
post_command=self._params['post_command'],
|
||||
runonce_command=self._params['run_once_command'],
|
||||
log_level=self._params['log_level'],
|
||||
token=secrets.token_urlsafe(36),
|
||||
stamp=getSqlDatetime(),
|
||||
)
|
||||
kwargs = {
|
||||
'username': self._user.pretty_name,
|
||||
'ip_from': self._request.ip,
|
||||
'ip': self._params['ip'],
|
||||
'ip_version': self._request.ip_version,
|
||||
'hostname': self._params['hostname'],
|
||||
'mac': self._params['mac'],
|
||||
'pre_command': self._params['pre_command'],
|
||||
'post_command': self._params['post_command'],
|
||||
'runonce_command': self._params['run_once_command'],
|
||||
'log_level': self._params['log_level'],
|
||||
'token': secrets.token_urlsafe(36),
|
||||
'stamp': getSqlDatetime(),
|
||||
}
|
||||
if 'certificate' in self._params:
|
||||
kwargs['certificate'] = self._params['certificate']
|
||||
if 'comms_url' in self._params:
|
||||
kwargs['comms_url'] = self._params['comms_url']
|
||||
|
||||
actorToken = ActorToken.objects.create(**kwargs)
|
||||
return ActorV3Action.actorResult(actorToken.token)
|
||||
|
||||
|
||||
@ -292,7 +314,10 @@ class Initialize(ActorV3Action):
|
||||
alias_token: typing.Optional[str] = None
|
||||
|
||||
def initialization_result(
|
||||
own_token: typing.Optional[str], unique_id: typing.Optional[str], os: typing.Any, alias_token: typing.Optional[str]
|
||||
own_token: typing.Optional[str],
|
||||
unique_id: typing.Optional[str],
|
||||
os: typing.Any,
|
||||
alias_token: typing.Optional[str],
|
||||
) -> typing.MutableMapping[str, typing.Any]:
|
||||
return ActorV3Action.actorResult(
|
||||
{
|
||||
|
@ -0,0 +1,27 @@
|
||||
# Generated by Django 4.2 on 2023-05-10 22:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("uds", "0044_notification_notifier_servicetokenalias_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="actortoken",
|
||||
name="certificate",
|
||||
field=models.TextField(blank=True, default=""),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="actortoken",
|
||||
name="comms_url",
|
||||
field=models.CharField(blank=True, default="", max_length=255),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="log",
|
||||
name="name",
|
||||
field=models.CharField(default="", max_length=64),
|
||||
),
|
||||
]
|
@ -1,17 +0,0 @@
|
||||
# Generated by Django 4.2 on 2023-04-20 03:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("uds", "0044_notification_notifier_servicetokenalias_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="log",
|
||||
name="name",
|
||||
field=models.CharField(default="", max_length=64),
|
||||
),
|
||||
]
|
@ -53,6 +53,10 @@ class ActorToken(models.Model):
|
||||
token = models.CharField(max_length=48, db_index=True, unique=True)
|
||||
stamp = models.DateTimeField() # Date creation or validation of this entry
|
||||
|
||||
# New fields for 4.0, optional certificate and comms_url
|
||||
certificate = models.TextField(blank=True, default='')
|
||||
comms_url = models.CharField(max_length=255, blank=True, default='')
|
||||
|
||||
class Meta: # pylint: disable=too-few-public-methods
|
||||
app_label = 'uds'
|
||||
|
||||
|
@ -152,14 +152,24 @@ async def tunnel_proc_async(
|
||||
|
||||
# Set min version from string (1.2 or 1.3) as ssl.TLSVersion.TLSv1_2 or ssl.TLSVersion.TLSv1_3
|
||||
if cfg.ssl_min_tls_version in ('1.2', '1.3'):
|
||||
context.minimum_version = getattr(ssl.TLSVersion, f'TLSv1_{cfg.ssl_min_tls_version.split(".")[1]}')
|
||||
try:
|
||||
context.minimum_version = getattr(ssl.TLSVersion, f'TLSv1_{cfg.ssl_min_tls_version.split(".")[1]}')
|
||||
except Exception as e:
|
||||
logger.exception('Setting min tls version failed: %s. Using defaults', e)
|
||||
context.minimum_version = ssl.TLSVersion.TLSv1_2
|
||||
# Any other value will be ignored
|
||||
|
||||
if cfg.ssl_ciphers:
|
||||
context.set_ciphers(cfg.ssl_ciphers)
|
||||
try:
|
||||
context.set_ciphers(cfg.ssl_ciphers)
|
||||
except Exception as e:
|
||||
logger.exception('Setting ciphers failed: %s. Using defaults', e)
|
||||
|
||||
if cfg.ssl_dhparam:
|
||||
context.load_dh_params(cfg.ssl_dhparam)
|
||||
try:
|
||||
context.load_dh_params(cfg.ssl_dhparam)
|
||||
except Exception as e:
|
||||
logger.exception('Loading dhparams failed: %s. Using defaults', e)
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
Loading…
Reference in New Issue
Block a user