|
Lines 12-18
Link Here
|
| 12 |
VPNCONF="${VPNDIR}/${VPN}.conf" |
12 |
VPNCONF="${VPNDIR}/${VPN}.conf" |
| 13 |
|
13 |
|
| 14 |
depend() { |
14 |
depend() { |
| 15 |
need localmount net |
15 |
# grep -q "^[ ]*dev[ ].*tap0" "${VPNCONF}" |
|
|
16 |
# if [ $? -eq 0 ] ; then |
| 17 |
# need localmount net.tap0 |
| 18 |
# else |
| 19 |
# need localmount net |
| 20 |
# fi |
| 16 |
use dns |
21 |
use dns |
| 17 |
after bootmisc |
22 |
after bootmisc |
| 18 |
} |
23 |
} |
|
Lines 66-89
Link Here
|
| 66 |
|
71 |
|
| 67 |
checkconfig || return 1 |
72 |
checkconfig || return 1 |
| 68 |
|
73 |
|
| 69 |
local args="" reenter=${RE_ENTER:-no} |
74 |
local args=("") |
|
|
75 |
local reenter=${RE_ENTER:-no} |
| 70 |
# If the config file does not specify the cd option, we do |
76 |
# If the config file does not specify the cd option, we do |
| 71 |
# But if we specify it, we override the config option which we do not want |
77 |
# But if we specify it, we override the config option which we do not want |
| 72 |
if ! grep -q "^[ ]*cd[ ].*" "${VPNCONF}" ; then |
78 |
if ! grep -q "^[ ]*cd[ ].*" "${VPNCONF}" ; then |
| 73 |
args="${args} --cd ${VPNDIR}" |
79 |
args+=( --cd ${VPNDIR}) |
| 74 |
fi |
80 |
fi |
| 75 |
|
|
|
| 76 |
# We mark the service as inactive and then start it. |
81 |
# We mark the service as inactive and then start it. |
| 77 |
# When we get an authenticated packet from the peer then we run our script |
82 |
# When we get an authenticated packet from the peer then we run our script |
| 78 |
# which configures our DNS if any and marks us as up. |
83 |
# which configures our DNS if any and marks us as up. |
| 79 |
if [ "${DETECT_CLIENT:-yes}" = "yes" ] && \ |
84 |
if [ "${DETECT_CLIENT:-yes}" = "yes" ] && \ |
| 80 |
grep -q "^[ ]*remote[ ].*" "${VPNCONF}" ; then |
85 |
grep -q "^[ ]*remote[ ].*" "${VPNCONF}" ; then |
| 81 |
reenter="yes" |
86 |
reener="yes" |
| 82 |
args="${args} --up-delay --up-restart" |
87 |
args+=(--up-delay --up-restart) |
| 83 |
args="${args} --script-security 2" |
|
|
| 84 |
args="${args} --up /etc/openvpn/up.sh" |
| 85 |
args="${args} --down-pre --down /etc/openvpn/down.sh" |
| 86 |
|
| 87 |
# Warn about setting scripts as we override them |
88 |
# Warn about setting scripts as we override them |
| 88 |
if grep -Eq "^[ ]*(up|down)[ ].*" "${VPNCONF}" ; then |
89 |
if grep -Eq "^[ ]*(up|down)[ ].*" "${VPNCONF}" ; then |
| 89 |
ewarn "WARNING: You have defined your own up/down scripts" |
90 |
ewarn "WARNING: You have defined your own up/down scripts" |
|
Lines 102-118
Link Here
|
| 102 |
fi |
103 |
fi |
| 103 |
else |
104 |
else |
| 104 |
# So we're a server. Run as openvpn unless otherwise specified |
105 |
# So we're a server. Run as openvpn unless otherwise specified |
| 105 |
grep -q "^[ ]*user[ ].*" "${VPNCONF}" || args="${args} --user openvpn" |
106 |
grep -q "^[ ]*user[ ].*" "${VPNCONF}" || args+=( --user openvpn) |
| 106 |
grep -q "^[ ]*group[ ].*" "${VPNCONF}" || args="${args} --group openvpn" |
107 |
grep -q "^[ ]*group[ ].*" "${VPNCONF}" || args+=( --group openvpn) |
| 107 |
fi |
108 |
fi |
| 108 |
|
109 |
|
|
|
110 |
#common settings: |
| 111 |
args+=(--script-security 2) |
| 112 |
args+=(--up "/etc/openvpn/up.sh ${SVCNAME}") |
| 113 |
args+=(--down-pre --down "/etc/openvpn/down.sh ${SVCNAME}") |
| 114 |
|
| 109 |
# Ensure that our scripts get the PEER_DNS variable |
115 |
# Ensure that our scripts get the PEER_DNS variable |
| 110 |
[ -n "${PEER_DNS}" ] && args="${args} --setenv PEER_DNS ${PEER_DNS}" |
116 |
[ -n "${PEER_DNS}" ] && args+=( --setenv PEER_DNS ${PEER_DNS}) |
| 111 |
|
117 |
|
| 112 |
[ "${reenter}" = "yes" ] && mark_service_inactive "${SVCNAME}" |
118 |
[ "${reenter}" = "yes" ] && mark_service_inactive "${SVCNAME}" |
| 113 |
start-stop-daemon --start --exec /usr/sbin/openvpn --pidfile "${VPNPID}" \ |
119 |
start-stop-daemon --start --exec /usr/sbin/openvpn --pidfile "${VPNPID}" \ |
| 114 |
-- --config "${VPNCONF}" --writepid "${VPNPID}" --daemon \ |
120 |
-- --config "${VPNCONF}" --writepid "${VPNPID}" --daemon \ |
| 115 |
--setenv SVCNAME "${SVCNAME}" ${args} |
121 |
--setenv SVCNAME "${SVCNAME}" "${args[@]}" |
| 116 |
eend $? "Check your logs to see why startup failed" |
122 |
eend $? "Check your logs to see why startup failed" |
| 117 |
} |
123 |
} |
| 118 |
|
124 |
|
|
Lines 127-132
Link Here
|
| 127 |
ebegin "Stopping ${SVCNAME}" |
133 |
ebegin "Stopping ${SVCNAME}" |
| 128 |
start-stop-daemon --stop --quiet \ |
134 |
start-stop-daemon --stop --quiet \ |
| 129 |
--exec /usr/sbin/openvpn --pidfile "${VPNPID}" |
135 |
--exec /usr/sbin/openvpn --pidfile "${VPNPID}" |
|
|
136 |
#remove device from bridge |
| 137 |
IFACE=$(sed -n 's/[[:space:]]*dev[[:space:]]*//p' ${VPNCONF}) |
| 138 |
#IFACE="$( awk '/^\ *dev/ { print $2 }' ${VPNCONF} )" |
| 139 |
BRIDGE=$(ls -l /sys/class/net/${IFACE}/brport/bridge 2>/dev/null|sed 's/.*\///' ) |
| 140 |
if [ "${BRIDGE}" != " "] ; then |
| 141 |
einfo "BRIDGE : $BRIDGE IFACE: $IFACE" |
| 142 |
/sbin/brctl delif ${BRIDGE} ${IFACE} |
| 143 |
ifconfig ${IFACE} 0.0.0.0 |
| 144 |
fi |
| 130 |
eend $? |
145 |
eend $? |
| 131 |
} |
146 |
} |
| 132 |
|
147 |
|