├── .github ├── FUNDING.yml └── workflows │ └── build.yaml ├── Dockerfile ├── LICENSE ├── README.md ├── confd ├── conf.d │ └── openvpn-monitor.toml └── templates │ └── openvpn-monitor.conf.tmpl └── entrypoint.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ruimarinho 2 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: master 6 | tags: '*' 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Prepare Docker build 13 | id: prepare 14 | run: | 15 | if [[ $GITHUB_REF == refs/tags/* ]]; then 16 | TAG=${GITHUB_REF#refs/tags/} 17 | echo ::set-output name=tag_name::${TAG} 18 | echo ::set-output name=version::${TAG%-*} 19 | else 20 | echo ::set-output name=version::${GITHUB_SHA::8} 21 | fi 22 | echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ') 23 | echo ::set-output name=docker_platforms::linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386 24 | echo ::set-output name=docker_username::ruimarinho 25 | echo ::set-output name=docker_image::ruimarinho/openvpn-monitor 26 | 27 | - name: Set up Docker Buildx 28 | uses: crazy-max/ghaction-docker-buildx@v1 29 | 30 | - name: Checkout 31 | uses: actions/checkout@v2 32 | 33 | - name: Login into Docker Hub 34 | env: 35 | DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} 36 | run: | 37 | echo "${DOCKER_HUB_PASSWORD}" | docker login --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin 38 | 39 | - name: Build multi-platform Docker image 40 | env: 41 | MAXMIND_LICENSE_KEY: ${{ secrets.MAXMIND_LICENSE_KEY }} 42 | UPSTREAM_VERSION: "1.1.3" 43 | run: | 44 | docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \ 45 | --output "type=image,push=true" \ 46 | --progress=plain \ 47 | --build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \ 48 | --build-arg "MAXMIND_LICENSE_KEY=${MAXMIND_LICENSE_KEY}" \ 49 | --build-arg "VCS_REF=${GITHUB_SHA::8}" \ 50 | --build-arg "VERSION=${{ steps.prepare.outputs.version }}" \ 51 | --build-arg "UPSTREAM_VERSION=${UPSTREAM_VERSION}" \ 52 | --tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \ 53 | --tag "${{ steps.prepare.outputs.docker_image }}:latest" \ 54 | . 55 | 56 | - name: Check Docker image manifest 57 | run: | 58 | docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} 59 | 60 | - name: Clear Docker credentials 61 | run: | 62 | rm -f ${HOME}/.docker/config.json 63 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:slim 2 | 3 | ARG UPSTREAM_VERSION 4 | ARG MAXMIND_LICENSE_KEY 5 | 6 | ENV GOPATH /go 7 | ENV PATH /go/bin:$PATH 8 | 9 | RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin 10 | 11 | RUN apt-get update \ 12 | && apt-get install -y git software-properties-common wget \ 13 | && add-apt-repository ppa:longsleep/golang-backports \ 14 | && apt-get install -y golang-go 15 | 16 | RUN go get -v -u github.com/kelseyhightower/confd \ 17 | && rm -rf /go/src/github.com/kelseyhightower/confd \ 18 | && pip install gunicorn \ 19 | && mkdir /openvpn-monitor \ 20 | && wget -O - https://github.com/furlongm/openvpn-monitor/archive/${UPSTREAM_VERSION}.tar.gz | tar -C /openvpn-monitor --strip-components=1 -zxvf - \ 21 | && cp /openvpn-monitor/openvpn-monitor.conf.example /openvpn-monitor/openvpn-monitor.conf \ 22 | && pip install /openvpn-monitor \ 23 | && mkdir -p /var/lib/GeoIP/ \ 24 | && wget -O - "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=$MAXMIND_LICENSE_KEY&suffix=tar.gz" | tar -C /var/lib/GeoIP/ --strip-components=1 -zxvf - \ 25 | && rm -rf /var/lib/apt/lists/ \ 26 | && rm -rf /usr/lib/go-1.11 \ 27 | && rm -rf $GOPATH/src 28 | 29 | COPY confd /etc/confd 30 | COPY entrypoint.sh / 31 | 32 | WORKDIR /openvpn-monitor 33 | 34 | EXPOSE 80 35 | 36 | ENTRYPOINT ["/entrypoint.sh"] 37 | 38 | CMD ["gunicorn", "openvpn-monitor", "--bind", "0.0.0.0:80"] 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Rui Marinho 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ruimarinho/openvpn-monitor 2 | 3 | [![build status][github-image]][github-url] 4 | [![ruimarinho/openvpn-monitor][docker-stars-image]][docker-hub-url] [![ruimarinho/openvpn-monitor][docker-pulls-image]][docker-hub-url] 5 | 6 | The trusted multi-platform [web-based OpenVPN Monitor](http://openvpn-monitor.openbytes.ie) docker image. 7 | 8 | * `amd64` (`x86_64`) 9 | * `arm64` (`aarch64`, `armv8`) 10 | * `arm32v7` (`armv7`) 11 | * `arm32v6` (`armv6`) 12 | * `i386` 13 | 14 | ## What is OpenVPN Monitor? 15 | 16 | OpenVPN Monitor is a web-based utility that displays the status of OpenVPN servers. It includes information such as the usernames/hostnames connected, remote and VPN IP addresses, approximate locations (using GeoIP), traffic consumption and more. 17 | 18 | ## Usage 19 | 20 | First, make sure OpenVPN is configured to open the management interface that the OpenVPN Monitor connects to. Edit the `openvpn.conf` file and add the following directive (choose port `5555` or any other of your preference): 21 | 22 | ``` 23 | management 127.0.0.1 5555 24 | ``` 25 | 26 | Note: if you're running OpenVPN in a container as well, allow for external connections with: 27 | 28 | ``` 29 | management 0.0.0.0 5555 30 | ``` 31 | 32 | All settings of OpenVPN Monitor can be dynamically configured via environment variables (thanks to confd) without having to create a new image or bind-mounting the configuration file. 33 | 34 | The environment variable are organized into two groups: 35 | 36 | - `OPENVPNMONITOR_DEFAULT_`: populates the global `[OpenVPN-Monitor]` section. 37 | - `OPENVPNMONITOR_SITES__`: populates each site section. **Note: if property contains underscores, like `datetime_format` and `show_disconnect`, you must pass those properties without the underscore. See example below.** 38 | 39 | By default, GeoIP is automatically available (no additional download step is required). For this reason, the location of the `geoip_data` file is hardcoded in the configuration file. The `datetime_format` defaults to `%d/%m/%Y %H:%M:%S` if none is provided. Everything else must be set and there is no whitelist of property names. This ensures compatibility of this image with future versions of OpenVPN monitor without too much maintenance. 40 | 41 | So a minimal and accessible, yet non-functional, version of OpenVPN Monitor can be reduced to: 42 | 43 | ``` 44 | docker run -p 80:80 --rm ruimarinho/openvpn-monitor 45 | ``` 46 | 47 | Let's add some configuration, including changing the page name, adding a logo, some geolocation features and two sites - one that connects to a running TCP OpenVPN server and another one to an UDP server. 48 | 49 | Using the scheme above, the configuration is as simple as setting the appropriate environment variables: 50 | 51 | ``` 52 | docker run --name openvpn-monitor \ 53 | -e OPENVPNMONITOR_DEFAULT_DATETIMEFORMAT="%%d/%%m/%%Y" \ 54 | -e OPENVPNMONITOR_DEFAULT_LATITUDE=-37 \ 55 | -e OPENVPNMONITOR_DEFAULT_LOGO=logo.jpg \ 56 | -e OPENVPNMONITOR_DEFAULT_LONGITUDE=144 \ 57 | -e OPENVPNMONITOR_DEFAULT_MAPS=True \ 58 | -e OPENVPNMONITOR_DEFAULT_MAPSHEIGHT=500 \ 59 | -e OPENVPNMONITOR_DEFAULT_SITE=Test \ 60 | -e OPENVPNMONITOR_SITES_0_ALIAS=UDP \ 61 | -e OPENVPNMONITOR_SITES_0_HOST=openvpn-udp \ 62 | -e OPENVPNMONITOR_SITES_0_NAME=UDP \ 63 | -e OPENVPNMONITOR_SITES_0_PORT=5555 \ 64 | -e OPENVPNMONITOR_SITES_0_SHOWDISCONNECT=True \ 65 | -e OPENVPNMONITOR_SITES_1_ALIAS=TCP \ 66 | -e OPENVPNMONITOR_SITES_1_HOST=openvpn-udp \ 67 | -e OPENVPNMONITOR_SITES_1_NAME=TCP \ 68 | -e OPENVPNMONITOR_SITES_1_PORT=5555 \ 69 | -p 80:80 ruimarinho/openvpn-monitor 70 | ``` 71 | 72 | Now OpenVPN Monitor should be accessible via http://127.0.0.1:80. 73 | 74 | *Note that for the `logo.jpg` to be readable, you need to bind-mount it or pass an URL instead. Also, the datetime format needs to be escaped as shown above (suing two %).* 75 | 76 | ## Supported Docker versions 77 | 78 | This image is officially supported on Docker version 1.12, with support for older versions provided on a best-effort basis. 79 | 80 | ## License 81 | 82 | MIT 83 | 84 | [docker-hub-url]: https://hub.docker.com/r/ruimarinho/openvpn-monitor 85 | [docker-pulls-image]: https://img.shields.io/docker/pulls/ruimarinho/openvpn-monitor.svg?style=flat-square 86 | [docker-stars-image]: https://img.shields.io/docker/stars/ruimarinho/openvpn-monitor.svg?style=flat-square 87 | [github-image]: https://github.com/ruimarinho/docker-openvpn-monitor/workflows/build/badge.svg 88 | [github-url]: https://github.com/ruimarinho/docker-openvpn-monitor/actions 89 | -------------------------------------------------------------------------------- /confd/conf.d/openvpn-monitor.toml: -------------------------------------------------------------------------------- 1 | [template] 2 | src = "openvpn-monitor.conf.tmpl" 3 | dest = "/openvpn-monitor/openvpn-monitor.conf" 4 | keys = [ 5 | "/openvpnmonitor" 6 | ] 7 | -------------------------------------------------------------------------------- /confd/templates/openvpn-monitor.conf.tmpl: -------------------------------------------------------------------------------- 1 | [OpenVPN-Monitor] 2 | {{- range $i := ls "/openvpnmonitor/default" }} 3 | {{- if eq $i "datetimeformat" }} 4 | datetime_format={{ replace (getv (printf "/openvpnmonitor/default/%s" $i)) "%%" "%" -1 -}} 5 | {{- else if eq $i "mapsheight" }} 6 | maps_height={{- getv (printf "/openvpnmonitor/default/%s" $i) -}} 7 | {{else}} 8 | {{$i}}={{ getv (printf "/openvpnmonitor/default/%s" $i) -}} 9 | {{end -}} 10 | {{end}} 11 | geoip_data=/var/lib/GeoIP/GeoLite2-City.mmdb 12 | {{ if not (exists "/openvpnmonitor/default/datetimeformat") -}} 13 | datetime_format=%d/%m/%Y %H:%M:%S 14 | {{end}} 15 | 16 | {{- range $i := ls "/openvpnmonitor/sites" -}} 17 | {{if not (exists (printf "/openvpnmonitor/sites/%s/alias" $i)) }} 18 | [Site {{$i}}] 19 | {{ end -}} 20 | {{- range $property := ls (printf "/openvpnmonitor/sites/%s" $i) }} 21 | {{- if eq $property "alias" }} 22 | [{{ getv (printf "/openvpnmonitor/sites/%s/%s" $i $property) }}] 23 | {{else -}} 24 | {{if exists (printf "/openvpnmonitor/sites/%s/%s" $i $property) }} 25 | {{- if eq $property "showdisconnect" -}} 26 | show_disconnect={{- getv (printf "/openvpnmonitor/sites/%s/%s" $i "showdisconnect") -}} 27 | {{- else -}} 28 | {{- $property }}={{- getv (printf "/openvpnmonitor/sites/%s/%s" $i $property) -}} 29 | {{end -}} 30 | {{end}} 31 | {{end -}} 32 | {{end -}} 33 | {{end -}} 34 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | confd -onetime -backend env --log-level debug 5 | 6 | cat openvpn-monitor.conf 7 | 8 | exec "$@" 9 | --------------------------------------------------------------------------------