1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#!/usr/bin/perl
package Dnsconf;
require "__WIZ_HOME__/common/scripts/Vareqval.pm";
use MDK::Common;
use strict;
use standalone;
sub up_serial {
my ($file) = @_;
my $serial_nbm = `date +%Y%m%d00` or die "date not found: $!";
output($file, map {
my $line = $_;
if (/^(\s*)(\d*)(\s*;\s*Serial.*)$/) {
my $serial_f = $2;
$serial_f++;
if ($serial_f <= $serial_nbm) {
$serial_f = $serial_nbm;
chomp($serial_f);
$line = "$1$serial_f$3\n";
}
}
$line;
} cat_($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");
standalone::explanations("Now putting $file configuration");
my $ispns1 = $ENV{wiz_ext_dns1} || "// __ISPN1__";
my $ispns2 = $ENV{wiz_ext_dns2} || "// __ISPN2__";
output($file, map {
s|__ISPNS1__|$ispns1|g;
s|__ISPNS2__|$ispns2|g;
s|__dname__|$wiz_domain_name|g;
s|__revnet__|$reversnet|g;
s|__net__|$s_trunc|g;
$_;
} cat_("__WIZ_HOME__/dns_wizard/scripts/named.conf.default"));
# 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);
# 127.0.0.rev
$file="/var/named/127.0.0.rev";
MDK::Common::cp_af($file, $file . ".orig");
output($file, map {
s|__hname__|$wiz_host_name|g;
$_;
} cat_("__WIZ_HOME__/dns_wizard/scripts/127.0.0.rev.default"));
up_serial($file);
# $ipnet.rev
$file = "/var/named/$s_trunc.rev";
MDK::Common::cp_af($file, $file.".orig");
output($file, map {
s|__dname__|$wiz_domain_name|g;
s|__hname__|$wiz_host_name|g;
s|__revnet__|$reversnet|g;
s|__nb__|$ds|g;
$_;
} cat_("__WIZ_HOME__/dns_wizard/scripts/ipnet.rev.default"));
up_serial($file);
# $domain.db
$file = "/var/named/$wiz_domain_name.db";
MDK::Common::cp_af($file, $file.".orig");
output($file, map {
s|__dname__|$wiz_domain_name|g;
s|__hname__|$wiz_host_name|g;
s|__ip__|$wiz_ip_server|g;
s|__host__|$host|g;
s|__nb__|$ds|g;
$_;
} cat_("__WIZ_HOME__/dns_wizard/scripts/domain.db.default"));
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";
system("/sbin/chkconfig --level 235 named on");
system("/etc/rc.d/init.d/named restart");
%mdk = Vareqval->get("/etc/sysconfig/mdk_serv");
$mdk{wiz_caching_dns} = "1";
Vareqval->commit("/etc/sysconfig/mdk_serv", \%mdk);
10;
}
1;
|