#! /usr/bin/perl

# Starting Mendocino, content-inspection provided the ability to specify
# directions in which inspection is to be enabled. Previously, inspection
# was enabled in all directions; to preserve the behavior from before, we
# need to add 'inspect-all enable' under content-inspection

use strict;
use warnings;

use lib "/opt/vyatta/share/perl5/";
use XorpConfigParser;
use File::Copy;

my $orig_cfg = shift;
exit 1 unless $orig_cfg;

my $xcp = new XorpConfigParser();
$xcp->parse($orig_cfg);

my $ci = $xcp->get_node(['content-inspection']);
exit 0 unless $ci; # content-inspection not configured

# add 'inspect-all enable' under content-inspection
my $loc = $xcp->create_node(['content-inspection', 'inspect-all', 'enable']);
die "Unable to add 'inspect-all enable' under content-inspection\n" unless $loc;

my $tmpname = "/tmp/vyatta_migrate_content_inspection.$$";
open (my $tmp, '>', $tmpname)
    or die "Can't open: $tmpname: $!";

select $tmp;
$xcp->output(0);
select STDOUT;
close $tmp;

move($tmpname, $orig_cfg)
    or die "Move $tmpname to $orig_cfg failed: $!";

exit 0;
