Skip to content

Commit

Permalink
awstats configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
turian committed May 15, 2010
1 parent 5c0c120 commit c61725c
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 37 deletions.
7 changes: 7 additions & 0 deletions README
Expand Up @@ -22,9 +22,15 @@ Instructions for each OSQA:

* Run ./install-webfaction-cpanel.py

* Get awstats cpanel configured:
./install-webfaction-cpanel-awstats.py

* Get OSQA env variables:
eval $(./makeenv.py )

* Configure awstats:
./configureawstats.sh

* Get the OSQA source + make a virtualenv:
./getsource.sh

Expand Down Expand Up @@ -96,6 +102,7 @@ cd cd osqa-install-webfaction/

Webfaction API documentation here:
http://docs.webfaction.com/xmlrpc-api/tutorial.html
http://docs.webfaction.com/xmlrpc-api/apiref.html

NOTES:
* All OSQA sites should share one env dir (ENVDIR).
Expand Down
2 changes: 1 addition & 1 deletion batch.sh
@@ -1,5 +1,5 @@
#!/bin/sh
rm moreglobals.py*
./install-webfaction-cpanel.py && eval $(./makeenv.py ) && ./getsource.sh && ./modifysettings.py && ./configurebackup.pl && ./modifycron.py && ./createdb.sh
./install-webfaction-cpanel.py && install-webfaction-cpanel-awstats.py && eval $(./makeenv.py ) && ./configureawstats.sh && ./getsource.sh && ./modifysettings.py && ./configurebackup.pl && ./modifycron.py && ./createdb.sh
./modifyhttpdconf.py && ./modifywsgi.py && ./startapache.sh
chmod go-rwx globals.py* moreglobals.py* && cp globals.py moreglobals.py $OSQA_WEBAPPDIR ; chmod go-rwx $OSQA_WEBAPPDIR/globals.py $OSQA_WEBAPPDIR/moreglobals.py
12 changes: 12 additions & 0 deletions configureawstats.sh
@@ -0,0 +1,12 @@
#!/bin/sh

AWDIR="$HOME/webapps/$OSQA_AWSTATS_APPNAME"
CONFFILE="$AWDIR/cgi-bin/awstats.conf"
perl -i -pe 's/DNSLookup=2/DNSLookup=1/g;' $CONFFILE;
perl -i -pe 's/#LoadPlugin="hashfiles"/LoadPlugin="hashfiles"/g;' $CONFFILE;
perl -i -pe "s/SiteDomain=.*/SiteDomain=\"$OSQA_FULLDOMAINNAME\"/g;" $CONFFILE;
perl -i -pe 's/SkipFiles=.*/SkipFiles="REGEX[^\\\/awstats]"/g;' $CONFFILE;

cd $AWDIR ;
perl -i -pe 's/\.1/.*/g;' ./update_awstats.sh
./update_awstats.sh
43 changes: 43 additions & 0 deletions cpanel.py
@@ -0,0 +1,43 @@
"""
WebFaction cpanel helper functions.
"""

import sys

def try_remove(server, session_id, name, type, delete_thing, list_thing, namename="name", delete_extra_params=[]):
"""
Try to remove something using the webfaction API, if it exists.
"""
# See if the something already exists.
r = server.__getattr__(list_thing)(session_id)
to_delete = False
for i in r:
# print >> sys.stderr, i
if i[namename] == name:
to_delete = True
break

# If the something already exists, remove it before adding it
if to_delete:
print >> sys.stderr, "%s %s already exists. Removing..." % (type, name)
# print >> sys.stderr, delete_thing, ([session_id, name] + delete_extra_params)
r = server.__getattr__(delete_thing)(*([session_id, name] + delete_extra_params))
print >> sys.stderr, "server.%s: %s" % (delete_thing, r)

def force_create(server, session_id, name, type, create_thing, delete_thing, list_thing, create_parameters=[], namename="name", delete_extra_params=[], overwrite=True):
"""
Force the creation of something using the webfaction API.
overwrite determines whether to delete the entity if it exists.
"""
print >> sys.stderr, tuple([repr(s) for s in [server, session_id, name, type, create_thing, delete_thing, list_thing, create_parameters]])
print >> sys.stderr, "force_create(server=%s, session_id=%s, name=%s, type=%s, create_thing=%s, delete_thing=%s, list_thing=%s, create_parameters=%s)" % tuple([repr(s) for s in [server, session_id, name, type, create_thing, delete_thing, list_thing, create_parameters]])

if overwrite:
try_remove(server, session_id, name, type, delete_thing, list_thing, namename=namename, delete_extra_params=delete_extra_params)

# Create the something
#print [session_id, name] + create_parameters
r = server.__getattr__(create_thing)(*([session_id, name] + create_parameters))
print >> sys.stderr, "server.%s: %s" % (create_thing, r)
return r

3 changes: 3 additions & 0 deletions globals.py.dist
Expand Up @@ -28,6 +28,9 @@ MAILBOXUSERNAME = APPNAME # Webfaction mailbox username
MAILBOXPASSWORD = None # Webfaction mailbox password. If None,
# pick a random password.

AWSTATS_APPNAME = APPNAME + "_awstats" # Awstats Webfaction application name
AWSTATS_URLPATH = URLPATH + "awstats" # Awstats URL path of the forum

if SUBDOMAINNAME is None:
FULLDOMAINNAME = DOMAINNAME
else:
Expand Down
24 changes: 24 additions & 0 deletions install-webfaction-cpanel-awstats.py
@@ -0,0 +1,24 @@
#!/usr/bin/env python

from globals import *
from moreglobals import *
import sys

from cpanel import try_remove, force_create

import xmlrpclib
server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
session_id, account = server.login(USERNAME, PASSWORD)
#print >> sys.stderr, repr(session_id)
#print >> sys.stderr, repr(account)
#{'username': 'test5', 'home': '/home2', 'id': 237}

#for i in server.list_emails(session_id):
# print >> sys.stderr, i

r = force_create(server, session_id, AWSTATS_APPNAME, "app", "create_app", "delete_app", "list_apps", ['awstats68', False, WEBSITENAME])

if SERVERIP is None:
SERVERIP = server.list_websites(session_id)[0]["ip"]
print >> sys.stderr, "No SERVERIP given. Using %s" % SERVERIP
r = force_create(server, session_id, WEBSITENAME, "website", "create_website", "delete_website", "list_websites", [SERVERIP, False, [FULLDOMAINNAME], [APPNAME, URLPATH], [AWSTATS_APPNAME, AWSTATS_URLPATH]])
38 changes: 2 additions & 36 deletions install-webfaction-cpanel.py
Expand Up @@ -3,6 +3,8 @@
from globals import *
import sys

from cpanel import try_remove, force_create

# Write new globals here
moreglobals = open("moreglobals.py", "wt")

Expand All @@ -16,42 +18,6 @@
#for i in server.list_emails(session_id):
# print >> sys.stderr, i

def try_remove(server, session_id, name, type, delete_thing, list_thing, namename="name", delete_extra_params=[]):
"""
Try to remove something using the webfaction API, if it exists.
"""
# See if the something already exists.
r = server.__getattr__(list_thing)(session_id)
to_delete = False
for i in r:
# print >> sys.stderr, i
if i[namename] == name:
to_delete = True
break

# If the something already exists, remove it before adding it
if to_delete:
print >> sys.stderr, "%s %s already exists. Removing..." % (type, name)
# print >> sys.stderr, delete_thing, ([session_id, name] + delete_extra_params)
r = server.__getattr__(delete_thing)(*([session_id, name] + delete_extra_params))
print >> sys.stderr, "server.%s: %s" % (delete_thing, r)

def force_create(server, session_id, name, type, create_thing, delete_thing, list_thing, create_parameters=[], namename="name", delete_extra_params=[], overwrite=True):
"""
Force the creation of something using the webfaction API.
overwrite determines whether to delete the entity if it exists.
"""
print >> sys.stderr, tuple([repr(s) for s in [server, session_id, name, type, create_thing, delete_thing, list_thing, create_parameters]])
print >> sys.stderr, "force_create(server=%s, session_id=%s, name=%s, type=%s, create_thing=%s, delete_thing=%s, list_thing=%s, create_parameters=%s)" % tuple([repr(s) for s in [server, session_id, name, type, create_thing, delete_thing, list_thing, create_parameters]])

if overwrite:
try_remove(server, session_id, name, type, delete_thing, list_thing, namename=namename, delete_extra_params=delete_extra_params)

# Create the something
r = server.__getattr__(create_thing)(*([session_id, name] + create_parameters))
print >> sys.stderr, "server.%s: %s" % (create_thing, r)
return r

if SUBDOMAINNAME is None:
r = force_create(server, session_id, DOMAINNAME, "domain", "create_domain", "delete_domain", "list_domains", namename="domain", overwrite=False)
else:
Expand Down

0 comments on commit c61725c

Please sign in to comment.