diff options
-rw-r--r-- | dns_wizard/Bind.pm | 231 | ||||
-rwxr-xr-x | nfs_wizard/NFS.pm | 157 | ||||
-rw-r--r-- | time_wizard/Ntp.pm | 220 |
3 files changed, 608 insertions, 0 deletions
diff --git a/dns_wizard/Bind.pm b/dns_wizard/Bind.pm new file mode 100644 index 00000000..26d745fb --- /dev/null +++ b/dns_wizard/Bind.pm @@ -0,0 +1,231 @@ +#!/usr/bin/perl + +# Drakwizard + +# Copyright (C) 2003 Mandrakesoft +# +# Author: Florent Villard <warly@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 MDK::Wizard::Bind; +use lib qw(/usr/lib/libDrakX); +use strict; + +use common; +use MDK::Wizard::Wizcommon; + +my $wiz = new MDK::Wizard::Wizcommon; +my $dns1; +my $dns2; + +my $o = { + name => '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 + }, +}; + +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)); +} + +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"); + system("/sbin/chkconfig --level 235 named on"); + system("/etc/rc.d/init.d/named restart"); +} + +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, + }, $class; +} + +1; diff --git a/nfs_wizard/NFS.pm b/nfs_wizard/NFS.pm new file mode 100755 index 00000000..dd898072 --- /dev/null +++ b/nfs_wizard/NFS.pm @@ -0,0 +1,157 @@ +#!/usr/bin/perl + +# Drakwizard + +# Copyright (C) 2002,2003 Mandrakesoft +# +# Authors: Arnaud Desmons <adesmons@mandrakesoft.com> +# Florent Villard <warly@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 MDK::Wizard::NFS; +use strict; + +use common; +use services; +use MDK::Wizard::Wizcommon; + +my $wiz = new MDK::Wizard::Wizcommon; + +my $o = { + name => N('NFS Wizard'), + var => { + wiz_nfs_dir => '', + wiz_nfs_level => '', + wiz_netmask => '' + }, + needed_rpm => [ 'nfs-utils' ], + defaultimage => "$ENV{__WIZ_HOME__}nfs_wizard/images/NFS.png" + }; + +my %level = ( + 1 => N('All - No access restriction'), + 2 => N('Local Network - access for local network (recommended)') +); + +$o->{pages} = { + welcome => { + name => N('NFS Server Configuration Wizard') . "\n\n" . N('This wizard will help you configuring the NFS Server for your network.'), + no_back => 1, + next => 'nfs' + }, + nfs => { + name => N('NFS Server'), + post => \&check, + data => [ + { label => N('Directory:'), val => \$o->{var}{wiz_nfs_dir} }, + ], + next => 'ask_level' + }, + ask_level => { + name => N('Access Control') . "\n\n" . N('NFS can be restricted to a certain ip class') . "\n\n" . N('Choose the level that suits your needs. If you don\'t know, the Local Network level is usually the most appropriate. Beware that the All level may be not secure.'), + pre => sub { + $o->{var}{wiz_netmask} = network_mask() if !$o->{var}{wiz_netmask} || $o->{var}{wiz_netmask} eq '0.0.0.0/0.0.0.0' + }, + data => [ + { val => \$o->{var}{wiz_nfs_level}, list => [ keys %level ], format => sub { $level{$_[0]} } }, + ], + post => \&chooser, + next => 'summary' + }, + shownet => { + name => N('Grant access on local network') . "\n\n" . N('Access will be allowed for hosts on the network. Here is the information found about your current local network, you can modify it if needed.'), + data => [ + { label => N('Authorized network:'), val => \$o->{var}{wiz_netmask} }, + ], + next => 'summary' + + }, + error_dir => { + name => N('Error.') . "\n\n" . N('The path you entered does not exist.'), + ignore => 1, + next => 'nfs' + }, + summary => { + name => N('The wizard collected the following parameters.'), + pre => sub { + $o->{var}{wiz_text_level} = $level{$o->{var}{wiz_nfs_level}}; + $o->{var}{wiz_netmask} = $o->{var}{wiz_nfs_level} == 1 ? "0.0.0.0/0.0.0.0" : $o->{var}{wiz_netmask} + }, + data => [ + { label => N('Exported dir:'), fixed_val => \$o->{var}{wiz_nfs_dir} }, + { label => N('Access :'), fixed_val => \$o->{var}{wiz_text_level} }, + { label => N('Netmask :'), fixed_val => \$o->{var}{wiz_netmask} }, + ], + post => \&do_it, + next => 'end' + }, + end => { + name => N('Congratulations') . "\n\n" . N('The wizard successfully configured your NFS Server'), + end => 1, + next => 0 +}, +}; + +sub new { + my ($class, $conf) = @_; + bless { + o => $o, + }, $class; +} + +sub check { + -d $o->{var}{wiz_nfs_dir} or return 'error_dir' +} + +sub network_mask { + my $wiz_ip_server = $wiz->{net}->itf_get("IPADDR"); + my $mask = $wiz->{net}->itf_get("NETMASK"); + $mask = $mask ? $mask : "255.255.255.0"; + $wiz_ip_server = $wiz_ip_server ? $wiz_ip_server : "192.168.1.0"; + "$1.$2.$3.0/$mask" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; +} + +sub chooser { + $o->{var}{wiz_nfs_level} == 2 and 'shownet' +} + +sub do_it { + $::testing and return; + my $line; + my $file = "/etc/exports"; + chomp($o->{var}{wiz_nfs_dir}); + -f $file and cp_af($file, $file.".orig"); + if ($o->{var}{wiz_nfs_level} == 2) { + my $mask = $wiz->{net}->itf_get("NETMASK"); + $line = "$o->{var}{wiz_nfs_dir} $o->{var}{wiz_netmask}(rw,no_root_squash,sync)\n"; + } + else { + $line = "$o->{var}{wiz_nfs_dir} *(rw,no_root_squash,sync)\n"; + } + my $t; + foreach (cat_($file)) { + if (/^(?!\#).*$o->{var}{wiz_nfs_dir}\s.*/) { + $t = $_; + last; + } + } + substInFile { s|^(?!\#).*$o->{var}{wiz_nfs_dir}\s.*|\#$&|} $file; + append_to_file($file, $line); + system("/usr/sbin/exportfs -a"); + services::start('nfs') if services::is_service_running('nfs') +} + +1; diff --git a/time_wizard/Ntp.pm b/time_wizard/Ntp.pm new file mode 100644 index 00000000..dbc38909 --- /dev/null +++ b/time_wizard/Ntp.pm @@ -0,0 +1,220 @@ +#!/usr/bin/perl + +# Drakwizard + +# Copyright (C) 2002, 2003 Mandrakesoft +# +# Authors: Arnaud Desmons <adesmons@mandrakesoft.com> +# Florent Villard <warly@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 MDK::Wizard::Ntp; +use strict; + +use common; +use services; +require MDK::Wizard::Wizcommon; + +my $wiz = new MDK::Wizard::Wizcommon; + +my $o = { + name => N('Time wizard'), + var => { + varserver1 => '', + varserver2 => '', + wiz_timezone => '' + }, + needed_rpm => [ 'ntp' ], + defaultimage => "$ENV{__WIZ_HOME__}time_wizard/images/Time.png" + }; + +my %ntp_servers = ( +'pool.ntp.org' => "Randomly choosen ntp server (pool.ntp.org)", +'bernina.ethz.ch' => "Swiss Fed. Inst. of Technology", +'clock.nc.fukuoka-u.ac.jp' => "Fukuoka university, Fukuoka, Japan", +'clock.psu.edu' => "Penn State University, University Park, PA", +'clock.tricity.wsu.edu' => "Washington State University Tri-Cities, Richland, Wa", +'constellation.ecn.uoknor.edu' => "University of Oklahoma, Norman, Oklahoma, USA", +'fartein.ifi.uio.no' => "University of Oslo, Norway", +'ntp.adelaide.edu.au' => "University of Adelaide, South Australia", +'ntp.cs.strath.ac.uk' => "Dept. Computer Science, Strathclyde University, Glasgow, Scotland", +'ntp.shim.org' => "Singapore", +'ntp.tmc.edu' => "Baylor College of Medicine, Houston, Tx", +'ntp1.cmc.ec.gc.ca' =>"Canadian Meteorological Centre, Dorval, Quebec, Canada" +); + +my %actions = ( + try_again => N('Try again'), + save_quit => N('Save config without test') +); + +my %country; +my @country; +if (-d '/usr/share/zoneinfo') { + opendir my $dir, '/usr/share/zoneinfo'; + foreach my $z (grep { /^[A-Z]/ } readdir $dir) { + if (-d "/usr/share/zoneinfo/$z") { + opendir my $dir2, "/usr/share/zoneinfo/$z"; + push @{$country{$z}}, map { "$_" } grep { /^[A-Z]/ } readdir $dir2; + closedir $dir2 + } else { + $country{$z} = 1 + } + } + closedir $dir; +} + +$o->{pages} = { + welcome => { + name => N('This wizard will help you to set the time of your server synchronized with an external time server.') . "\n\n" . N('Thus your server will be the local time server for your network.') . "\n\n" . N('press next to begin, or cancel to leave this wizard'), + no_back => 1, + next => 'config' + }, + config => { + name => N('Time Servers') . "\n\n" . N('Select a primary and secondary server from the list.') . "\n\n" . N('(we recommand you to use pool.ntp.org twice as this server randomly points to available time servers)'), + pre => sub { + $o->{var}{varserver1} ||= 'pool.ntp.org'; + $o->{var}{varserver2} ||= 'pool.ntp.org'; + }, + data => [ + { label => N('Primary Time Server:'), val => \$o->{var}{varserver1}, list => [ keys %ntp_servers ], format => sub { $ntp_servers{$_[0]} } }, + { label => N('Secondary Time Server:'), val => \$o->{var}{varserver2}, list => [ keys %ntp_servers ], format => sub { $ntp_servers{$_[0]} } }, + ], + next => 'choose_region' + }, + choose_region => { + name => N('Choose a timezone'), + pre => sub { + my (undef, $region, $country) = get_timezone(); + $o->{var}{wiz_region} ||= $region; + $o->{var}{wiz_country} ||= $country + }, + data => [ + { label => N('Choose a region:'), val => \$o->{var}{wiz_region}, list => [ keys %country ] }, + ], + post => sub { + 'choose_country' if ref $country{$o->{var}{wiz_region}} + }, + next => 'test_server' + }, + choose_country => { + name => N('Choose a timezone'), + pre => sub { + @country = ref $country{$o->{var}{wiz_region}} ? @{$country{$o->{var}{wiz_region}}} : () + }, + data => [ + { label => N('Choose a country:'), val => \$o->{var}{wiz_country}, fixed_list => \@country }, + ], + next => 'test_server' + }, + test_server => { + name => N('Testing the time servers availability') . "\n\n" . N('If the time server is not immediately available (network or other reason), there will be about a 30 second delay.') . "\n\n" . N('Press next to start the time servers test.'), + pre => sub { + $o->{var}{wiz_timezone} = $o->{var}{wiz_region} . (ref $country{$o->{var}{wiz_region}} ? "/$o->{var}{wiz_country}" : ""); + }, + post => \&test, + data => [ + { label => N('Primary Time Server:'), fixed_val => \$o->{var}{varserver1} }, + { label => N('Secondary Time Server:'), fixed_val => \$o->{var}{varserver2} }, + { label => N('Time zone:'), fixed_val => \$o->{var}{wiz_timezone} }, + ], + next => 'end' + }, + warning => { + name => N('Warning.'), + data => [ { label => N('') } ], + ignore => 1, + next => 'summary' + }, + server_not_responding => { + name => N('Warming.'), + post => sub { + if ($o->{var}{action} eq 'save_quit') { + do_it(); + 'end' + } else { + 'test_server' + } + }, + data => [ + { label => N('The time servers are not responding. The causes could be:') }, + { label => N('- non existent time servers') }, + { label => N('- no outside network') }, + { label => N('- other reasons...') }, + { label => N('- You can try again to contact time servers, or save configuration without actually setting time.') }, + { val => \$o->{var}{action}, list => [ keys %actions ], format => sub { $actions{$_[0]} } }, + ], + next => 'config' + }, + end => { + name => N('Time server configuration saved') . "\n\n" . N('Your server can now act as a time server for your local network.'), + end => 1, + next => 0 + }, +}; + +sub new { + my ($class, $conf) = @_; + bless { + o => $o, + }, $class; +} + +sub get_timezone { + -f "/etc/sysconfig/clock" or return; + my %conf = getVarsFromSh("/etc/sysconfig/clock"); + my ($c,$r) = split "/", $conf{ZONE}; + return ($conf{ZONE}, $c, $r) +} + +sub test { + $::testing and return 'end'; + system("/usr/sbin/ntpdate -q $o->{var}{varserver1} $o->{var}{varserver2}"); + if (!($? >> 8)) { + do_it(); + return 'end' + } + 'server_not_responding' +} + +sub do_it { + $::testing and return; + my $file = "/etc/sysconfig/clock"; + MDK::Common::cp_af($file, $file.".orig"); + open(NEW, "> $file") or die "can not open $file: $!"; + print NEW "UTC=true\n"; + print NEW "ZONE=$o->{var}{wiz_timezone}\n"; + print NEW "ARC=false\n"; + close NEW or die "can not close $file: $!"; + MDK::Common::cp_af("/usr/share/zoneinfo/$o->{var}{wiz_timezone}", "/etc/localtime"); + -f "/etc/ntp/step-tickers" and MDK::Common::cp_af("/etc/ntp/step-tickers", "/etc/ntp/step-tickers.orig"); + open(NEW, "> /etc/ntp/step-tickers") or die "can not open /etc/ntp/step-tickers: $!"; + print NEW $o->{var}{varserver1}."\n"; + print NEW $o->{var}{varserver2}."\n"; + close NEW or die "can not close /etc/ntp/step-tickers: $!"; + substInFile { s/(# server clock.via.net)/$1\nserver $o->{var}{varserver1}/ } '/etc/ntp.conf' if -f '/etc/ntp.conf'; + standalone::explanations("Wrote /etc/ntp/step-tickers, starting services"); + my @services = qw(crond atd ntpd); + foreach (@services) { + services::stop($_) + } + foreach (reverse @services) { + services::start($_) + } + system("/sbin/hwclock --systohc --utc"); +} + +1; |