Active Topics

 



Notices


Reply
Thread Tools
Posts: 31 | Thanked: 13 times | Joined on Mar 2008 @ Germany
#1
At home and at university our wlan is secured by openvpn so id like to have it started automatically when i connect to the wlan. So i wrote two little scripts to do that (sure you could also have some shortcuts to start openvpn but this is maybe for a little more comfort). Everytime a interface goes up or down all scripts in /etc/network/if-up.d or if-down.d are started. when you connect to a wlan the ssid is set in the shell variable $ICD_CONNECTION_ID. So this we take to decide which wlan we connected to and easy as that just rename your openvpn config file like the ssid of your wlan (ssid.conf) and with the two scripts it should start when going online and go down when going offline.

add a file (maybe call it ovpnauto) to /etc/network/if-up.d/ and put the following in it:

Code:
#!/bin/sh

OPENVPN=/etc/init.d/openvpn

if [ ! -x $OPENVPN ]; then
  exit 0
fi

if [ -n "$ICD_CONNECTION_ID" ]; then
  CONF=/etc/openvpn/$ICD_CONNECTION_ID.conf
  if [ ! -f $CONF ]; then
    exit 0
  fi
  $OPENVPN start $ICD_CONNECTION_ID
fi
then another on in /etc/network/if-down.d with this code in it:

Code:
#!/bin/sh

OPENVPN=/etc/init.d/openvpn

if [ ! -x $OPENVPN ]; then
  exit 0
fi

if [ $IFACE = "wlan0" ]; then
  $OPENVPN stop
fi
after that the two files must be set executable by doing a chmod 700 $filename on them.

Now when you connect to your wlan if there is a matching openvpn config it will be started (matching to the ssid)
 

The Following 7 Users Say Thank You to Eris For This Useful Post:
Posts: 3,841 | Thanked: 1,079 times | Joined on Nov 2006
#2
I haven't tried your method yet, but that looks promising.
__________________
N800/OS2007|N900/Maemo5
-- Metalayer-crawler delenda est.
-- Current state: Fed up with everything MeeGo.
 
Posts: 207 | Thanked: 119 times | Joined on Nov 2009 @ Pittsburgh, PA, USA
#3
I little bit modified openvpn package and add possibility to choose connection types and network limitations for each .conf
I put additional parameters in file Name.connections (where is Name same to Name.conf file in /etc/openvpn). It is look like:
================================
#Allowed connection types.
#CONNECTION_TYPE=GPRS
#CONNECTION_TYPE=WLAN_INFRA
#CONNECTION_TYPE=ANY #(default)
#CONNECTION_TYPE=GPRS WLAN_INFRA
#DENY_CONNECTION_TYPES=XXXX
#Allowed connection types.
#CONNECTION_NAME="AT&T Internet" PITT
#CONNECTION_NAME=PITT
#CONNECTION_NAME=ANY #(default)

DENY_CONNECTION_NAMES=myhome
====================================

If it is interesting I could build new openvpn package with modifications (on weekend only).
 
Posts: 306 | Thanked: 106 times | Joined on Feb 2010
#4
Originally Posted by mikhmv View Post
If it is interesting I could build new openvpn package with modifications (on weekend only).
Yes, this will be quite useful.
__________________
------------------------------------------------------------------
Voice choppy on sip calls
Please vote for bug number 10388
 
Reply


 
Forum Jump


All times are GMT. The time now is 02:27.