diff --git a/README.md b/README.md index fe52837..0e2b914 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,22 @@ Read the [docker installation instructions](https://github.com/ruimarinho/docker ### Install dependencies and configure apache + +##### raspberryPi +raspberryPi follows instructions set out in Debian / Ubuntu below, with the exception of the python-semantic-version. +You will need to install this manually from PIP using the below command. +When following the Debian / Ubuntu instructions remember to remove the python-semantic-version item from the apt-get command + +```shell +pip install semantic_version +``` + #### Debian / Ubuntu +The below will install and configure the web application, applying relative Alias commands to access local resources ```shell apt-get -y install python-geoip python-ipaddr python-humanize python-bottle python-semantic-version apache2 libapache2-mod-wsgi git wget geoip-database-extra +echo "Alias /images/ /var/www/html/openvpn-monitor/images/" > /etc/apache2/conf-available/openvpn-monitor.conf echo "WSGIScriptAlias /openvpn-monitor /var/www/html/openvpn-monitor/openvpn-monitor.py" > /etc/apache2/conf-available/openvpn-monitor.conf a2enconf openvpn-monitor systemctl restart apache2 @@ -63,7 +75,6 @@ echo "WSGIScriptAlias /openvpn-monitor /var/www/html/openvpn-monitor/openvpn-mon systemctl restart httpd ``` - ### Checkout OpenVPN-Monitor ```shell @@ -75,7 +86,7 @@ git clone https://github.com/furlongm/openvpn-monitor.git ### Configure OpenVPN Add the following line to your OpenVPN server configuration to run the -management console on 127.0.0.1 port 5555: +management console on 127.0.0.1 port 5555: (This port is arbitary, you may choose any) ``` management 127.0.0.1 5555 @@ -87,13 +98,52 @@ access to the management interface. ### Configure OpenVPN-Monitor -The example configuration file `/var/www/html/openvpn-monitor/openvpn-monitor.conf` +The provided configuration file `/var/www/html/openvpn-monitor/openvpn-monitor.conf` should give some indication of how to set site name, add a logo, etc. You can also set a default location (latitude and longitude) for the embedded maps. If not set, the default location is New York, USA. -Edit `/var/www/html/openvpn-monitor/openvpn-monitor.conf` to match your site. +Complete the following by editing `/var/www/html/openvpn-monitor/openvpn-monitor.conf` to match your site. + +#### OpenVPN-Monitor +The below should help you quickly configure your vpn monitor with relevant settings + +| Option | Default | Description | +| --- | --- | --- | +| site | Example | The name of the monitoring box - Free text, can be anything | +| logo | None | Optional logo. This will be displayed in the top right. No default provided | +| latitude | -37.8067 | Latitude location for the centre of map and marker icon to be set. Requires longitude or no action is taken. | +| longitude | 144.9635 | Longitude location for the centre of map and marker icon to be set. Requires latitude or no action is taken. | +| Maps | False | Will the site display the map| +| geoip_data | /usr/share/GeoIP/GeoIPCity.dat | GeoLocation data location. Unless you are making locational changes this should not need to be changed. | +| datetime_format | %a %b %d %H:%M:%S %Y | DateTime format for server display | +| marker | False | Display a marker on the map for the OpenVPN-Monitor Box | +| externalip | 0.0.0.0 | External IP of the OpenVPN-Monitor box. If latitude and longitude not specified then this is used to locate the Monitor box | +| pervpn_control | False | Display a layer control to turn of element markers per vpn | +| itemtype_control | False | Display a layer control to turn off element markers per connection type | +| allowFullscreen | False | Allow the map to be displayed in FullScreen mode | + +Note: If latitude, longitude and externalip all cannot be validated then Melbourne, Australia becomes the default centre and marker location. + +#### Per VPN Settings +The below should help you quickly configure connections to vpns + +| Option | Default | Description | +| --- | --- | --- | +| host | localhost | Specifies the IP or DNS name of the VPN management interface to connect. | +| port | 5555 | Specifies the Port of the management internace to connect. | +| name | default | Free Text. The name of the VPN Connection | +| show_disconnect | False | Show a button to disconnect clients | +| externalip | 0.0.0.0 | External IP of the VPN Server. If latitude and longitude not specified then this is used to locate the VPN | +| latitude | -35.308065 | Latitude location for the vpn marker icon. Requires longitude or no action is taken. | +| longitude | 149.124521 | Longitude location for the vpn marker icon. Requires Latitude or no action is taken. | +| marker | False | Display a marker on the map for the VPN Server | +| connection_lines | False | Display connection lines between the Server and the Clients. Requires marker to be on for VPN. | + +Note: If latitude, longitude and externalip all cannot be validated then Canberra, Australia becomes the default marker location. + +### Your Done You should now be able to navigate to `http://myipaddress/openvpn-monitor/` Note the trailing slash, the images may not appear without it. @@ -127,3 +177,5 @@ the COPYING file. Flags are created by Matthias Slovig (flags@slovig.de) and are licensed under Creative Commons License Deed Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0). See http://flags.blogpotato.de/ for more details. +Fullscreen control provided by https://github.com/brunob/leaflet.fullscreen +Spiderfy (Closeby Marker control) provided by https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet diff --git a/images/favicon.ico b/images/favicon.ico new file mode 100644 index 0000000..018dd27 Binary files /dev/null and b/images/favicon.ico differ diff --git a/images/marker-icon-blue.png b/images/marker-icon-blue.png new file mode 100644 index 0000000..950edf2 Binary files /dev/null and b/images/marker-icon-blue.png differ diff --git a/images/marker-icon-green.png b/images/marker-icon-green.png new file mode 100644 index 0000000..fe2a6af Binary files /dev/null and b/images/marker-icon-green.png differ diff --git a/images/marker-icon-orange.png b/images/marker-icon-orange.png new file mode 100644 index 0000000..d6c02e9 Binary files /dev/null and b/images/marker-icon-orange.png differ diff --git a/images/marker-icon-red.png b/images/marker-icon-red.png new file mode 100644 index 0000000..364ac35 Binary files /dev/null and b/images/marker-icon-red.png differ diff --git a/images/route-icon.png b/images/route-icon.png new file mode 100644 index 0000000..eae13b4 Binary files /dev/null and b/images/route-icon.png differ diff --git a/openvpn-monitor.conf b/openvpn-monitor.conf index 9d8ca18..f5f0ee7 100644 --- a/openvpn-monitor.conf +++ b/openvpn-monitor.conf @@ -6,9 +6,30 @@ site=Example maps=True geoip_data=/usr/share/GeoIP/GeoIPCity.dat datetime_format=%d/%m/%Y %H:%M:%S +marker=True +externalip=0.0.0.0 +pervpn_control=True +itemtype_control=True +allowFullscreen=True [VPN1] host=localhost port=5555 name=Staff VPN show_disconnect=False +externalip=0.0.0.0 +#latitude=-35 +#longitude=149 +marker=True +connection_lines=True + +#[VPN2] +#host=remotehost +#port=5555 +#name=Test VPN +#show_disconnect=False +#externalip=0.0.0.0 +#latitude=-35 +#longitude=149 +#marker=True +#connection_lines=True diff --git a/openvpn-monitor.py b/openvpn-monitor.py index f53571d..d982f7e 100755 --- a/openvpn-monitor.py +++ b/openvpn-monitor.py @@ -106,14 +106,28 @@ def load_default_settings(self): info('Using default settings => localhost:5555') self.settings = {'site': 'Default Site', 'geoip_data': '/usr/share/GeoIP/GeoIPCity.dat', - 'datetime_format': '%d/%m/%Y %H:%M:%S'} + 'datetime_format': '%d/%m/%Y %H:%M:%S', + 'marker': False, + 'externalip': '0.0.0.0', + 'pervpn_control': False, + 'itemtype_control': False, + 'allowFullscreen': False} self.vpns['Default VPN'] = {'name': 'default', 'host': 'localhost', 'port': '5555', - 'show_disconnect': False} + 'show_disconnect': False, + 'externalip': '0.0.0.0', + 'latitude': '-35.308065', + 'longitude': '149.124521', + 'marker': False, + 'connection_lines': False} + def parse_global_section(self, config): - global_vars = ['site', 'logo', 'latitude', 'longitude', 'maps', 'geoip_data', 'datetime_format'] + global_vars = ['site', 'logo', 'latitude', 'longitude', 'maps', + 'geoip_data', 'datetime_format', 'marker', + 'externalip', 'pervpn_control', + 'itemtype_control', 'allowFullscreen'] for var in global_vars: try: self.settings[var] = config.get('OpenVPN-Monitor', var) @@ -134,10 +148,13 @@ def parse_vpn_section(self, config, section): except configparser.Error as e: warning('CONFIG: {0!s} on option {1!s}: '.format(e, option)) vpn[option] = None - if 'show_disconnect' in vpn and vpn['show_disconnect'] == 'True': - vpn['show_disconnect'] = True - else: - vpn['show_disconnect'] = False + vpn['show_disconnect'] = bool('show_disconnect' in vpn and + vpn['show_disconnect'] == 'True') + vpn['marker'] = bool('marker' in vpn and vpn['marker'] == 'True') + vpn['connection_lines'] = bool('connection_lines' in vpn and + vpn['connection_lines'] == 'True') + if 'externalip' not in vpn: + vpn['externalip'] = '0.0.0.0' if args.debug: debug("=== begin section\n{0!s}\n=== end section".format(vpn)) @@ -180,6 +197,18 @@ def collect_data(self, vpn): vpn['stats'] = self.parse_stats(stats) status = self.send_command('status 3\n') vpn['sessions'] = self.parse_status(status, self.gi, vpn['semver']) + if 'latitude' not in vpn or 'longitude' not in vpn: + # default Canberra + vpn['longitude'] = '149.124521' + vpn['latitude'] = '-35.308065' + if 'externalip' in vpn: + try: + gir = self.gi.record_by_addr(str(vpn['externalip'])) + except SystemError: + gir = None + if gir is not None: + vpn['longitude'] = gir['longitude'] + vpn['latitude'] = gir['latitude'] def _socket_send(self, command): if sys.version_info[0] == 2: @@ -431,6 +460,7 @@ def __init__(self, cfg, monitor): def init_vars(self, settings, monitor): self.vpns = list(monitor.vpns.items()) + self.gi = monitor.gi self.site = 'Example' if 'site' in settings: @@ -444,12 +474,46 @@ def init_vars(self, settings, monitor): if 'maps' in settings and settings['maps'] == 'True': self.maps = True - self.latitude = 40.72 - self.longitude = -74 - if 'latitude' in settings: + self.externalip = '0.0.0.0' + if 'externalip' in settings: + self.externalip = settings['externalip'] + + # default melbourne + self.latitude = -37.8067 + self.longitude = 144.9635 + if 'latitude' in settings and 'longitude' in settings: self.latitude = settings['latitude'] - if 'longitude' in settings: self.longitude = settings['longitude'] + else: + try: + gir = self.gi.record_by_addr(self.externalip) + except SystemError: + gir = None + if gir is not None: + self.location = gir['country_code'] + self.city = get_str(gir['city']) + self.country_name = gir['country_name'] + self.longitude = gir['longitude'] + self.latitude = gir['latitude'] + + self.marker = False + if 'marker' in settings and settings['marker'] == 'True': + self.marker = True + + self.pervpn_control = False + if ('pervpn_control' in settings and + settings['pervpn_control'] == 'True'): + self.pervpn_control = True + + self.itemtype_control = False + if ('itemtype_control' in settings and + settings['itemtype_control'] == 'True'): + self.itemtype_control = True + + self.allowFullscreen = False + if ('allowFullscreen' in settings and + settings['allowFullscreen'] == 'True'): + self.allowFullscreen = True self.datetime_format = settings['datetime_format'] @@ -472,6 +536,23 @@ def print_html_header(self): output('') if self.maps: output('') + if self.maps and self.allowFullscreen: + # Leaflet.Control.FullScreen css + output('') # noqa: E501 + output('') + + # favicon + output('') # js output('') @@ -484,6 +565,11 @@ def print_html_header(self): output('});') if self.maps: output('') + # spiderfy + output('') # noqa: E501 + if self.maps and self.allowFullscreen: + # Leaflet.Control.FullScreen js + output('') # noqa: E501 output('
') @@ -541,6 +627,7 @@ def print_session_table_headers(vpn_mode, show_disconnect): elif vpn_mode == 'Server': headers = server_headers + output('VPN Mode | Status | Pingable | ') output('Clients | Total Bytes In | Total Bytes Out | ') @@ -605,15 +693,18 @@ def print_vpn(self, vpn_id, vpn): output('{0!s} | '.format(local_ip)) if vpn_mode == 'Client': output('{0!s} | '.format(remote_ip)) - output('
---|