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 /legacy | |
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 'legacy')
-rwxr-xr-x | legacy/change_profile.cgi | 86 | ||||
-rwxr-xr-x | legacy/findks.cgi | 153 | ||||
-rw-r--r-- | legacy/install_trigger.cgi | 87 | ||||
-rwxr-xr-x | legacy/nopxe.cgi | 80 | ||||
-rwxr-xr-x | legacy/register_mac.cgi | 105 | ||||
-rwxr-xr-x | legacy/watcher.py | 63 |
6 files changed, 574 insertions, 0 deletions
diff --git a/legacy/change_profile.cgi b/legacy/change_profile.cgi new file mode 100755 index 0000000..f7330f1 --- /dev/null +++ b/legacy/change_profile.cgi @@ -0,0 +1,86 @@ +#!/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/legacy/findks.cgi b/legacy/findks.cgi new file mode 100755 index 0000000..39adbcf --- /dev/null +++ b/legacy/findks.cgi @@ -0,0 +1,153 @@ +#!/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/legacy/install_trigger.cgi b/legacy/install_trigger.cgi new file mode 100644 index 0000000..b83ff57 --- /dev/null +++ b/legacy/install_trigger.cgi @@ -0,0 +1,87 @@ +#!/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/legacy/nopxe.cgi b/legacy/nopxe.cgi new file mode 100755 index 0000000..a2eae88 --- /dev/null +++ b/legacy/nopxe.cgi @@ -0,0 +1,80 @@ +#!/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/legacy/register_mac.cgi b/legacy/register_mac.cgi new file mode 100755 index 0000000..3f251c4 --- /dev/null +++ b/legacy/register_mac.cgi @@ -0,0 +1,105 @@ +#!/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/register_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/legacy/watcher.py b/legacy/watcher.py new file mode 100755 index 0000000..dfa8dc3 --- /dev/null +++ b/legacy/watcher.py @@ -0,0 +1,63 @@ +# 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() + |