Project

General

Profile

Download (1.99 KB) Statistics
| Branch: | Tag: | Revision:
1 5b4ee05e Ermal
#!/bin/sh
2 ac24dc24 Renato Botelho
#
3
# openvpn.attributes.sh
4
#
5
# part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
# Copyright (c) 2004-2013 BSD Perimeter
7
# Copyright (c) 2013-2016 Electric Sheep Fencing
8 0284d79e jim-p
# Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9 ac24dc24 Renato Botelho
# All rights reserved.
10
#
11 b12ea3fb Renato Botelho
# Licensed under the Apache License, Version 2.0 (the "License");
12
# you may not use this file except in compliance with the License.
13
# You may obtain a copy of the License at
14 ac24dc24 Renato Botelho
#
15 b12ea3fb Renato Botelho
# http://www.apache.org/licenses/LICENSE-2.0
16 ac24dc24 Renato Botelho
#
17 b12ea3fb Renato Botelho
# Unless required by applicable law or agreed to in writing, software
18
# distributed under the License is distributed on an "AS IS" BASIS,
19
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
# See the License for the specific language governing permissions and
21
# limitations under the License.
22 5b4ee05e Ermal
23 ae472dc1 Shawn Bruce
24
lockfile="/tmp/ovpn_${dev}_${username}_${trusted_port}.lock"
25
rulesfile="/tmp/ovpn_${dev}_${username}_${trusted_port}.rules"
26
anchorname="openvpn/${dev}_${username}_${trusted_port}"
27
28 5b4ee05e Ermal
if [ "$script_type" = "client-connect" ]; then
29 ae472dc1 Shawn Bruce
	i=1
30
	while [ -f "${lockfile}" ]; do
31
		if [ $i -ge 30 ]; then
32
			/bin/echo "Timeout while waiting for lockfile"
33
			exit 1
34
		fi
35
36
		/bin/sleep 1
37
		i=$(( i + 1 ))
38
	done
39
	/usr/bin/touch "${lockfile}"
40
41
	/bin/cat "${rulesfile}" | /usr/bin/sed "s/{clientip}/${ifconfig_pool_remote_ip}/g" > "${rulesfile}.tmp" && /bin/mv "${rulesfile}.tmp" "${rulesfile}"
42
	/sbin/pfctl -a "openvpn/${dev}_${username}_${trusted_port}" -f "${rulesfile}"
43
	/bin/rm "${rulesfile}"
44
45 5b4ee05e Ermal
	if [ -f /tmp/$common_name ]; then
46
		/bin/cat /tmp/$common_name > $1
47
		/bin/rm /tmp/$common_name
48
	fi
49 ae472dc1 Shawn Bruce
50
	/bin/rm "${lockfile}"
51 5b4ee05e Ermal
elif [ "$script_type" = "client-disconnect" ]; then
52 ae472dc1 Shawn Bruce
	i=1
53
	while [ -f "${lockfile}" ]; do
54
		if [ $i -ge 30 ]; then
55
			/bin/echo "Timeout while waiting for lockfile"
56
			exit 1
57
		fi
58
59
		/bin/sleep 1
60
		i=$(( i + 1 ))
61
	done
62
	/usr/bin/touch "${lockfile}"
63
64
	command="/sbin/pfctl -a '${anchorname}' -F rules"
65 7d61beba Phil Davis
	eval $command
66 5b4ee05e Ermal
	/sbin/pfctl -k $ifconfig_pool_remote_ip
67
	/sbin/pfctl -K $ifconfig_pool_remote_ip
68 ae472dc1 Shawn Bruce
69
	/bin/rm "${lockfile}"
70 5b4ee05e Ermal
fi
71
72
exit 0