summaryrefslogtreecommitdiffstats
path: root/dhcp_wizard
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2004-07-29 01:48:40 +0000
committerAntoine Ginies <aginies@mandriva.com>2004-07-29 01:48:40 +0000
commit783492b7898f1b65b18b4f912e5a7aa6024e78a9 (patch)
tree608639fadc365e117921c81926407d26363121ca /dhcp_wizard
parent31f34fba8022f2d8766641c84c5664b61631e127 (diff)
downloaddrakwizard-783492b7898f1b65b18b4f912e5a7aa6024e78a9.tar
drakwizard-783492b7898f1b65b18b4f912e5a7aa6024e78a9.tar.gz
drakwizard-783492b7898f1b65b18b4f912e5a7aa6024e78a9.tar.bz2
drakwizard-783492b7898f1b65b18b4f912e5a7aa6024e78a9.tar.xz
drakwizard-783492b7898f1b65b18b4f912e5a7aa6024e78a9.zip
fix pb of multi interface
Diffstat (limited to 'dhcp_wizard')
-rwxr-xr-xdhcp_wizard/Dhcp.pm174
1 files changed, 80 insertions, 94 deletions
diff --git a/dhcp_wizard/Dhcp.pm b/dhcp_wizard/Dhcp.pm
index e2066353..feecc40b 100755
--- a/dhcp_wizard/Dhcp.pm
+++ b/dhcp_wizard/Dhcp.pm
@@ -30,71 +30,82 @@ use MDK::Wizard::Varspaceval;
use MDK::Wizard::Wizcommon;
my $wiz = new MDK::Wizard::Wizcommon;
-my $interface = 'eth0';
+
my $wiz_ip_server = $wiz->{net}->itf_get("IPADDR");
-if (!$wiz_ip_server) {
- ($wiz_ip_server) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
-}
my $wiz_tftpserverip = $wiz_ip_server;
-my $d = $4 if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
-my $s = "$1.$2.$3" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
my $o = {
- name => N("DHCP Wizard"),
- var => {
- ip1 => '',
- ip2 => '',
- pxe => '1',
- gateway => "$wiz_ip_server",
- wiz_authoritative => 0,
- einterface => $wiz->{net}->default_itf
- },
- needed_rpm => [ 'dhcp-server' ],
- defaultimage => "$ENV{__WIZ_HOME__}dhcp_wizard/images/DHCP.png"
- };
+ name => N("DHCP Wizard"),
+ var => {
+ ip1 => '',
+ ip2 => '',
+ pxe => '1',
+ gateway => '',
+ wiz_authoritative => 0,
+ interface => $wiz->{net}->default_itf
+ },
+ needed_rpm => [ 'dhcp-server' ],
+ defaultimage => "/usr/share/wizards/dhcp_wizard/images/DHCP.png"
+ };
$o->{pages} = {
- welcome => {
- name => N("DHCP Wizard") . "\n\n\n" . N("DHCP is a service that automatically assigns networking addresses to your workstations.") . "\n\n\n" . N("This wizard will help you configuring the DHCP services of your server."),
- post => sub { $wiz->check_dhcp },
- no_back => 1,
- next => 'ip_range'
- },
- ip_range => {
- name => N("Range of addresses used by DHCP") . "\n\n\n" . N("Select the range of addresses assigned to the workstations by the DHCP service; unless you have special needs, you can safely accept the proposed values. (ie: 192.168.100.20 192.168.100.40)") . "\n\n" . N("If you want to enable PXE in your dhcp server please check the box (Pre-boot eXecution Environment, a protocol that allows computers to boot through the network)."),
- pre => sub {
- $o->{var}{ip1} ||= compute_range();
- $o->{var}{ip2} ||= compute_range2();
- },
- data => [
- { label => N("Lowest IP address:"), val => \$o->{var}{ip1} },
- { label => N("Highest IP address:"), val => \$o->{var}{ip2} },
- { label => N("Gateway IP address:"), val => \$o->{var}{gateway} },
- { label => N("Enable PXE:"), type => 'bool', val => \$o->{var}{pxe} },
- ],
- complete => \&check,
- post => sub { return keys %{$wiz->{net}{itf}} > 1 ? 'interface' : 'summary' },
- },
- interface => {
- name => N("Interface the dhcp server must listen to"),
- pre => sub {
- $o->{var}{interface} ||= $wiz->{net}->default_itf
- },
- data => [
- { list => [ keys %{$wiz->{net}{itf}} ], val => \$o->{var}{interface} },
- ],
- next => 'summary'
- },
+ welcome => {
+ name => N("DHCP Wizard") . "\n\n\n" . N("DHCP is a service that automatically assigns networking addresses to your workstations.") . "\n\n\n" . N("This wizard will help you configuring the DHCP services of your server."),
+ no_back => 1,
+ next => 'interface'
+ },
+ interface => {
+ name => N("Interface the dhcp server must listen to"),
+ pre => sub {
+ if (!$wiz_ip_server) {
+ my $interface = 'eth0';
+ ($wiz_ip_server) = `/sbin/ip addr show dev $interface` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
+ }
+ $o->{var}{interface} |= $wiz->{net}->default_itf;
+ },
+ data => [
+ { list => [ keys %{$wiz->{net}{itf}} ], val => \$o->{var}{interface} },
+ ],
+ next => 'ip_range'
+ },
+ ip_range => {
+ name => N("Range of addresses used by DHCP") . "\n\n\n" . N("Select the range of addresses assigned to the workstations by the DHCP service; unless you have special needs, you can safely accept the proposed values. (ie: 192.168.100.20 192.168.100.40)") . "\n\n" . N("If you want to enable PXE in your dhcp server please check the box (Pre-boot eXecution Environment, a protocol that allows computers to boot through the network)."),
+ pre => sub {
+ ($wiz_ip_server) = `/sbin/ip addr show dev $o->{var}{interface}` =~ /^\s*inet\s+(\d+\.\d+\.\d+\.\d+)/m;
+ $wiz_tftpserverip = $wiz_ip_server;
+ my $d = $4 if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $s = "$1.$2.$3" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ $o->{var}{ip1} = compute_range($d, $s);
+ $o->{var}{ip2} = compute_range2($d, $s);
+ },
+ data => [
+ { label => N("Lowest IP address:"), val => \$o->{var}{ip1} },
+ { label => N("Highest IP address:"), val => \$o->{var}{ip2} },
+ { label => N("Gateway IP address:"), val => \$o->{var}{gateway} },
+ { label => N("Enable PXE:"), type => 'bool', val => \$o->{var}{pxe} },
+ ],
+ next => 'summary'
+ },
dhcp_warning => {
name => N("Warning") . "\n\n" . N("You are in dhcp, server may not work with your configuration."),
ignore => 1,
next => 'ip_range'
},
+ ip_range_error => {
+ name => N("Error") . "\n\n" . N("The IP range specified is not correct."),
+ ignore => 1,
+ next => 'ip_range'
+ },
ip_range_warning => {
name => N("Warning") . "\n\n" . N("The IP range specified is not in server address range."),
ignore => 1,
next => 'summary'
},
+ server_in_range => {
+ name => N("Error") . "\n\n" . N("The IP of the server must not be in range."),
+ ignore => 1,
+ next => 'ip_range'
+ },
summary => {
name => N("Configuring the DHCP server") . "\n\n" . N("The wizard collected the following parameters needed to configure your DHCP service:"),
pre => sub {
@@ -104,7 +115,7 @@ $o->{pages} = {
{ label => N("Lowest IP address:"), fixed_val => \$o->{var}{ip1} },
{ label => N("Highest IP address:"), fixed_val => \$o->{var}{ip2} },
{ label => N("Gateway IP address:"), fixed_val => \$o->{var}{gateway} },
- { label => N("Interface:"), fixed_val => \$o->{var}{einterface} },
+ { label => N("Interface:"), fixed_val => \$o->{var}{interface} },
{ label => N("Enable PXE:"), fixed_val => \$o->{var}{pxeornot} },
],
post => \&do_it,
@@ -124,7 +135,10 @@ $o->{pages} = {
},
};
+
+
sub compute_range {
+ my ($d, $s) = @_;
my $n;
if ($d <= 64) { $n = "65" }
elsif ($d <= 128) { $n = "129" }
@@ -133,6 +147,7 @@ sub compute_range {
}
sub compute_range2 {
+ my ($d, $s) = @_;
my $n;
if ($d <= 128) { $n = "254" }
elsif ($d > 192) { $n = "192" }
@@ -143,56 +158,23 @@ sub compute_range2 {
sub check {
my $check_ip = sub { return $_[0] < 0 || $_[0] > 255 ? 0 : 1 };
my $r1_trunc = "$1.$2.$3" if $o->{var}{ip1} =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
- foreach ($1, $2, $3, $4) {
- if (!$check_ip->($_)) {
- $::in->ask_warn(N("Error"), N("The IP specified is not correct: %s", $o->{var}{ip1}));
- return 1;
- }
- }
+ foreach ($1, $2, $3, $4) { $check_ip->($_) or return 'ip_range_error' }
my $r2_trunc = "$1.$2.$3" if $o->{var}{ip2} =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
- foreach ($1, $2, $3, $4) {
- if (!$check_ip->($_)) {
- $::in->ask_warn(N("Error"), N("The IP specified is not correct: %s", $o->{var}{ip2}));
- return 1;
- }
- }
+ foreach ($1, $2, $3, $4) { $check_ip->($_) or return 'ip_range_error' }
my $d1 = $4 if $o->{var}{ip1} =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
my $d2 = $4 if $o->{var}{ip2} =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
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})/;
- if (!$r1_trunc) {
- standalone::explanations("DHCP wizard : incorrect adress range 1");
- return 1;
- }
- if (!$r2_trunc) {
- standalone::explanations("DHCP wizard : incorrect adress range 2");
- $::in->ask_warn(N("Error"), N("The IP specified is not correct: %s", $o->{var}{ip2}));
- ip_range_error($r2_trunc);
- return 1;
- }
+ if (!$r1_trunc) { standalone::explanations("DHCP wizard : incorrect adress range 1"); return 'ip_range_error' }
+ if (!$r2_trunc) { standalone::explanations("DHCP wizard : incorrect adress range 2"); return 'ip_range_error' }
if ($r1_trunc ne $s_trunc || $r2_trunc ne $s_trunc) {
- standalone::explanations("DHCP wizard : range not in network");
- $::in->ask_warn(N("Error"), N("The IP range specified is not correct since it's not in the network"));
- return 1;
- }
- if (!$d1 || !$d2) {
- standalone::explanations("DHCP wizard : bad range");
- $::in->ask_warn(N("Error"), N("The IP range specified is not correct"));
- return 1;
- }
- if ($d1 > $d2) {
- standalone::explanations("DHCP wizard : bad range");
- $::in->ask_warn(N("Error"), N("The IP range specified is not correct: the end IP is below the first IP"));
- return 1;
+ standalone::explanations("DHCP wizard : range not in network");
+ return 'ip_range_warning';
}
- if ($ds >= $d1 && $ds <= $d2) {
- standalone::explanations("DHCP wizard : server in range");
- $::in->ask_warn(N("Error"), N("The IP range specified is not correct since the server IP is in:
-%s is included in %s-%s whereas the IP of the server must not be in range.",
- $wiz_ip_server, $o->{var}{ip1}, $o->{var}{ip2}));
- return 1;
- }
- return 0
+ if (!$d1 || !$d2 || $d1 > $d2) { standalone::explanations("DHCP wizard : bad range"); return 'ip_range_error' }
+ if ($ds >= $d1 && $ds <= $d2) { standalone::explanations("DHCP wizard : server in range"); return 'server_in_range' }
+ return 'interface' if keys %{$wiz->{net}{itf}} > 1;
+ 0
}
sub do_it {
@@ -252,7 +234,7 @@ sub do_it {
s|__gateway__|$o->{var}{gateway}|g;
s|__tftpserverip__|$wiz_tftpserverip|g;
$_;
- } cat_("__WIZ_HOME__/dhcp_wizard/scripts/dhcpd.conf.default"));
+ } cat_("/usr/share/wizards//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");
MDK::Common::touch("/var/dhcpd/dhcpd.leases");
@@ -276,6 +258,10 @@ mask = $wiz_ip_netmask, rng1 = $wiz_ip_range1, rng2 = $wiz_ip_range2, dname = $w
} "/etc/dhcpd.conf";
}
+ $o->{var}{gateway} or substInFile {
+ s/#\s+doption routers.*//;
+ } "/etc/dhcpd.conf";
+
if (services::is_service_running('dhcpd')) {
services::restart('dhcpd')
} else {