add arch=both to download bounce
[grml.org.git] / cgi-bin / download.cgi
1 #!/usr/bin/python
2
3 current_version = "2010.04"
4 mirror_url = "http://download.grml.org/"
5
6 #### END OF CONFIGURATION ####
7
8 import cgi, re
9
10 safe_regex = re.compile('^[a-zA-Z0-9_]+$')
11
12 def validate_input(value):
13         x = safe_regex.match(value)
14         if not x:
15                 raise Exception("unsafe input found" + str(x))
16         return value
17
18 def get_download_url(flavour, arch, filetype):
19         folder = ''
20         product = 'grml'
21         if arch == "amd64": product = 'grml64'
22         if flavour == 'full':
23                 pass
24         else:
25                 product += '-' + flavour
26
27         filetypes = {
28                 'iso': '',
29                 'bt': '.torrent',
30                 'md5': '.md5',
31                 'sha1': '.sha1',
32                 'signature': '.sha1.asc'
33         }
34         fileext = filetypes[filetype]
35         if "rc" in current_version: 
36                 folder = "devel/"
37
38         iso = product + '_' + current_version + '.iso' + fileext
39         return mirror_url + folder +  iso
40
41 def run():
42         import cgitb
43         cgitb.enable()
44
45         try:
46                 form = cgi.FieldStorage()
47                 try:
48                         global current_version
49                         current_version = form['version'].value
50                 except Exception:
51                         pass
52                 flavour = validate_input(form['flavour'].value)
53                 arch = validate_input(form['arch'].value)
54                 filetype = "iso"
55                 if "filetype" in form: filetype = validate_input(form['filetype'].value)
56
57                 print "Status: 302"
58                 print "Location: " + get_download_url(flavour, arch, filetype)
59                 print
60         except Exception, e:
61                 print "Content-Type: text/html"     # HTML is following
62                 print                               # blank line, end of headers
63                 print "<H1>Error</H1>"
64                 print "Please select flavour and architecture."
65                 print e
66
67 if __name__ == "__main__":
68         run()
69