From 59fcf7bc502d250ea9cec8d9f9b0d2e3233d95e9 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 19 Sep 2007 18:14:03 -0400 Subject: Move all CGI scripts to a cobbler subdirectory under cgi-bin for namespacing. In addition, the webui is now just "webui.cgi" in that directory. RPMs and setup.py also updated. --- scripts/cobbler_webui.cgi | 110 ---------------------------------------------- scripts/webui.cgi | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 110 deletions(-) delete mode 100755 scripts/cobbler_webui.cgi create mode 100755 scripts/webui.cgi (limited to 'scripts') diff --git a/scripts/cobbler_webui.cgi b/scripts/cobbler_webui.cgi deleted file mode 100755 index 899610c4..00000000 --- a/scripts/cobbler_webui.cgi +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python -# -# Web Interface for Cobbler - CGI Controller -# -# Copyright 2007 Albert P. Tobey -# -# 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 Cookie -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 configure(): - # FIXME: read a config file ... - config = { - 'token': None, - 'server': None, - 'base_url': None, - 'username': None, - 'password': None, - 'cgitb_enabled': 1 - } - #config.username = 'testuser', - #config.password = 'llamas2007' - - # defaults - if config['server'] is None: - config['server'] = "http://localhost/cobbler_api_rw" - - if config['base_url'] is None: - config['base_url'] = base_url() - - return config - -def main(): - content = "Something went wrong and I couldn't generate any content for you!" - cw_conf = configure() - path = map_modes() - form = cgi.parse() - cookies = Cookie.SimpleCookie(os.environ.get("HTTP_COOKIE","")) - - # make cgitb enablement configurable - if cw_conf['cgitb_enabled'] == 1: - cgitb.enable() - cw_conf.pop('cgitb_enabled') - - # exchnage single-element arrays in the 'form' dictionary for just that item - # so there isn't a ton of 'foo[0]' craziness where 'foo' should suffice - # - 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] - - # instantiate a CobblerWeb object - cw = CobblerWeb( **cw_conf ) - - # FIXME: allow for direct URL access and pages will redirect appropriately. - - #if not path.startswith('login') and (cw_conf['token'] is None and (cw_conf['username'] is None or cw_conf['password'] is None)): - # func = getattr( cw, 'login' ) - # content = func( message="Authentication Required." ) - - # check for a valid path/mode - if path in cw.modes(): - func = getattr( cw, path ) - content = func( **form ) - - # handle invalid paths gracefully - else: - func = getattr( cw, 'error_page' ) - content = func( "Invalid Mode: \"%s\"" % path ) - - # finally, get any cookies generated by the CobblerWeb object - cookie_header = cw.cookies().output() - if cookie_header: - print cookie_header - - # deliver content - print "Content-type: text/html" - print - print content - -main() - diff --git a/scripts/webui.cgi b/scripts/webui.cgi new file mode 100755 index 00000000..899610c4 --- /dev/null +++ b/scripts/webui.cgi @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# +# Web Interface for Cobbler - CGI Controller +# +# Copyright 2007 Albert P. Tobey +# +# 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 Cookie +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 configure(): + # FIXME: read a config file ... + config = { + 'token': None, + 'server': None, + 'base_url': None, + 'username': None, + 'password': None, + 'cgitb_enabled': 1 + } + #config.username = 'testuser', + #config.password = 'llamas2007' + + # defaults + if config['server'] is None: + config['server'] = "http://localhost/cobbler_api_rw" + + if config['base_url'] is None: + config['base_url'] = base_url() + + return config + +def main(): + content = "Something went wrong and I couldn't generate any content for you!" + cw_conf = configure() + path = map_modes() + form = cgi.parse() + cookies = Cookie.SimpleCookie(os.environ.get("HTTP_COOKIE","")) + + # make cgitb enablement configurable + if cw_conf['cgitb_enabled'] == 1: + cgitb.enable() + cw_conf.pop('cgitb_enabled') + + # exchnage single-element arrays in the 'form' dictionary for just that item + # so there isn't a ton of 'foo[0]' craziness where 'foo' should suffice + # - 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] + + # instantiate a CobblerWeb object + cw = CobblerWeb( **cw_conf ) + + # FIXME: allow for direct URL access and pages will redirect appropriately. + + #if not path.startswith('login') and (cw_conf['token'] is None and (cw_conf['username'] is None or cw_conf['password'] is None)): + # func = getattr( cw, 'login' ) + # content = func( message="Authentication Required." ) + + # check for a valid path/mode + if path in cw.modes(): + func = getattr( cw, path ) + content = func( **form ) + + # handle invalid paths gracefully + else: + func = getattr( cw, 'error_page' ) + content = func( "Invalid Mode: \"%s\"" % path ) + + # finally, get any cookies generated by the CobblerWeb object + cookie_header = cw.cookies().output() + if cookie_header: + print cookie_header + + # deliver content + print "Content-type: text/html" + print + print content + +main() + -- cgit