Author: mzugec Date: Wed Sep 30 17:21:17 2009 New Revision: 58847 URL: http://svn.opensuse.org/viewcvs/yast?rev=58847&view=rev Log: - YaPI: validate routing - YaPI: split code in Write into separate functions Modified: trunk/network/src/lan/YaPI/NETWORK.pm Modified: trunk/network/src/lan/YaPI/NETWORK.pm URL: http://svn.opensuse.org/viewcvs/yast/trunk/network/src/lan/YaPI/NETWORK.pm?rev=58847&r1=58846&r2=58847&view=diff ============================================================================== --- trunk/network/src/lan/YaPI/NETWORK.pm (original) +++ trunk/network/src/lan/YaPI/NETWORK.pm Wed Sep 30 17:21:17 2009 @@ -39,11 +39,12 @@ %configuration = ( 'bootproto' => LanItems->bootproto ); } elsif (LanItems->bootproto eq "static"){ %configuration = ( 'bootproto' => 'static' ); - %configuration->{'ipaddr'} = LanItems->ipaddr . "/" . LanItems->prefix; + $configuration{'ipaddr'} = LanItems->ipaddr . "/" . LanItems->prefix; } $interfaces{LanItems->interfacename}=\%configuration; } elsif (LanItems->getCurrentItem()->{'hwinfo'}->{'type'} eq "eth") { - $interfaces{%{LanItems->getCurrentItem()}->{"hwinfo"}->{"dev_name"}}= {}; + my $device = LanItems->getCurrentItem()->{"hwinfo"}->{"dev_name"}; + $interfaces{$device}= {}; } } @@ -56,21 +57,22 @@ return \%ret; } -BEGIN{$TYPEINFO{Write} = ["function", - "boolean",["map","string","any"]]; -} -sub Write { - my $self = shift; - my $args = shift; - y2milestone("YaPI->Write with settings:", Dumper(\$args)); - # SAVE DEFAULT ROUTE - if (exists($args->{'route'})){ +sub writeRoute { + my $args = shift; + my %ret = ('exit'=>0, 'error'=>''); + my $gw=""; my $dest=""; my @route = (); if (defined ($args->{'route'}->{'default'}->{'via'})){ $gw = $args->{'route'}->{'default'}->{'via'}; if ($gw ne ""){ + YaST::YCP::Import ("IP"); + unless (IP->Check4($gw) eq "") { + $ret{'exit'} = -1; + $ret{'error'} = IP->Valid4(); + return \%ret; + }; $dest = "default"; @route = ( {"destination" => $dest, "gateway" => $gw, @@ -84,27 +86,36 @@ Routing->Routes( \@route ); y2milestone("YaPI->Write after change Routes:", Dumper(Routing->Routes)); Routing->Write(); - } - # SAVE HOSTNAME - if (exists($args->{'hostname'})){ + return \%ret; +} + +sub writeHostname { + my $args = shift; + my $ret = {'exit'=>0, 'error'=>''}; y2milestone("hostname", Dumper(\$args->{'hostname'})); DNS->Read(); DNS->hostname($args->{'hostname'}->{'name'}); DNS->domain($args->{'hostname'}->{'domain'}); DNS->modified(1); DNS->Write(); - } - # SAVE DNS Settings - if (exists($args->{'dns'})){ + return $ret; +} + +sub writeDNS { + my $args = shift; + my $ret = {'exit'=>0, 'error'=>''}; y2milestone("dns", Dumper(\$args->{'dns'})); DNS->Read(); DNS->nameservers($args->{'dns'}->{'nameservers'}); DNS->searchlist($args->{'dns'}->{'searches'}); DNS->modified(1); DNS->Write(); - } - # SAVE DNS Settings - if (exists($args->{'interface'})){ + return $ret; +} + +sub writeInterfaces { + my $args = shift; + my $ret = {'exit'=>0, 'error'=>''}; y2milestone("interface", Dumper(\$args->{'interface'})); foreach my $dev (keys %{$args->{'interface'}}){ YaST::YCP::Import ("NetworkInterfaces"); @@ -115,7 +126,7 @@ my $prefix="32"; YaST::YCP::Import ("Netmask"); my @ip_row = split(/\//, $ip); - my $prefix = $ip_row[$#ip_row]; + $prefix = $ip_row[$#ip_row]; if (Netmask->Check4($prefix)){ y2milestone("Valid netmask: ", $prefix, " will change to prefixlen"); $prefix = Netmask->ToBits($prefix); @@ -131,10 +142,41 @@ YaST::YCP::Import ("Service"); Service->Restart("network"); } + return $ret; +} + + +BEGIN{$TYPEINFO{Write} = ["function", + ["map","string","any"],["map","string","any"]]; +} +sub Write { + my $self = shift; + my $args = shift; +# my %ret = ('exit'=>0, 'error'=>''); + y2milestone("YaPI->Write with settings:", Dumper(\$args)); + # SAVE DEFAULT ROUTE + if (exists($args->{'route'})){ + my $route_ret = writeRoute($args); + return $route_ret if ($route_ret->{'exit'} != 0); + } + # SAVE HOSTNAME + if (exists($args->{'hostname'})){ + my $hn_ret = writeHostname($args); + return $hn_ret if ($hn_ret->{'exit'} != 0); + } + # SAVE DNS Settings + if (exists($args->{'dns'})){ + my $dns_ret = writeDNS($args); + return $dns_ret if ($dns_ret->{'exit'} != 0); + } + # SAVE interfaces Settings + if (exists($args->{'interface'})){ + my $ifc_ret = writeInterfaces($args); + return $ifc_ret if ($ifc_ret->{'exit'} != 0); } - return 1; + return {'exit'=>0, 'error'=>''}; } 1; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org