#!/usr/bin/perl

# Strongswan user connect/disconnect handler script
# Executes each time user connects/disconnects

use lib '/etc/openvpn';
use File::Basename;
use feature qw(switch);

use NVPNLog;
use NVPNApi;

nvpn_log_init;

system("env > /tmp/pluto");

my ($username, $internalip, $externalip, $mode) = ($ENV{'PLUTO_XAUTH_ID'}, $ENV{'PLUTO_PEER_CLIENT'}, $ENV{'PLUTO_ME'}, $ENV{'PLUTO_VERB'});

# striping netmask from internal ip
$internalip =~ s/\/.*//g;

given ($mode)
{
	when ("up-client") {
		nvpn_handle_connect($username, $internalip, $externalip, "1.2.3.4", "strongswan");
	}

	when ("down-client") {
		nvpn_handle_disconnect($username, $internalip, $externalip, "strongswan");
	}
}

nvpn_log_close;

