#!/usr/bin/python -t import os import string import socket import syslog import re def getKickstartDesignation(listfile, hostname): file = open(listfile, 'r') contents = file.read() ## # Remove all comments, strip spaces and remove resulting blank lines, # and strip the trailing newline, if any. # contents = re.sub(re.compile('^#.*\n', re.M), '', contents) contents = re.sub('[ \t]*', '', contents) contents = re.sub(re.compile('^\n', re.M), '', contents) contents = re.sub('\n$', '', contents) # # Split lines into a dictionary entries = string.split(contents, '\n') # # Iterate through entries and return the first match, if any. # Remember _default_ if we run across it. defaultks = '' for entry in entries: (hostregex, kscfg) = string.split(entry, '=') if hostregex == '_default_': defaultks = kscfg elif re.compile('^' + hostregex).match(hostname): return (kscfg, hostregex) return (defaultks, 'none, default used') ipaddr = os.environ['REMOTE_ADDR'] (remotehost, aliases, ip) = socket.gethostbyaddr(ipaddr) (ksdes, matchregex) = getKickstartDesignation('ks.list', remotehost) pathtoks = '/srv/install/linux/ks/' kscfg = '%s/%s' % (pathtoks, ksdes) file = open(kscfg, 'r') sysmsg = 'Kickstarting %s with install type %s' % (remotehost, ksdes) syslog.openlog('kscgi') syslog.syslog(syslog.LOG_NOTICE, sysmsg) syslog.closelog() print "Content-type: text/plain" print print "# System: %s" % remotehost print "# Kickstart type: %s" % ksdes print "# Matching entry: %s" % matchregex print "#" print file.read()