#!/usr/bin/env python """ Author: Bas van der Vlies Date : 12 February 2002 Desc. : This script is used to control how a node is booted with PXE enabled network cards. The PC boots starts and fetch a pxe config file which tells how the PC must boot. This daemon enables a client to remove his pxe-config file. It then uses the DEFAULT one. Note: This server can ONLY be started from inetd. CVS info $Date: 2002/02/18 15:02:00 $ $Revision: 1.1 $ """ import time import socket import sys import os import string import syslog # DEBUG # DEBUG=1 # Some Global Constants # BUFSIZE=4096 STDIN=0 STDOUT=1 PXE_CONF_DIR = '/tftpboot/pxelinux.cfg' # Give the current time # def now(): return time.ctime(time.time()) def remove_link(filename): """This removes the pxe config filename for the host that is connected: filename : string """ file = os.path.join(PXE_CONF_DIR, filename) if DEBUG: print 'file = %s' %file if not os.path.exists(file): return if os.path.islink(file): try: os.unlink(file) syslog.openlog("pxeconfigd") syslog.syslog(syslog.LOG_INFO, file) syslog.closelog() except OSError: err_msg = "No permission at directory: %s" %PXE_CONF_DIR os.write(STDOUT, err_msg) sys.exit(1) # This function handles the client connection. It closes # the connection if there is no data # def handleConnection(): """Determines which host connects to the server """ # Determine client address # try: client_addr = socket.fromfd(sys.stdin.fileno(), socket.AF_INET, socket.SOCK_STREAM) client_ip = client_addr.getpeername()[0] except socket.error, detail: print "pxeconfigd can only be started from inetd!!!" sys.exit(1) # translate ip address ---> hex address # d = string.split(client_ip, '.') client_haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3])) if DEBUG: print 'ip = %s, hex = %s' %(client_ip, client_haddr) remove_link(client_haddr) sys.exit(0) def server(): """Start the daemon """ if not os.path.isdir(PXE_CONF_DIR): os.write(STDOUT, "PXE booting is not configured") sys.exit(1) handleConnection() if __name__ == '__main__': server()