Merge remote-tracking branch 'origin/github/pr/45'
[grml.org.git] / scripts / grml-vpnc-tugraz
1 #!/bin/sh
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 # Latest change: Tue Mar 28 10:02:46 CEST 2006 [mika]
8 ################################################################################
9
10 # Documentation:
11 # http://www.zid.tugraz.at/ki/netz/extern/vpn/
12
13 LANG=C
14 LC_ALL=C
15
16 if [ "$UID" != 0 ];  then
17   sudo $0
18   exit
19 fi
20
21 function typeofservice() {
22 NETWORK=$(dialog --stdout --clear --title "foobar" --menu \
23 "This script is a submenu of grml-network to set up an internet connection
24
25 Notice if you want to connect to WLAN at TU Graz:
26 Make sure you have a connection to the access point and an ip-address.
27 Run 'iwconfig \$DEVICE essid tug ; dhclient \$DEVICE'." 0 0 0 \
28 "WLAN"   "Connect via WLAN to TU Graz network" \
29 "VCGraz" "Connect to VC-Graz (not yet tested - use grml-pptp-vcgraz!)" \
30 "External" "External connection (not yet tested!)" \
31 "Exit"   "Exit this program")
32
33 retval=$?
34
35 case $retval in
36   0)
37         if [ $NETWORK == WLAN ]; then
38          GATEWAY=129.27.200.1
39          # GATEWAY=172.27.12.2
40          ACCOUNT='Account information - your TUGOnline username'
41         fi
42
43         if [ $NETWORK == VCGraz ]; then
44          GATEWAY=10.0.0.1
45          ACCOUNT='Account information - your account number'
46         fi
47
48         if [ $NETWORK == External ]; then
49          GATEWAY=129.27.200.1
50          ACCOUNT='Account information - account number'
51         fi
52         ;;
53   1)
54         echo "Cancel pressed." ; exit
55         ;;
56   255)
57         echo "ESC pressed." ; exit
58         ;;
59 esac
60 }
61
62 runit(){
63 echo "# vpnc at $NETWORK" > /etc/vpnc/vpnctugraz.conf
64 echo "
65 Debug 0
66 IKE DH Group dh2
67 Perfect Forward Secrecy dh2
68 IPSec gateway $GATEWAY
69 IPSec ID default
70 IPSec secret default
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 #################################################################