summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Vyatta/ConfigMgmt.pm22
-rwxr-xr-xscripts/vyatta-config-mgmt.pl40
-rw-r--r--templates-op/show/system/commit/file/node.tag/compare/node.def1
-rw-r--r--templates-op/show/system/commit/file/node.tag/compare/node.tag/node.def8
-rw-r--r--templates-op/show/system/commit/file/node.tag/node.def11
-rw-r--r--templates-op/show/system/commit/node.def1
6 files changed, 76 insertions, 7 deletions
diff --git a/lib/Vyatta/ConfigMgmt.pm b/lib/Vyatta/ConfigMgmt.pm
index 7c2ab91..6a49af3 100644
--- a/lib/Vyatta/ConfigMgmt.pm
+++ b/lib/Vyatta/ConfigMgmt.pm
@@ -29,7 +29,8 @@ use warnings;
our @EXPORT = qw(cm_commit_add_log cm_commit_get_log cm_get_archive_dir
cm_get_lr_conf_file cm_get_lr_state_file
cm_get_commit_hook_dir cm_write_file cm_read_file
- cm_commit_get_file);
+ cm_commit_get_file cm_commit_get_file_name
+ cm_get_num_revs);
use base qw(Exporter);
use Vyatta::Config;
@@ -92,6 +93,14 @@ sub cm_get_max_revs {
return $revs;
}
+sub cm_get_num_revs {
+
+ my @lines = cm_read_file($commit_log_file);
+ my $num_revs = scalar(@lines);
+ $num_revs-- if $num_revs > 0; # rev files start at 0
+ return $num_revs;
+}
+
sub cm_commit_add_log {
my ($user, $via, $comment) = @_;
@@ -118,7 +127,7 @@ sub cm_commit_get_log {
my @lines = cm_read_file($commit_log_file);
my @commit_log = ();
- my $count = 1;
+ my $count = 0;
foreach my $line (@lines) {
if ($line !~ /^\|(.*)\|$/) {
print "Invalid log format [$line]\n";
@@ -139,6 +148,13 @@ sub cm_commit_get_log {
return @commit_log;
}
+sub cm_commit_get_file_name {
+ my ($revnum) = @_;
+
+ my $filename = $archive_dir . "/config.boot." . $revnum . ".gz";
+ return $filename;
+}
+
sub cm_commit_get_file {
my ($revnum) = @_;
@@ -148,7 +164,7 @@ sub cm_commit_get_file {
exit 1;
}
- my $filename = $archive_dir . "/config.boot." . $revnum . ".gz";
+ my $filename = cm_commit_get_file_name($revnum);
die "File [$filename] not found." if ! -e $filename;
my $fh = new IO::Zlib;
diff --git a/scripts/vyatta-config-mgmt.pl b/scripts/vyatta-config-mgmt.pl
index c074793..46d57e9 100755
--- a/scripts/vyatta-config-mgmt.pl
+++ b/scripts/vyatta-config-mgmt.pl
@@ -55,12 +55,21 @@ sub get_link {
return $link;
}
+sub check_valid_rev {
+ my ($rev) = @_;
+
+ my $num_revs = cm_get_num_revs();
+ return 1 if $rev <= $num_revs;
+ print "Invalid revision [$rev]\n";
+ exit 1;
+}
#
# main
#
my ($action, $uri, $revs, $revnum);
+Getopt::Long::Configure('pass_through');
GetOptions("action=s" => \$action,
"uri=s" => \$uri,
"revs=i" => \$revs,
@@ -136,6 +145,7 @@ if ($action eq 'update-revs') {
}
my $lr_conf = "$config_file {\n";
$lr_conf .= "\t rotate $revs\n";
+ $lr_conf .= "\t start 0\n";
$lr_conf .= "\t compress \n";
$lr_conf .= "}\n";
cm_write_file($lr_conf_file, $lr_conf);
@@ -160,6 +170,36 @@ if ($action eq 'show-commit-file') {
print $file;
}
+if ($action eq 'diff') {
+ print "diff\n" if $debug;
+ my $args = $#ARGV;
+ if ($args < 0) {
+ my $tmp_config_file = "/tmp/config.boot.$$";
+ my $tmp_config_file2 = "/tmp/config.boot2.$$";
+ system("cli-shell-api showCfg --show-active-only> $tmp_config_file");
+ system("cli-shell-api showCfg > $tmp_config_file2");
+ my $diff = `diff -u -w $tmp_config_file2 $tmp_config_file`;
+ print $diff;
+ system("rm $tmp_config_file $tmp_config_file2");
+ } elsif ($args eq 0) {
+ my $rev1 = $ARGV[0];
+ check_valid_rev($rev1);
+ my $filename = cm_commit_get_file_name(0);
+ my $filename2 = cm_commit_get_file_name($rev1);
+ my $diff = `zdiff -u $filename2 $filename`;
+ print $diff;
+ } elsif ($args eq 1) {
+ my $rev1 = $ARGV[0];
+ my $rev2 = $ARGV[1];
+ check_valid_rev($rev1);
+ check_valid_rev($rev2);
+ my $filename = cm_commit_get_file_name($rev1);
+ my $filename2 = cm_commit_get_file_name($rev2);
+ my $diff = `zdiff -u $filename2 $filename`;
+ print $diff;
+ }
+}
+
exit $rc;
# end of file
diff --git a/templates-op/show/system/commit/file/node.tag/compare/node.def b/templates-op/show/system/commit/file/node.tag/compare/node.def
new file mode 100644
index 0000000..84cb0a9
--- /dev/null
+++ b/templates-op/show/system/commit/file/node.tag/compare/node.def
@@ -0,0 +1 @@
+help: compare config file revisions
diff --git a/templates-op/show/system/commit/file/node.tag/compare/node.tag/node.def b/templates-op/show/system/commit/file/node.tag/compare/node.tag/node.def
new file mode 100644
index 0000000..95a4bed
--- /dev/null
+++ b/templates-op/show/system/commit/file/node.tag/compare/node.tag/node.def
@@ -0,0 +1,8 @@
+help: compare config file revisions
+run: if [ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ];
+ then
+ ${vyatta_sbindir}/vyatta-config-mgmt.pl \
+ --action=diff "$5" "$7"
+ else
+ echo Must be an admin user to run this command.
+ fi
diff --git a/templates-op/show/system/commit/file/node.tag/node.def b/templates-op/show/system/commit/file/node.tag/node.def
index 52fd065..ac62ad5 100644
--- a/templates-op/show/system/commit/file/node.tag/node.def
+++ b/templates-op/show/system/commit/file/node.tag/node.def
@@ -1,4 +1,9 @@
help: show commit revision file
-run: ${vyatta_sbindir}/vyatta-config-mgmt.pl \
- --action=show-commit-file \
- --revnum="$5"
+run: if [ "$VYATTA_USER_LEVEL_DIR" == "/opt/vyatta/etc/shell/level/admin" ];
+ then
+ ${vyatta_sbindir}/vyatta-config-mgmt.pl \
+ --action=show-commit-file \
+ --revnum="$5"
+ else
+ echo Must be an admin user to run this command.
+ fi
diff --git a/templates-op/show/system/commit/node.def b/templates-op/show/system/commit/node.def
index 4646d29..4fea8fc 100644
--- a/templates-op/show/system/commit/node.def
+++ b/templates-op/show/system/commit/node.def
@@ -1,3 +1,2 @@
help: Show commit revisions log
run: ${vyatta_sbindir}/vyatta-config-mgmt.pl --action=show-commit-log
-