Compare commits

...

10 Commits

Author SHA1 Message Date
jorgepastorr 880991984f merge migrations 2023-11-26 11:31:07 +01:00
Jorge Pastor febc2783fd commet conflict lines in migrations systemusers 2023-11-26 09:52:03 +00:00
Jorge Pastor 7a6d4783d0 mailbox not change pass on single reload 2023-11-26 09:52:03 +00:00
Jorge Pastor f8b05b24e5 max length 32 databaseuser 2023-11-26 09:52:03 +00:00
Jorge Pastor 7a8c6c9b90 nextcloud size on cron 2023-11-26 09:52:03 +00:00
Jorge Pastor 2cd20465c9 fix resource agragation otion last value query 2023-11-26 09:52:03 +00:00
Jorge Pastor 44b2720b3e change update user password on mysql 2023-11-26 09:52:03 +00:00
jorgepastorr 70224b3391 add icon nextcloud on SAS 2023-11-26 09:52:03 +00:00
jorgepastorr 5a6b972b51 fix last nyapa with target_server on SAS 2023-11-26 09:52:03 +00:00
jorgepastorr c94342141e nyapa hiden target server in SAS 2023-11-26 09:52:03 +00:00
14 changed files with 83 additions and 32 deletions

6
.gitignore vendored
View File

@ -7,3 +7,9 @@
local_settings.py local_settings.py
build build
*.egg-info *.egg-info
/.Trash*
/.git
/.idea
.idea
.Trash-1000/

View File

@ -89,20 +89,12 @@ class MySQLUserController(ServiceController):
if user.type != user.MYSQL: if user.type != user.MYSQL:
return return
context = self.get_context(user) context = self.get_context(user)
if user.target_server.name != "mysql.pangea.lan": self.append(textwrap.dedent("""\
self.append(textwrap.dedent("""\ # Create user %(username)s
# Create user %(username)s mysql -e 'CREATE USER IF NOT EXISTS "%(username)s"@"%(host)s";'
mysql -e 'CREATE USER IF NOT EXISTS "%(username)s"@"%(host)s";' mysql -e 'ALTER USER IF EXISTS "%(username)s"@"%(host)s" IDENTIFIED BY PASSWORD "%(password)s";'\
mysql -e 'ALTER USER IF EXISTS "%(username)s"@"%(host)s" IDENTIFIED BY PASSWORD "%(password)s";'\ """) % context
""") % context )
)
else:
self.append(textwrap.dedent("""\
# Create user %(username)s
mysql -e 'CREATE USER "%(username)s"@"%(host)s";' || true # User already exists
mysql -e 'UPDATE mysql.user SET Password="%(password)s" WHERE User="%(username)s";'\
""") % context
)
def delete(self, user): def delete(self, user):
if user.type != user.MYSQL: if user.type != user.MYSQL:

View File

@ -58,12 +58,12 @@ class DatabaseForm(forms.ModelForm):
class DatabaseCreationForm(DatabaseUserCreationForm): class DatabaseCreationForm(DatabaseUserCreationForm):
username = forms.CharField(label=_("Username"), max_length=16, username = forms.CharField(label=_("Username"), max_length=32,
required=False, validators=[validators.validate_name], required=False, validators=[validators.validate_name],
help_text=_("Required. 16 characters or fewer. Letters, digits and " help_text=_("Required. 32 characters or fewer. Letters, digits and "
"@/./+/-/_ only."), "@/./+/-/_ only."),
error_messages={ error_messages={
'invalid': _("This value may contain 16 characters or fewer, only letters, numbers and " 'invalid': _("This value may contain 32 characters or fewer, only letters, numbers and "
"@/./+/-/_ characters.")}) "@/./+/-/_ characters.")})
user = forms.ModelChoiceField(required=False, queryset=DatabaseUser.objects) user = forms.ModelChoiceField(required=False, queryset=DatabaseUser.objects)

View File

@ -213,6 +213,8 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
old = Mailbox.objects.get(pk=obj.pk) old = Mailbox.objects.get(pk=obj.pk)
if old.custom_filtering != obj.custom_filtering: if old.custom_filtering != obj.custom_filtering:
messages.warning(request, msg) messages.warning(request, msg)
# pass var to the backend so you don't change the password
obj.changepass = None
elif obj.custom_filtering: elif obj.custom_filtering:
messages.warning(request, msg) messages.warning(request, msg)
super(MailboxAdmin, self).save_model(request, obj, form, change) super(MailboxAdmin, self).save_model(request, obj, form, change)

View File

@ -69,13 +69,15 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController):
self.append(textwrap.dedent(""" self.append(textwrap.dedent("""
# Update/create %(user)s user state # Update/create %(user)s user state
if id %(user)s ; then if id %(user)s ; then
old_password=$(getent shadow %(user)s | cut -d':' -f2) if [[ "%(changepass)s" == "True" ]]; then
usermod %(user)s \\ old_password=$(getent shadow %(user)s | cut -d':' -f2)
--shell %(initial_shell)s \\ usermod %(user)s \\
--password '%(password)s' --shell %(initial_shell)s \\
if [[ "$old_password" != '%(password)s' ]]; then --password '%(password)s'
# Postfix SASL caches passwords if [[ "$old_password" != '%(password)s' ]]; then
RESTART_POSTFIX=1 # Postfix SASL caches passwords
RESTART_POSTFIX=1
fi
fi fi
else else
useradd %(user)s \\ useradd %(user)s \\
@ -135,6 +137,11 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController):
super().commit() super().commit()
def get_context(self, mailbox): def get_context(self, mailbox):
# Check if you have to change password
try:
changepass = mailbox.changepass
except:
changepass = True
context = { context = {
'user': mailbox.name, 'user': mailbox.name,
'group': mailbox.name, 'group': mailbox.name,
@ -144,6 +151,7 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController):
'maildir': os.path.join(mailbox.get_home(), 'Maildir'), 'maildir': os.path.join(mailbox.get_home(), 'Maildir'),
'initial_shell': self.SHELL, 'initial_shell': self.SHELL,
'banner': self.get_banner(), 'banner': self.get_banner(),
'changepass': changepass,
} }
context['deleted_home'] = settings.MAILBOXES_MOVE_ON_DELETE_PATH % context context['deleted_home'] = settings.MAILBOXES_MOVE_ON_DELETE_PATH % context
return context return context

View File

@ -32,7 +32,12 @@ class Last(Aggregation):
verbose_name = _("Last value") verbose_name = _("Last value")
def filter(self, dataset, date=None): def filter(self, dataset, date=None):
dataset = dataset.order_by('object_id', '-id').distinct('monitor')
# dataset = dataset.order_by('object_id', '-id').distinct('monitor')
now = timezone.now()
epoch = now - datetime.timedelta(minutes=2)
dataset = dataset.filter( created_at__range=(epoch, now ))
if date is not None: if date is not None:
dataset = dataset.filter(created_at__lte=date) dataset = dataset.filter(created_at__lte=date)
return dataset return dataset

View File

@ -19,7 +19,7 @@ class NextCloudAPIMixin(object):
def validate_response(self, response): def validate_response(self, response):
request = response.request request = response.request
context = (request.method, response.url, request.body, response.status_code) context = (request.method, response.url, request.body, response.status_code)
sys.stderr.write("%s %s '%s' HTTP %s\n" % context) # sys.stderr.write("%s %s '%s' HTTP %s\n" % context)
if response.status_code != requests.codes.ok: if response.status_code != requests.codes.ok:
raise RuntimeError("%s %s '%s' HTTP %s" % context) raise RuntimeError("%s %s '%s' HTTP %s" % context)
root = ET.fromstring(response.text) root = ET.fromstring(response.text)

View File

@ -700,7 +700,6 @@ class UNIXUserControllerNewServers(ServiceController):
def get_groups(self, user): def get_groups(self, user):
groups = [] groups = []
if user.is_main: if user.is_main:
groups = list(user.account.systemusers.exclude(username=user.username).values_list('username', flat=True))
groups.append("main-systemusers") groups.append("main-systemusers")
return groups return groups

View File

@ -11,7 +11,7 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL), # migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
operations = [ operations = [
@ -25,7 +25,7 @@ class Migration(migrations.Migration):
('directory', models.CharField(blank=True, help_text="Optional directory relative to user's home.", max_length=256, verbose_name='directory')), ('directory', models.CharField(blank=True, help_text="Optional directory relative to user's home.", max_length=256, verbose_name='directory')),
('shell', models.CharField(choices=[('/dev/null', 'No shell, FTP only'), ('/bin/rssh', 'No shell, SFTP/RSYNC only'), ('/usr/bin/git-shell', 'No shell, GIT only'), ('/bin/bash', '/bin/bash')], default='/dev/null', max_length=32, verbose_name='shell')), ('shell', models.CharField(choices=[('/dev/null', 'No shell, FTP only'), ('/bin/rssh', 'No shell, SFTP/RSYNC only'), ('/usr/bin/git-shell', 'No shell, GIT only'), ('/bin/bash', '/bin/bash')], default='/dev/null', max_length=32, verbose_name='shell')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this account should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), ('is_active', models.BooleanField(default=True, help_text='Designates whether this account should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='systemusers', to=settings.AUTH_USER_MODEL, verbose_name='Account')), # ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='systemusers', to=settings.AUTH_USER_MODEL, verbose_name='Account')),
('groups', models.ManyToManyField(blank=True, help_text='A new group will be created for the user. Which additional groups would you like them to be a member of?', to='systemusers.SystemUser')), ('groups', models.ManyToManyField(blank=True, help_text='A new group will be created for the user. Which additional groups would you like them to be a member of?', to='systemusers.SystemUser')),
], ],
), ),

View File

@ -0,0 +1,14 @@
# Generated by Django 2.2.28 on 2023-11-26 09:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('systemusers', '0002_auto_20150429_1413_squashed_0004_auto_20210330_1049'),
('systemusers', '0004_auto_20230813_0920'),
]
operations = [
]

View File

@ -6,5 +6,4 @@ from orchestra.admin.utils import admin_date
display_last_run_at = admin_date('last_run_at', short_description=_("Last run")) display_last_run_at = admin_date('last_run_at', short_description=_("Last run"))
PeriodicTaskAdmin.list_display = ('__unicode__', display_last_run_at, 'total_run_count', 'enabled')
PeriodicTaskAdmin.list_display = ('__unicode__', display_last_run_at, 'total_run_count', 'enabled')

View File

@ -25,7 +25,6 @@ class PluginForm(forms.ModelForm):
class PluginDataForm(PluginForm): class PluginDataForm(PluginForm):
data = forms.CharField(widget=forms.HiddenInput, required=False) data = forms.CharField(widget=forms.HiddenInput, required=False)
target_server = forms.ModelChoiceField(queryset=Server.objects.filter(name__in=WEB_SERVERS),)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -100,6 +99,8 @@ class ExtendedPluginDataForm(PluginDataForm):
widget=forms.PasswordInput, widget=forms.PasswordInput,
help_text=_("Enter the same password as above, for verification.")) help_text=_("Enter the same password as above, for verification."))
target_server = forms.ModelChoiceField(queryset=Server.objects.filter(name__in=WEB_SERVERS),)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ExtendedPluginDataForm, self).__init__(*args, **kwargs) super(ExtendedPluginDataForm, self).__init__(*args, **kwargs)
self.fields['sftpuser'].widget = forms.HiddenInput() self.fields['sftpuser'].widget = forms.HiddenInput()

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,25 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="225.000000pt" height="225.000000pt" viewBox="0 0 225.000000 225.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,225.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M1020 2240 c-441 -44 -804 -329 -953 -747 -80 -222 -80 -515 0 -736
117 -328 364 -574 690 -690 221 -80 515 -80 736 0 382 136 658 457 733 850 22
114 22 302 0 416 -75 393 -352 714 -733 850 -134 48 -328 72 -473 57z m237
-832 c59 -28 122 -90 147 -145 l18 -41 32 35 c99 114 273 87 337 -52 76 -163
-102 -341 -266 -266 -22 10 -54 34 -71 54 l-32 35 -18 -41 c-25 -56 -87 -117
-149 -147 -73 -35 -180 -34 -256 1 -64 30 -129 93 -154 149 l-17 38 -32 -35
c-99 -114 -273 -87 -337 52 -76 163 102 341 266 266 22 -10 54 -34 71 -54 l32
-35 17 38 c67 149 262 219 412 148z"/>
<path d="M1045 1294 c-126 -66 -142 -234 -30 -320 65 -49 170 -45 232 9 44 38
63 82 63 141 0 111 -75 186 -187 186 -26 0 -61 -7 -78 -16z"/>
<path d="M590 1180 c-12 -12 -20 -33 -20 -55 0 -45 29 -75 73 -75 51 0 77 24
77 71 0 50 -27 79 -75 79 -22 0 -43 -8 -55 -20z"/>
<path d="M1550 1182 c-16 -13 -22 -29 -22 -57 0 -48 28 -75 78 -75 45 0 74 30
74 75 0 45 -29 75 -74 75 -19 0 -44 -8 -56 -18z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB