All pastes #20657 Raw Edit

Untitled

public python v1 · immutable
#20657 ·published 2005-08-21 19:04 UTC
rendered paste body
#!/usr/bin/env pythonclass dhcpd:    def __init__(self, fw):        self.fw = fw    def run(self):        base = '/etc/dhcp3/dhcpd.conf'        src = file('%s.template' % base, 'r')        template = src.read()        src.close()        subnets = ''        hosts = ''        for lanif in self.fw.fwconfig.interfaces['lan']:            if lanif.has_key('dhcpd') and lanif['dhcpd']:                if lanif['dhcpd']['allow_stangers']:                    lanif['dhcpd_range'] = '\n    range %(range_start)s' \                        ' %(range_end)s;' % lanif['dhcpd']                else:                    lanif['dhcpd_range'] = ''                subnets += '''# Expanding SUBNET_DEFINITIONS (%(device)s)subnet %(subnet)s netmask %(netmask)s { %(dhcpd_range)s    option broadcast-address %(broadcast)s;    option domain-name-servers %(ip)s;    option routers %(ip)s;}''' % lanif        template = template.replace('%(subnets)s', subnets)        for user, usrdata in self.fw.fwusers.users.iteritems():            hosts += '''host %s {    hardware ethernet %s;    fixed-address %s;}''' % (user, usrdata['mac'], usrdata['ip'])        template = template.replace('%(hosts)s', hosts)        dst = file(base, 'w')        dst.write(template)        dst.close()        self.fw.check_pid('/var/run/dhcpd.pid',            'invoke-rc.d dhcp3-server restart')