summaryrefslogtreecommitdiff
path: root/scripts/ip-up
blob: a8461c235f77c9bcce19b47bd84385a91aa4a729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# /etc/ppp/ip-up
#
# When the ppp link comes up, this script is called with the following
# parameters
#       $1      the interface name used by pppd (e.g. ppp3)
#       $2      the tty device name
#       $3      the tty device speed
#       $4      the local IP address for the interface
#       $5      the remote IP address
#       $6      the parameter specified by the 'ipparam' option to pppd

# Script found here: https://gist.github.com/blt04/6093918
# Modified by BSS 2017-09-09 to fit my needs

# Available variables:
# $SERVER - the VPN server address

#
function ip_up_post () {
  case $SERVER in
    #  "NDN MGMT KAS"
    "dk-kas-mfw.nordu.net" )
      SERVERNAME="NDN MGMT KAS"
      ;;
    #  "NDN MGMT UNI"
    "dk-uni-mfw.nordu.net" )
      SERVERNAME="NDN MGMT UNI"
      ;;
    #  "NDN MGMT FRE"
    "se-fre-mfw.nordu.net" )
      SERVERNAME="NDN MGMT FRE"
      ;;
    #  "NORDUnet VPN TUG"
    109.105.104.2 )
      SERVERNAME="NORDUnet VPN TUG"
      /sbin/route -n add 109.105.96.0/19    -interface $IFNAME  # NDN Public
      /sbin/route -n add 193.10.0.0/15      -interface $IFNAME  # SUNET Public
      ;;
    #  "NDN MGMT ORE"
    "dk-ore-mfw.nordu.net" )
      SERVERNAME="NDN MGMT ORE"
      ;;
    #  "NDN MGMT TUG"
    "se-tug-mfw.nordu.net" )
      SERVERNAME="NDN MGMT TUG"
      ;;
    #  "NORDUnet VPN Øre"
    109.105.99.180 )
      SERVERNAME="NORDUnet VPN Øre"
      /sbin/route -n add 109.105.110.128/26 -interface $IFNAME  # VMWare Kaltura Jupiter
      /sbin/route -n add 109.105.112.224/27 -interface $IFNAME  # Zoom Project
      /sbin/route -n add 109.105.113.128/28 -interface $IFNAME  # dk-ore-sx-01 DC
      /sbin/route -n add 109.105.113.144/28 -interface $IFNAME  # dk-uni-sx-01 DC
      /sbin/route -n add 109.105.113.208/28 -interface $IFNAME  # SBC Unused
      /sbin/route -n add 109.105.113.224/27 -interface $IFNAME  # VCONF MCU
      /sbin/route -n add 109.105.116.0/28   -interface $IFNAME  # ndn-dk-internal-lab Customer Network
      /sbin/route -n add 109.105.116.16/28  -interface $IFNAME  # ndn-dk-customer_wayf Customer Network
      /sbin/route -n add 109.105.116.32/28  -interface $IFNAME  # ndn-dk-customer_sunet Customer Network
      /sbin/route -n add 109.105.116.48/28  -interface $IFNAME  # ndn-dk-customer_uninett Customer Network
      /sbin/route -n add 109.105.116.64/28  -interface $IFNAME  # ndn-dk-customer_funet Customer Network
      /sbin/route -n add 109.105.116.80/28  -interface $IFNAME  # ndn-dk-customer_deic Customer Network
      /sbin/route -n add 109.105.116.96/28  -interface $IFNAME  # ndn-dk-customer_rhnet Customer Network
      /sbin/route -n add 109.105.116.112/28 -interface $IFNAME  # ndn-dk-customer_geant Customer Network
      /sbin/route -n add 109.105.116.128/28 -interface $IFNAME  # ndn-dk-cumstomer_media Customer Network
      /sbin/route -n add 10.96.0.0/23       -interface $IFNAME  # Panopto RFC1918
      /sbin/route -n add 10.96.2.0/23       -interface $IFNAME  # MediaSite RFC1918
      /sbin/route -n add 10.96.4.0/23       -interface $IFNAME  # Kaltura RFC1918
      /sbin/route -n add 185.174.116.0/24   -interface $IFNAME  # Zoom servers
      /sbin/route -n add 185.174.117.0/24   -interface $IFNAME  # Zoom servers
      /sbin/route -n add 172.29.10.0/24     -interface $IFNAME  # NTNX-2 Prism central UNI-ORE RFC1918
      /sbin/route -n add 172.29.11.0/24     -interface $IFNAME  # NTNX-2 Management UNI-ORE Nyt cluster RFC1918
      ;;
    #  "NORDUnet VPN KAS"
    109.105.106.4 )
      SERVERNAME="NORDUnet VPN KAS"
      /sbin/route -n add 109.105.96.0/19    -interface $IFNAME  # NDN Public
      /sbin/route -n add 193.10.0.0/15      -interface $IFNAME  # NDN Public #2
      ;;
  esac
  # If you don't want a dialog displayed with a confimation that the script have been run, then comment-out this next line.
  osascript -e "display dialog \"Created routes for $SERVER ($SERVERNAME) on $IFNAME\" with title \"VPN Info\" buttons {\"OK\"} default button 1"
}

# Find the current VPN connection and call ip_up_post
SERVICES=$(echo "list State:/Network/Service/[^/]+/PPP" | /usr/sbin/scutil | /usr/bin/cut -c 16- | /usr/bin/cut -d / -f 1-4)
for SERVICE in $SERVICES
do
  if [ "$(echo show $SERVICE/PPP | /usr/sbin/scutil | grep InterfaceName | /usr/bin/cut -c 19-)" == "$IFNAME" ]; then
    SERVER=$(echo show $SERVICE/PPP | /usr/sbin/scutil | grep CommRemoteAddress | /usr/bin/cut -c 23-)
    ip_up_post
  fi
done