summaryrefslogtreecommitdiffstats
path: root/dns_wizard
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2004-01-19 13:05:45 +0000
committerAntoine Ginies <aginies@mandriva.com>2004-01-19 13:05:45 +0000
commit0048e0f74f0e65ece6fa20abbec175c30da1b026 (patch)
tree6dd3951fe97a11f781061ac7501c7969f2699102 /dns_wizard
parentd116068386579cedf636a9947723234edee88689 (diff)
downloaddrakwizard-0048e0f74f0e65ece6fa20abbec175c30da1b026.tar
drakwizard-0048e0f74f0e65ece6fa20abbec175c30da1b026.tar.gz
drakwizard-0048e0f74f0e65ece6fa20abbec175c30da1b026.tar.bz2
drakwizard-0048e0f74f0e65ece6fa20abbec175c30da1b026.tar.xz
drakwizard-0048e0f74f0e65ece6fa20abbec175c30da1b026.zip
- new Bind wizard, full re-write based on Cluster tools
Diffstat (limited to 'dns_wizard')
-rw-r--r--dns_wizard/Bind.pm916
1 files changed, 722 insertions, 194 deletions
diff --git a/dns_wizard/Bind.pm b/dns_wizard/Bind.pm
index e7c3b534..dea69c92 100644
--- a/dns_wizard/Bind.pm
+++ b/dns_wizard/Bind.pm
@@ -1,10 +1,8 @@
-#!/usr/bin/perl
-
-# Drakwizard
-
-# Copyright (C) 2003 Mandrakesoft
+#!/usr/bin/perl -w
#
-# Author: Florent Villard <warly@mandrakesoft.com>
+# version 0.4
+# Copyright (C) 2004 Mandrakesoft
+# Author: Antoine Ginies <aginies _ateuh _ 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
@@ -22,214 +20,744 @@
package MDK::Wizard::Bind;
use lib qw(/usr/lib/libDrakX);
+use ugtk2;
use strict;
use common;
-use services;
+use MDK::Wizard::Varspaceval;
use MDK::Wizard::Wizcommon;
+
+#unless ($> == 0) {
+# die "You are not root Exiting\n";
+#}
+
my $wiz = new MDK::Wizard::Wizcommon;
-my $dns1;
-my $dns2;
+
+
+my $SERIAL = `date +%d%m20%y`;
+my $HOSTNAME = $wiz->{net}->network_get("HOSTNAME");
+#my $IPSERVER = $wiz->{net}->itf_get("IPADDR");
+my $interface = 'eth0';
+my ($IPSERVER) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
+#my $DOMAINNAME = $wiz->{net}->network_get("DOMAINNAME");
+my $DOMAINNAME = chomp_(`domainname`);
+
+my $WDIR = "/tmp/dnstest";
+my $NAMED_DIR = "/var/named";
+my $DNSKEY = "";
+my $SHORTHOSTNAME = chomp_(`hostname -s`);
+my $TEXTINFO = "dns Wizard";
+my $REP_SAVE = "/tmp/bck";
+my $ZONE_DIR = $NAMED_DIR . "/zone";
+my $DATE = `date +%d-%m-20%y`;
+
my $o = {
- name => N("DNS Configuration Wizard"),
- var => {
- ext_dns1 => '',
- ext_dns2 => ''
- },
- needed_rpm => [ 'bind' ],
- defaultimage => "$ENV{__WIZ_HOME__}dns_wizard/images/DNS.png"
- };
-
-$o->{pages} = {
- welcome => {
- name => N("DNS configuration wizard") . "\n\n" . N("DNS (Domain Name Server) is the service that maps an IP address of a machine with an internet host name.") . "\n\n" . N("This wizard will help you configuring the DNS services of your server. This configuration will provide a local DNS service for local computers names, with non-local requests forwarded to an outside DNS."),
- no_back => 1,
- next => 'dns_ip'
- },
- dns_ip => {
- name => N("DNS Server Addresses") . "\n\n" . N("DNS will allow your network to communicate with the Internet using standard internet host names. In order to configure DNS, you must provide the IP address of primary and secondary DNS server; usually this address are given by your Internet provider.") . N("IP addresses are a dotted list of four numbers smaller than 256"),
- pre => sub {
- $o->{var}{ext_dns1} ||= $dns1;
- $o->{var}{ext_dns2} ||= $dns2
- },
- data => [
- { label => N("Primary DNS Address"), val => \$o->{var}{ext_dns1} },
- { label => N("Secondary DNS Address:"), val => \$o->{var}{ext_dns2} },
- ],
- next => 'summary'
- },
- ip_error => {
- name => 'Error.' . "\n\n" . N("This is not a valid address... press next to continue"),
- ignore => 1,
- next => 'dns_ip'
- },
- ip_warning => {
- name => 'Warning.' . "\n\n" . N("You have entered an empty address for the DNS server.") . "\n\n" .
- N("Your setting could be accepted, but you will not be able to identify machine names outside your local network.") . "\n\n" .
- N("Press next to leave these values empty, or back to enter a value."),
- next => 'summary'
- },
- summary => {
- name => N("Configuring the DNS Server") . "\n\n" . N("The wizard collected the following parameters needed to configure your DNS service:") . "\n\n" . N("To accept these values, and configure your server, click the Next button or use the Back button to correct them"),
- data => [
- { label => N("Primary DNS Address:"), fixed_val => \$o->{var}{ext_dns1} },
- { label => N("Secondary DNS Address:"), fixed_val => \$o->{var}{ext_dns2} },
- ],
- post => \&do_it,
- next => 'end'
- },
- end => {
- name => N("Congratulations"),
- data => [ { label => N("The wizard successfully configured the DNS services of your server.") } ],
- end => 1,
- next => 0
- },
+ name => 'DNS Configuration Wizard',
+ var => {
+ IPOFFORWARDER => '',
+ ADDSEARCH => '',
+ DOMAINNAME => $DOMAINNAME,
+ SHORTHOSTNAME => $SHORTHOSTNAME,
+ IPMASTER => '',
+ CLIENTNAME => '',
+ CLIENTIP => '',
+ },
+ needed_rpm => [ 'bind' ],
+ defaultimage => "/usr/share/wizards/dns_wizard/images/DNS.png"
+ };
+
+my %level = (
+ 1 => N("Master - Master DNS server"),
+ 2 => N("Slave - Slave DNS server"),
+ 3 => N("Add host - Add a host in existing configuration"),
+ 4 => N("remove host - Remove a Host in DNS"),
+ );
+
+
+my @list_hosts;
+sub list_hosts {
+ my $iprev = get_spe_ip('iprev', $IPSERVER);
+ my $db = "$ZONE_DIR/db.$iprev.hosts";
+ my $ipnor = get_spe_ip('iprev', $IPSERVER);
+ foreach (cat_($db)) {
+ my ($h) = /\d{1,3}\tIN\tPTR\t(.*)/;
+ !$h or push @list_hosts,$h;
+ }
+ @list_hosts;
+}
+
+$o->{pages} = {
+ welcome => {
+ name => N('DNS Master configuration wizard') . "\n\n" . N('DNS (Domain Name Server) is the service that maps an IP address of a machine with an internet host name.') . "\n\n" . N('This wizard will help you configuring the DNS services of your server. This configuration will provide a local DNS service for local computers names, with non-local requests forwarded to an outside DNS.'),
+ no_back => 1,
+ post => \&check_domain,
+ post => \&check_hostname,
+ post => \&check_dhcp,
+ pre => sub {
+ $o->{var}{wiz_level} ||= 1;
+ },
+ post => sub {
+ if ($o->{var}{wiz_level} == 2) {
+ return 'slave' }
+ elsif ($o->{var}{wiz_level} == 3) {
+ return 'addhost' }
+ elsif ($o->{var}{wiz_level} == 4) {
+ return 'removehost' }
+ },
+ data => [
+ { label => N("What Kind of DNS :"), val => \$o->{var}{wiz_level}, list => [ keys %level ], format => sub { $level{$_[0]} } },
+ ],
+ next => 'ipforward',
+ },
+ addhost => {
+ name => N("Client identification:") . "\n\n" . N("Your client on the network will be identified by name, as in clientname.company.net. Every machine on the network must have a (unique) IP address, in the usual dotted syntax.") . "\n\n" . N("(you don't need to type the domain after the name)") . "\n\n" . N("Note that the given IP number and client name should be unique in the network."),
+ data => [
+ { label => N("Name of the machine:"), val => \$o->{var}{CLIENTNAME} },
+ { label => N("IP number of the machine:"), val => \$o->{var}{CLIENTIP} },
+ ],
+ post => \&check_iph,
+ next => 'summaryadd',
+ },
+ removehost => {
+ name => N('Remove Host') . "\n\n" . N('Remove a host in existing dns configuration.') . "\n\n" . N('Choose the host you want to remove in the following list.'),
+ data => [
+ { label => N("Name of the machine:"), val => \$o->{var}{N}, fixed_list => \@list_hosts },
+ ],
+ post => \&list_hosts,
+ next => 'summaryremove',
+ },
+ slave => {
+ name => N('Slave DNS server') . "\n\n" . N("A slave name server will take some of the burden away from your primary name server, and will also function as a backup server, in case your master server is unreachable."),
+ data => [
+ { label => N('IP of master DNS server'), val => \$o->{var}{IPMASTER} },
+ ],
+ post => \&check_ipm,
+ next => 'summaryslave',
+ },
+ error_hostname => {
+ name => N('You need to readjust your hostname'),
+ end => 1,
+ next => 0,
+ },
+ error_domain => {
+ name => N('You need to readjust your domainame'),
+ end => 1,
+ next => 0,
+ },
+ ipforward => {
+ name => N('IP of your forwarders') . "\n\n" . N('Forwarding occurs on only those queries for which the server is not authoritative and does not have the answer in its cache.') . "\n\n" . N('So if you need it and know your ip forwarder enter IP address of it, if you dont know leave it blank'),
+ data => [
+ { label => N('IP forwarders'), val => \$o->{var}{IPOFFORWARDER} },
+ ],
+ post => \&check_ipf,
+ next => 'addsearch',
+ },
+ addsearch => {
+ name => N('Add search domain') . "\n\n" . N('Search list for host-name lookup. The search list is normally determined from the local domain name; by default, it contains only the local domain name. This may be changed by listing the desired domain search path following the search keyword') . "\n\n" . N('Domainname of this server is automatically added, and you dont need to add it here.'),
+ data => [
+ { label => N('add search domain'), val => \$o->{var}{ADDSEARCH} },
+ ],
+ next => 'summary',
+ },
+ error_ipf => {
+ name => N('Error IP of forwarder') . "\n\n" . N('This is not a valid IP address for your forwarder... press next to continue'),
+ ignore => 1,
+ next => 'ipforward',
+ },
+ error_ipm => {
+ name => N('Error Ip of DNS master') . "\n\n" . N('This is not a valid Master DNS IP address... press next to continue'),
+ ignore => 1,
+ next => 'slave',
+ },
+ error_iph => {
+ name => N('Error Ip of new host') . "\n\n" . N('This is not a valid IP address... press next to continue'),
+ ignore => 1,
+ next => 'addhost',
+ },
+ dhcp_warning => {
+ name => N("Warning") . "\n\n" . N("You are in dhcp, server may not work with your configuration."),
+ ignore => 1,
+ next => 'client_id'
+ },
+ error_add => {
+ name => N('Error add host') . "\n\n" . N('It seems that host is already in your DNS configuration... press next to continue'),
+ ignore => 1,
+ next => 'addhost',
+ },
+ error_remove => {
+ name => N('Error remove host') . "\n\n" . N('It seems that this is not present in your DNS configuration... press next to continue'),
+ ignore => 1,
+ next => 'removehost',
+ },
+ summaryslave => {
+ name => N('Ok Now building your DNS slave configuration') . "\n\n" . N('with this configuration:'),
+ data => [
+ { label => N('Ip of master DNS server'), fixed_val => \$o->{var}{IPMASTER} },
+ ],
+ post => \&do_it_slave,
+ next => 'end',
+ },
+ summaryadd => {
+ name => N('Client with this identification will be added to your DNS'),
+ data => [
+ { label => N("Name of the machine:"), fixed_val => \$o->{var}{CLIENTNAME} },
+ { label => N("IP number of the machine:"), fixed_val => \$o->{var}{CLIENTIP} },
+ ],
+ post => \&do_it_add,
+ next => 'endadd',
+ },
+ summaryremove => {
+ name => N('Client with this identification will be removed to your DNS'),
+ data => [
+ { label => N("Name of the machine:"), val => \$o->{var}{N}, fixed_list => \@list_hosts },
+ ],
+ post => \&do_it_remove,
+ next => 'endremove',
+ },
+ summary => {
+ name => N('Ok Now building your DNS configuration') . "\n\n" . N('with this configuration:'),
+ data => [
+ { label => N('Server Hostname'), fixed_val => \$o->{var}{SHORTHOSTNAME} },
+ { label => N('Domainname'), fixed_val => \$o->{var}{DOMAINNAME} },
+ { label => N('IP forwarders'), fixed_val => \$o->{var}{IPOFFORWARDER} },
+ { label => N('add search domain'), fixed_val => \$o->{var}{ADDSEARCH} },
+ ],
+ post => \&do_it_master,
+ next => 'end',
+ },
+ endadd => {
+ name => N('Congratulations'),
+ data => [ { label => N('The wizard successfully add host in your DNS.') } ],
+ next => 'addhost',
+ },
+ endremove => {
+ name => N('Congratulations'),
+ data => [ { label => N('The wizard successfully remove host in your DNS.') } ],
+ next => 'removehost',
+ },
+ end => {
+ name => N('Congratulations'),
+ data => [ { label => N('The wizard successfully configured the DNS service of your server.') } ],
+ no_back => 1,
+ end => 1,
+ next => 0,
+ },
+ };
+
+
+sub check_dhcp {
+ $wiz->{net}->is_dhcp() and return 'dhcp_warning';
+}
+
+sub interface_to_ip {
+ my ($interface) = @_;
+ my ($ip) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
+ $ip;
+}
+
+sub crea_wdir {
+ if (-e $WDIR) { system("rm -rf $WDIR") }
+ mkdir_p($WDIR);
+}
+
+sub resolv_ip {
+ my ($ip) = @_;
+ gethostbyaddr(Socket::inet_aton($ip), Socket::AF_INET());
+}
+
+sub resolv_name {
+ my ($name) = @_;
+ join(".", unpack "C4", (gethostbyname $name)[4]);
+}
+
+
+sub get_spe_ip {
+ # waiting iprev, ipnorm or ipend
+ my ($att, $ip) = @_;
+ my @o = split(/\./, $ip);
+ if ($att =~ /iprev/) {
+ my $iprev = $o[2] . "." . $o[1] . "." . $o[0];
+ return $iprev;
+ } elsif ($att =~ /ipnor/) {
+ my $ipnor = $o[0] . "." . $o[1] . "." . $o[2];
+ return $ipnor;
+ } elsif ($att =~ /ipend/) {
+ my $ipend = $o[3];
+ return $ipend;
+ }
+}
+
+
+# check that hostnmae is != from localhost
+sub check_hostname {
+ if ($o->{var}{SHORTHOSTNAME} =~ /localhost/) {
+ return 'error_hostname' }
+}
+
+# check domainame != localdomain
+sub check_domain {
+ if (member($o->{var}{DOMAINNAME}, qw(localdomain (none)))) {
+ return 'error_domain' }
+}
+
+sub crea_db_local {
+ output($WDIR . "/db.localhost", <<EOF);
+\$TTL 3D
+\@ IN SOA $HOSTNAME. root.$HOSTNAME. (
+ $SERIAL ; Serial
+ 8H ; Refresh
+ 2H ; Retry
+ 4W ; Expire
+ 1D) ; Minimum TTL
+ NS $HOSTNAME.
+1 IN PTR localhost.
+EOF
+}
+# end of db.local
+
+
+# create named.conf file
+sub crea_named_common {
+ output($WDIR . "/named.conf", <<EOF);
+key mykey {
+ algorithm hmac-md5;
+ secret "$DNSKEY";
+};
+
+controls {
+ inet 127.0.0.1 port 953
+ allow { 127.0.0.1; } keys { mykey; };
+};
+
+options {
+ directory "$NAMED_DIR";
+ pid-file "$NAMED_DIR/named.pid";
+ version "Wizard drake";
+ allow-query { any; };
+ allow-transfer { any; };
+EOF
+
+ !$o->{var}{IPOFFORWARDER} or append_to_file($WDIR . "/named.conf", "\tforwarders { $o->{var}{IPOFFORWARDER}; };\n");
+ append_to_file($WDIR . "/named.conf", <<EOF);
+};
+
+zone "localhost" {
+ type master;
+ file "zone/db.localhost";
+};
+
+zone "0.0.127.in-addr.arpa" {
+ type master;
+ file "zone/db.127.0.0.1";
};
-sub up_serial {
- my ($file) = @_;
-
- my (undef, undef, undef, $mday, $mon, $year) = gmtime(time);
- $year += 1900;
- my $serial_nbm = sprintf "%4dY%2dm%2d00", $year, $mon, $mday;
- 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));
+zone "." {
+ type hint;
+ file "zone/root.hints";
+};
+
+EOF
+}
+# end named.conf
+
+sub crea_named_master {
+ my ($ip, $d) = @_;
+ my $iprev = get_spe_ip('iprev', $ip);
+ append_to_file($WDIR . "/named.conf", <<EOF);
+zone "$iprev.in-addr.arpa" {
+ type master;
+ file "zone/db.$iprev.hosts";
+ forwarders { };
+};
+
+zone "$d" {
+ type master;
+ file "zone/db.$d.hosts";
+ forwarders { };
+};
+EOF
+}
+
+sub crea_named_slave {
+ my ($ip, $d, $IPM) = @_;
+ my $iprev = get_spe_ip('iprev', $ip);
+ append_to_file($WDIR . "/named.conf", <<EOF);
+zone "$iprev.in-addr.arpa" {
+ type slave;
+ masters { $IPM; };
+ file "bak.db.$iprev.hosts";
+};
+
+zone "$d" {
+ type slave;
+ masters { $IPM; };
+ file "bak.db.$d.hosts";
+};
+EOF
+}
+
+# create hints
+sub crea_hints {
+ output($WDIR . "/root.hints", <<EOF);
+; <<>> DiG 8.1 <<>> \@A.ROOT-SERVERS.NET.
+; (1 server found)
+;; res options: init recurs defnam dnsrch
+;; got answer:
+;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10
+;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13
+;; QUERY SECTION:
+;; ., type = NS, class = IN
+
+;; ANSWER SECTION:
+. 6D IN NS G.ROOT-SERVERS.NET.
+. 6D IN NS J.ROOT-SERVERS.NET.
+. 6D IN NS K.ROOT-SERVERS.NET.
+. 6D IN NS L.ROOT-SERVERS.NET.
+. 6D IN NS M.ROOT-SERVERS.NET.
+. 6D IN NS A.ROOT-SERVERS.NET.
+. 6D IN NS H.ROOT-SERVERS.NET.
+. 6D IN NS B.ROOT-SERVERS.NET.
+. 6D IN NS C.ROOT-SERVERS.NET.
+. 6D IN NS D.ROOT-SERVERS.NET.
+. 6D IN NS E.ROOT-SERVERS.NET.
+. 6D IN NS I.ROOT-SERVERS.NET.
+. 6D IN NS F.ROOT-SERVERS.NET.
+
+;; ADDITIONAL SECTION:
+G.ROOT-SERVERS.NET. 5w6d16h IN A 192.112.36.4
+J.ROOT-SERVERS.NET. 5w6d16h IN A 198.41.0.10
+K.ROOT-SERVERS.NET. 5w6d16h IN A 193.0.14.129
+L.ROOT-SERVERS.NET. 5w6d16h IN A 198.32.64.12
+M.ROOT-SERVERS.NET. 5w6d16h IN A 202.12.27.33
+A.ROOT-SERVERS.NET. 5w6d16h IN A 198.41.0.4
+H.ROOT-SERVERS.NET. 5w6d16h IN A 128.63.2.53
+B.ROOT-SERVERS.NET. 5w6d16h IN A 128.9.0.107
+C.ROOT-SERVERS.NET. 5w6d16h IN A 192.33.4.12
+D.ROOT-SERVERS.NET. 5w6d16h IN A 128.8.10.90
+E.ROOT-SERVERS.NET. 5w6d16h IN A 192.203.230.10
+I.ROOT-SERVERS.NET. 5w6d16h IN A 192.36.148.17
+F.ROOT-SERVERS.NET. 5w6d16h IN A 192.5.5.241
+;; Total query time: 215 msec
+;; FROM: roke.uio.no to SERVER: A.ROOT-SERVERS.NET. 198.41.0.4
+;; WHEN: Sun Feb 15 01:22:51 1998
+;; MSG SIZE sent: 17 rcvd: 436
+EOF
+}
+# end roots.hints
+
+# create ipreverse
+sub crea_iprev {
+ my ($ip, $d) = @_;
+ my $iprev = get_spe_ip('iprev', $ip);
+ my $ipend = get_spe_ip('ipend', $ip);
+ output($WDIR . "/db." . $iprev . ".hosts", <<EOF);
+\$TTL 3D
+@ IN SOA $SHORTHOSTNAME.$d. $SHORTHOSTNAME.$d. (
+ $SERIAL ; serial
+ 10800 ; Refresh
+ 3600 ; Retry
+ 604800 ; Expire
+ 86400) ; Minimum TTL
+ NS $SHORTHOSTNAME.$d.
+$ipend IN PTR $SHORTHOSTNAME.$d.
+EOF
+
+}
+# end create iprev
+
+# create ipnormal
+sub crea_ipnorm {
+ my ($ip, $d) = @_;
+ output($WDIR . "/db.$d.hosts", <<EOF);
+\$TTL 3D
+@ IN SOA $SHORTHOSTNAME.$d. root.$SHORTHOSTNAME.$d. (
+ $SERIAL ; Serial
+ 8H ; Refresh
+ 2H ; Retry
+ 4W ; Expire
+ 1D) ; Minimum TTL
+ TXT $TEXTINFO
+ IN NS $SHORTHOSTNAME.$d.
+localhost A 127.0.0.1
+dnsmaster IN CNAME $SHORTHOSTNAME.$d.
+$SHORTHOSTNAME.$d. IN A $ip
+EOF
+}
+# end of ipnorm
+
+
+# create 127.0.
+sub crea_127 {
+ my $d = $DOMAINNAME;
+ output($WDIR . "/db.127.0.0.1", <<EOF);
+\$TTL 3D
+\@ IN SOA $d. root.$d. (
+ $SERIAL ; Serial
+ 28800 ; Refresh
+ 7200 ; Retry
+ 604800 ; Expire
+ 86400) ; Minimum TTL
+ NS $HOSTNAME.
+localhost IN A 127.0.0.1
+EOF
+}
+# end create 127
+
+# create rndc.conf
+sub crea_rndc {
+ output($WDIR . "/rndc.conf", <<EOF);
+/*
+* Copyright (C) 2000, 2001 Internet Software Consortium.
+*
+* Permission to use, copy, modify, and distribute this software for any
+* purpose with or without fee is hereby granted, provided that the above
+* copyright notice and this permission notice appear in all copies.
+*
+* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+/* Id: dns_cluster.pm,v 1.18 2003/04/10 16:01:47 aginies Exp */
+/*
+* Sample rndc configuration file.
+*/
+
+options {
+ default-server localhost;
+ default-key "mykey";
+};
+
+server localhost {
+ key "mykey";
+};
+
+key "mykey" {
+ algorithm hmac-md5;
+ secret "$DNSKEY";
+};
+EOF
+}
+# end of create rndc
+
+# save old config files
+
+sub save_old_config {
+ if (-d $ZONE_DIR) {
+ print " - Backup of current configuration in " . $REP_SAVE . "\n";
+ }
+ if (-d "$REP_SAVE/dns") { rm_rf("$REP_SAVE/dns") }
+ mkdir_p($REP_SAVE . '/dns');
+ cp_af($_, "$REP_SAVE/dns/$_" . '-' . $DATE . '.sauv') foreach glob_($ZONE_DIR . "/*");
+ if (-e "/etc/named.conf") {
+ cp_af("/etc/named.conf", "$REP_SAVE/dns/named.conf-$DATE");
+ }
+}
+# end save old config
+
+sub generate_rndc {
+ mkdir_p($WDIR);
+ system("rndc-confgen -a -c $WDIR/rndc.key");
+ my ($key) = cat_("$WDIR/rndc.key") =~ /secret \"(\S*)\";/;
+ $key;
+}
+
+
+# reinit resolv.conf
+sub set_resolv {
+ output($WDIR . "/resolv.conf", <<EOF);
+domain $DOMAINNAME
+search $DOMAINNAME
+nameserver $IPSERVER
+EOF
+
+ !$o->{var}{IPMASTER} or return append_to_file($WDIR . "/resolv.conf", "nameserver $o->{var}{IPMASTER}\n");
+ !$o->{var}{ADDSEARCH} or return append_to_file($WDIR . "/resolv.conf", "search $o->{var}{ADDSEARCH}\n");
+ !$o->{var}{IPOFFORWARDER} or return append_to_file($WDIR . "/resolv.conf", "nameserver $o->{var}{IPOFFORWARDER}\n");
+}
+# end set resolv.conf
+
+# set /etc/hosts
+sub set_hosts {
+ my ($ip, $h) = @_;
+ if (!any { /$ip\s* $h/ } cat_($WDIR . "/hosts")) {
+ append_to_file($WDIR . "/hosts", <<EOF);
+$ip $h
+EOF
+ }
+}
+# end set hosts
+
+# check config of dns
+sub check_config {
+ system('named-checkconf', $WDIR . '/named.conf');
+}
+# end check config
+
+# copy file correct place
+sub copy_good {
+ mkdir_p($ZONE_DIR);
+ cp_af($WDIR . '/named.conf', '/etc/named.conf');
+ cp_af($WDIR . '/rndc.conf', '/etc/rndc.conf');
+ cp_af($WDIR . '/hosts', '/etc/hosts');
+ cp_af($WDIR . '/resolv.conf', '/etc/resolv.conf');
+ cp_af($WDIR . '/root.hints', $ZONE_DIR . '/');
+ cp_af(glob($WDIR . '/db*'), $ZONE_DIR . '/');
+}
+# end copy goodplace
+
+my $ip_regexp = qr/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
+sub check_ipm {
+ my $ip = $o->{var}{IPMASTER};
+ $ip or return 'slave';
+ my @fields = $ip =~ $ip_regexp or return 'error_ipm';
+ every { 0 <= $_ && $_ <= 255 } @fields or return 'error_ipm';
+}
+
+sub check_ipf {
+ my $ip = $o->{var}{IPOFFORWARDER};
+ $ip or return 'addsearch';
+ my @fields = $ip =~ $ip_regexp or return 'error_ipf';
+ every { 0 <= $_ && $_ <= 255 } @fields or return 'error_ipf';
+}
+
+
+sub check_iph {
+ my $ip = $o->{var}{CLIENTIP};
+ my @fields = $ip =~ $ip_regexp or return 'error_iph';
+ every { 0 <= $_ && $_ <= 255 } @fields or return 'error_iph';
}
sub do_it {
$::testing and return;
- my $wiz_ip_server = $wiz->{net}->itf_get("IPADDR");
- my $wiz_domain_name = $wiz->{net}->network_get("DOMAINNAME");
- my $wiz_host_name = $wiz->{net}->network_get("HOSTNAME");
- my $s_trunc = "$1.$2.$3" if $wiz_ip_server =~ /(\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_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
- my $file = "/etc/host.conf";
-
- -f $file and MDK::Common::cp_af($file, $file.".orig");
- MDK::Common::cp_af("__WIZ_HOME__/dns_wizard/scripts/host.conf.default", $file);
-
- $file = "/etc/named.conf";
- -f $file and MDK::Common::cp_af($file, $file.".orig");
-
- my $ispns1 = $o->{var}{ext_dns1} || "// __ISPN1__";
- my $ispns2 = $o->{var}{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"));
-
- standalone::explanations("$file : DNS1: $ispns1 DNS2: $ispns2");
-# 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";
- -f $file and MDK::Common::cp_af($file, $file . ".orig");
- MDK::Common::cp_af("__WIZ_HOME__/dns_wizard/scripts/root.hints.default", $file);
- standalone::explanations("$file clobbered");
-# 127.0.0.rev
- $file="/var/named/127.0.0.rev";
- -f $file and 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"));
- standalone::explanations("$file : hostname: $wiz_host_name");
- up_serial($file);
-
-# $ipnet.rev
- $file = "/var/named/$s_trunc.rev";
- -f $file and 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);
- standalone::explanations("$file : domain: $wiz_domain_name hostname: $wiz_host_name revnet: $reversnet
-nb: $ds");
-# $domain.db
- $file = "/var/named/$wiz_domain_name.db";
- -f $file and 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);
- standalone::explanations("$file : domain: $wiz_domain_name hostname: $wiz_host_name revnet: $reversnet
-nb: $ds");
-# resolv.conf
- $file = "/etc/resolv.conf";
- -f $file and MDK::Common::cp_af($file, $file.".orig");
- open(NEW, "> $file");
- print NEW "domain $wiz_domain_name\n";
- print NEW "nameserver $wiz_ip_server\n";
- standalone::explanations("$file : domain: $wiz_domain_name nameserver: $wiz_ip_server");
- services::start_service_on_boot('named');
- if (services::is_service_running('named')) {
- services::restart('named')
- } else {
- services::start('named')
+ my ($st) = @_;
+ crea_wdir($WDIR);
+ # create files
+ crea_db_local();
+ crea_127();
+ crea_named_common();
+ # set host configuration
+ if (-f $WDIR . '/hosts') { rm_rf($WDIR . '/hosts') }
+ set_hosts('127.0.0.1', 'localhost.localdomain localhost');
+ set_hosts($IPSERVER, $HOSTNAME);
+}
+
+sub end_it {
+ crea_hints();
+ crea_rndc();
+ # set configuration files on server
+ set_resolv();
+ # check generated config file are good
+ check_config();
+ # create backup
+ save_old_config();
+ # copy in correct place
+ copy_good();
+ # start or restart the service
+ system('service named restart');
+}
+
+
+sub do_it_master {
+ return if $::testing;
+ my $in = 'interactive'->vnew('su', 'dns');
+ my $w = $in->wait_message(N("Master DNS server"), N("Configuring your system as Master DNS server ..."));
+ do_it();
+ crea_iprev($IPSERVER, $DOMAINNAME);
+ crea_ipnorm($IPSERVER, $DOMAINNAME);
+ crea_named_master($IPSERVER, $DOMAINNAME);
+ end_it();
+undef $w;
+}
+
+sub do_it_slave {
+ return if $::testing;
+ my $in = 'interactive'->vnew('su', 'dns');
+ my $w = $in->wait_message(N("Slave DNS server"), N("Configuring your system as Slave DNS server ..."));
+ do_it();
+ rm_rf(glob("$NAMED_DIR/bak*"));
+ crea_named_slave($IPSERVER, $DOMAINNAME ,$o->{var}{IPMASTER});
+ end_it();
+undef $w;
+}
+
+sub get_shortname {
+# sure someone can find a better method to do that
+ my ($name) = @_;
+ my @DT = split(/\./, $DOMAINNAME);
+ my $NB = $#DT;
+ if (any { /$DOMAINNAME$/x } $name) {
+ my @shortname = split(/\./, $name);
+ splice(@shortname, -$NB);
+ my $shortn;
+ foreach (@shortname) {
+ $shortn or return $shortn = $_;
+ !$shortn or return $shortn . "." . $_;
}
+ } else { return $name }
+}
+
+sub do_it_add {
+ return if $::testing;
+ my $iprev = get_spe_ip('iprev', $IPSERVER);
+ my $ipend = get_spe_ip('ipend', $o->{var}{CLIENTIP});
+ my $SNAME= get_shortname($o->{var}{CLIENTNAME});
+ if (any { /$o->{var}{CLIENTIP}/ } cat_("$ZONE_DIR/db.$DOMAINNAME.hosts")) {
+ return 'error_add';
+ } elsif (any { /$SNAME.$DOMAINNAME.$/ } cat_("$ZONE_DIR/db.$iprev.hosts")) {
+ return 'error_add';
+ } else {
+ print "good add\n";
+ append_to_file("$ZONE_DIR/db.$DOMAINNAME.hosts",
+ "$SNAME.$DOMAINNAME\.\tIN\tA\t$o->{var}{CLIENTIP}\n");
+ append_to_file("$ZONE_DIR/db.$iprev.hosts",
+ "$ipend\tIN\tPTR\t$SNAME.$DOMAINNAME\.\n");
+ }
+ system("service named reload");
+}
+
+sub do_it_remove {
+ return if $::testing;
+ my $iprev = get_spe_ip('iprev', $IPSERVER);
+ my $ipend = get_spe_ip('ipend', $o->{var}{CLIENTIP});
+ if (!any { /$o->{var}{CLIENTIP}$/ } cat_("$ZONE_DIR/db.$DOMAINNAME.hosts")) {
+ return 'error_remove';
+ } else {
+ substInFile {
+ s/.*$o->{var}{CLIENTIP}$//;
+ } "$ZONE_DIR/db.$DOMAINNAME.hosts";
+ substInFile {
+ s/^$ipend\S*.*//;
+ } "$ZONE_DIR/db.$iprev.hosts";
+ }
+ system("service named reload");
}
+
+#34 IN PTR xp2400.guibland.com.
+sub do_it_list {
+ return if $::testing;
+ my $iprev = get_spe_ip('iprev', $IPSERVER);
+ my $db = "$ZONE_DIR/db.$iprev.hosts";
+ my $ipnor = get_spe_ip('ipnor', $IPSERVER);
+ my @hosts; my @ip;
+ foreach (cat_($db)) {
+ my ($ipend, $h) = /(\d{1,3})\tIN\tPTR\t(.*)/;
+ if (!$h) { push @hosts, $h; push @ip, $ipend }
+ }
+}
+
+
sub new {
my ($class, $conf) = @_;
- my $file = "/etc/named.conf";
- if (-f $file) {
- open my $NEW, $file;
- DNS : while (<$NEW>) {
- $dns2 = "";
- if (m/^\s*options\s*\{/s...m/^\s*\}\;/s ) {
- if (m/^\s*forwarders\s*\{/s...m/^\s*\}\;/s ) {
- if (/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/) {
- $dns2 = "$1.$2.$3.$4";
- $dns1 and next DNS;
- $dns1 = $dns2;
- }
- }
- }
- }
- close $NEW;
- }
- if (!$dns1) {
- $dns1 = $wiz->{net}->network_get("dnsServer");
- if ($dns1 eq '127.0.0.1') {
- $dns1 = $wiz->{net}->network_get("dnsServer2");
- $dns2 = $wiz->{net}->network_get("dnsServer3") || '127.0.0.1'
- } else {
- $dns2 = $wiz->{net}->network_get("dnsServer2")
- }
- }
-
bless {
- o => $o,
+ o => $o,
}, $class;
}