#!/bin/sh
echo "VPN Connection Up"

usi set rcms.vpn_status Connected

date=$(date +%Y-%m-%d)
time=$(date +%H:%M:%S)
usi set rcms.last_vpn_connect_time $date\ $time

VPN_VIRTUAL_IP=$(ifconfig tun9 | sed -nr 's/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
if [ -z "$VPN_VIRTUAL_IP" ]; then
    usi set rcms.vpn_virtualip ""
else
    usi set rcms.vpn_virtualip $VPN_VIRTUAL_IP
fi

VPN_SUBNET=$(usi get rcms.vpn_subnettemp)
if [ -z "$VPN_SUBNET" ]; then
    usi set rcms.vpn_subnet Null
else
    usi set rcms.vpn_subnet $VPN_SUBNET
fi

#adding ACCEPT FORWARD for tun9,fix problem of subnet unreachable.
iptables -I FORWARD -i tun9 -j ACCEPT

service_ros route restart
service_ros policy_route restart
#rmsg rcms cmd start_vpn_portmapping rvpn_ip $VPN_VIRTUAL_IP
