Skip to content

Commit

Permalink
add other args option to pass directly to openvpn
Browse files Browse the repository at this point in the history
  • Loading branch information
StudioEtrange committed Apr 16, 2020
1 parent c26f35b commit 6e39033
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Running the following on your docker host should give you the correct network:

**NOTE**: if you don't use the `-v` to configure your VPN, then you'll have to
make sure that `redirect-gateway def1` is set, otherwise routing may not work.
Or you could use -o option to pass it : `-o '--redirect-gateway def1'`

**NOTE 2**: if you have a port you want to make available, you have to add the
docker `-p` option to the VPN container. The network stack will be reused by
Expand All @@ -115,6 +116,10 @@ the second container (that's what `--net=container:vpn` does).
optional arg: [port] to use, instead of default
-m '<mss>' Maximum Segment Size <mss>
required arg: '<mss>'
-o '<args>' Allow to pass any arguments directly to openvpn
required arg: '<args>'
<args> could be any string matching openvpn arguments
i.e '--arg1 value --arg2 value'
-p '<port>[;protocol]' Forward port <port>
required arg: '<port>'
optional arg: [protocol] to use instead of default (tcp)
Expand All @@ -141,6 +146,7 @@ ENVIRONMENT VARIABLES
* `DNS` - As above, Use the VPN provider's DNS resolvers
* `FIREWALL` - As above, setup firewall to disallow net access w/o the VPN
* `MSS` - As above, set Maximum Segment Size
* `OTHER_ARGS` - As above, pass arguments directly to openvpn
* `ROUTE6` - As above, add a route to allow replies to your internal network
* `ROUTE` - As above, add a route to allow replies to your private network
* `TZ` - Set a timezone, IE `EST5EDT`
Expand Down
9 changes: 7 additions & 2 deletions openvpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ Options (fields in '[]' are optional, '<>' are required):
optional arg: [port] to use, instead of default
-m '<mss>' Maximum Segment Size <mss>
required arg: '<mss>'
-o '<args>' Allow to pass any arguments directly to openvpn
required arg: '<args>'
<args> could be any string matching openvpn arguments
i.e '--arg1 value --arg2 value'
-p '<port>[;protocol]' Forward port <port>
required arg: '<port>'
optional arg: [protocol] to use instead of default (tcp)
Expand Down Expand Up @@ -273,13 +277,14 @@ while read i; do
eval vpnportforward $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $i)
done < <(env | awk '/^VPNPORT[0-9=_]/ {sub (/^[^=]*=/, "", $0); print}')

while getopts ":hc:df:m:p:R:r:v:" opt; do
while getopts ":hc:df:m:o:p:R:r:v:" opt; do
case "$opt" in
h) usage ;;
c) cert_auth "$OPTARG" ;;
d) dns ;;
f) firewall "$OPTARG"; touch $route $route6 ;;
m) MSS="$OPTARG" ;;
o) OTHER_ARGS="$OPTARG" ;;
p) eval vpnportforward $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $OPTARG) ;;
R) return_route6 "$OPTARG" ;;
r) return_route "$OPTARG" ;;
Expand All @@ -303,6 +308,6 @@ else
[[ -e $conf ]] || { echo "ERROR: VPN not configured!"; sleep 120; }
[[ -e $cert ]] || grep -Eq '^ *(<ca>|ca +)' $conf ||
{ echo "ERROR: VPN CA cert missing!"; sleep 120; }
exec sg vpn -c "openvpn --cd $dir --config $conf \
exec sg vpn -c "openvpn --cd $dir --config $conf ${OTHER_ARGS:-} \
${MSS:+--fragment $MSS --mssfix}"
fi

0 comments on commit 6e39033

Please sign in to comment.