diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Vyatta/Config.pm | 42 | ||||
-rwxr-xr-x | lib/Vyatta/ConfigLoad.pm | 48 | ||||
-rwxr-xr-x | lib/Vyatta/ConfigOutput.pm | 133 |
3 files changed, 170 insertions, 53 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index 4ede95e..8de3aba 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -525,6 +525,48 @@ sub listDeleted { return @deleted; } +## isDeactivated("node") +# returns back whether this node is in an active (false) or +# deactivated (true) state. +sub getDeactivated { + my ($self, $node) = @_; + + if (!defined $node) { + } + + # let's setup the filepath for the change_dir + $node =~ s/\//%2F/g; + $node =~ s/\s+/\//g; + #now walk up parent in local and in active looking for '.disable' file + + my @a = split(" ",$node); + $node = join("/",@a); + + while (1) { + my $filepath = "$self->{_changes_only_dir_base}/$node"; + my $filepathActive = "$self->{_active_dir_base}/$node"; + + my $local = $filepath . "/.disable"; + my $active = $filepathActive . "/.disable"; + + if (-e $local && -e $active) { + return ("both",$node); + } + elsif (-e $local && !(-e $active)) { + return ("local",$node); + } + elsif (!(-e $local) && -e $active) { + return ("active",$node); + } + my $pos = rindex($node, "/"); + if ($pos == -1) { + last; + } + $node = substr($node,0,$pos); + } + return (undef,undef); +} + ## isChanged("node") # will check the change_dir to see if the "node" has been changed from a previous # value. returns true or false. diff --git a/lib/Vyatta/ConfigLoad.pm b/lib/Vyatta/ConfigLoad.pm index 627b361..54befc6 100755 --- a/lib/Vyatta/ConfigLoad.pm +++ b/lib/Vyatta/ConfigLoad.pm @@ -86,7 +86,12 @@ sub enumerate_branch { if (defined($val)) { push @cur_path, $val; } - push @all_naked_nodes, [ @cur_path ]; + if (defined $cur_node->{'disable'}) { + push @all_naked_nodes, [ '!', @cur_path ]; + } + else { + push @all_naked_nodes, [ @cur_path ]; + } my @qpath = applySingleQuote(@cur_path); push @all_nodes, [\@qpath, 0]; } @@ -270,6 +275,7 @@ sub findDeletedNodes { } my @set_list = (); +my @disable_list = (); # find specified node's values in active config that are set # (added or changed). @@ -322,21 +328,33 @@ sub findSetNodes { return; } foreach (sort keys %{$new_ref}) { - if (scalar(keys %{$new_ref->{$_}}) == 0) { - # we are at a non-value leaf node. - # check if we need to add this node. - if (!defined($active_hash{$_})) { - my @plist = applySingleQuote(@active_path, $_); - push @set_list, [\@plist, 0]; - } else { - # node already present. do nothing. + if (scalar(keys %{$new_ref->{$_}}) == 0) { + # we are at a non-value leaf node. + # check if we need to add this node. + if (!defined($active_hash{$_})) { + my @plist = applySingleQuote(@active_path, $_); + if ($active_path[0] eq '!') { + my @tmp = @plist[1..$#plist]; + push @disable_list, [\@tmp, 0]; + push @set_list, [\@tmp, 0]; + } + else { + push @set_list, [\@plist, 0]; + } + } else { + # node already present. do nothing. + } + next; } - next; - } - # we recur regardless of whether it's in active. all changes will be - # handled when we reach leaf nodes (above). - findSetNodes($new_ref->{$_}, [ @active_path, $_ ]); + if ($active_path[0] eq '!') { + my @plist = applySingleQuote(@active_path, $_); + my @tmp = @plist[1..$#plist]; + push @disable_list, [\@tmp, 0]; + } + findSetNodes($new_ref->{$_}, [ @active_path, $_ ]); } + # we recur regardless of whether it's in active. all changes will be + # handled when we reach leaf nodes (above). } # compare the current active config with the specified hierarchy and return @@ -347,6 +365,7 @@ sub getConfigDiff { $active_cfg = new Vyatta::Config; $new_cfg_ref = shift; @set_list = (); + @disable_list = (); @delete_list = (); findDeletedNodes($new_cfg_ref, [ ]); findSetNodes($new_cfg_ref, [ ]); @@ -369,6 +388,7 @@ sub getConfigDiff { my %diff = ( 'delete' => \@new_delete_list, 'set' => \@set_list, + 'deactivate' => \@disable_list, ); return %diff; } diff --git a/lib/Vyatta/ConfigOutput.pm b/lib/Vyatta/ConfigOutput.pm index fd30049..fd377d7 100755 --- a/lib/Vyatta/ConfigOutput.pm +++ b/lib/Vyatta/ConfigOutput.pm @@ -66,9 +66,10 @@ my $config = undef; # deleted" from displayDeletedOrigChildren.) sub displayValues { my @cur_path = @{$_[0]}; - my $prefix = $_[1]; - my $name = $_[2]; - my $simple_show = $_[3]; + my $dis = $_[1]; + my $prefix = $_[2]; + my $name = $_[3]; + my $simple_show = $_[4]; my ($is_multi, $is_text, $default) = $config->parseTmpl(\@cur_path); if ($is_text) { $default =~ /^"(.*)"$/; @@ -99,7 +100,7 @@ sub displayValues { if ($is_password && $hide_password) { $oval = $HIDE_PASSWORD; } - print "$prefix$name $oval\n"; + print "$dis$prefix$name $oval\n"; } return; } @@ -108,7 +109,7 @@ sub displayValues { if ($is_password && $hide_password) { $del = $HIDE_PASSWORD; } - print "-$prefix$name $del\n"; + print "$dis-$prefix$name $del\n"; } } foreach my $nval (@nvals) { @@ -123,7 +124,7 @@ sub displayValues { if ($is_password && $hide_password) { $nval = $HIDE_PASSWORD; } - print "$diff$prefix$name $nval\n"; + print "$dis$diff$prefix$name $nval\n"; } } else { my $oval = $config->returnOrigValue(''); @@ -145,7 +146,7 @@ sub displayValues { if ($is_password && $hide_password) { $oval = $HIDE_PASSWORD; } - print "$prefix$name $oval\n"; + print "$dis$prefix$name $oval\n"; } return; } @@ -166,10 +167,10 @@ sub displayValues { if ($is_password && $hide_password) { $value = $HIDE_PASSWORD; } - print "$diff$prefix$name $value\n"; + print "$dis$diff$prefix$name $value\n"; } elsif ($cnodes{'def'} && ($diff eq '>' || $diff eq '-')) { - print "$diff$prefix$name $value\n"; + print "$dis$diff$prefix$name $value\n"; } } } @@ -180,25 +181,40 @@ sub displayValues { # deleted.) sub displayDeletedOrigChildren { my @cur_path = @{$_[0]}; - my $prefix = $_[1]; - my $dont_show_as_deleted = $_[2]; + my $dis = $_[1]; + my $prefix = $_[2]; + my $dont_show_as_deleted = $_[3]; my $dprefix = '-'; if (defined($dont_show_as_deleted)) { $dprefix = ''; } $config->setLevel(''); + my @children = $config->listOrigNodes(join ' ', @cur_path); for my $child (sort @children) { if ($child eq 'node.val') { # should not happen! next; } + my $is_tag = $config->isTagNode([ @cur_path, $child ]); + + if (!defined $is_tag) { + my $path = join(' ',( @cur_path, $child )); + my ($state, $n) = $config->getDeactivated($path); + if (defined $state) { + $dis = '! '; + } + else { + $dis = ''; + } + } + $config->setLevel(join ' ', (@cur_path, $child)); my @cnames = sort $config->listOrigNodesNoDef(); if ($cnames[0] eq 'node.val') { - displayValues([ @cur_path, $child ], $prefix, $child, + displayValues([ @cur_path, $child ], $dis, $prefix, $child, $dont_show_as_deleted); } elsif ($cnames[0] eq 'def') { #ignore @@ -210,21 +226,32 @@ sub displayDeletedOrigChildren { # should not happen next; } - print "$dprefix$prefix$child $cname {\n"; + + #need separate check here + my $path = join(' ',( @cur_path, $child, $cname )); + my ($state, $n) = $config->getDeactivated($path); + if (defined $state) { + $dis = '! '; + } + else { + $dis = ''; + } + + print "$dis$dprefix$prefix$child $cname {\n"; displayDeletedOrigChildren([ @cur_path, $child, $cname ], - "$prefix ", $dont_show_as_deleted); - print "$dprefix$prefix}\n"; + $dis,"$prefix ", $dont_show_as_deleted); + print "$dis$dprefix$prefix}\n"; } } else { - print "$dprefix$prefix$child {\n"; - displayDeletedOrigChildren([ @cur_path, $child ], "$prefix ", + print "$dis$dprefix$prefix$child {\n"; + displayDeletedOrigChildren([ @cur_path, $child ],$dis, "$prefix ", $dont_show_as_deleted); - print "$dprefix$prefix}\n"; + print "$dis$dprefix$prefix}\n"; } } else { my $has_tmpl_children = $config->hasTmplChildren([ @cur_path, $child ]); - print "$dprefix$prefix$child" - . ($has_tmpl_children ? " {\n$dprefix$prefix}\n" : "\n"); + print "$dis$dprefix$prefix$child" + . ($has_tmpl_children ? " {\n$dis$dprefix$prefix}\n" : "\n"); } } } @@ -235,12 +262,18 @@ sub displayDeletedOrigChildren { sub displayChildren { my %child_hash = %{$_[0]}; my @cur_path = @{$_[1]}; - my $prefix = $_[2]; + my $dis = $_[2]; + my $prefix = $_[3]; for my $child (sort (keys %child_hash)) { + my $dis = ""; + my @tmp = @cur_path; + push (@tmp,$child); + if ($child eq 'node.val') { # should not happen! next; } + my ($diff, $vdiff) = (' ', ' '); if ($child_hash{$child} eq 'added') { $diff = '+'; @@ -252,6 +285,18 @@ sub displayChildren { $vdiff = '>'; } my $is_tag = $config->isTagNode([ @cur_path, $child ]); + + if (!defined($is_tag)) { + my $path = join(' ',( @cur_path, $child )); + my ($state, $n) = $config->getDeactivated($path); + if (defined $state) { + $dis = '! '; + } + else { + $dis = ''; + } + } + $config->setLevel(join ' ', (@cur_path, $child)); my %cnodes = $config->listNodeStatus(); my @cnames = sort keys %cnodes; @@ -269,7 +314,7 @@ sub displayChildren { } if ($leaf == 1) { - displayValues([ @cur_path, $child ], $prefix, $child); + displayValues([ @cur_path, $child ], $dis, $prefix, $child); } elsif (scalar($#cnames) >= 0) { if ($is_tag) { @cnames = sort versioncmp @cnames; @@ -278,50 +323,60 @@ sub displayChildren { # should not happen next; } + + my $path = join(' ',( @cur_path, $child, $cname )); + my ($state, $n) = $config->getDeactivated($path); + if (defined $state) { + $dis = '! '; + } + else { + $dis = ''; + } + my $tdiff = ' '; if ($cnodes{$cname} eq 'deleted') { $tdiff = '-'; } elsif ($cnodes{$cname} eq 'added') { $tdiff = '+'; } - print "$tdiff$prefix$child $cname {\n"; + print "$dis$tdiff$prefix$child $cname {\n"; if ($cnodes{$cname} eq 'deleted') { displayDeletedOrigChildren([ @cur_path, $child, $cname ], - "$prefix "); + $dis, "$prefix "); } else { $config->setLevel(join ' ', (@cur_path, $child, $cname)); my %ccnodes = $config->listNodeStatus(); displayChildren(\%ccnodes, [ @cur_path, $child, $cname ], - "$prefix "); + $dis, "$prefix "); } - print "$tdiff$prefix}\n"; + print "$dis$tdiff$prefix}\n"; } } else { - print "$diff$prefix$child {\n"; + print "$dis$diff$prefix$child {\n"; if ($child_hash{$child} eq 'deleted') { # this should not happen - displayDeletedOrigChildren([ @cur_path, $child ], "$prefix "); + displayDeletedOrigChildren([ @cur_path, $child ], $dis, "$prefix "); } else { - displayChildren(\%cnodes, [ @cur_path, $child ], "$prefix "); + displayChildren(\%cnodes, [ @cur_path, $child ], $dis, "$prefix "); } - print "$diff$prefix}\n"; + print "$dis$diff$prefix}\n"; } } else { if ($child_hash{$child} eq 'deleted') { $config->setLevel(''); my @onodes = $config->listOrigNodes(join ' ', (@cur_path, $child)); if ($#onodes == 0 && $onodes[0] eq 'node.val') { - displayValues([ @cur_path, $child ], $prefix, $child); + displayValues([ @cur_path, $child ], $dis, $prefix, $child); } else { - print "$diff$prefix$child {\n"; - displayDeletedOrigChildren([ @cur_path, $child ], "$prefix "); - print "$diff$prefix}\n"; + print "$dis$diff$prefix$child {\n"; + displayDeletedOrigChildren([ @cur_path, $child ], $dis, "$prefix "); + print "$dis$diff$prefix}\n"; } } else { my $has_tmpl_children = $config->hasTmplChildren([ @cur_path, $child ]); - print "$diff$prefix$child" - . ($has_tmpl_children ? " {\n$diff$prefix}\n" : "\n"); + print "$dis$diff$prefix$child" + . ($has_tmpl_children ? " {\n$dis$diff$prefix}\n" : "\n"); } } } @@ -350,9 +405,9 @@ sub outputNewConfig { if ($leaf == 1) { # this is a leaf value-node - displayValues([ @_ ], '', $_[$#_]); + displayValues([ @_ ], '', '', $_[$#_]); } else { - displayChildren(\%rnodes, [ @_ ], ''); + displayChildren(\%rnodes, [ @_ ], '', ''); } } else { if ($config->existsOrig() && ! $config->exists()) { @@ -371,7 +426,7 @@ sub outputNewConfig { sub outputActiveConfig { $config = new Vyatta::Config; $config->setLevel(join ' ', @_); - displayDeletedOrigChildren([ @_ ], '', 1); + displayDeletedOrigChildren([ @_ ], '','', 1); } 1; |