From 708bbb3a3f5fb4a9e0fbfb5b28b3c90d67c01414 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Tue, 8 Aug 2023 16:20:46 +0200 Subject: [PATCH] websites complete fusion --- orchestra/contrib/websites/admin.py | 2 +- .../contrib/websites/backends/webalizer.py | 79 +++++++++++++------ orchestra/contrib/websites/forms.py | 21 +++++ 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/orchestra/contrib/websites/admin.py b/orchestra/contrib/websites/admin.py index 581796d6..6682c4c7 100644 --- a/orchestra/contrib/websites/admin.py +++ b/orchestra/contrib/websites/admin.py @@ -60,7 +60,7 @@ class ContentInline(AccountAdminMixin, admin.TabularInline): class WebsiteAdmin(SelectAccountAdminMixin, ExtendedModelAdmin): list_display = ( - 'name', 'display_domains', 'display_webapps', 'account_link', 'display_active' + 'name', 'display_domains', 'display_webapps', 'account_link', 'target_server', 'display_active' ) list_filter = ( 'protocol', IsActiveListFilter, HasWebAppsListFilter, HasDomainsFilter diff --git a/orchestra/contrib/websites/backends/webalizer.py b/orchestra/contrib/websites/backends/webalizer.py index 093aa6bd..d08b88ed 100644 --- a/orchestra/contrib/websites/backends/webalizer.py +++ b/orchestra/contrib/websites/backends/webalizer.py @@ -4,6 +4,7 @@ import textwrap from django.utils.translation import gettext_lazy as _ from orchestra.contrib.orchestration import ServiceController +from orchestra.settings import NEW_SERVERS from .. import settings @@ -29,7 +30,8 @@ class WebalizerController(ServiceController): cat << 'EOF' > %(webalizer_conf_path)s %(webalizer_conf)s EOF - chown %(user)s:www-data %(webalizer_path)s + # chown %(user)s:www-data %(webalizer_path)s + chown www-data:www-data %(webalizer_path)s chmod g+xr %(webalizer_path)s """) % context ) @@ -54,18 +56,35 @@ class WebalizerController(ServiceController): 'webalizer_conf_path': os.path.join(settings.WEBSITES_WEBALIZER_PATH, conf_file), 'user': content.webapp.account.username, 'banner': self.get_banner(), + 'target_server': content.website.target_server, } - context['webalizer_conf'] = textwrap.dedent("""\ - # %(banner)s - LogFile %(site_logs)s - LogType clf - OutputDir %(webalizer_path)s - HistoryName webalizer.hist - Incremental yes - IncrementalName webalizer.current - ReportTitle Stats of - HostName %(site_name)s - + if context.get('target_server').name in NEW_SERVERS: + context['webalizer_conf'] = textwrap.dedent("""\ + # %(banner)s + LogFile %(site_logs)s + LogType clf + OutputDir %(webalizer_path)s + HistoryName awffull.hist + Incremental yes + IncrementalName awffull.current + ReportTitle Stats of + HostName %(site_name)s + """) % context + else: + context['webalizer_conf'] = textwrap.dedent("""\ + # %(banner)s + LogFile %(site_logs)s + LogType clf + OutputDir %(webalizer_path)s + HistoryName webalizer.hist + Incremental yes + IncrementalName webalizer.current + ReportTitle Stats of + HostName %(site_name)s + """) % context + + context['webalizer_conf'] = context['webalizer_conf'] + textwrap.dedent("""\ + PageType htm* PageType php* PageType shtml @@ -84,20 +103,28 @@ class WebalizerController(ServiceController): HideURL *.ra IncludeURL * - - SearchEngine yahoo.com p= - SearchEngine altavista.com q= - SearchEngine google.com q= - SearchEngine eureka.com q= - SearchEngine lycos.com query= - SearchEngine hotbot.com MT= - SearchEngine msn.com MT= - SearchEngine infoseek.com qt= - SearchEngine webcrawler searchText= - SearchEngine excite search= - SearchEngine netscape.com search= - SearchEngine mamma.com query= - SearchEngine alltheweb.com query= + + SearchEngine google. q= + SearchEngine yahoo. p= + SearchEngine msn. q= + SearchEngine search.aol query= + SearchEngine altavista. q= + SearchEngine lycos. query= + SearchEngine hotbot. query= + SearchEngine alltheweb. query= + SearchEngine infoseek. qt= + SearchEngine webcrawler searchText= + SearchEngine excite search= + SearchEngine netscape. query= + SearchEngine ask.com q= + SearchEngine webwombat. ix= + SearchEngine earthlink. q= + SearchEngine search.comcast. q= + SearchEngine search.mywebsearch. searchfor= + SearchEngine reference.com q= + SearchEngine mamma.com query= + # Last attempt catch all + SearchEngine search. q= DumpSites yes""") % context return context diff --git a/orchestra/contrib/websites/forms.py b/orchestra/contrib/websites/forms.py index fc4a5029..2df37fd0 100644 --- a/orchestra/contrib/websites/forms.py +++ b/orchestra/contrib/websites/forms.py @@ -3,6 +3,8 @@ from collections import defaultdict from django import forms from django.core.exceptions import ValidationError +from orchestra.contrib.webapps.models import WebApp + from .utils import normurlpath from .validators import validate_domain_protocol, validate_server_name @@ -26,6 +28,25 @@ class WebsiteAdminForm(forms.ModelForm): except ValidationError as err: self.add_error('domains', err) return self.cleaned_data + + def clean_target_server(self): + # valida que el webapp pertenezca al server indicado + try: + server = self.cleaned_data['target_server'] + except: + server = self.instance.target_server + + diferentServer = False + for i in range(int(self.data['content_set-TOTAL_FORMS']) + 1): + if f"content_set-{i}-webapp" in self.data.keys() and f"content_set-{i}-DELETE" not in self.data.keys(): + if self.data[f"content_set-{i}-webapp"]: + idWebapp = self.data[f"content_set-{i}-webapp"] + webapp = WebApp.objects.get(id=idWebapp) + if webapp.target_server.id != server.id : + diferentServer = True + if diferentServer: + self.add_error("target_server", f"Some Webapp does not belong to the {server.name} server") + return server class WebsiteDirectiveInlineFormSet(forms.models.BaseInlineFormSet):