diff options
author | Michael DeHaan <mdehaan@redhat.com> | 2008-04-18 17:31:26 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@redhat.com> | 2008-04-18 17:31:26 -0400 |
commit | efbcc041464733e90af670a5d1dfe13e70aaa05c (patch) | |
tree | e04450dfaed37ad8757f0e96d5314d36a46444b0 /scripts | |
parent | b15ca0fe01a01ee6792c857e766642d9d50ab760 (diff) | |
download | third_party-cobbler-efbcc041464733e90af670a5d1dfe13e70aaa05c.tar.gz third_party-cobbler-efbcc041464733e90af670a5d1dfe13e70aaa05c.tar.xz third_party-cobbler-efbcc041464733e90af670a5d1dfe13e70aaa05c.zip |
Kickstarts are now dynamically generated by mod_python, CGI's now fall
under mod_python, kickstart templating code now moved out of sync function.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/change_profile.cgi | 86 | ||||
-rwxr-xr-x | scripts/findks.cgi | 153 | ||||
-rw-r--r-- | scripts/install_trigger.cgi | 87 | ||||
-rwxr-xr-x | scripts/nopxe.cgi | 80 | ||||
-rwxr-xr-x | scripts/register_mac.cgi | 105 | ||||
-rwxr-xr-x | scripts/services.py | 67 | ||||
-rwxr-xr-x | scripts/watcher.py | 63 |
7 files changed, 67 insertions, 574 deletions
diff --git a/scripts/change_profile.cgi b/scripts/change_profile.cgi deleted file mode 100755 index f7330f1..0000000 --- a/scripts/change_profile.cgi +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python - -# Michael DeHaan <mdehaan@redhat.com> -# (C) 2008 Red Hat Inc -# -# 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. - -# what is this? This is a -# script to change cobbler profiles for the requestor -# from one profile to another, as specified by ?profile=foo -# ex: wget http://cobbler.example.org/cgi-bin/change_profile.cgi?profile=foo -# suitable to be called from kickstart,etc - -import cgi -import cgitb -import time -import os -import sys -import socket -import xmlrpclib - -COBBLER_BASE = "/var/www/cobbler" -XMLRPC_SERVER = "http://127.0.0.1/cobbler_api" -DEFAULT_PROFILE = "default" - -#---------------------------------------------------------------------- - -class ServerProxy(xmlrpclib.ServerProxy): - - def __init__(self, url=None): - xmlrpclib.ServerProxy.__init__(self, url, allow_none=True) - -#---------------------------------------------------------------------- - -def parse_query(): - - form = cgi.parse() - - mac = "-1" - if os.environ.has_key("HTTP_X_RHN_PROVISIONING_MAC_0"): - # FIXME: will not key off other NICs - devicepair = os.environ["HTTP_X_RHN_PROVISIONING_MAC_0"] - return devicepair.split()[1].strip() - - if form.has_key("profile"): - profile = form["profile"][0] - else: - profile = DEFAULT_PROFILE - system = autodetect() - print "# incoming profile = %s" % profile - print "# incoming system = %s" % system - return (system["name"],profile) - -#---------------------------------------------------------------------- - -def autodetect(): - # get mac address, requires kssendmac on the kernel options line. - else: - return "-1" - - -#---------------------------------------------------------------------- - -def header(): - print "Content-type: text/plain" - print - -#---------------------------------------------------------------------- - -if __name__ == "__main__": - cgitb.enable(format='text') - header() - server = ServerProxy(XMLRPC_SERVER) - (mac, profile) = parse_query() - try: - ip = os.environ["REMOTE_ADDR"] - except: - ip = "???" - print "# attempting to change system(mac=%s) to profile(%s)" % (mac,profile) - server.change_profile(mac,profile) - diff --git a/scripts/findks.cgi b/scripts/findks.cgi deleted file mode 100755 index 39adbcf..0000000 --- a/scripts/findks.cgi +++ /dev/null @@ -1,153 +0,0 @@ -#!/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. - -# based on: -# Cobbler ks-serving script -# July 5 2007 -# Adam Wolf <adamwolf@feelslikeburning.com> -# http://feelslikeburning.com/projects/live-cd-restoring-with-cobbler/ - -import cgi -import cgitb -import time -import os -import sys -import socket -import xmlrpclib - -COBBLER_BASE = "/var/www/cobbler" -XMLRPC_SERVER = "http://127.0.0.1/cobbler_api_rw" - -#---------------------------------------------------------------------- - -class ServerProxy(xmlrpclib.ServerProxy): - - def __init__(self, url=None): - xmlrpclib.ServerProxy.__init__(self, url, allow_none=True) - -#---------------------------------------------------------------------- - -def parse_query(): - - form = cgi.parse() - - if form.has_key("system"): - name = form["system"][0] - type = "system" - elif form.has_key("profile"): - name = form["profile"][0] - type = "profile" - else: - type = "system" - name = autodetect() - return (name,type) - -#---------------------------------------------------------------------- - -def autodetect(): - - # connect to cobblerd and get the list of systems - - try: - xmlrpc_server = ServerProxy(XMLRPC_SERVER) - systems = xmlrpc_server.get_systems() - except: - print "# could not contact cobblerd at %s" % XMLRPC_SERVER - sys.exit(1) - - # if kssendmac was in the kernel options line, see - # if a system can be found matching the MAC address. This - # is more specific than an IP match. - - if os.environ.has_key("HTTP_X_RHN_PROVISIONING_MAC_0"): - # FIXME: will not key off other NICs - devicepair = os.environ["HTTP_X_RHN_PROVISIONING_MAC_0"] - mac = devicepair.split()[1].strip() - # mac is the macaddress of the first nic reported by anaconda - - candidates = [] - for x in systems: - - for y in x["interfaces"]: - if x["interfaces"][y]["ip_address"] == ip: - candidates.append(x) - - if len(candidates) == 0: - print "# no system entries with MAC %s found" % mac - print "# trying IP lookup" - elif len(candidates) > 1: - print "# multiple system entries with MAC %s found" % mac - sys.exit(1) - elif len(candidates) == 1: - print "# kickstart matched by MAC: %s" % mac - return candidates[0] - - # attempt to match by the IP. - - ip = os.environ["REMOTE_ADDR"] - candidates = [system['name'] for system in systems if system['ip_address'] == ip] - - if len(candidates) == 0: - print "# no system entries with ip %s found" % ip - sys.exit(1) - elif len(candidates) > 1: - print "# multiple system entries with ip %s found" % ip - sys.exit(1) - elif len(candidates) == 1: - return candidates[0] - -#---------------------------------------------------------------------- - -def serve_file(name): - - # never hurts to be safe... - name = name.replace("/","") - name = name.replace("..","") - name = name.replace(";","") - - if type == "system": - ks_path = "%s/kickstarts_sys/%s/ks.cfg" % (COBBLER_BASE, name) - elif type == "profile": - ks_path = "%s/kickstarts/%s/ks.cfg" % (COBBLER_BASE, name) - - if not os.path.exists(ks_path): - print "# no such cobbler object" - sys.exit(1) - - try: - ksfile = open(ks_path) - except: - print "# Cannot open file %s" % ks_path - sys.exit(1) - - for line in ksfile: - print line.strip() - ksfile.close() - -#---------------------------------------------------------------------- - -def header(): - print "Content-type: text/plain" - print - print "# kickstart managed by Cobbler -- http://cobbler.et.redhat.com" - print "# served on %s" % time.ctime() - -#---------------------------------------------------------------------- - -if __name__ == "__main__": - cgitb.enable(format='text') - header() - (name, type) = parse_query() - print "# %s %s" % (type,name) - print "# requestor ip = %s" % os.environ["REMOTE_ADDR"] - print "# =============================" - print " " - serve_file(name) - - diff --git a/scripts/install_trigger.cgi b/scripts/install_trigger.cgi deleted file mode 100644 index b83ff57..0000000 --- a/scripts/install_trigger.cgi +++ /dev/null @@ -1,87 +0,0 @@ -#!/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>, 2007-2008 - -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() - - ip = "?" - if os.environ.has_key("REMOTE_ADDR"): - ip = os.environ["REMOTE_ADDR"] - - name = "?" - objtype = "?" - if form.has_key("system"): - name = form["system"][0] - objtype = "system" - elif form.has_key("profile"): - name = form["profile"][0] - objtype = "profile" - - mode = "?" - if form.has_key("mode"): - mode = form["mode"][0] - - return (mode,objtype,name,ip) - -def invoke(mode,objtype,name,ip): - """ - Determine if this feature is enabled. - """ - - xmlrpc_server = ServerProxy(XMLRPC_SERVER) - print xmlrpc_server.run_install_triggers(mode,objtype,name,ip) - - return True - -#---------------------------------------------------------------------- - -def header(): - print "Content-type: text/plain" - print - -#---------------------------------------------------------------------- - -if __name__ == "__main__": - cgitb.enable(format='text') - header() - (mode,objtype,name,ip) = parse_query() - invoke(mode,objtype,name,ip) - - diff --git a/scripts/nopxe.cgi b/scripts/nopxe.cgi deleted file mode 100755 index a2eae88..0000000 --- a/scripts/nopxe.cgi +++ /dev/null @@ -1,80 +0,0 @@ -#!/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 disables the netboot flag for a given -# system if (and only if) pxe_just_once is enabled in settings. -# It must not be able to do anything else for security -# reasons. -# -# -# (C) Red Hat, 2007 -# 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 disable(name): - """ - Determine if this feature is enabled. - """ - - #try: - xmlrpc_server = ServerProxy(XMLRPC_SERVER) - print xmlrpc_server.disable_netboot(name) - #except: - # print "# could not contact cobblerd at %s" % XMLRPC_SERVER - # sys.exit(1) - - return True - -#---------------------------------------------------------------------- - -def header(): - print "Content-type: text/plain" - print - -#---------------------------------------------------------------------- - -if __name__ == "__main__": - cgitb.enable(format='text') - header() - name = parse_query() - disable(name) - - diff --git a/scripts/register_mac.cgi b/scripts/register_mac.cgi deleted file mode 100755 index 5507525..0000000 --- a/scripts/register_mac.cgi +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python - -# Michael DeHaan <mdehaan@redhat.com> -# (C) 2008 Red Hat Inc -# -# 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. - -# what is this? This is a -# script to auto add systems who make a wget into cobbler. -# right now it requires "kssendmac" in kernel options and takes only 1 arg -# ex: wget http://cobbler.example.org/cgi-bin/regsister_mac?profile=foo -# suitable to be called from kickstart,etc - -import cgi -#import cgitb -import time -import os -import sys -import socket -import xmlrpclib - -# FIXME: edit these two variables to match your webui configuration -USERNAME = "cobbler" -PASSWORD = "cobbler" - -COBBLER_BASE = "/var/www/cobbler" -XMLRPC_SERVER = "http://127.0.0.1/cobbler_api_rw" -DEFAULT_PROFILE = "default" - -#---------------------------------------------------------------------- - -class ServerProxy(xmlrpclib.ServerProxy): - - def __init__(self, url=None): - xmlrpclib.ServerProxy.__init__(self, url, allow_none=True) - -#---------------------------------------------------------------------- - -def parse_query(): - - form = cgi.parse() - - if form.has_key("profile"): - profile = form["profile"][0] - else: - profile = DEFAULT_PROFILE - mac = autodetect() - print "# incoming profile = %s" % profile - return (mac,profile) - -#---------------------------------------------------------------------- - -def autodetect(): - - # connect to cobblerd and get the list of systems - - try: - xmlrpc_server = ServerProxy(XMLRPC_SERVER) - systems = xmlrpc_server.get_systems() - except: - print "# could not contact cobblerd at %s" % XMLRPC_SERVER - sys.exit(1) - - # if kssendmac was in the kernel options line, see - # if a system can be found matching the MAC address. This - # is more specific than an IP match. - - if os.environ.has_key("HTTP_X_RHN_PROVISIONING_MAC_0"): - # FIXME: will not key off other NICs - devicepair = os.environ["HTTP_X_RHN_PROVISIONING_MAC_0"] - mac = devicepair.split()[1].strip() - print "# discovered MAC: %s" % mac.lower() - return mac.lower() - else: - print "# missing kssendmac in the kernel args? Can't continue." - return "BB:EE:EE:EE:EE:FF" - -#---------------------------------------------------------------------- - - -def make_change(server,mac,profile,token): - server.register_mac(mac,profile) - -#---------------------------------------------------------------------- - -def header(): - print "Content-type: text/plain" - print - -#---------------------------------------------------------------------- - -if __name__ == "__main__": - #cgitb.enable(format='text') - header() - server = ServerProxy(XMLRPC_SERVER) - token = server.login(USERNAME,PASSWORD) - (mac, profile) = parse_query() - print "# running for %s %s" % (mac,profile) - make_change(server,mac,profile,token) - diff --git a/scripts/services.py b/scripts/services.py new file mode 100755 index 0000000..07243ae --- /dev/null +++ b/scripts/services.py @@ -0,0 +1,67 @@ +""" +mod_python gateway to cgi-like cobbler web functions + +Copyright 2007-2008, 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 +import os +from cobbler.services import CobblerSvc + +#======================================= + +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_uri = req.uri + + # apache.log_error("cannot load /var/lib/cobbler/web.ss") + 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')) + + form["REMOTE_ADDR"] = req.subprocess_env.get("REMOTE_ADDR",None) + form["REMOTE_MAC"] = req.subprocess_env.get("HTTP_X_RHN_PROVISIONING_MAC_0",None) + + # instantiate a CobblerWeb object + cw = CobblerSvc( + apache = apache, + server = "http://127.0.0.1/cobbler_api" + ) + + # check for a valid path/mode + # handle invalid paths gracefully + mode = form.get('op','index') + + func = getattr( cw, mode ) + content = func( **form ) + + # apache.log_error("%s:%s ... %s" % (my_user, my_uri, str(form))) + req.content_type = "text/plain" + req.write(content) + + return apache.OK + diff --git a/scripts/watcher.py b/scripts/watcher.py deleted file mode 100755 index dfa8dc3..0000000 --- a/scripts/watcher.py +++ /dev/null @@ -1,63 +0,0 @@ -# cobbler mod_python handler for observing kickstart activity -# -# 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. - -import time -from mod_python import apache - -def outputfilter(filter): - - - # extract important info - request = filter.req - connection = request.connection - (address,port) = connection.remote_addr - - # open the logfile (directory be set writeable by installer) - logfile = open("/var/log/cobbler/kicklog/%s" % address,"a+") - - log_it = True - if request.the_request.find("cobbler_track") == -1 and request.the_request.find("cblr/") == -1: - log_it = False - - if log_it: - # write the timestamp - t = time.localtime() - seconds = str(time.mktime(t)) - logfile.write(seconds) - logfile.write("\t") - timestr = str(time.asctime(t)) - logfile.write(timestr) - logfile.write("\t") - - # write the IP address of the client - logfile.write(address) - logfile.write("\t") - - # write the filename being requested - logfile.write(request.the_request) - # logfile.write(request.filename) - logfile.write("\n") - - # if requesting this file, don't return it - if request.the_request.find("watcher.py") != -1: - filter.close() - return - - # pass-through filter - s = filter.read() - while s: - filter.write(s) - s = filter.read() - if s is None: - filter.close() - logfile.close() - |