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
|
|
|
|
2023-10-24 16:59:02 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2014-05-08 16:59:35 +00:00
|
|
|
|
2015-05-21 13:34:12 +00:00
|
|
|
from orchestra.contrib.orchestration import ServiceController
|
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
|
2015-05-21 13:34:12 +00:00
|
|
|
cat << 'EOF' > %(webalizer_conf_path)s
|
|
|
|
%(webalizer_conf)s
|
|
|
|
EOF
|
2015-03-18 21:51:12 +00:00
|
|
|
chown %(user)s:www-data %(webalizer_path)s
|
|
|
|
chmod g+xr %(webalizer_path)s
|
|
|
|
""") % context
|
2015-03-10 16:57:23 +00:00
|
|
|
)
|
2014-05-08 16:59:35 +00:00
|
|
|
|
|
|
|
def delete(self, content):
|
2015-03-10 11:46:48 +00:00
|
|
|
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()
|
2015-03-10 11:46:48 +00:00
|
|
|
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:
|
2015-03-10 16:57:23 +00:00
|
|
|
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,
|
2015-03-10 11:46:48 +00:00
|
|
|
'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(),
|
|
|
|
}
|
2015-03-02 10:37:25 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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 *
|
|
|
|
|
|
|
|
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=
|
|
|
|
|
2015-03-10 16:57:23 +00:00
|
|
|
DumpSites yes""") % context
|
2015-05-21 13:34:12 +00:00
|
|
|
return context
|