Compare commits
7 Commits
f067732802
...
b06f0d1cd6
Author | SHA1 | Date |
---|---|---|
Jorge Pastor | b06f0d1cd6 | |
Jorge Pastor | 8eae8e624f | |
Jorge Pastor | e2dd8a90ae | |
Jorge Pastor | b782269b12 | |
Jorge Pastor | f7a4fc749b | |
Jorge Pastor | 1610c301cf | |
Jorge Pastor | 2ca503a945 |
|
@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from orchestra.core import validators
|
from orchestra.core import validators
|
||||||
|
|
||||||
from .models import DatabaseUser, Database
|
from .models import DatabaseUser, Database
|
||||||
|
from .settings import DATABASES_SERVERS
|
||||||
|
|
||||||
|
|
||||||
class DatabaseUserCreationForm(forms.ModelForm):
|
class DatabaseUserCreationForm(forms.ModelForm):
|
||||||
|
@ -22,6 +23,11 @@ class DatabaseUserCreationForm(forms.ModelForm):
|
||||||
model = DatabaseUser
|
model = DatabaseUser
|
||||||
fields = ('username', 'account', 'type')
|
fields = ('username', 'account', 'type')
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(DatabaseUserCreationForm, self).__init__(*args, **kwargs)
|
||||||
|
qsServer = self.fields['target_server'].queryset.filter(name__in=DATABASES_SERVERS)
|
||||||
|
self.fields['target_server'].queryset = qsServer
|
||||||
|
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
password1 = self.cleaned_data.get("password1")
|
password1 = self.cleaned_data.get("password1")
|
||||||
password2 = self.cleaned_data.get("password2")
|
password2 = self.cleaned_data.get("password2")
|
||||||
|
@ -74,6 +80,10 @@ class DatabaseCreationForm(DatabaseUserCreationForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(DatabaseCreationForm, self).__init__(*args, **kwargs)
|
super(DatabaseCreationForm, self).__init__(*args, **kwargs)
|
||||||
account_id = self.initial.get('account', self.initial_account)
|
account_id = self.initial.get('account', self.initial_account)
|
||||||
|
|
||||||
|
qsServer = self.fields['target_server'].queryset.filter(name__in=DATABASES_SERVERS)
|
||||||
|
self.fields['target_server'].queryset = qsServer
|
||||||
|
|
||||||
if account_id:
|
if account_id:
|
||||||
qs = self.fields['user'].queryset.filter(account=account_id).order_by('username')
|
qs = self.fields['user'].queryset.filter(account=account_id).order_by('username')
|
||||||
choices = [ (u.pk, "%s (%s) (%s)" % (u, u.get_type_display(), str(u.target_server.name) )) for u in qs ]
|
choices = [ (u.pk, "%s (%s) (%s)" % (u, u.get_type_display(), str(u.target_server.name) )) for u in qs ]
|
||||||
|
|
|
@ -27,3 +27,12 @@ DATABASES_DEFAULT_HOST = Setting('DATABASES_DEFAULT_HOST',
|
||||||
DATABASES_MYSQL_DB_DIR = Setting('DATABASES_MYSQL_DB_DIR',
|
DATABASES_MYSQL_DB_DIR = Setting('DATABASES_MYSQL_DB_DIR',
|
||||||
'/var/lib/mysql',
|
'/var/lib/mysql',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
DATABASES_SERVERS = Setting('DATABASES_SERVERS', (
|
||||||
|
'wpmu',
|
||||||
|
'mysql.pangea.lan',
|
||||||
|
'web-11.pangea.lan',
|
||||||
|
'web-12.pangea.lan',
|
||||||
|
)
|
||||||
|
)
|
|
@ -198,8 +198,10 @@ class ResourceData(models.Model):
|
||||||
('content_type', 'object_id'),
|
('content_type', 'object_id'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# def __str__(self):
|
||||||
|
# return "%s: %s" % (self.resource, self.content_object)
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s: %s" % (self.resource, self.content_object)
|
return "%s" % (self.content_object)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit(self):
|
def unit(self):
|
||||||
|
|
|
@ -10,6 +10,8 @@ from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from orchestra.contrib.orchestration import ServiceController
|
from orchestra.contrib.orchestration import ServiceController
|
||||||
from orchestra.contrib.resources import ServiceMonitor
|
from orchestra.contrib.resources import ServiceMonitor
|
||||||
|
from orchestra.contrib.resources.models import ResourceData
|
||||||
|
from orchestra.contrib.saas.models import SaaS
|
||||||
|
|
||||||
from . import ApacheTrafficByName
|
from . import ApacheTrafficByName
|
||||||
from .. import settings
|
from .. import settings
|
||||||
|
@ -52,11 +54,31 @@ class NextCloudAPIMixin(object):
|
||||||
def create(self, saas):
|
def create(self, saas):
|
||||||
data = {
|
data = {
|
||||||
'userid': saas.name,
|
'userid': saas.name,
|
||||||
'password': saas.password
|
'password': saas.password,
|
||||||
}
|
}
|
||||||
self.api_post('users', data)
|
self.api_post('users', data)
|
||||||
|
|
||||||
|
def update_group(self, saas):
|
||||||
|
data = {
|
||||||
|
'groupid': saas.account.username
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
self.api_get('groups/%s' % saas.account.username)
|
||||||
|
except RuntimeError:
|
||||||
|
self.api_post('groups', data)
|
||||||
|
self.api_post(f'users/{saas.name}/groups', data)
|
||||||
|
|
||||||
def update(self, saas):
|
def update_quota(self, saas):
|
||||||
|
if hasattr(saas, 'resources') and hasattr(saas.resources, 'nextcloud-disk'):
|
||||||
|
resource = getattr(saas.resources, 'nextcloud-disk')
|
||||||
|
quotaValue = f"{resource.allocated}G" if resource.allocated > 0 else "default"
|
||||||
|
data = {
|
||||||
|
'key': "quota",
|
||||||
|
'value': quotaValue
|
||||||
|
}
|
||||||
|
self.api_put(f'users/{saas.name}', data)
|
||||||
|
|
||||||
|
def update_password(self, saas):
|
||||||
"""
|
"""
|
||||||
key: email|quota|display|password
|
key: email|quota|display|password
|
||||||
value: el valor a modificar.
|
value: el valor a modificar.
|
||||||
|
@ -69,6 +91,12 @@ class NextCloudAPIMixin(object):
|
||||||
'value': saas.password,
|
'value': saas.password,
|
||||||
}
|
}
|
||||||
self.api_put('users/%s' % saas.name, data)
|
self.api_put('users/%s' % saas.name, data)
|
||||||
|
|
||||||
|
def disable_user(self, saas):
|
||||||
|
self.api_put('users/%s/disable' % saas.name)
|
||||||
|
|
||||||
|
def enable_user(self, saas):
|
||||||
|
self.api_put('users/%s/enable' % saas.name)
|
||||||
|
|
||||||
def get_user(self, saas):
|
def get_user(self, saas):
|
||||||
"""
|
"""
|
||||||
|
@ -112,21 +140,30 @@ class NextCloudController(NextCloudAPIMixin, ServiceController):
|
||||||
try:
|
try:
|
||||||
self.api_get('users/%s' % saas.name)
|
self.api_get('users/%s' % saas.name)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
if getattr(saas, 'password'):
|
if getattr(saas, 'password', None):
|
||||||
self.create(saas)
|
self.create(saas)
|
||||||
|
self.update_group(saas)
|
||||||
|
self.update_quota(saas)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
if getattr(saas, 'password'):
|
if getattr(saas, 'password', None):
|
||||||
self.update(saas)
|
self.update_password(saas)
|
||||||
|
else:
|
||||||
|
self.update_group(saas)
|
||||||
|
self.update_quota(saas)
|
||||||
|
|
||||||
def remove(self, saas, server):
|
def remove(self, saas, server):
|
||||||
self.api_delete('users/%s' % saas.name)
|
self.api_delete('users/%s' % saas.name)
|
||||||
|
|
||||||
def save(self, saas):
|
def save(self, saas):
|
||||||
# TODO disable user https://github.com/owncloud/core/issues/12601
|
|
||||||
self.append(self.update_or_create, saas)
|
self.append(self.update_or_create, saas)
|
||||||
|
if saas.is_active:
|
||||||
|
self.enable_user(saas)
|
||||||
|
else:
|
||||||
|
self.disable_user(saas)
|
||||||
|
|
||||||
|
|
||||||
def delete(self, saas):
|
def delete(self, saas):
|
||||||
self.append(self.remove, saas)
|
self.append(self.remove, saas)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from orchestra.plugins.forms import ExtendedPluginDataForm, PluginDataForm
|
||||||
from ..options import AppOption
|
from ..options import AppOption
|
||||||
from . import AppType
|
from . import AppType
|
||||||
from .php import PHPApp, PHPAppForm, PHPAppSerializer
|
from .php import PHPApp, PHPAppForm, PHPAppSerializer
|
||||||
|
from orchestra.settings import WEB_SERVERS
|
||||||
|
|
||||||
class StaticApp(AppType):
|
class StaticApp(AppType):
|
||||||
name = 'static'
|
name = 'static'
|
||||||
|
@ -27,6 +27,9 @@ class WebalizerAppform(PluginDataForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(WebalizerAppform, self).__init__(*args, **kwargs)
|
super(WebalizerAppform, self).__init__(*args, **kwargs)
|
||||||
self.fields['sftpuser'].widget = forms.HiddenInput()
|
self.fields['sftpuser'].widget = forms.HiddenInput()
|
||||||
|
if self.instance.id is None:
|
||||||
|
qsServer = self.fields['target_server'].queryset.filter(name__in=WEB_SERVERS)
|
||||||
|
self.fields['target_server'].queryset = qsServer
|
||||||
|
|
||||||
class WebalizerApp(AppType):
|
class WebalizerApp(AppType):
|
||||||
name = 'webalizer'
|
name = 'webalizer'
|
||||||
|
|
|
@ -7,9 +7,18 @@ from orchestra.contrib.webapps.models import WebApp
|
||||||
|
|
||||||
from .utils import normurlpath
|
from .utils import normurlpath
|
||||||
from .validators import validate_domain_protocol, validate_server_name
|
from .validators import validate_domain_protocol, validate_server_name
|
||||||
|
from orchestra.settings import WEB_SERVERS
|
||||||
|
|
||||||
class WebsiteAdminForm(forms.ModelForm):
|
class WebsiteAdminForm(forms.ModelForm):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(WebsiteAdminForm, self).__init__(*args, **kwargs)
|
||||||
|
if self.instance.id is None:
|
||||||
|
qsServer = self.fields['target_server'].queryset.filter(name__in=WEB_SERVERS)
|
||||||
|
else:
|
||||||
|
qsServer = self.fields['target_server'].queryset.filter(id=self.instance.target_server_id)
|
||||||
|
self.fields['target_server'].queryset = qsServer
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
""" Prevent multiples domains on the same protocol """
|
""" Prevent multiples domains on the same protocol """
|
||||||
super(WebsiteAdminForm, self).clean()
|
super(WebsiteAdminForm, self).clean()
|
||||||
|
|
|
@ -99,7 +99,8 @@ NEW_SERVERS = Setting('NEW_SERVERS',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
WEB_SERVERS = Setting('WEBAPPS_SERVERS', (
|
WEB_SERVERS = Setting('WEB_SERVERS', (
|
||||||
|
'wpmu',
|
||||||
'web.pangea.lan',
|
'web.pangea.lan',
|
||||||
'web-ng',
|
'web-ng',
|
||||||
'web-11.pangea.lan',
|
'web-11.pangea.lan',
|
||||||
|
|
Loading…
Reference in New Issue