django-orchestra/orchestra/contrib/websites/backends/webalizer.py

131 lines
5.2 KiB
Python
Raw Permalink Normal View History

2014-05-08 16:59:35 +00:00
import os
2015-03-02 10:37:25 +00:00
import textwrap
2014-05-08 16:59:35 +00:00
from django.utils.translation import gettext_lazy as _
2014-05-08 16:59:35 +00:00
from orchestra.contrib.orchestration import ServiceController
2023-08-08 14:20:46 +00:00
from orchestra.settings import NEW_SERVERS
2014-05-08 16:59:35 +00:00
from .. import settings
2016-03-08 10:16:49 +00:00
class WebalizerController(ServiceController):
2015-04-23 19:46:23 +00:00
"""
Creates webalizer conf file for each time a webalizer webapp is mounted on a website.
"""
2015-03-10 21:51:10 +00:00
verbose_name = _("Webalizer Content")
2014-05-08 16:59:35 +00:00
model = 'websites.Content'
2015-03-12 14:05:23 +00:00
default_route_match = "content.webapp.type == 'webalizer'"
2015-04-24 11:39:20 +00:00
doc_settings = (settings,
('WEBSITES_WEBALIZER_PATH',)
)
2014-05-08 16:59:35 +00:00
def save(self, content):
context = self.get_context(content)
2015-03-02 10:37:25 +00:00
self.append(textwrap.dedent("""\
mkdir -p %(webalizer_path)s
if [[ ! -e %(webalizer_path)s/index.html ]]; then
echo 'Webstats are coming soon' > %(webalizer_path)s/index.html
fi
cat << 'EOF' > %(webalizer_conf_path)s
%(webalizer_conf)s
EOF
2023-08-08 14:20:46 +00:00
# chown %(user)s:www-data %(webalizer_path)s
chown www-data:www-data %(webalizer_path)s
2015-03-18 21:51:12 +00:00
chmod g+xr %(webalizer_path)s
""") % context
)
2014-05-08 16:59:35 +00:00
def delete(self, content):
context = self.get_context(content)
2015-04-21 13:12:48 +00:00
delete_webapp = not type(content.webapp).objects.filter(pk=content.webapp.pk).exists()
if delete_webapp:
2015-04-21 13:12:48 +00:00
self.append("rm -fr %(webapp_path)s" % context)
remounted = content.webapp.content_set.filter(website=content.website).exists()
if delete_webapp or not remounted:
self.append("rm -fr %(webalizer_path)s" % context)
self.append("rm -f %(webalizer_conf_path)s" % context)
2014-05-08 16:59:35 +00:00
def get_context(self, content):
2015-03-02 10:37:25 +00:00
conf_file = "%s.conf" % content.website.unique_name
2014-05-08 16:59:35 +00:00
context = {
2015-03-02 10:37:25 +00:00
'site_logs': content.website.get_www_access_log_path(),
2014-05-08 16:59:35 +00:00
'site_name': content.website.name,
'webapp_path': content.webapp.get_path(),
2014-05-08 16:59:35 +00:00
'webalizer_path': os.path.join(content.webapp.get_path(), content.website.name),
'webalizer_conf_path': os.path.join(settings.WEBSITES_WEBALIZER_PATH, conf_file),
2015-03-02 10:37:25 +00:00
'user': content.webapp.account.username,
2014-05-08 16:59:35 +00:00
'banner': self.get_banner(),
2023-08-08 14:20:46 +00:00
'target_server': content.website.target_server,
2014-05-08 16:59:35 +00:00
}
2023-08-08 14:20:46 +00:00
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("""\
2015-03-02 10:37:25 +00:00
PageType htm*
PageType php*
PageType shtml
PageType cgi
PageType pl
DNSCache /var/lib/dns_cache.db
DNSChildren 15
HideURL *.gif
HideURL *.GIF
HideURL *.jpg
HideURL *.JPG
HideURL *.png
HideURL *.PNG
HideURL *.ra
IncludeURL *
2023-08-08 14:20:46 +00:00
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=
2015-03-02 10:37:25 +00:00
DumpSites yes""") % context
return context