Skip to content

Commit

Permalink
removed python code, use only bash
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasLohr committed Sep 12, 2018
1 parent c3e9ea5 commit 110b86e
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 253 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ RUN mkdir -p /tmp/f5fpc && \

ADD ./files/opt/* /opt/

CMD ["/opt/idle.sh"]

32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ The docker image allows two operating modes:
* Install Docker. **Important:** Do **not** use the packages provided by your
distribution packages sources.
Use the officical resources from docker: https://docs.docker.com/engine/installation/.
* If you want to use the gateway mode: Install required python packages:
```
pip install -r requirements.txt
```


### Mac

Expand All @@ -27,20 +24,15 @@ The docker image allows two operating modes:

## Start F5 VPN client

### VPN client mode
### VPN client mode (quick)

You don't need to clone this repository.
Just start the Docker container with the following command:
```
docker run --name f5fpc --net host -it --rm --privileged matthiaslohr/f5fpc /bin/bash
docker run --name f5fpc-vpn --net host -it --rm --privileged matthiaslohr/f5fpc /opt/connect.sh
```

Start the VPN client and connect to your VPN server with
```
f5fpc -s
```

Status check:
You can check status with:
```
f5fpc -i
```
Expand All @@ -51,6 +43,16 @@ f5fpc -o
```


### VPN client mode (helper script)

Clone this repository to your favourite place and ```cd``` into the directory.

Run
```
./f5fpc-vpn.sh client
```


### Gateway mode

There's a wrapper script (```f5fpy-client.py```) which helps to set up
Expand All @@ -59,16 +61,16 @@ Therefore for this mode you need to clone this repository and ```cd``` to it.

Simply run:
```
./f5fpc-client.py <VPN_HOST> <USER>
./f5fpc-vpn.sh gateway
```

Auto route setup for connecting to a VPN network which uses the 10.0.0.0/8 IP range (needs root add/remove routes):
```
sudo ./f5fpc-client.py <VPN_HOST> <USER> -n 10.0.0.0/8
sudo ./f5fpc-vpn.sh -n 10.0.0.0/8
```

For more information and options see
```
./f5fpc-client.py -h
./f5fpc-vpn.sh -h
```

157 changes: 0 additions & 157 deletions f5fpc-client.py

This file was deleted.

139 changes: 139 additions & 0 deletions f5fpc-vpn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

CONTAINER_NAME="f5fpc-vpn"
F5FPC_ARGS=""
keep_running=1

show_help() {
cat << EOF
Usage: $0 <MODE> [<PARAMETERS...>]
Supported modes:
- client
- gateway
Supported parameters:
-h --help Show this help text
EOF
}

observe_f5fpc() {
last_result=-1
while [ $keep_running ] ; do
output=`docker exec "$CONTAINER_NAME" /usr/local/bin/f5fpc -i`
result=$?
case $result in
0) # Everything seems to be ok
;;
1)
if [ "$last_result" != "1" ] ; then
echo "Session initialized"
fi
;;
2)
if [ "$last_result" != "2" ] ; then
echo "User login in progress"
fi
;;
3)
if [ "$last_result" != "3" ] ; then
echo "Waiting..."
fi
;;
5)
if [ "$last_result" != "5" ] ; then
echo "Connection established successfully"
fi
;;
85) # client not connected
exit
;;
*)
echo "Unknown result code: $result"
echo "Please create an issue with this code here:"
echo "https://github.com/MatthiasLohr/docker-f5fpc/issues/new"
echo ""
echo "Additional information:"
echo "$output"
;;
esac
last_result="$result"
done
}

start_client() {
docker run -d --rm --privileged \
--name "$CONTAINER_NAME" \
--net host \
matthiaslohr/f5fpc \
/opt/idle.sh > /dev/null
if [ "$?" != 0 ] ; then
echo "Error starting docker container."
exit 1
fi
docker exec -it "$CONTAINER_NAME" /opt/connect.sh
observe_f5fpc
}

start_gateway() {
docker run -d --rm --privileged \
--name "$CONTAINER_NAME" \
--sysctl net.ipv4.ip_forward=1 \
matthiaslohr/f5fpc \
/opt/idle.sh > /dev/null
if [ "$?" != 0 ] ; then
echo "Error starting docker container."
exit 1
fi
docker exec -it "$CONTAINER_NAME" /opt/connect.sh
observe_f5fpc
}

stop_vpn() {
echo "Shutting down..."
docker exec "$CONTAINER_NAME" /usr/local/bin/f5fpc -o > /dev/null
docker stop "$CONTAINER_NAME"
exit
}

# read CLI parameters
POSITIONAL=()
while [ $# -gt 0 ] ; do
case $1 in
-h|--help)
show_help
exit
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters

# start vpn connection
trap stop_vpn INT
MODE="$1"

if [ -z "$MODE" ] ; then
echo "No mode given!"
show_help
exit 1
fi

case $MODE in
client)
start_client
;;
gateway)
start_gateway
;;
*)
echo "Unsupported mode $MODE!"
show_help
exit 1
;;
esac

Loading

0 comments on commit 110b86e

Please sign in to comment.