diff options
Diffstat (limited to 'dhcp_wizard')
-rw-r--r-- | dhcp_wizard/scripts/Dhcpconf.pm | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/dhcp_wizard/scripts/Dhcpconf.pm b/dhcp_wizard/scripts/Dhcpconf.pm new file mode 100644 index 00000000..9c38736a --- /dev/null +++ b/dhcp_wizard/scripts/Dhcpconf.pm @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +package Dhcpconf; +require "__WIZ_HOME__/common/scripts/Vareqval.pm"; +use MDK::Common; +use strict; + +sub do_it { + my %mdk = Vareqval->get("/etc/sysconfig/mdk_serv"); + my $wiz_domain_name = $mdk{wiz_domain_name} if defined $mdk{wiz_domain_name} or + die "wiz_domain_name not in /etc/sysconfig/mdk_serv"; + my $wiz_host_name = $mdk{wiz_host_name} if defined $mdk{wiz_host_name} or + die "wiz_host_name not in /etc/sysconfig/mdk_serv"; + + defined $ENV{wiz_ip_range1} or die "wiz_ip_range1 not defined : $!"; + defined $ENV{wiz_ip_range2} or die "wiz_ip_range2 not defined : $!"; + my $wiz_ip_range1 = $ENV{wiz_ip_range1}; + my $wiz_ip_range2 = $ENV{wiz_ip_range2}; + $mdk{wiz_ip_range1} = $wiz_ip_range1; + $mdk{wiz_ip_range2} = $wiz_ip_range2; + + my $wiz_device = $mdk{wiz_device} if defined $mdk{wiz_device} or + die "wiz_device not in /etc/sysconfig/mdk_serv"; + Vareqval->commit("/etc/sysconfig/mdk_serv", \%mdk); + my %mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$wiz_device); + my $wiz_ip_net = $mdk{NETWORK} if defined $mdk{NETWORK} or + die "NETWORK not in /etc/sysconfig/network-scripts/ifcfg-".$wiz_device; + my $wiz_ip_server = $mdk{IPADDR} if defined $mdk{IPADDR} or + die "IPADDR not in /etc/sysconfig/network-scripts/ifcfg-".$wiz_device; + my $wiz_ip_netmask = $mdk{NETMASK} if defined $mdk{NETMASK} or + die "NETMASK not in /etc/sysconfig/network-scripts/ifcfg-".$wiz_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"); + open(NEW, "> $file") or die "can not open $file: $!"; + print NEW "INTERFACES=$wiz_device\n"; + close($file) or die "can not close $file: $!"; + $file = "/etc/rc.d/init.d/dhcpd"; +# 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 (<OLD>) { + 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); + MDK::Common::cp_af($tmp, $file); + } + $file = "/etc/dhcpd.conf"; + MDK::Common::cp_af($file, $file.".orig"); + my $tmp = `mktemp /tmp/Dhcpdconf.XXXXXX` or + die "can't make a temp file: $!"; + open(NEW, "> $tmp") or + die "can't open $tmp: $!"; + open(OLD, "< __WIZ_HOME__/dhcp_wizard/scripts/dhcpd.conf.default") or + die "can't open default: $!"; + while (<OLD>) { + 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; + print NEW $_; + } + close(OLD); + close(NEW); + MDK::Common::cp_af($tmp, $file); + system("touch /var/dhcpd/dhcpd.leases") or die "can not touch /var/dhcpd/dhcd.leases: $!"; +# modifying webmin config + $file="/etc/webmin/dhcpd/config"; + if (-f $file) { + %mdk = Vareqval->get($file); + $mdk{lease_file} = "/var/dhcpd/dhcpd.leases"; + $mdk{interfaces} = $wiz_device; + } + system("/etc/rc.d/init.d/dhcpd restart"); +} + |