source: npl/internetserver/openvpn_conf/root/etc/openvpn/learn-address.sh @ 5a444e8

Last change on this file since 5a444e8 was 5a444e8, checked in by Edwin Eefting <edwin@datux.nl>, 6 years ago

added openvpn certificate based firewalling

  • Property mode set to 100755
File size: 855 bytes
Line 
1#!/bin/bash
2
3# Openvpn iptables rules based on certificate name.
4# (C)2018 SYN-3 edwin@datux.nl
5
6OPERATION=$1
7IP=$2
8CN=$3
9
10CHAIN="openvpn_$IP"
11
12log()
13{
14 logger -t learn-address "$1"
15}
16
17allow_tcp()
18{
19    log "Allowing tcp to $1 port $2"
20    iptables -I $CHAIN -d $1 -p tcp --dport $2 -jACCEPT
21}
22
23allow_udp()
24{
25    log "Allowing udp to $1 port $2"
26    iptables -I $CHAIN -d $1 -p udp --dport $2 -jACCEPT
27}
28
29# always cleanup first (in case of openvpn issues/restarts)
30log "Deleting $IP"
31iptables -D FORWARD -s $IP -j $CHAIN
32iptables -F $CHAIN
33iptables -X $CHAIN
34
35
36if [ "$OPERATION" == "add" ] || [ "$OPERATION" == "update" ]; then
37    # add chain
38    log "Adding $IP for $CN"
39    iptables -N $CHAIN
40    iptables -I FORWARD -s $IP -j $CHAIN
41
42    # add rules
43    if [ -e /etc/openvpn/rules/$CN ]; then
44        source /etc/openvpn/rules/$CN
45    fi
46
47fi
48
49
50exit 0
Note: See TracBrowser for help on using the repository browser.