From 83d246d1e284fbf70f69969dbde2771fc4604f7c Mon Sep 17 00:00:00 2001
From: John Estabrook <jestabro@vyos.io>
Date: Wed, 30 Dec 2020 11:09:40 -0600
Subject: migration: T3161: remove ConfigLoad.pm, all dependents and references

Remove ConfigLoad.pm due to its legacy reference to XorpConfigParser,
all dependent scripts:
vyatta-boot-config-loader
vyatta-config-loader.pl
vyatta-load-config.pl
(rewritten or obviated), and references in logrotate, Makefile.am, and
vyos-router (vyatta-boot-config-loader was kept as a fallback when
initially introducing vyos-boot-config-loader.py).
---
 scripts/init/vyos-router          |   3 -
 scripts/vyatta-boot-config-loader |  79 ------------
 scripts/vyatta-config-loader.pl   | 156 ------------------------
 scripts/vyatta-load-config.pl     | 248 --------------------------------------
 4 files changed, 486 deletions(-)
 delete mode 100755 scripts/vyatta-boot-config-loader
 delete mode 100755 scripts/vyatta-config-loader.pl
 delete mode 100755 scripts/vyatta-load-config.pl

(limited to 'scripts')

diff --git a/scripts/init/vyos-router b/scripts/init/vyos-router
index 2668390..9130307 100755
--- a/scripts/init/vyos-router
+++ b/scripts/init/vyos-router
@@ -100,9 +100,6 @@ load_bootfile ()
       fi
       if [ -x $vyos_libexec_dir/vyos-boot-config-loader.py ]; then
           sg ${GROUP} -c "$vyos_libexec_dir/vyos-boot-config-loader.py $BOOTFILE"
-      else
-          # if not available, fallback to earlier version
-          sg ${GROUP} -c "$vyatta_sbindir/vyatta-boot-config-loader $BOOTFILE"
       fi
     )
 }
diff --git a/scripts/vyatta-boot-config-loader b/scripts/vyatta-boot-config-loader
deleted file mode 100755
index b242b78..0000000
--- a/scripts/vyatta-boot-config-loader
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/bin/bash
-
-BOOT_FILE=$1
-shift
-
-CAPI=/bin/cli-shell-api
-CLOG=/var/log/vyatta/vyatta-config-loader.log
-COMMIT=/opt/vyatta/sbin/my_commit
-COMMIT_LOG=/var/log/vyatta/vyatta-commit.log
-
-do_log () {
-  local level=$1
-  shift
-  logger -t 'boot-config-loader' -p "local0.$level" -- "$*"
-}
-
-do_commit () {
-  # Check if debug is enabled in the kernel command line
-  grep vyos-debug /proc/cmdline > /dev/null
-  if [ $? == 0 ]; then
-    VYOS_DEBUG=$debug $COMMIT "$@" >>$COMMIT_LOG
-  else
-    $COMMIT "$@" >>$COMMIT_LOG
-  fi
-}
-
-trace () {
-  echo "$(date +'%F %T')  $*"
-}
-
-umask 0002
-
-(
-  trace '== begin boot-config-loader'
-  # set up config session
-  SID=$$
-  SENV=$($CAPI getSessionEnv $SID)
-  eval "$SENV"
-  if ! $CAPI setupSession; then
-    do_log err 'Cannot set up configuration session.'
-    trace 'Cannot set up configuration session.'
-    exit 1
-  fi
-
-  # do load
-  trace '-- begin load'
-  if ! $CAPI loadFile $BOOT_FILE; then
-    do_log warn "Failure(s) encountered during load. See $CLOG for details."
-    trace '-- load finished with failure(s)'
-  else
-    trace '-- load finished successfully'
-  fi
-
-  # do commit
-  trace '-- begin commit'
-  ret=0
-  export COMMIT_VIA=boot-config-loader
-  if ! do_commit ; then
-    do_log err 'Commit failed at boot.'
-    trace '-- commit failed'
-    ret=1
-  else
-    trace '-- commit succeeded'
-  fi
-
-  # clean up
-  if ! $CAPI teardownSession; then
-    do_log warn 'Failed to tear down configuration session.'
-    trace '-- teardown failed'
-  else
-    trace '-- teardown succeeded'
-  fi
-  trace '-- exiting'
-  echo $ret > /tmp/vyos-config-status
-  sync
-  exit $ret
-) </dev/null >>$CLOG 2>&1
-
-exit $?
diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl
deleted file mode 100755
index 9e296ad..0000000
--- a/scripts/vyatta-config-loader.pl
+++ /dev/null
@@ -1,156 +0,0 @@
-#!/usr/bin/perl
-
-# Author: An-Cheng Huang <ancheng@vyatta.com>
-# Date: 2007
-# Description: configuration loader
-
-# **** License ****
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# This code was originally developed by Vyatta, Inc.
-# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc.
-# All Rights Reserved.
-# **** End License ****
-
-# Perl script for loading the startup config file.
-# $0: startup config file.
-
-use strict;
-use lib "/opt/vyatta/share/perl5/";
-use Vyatta::ConfigLoad;
-use Sys::Syslog qw(:standard :macros);
-use POSIX qw(strftime);
-
-my $CWRAPPER = '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper';
-my $CONFIG_LOG = '/var/log/vyatta/vyatta-config-loader.log';
-my $COMMIT_CMD  = "$CWRAPPER commit";
-my $CLEANUP_CMD = "$CWRAPPER cleanup";
-my $BEGIN_CMD   = "$CWRAPPER begin";
-my $END_CMD     = "$CWRAPPER end";
-
-umask 0002;
-
-# Set up logging
-openlog("config-loader", "nofail", LOG_LOCAL0);
-
-open(STDIN, '<', "/dev/null")
-    or die "Can't open /dev/null : $!";
-open(STDOUT, '>>', $CONFIG_LOG)
-    or die "Can't open $CONFIG_LOG : $!";
-open(STDERR, '>&STDOUT')
-    or die "Can't redirect stderr: $!";
-
-sub trace {
-    my $str = shift;
-
-    printf "%s %s\n", strftime("%F %T ", localtime), $str;
-}
-
-# get a list of all config statement in the startup config file
-my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true');
-my @all_nodes    = @{$cfg_hier{'set'}};
-
-# empty configuration?
-die "Empty configuration!\n"
-    if (scalar(@all_nodes) == 0);
-
-# set up the config environment
-unless (system($BEGIN_CMD) == 0) {
-    syslog(LOG_WARNING, "Cannot set up configuration environment");
-    die "Cannot set up configuration environment\n";
-}
-
-my $start = time;
-trace "-- begin";
-
-#cmd below is added to debug last set of command ordering
-foreach (@all_nodes) {
-    my ($path_ref, $rank) = @$_;
-    my @pr = @$path_ref;
-
-    if ($pr[0] =~ /^comment$/) {
-        my $ct = 0;
-        my $rel_path;
-        foreach my $rp (@pr[1..$#pr]) {
-            $ct++;
-            my $tmp_path = $rel_path . "/" . $rp;
-            my $node_path = "/opt/vyatta/share/vyatta-cfg/templates/". $tmp_path . "/node.def";
-
-            last if ($rp eq '"');
-            last if ($rp eq '""');
-
-            if (!-e $node_path) {
-
-                #pop this element
-                delete $pr[$ct];
-                last;
-            }
-            $rel_path = $tmp_path;
-        }
-
-        my $comment_cmd = "$CWRAPPER " . join(" ",@pr);
-        `$comment_cmd`;
-        next;
-    }
-
-    my $cmd = 'set ' . join(' ', @pr);
-
-    # Show all commands in log
-    trace $cmd;
-    unless (system("$CWRAPPER $cmd") == 0) {
-        warn "*** %s failed: %d\n", $cmd, $?;
-        syslog(LOG_NOTICE, "[[%s]] failed", $cmd);
-    }
-}
-
-my $commit_start = time;
-trace "commit";
-syslog(LOG_INFO, "Configuration took %d seconds.", $commit_start - $start);
-
-unless (system($COMMIT_CMD) == 0) {
-    warn "*** Commit failed: %d\n", $?;
-    syslog(LOG_WARNING, "Commit failed at boot");
-
-    system($CLEANUP_CMD);
-    system($END_CMD);
-    exit 1;
-}
-
-my $commit_end = time;
-syslog(LOG_INFO, "Commit succeeded took %d seconds.",$commit_end - $commit_start);
-
-# Now process any deactivate nodes
-my @deactivate_nodes = @{$cfg_hier{'deactivate'}};
-if (@deactivate_nodes) {
-    foreach (@deactivate_nodes) {
-        my $cmd = "deactivate " . $_;
-        trace $cmd;
-
-        unless (system("$CWRAPPER $cmd") == 0) {
-            warn "*** %s failed: %d\n", $cmd, $?;
-            syslog(LOG_WARNING, "[[%s]] failed", $cmd);
-            last;
-        }
-    }
-
-    unless (system($COMMIT_CMD) == 0) {
-        warn  "deactivate commit failed: %d\n", $?;
-        syslog(LOG_NOTICE, "Commit deactivate failed at boot");
-        system($CLEANUP_CMD);
-    }
-}
-
-unless (system($END_CMD) == 0) {
-    syslog(LOG_WARNING, "Cannot teardown configuration environment");
-    die "Cannot teardown configuration environment\n";
-}
-trace "done.";
-
-exit 0;
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl
deleted file mode 100755
index d432af9..0000000
--- a/scripts/vyatta-load-config.pl
+++ /dev/null
@@ -1,248 +0,0 @@
-#!/usr/bin/perl
-
-# Author: Vyatta <eng@vyatta.com>
-# Date: 2007
-# Description: Perl script for loading config file at run time.
-
-# **** License ****
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# This code was originally developed by Vyatta, Inc.
-# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc.
-# All Rights Reserved.
-# **** End License ****
-
-# $0: config file.
-
-use strict;
-use lib "/opt/vyatta/share/perl5/";
-use POSIX;
-use IO::Prompt;
-use Getopt::Long;
-use Sys::Syslog qw(:standard :macros);
-use Vyatta::Config;
-use Vyatta::ConfigLoad;
-use Vyatta::Misc qw(get_short_config_path);
-
-$SIG{'INT'} = 'IGNORE';
-
-my $etcdir       = $ENV{vyatta_sysconfdir};
-my $sbindir      = $ENV{vyatta_sbindir};
-my $bootpath     = $etcdir . "/config";
-my $load_file    = $bootpath . "/config.boot";
-my $url_tmp_file = $bootpath . "/config.boot.$$";
-my $vyos_libexec_dir = $ENV{vyos_libexec_dir};
-
-
-#
-# Note: to get merge to work on arbitrary nodes
-# within the configuration multinodes need to be escaped.
-# i.e.:
-# load --merge='load-balancing/wan/interface-health\ eth0'
-#
-# will start loading of the configuration node from:
-#
-# load-balancing/wan/interface-health:eth0
-#
-# Note current loading is limited to first new
-# multinode.
-#
-sub usage {
-    print "Usage: $0 --merge=<root>\n";
-    exit 0;
-}
-
-my $merge;
-GetOptions(
-    "merge:s"              => \$merge,
-    ) or usage();
-
-my $mode = 'local';
-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/ ) {
-        $mode  = 'url';
-        $proto = lc($1);
-        unless( $proto eq 'tftp'  ||
-		$proto eq 'ftp'   ||
-		$proto eq 'http'  ||
-		$proto eq 'https' ||
-		$proto eq 'scp'   ||
-		$proto eq 'sftp'  ) {
-	    die "Invalid url protocol [$proto]\n";
-        }
-    } else {
-        print "Invalid url [$load_file]\n";
-        exit 1;
-    }
-}
-
-if ( $mode eq 'local' and !( $load_file =~ /^\// ) ) {
-    # relative path
-    $load_file = "$bootpath/$load_file";
-}
-
-my $cfg;
-if ( $mode eq 'local' ) {
-    die "Cannot open configuration file $load_file: $!\n"
-	unless open( $cfg, '<', $load_file);
-}
-elsif ( $mode eq 'url' ) {
-    if ( !-f '/usr/bin/curl' ) {
-        print "Package [curl] not installed\n";
-        exit 1;
-    }
-    if ( $proto eq 'http' or $proto eq 'https' ) {
-        #
-        # error codes are send back in html, so 1st try a header
-        # and look for "HTTP/1.1 200 OK" or "HTTP/1.1 301 Moved Permanently"
-        #
-        my $rc = `curl -L -q -I $load_file 2>&1`;
-        if ( $rc =~ /HTTP\/\d+\.?\d\s+(\d+)\s+(.*)$/mi ) {
-            my $rc_code   = $1;
-            my $rc_string = $2;
-            if ( $rc_code == 200 or $rc_code == 301 ) {
-                # good response
-            }
-            else {
-                print "http error: [$rc_code] $rc_string\n";
-                exit 1;
-            }
-        }
-        else {
-            print "Error: $rc\n";
-            exit 1;
-        }
-    }
-    my $rc = system("curl -# -o $url_tmp_file $load_file");
-    if ($proto =~ /^(scp|sftp)$/ && ($rc >> 8) == 51){
-        $load_file =~ m/(?:scp|sftp):\/\/(.*?)\//;
-        my $host = $1;
-        if ($host =~ m/.*@(.*)/) {
-          $host = $1;
-        }
-        my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`;
-        print "The authenticity of host '$host' can't be established.\n";
-        my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`;
-        chomp $fingerprint;
-        print "RSA key fingerprint is $fingerprint.\n";
-        if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) {
-            mkdir "~/.ssh/";
-            open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts") 
-              or die "Cannot open known_hosts: $!";
-            print $known_hosts "$rsa_key\n";
-            close($known_hosts);
-            $rc = system("curl -# -o $url_tmp_file $load_file");
-            print "\n";
-        }
-    }
-    if ($rc) {
-        print "Can not open remote configuration file $load_file\n";
-        exit 1;
-    }
-    die "Cannot open configuration file $load_file: $!\n"
-	unless open( $cfg, '<', $url_tmp_file);
-
-    $load_file = $url_tmp_file;
-}
-
-my $xorp_cfg  = 0;
-my $valid_cfg = 0;
-while (<$cfg>) {
-    if (/\/\*XORP Configuration File, v1.0\*\//) {
-        $xorp_cfg = 1;
-        last;
-    }
-    elsif (/vyatta-config-version/) {
-        $valid_cfg = 1;
-        last;
-    }
-    elsif (/vyos-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("$vyos_libexec_dir/run-config-migration.py $load_file");
-
-# note: "load" is now handled in the backend so only "merge" is actually
-# handled in this script. "merge" hasn't been moved into the backend since
-# the command itself needs to be revisited after mendocino time frame.
-
-# when presenting to users, show shortened /config path
-my $shortened_load_file = get_short_config_path($load_file);
-print "Loading configuration from '$shortened_load_file'...\n";
-
-my $cobj = new Vyatta::Config;
-if (!defined($merge)) {
-  # "load" => use backend through API
-  $cobj->loadFile($load_file);
-} else {
-  # "merge" => handled here
-  my %cfg_hier = Vyatta::ConfigLoad::loadConfigHierarchy($load_file,$merge);
-  if ( scalar( keys %cfg_hier ) == 0 ) {
-    print "The specified file does not contain any configuration.\n";
-    print
-      "Do you want to remove everything in the running configuration? [no] ";
-    my $resp = <STDIN>;
-    if ( !( $resp =~ /^yes$/i ) ) {
-      print "Configuration not loaded\n";
-      exit 1;
-    }
-  }
-
-  my %cfg_diff = Vyatta::ConfigLoad::getConfigDiff(\%cfg_hier);
-  my @set_list    = @{ $cfg_diff{'set'} };
-  foreach (@set_list) {
-    my ( $cmd_ref, $rank ) = @{$_};
-    my @cmd = ( "$sbindir/my_set", @{$cmd_ref} );
-    my $cmd_str = join ' ', @cmd;
-    system("$cmd_str");
-    if ( $? >> 8 ) {
-      $cmd_str =~ s/^$sbindir\/my_//;
-      print "\"$cmd_str\" failed\n";
-    }
-  }
-}
-
-if (!($cobj->sessionChanged())) {
-  print "No configuration changes to commit\n";
-  exit 0;
-}
-
-print ("\n" . (defined($merge) ? 'Merge' : 'Load')
-       . " complete.  Use 'commit' to make changes active.\n");
-exit 0;
-- 
cgit v1.2.3