05fa94747e928fe353a490d2bf91184d1ff8b311
[grml-network.git] / sbin / grml-vpnc-tugraz
1 #!/bin/bash
2 # Filename:      grml-vpnc-tugraz
3 # Purpose:       connect via vpnc in VC-Graz/TU Graz (www.vc-graz.ac.at / www.tugraz.at)
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 # Documentation:
10 # http://www.zid.tugraz.at/ki/netz/extern/vpn/
11
12 export LANG=C
13 export LC_ALL=C
14
15 if [ "$UID" != 0 ];  then
16   sudo $0
17   exit
18 fi
19
20 typeofservice() {
21 NETWORK=$(dialog --stdout --clear --title "foobar" --menu \
22 "This script is a submenu of grml-network to set up an internet connection
23
24 Notice if you want to connect to WLAN at TU Graz:
25 Make sure you have a connection to the access point and an ip-address.
26 Run 'iwconfig \$DEVICE essid tug ; dhclient \$DEVICE'." 0 0 0 \
27 "WLAN"   "Connect via WLAN to TU Graz network" \
28 "VCGraz" "Connect to VC-Graz (not yet tested - use grml-pptp-vcgraz!)" \
29 "External" "External connection (not yet tested!)" \
30 "Exit"   "Exit this program")
31
32 retval=$?
33
34 case $retval in
35   0)
36         if [ $NETWORK == WLAN ]; then
37          GATEWAY=129.27.200.1
38          # GATEWAY=172.27.12.2
39          ACCOUNT='Account information - your TUGOnline username'
40         fi
41
42         if [ $NETWORK == VCGraz ]; then
43          GATEWAY=10.0.0.1
44          ACCOUNT='Account information - your account number'
45         fi
46
47         if [ $NETWORK == External ]; then
48          GATEWAY=129.27.200.1
49          ACCOUNT='Account information - account number'
50         fi
51         ;;
52   1)
53         echo "Cancel pressed." ; exit
54         ;;
55   255)
56         echo "ESC pressed." ; exit
57         ;;
58 esac
59 }
60
61 runit(){
62 echo "# vpnc at $NETWORK" > /etc/vpnc/vpnctugraz.conf
63 echo "
64 Debug 0
65 IKE DH Group dh2
66 Perfect Forward Secrecy dh2
67 IPSec gateway $GATEWAY
68 IPSec ID default
69 IPSec secret default
70 # Rekeying interval 21600
71 Xauth username $ACCOUNTNAME
72 Xauth password $PASSWORD
73
74 " >> /etc/vpnc/vpnctugraz.conf
75
76 echo -e "#!/bin/sh\nLANG=C\n" > /etc/init.d/vpnctug
77 cat >> /etc/init.d/vpnctug << "EOF"
78 case "$1" in
79   start)
80     echo "Starting vpnc"
81 #    route del default
82 #    vpnc /etc/vpnc/vpnctugraz.conf
83     vpnc-connect /etc/vpnc/vpnctugraz.conf
84 #    route add default dev tun0
85     ;;
86
87   stop)
88     echo "Stopping vpnc"
89     /usr/sbin/vpnc-disconnect
90     killall -HUP vpnc
91     ;;
92
93   *)
94     echo "Usage: /etc/init.d/vpnctug {start|stop}" >&2
95     ;;
96
97 esac
98
99 exit 0
100 EOF
101
102 chmod 600 /etc/vpnc/vpnctugraz.conf
103 chmod +x /etc/init.d/vpnctug
104 /etc/init.d/vpnctug start
105 }
106
107 typeofservice
108 if [ -z "$ACCOUNTNAME" ] || [ -z "$PASSWORD" ] ; then
109   ACCOUNTNAME=$(dialog --stdout --title "vpnc in $NETWORK" --inputbox "${ACCOUNT}:" 0 0) || exit 0
110   PASSWORD=$(dialog --stdout --title "vpnc in $NETWORK" --passwordbox "Account password (hidden typing)" 0 40) || exit 0
111   [ -z "$ACCOUNTNAME" ] && exit 1
112   [ -z "$PASSWORD" ] && exit 1
113   runit
114 else
115   runit
116 fi
117
118 ## END OF FILE #################################################################