diff options
author | Arnaud Desmons <adesmons@mandriva.com> | 2002-08-26 09:44:07 +0000 |
---|---|---|
committer | Arnaud Desmons <adesmons@mandriva.com> | 2002-08-26 09:44:07 +0000 |
commit | 81adda61c911154f2ed92724f07336011e207844 (patch) | |
tree | f0ca4885ad7fa6eed406d717031a3cf4a9081dba /dhcp_wizard | |
parent | 5862040f732cfbaf570f7f6656514ef95b7af64c (diff) | |
download | drakwizard-81adda61c911154f2ed92724f07336011e207844.tar drakwizard-81adda61c911154f2ed92724f07336011e207844.tar.gz drakwizard-81adda61c911154f2ed92724f07336011e207844.tar.bz2 drakwizard-81adda61c911154f2ed92724f07336011e207844.tar.xz drakwizard-81adda61c911154f2ed92724f07336011e207844.zip |
explanations and pixel shortcuts
Diffstat (limited to 'dhcp_wizard')
-rw-r--r-- | dhcp_wizard/scripts/Dhcpconf.pm | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/dhcp_wizard/scripts/Dhcpconf.pm b/dhcp_wizard/scripts/Dhcpconf.pm index 3a3a3e8d..3f88e414 100644 --- a/dhcp_wizard/scripts/Dhcpconf.pm +++ b/dhcp_wizard/scripts/Dhcpconf.pm @@ -1,34 +1,41 @@ #!/usr/bin/perl +# DHCP Conf Parser + +# Copyright (C) 2002 MandrakeSoft Arnaud Desmons <adesmons@mandrakesoft.com> +# +# 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 %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_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}; - $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; + 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 @@ -36,11 +43,11 @@ sub do_it { #[ -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(NEW) or die "can not close $file: $!"; + 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: $!"; @@ -62,13 +69,7 @@ sub do_it { } $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>) { + output($file, map { s|__hname__|$wiz_host_name|g; s|__net__|$wiz_ip_net|g; s|__ip__|$wiz_ip_server|g; @@ -76,19 +77,19 @@ sub do_it { s|__rng1__|$wiz_ip_range1|g; s|__rng2__|$wiz_ip_range2|g; s|__dname__|$wiz_domain_name|g; - print NEW $_; - } - close(OLD); - close(NEW); - chomp($tmp); - system("mv $tmp $file"); + $_; + } 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"); 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); + 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; |