#!/usr/bin/perl -w
# Script to convert ipsec.conf from format 1.9x to format 2.
# (c) garloff@suse.de, 2/2004, Artistic
use strict;

my $version2_found = 0;
my $configsetup_found = 0;
my $configsetup_oe_found = 0;
while (<>) {
	if (/^ *#/ or $version2_found == 1) {
		print;
		next;
	}
	if (/^ *version *2\.0/) {
		$version2_found = 1;
		print;
		next;
	}
	if (/^ *config *setup/) {
		$configsetup_found = 1;
		print "### Converted to version 2.0 ipsec.conf by openswan %post\n";
		print "version 2.0\n\n";
		print;
		next;
	}
	if($configsetup_found)
	{
	    if(/^[ \t]+OE=off/)
	    {
		$configsetup_oe_found = 1;
		print;
		next;
	    }
	}
	s/^([\t ]*)plutoload( *)=/\t### Commented out by openswan %post\n$1#plutoload$2=/;
	s/^([\t ]*)plutostart( *)=/$1#plutostart$2=/;
	print;
}

if ($version2_found != 1 && $configsetup_oe_found != 1) {
	print "
### Added by openswan %post	
# Switch off Opportunistic Encryption policies -- BEGIN
conn block
	auto=ignore
conn private
	auto=ignore
conn private-or-clear
	auto=ignore
conn clear-or-private
	auto=ignore
conn clear
	auto=ignore
conn packetdefault
	auto=ignore
#conn OEself
#	auto=ignore
# Switch off Opportunistic Encryption -- END\n";
}

