From 23c2cf67eda71cd15a94f1a28a9e699ea45cbc3e Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 1 Jul 2008 17:12:07 -0700 Subject: Partial fix for 3383: check for vyatta-config-version, warn/prompt that it appears to be invalid config. --- scripts/vyatta-load-config.pl | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'scripts/vyatta-load-config.pl') diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index 29d4dec..ee4a9c4 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -23,6 +23,9 @@ use strict; use lib "/opt/vyatta/share/perl5/"; +use POSIX; +use IO::Prompt; +use Sys::Syslog qw(:standard :macros); use VyattaConfigLoad; my $etcdir = $ENV{vyatta_sysconfdir}; @@ -42,6 +45,7 @@ my $proto; if (defined($ARGV[0])) { $load_file = $ARGV[0]; } +my $orig_load_file = $load_file; if ($load_file =~ /^[^\/]\w+:\//) { if ($load_file =~ /^(\w+):\/\/\w/) { @@ -107,20 +111,36 @@ if ($mode eq 'local') { } $load_file = $url_tmp_file; } + +my $xorp_cfg = 0; +my $valid_cfg = 0; while () { if (/\/\*XORP Configuration File, v1.0\*\//) { - print "Warning: Loading a pre-Glendale configuration.\n"; - print "Do you want to continue? [no] "; - my $resp = ; - if (!($resp =~ /^yes$/i)) { - print "Configuration not loaded\n"; - exit 1; - } + $xorp_cfg = 1; + last; + } elsif (/vyatta-config-version/) { + $valid_cfg = 1; last; } } +if ($xorp_cfg or ! $valid_cfg) { + if ($xorp_cfg) { + print "Warning: Loading a pre-Glendale configuration.\n"; + } else { + print "Warning: file does NOT appear to be a valid config file.\n"; + } + if (!prompt("Do you want to continue? ", -tty, -Yes, -default=>'no')) { + print "Configuration not loaded\n"; + exit 1; + } +} close CFG; +# log it +openlog($0, "", LOG_USER); +my $login = getlogin() || getpwuid($<) || "unknown"; +syslog("warning", "Load config [$orig_load_file] by $login"); + # do config migration system("$sbindir/vyatta_config_migrate.pl $load_file"); -- cgit v1.2.3