summaryrefslogtreecommitdiffstats
path: root/scripts/cobbler_webui.cgi
blob: a4ee8dbb46c6b4f0bb3187c726dce95ee49e999c (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
#!/usr/bin/env python
#
# Web Interface for Cobbler - CGI Controller
#
# Copyright 2007 Albert P. Tobey <tobert@gmail.com>
# 
# This software may be freely redistributed under the terms of the GNU
# general public license.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import cgi
import cgitb
import os
import sys
from cobbler.webui.CobblerWeb import CobblerWeb

def map_modes():
    path = os.environ.get( 'PATH_INFO', 'index' )

    if path.startswith('/'):
        path = path[1:]
    if path.endswith('/'):
        path = path[:-1]

    if path is '':
        path = 'index'

    return path

def base_url():
    return os.environ.get('SCRIPT_NAME', '')

def main():

    cgitb.enable()

    print "Content-type: text/html"
    print

    path = map_modes()
    form = cgi.parse()

    # ditch single-element arrays in the 'form' dictionary
    # - may be bad for form elements that are sometimes lists and sometimes
    # single items
    for key,val in form.items():
        if isinstance(val, list):
            if len(val) == 1:
                form[key] = val[0]

    cw = CobblerWeb( server="http://localhost/cobbler_api_rw", base_url=base_url(), username='testuser', password='llamas2007' )

    if path in cw.modes():
        func = getattr( cw, path )
        print func( **form )

main()