source: trunk/pxeconfigd @ 67

Last change on this file since 67 was 45, checked in by bas, 20 years ago

update version info for:

  • pxeconfig, pxeconfigd and control

postinst:

  • Fixed an bug two entries for xinetd.d

Authors:

  • Added Ramon Bastiaans

INSTALL:

  • update info for xinetd
  • Property keywords set to Id
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (C) 2002
4#
5# This file is part of the pxeconfig utils
6#
7# This program is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the
9# Free Software Foundation; either version 2, or (at your option) any
10# later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
20#
21# SVN info
22#  $Id: pxeconfigd 45 2004-09-03 11:40:04Z bas $
23"""
24Author: Bas van der Vlies <basv@sara.nl>
25Date  : 12 February 2002
26Desc. : This script is used to control how a node is booted with PXE
27        enabled network cards. The node boots and fetch a pxe
28        config file which tells how the node must boot. This daemon
29        enables a client to remove his/here pxe config file. With the
30        next boot it will use the default one.
31
32        command line option:
33          -d/--directory <dir>
34            Where <dir> is the directory where the pxe config files reside.
35          -V/--version
36            Prints the version number and exits
37         
38        Note:
39          This server can ONLY be started from inetd.
40"""
41import time
42import socket
43import sys
44import os
45import string
46import syslog
47import getopt
48
49# DEBUG
50#
51DEBUG=1
52
53# Some Global Constants
54#
55BUFSIZE=4096
56STDIN=0
57STDOUT=1
58SHORTOPT_LIST='Vd:'
59LONGOPT_LIST=['version', 'directory=']
60
61PXE_CONF_DIR = '/tftpboot/pxelinux.cfg'
62VERSION = '0.4.4'
63
64# Give the current time
65#
66def now():
67    return time.ctime(time.time())
68
69
70def remove_link(filename):
71  """This removes the pxe config filename for the host that is connected:
72      filename : string
73  """
74
75  file = os.path.join(PXE_CONF_DIR, filename)
76
77  if DEBUG:
78    print 'file = %s' %file
79
80  if not os.path.exists(file): return
81
82  if os.path.islink(file): 
83    try:
84      os.unlink(file)
85      syslog.openlog("pxeconfigd")
86      syslog.syslog(syslog.LOG_INFO, file)
87      syslog.closelog()
88    except OSError:
89      err_msg = "No permission at directory: %s" %PXE_CONF_DIR
90      os.write(STDOUT, err_msg)
91      sys.exit(1)
92
93# This function handles the client connection. It closes
94# the connection if there is no data
95#
96def handleConnection():
97  """Determines which host connects to the server
98  """
99
100  # Determine client address
101  #
102  try:
103    client_addr = socket.fromfd(sys.stdin.fileno(), socket.AF_INET, 
104                          socket.SOCK_STREAM)
105    client_ip = client_addr.getpeername()[0] 
106
107  except socket.error, detail:
108    print "pxeconfigd can only be started from inetd!!!"
109    sys.exit(1)
110
111
112  # translate ip address ---> hex address
113  #
114  d = string.split(client_ip, '.')
115  client_haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3]))
116
117  if DEBUG:
118    print 'ip = %s, hex = %s' %(client_ip, client_haddr)
119
120  remove_link(client_haddr)
121  sys.exit(0)
122
123def check_args(argv):
124  """
125  Must we use another directory for the PXE configuration
126  """
127  global PXE_CONF_DIR
128
129  try:
130    opts, args = getopt.getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST)
131  except getopt.error, detail:
132    print __doc__
133    print detail
134    sys.exit(1)
135
136  for opt, value in opts:
137
138    if opt in ['-d', '--directory']:
139      if not os.path.isdir(value):
140        os.write(STDOUT, "PXE booting is not configured")
141        sys.exit(1)
142      else:
143        PXE_CONF_DIR = value
144
145    elif opt in ['-V', '--version']:
146      print VERSION
147      sys.exit(0)
148
149def server():
150  """Start the daemon
151  """
152  check_args(sys.argv)
153  handleConnection()
154
155if __name__ == '__main__':
156  server()
Note: See TracBrowser for help on using the repository browser.