#!/usr/bin/perl # DHCP Conf Parser # Copyright (C) 2002 MandrakeSoft Arnaud Desmons # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package Dhcpconf; require "__WIZ_HOME__/common/scripts/Vareqval.pm"; require "__WIZ_HOME__/common/scripts/DrakconnectConf.pm"; use MDK::Common; use strict; use standalone; my $o = DrakconnectConf->new(); sub do_it { my $wiz_ip_server = $o->get_from_known_dev("IP"); my $wiz_domain_name = $o->get("DomainName"); my $wiz_host_name = $o->get("SystemName"); my $wiz_ip_net = "$1.$2.$3" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; my $wiz_ip_range1 = $ENV{wiz_ip_range1}; my $wiz_ip_range2 = $ENV{wiz_ip_range2}; my $wiz_ip_netmask = $o->get_from_known_dev("Mask"); my $wiz_device = $o->get_device(); # patch to rewrite when got new file about dhcp with INTERFACES value # currently, I put the device to configure as dhcp server # in /etc/sysconfig/dhcpd #[ -f /etc/sysconfig/dhcpd ] && cp -f /etc/sysconfig/dhcpd /var/tmp/wiz_bck/orig/dhcpd my $file = "/etc/sysconfig/dhcpd"; MDK::Common::cp_af($file, $file.".orig"); MDK::Common::append_to_file($file, "INTERFACES=$wiz_device"); $file = "/etc/rc.d/init.d/dhcpd"; # now patching etc/rc.d/init.d/dhcpd standalone::explanations("now patching etc/rc.d/init.d/dhcpd"); if (!`grep INTERFACES $file`){ MDK::Common::cp_af($file, $file . ".orig"); my $tmp = `mktemp /tmp/Dhcpconf.XXXXXX` or die "can't make a temp file: $!"; open(NEW, "> $tmp") or die "can't open $tmp: $!"; open(OLD, "< $file") or die "can't open default: $!"; while () { if (m|daemon\s*/usr/sbin/dhcp|) { print NEW "\tif [ -f /etc/sysconfig/dhcpd ]; then \t\t. /etc/sysconfig/dhcpd \t\tDEV=\$INTERFACES \tfi\n"; } print NEW $_; } close(OLD); close(NEW); chomp($tmp); system("mv $tmp $file"); } $file = "/etc/dhcpd.conf"; MDK::Common::cp_af($file, $file.".orig"); output($file, map { s|__hname__|$wiz_host_name|g; s|__net__|$wiz_ip_net|g; s|__ip__|$wiz_ip_server|g; s|__mask__|$wiz_ip_netmask|g; s|__rng1__|$wiz_ip_range1|g; s|__rng2__|$wiz_ip_range2|g; s|__dname__|$wiz_domain_name|g; $_; } cat_ ("__WIZ_HOME__/dhcp_wizard/scripts/dhcpd.conf.default")); standalone::explanations("$file: hname = $wiz_host_name, net = $wiz_ip_net, ip = $wiz_ip_server, mask = $wiz_ip_netmask, rng1 = $wiz_ip_range1, rng2 = $wiz_ip_range2, dname = $wiz_domain_name"); MDK::Common::touch("/var/dhcpd/dhcpd.leases"); # modifying webmin config $file="/etc/webmin/dhcpd/config"; if (-f $file) { my %mdk = Vareqval->get($file); $mdk{lease_file} = "/var/dhcpd/dhcpd.leases"; $mdk{interfaces} = $wiz_device; standalone::explanations("$file: lease_file = $mdk{lease_file}, interfaces = $mdk{interfaces}"); Vareqval->commit($file, \%mdk); } system("/etc/rc.d/init.d/dhcpd restart"); 10; } 1;