mirror of
https://github.com/cmur2/openvpn-status-web.git
synced 2025-09-29 07:52:07 +02:00
Compare commits
156 Commits
Author | SHA1 | Date | |
---|---|---|---|
65a65081ae | |||
194137adc8 | |||
ee06f65e81 | |||
![]() |
075922e484 | ||
![]() |
9ece1e125b | ||
![]() |
ba50185f44 | ||
![]() |
d57e8b7d2e | ||
![]() |
2d77c0efee | ||
![]() |
4f6725825a | ||
![]() |
8af23da209 | ||
![]() |
78d4c3c8cb | ||
![]() |
39f570ec48 | ||
![]() |
1eb6202a8f | ||
![]() |
a329966bc5 | ||
![]() |
575516bd27 | ||
![]() |
af253c61f0 | ||
![]() |
a804f842df | ||
![]() |
648b4d94b6 | ||
![]() |
117f70e2e3 | ||
![]() |
1e0444a71d | ||
![]() |
20c6c9176a | ||
![]() |
a0ad379b00 | ||
![]() |
d8f4931657 | ||
![]() |
6676f47c97 | ||
![]() |
811b928403 | ||
![]() |
f4a48b8ce0 | ||
![]() |
f985ec1c12 | ||
![]() |
3d10b7d128 | ||
![]() |
27876c7f12 | ||
![]() |
9d584ceb71 | ||
![]() |
1996f1d9b9 | ||
![]() |
f342b07495 | ||
557a328336 | |||
057d243db8 | |||
![]() |
e3a06fdf6c | ||
![]() |
bfe39adaf8 | ||
![]() |
9159a53cce | ||
![]() |
51825eb2da | ||
![]() |
280e2b9ae1 | ||
![]() |
6d56db855f | ||
![]() |
0b782b7dd3 | ||
ea7b3a947c | |||
eb2bb4d632 | |||
2a9bacf196 | |||
39adc74fbc | |||
9ad59194bd | |||
528709c895 | |||
39d2b3ce94 | |||
406ed867f7 | |||
![]() |
22d9797f55 | ||
![]() |
55aecedef7 | ||
![]() |
d401074524 | ||
![]() |
ff6572bdac | ||
![]() |
b4bf74240b | ||
![]() |
fb4b3ca461 | ||
![]() |
8a6722f981 | ||
![]() |
8249b01c95 | ||
![]() |
5d04255a95 | ||
![]() |
846d41d35d | ||
![]() |
ce0e80f35f | ||
![]() |
0ec3faf5b4 | ||
![]() |
10a4e757f3 | ||
![]() |
f95134c315 | ||
![]() |
7da4cb910f | ||
![]() |
382daa34c6 | ||
![]() |
5338b30e32 | ||
![]() |
47ee407af2 | ||
![]() |
281750d6ea | ||
![]() |
42743a1786 | ||
![]() |
7c94192765 | ||
![]() |
a3a65f05bc | ||
![]() |
e87a4d86f6 | ||
![]() |
2145e183e3 | ||
![]() |
9e5aa1ff71 | ||
![]() |
a99ba901c9 | ||
![]() |
cc21291a5c | ||
![]() |
ba00407d55 | ||
![]() |
80bd4f8584 | ||
e4034073a6 | |||
![]() |
f4d17809a2 | ||
08b50d5974 | |||
![]() |
f287906240 | ||
27306b831f | |||
1e12701fc3 | |||
597b619b0b | |||
61f7cbd76c | |||
2628c08975 | |||
![]() |
7343081406 | ||
ec4d028c03 | |||
12b5153604 | |||
7c0722e875 | |||
![]() |
afd7f4fa98 | ||
![]() |
63272da3e3 | ||
![]() |
ae7fc1137b | ||
![]() |
1f69dabf5f | ||
0e9c9fea68 | |||
0ffe369ef1 | |||
![]() |
c2cac319ae | ||
![]() |
5f343d7873 | ||
![]() |
0a45726857 | ||
109b27fecc | |||
b44517ec21 | |||
![]() |
520da15739 | ||
![]() |
9b3a13abef | ||
![]() |
b81d61b8d7 | ||
147a905bfc | |||
eeed0fa089 | |||
586ae8ae0f | |||
![]() |
075ec1e548 | ||
64ec5e1e56 | |||
![]() |
7597c17e93 | ||
ac647a4f21 | |||
78f45f5080 | |||
9aeb1a9ad5 | |||
88c22a6504 | |||
![]() |
289535d753 | ||
![]() |
8d42bdafc1 | ||
f8666fdfc2 | |||
41f5d4ed62 | |||
92ee01e5de | |||
bf3ba8f7cd | |||
140c60c753 | |||
d959e7fe62 | |||
4cde78fe96 | |||
23dd4aa63f | |||
1547db7bc6 | |||
b1aa38059f | |||
17054794da | |||
ab81c8975e | |||
1804693c15 | |||
cdc20e8042 | |||
998f9e683c | |||
cf69d6417d | |||
cb1d029326 | |||
563fb5743b | |||
a852aa4b4d | |||
d5f8d66422 | |||
f873d8176e | |||
c14d59e0bf | |||
![]() |
a78a178150 | ||
![]() |
e0c3073d82 | ||
![]() |
c885e875ad | ||
![]() |
f2794ccea4 | ||
![]() |
457aec64db | ||
![]() |
468e002162 | ||
![]() |
35b5be15a4 | ||
![]() |
c51968618d | ||
![]() |
a1a6b33902 | ||
![]() |
33013c56f3 | ||
![]() |
ed42fc9f30 | ||
![]() |
635e562a3d | ||
![]() |
438931f8a6 | ||
![]() |
cd6e41fcfa | ||
![]() |
87d9ea302f | ||
![]() |
d6a7b8c0ee | ||
![]() |
addc1cf45a |
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
32
.github/workflows/ci.yml
vendored
Normal file
32
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request:
|
||||||
|
branches: [master]
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: '35 4 * * 4' # weekly on thursday morning
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
ruby-version:
|
||||||
|
- '2.7'
|
||||||
|
- '3.0'
|
||||||
|
- '3.1'
|
||||||
|
- '3.2'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: ${{ matrix.ruby-version }}
|
||||||
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
||||||
|
- name: Lint and Test
|
||||||
|
run: |
|
||||||
|
bundle exec rake ci
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
*.lock
|
*.lock
|
||||||
pkg/*
|
pkg/*
|
||||||
|
.yardoc
|
||||||
|
105
.rubocop.yml
Normal file
105
.rubocop.yml
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
require:
|
||||||
|
- rubocop-rake
|
||||||
|
- rubocop-rspec
|
||||||
|
|
||||||
|
AllCops:
|
||||||
|
TargetRubyVersion: '2.7'
|
||||||
|
NewCops: enable
|
||||||
|
|
||||||
|
Gemspec/RequireMFA:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Layout/EmptyLineAfterGuardClause:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
# allows nicer usage of private_class_method
|
||||||
|
Layout/EmptyLinesAroundArguments:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Layout/HashAlignment:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Layout/LeadingEmptyLines:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Layout/LineLength:
|
||||||
|
Max: 200
|
||||||
|
|
||||||
|
Layout/SpaceInsideHashLiteralBraces:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/AbcSize:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/BlockLength:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/ClassLength:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/CyclomaticComplexity:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/MethodLength:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/PerceivedComplexity:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Naming/MethodParameterName:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Naming/MemoizedInstanceVariableName:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/AccessorGrouping:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/ConditionalAssignment:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/Documentation:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/FormatStringToken:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/GuardClause:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/HashEachMethods:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Style/HashTransformKeys:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Style/HashTransformValues:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
|
Style/IdenticalConditionalBranches:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/InverseMethods:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/NegatedIf:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/RescueModifier:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Style/Semicolon:
|
||||||
|
AllowAsExpressionSeparator: true
|
||||||
|
|
||||||
|
Style/SymbolArray:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
RSpec/ExampleLength:
|
||||||
|
Max: 10
|
||||||
|
|
||||||
|
RSpec/FilePath:
|
||||||
|
CustomTransform:
|
||||||
|
OpenVPNStatusWeb: openvpn-status-web
|
||||||
|
|
||||||
|
RSpec/MultipleExpectations:
|
||||||
|
Max: 5
|
16
.solargraph.yml
Normal file
16
.solargraph.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
include:
|
||||||
|
- "**/*.rb"
|
||||||
|
- "bin/openvpn-status-web"
|
||||||
|
exclude:
|
||||||
|
- spec/**/*
|
||||||
|
- test/**/*
|
||||||
|
- vendor/**/*
|
||||||
|
- ".bundle/**/*"
|
||||||
|
require: []
|
||||||
|
domains: []
|
||||||
|
reporters:
|
||||||
|
- rubocop
|
||||||
|
- require_not_found
|
||||||
|
require_paths: []
|
||||||
|
max_files: 5000
|
@@ -1,9 +0,0 @@
|
|||||||
language: ruby
|
|
||||||
|
|
||||||
rvm:
|
|
||||||
- 2.0.0
|
|
||||||
- 1.9.3
|
|
||||||
- 1.8.7
|
|
||||||
|
|
||||||
gemfile:
|
|
||||||
- Gemfile
|
|
2
Gemfile
2
Gemfile
@@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
65
README.md
65
README.md
@@ -1,17 +1,68 @@
|
|||||||
# openvpn-status-web
|
# openvpn-status-web
|
||||||
|
|
||||||
Small (another word for naive in this case, it's simple and serves my needs) [rack](http://rack.github.com/) app
|
 [](https://depfu.com/github/cmur2/openvpn-status-web?project_id=6194)
|
||||||
providing the information the [OpenVPN](http://openvpn.net/index.php/open-source.html) server collects in it's status file
|
|
||||||
especially including a list of currently connected clients (common name, remote address, traffic, ...).
|
## Description
|
||||||
It comes with a Debian 6 compatible init.d file.
|
|
||||||
|
Small (another word for naive in this case, it's simple and serves my needs) [Rack](http://rack.github.com/) application providing the information an [OpenVPN](http://openvpn.net/index.php/open-source.html) server collects in it's status file especially including a list of currently connected clients (common name, remote address, traffic, ...).
|
||||||
|
|
||||||
It lacks:
|
It lacks:
|
||||||
|
|
||||||
* authentication
|
* caching (parses file on each request, page does auto-refresh every minute as OpenVPN updates the status file these often by default)
|
||||||
* caching (parses file on each request, page does auto-refresh every minute as OpenVPN updates the status file these often)
|
|
||||||
* management interface support
|
* management interface support
|
||||||
* *possibly more...*
|
* *possibly more...*
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Install the gem:
|
||||||
|
|
||||||
|
gem install openvpn-status-web
|
||||||
|
|
||||||
|
Create a configuration file in YAML format somewhere:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# listen address and port
|
||||||
|
host: "0.0.0.0"
|
||||||
|
port: "8080"
|
||||||
|
# optional: drop priviliges in case you want to but you should give this user at least read access on the log files
|
||||||
|
user: "nobody"
|
||||||
|
group: "nogroup"
|
||||||
|
# logfile is optional, logs to STDOUT else
|
||||||
|
logfile: "openvpn-status-web.log"
|
||||||
|
# hash with each VPNs display name for humans as key and further config as value
|
||||||
|
vpns:
|
||||||
|
My Small VPN:
|
||||||
|
# the status file path and status file format version are required
|
||||||
|
version: 1
|
||||||
|
status_file: "/var/log/openvpn-status.log"
|
||||||
|
My Other VPN:
|
||||||
|
version: 3
|
||||||
|
status_file: "/var/log/other-openvpn-status.log"
|
||||||
|
```
|
||||||
|
|
||||||
|
Your OpenVPN configuration should contain something like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ...snip...
|
||||||
|
status /var/log/openvpn-status.log
|
||||||
|
status-version 1
|
||||||
|
# ...snip...
|
||||||
|
```
|
||||||
|
|
||||||
|
For more information about OpenVPN status file and version, see their [man page](https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage). openvpn-status-web is able to parse all versions from 1 to 3.
|
||||||
|
|
||||||
|
## Advanced topics
|
||||||
|
|
||||||
|
### Authentication
|
||||||
|
|
||||||
|
If the information exposed is important to you serve it via the VPN or use a webserver as a proxy to handle SSL and/or HTTP authentication.
|
||||||
|
|
||||||
|
### Startup
|
||||||
|
|
||||||
|
There is a [Dockerfile](docs/Dockerfile) that can be used to build a Docker image for running openvpn-status-web.
|
||||||
|
|
||||||
|
The [Debian 6 init script](docs/debian-init-openvpn-status-web) assumes that openvpn-status-web is installed into the system ruby (no RVM support) and the config.yaml is at `/opt/openvpn-status-web/config.yaml`. Modify to your needs.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
openvpn-statsu-web is licensed under the Apache License, Version 2.0. See LICENSE for more information.
|
openvpn-status-web is licensed under the Apache License, Version 2.0. See LICENSE for more information.
|
||||||
|
23
Rakefile
23
Rakefile
@@ -1,6 +1,27 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'bundler/gem_tasks'
|
require 'bundler/gem_tasks'
|
||||||
require 'rspec/core/rake_task'
|
require 'rspec/core/rake_task'
|
||||||
|
require 'rubocop/rake_task'
|
||||||
|
require 'bundler/audit/task'
|
||||||
|
|
||||||
RSpec::Core::RakeTask.new(:spec)
|
RSpec::Core::RakeTask.new(:spec)
|
||||||
|
RuboCop::RakeTask.new
|
||||||
|
Bundler::Audit::Task.new
|
||||||
|
|
||||||
task :default => :spec
|
desc 'Run experimental solargraph type checker'
|
||||||
|
task :solargraph do
|
||||||
|
sh 'solargraph typecheck'
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :solargraph do
|
||||||
|
desc 'Should be run by developer once to prepare initial solargraph usage (fill caches etc.)'
|
||||||
|
task :init do
|
||||||
|
sh 'solargraph download-core'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task default: [:rubocop, :spec, 'bundle:audit', :solargraph]
|
||||||
|
|
||||||
|
desc 'Run all tasks desired for CI'
|
||||||
|
task ci: ['solargraph:init', :default]
|
||||||
|
15
docs/Dockerfile
Normal file
15
docs/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM alpine:3.16
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
ENV VERSION=3.4.0
|
||||||
|
|
||||||
|
RUN apk --no-cache add openssl ca-certificates && \
|
||||||
|
apk --no-cache add ruby ruby-etc ruby-webrick && \
|
||||||
|
apk --no-cache add --virtual .build-deps ruby-dev build-base tzdata && \
|
||||||
|
gem install --no-document openvpn-status-web -v ${VERSION} && \
|
||||||
|
# set timezone to Berlin
|
||||||
|
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \
|
||||||
|
apk del .build-deps
|
||||||
|
|
||||||
|
ENTRYPOINT ["openvpn-status-web", "/etc/openvpn-status-web/config.yml"]
|
40
docs/debian-init-openvpn-status-web
Executable file
40
docs/debian-init-openvpn-status-web
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: openvpn-status-web
|
||||||
|
# Required-Start: $remote_fs $syslog
|
||||||
|
# Required-Stop: $remote_fs $syslog
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Handle openvpn-status-web gem
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
# using the system ruby's gem binaries directory
|
||||||
|
DAEMON="/var/lib/gems/1.8/bin/openvpn-status-web"
|
||||||
|
|
||||||
|
CONFIG_FILE="/opt/openvpn-status-web/config.yaml"
|
||||||
|
|
||||||
|
DAEMON_OPTS="$CONFIG_FILE"
|
||||||
|
|
||||||
|
test -x $DAEMON || exit 0
|
||||||
|
|
||||||
|
. /lib/lsb/init-functions
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
log_daemon_msg "Starting openvpn-web-status" "openvpn-web-status"
|
||||||
|
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/openvpn-web-status.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
log_daemon_msg "Stopping openvpn-web-status" "openvpn-web-status"
|
||||||
|
start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/openvpn-web-status.pid"
|
||||||
|
;;
|
||||||
|
restart|force-reload)
|
||||||
|
log_daemon_msg "Restarting openvpn-web-status" "openvpn-web-status"
|
||||||
|
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "/var/run/openvpn-web-status.pid"
|
||||||
|
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/openvpn-web-status.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
@@ -1,8 +1,8 @@
|
|||||||
TITLE,OpenVPN 2.1_rc15 mipsel-unknown-linux-gnu [SSL] [LZO1] [EPOLL] built on Mar 27 2009
|
TITLE,OpenVPN 2.1_rc15 mipsel-unknown-linux-gnu [SSL] [LZO1] [EPOLL] built on Mar 27 2009
|
||||||
TIME,Sun Jan 1 23:42:00 2012,1238702330
|
TIME,Sun Jan 1 23:42:00 2012,1238702330
|
||||||
HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t)
|
HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t)
|
||||||
CLIENT_LIST,foo,1.2.3.4:1234,11811160064,4194304,Sun Jan 1 23:42:00 2012,1238702330
|
CLIENT_LIST,foo,1.2.3.4:1234,192.168.66.2,11811160064,4194304,Sun Jan 1 23:42:00 2012,1238702330
|
||||||
CLIENT_LIST,bar,1.2.3.5:1235,512,2048,Sun Jan 1 23:42:00 2012,1238702330
|
CLIENT_LIST,bar,1.2.3.5:1235,2001:db8:0:0::1000,512,2048,Sun Jan 1 23:42:00 2012,1238702330
|
||||||
HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t)
|
HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t)
|
||||||
ROUTING_TABLE,192.168.0.0/24,foo,1.2.3.4:1234,Sun Jan 1 23:42:00 2012,1238702330
|
ROUTING_TABLE,192.168.0.0/24,foo,1.2.3.4:1234,Sun Jan 1 23:42:00 2012,1238702330
|
||||||
ROUTING_TABLE,192.168.66.2,bar,1.2.3.5:1235,Sun Jan 1 23:42:00 2012,1238702330
|
ROUTING_TABLE,192.168.66.2,bar,1.2.3.5:1235,Sun Jan 1 23:42:00 2012,1238702330
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
TITLE OpenVPN 2.1_rc15 mipsel-unknown-linux-gnu [SSL] [LZO1] [EPOLL] built on Mar 27 2009
|
TITLE OpenVPN 2.1_rc15 mipsel-unknown-linux-gnu [SSL] [LZO1] [EPOLL] built on Mar 27 2009
|
||||||
TIME Sun Jan 1 23:42:00 2012 1238702330
|
TIME Sun Jan 1 23:42:00 2012 1238702330
|
||||||
HEADER CLIENT_LIST Common Name Real Address Virtual Address Bytes Received Bytes Sent Connected Since Connected Since (time_t)
|
HEADER CLIENT_LIST Common Name Real Address Virtual Address Bytes Received Bytes Sent Connected Since Connected Since (time_t)
|
||||||
CLIENT_LIST foo 1.2.3.4:1234 11811160064 4194304 Sun Jan 1 23:42:00 2012 1238702330
|
CLIENT_LIST foo 1.2.3.4:1234 192.168.66.2 11811160064 4194304 Sun Jan 1 23:42:00 2012 1238702330
|
||||||
CLIENT_LIST bar 1.2.3.5:1235 512 2048 Sun Jan 1 23:42:00 2012 1238702330
|
CLIENT_LIST bar 1.2.3.5:1235 2001:db8:0:0::1000 512 2048 Sun Jan 1 23:42:00 2012 1238702330
|
||||||
HEADER ROUTING_TABLE Virtual Address Common Name Real Address Last Ref Last Ref (time_t)
|
HEADER ROUTING_TABLE Virtual Address Common Name Real Address Last Ref Last Ref (time_t)
|
||||||
ROUTING_TABLE 192.168.0.0/24 foo 1.2.3.4:1234 Sun Jan 1 23:42:00 2012 1238702330
|
ROUTING_TABLE 192.168.0.0/24 foo 1.2.3.4:1234 Sun Jan 1 23:42:00 2012 1238702330
|
||||||
ROUTING_TABLE 192.168.66.2 bar 1.2.3.5:1235 Sun Jan 1 23:42:00 2012 1238702330
|
ROUTING_TABLE 192.168.66.2 bar 1.2.3.5:1235 Sun Jan 1 23:42:00 2012 1238702330
|
||||||
|
8
examples/status2_5.v2
Normal file
8
examples/status2_5.v2
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
TITLE,OpenVPN 2.5.1 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2021
|
||||||
|
TIME,2012-01-01 23:42:00,1238702330
|
||||||
|
HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Virtual IPv6 Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username,Client ID,Peer ID,Data Channel Cipher
|
||||||
|
CLIENT_LIST,foo,1.2.3.4:1234,192.168.66.2,,11811160064,4194304,2012-01-01 23:42:00,1238702330,UNDEF,1,0,AES-256-GCM
|
||||||
|
HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t)
|
||||||
|
ROUTING_TABLE,192.168.66.2,foo,1.2.3.4:1234,2012-01-01 23:42:00,1238702330
|
||||||
|
GLOBAL_STATS,Max bcast/mcast queue length,42
|
||||||
|
END
|
@@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'openvpn-status-web'
|
require 'openvpn-status-web'
|
||||||
|
|
@@ -1,48 +0,0 @@
|
|||||||
#! /bin/sh
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: openvpn-status-web
|
|
||||||
# Required-Start: $remote_fs $syslog
|
|
||||||
# Required-Stop: $remote_fs $syslog
|
|
||||||
# Default-Start: 2 3 4 5
|
|
||||||
# Default-Stop: 0 1 6
|
|
||||||
# Short-Description: Handle openvpn-status-web
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
# your ruby interpreter
|
|
||||||
DAEMON="/usr/bin/ruby"
|
|
||||||
|
|
||||||
# some unique name identifying your VPN
|
|
||||||
VPN_NAME="vpn.example.org"
|
|
||||||
|
|
||||||
# path to the OpenVPN status log file
|
|
||||||
STATUS_PATH="/var/log/openvpn-status.log"
|
|
||||||
|
|
||||||
# host and port for this daemon to listen on
|
|
||||||
HOST="127.0.0.1"
|
|
||||||
PORT="3000"
|
|
||||||
|
|
||||||
DAEMON_OPTS="/opt/openvpn-status-web/status.rb $VPN_NAME $STATUS_PATH $HOST $PORT"
|
|
||||||
|
|
||||||
test -x $DAEMON || exit 0
|
|
||||||
|
|
||||||
. /lib/lsb/init-functions
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
log_daemon_msg "Starting openvpn-web-status for $VPN_NAME" "openvpn-web-status"
|
|
||||||
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/$VPN_NAME.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
log_daemon_msg "Stopping openvpn-web-status for $VPN_NAME" "openvpn-web-status"
|
|
||||||
start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/$VPN_NAME.pid"
|
|
||||||
;;
|
|
||||||
restart|force-reload)
|
|
||||||
log_daemon_msg "Restarting openvpn-web-status for $VPN_NAME" "openvpn-web-status"
|
|
||||||
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "/var/run/$VPN_NAME.pid"
|
|
||||||
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/$VPN_NAME.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
143
lib/openvpn-status-web.rb
Normal file → Executable file
143
lib/openvpn-status-web.rb
Normal file → Executable file
@@ -1,96 +1,149 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'date'
|
||||||
require 'etc'
|
require 'etc'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
require 'ipaddr'
|
require 'ipaddr'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'rack'
|
require 'rack'
|
||||||
|
require 'rackup'
|
||||||
|
require 'erb'
|
||||||
require 'metriks'
|
require 'metriks'
|
||||||
|
require 'better_errors' if ENV.fetch('RACK_ENV', nil) == 'development'
|
||||||
|
|
||||||
|
require 'openvpn-status-web/status'
|
||||||
|
require 'openvpn-status-web/parser/v1'
|
||||||
|
require 'openvpn-status-web/parser/v2'
|
||||||
|
require 'openvpn-status-web/parser/v3'
|
||||||
require 'openvpn-status-web/int_patch'
|
require 'openvpn-status-web/int_patch'
|
||||||
require 'openvpn-status-web/version'
|
require 'openvpn-status-web/version'
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
|
# @return [Logger]
|
||||||
def self.logger
|
def self.logger
|
||||||
@logger
|
@logger
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param logger [Logger]
|
||||||
|
# @return [Logger]
|
||||||
def self.logger=(logger)
|
def self.logger=(logger)
|
||||||
@logger = logger
|
@logger = logger
|
||||||
end
|
end
|
||||||
|
|
||||||
class LogFormatter
|
class LogFormatter
|
||||||
def call(lvl, time, progname, msg)
|
# @param lvl [Object]
|
||||||
"[%s] %-5s %s\n" % [Time.now.strftime('%Y-%m-%d %H:%M:%S'), lvl, msg.to_s]
|
# @param _time [DateTime]
|
||||||
|
# @param _progname [String]
|
||||||
|
# @param msg [Object]
|
||||||
|
# @return [String]
|
||||||
|
def call(lvl, _time, _progname, msg)
|
||||||
|
format("[%s] %-5s %s\n", Time.now.strftime('%Y-%m-%d %H:%M:%S'), lvl, msg.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Daemon
|
class Daemon
|
||||||
def initialize(name, file)
|
def initialize(vpns)
|
||||||
@name = name
|
@vpns = vpns
|
||||||
@file = file
|
|
||||||
|
@main_tmpl = read_template(File.join(File.dirname(__FILE__), 'openvpn-status-web/main.html.erb'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
main_tmpl = read_template(File.join(File.dirname(__FILE__), 'openvpn-status-web/main.html.erb'))
|
return [405, {'Content-Type' => 'text/plain'}, ['Method Not Allowed']] if env['REQUEST_METHOD'] != 'GET'
|
||||||
# variables for template
|
return [404, {'Content-Type' => 'text/plain'}, ['Not Found']] if env['PATH_INFO'] != '/'
|
||||||
name = @name
|
|
||||||
client_list, routing_table, global_stats = read_status_log(@file)
|
|
||||||
|
|
||||||
html = main_tmpl.result(binding)
|
# variables for template
|
||||||
[200, {"Content-Type" => "text/html"}, [html]]
|
vpns = @vpns
|
||||||
|
stati = {}
|
||||||
|
@vpns.each do |name, config|
|
||||||
|
stati[name] = parse_status_log(config)
|
||||||
|
end
|
||||||
|
# eval
|
||||||
|
html = @main_tmpl.result(binding)
|
||||||
|
|
||||||
|
[200, {'Content-Type' => 'text/html'}, [html]]
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_template(file)
|
def read_template(file)
|
||||||
text = File.open(file, 'rb') do |f| f.read end
|
text = File.read(file, mode: 'rb')
|
||||||
|
|
||||||
ERB.new(text)
|
ERB.new(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_status_log(file)
|
def parse_status_log(vpn)
|
||||||
text = File.open(file, 'rb') do |f| f.read end
|
text = File.read(vpn['status_file'], mode: 'rb')
|
||||||
|
|
||||||
current_section = :none
|
case vpn['version']
|
||||||
client_list = []
|
when 1
|
||||||
routing_table = []
|
OpenVPNStatusWeb::Parser::V1.new.parse_status_log(text)
|
||||||
global_stats = []
|
when 2
|
||||||
|
OpenVPNStatusWeb::Parser::V2.new.parse_status_log(text)
|
||||||
text.lines.each do |line|
|
when 3
|
||||||
(current_section = :cl; next) if line == "OpenVPN CLIENT LIST\n"
|
OpenVPNStatusWeb::Parser::V3.new.parse_status_log(text)
|
||||||
(current_section = :rt; next) if line == "ROUTING TABLE\n"
|
else
|
||||||
(current_section = :gs; next) if line == "GLOBAL STATS\n"
|
raise "No suitable parser for status-version #{vpn['version']}"
|
||||||
(current_section = :end; next) if line == "END\n"
|
|
||||||
|
|
||||||
case current_section
|
|
||||||
when :cl then client_list << line.strip.split(',')
|
|
||||||
when :rt then routing_table << line.strip.split(',')
|
|
||||||
when :gs then global_stats << line.strip.split(',')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[client_list[2..-1], routing_table[1..-1], global_stats]
|
# @return [void]
|
||||||
end
|
|
||||||
|
|
||||||
def self.run!
|
def self.run!
|
||||||
if ARGV.length != 4
|
if ARGV.length != 1
|
||||||
puts "Usage: openvpn-status-web vpn-name status-log listen-host listen-port"
|
puts 'Usage: openvpn-status-web config_file'
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
OpenVPNStatusWeb.logger = Logger.new(STDOUT)
|
config_file = ARGV[0]
|
||||||
|
|
||||||
OpenVPNStatusWeb.logger.progname = "openvpn-status-web"
|
if !File.file?(config_file)
|
||||||
OpenVPNStatusWeb.logger.formatter = LogFormatter.new
|
puts 'Config file not found!'
|
||||||
|
exit 1
|
||||||
OpenVPNStatusWeb.logger.info "Starting..."
|
|
||||||
|
|
||||||
Signal.trap('INT') do
|
|
||||||
OpenVPNStatusWeb.logger.info "Quitting..."
|
|
||||||
Rack::Handler::WEBrick.shutdown
|
|
||||||
end
|
end
|
||||||
|
|
||||||
app = Daemon.new(ARGV[0], ARGV[1])
|
puts "openvpn-status-web version #{OpenVPNStatusWeb::VERSION}"
|
||||||
Rack::Handler::WEBrick.run app, :Host => ARGV[2], :Port => ARGV[3]
|
puts "Using config file #{config_file}"
|
||||||
|
|
||||||
|
config = YAML.safe_load(File.read(config_file, mode: 'r'))
|
||||||
|
|
||||||
|
if config['logfile']
|
||||||
|
OpenVPNStatusWeb.logger = Logger.new(config['logfile'])
|
||||||
|
else
|
||||||
|
OpenVPNStatusWeb.logger = Logger.new($stdout)
|
||||||
|
end
|
||||||
|
|
||||||
|
OpenVPNStatusWeb.logger.progname = 'openvpn-status-web'
|
||||||
|
OpenVPNStatusWeb.logger.formatter = LogFormatter.new
|
||||||
|
|
||||||
|
OpenVPNStatusWeb.logger.info 'Starting...'
|
||||||
|
|
||||||
|
# drop priviliges as soon as possible
|
||||||
|
# NOTE: first change group than user
|
||||||
|
if config['group']
|
||||||
|
group = Etc.getgrnam(config['group'])
|
||||||
|
Process::Sys.setgid(group.gid) if group
|
||||||
|
end
|
||||||
|
if config['user']
|
||||||
|
user = Etc.getpwnam(config['user'])
|
||||||
|
Process::Sys.setuid(user.uid) if user
|
||||||
|
end
|
||||||
|
|
||||||
|
# configure rack
|
||||||
|
app = Daemon.new(config['vpns'])
|
||||||
|
if ENV.fetch('RACK_ENV', nil) == 'development'
|
||||||
|
app = BetterErrors::Middleware.new(app)
|
||||||
|
BetterErrors.application_root = File.expand_path(__dir__)
|
||||||
|
end
|
||||||
|
|
||||||
|
Signal.trap('INT') do
|
||||||
|
OpenVPNStatusWeb.logger.info 'Quitting...'
|
||||||
|
Rackup::Handler::WEBrick.shutdown
|
||||||
|
end
|
||||||
|
Signal.trap('TERM') do
|
||||||
|
OpenVPNStatusWeb.logger.info 'Quitting...'
|
||||||
|
Rackup::Handler::WEBrick.shutdown
|
||||||
|
end
|
||||||
|
|
||||||
|
Rackup::Handler::WEBrick.run app, Host: config['host'], Port: config['port']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -1,13 +1,14 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Integer
|
class Integer
|
||||||
def as_bytes
|
def as_bytes
|
||||||
return "1 Byte" if self == 1
|
return '1 Byte' if self == 1
|
||||||
|
|
||||||
label = ["Bytes", "KiB", "MiB", "GiB", "TiB"]
|
label = %w[Bytes KiB MiB GiB TiB]
|
||||||
i = 0
|
i = 0
|
||||||
num = self.to_f
|
num = to_f
|
||||||
while num >= 1024 do
|
while num >= 1024
|
||||||
num = num / 1024
|
num /= 1024
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -42,67 +42,102 @@ thead {
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>OpenVPN Status for <%= name %></h1>
|
<% vpns.each do |name,config| %>
|
||||||
|
<% status = stati[name] %>
|
||||||
|
<h1>OpenVPN Status for <%= name %></h1>
|
||||||
|
|
||||||
<h2>Client List</h2>
|
<h2>Client List</h2>
|
||||||
<div>
|
<div>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<td class="first">Common Name</td>
|
<% status.client_list_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle">Real Address</td>
|
<% if i == 0 %>
|
||||||
<td class="middle">Data Received</td>
|
<td class="first">
|
||||||
<td class="middle">Data Sent</td>
|
<% elsif i == status.client_list_headers.size-1 %>
|
||||||
<td class="last">Connected Since</td>
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<%= header %></td>
|
||||||
|
<% end %>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% client_list.each do |client| %>
|
<% status.client_list.each do |client| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="first"><%= client[0] %></td>
|
<% status.client_list_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle"><%= client[1] %></td>
|
<% if i == 0 %>
|
||||||
<td class="middle"><%= client[2].to_i.as_bytes %></td>
|
<td class="first">
|
||||||
<td class="middle"><%= client[3].to_i.as_bytes %></td>
|
<% elsif i == status.client_list_headers.size-1 %>
|
||||||
<td class="last"><%= client[4] %></td>
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<% if header =~ /(Received|Sent)/ %>
|
||||||
|
<%= client[i].as_bytes %></td>
|
||||||
|
<% elsif client[i].is_a? DateTime %>
|
||||||
|
<%= client[i].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
||||||
|
<% else %>
|
||||||
|
<%= client[i] %></td>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Routing Table</h2>
|
<h2>Routing Table</h2>
|
||||||
<div>
|
<div>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<td class="first">Virtual Address</td>
|
<% status.routing_table_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle">Common Name</td>
|
<% if i == 0 %>
|
||||||
<td class="middle">Real Address</td>
|
<td class="first">
|
||||||
<td class="last">Last Ref</td>
|
<% elsif i == status.routing_table_headers.size-1 %>
|
||||||
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<%= header %></td>
|
||||||
|
<% end %>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% routing_table.each do |e| %>
|
<% status.routing_table.each do |route| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="first"><%= e[0] %></td>
|
<% status.routing_table_headers.each_with_index do |header,i| %>
|
||||||
<td class="middle"><%= e[1] %></td>
|
<% if i == 0 %>
|
||||||
<td class="middle"><%= e[2] %></td>
|
<td class="first">
|
||||||
<td class="last"><%= e[3] %></td>
|
<% elsif i == status.routing_table_headers.size-1 %>
|
||||||
|
<td class="last">
|
||||||
|
<% else %>
|
||||||
|
<td class="middle">
|
||||||
|
<% end %>
|
||||||
|
<% if route[i].is_a? DateTime %>
|
||||||
|
<%= route[i].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
||||||
|
<% else %>
|
||||||
|
<%= route[i] %></td>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Global Stats</h2>
|
<h2>Global Stats</h2>
|
||||||
<div>
|
<div>
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% global_stats.each do |e| %>
|
<% status.global_stats.each do |global| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= e[0] %>:</td>
|
<td><%= global[0] %>:</td>
|
||||||
<td><%= e[1] %></td>
|
<td><%= global[1] %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
55
lib/openvpn-status-web/parser/modern_stateless.rb
Normal file
55
lib/openvpn-status-web/parser/modern_stateless.rb
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module OpenVPNStatusWeb
|
||||||
|
module Parser
|
||||||
|
class ModernStateless
|
||||||
|
def self.parse_status_log(text, sep)
|
||||||
|
status = Status.new
|
||||||
|
status.client_list_headers = []
|
||||||
|
status.client_list = []
|
||||||
|
status.routing_table_headers = []
|
||||||
|
status.routing_table = []
|
||||||
|
status.global_stats = []
|
||||||
|
|
||||||
|
text.lines.each do |line|
|
||||||
|
parts = line.strip.split(sep)
|
||||||
|
status.client_list_headers = parts[2..] if parts[0] == 'HEADER' && parts[1] == 'CLIENT_LIST'
|
||||||
|
status.client_list << parse_client(parts[1..], status.client_list_headers) if parts[0] == 'CLIENT_LIST'
|
||||||
|
status.routing_table_headers = parts[2..] if parts[0] == 'HEADER' && parts[1] == 'ROUTING_TABLE'
|
||||||
|
status.routing_table << parse_route(parts[1..], status.routing_table_headers) if parts[0] == 'ROUTING_TABLE'
|
||||||
|
status.global_stats << parse_global(parts[1..2]) if parts[0] == 'GLOBAL_STATS'
|
||||||
|
end
|
||||||
|
|
||||||
|
status
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method def self.parse_client(client, headers)
|
||||||
|
headers.each_with_index do |header, i|
|
||||||
|
client[i] = parse_date(client[i]) if header.end_with?('Since')
|
||||||
|
client[i] = client[i].to_i if header.start_with?('Bytes')
|
||||||
|
end
|
||||||
|
|
||||||
|
client
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method def self.parse_route(route, headers)
|
||||||
|
headers.each_with_index do |header, i|
|
||||||
|
route[i] = parse_date(route[i]) if header.end_with?('Last Ref')
|
||||||
|
end
|
||||||
|
|
||||||
|
route
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method def self.parse_global(global)
|
||||||
|
global[1] = global[1].to_i
|
||||||
|
global
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method def self.parse_date(date_string)
|
||||||
|
DateTime.strptime(date_string, '%a %b %d %k:%M:%S %Y')
|
||||||
|
rescue ArgumentError
|
||||||
|
DateTime.strptime(date_string, '%Y-%m-%d %k:%M:%S')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
57
lib/openvpn-status-web/parser/v1.rb
Normal file
57
lib/openvpn-status-web/parser/v1.rb
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module OpenVPNStatusWeb
|
||||||
|
module Parser
|
||||||
|
class V1
|
||||||
|
def parse_status_log(text)
|
||||||
|
current_section = :none
|
||||||
|
client_list = []
|
||||||
|
routing_table = []
|
||||||
|
global_stats = []
|
||||||
|
|
||||||
|
text.lines.each do |line|
|
||||||
|
(current_section = :cl; next) if line == "OpenVPN CLIENT LIST\n"
|
||||||
|
(current_section = :rt; next) if line == "ROUTING TABLE\n"
|
||||||
|
(current_section = :gs; next) if line == "GLOBAL STATS\n"
|
||||||
|
(current_section = :end; next) if line == "END\n"
|
||||||
|
|
||||||
|
case current_section
|
||||||
|
when :cl
|
||||||
|
client_list << line.strip.split(',')
|
||||||
|
when :rt
|
||||||
|
routing_table << line.strip.split(',')
|
||||||
|
when :gs
|
||||||
|
global_stats << line.strip.split(',')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
status = Status.new
|
||||||
|
status.client_list_headers = ['Common Name', 'Real Address', 'Data Received', 'Data Sent', 'Connected Since']
|
||||||
|
status.client_list = client_list[2..].map { |client| parse_client(client) }
|
||||||
|
status.routing_table_headers = ['Virtual Address', 'Common Name', 'Real Address', 'Last Ref']
|
||||||
|
status.routing_table = routing_table[1..].map { |route| parse_route(route) }
|
||||||
|
status.global_stats = global_stats.map { |global| parse_global(global) }
|
||||||
|
status
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def parse_client(client)
|
||||||
|
client[2] = client[2].to_i
|
||||||
|
client[3] = client[3].to_i
|
||||||
|
client[4] = DateTime.strptime(client[4], '%a %b %d %k:%M:%S %Y')
|
||||||
|
client
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_route(route)
|
||||||
|
route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y')
|
||||||
|
route
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_global(global)
|
||||||
|
global[1] = global[1].to_i
|
||||||
|
global
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
lib/openvpn-status-web/parser/v2.rb
Normal file
13
lib/openvpn-status-web/parser/v2.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative 'modern_stateless'
|
||||||
|
|
||||||
|
module OpenVPNStatusWeb
|
||||||
|
module Parser
|
||||||
|
class V2
|
||||||
|
def parse_status_log(text)
|
||||||
|
OpenVPNStatusWeb::Parser::ModernStateless.parse_status_log(text, ',')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
lib/openvpn-status-web/parser/v3.rb
Normal file
13
lib/openvpn-status-web/parser/v3.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative 'modern_stateless'
|
||||||
|
|
||||||
|
module OpenVPNStatusWeb
|
||||||
|
module Parser
|
||||||
|
class V3
|
||||||
|
def parse_status_log(text)
|
||||||
|
OpenVPNStatusWeb::Parser::ModernStateless.parse_status_log(text, "\t")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
11
lib/openvpn-status-web/status.rb
Normal file
11
lib/openvpn-status-web/status.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module OpenVPNStatusWeb
|
||||||
|
class Status
|
||||||
|
attr_accessor :client_list_headers
|
||||||
|
attr_accessor :client_list
|
||||||
|
attr_accessor :routing_table_headers
|
||||||
|
attr_accessor :routing_table
|
||||||
|
attr_accessor :global_stats
|
||||||
|
end
|
||||||
|
end
|
@@ -1,4 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
VERSION = "0.0.1"
|
VERSION = '3.4.0'
|
||||||
end
|
end
|
||||||
|
@@ -1,31 +1,45 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
$:.push File.expand_path("../lib", __FILE__)
|
require_relative 'lib/openvpn-status-web/version'
|
||||||
|
|
||||||
require 'openvpn-status-web/version'
|
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'openvpn-status-web'
|
s.name = 'openvpn-status-web'
|
||||||
s.version = OpenVPNStatusWeb::VERSION
|
s.version = OpenVPNStatusWeb::VERSION
|
||||||
s.summary = 'openvpn-status-web'
|
s.summary = 'openvpn-status-web'
|
||||||
s.description = 'Small Rack application that parses and serves the OpenVPN status file.'
|
s.description = 'Small Rack (Ruby) application serving OpenVPN status file.'
|
||||||
s.author = 'Christian Nicolai'
|
s.author = 'Christian Nicolai'
|
||||||
s.email = 'chrnicolai@gmail.com'
|
|
||||||
s.license = 'Apache License Version 2.0'
|
|
||||||
s.homepage = 'https://github.com/cmur2/openvpn-status-web'
|
s.homepage = 'https://github.com/cmur2/openvpn-status-web'
|
||||||
|
s.license = 'Apache-2.0'
|
||||||
|
s.metadata = {
|
||||||
|
'bug_tracker_uri' => "#{s.homepage}/issues",
|
||||||
|
'source_code_uri' => s.homepage
|
||||||
|
}
|
||||||
|
|
||||||
s.files = `git ls-files`.split($/)
|
s.files = `git ls-files -z`.split("\x0").select do |f|
|
||||||
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
f.match(%r{^(init.d|lib)/})
|
||||||
|
end
|
||||||
s.require_paths = ['lib']
|
s.require_paths = ['lib']
|
||||||
|
s.bindir = 'exe'
|
||||||
s.executables = ['openvpn-status-web']
|
s.executables = ['openvpn-status-web']
|
||||||
|
s.extra_rdoc_files = Dir['README.md', 'LICENSE']
|
||||||
|
|
||||||
|
s.required_ruby_version = '>= 2.7'
|
||||||
|
|
||||||
s.add_runtime_dependency 'rack'
|
|
||||||
s.add_runtime_dependency 'json'
|
|
||||||
s.add_runtime_dependency 'metriks'
|
s.add_runtime_dependency 'metriks'
|
||||||
|
s.add_runtime_dependency 'rack', '~> 3.0'
|
||||||
|
s.add_runtime_dependency 'rackup', '~> 2'
|
||||||
|
s.add_runtime_dependency 'webrick', '>= 1.6.1'
|
||||||
|
|
||||||
s.add_development_dependency 'bundler', '~> 1.3'
|
s.add_development_dependency 'better_errors'
|
||||||
|
s.add_development_dependency 'binding_of_caller'
|
||||||
|
s.add_development_dependency 'bundler'
|
||||||
|
s.add_development_dependency 'bundler-audit', '~> 0.9.0'
|
||||||
|
s.add_development_dependency 'rack-test'
|
||||||
s.add_development_dependency 'rake'
|
s.add_development_dependency 'rake'
|
||||||
s.add_development_dependency 'rspec'
|
s.add_development_dependency 'rspec'
|
||||||
s.add_development_dependency 'rack-test'
|
s.add_development_dependency 'rubocop', '~> 1.43.0'
|
||||||
|
s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
||||||
|
s.add_development_dependency 'rubocop-rspec', '~> 2.18.0'
|
||||||
|
s.add_development_dependency 'solargraph', '~> 0.48.0'
|
||||||
end
|
end
|
||||||
|
83
spec/openvpn-status-web/parser/modern_stateless_spec.rb
Normal file
83
spec/openvpn-status-web/parser/modern_stateless_spec.rb
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative '../../spec_helper'
|
||||||
|
|
||||||
|
describe OpenVPNStatusWeb::Parser::ModernStateless do
|
||||||
|
{
|
||||||
|
2 => status_v2,
|
||||||
|
3 => status_v3
|
||||||
|
}.each do |version, status|
|
||||||
|
context "for status-version #{version}" do
|
||||||
|
context 'with client list' do
|
||||||
|
it 'parses common names' do
|
||||||
|
expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses real addresses' do
|
||||||
|
expect(status.client_list.map { |client| client[1] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses virtual addresses' do
|
||||||
|
expect(status.client_list.map { |client| client[2] }).to eq(['192.168.66.2', '2001:db8:0:0::1000'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses received bytes' do
|
||||||
|
expect(status.client_list.map { |client| client[3] }).to eq([11_811_160_064, 512])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses sent bytes' do
|
||||||
|
expect(status.client_list.map { |client| client[4] }).to eq([4_194_304, 2048])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses connected since date' do
|
||||||
|
expect(status.client_list.map { |client| client[5] }).to eq(
|
||||||
|
[
|
||||||
|
DateTime.new(2012, 1, 1, 23, 42, 0),
|
||||||
|
DateTime.new(2012, 1, 1, 23, 42, 0)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.client_list[0].size).to eq(status.client_list_headers.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with routing table' do
|
||||||
|
it 'parses virtual addresses' do
|
||||||
|
expect(status.routing_table.map { |route| route[0] }).to eq(['192.168.0.0/24', '192.168.66.2', '192.168.66.3', '2001:db8:0:0::1000'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses common names' do
|
||||||
|
expect(status.routing_table.map { |route| route[1] }).to eq(%w[foo bar foo bar])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses real addresses' do
|
||||||
|
expect(status.routing_table.map { |route| route[2] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235', '1.2.3.4:1234', '1.2.3.5:1235'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses last ref date' do
|
||||||
|
expect(status.routing_table.map { |route| route[3] }).to eq(
|
||||||
|
[
|
||||||
|
DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0),
|
||||||
|
DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.routing_table[0].size).to eq(status.routing_table_headers.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses global stats' do
|
||||||
|
expect(status.global_stats.size).to eq(1)
|
||||||
|
expect(status.global_stats.first).to eq(['Max bcast/mcast queue length', 42])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses status-version 2 of OpenVPN 2.5' do
|
||||||
|
expect(status_2_5_v2).not_to be_nil
|
||||||
|
end
|
||||||
|
end
|
71
spec/openvpn-status-web/parser/v1_spec.rb
Normal file
71
spec/openvpn-status-web/parser/v1_spec.rb
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative '../../spec_helper'
|
||||||
|
|
||||||
|
describe OpenVPNStatusWeb::Parser::V1 do
|
||||||
|
def status
|
||||||
|
status_v1
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with client list' do
|
||||||
|
it 'parses common names' do
|
||||||
|
expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses real addresses' do
|
||||||
|
expect(status.client_list.map { |client| client[1] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses received bytes' do
|
||||||
|
expect(status.client_list.map { |client| client[2] }).to eq([11_811_160_064, 512])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses sent bytes' do
|
||||||
|
expect(status.client_list.map { |client| client[3] }).to eq([4_194_304, 2048])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses connected since date' do
|
||||||
|
expect(status.client_list.map { |client| client[4] }).to eq(
|
||||||
|
[
|
||||||
|
DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.client_list[0].length).to eq(status.client_list_headers.length)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with routing table' do
|
||||||
|
it 'parses virtual addresses' do
|
||||||
|
expect(status.routing_table.map { |route| route[0] }).to eq(['192.168.0.0/24', '192.168.66.2', '192.168.66.3', '2001:db8:0:0::1000'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses common names' do
|
||||||
|
expect(status.routing_table.map { |route| route[1] }).to eq(%w[foo bar foo bar])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses real addresses' do
|
||||||
|
expect(status.routing_table.map { |route| route[2] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235', '1.2.3.4:1234', '1.2.3.5:1235'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses last ref date' do
|
||||||
|
expect(status.routing_table.map { |route| route[3] }).to eq(
|
||||||
|
[
|
||||||
|
DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0),
|
||||||
|
DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the same number of headers' do
|
||||||
|
expect(status.routing_table[0].length).to eq(status.routing_table_headers.length)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parses global stats' do
|
||||||
|
expect(status.global_stats.size).to eq(1)
|
||||||
|
expect(status.global_stats.first).to eq(['Max bcast/mcast queue length', 42])
|
||||||
|
end
|
||||||
|
end
|
27
spec/spec_helper.rb
Normal file
27
spec/spec_helper.rb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rubygems'
|
||||||
|
require 'bundler/setup'
|
||||||
|
require 'rack/test'
|
||||||
|
|
||||||
|
require 'openvpn-status-web'
|
||||||
|
|
||||||
|
def status_v1
|
||||||
|
text = File.binread('examples/status.v1')
|
||||||
|
OpenVPNStatusWeb::Parser::V1.new.parse_status_log text
|
||||||
|
end
|
||||||
|
|
||||||
|
def status_v2
|
||||||
|
text = File.binread('examples/status.v2')
|
||||||
|
OpenVPNStatusWeb::Parser::V2.new.parse_status_log text
|
||||||
|
end
|
||||||
|
|
||||||
|
def status_2_5_v2
|
||||||
|
text = File.binread('examples/status2_5.v2')
|
||||||
|
OpenVPNStatusWeb::Parser::V2.new.parse_status_log text
|
||||||
|
end
|
||||||
|
|
||||||
|
def status_v3
|
||||||
|
text = File.binread('examples/status.v3')
|
||||||
|
OpenVPNStatusWeb::Parser::V3.new.parse_status_log text
|
||||||
|
end
|
Reference in New Issue
Block a user