summaryrefslogtreecommitdiff
path: root/webserver/wwwcvs-orig-files/modules/wwwgnu-nongnu/files/new.py
blob: dd455a6456326b152b82561564c705652bff6e4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os,sys
import string
from mod_python import apache, util
from syslog import *
import stat

# baughj, 2007.07.06 - add logging, usage of subprocess
# baughj, 2007.07.16 - make sure to chgrp/chmod checked out directory so that
# it can be updated by wwwcvs user later - why doesn't everything (cron job,
# etc) run as one user?
# add new 'translation' type for translation team webspace, see RT #348523.
# ward, 2008-08-18

# Stripped out actual cvs update, this script now just requests an update.
# See /usr/local/bin/update-cvs.sh for the actual cvs update code (and that 
# script is run from cron)
# ward, 2012-09-26

CHECKOUT = "/var/www/savannah-checkouts/"
LOGFILE = "/var/log/wwwcvs/new-savannah-project.log"

def touch(fname, times=None):
    with file(fname, 'a'):
        os.utime(fname, times)
        os.chmod(fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH)

def request_update (type, project=''):
    if type == 'www':
        touch('/usr/local/to-update/www')
        syslog(LOG_INFO, "Update requested for type: %s" % type)
        return
    touch('/usr/local/to-update/%s___%s' % (type, project))
    syslog(LOG_INFO, "Update requested for type: %s (project %s)" % (type,project))
    return

def handler (req):
    openlog('savannah-update', 0, LOG_LOCAL6)
    form = util.FieldStorage (req)

    req.content_type = 'text/html'
    req.send_http_header ()

    type = None
    project = None
    if form.has_key('type'):
        type = form['type']
    if form.has_key('project'):
        project = form['project']

    if (type == 'www'):
        request_update('www')
        req.content_type = 'text/html'
        req.send_http_header ()
        return apache.OK 

    if not (type and project):
        syslog(LOG_ERR, 'Error: missing type or project. Aborting.')
        return apache.HTTP_NOT_FOUND

    if (type != 'gnu') and (type != 'non-gnu') and (type != 'translations'):
        syslog(LOG_ERR, "Error: Type unknown, was %s. Aborting." % type)
        return apache.HTTP_NOT_FOUND
    
    if string.find (project, "/") != -1:
        syslog(LOG_ERR, "Error: / found in project name %s" % project)
        return apache.HTTP_NOT_FOUND

    request_update(type,project)
    req.content_type = 'text/html'
    req.send_http_header ()

    return apache.OK