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

95 lines
3.5 KiB
Python
Raw 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 ugettext_lazy as _
2014-07-09 16:17:43 +00:00
from orchestra.apps.orchestration import ServiceController
2014-05-08 16:59:35 +00:00
from .. import settings
2014-07-09 16:17:43 +00:00
class WebalizerBackend(ServiceController):
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'"
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
echo '%(webalizer_conf)s' > %(webalizer_conf_path)s
2015-03-18 21:51:12 +00:00
chown %(user)s:www-data %(webalizer_path)s
chmod g+xr %(webalizer_path)s
""") % context
)
2014-05-08 16:59:35 +00:00
def delete(self, content):
context = self.get_context(content)
delete_webapp = type(content.webapp).objects.filter(pk=content.webapp.pk).exists()
if delete_webapp:
2015-03-10 21:51:10 +00:00
self.append("rm -f %(webapp_path)s" % context)
if delete_webapp or not content.webapp.content_set.filter(website=content.website).exists():
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(),
}
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=
DumpSites yes""") % context
2014-05-08 16:59:35 +00:00
return context