summaryrefslogtreecommitdiffstats
path: root/dns_wizard/scripts
diff options
context:
space:
mode:
authorArnaud Desmons <adesmons@mandriva.com>2002-07-26 09:21:20 +0000
committerArnaud Desmons <adesmons@mandriva.com>2002-07-26 09:21:20 +0000
commit8713aefb261a6574396bc11929f8d445360c5ffd (patch)
treec219c63a160caf55644e68dfdc3b5b3338c6d322 /dns_wizard/scripts
parent73b46aef2e46fbd345e1186dc28c33ac64283e0f (diff)
downloaddrakwizard-8713aefb261a6574396bc11929f8d445360c5ffd.tar
drakwizard-8713aefb261a6574396bc11929f8d445360c5ffd.tar.gz
drakwizard-8713aefb261a6574396bc11929f8d445360c5ffd.tar.bz2
drakwizard-8713aefb261a6574396bc11929f8d445360c5ffd.tar.xz
drakwizard-8713aefb261a6574396bc11929f8d445360c5ffd.zip
first perl traduction
Diffstat (limited to 'dns_wizard/scripts')
-rw-r--r--dns_wizard/scripts/Dnsconf.pm163
1 files changed, 163 insertions, 0 deletions
diff --git a/dns_wizard/scripts/Dnsconf.pm b/dns_wizard/scripts/Dnsconf.pm
new file mode 100644
index 00000000..11f92a99
--- /dev/null
+++ b/dns_wizard/scripts/Dnsconf.pm
@@ -0,0 +1,163 @@
+#!/usr/bin/perl
+
+package Dnsconf;
+require "__WIZ_HOME__/common/scripts/Vareqval.pm";
+use MDK::Common;
+use strict;
+
+sub up_serial {
+ my ($file) = @_;
+
+ my $serial_nbm = `date +%Y%m%d00` or die "date not found: $!";
+ my $tmp = `mktemp /tmp/Dnsconf.XXXXXX` or die "can't make a temp file: $!";
+ open(OLD, "< $file") or die "can't open $file: $!";
+ open(NEW, "> $tmp") or die "can't open $tmp: $!";
+ while (<OLD>) {
+ if (/^([[:space:]]*)([0-9]*)([[:space:]]*;[[:space:]]*Serial.*)$/) {
+ my $serial_f = $2;
+ $serial_f++;
+ if ($serial_f <= $serial_nbm) {
+ $serial_f = $serial_nbm;
+ chomp($serial_f);
+ $_ = "$1$serial_f$3\n";
+ }
+ }
+ print NEW $_;
+ }
+ close(OLD) or die "can't close $file: $!";
+ close(NEW) or die "can't close $tmp: $!";
+ MDK::Common::cp_af($tmp, $file);
+}
+
+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";
+
+ my $device = $mdk{wiz_device} if defined $mdk{wiz_host_name} or
+ die "wiz_device not in /etc/sysconfig/mdk_serv";
+ my %mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$device);
+ my $wiz_ip_net = $mdk{NETWORK} if defined $mdk{NETWORK} or
+ die "NETWORK not in /etc/sysconfig/network-scripts/ifcfg-$device";
+ my $wiz_ip_server = $mdk{IPADDR} if defined $mdk{IPADDR} or
+ die "IPADDR not in /etc/sysconfig/network-scripts/ifcfg-$device";
+
+ my $s_trunc = "$1.$2.$3" if $wiz_ip_net =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $ds = "$4" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $host = "$1" if $wiz_host_name =~ /(.*?)\..*/;
+ my $reversnet = "$3$2$1" if $wiz_ip_net =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $file = "/etc/host.conf";
+
+ MDK::Common::cp_af($file, $file.".orig");
+ MDK::Common::cp_af("__WIZ_HOME__/dns_wizard/scripts/host.conf.default", $file);
+
+ $file = "/etc/named.conf";
+ MDK::Common::cp_af($file, $file.".orig");
+
+# now putting ${file} configuration"
+
+ my $tmp = `mktemp /tmp/Dnsconf.XXXXXX` or die "can't make a temp file: $!";
+ open(OLD, "< __WIZ_HOME__/dns_wizard/scripts/host.conf.default") or die "can't open default: $!";
+ open(NEW, "> $tmp") or die "can't open $tmp: $!";
+ my $ispns1 = $ENV{wiz_ext_dns1} || "// __ISPN1__";
+ my $ispns2 = $ENV{wiz_ext_dns2} || "// __ISPN2__";
+ while (<OLD>) {
+ s|__ISPNS1__|$ispns1|g;
+ s|__ISPNS2__|$ispns2|g;
+ s|__dname__|$wiz_domain_name|g;
+ s|__revnet__|$reversnet|g;
+ s|__net__|$s_trunc|g;
+ print NEW $_;
+ }
+ close(OLD);
+ close(NEW);
+ MDK::Common::cp_af($tmp, $file);
+# MDK::Common::rm_rf($tmp);
+# Bug fix for bind 9:
+ if (! -f "/etc/rndc.key") {system("touch /etc/rndc.key") or die "can not touch /etc/rndc.key: $!"};
+
+# root.hints
+ $file="/var/named/root.hints";
+ MDK::Common::cp_af($file, $file . ".orig");
+ MDK::Common::cp_af("__WIZ_HOME__/dns_wizard/scripts/root.hints.default", $file);
+ $file="/var/named/127.0.0.rev";
+ MDK::Common::cp_af($file, $file . ".orig");
+ my $tmp = `mktemp /tmp/Dnsconf.XXXXXX` or
+ die "can't make a temp file: $!";
+ open(NEW, "> $tmp") or
+ die "can't open $tmp: $!";
+ open(OLD, "< __WIZ_HOME__/dns_wizard/scripts/127.0.0.rev.default") or
+ die "can't open default: $!";
+ while (<OLD>) {
+ s|__hname__|$wiz_host_name|;
+ print NEW $_;
+ }
+ close(OLD);
+ close(NEW);
+ MDK::Common::cp_af($tmp, $file);
+# MDK::Common::rm_rf($tmp);
+ up_serial($file);
+
+#ipnet.rev
+ $file = "/var/named/$s_trunc.rev";
+ MDK::Common::cp_af($file, $file.".orig");
+ my $tmp = `mktemp /tmp/Dnsconf.XXXXXX` or
+ die "can't make a temp file: $!";
+ open(NEW, "> $tmp") or
+ die "can't open $tmp: $!";
+ open(OLD, "< __WIZ_HOME__/dns_wizard/scripts/ipnet.rev.default") or
+ die "can't open default: $!";
+ while (<OLD>) {
+ s|__dname__|$wiz_domain_name|g;
+ s|__hname__|$wiz_host_name|g;
+ s|__revnet__|$reversnet|g;
+ s|__nb__|$ds|;
+ print NEW $_;
+ }
+ close(OLD);
+ close(NEW);
+ MDK::Common::cp_af($tmp, $file);
+# MDK::Common::rm_rf($tmp);
+ up_serial($file);
+
+ $file = "/var/named/$wiz_domain_name.db";
+ MDK::Common::cp_af($file, $file.".orig");
+ my $tmp = `mktemp /tmp/Dnsconf.XXXXXX` or
+ die "can't make a temp file: $!";
+ open(NEW, "> $tmp") or
+ die "can't open $tmp: $!";
+ open(OLD, "< __WIZ_HOME__/dns_wizard/scripts/domain.db.default") or
+ die "can't open default: $!";
+ while (<OLD>) {
+ s|__dname__|$wiz_domain_name|g;
+ s|__hname__|$wiz_host_name|g;
+ s|__ip__|$wiz_ip_server|g;
+ s|__host__|$ENV{host}|g;
+ print NEW $_;
+ }
+ close(OLD);
+ close(NEW);
+ MDK::Common::cp_af($tmp, $file);
+# MDK::Common::rm_rf($tmp);
+ up_serial($file);
+
+#resolv.conf
+ $file = "/etc/resolv.conf";
+ MDK::Common::cp_af($file, $file.".orig");
+ open(NEW, "> $file");
+ print NEW "domain $wiz_domain_name\n";
+ print NEW "nameserver $wiz_ip_server\n";
+
+ print "toto\n";
+ system("/sbin/chkconfig --level 235 named on") or die "error on running /sbin/chkconfig: $!";
+
+ system("/etc/rc.d/init.d/named restart") or die "error on restarting /etc/rc.d/init.d/named: $!";
+ print "tata\n";
+ %mdk = Vareqval->get("/etc/sysconfig/mdk_serv");
+ $mdk{wiz_caching_dns} = "1";
+ Vareqval->commit("/etc/sysconfig/mdk_serv", \%mdk);
+}
+
+1;