diff options
| author | Michael DeHaan <mdehaan@redhat.com> | 2008-02-15 14:54:25 -0500 |
|---|---|---|
| committer | Michael DeHaan <mdehaan@redhat.com> | 2008-02-15 14:54:25 -0500 |
| commit | a47ee22ab684eed992128b60b136fca90ff9f119 (patch) | |
| tree | cd55daf8057049368b4aaa6d23c30408eae411d2 /scripts | |
| parent | 70bfc8f5a3150d09cc064a4c46efcaff80b29904 (diff) | |
| parent | a7d67f35019af0c25f133c979112fc6035d7e04c (diff) | |
Merge branch 'devel'
Merging devel work on 0.7.X/0.8 release with master
Conflicts:
CHANGELOG
cobbler.spec
cobbler/action_import.py
cobbler/utils.py
cobbler/webui/master.py
setup.py
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/cobbler | 3 | ||||
| -rw-r--r-- | scripts/cobbler_auth_help | 55 | ||||
| -rwxr-xr-x | scripts/cobblerd | 20 | ||||
| -rwxr-xr-x | scripts/findks.cgi | 2 | ||||
| -rwxr-xr-x | scripts/index.py | 160 | ||||
| -rwxr-xr-x | scripts/nopxe.cgi | 2 | ||||
| -rw-r--r-- | scripts/post_install_trigger.cgi | 72 | ||||
| -rwxr-xr-x | scripts/webui.cgi | 108 |
8 files changed, 302 insertions, 120 deletions
diff --git a/scripts/cobbler b/scripts/cobbler index 4aef615..1b69ab6 100755 --- a/scripts/cobbler +++ b/scripts/cobbler @@ -14,7 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ -import sys import cobbler.cobbler as app -sys.exit(app.main()) +app.main() diff --git a/scripts/cobbler_auth_help b/scripts/cobbler_auth_help new file mode 100644 index 0000000..8842d59 --- /dev/null +++ b/scripts/cobbler_auth_help @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +# Kerberos helper for logins +# +# Copyright 2007, Red Hat, Inc +# Michael DeHaan <mdehaan@redhat.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. + +# Usage: +# cobbler_auth_helper kerberos username pass +# (may do other auth types later) +# Returns: +# 0 on ok, non-0 on failure +# API info: +# http://search.cpan.org/~chansen/Authen-Simple-Kerberos-0.1/ + +use warnings; +use strict; + +use Authen::Simple::Kerberos; +use Getopt::Long; + +my $method; +my $username; +my $realm; +my $password; +my $verbose=0; + +my $result = GetOptions( + "method=s" => \$method, + "username=s" => \$username, + "realm=s" => \$realm, + "password=s" => \$password, +); + +my $kerberos = Authen::Simple::Kerberos->new( + realm => $realm +); + +print "authenticating: $username against $method $realm ($password)\n" if $verbose; + +if ( $kerberos->authenticate( $username, $password ) ) { + print "ok\n" if $verbose; + exit(42); +} + +print "denied\n" if $verbose; +exit(1); + diff --git a/scripts/cobblerd b/scripts/cobblerd index b6bf8a5..3170e58 100755 --- a/scripts/cobblerd +++ b/scripts/cobblerd @@ -16,24 +16,28 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import sys import os +import cobbler.api as bootapi import cobbler.cobblerd as app import logging import cobbler.utils as utils -logger = logging.getLogger("cobbler.cobblerd") -logger.setLevel(logging.DEBUG) -ch = logging.FileHandler("/var/log/cobbler/cobblerd.log") -ch.setLevel(logging.DEBUG) -formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") -ch.setFormatter(formatter) -logger.addHandler(ch) +#logger = logging.getLogger("cobbler.cobblerd") +#logger.setLevel(logging.DEBUG) +#ch = logging.FileHandler("/var/log/cobbler/cobblerd.log") +#ch.setLevel(logging.DEBUG) +#formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") +#ch.setFormatter(formatter) +#logger.addHandler(ch) + +api = bootapi.BootAPI() +logger = api.logger_remote if __name__ == "__main__": ############################################# # daemonizing code: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 - logger.debug("started") + logger.info("cobblerd started") try: pid = os.fork() if pid > 0: diff --git a/scripts/findks.cgi b/scripts/findks.cgi index fbb6fd2..70b9870 100755 --- a/scripts/findks.cgi +++ b/scripts/findks.cgi @@ -22,7 +22,7 @@ import socket import xmlrpclib COBBLER_BASE = "/var/www/cobbler" -XMLRPC_SERVER = "http://127.0.0.1:25151" +XMLRPC_SERVER = "http://127.0.0.1/cobbler_api_rw" #---------------------------------------------------------------------- diff --git a/scripts/index.py b/scripts/index.py new file mode 100755 index 0000000..d32a3a6 --- /dev/null +++ b/scripts/index.py @@ -0,0 +1,160 @@ +""" +mod_python gateway to all interesting cobbler web functions + +Copyright 2007, Red Hat, Inc +Michael DeHaan <mdehaan@redhat.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. +""" + +from mod_python import apache +from mod_python import Session +from mod_python import util + +import xmlrpclib +import cgi +from cobbler.webui import CobblerWeb + +XMLRPC_SERVER = "http://127.0.0.1:25152" # was http://127.0.0.1/cobbler_api_rw" + +#======================================= + +class ServerProxy(xmlrpclib.ServerProxy): + + """ + Establishes a connection from the mod_python + web interface to cobblerd, which incidentally + is also being proxied by Apache. + """ + + def __init__(self, url=None): + xmlrpclib.ServerProxy.__init__(self, url, allow_none=True) + +xmlrpc_server = ServerProxy(XMLRPC_SERVER) + +#======================================= + +def __get_user(req): + """ + What user are we logged in as? + """ + req.add_common_vars() + env_vars = req.subprocess_env.copy() + return env_vars["REMOTE_USER"] + +def __get_session(req): + """ + Get/Create the Apache Session Object + FIXME: any reason to not use MemorySession? + """ + if not hasattr(req,"session"): + req.session = Session.MemorySession(req) + return req.session + +#====================================================== + +def handler(req): + + """ + Right now, index serves everything. + + Hitting this URL means we've already cleared authn/authz + but we still need to use the token for all remote requests. + """ + + my_user = __get_user(req) + my_uri = req.uri + sess = __get_session(req) + token = sess['cobbler_token'] + + # needed? + req.add_common_vars() + + # process form and qs data, if any + fs = util.FieldStorage(req) + form = {} + for x in fs.keys(): + form[x] = str(fs.get(x,'default')) + + # instantiate a CobblerWeb object + cw = CobblerWeb.CobblerWeb( + apache = apache, + token = token, + base_url = "/cobbler/web/", + server = "http://127.0.0.1/cobbler_api_rw" + ) + + # check for a valid path/mode + # handle invalid paths gracefully + mode = form.get('mode','index') + if mode in cw.modes(): + func = getattr( cw, mode ) + content = func( **form ) + else: + func = getattr( cw, 'error_page' ) + content = func( "Invalid Mode: \"%s\"" % mode ) + + # apache.log_error("%s:%s ... %s" % (my_user, my_uri, str(form))) + req.content_type = "text/html" + req.write(content) + + return apache.OK + +#====================================================== + +def authenhandler(req): + + """ + Validates that username/password are a valid combination, but does + not check access levels. + """ + + my_pw = req.get_basic_auth_pw() + my_user = req.user + my_uri = req.uri + + apache.log_error("authenhandler called: %s" % my_user) + try: + token = xmlrpc_server.login(my_user,my_pw) + except Exception, e: + apache.log_error(str(e)) + return apache.HTTP_UNAUTHORIZED + + try: + ok = xmlrpc_server.check_access(token,my_uri) + except Exception, e: + apache.log_error(str(e)) + return apache.HTTP_FORBIDDEN + + + sess=__get_session(req) + sess['cobbler_token'] = token + sess.save() + + return apache.OK + +#====================================================== + +def accesshandler(req): + + """ + Not using this + """ + + return apache.OK + +#====================================================== + +def authenzhandler(req): + + """ + Not using this + """ + + return apache.OK + diff --git a/scripts/nopxe.cgi b/scripts/nopxe.cgi index e90e886..a2eae88 100755 --- a/scripts/nopxe.cgi +++ b/scripts/nopxe.cgi @@ -27,7 +27,7 @@ import xmlrpclib from cobbler import sub_process as sub_process COBBLER_BASE = "/var/www/cobbler" -XMLRPC_SERVER = "http://127.0.0.1:25151" +XMLRPC_SERVER = "http://127.0.0.1/cobbler_api" #---------------------------------------------------------------------- diff --git a/scripts/post_install_trigger.cgi b/scripts/post_install_trigger.cgi new file mode 100644 index 0000000..4a79c8b --- /dev/null +++ b/scripts/post_install_trigger.cgi @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +# 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. +# +# This script runs post install triggers in /var/lib/cobbler/triggers/install/post +# if the triggers are enabled in the settings file. +# +# (C) Tim Verhoeven <tim.verhoeven.be@gmail.com>, 2007 +# tweaked: Michael DeHaan <mdehaan@redhat.com> + +import cgi +import cgitb +import time +import os +import sys +import socket +import xmlrpclib +from cobbler import sub_process as sub_process + +COBBLER_BASE = "/var/www/cobbler" +XMLRPC_SERVER = "http://127.0.0.1/cobbler_api" + +#---------------------------------------------------------------------- + +class ServerProxy(xmlrpclib.ServerProxy): + + def __init__(self, url=None): + xmlrpclib.ServerProxy.__init__(self, url, allow_none=True) + +#---------------------------------------------------------------------- + +def parse_query(): + """ + Read arguments from query string. + """ + + form = cgi.parse() + + if form.has_key("system"): + return form["system"][0] + return 0 + +def invoke(name): + """ + Determine if this feature is enabled. + """ + + xmlrpc_server = ServerProxy(XMLRPC_SERVER) + print xmlrpc_server.run_post_install_triggers(name) + + return True + +#---------------------------------------------------------------------- + +def header(): + print "Content-type: text/plain" + print + +#---------------------------------------------------------------------- + +if __name__ == "__main__": + cgitb.enable(format='text') + header() + name = parse_query() + invoke(name) + + diff --git a/scripts/webui.cgi b/scripts/webui.cgi deleted file mode 100755 index 1a7257d..0000000 --- a/scripts/webui.cgi +++ /dev/null @@ -1,108 +0,0 @@ -#!/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 Cookie -import os -import sys -import ConfigParser -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 - } - - # defaults - if config['server'] is None: - config['server'] = "http://127.0.0.1/cobbler_api_rw" - - if config['base_url'] is None: - config['base_url'] = base_url() - - if ( os.access('/etc/cobbler/auth.conf', os.R_OK) ): - config_parser = ConfigParser.ConfigParser() - auth_conf = open("/etc/cobbler/auth.conf") - config_parser.readfp(auth_conf) - auth_conf.close() - for auth in config_parser.items("xmlrpc_service_users"): - sys.stderr.write( str(auth) ) - if auth[1].lower() != "disabled": - config['username'] = auth[0] - config['password'] = auth[1] - - 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() - - # 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 ) - - # 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 ) - - # deliver content - print "Content-type: text/html" - print - print content - -main() - |
