Compare commits
170 Commits
Author | SHA1 | Date |
---|---|---|
Christian Nicolai | cc0de6f563 | |
Christian Nicolai | 9933baed66 | |
dependabot[bot] | 6f106dd8ea | |
dependabot[bot] | e17c5bef2d | |
Christian Nicolai | a65bf15ab3 | |
renovate[bot] | 85791c1b74 | |
renovate[bot] | 5162bdaa8a | |
depfu[bot] | 4ead5d4972 | |
cn | d75cf2aade | |
Christian Nicolai | 88b41c8998 | |
depfu[bot] | 6d3d6e8242 | |
depfu[bot] | 45e9fb95cb | |
depfu[bot] | 8d9aac329f | |
depfu[bot] | d2f0de2d8a | |
depfu[bot] | a330744dde | |
depfu[bot] | 932c733203 | |
depfu[bot] | c640431eda | |
cn | b3c776a09d | |
depfu[bot] | 38375fbdf7 | |
depfu[bot] | fc25d49719 | |
depfu[bot] | 0322f9c97d | |
depfu[bot] | 35d78740a7 | |
depfu[bot] | 097f3ea988 | |
depfu[bot] | cb8698b80f | |
depfu[bot] | 90ec76a503 | |
depfu[bot] | 2f02388799 | |
depfu[bot] | 9d80258a8f | |
depfu[bot] | a189922123 | |
depfu[bot] | 9a795fe2f9 | |
depfu[bot] | 4df29aded8 | |
depfu[bot] | 0182d784ce | |
depfu[bot] | b3a5bbb244 | |
cn | 184e0c2a9b | |
depfu[bot] | 91a414c9c4 | |
depfu[bot] | b8f7390ddc | |
depfu[bot] | 3d6bb9c662 | |
depfu[bot] | 89ac867f6e | |
Christian Nicolai | 8e2ac7e677 | |
depfu[bot] | 4a5e258a86 | |
depfu[bot] | 1237f144d5 | |
cn | 65a65081ae | |
cn | 194137adc8 | |
cn | ee06f65e81 | |
depfu[bot] | 075922e484 | |
depfu[bot] | 9ece1e125b | |
depfu[bot] | ba50185f44 | |
depfu[bot] | d57e8b7d2e | |
depfu[bot] | 2d77c0efee | |
depfu[bot] | 4f6725825a | |
depfu[bot] | 8af23da209 | |
depfu[bot] | 78d4c3c8cb | |
depfu[bot] | 39f570ec48 | |
depfu[bot] | 1eb6202a8f | |
depfu[bot] | a329966bc5 | |
depfu[bot] | 575516bd27 | |
depfu[bot] | af253c61f0 | |
depfu[bot] | a804f842df | |
Christian Nicolai | 648b4d94b6 | |
depfu[bot] | 117f70e2e3 | |
depfu[bot] | 1e0444a71d | |
depfu[bot] | 20c6c9176a | |
depfu[bot] | a0ad379b00 | |
depfu[bot] | d8f4931657 | |
depfu[bot] | 6676f47c97 | |
depfu[bot] | 811b928403 | |
depfu[bot] | f4a48b8ce0 | |
depfu[bot] | f985ec1c12 | |
depfu[bot] | 3d10b7d128 | |
depfu[bot] | 27876c7f12 | |
depfu[bot] | 9d584ceb71 | |
depfu[bot] | 1996f1d9b9 | |
depfu[bot] | f342b07495 | |
cn | 557a328336 | |
cn | 057d243db8 | |
depfu[bot] | e3a06fdf6c | |
depfu[bot] | bfe39adaf8 | |
depfu[bot] | 9159a53cce | |
depfu[bot] | 51825eb2da | |
depfu[bot] | 280e2b9ae1 | |
depfu[bot] | 6d56db855f | |
depfu[bot] | 0b782b7dd3 | |
cn | ea7b3a947c | |
cn | eb2bb4d632 | |
cn | 2a9bacf196 | |
cn | 39adc74fbc | |
cn | 9ad59194bd | |
cn | 528709c895 | |
cn | 39d2b3ce94 | |
Christian Nicolai | 406ed867f7 | |
depfu[bot] | 22d9797f55 | |
depfu[bot] | 55aecedef7 | |
depfu[bot] | d401074524 | |
depfu[bot] | ff6572bdac | |
depfu[bot] | b4bf74240b | |
depfu[bot] | fb4b3ca461 | |
depfu[bot] | 8a6722f981 | |
depfu[bot] | 8249b01c95 | |
depfu[bot] | 5d04255a95 | |
depfu[bot] | 846d41d35d | |
depfu[bot] | ce0e80f35f | |
depfu[bot] | 0ec3faf5b4 | |
depfu[bot] | 10a4e757f3 | |
depfu[bot] | f95134c315 | |
depfu[bot] | 7da4cb910f | |
depfu[bot] | 382daa34c6 | |
depfu[bot] | 5338b30e32 | |
depfu[bot] | 47ee407af2 | |
depfu[bot] | 281750d6ea | |
depfu[bot] | 42743a1786 | |
depfu[bot] | 7c94192765 | |
depfu[bot] | a3a65f05bc | |
depfu[bot] | e87a4d86f6 | |
depfu[bot] | 2145e183e3 | |
depfu[bot] | 9e5aa1ff71 | |
depfu[bot] | a99ba901c9 | |
depfu[bot] | cc21291a5c | |
depfu[bot] | ba00407d55 | |
depfu[bot] | 80bd4f8584 | |
cn | e4034073a6 | |
depfu[bot] | f4d17809a2 | |
cn | 08b50d5974 | |
depfu[bot] | f287906240 | |
cn | 27306b831f | |
cn | 1e12701fc3 | |
cn | 597b619b0b | |
cn | 61f7cbd76c | |
cn | 2628c08975 | |
depfu[bot] | 7343081406 | |
cn | ec4d028c03 | |
cn | 12b5153604 | |
cn | 7c0722e875 | |
depfu[bot] | afd7f4fa98 | |
depfu[bot] | 63272da3e3 | |
depfu[bot] | ae7fc1137b | |
depfu[bot] | 1f69dabf5f | |
cn | 0e9c9fea68 | |
cn | 0ffe369ef1 | |
depfu[bot] | c2cac319ae | |
depfu[bot] | 5f343d7873 | |
depfu[bot] | 0a45726857 | |
cn | 109b27fecc | |
cn | b44517ec21 | |
depfu[bot] | 520da15739 | |
depfu[bot] | 9b3a13abef | |
depfu[bot] | b81d61b8d7 | |
cn | 147a905bfc | |
cn | eeed0fa089 | |
cn | 586ae8ae0f | |
depfu[bot] | 075ec1e548 | |
cn | 64ec5e1e56 | |
depfu[bot] | 7597c17e93 | |
Christian Nicolai | ac647a4f21 | |
cn | 78f45f5080 | |
Christian Nicolai | 9aeb1a9ad5 | |
Christian Nicolai | 88c22a6504 | |
depfu[bot] | 289535d753 | |
depfu[bot] | 8d42bdafc1 | |
cn | f8666fdfc2 | |
cn | 41f5d4ed62 | |
cn | 92ee01e5de | |
cn | bf3ba8f7cd | |
cn | 140c60c753 | |
cn | d959e7fe62 | |
cn | 4cde78fe96 | |
Christian Nicolai | 23dd4aa63f | |
Christian Nicolai | 1547db7bc6 | |
Christian Nicolai | b1aa38059f | |
Christian Nicolai | 17054794da | |
cn | ab81c8975e | |
cn | 1804693c15 |
|
@ -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
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "bundler"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
commit-message:
|
||||
prefix: "gems"
|
||||
labels: ["dependabot"]
|
||||
open-pull-requests-limit: 10
|
||||
pull-request-branch-name:
|
||||
separator: "-"
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
extends: [
|
||||
"config:recommended",
|
||||
":dependencyDashboard",
|
||||
":prHourlyLimitNone",
|
||||
":prConcurrentLimitNone",
|
||||
":label(dependency-upgrade)",
|
||||
],
|
||||
schedule: ["before 8am on thursday"],
|
||||
branchPrefix: "renovate-",
|
||||
dependencyDashboardHeader: "View repository job log [here](https://app.renovatebot.com/dashboard#github/cmur2/dyndnsd).",
|
||||
separateMinorPatch: true,
|
||||
commitMessagePrefix: "project: ",
|
||||
commitMessageAction: "update",
|
||||
commitMessageTopic: "{{depName}}",
|
||||
commitMessageExtra: "to {{#if isSingleVersion}}v{{{newVersion}}}{{else}}{{{newValue}}}{{/if}}",
|
||||
packageRules: [
|
||||
// Ruby dependencies are managed by dependabot (previously depfu, until PR creation failed)
|
||||
{
|
||||
matchManagers: ["bundler"],
|
||||
enabled: false,
|
||||
},
|
||||
// Commit message formats
|
||||
{
|
||||
matchDatasources: ["docker"],
|
||||
commitMessagePrefix: "docker: ",
|
||||
},
|
||||
{
|
||||
matchManagers: ["github-actions"],
|
||||
commitMessagePrefix: "ci: ",
|
||||
},
|
||||
],
|
||||
customManagers: [
|
||||
{
|
||||
customType: "regex",
|
||||
fileMatch: ["\.rb$", "^Rakefile$"],
|
||||
matchStrings: [
|
||||
"renovate: datasource=(?<datasource>.*?) depName=(?<depName>.*?)\\s.*_version = '(?<currentValue>.*)'\\s"
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
|
@ -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:
|
||||
- '3.0'
|
||||
- '3.1'
|
||||
- '3.2'
|
||||
- '3.3'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- 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,3 +1,4 @@
|
|||
.DS_Store
|
||||
*.lock
|
||||
pkg/*
|
||||
.yardoc
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
require:
|
||||
- rubocop-rake
|
||||
- rubocop-rspec
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 3.0'
|
||||
NewCops: enable
|
||||
|
||||
Gemspec/DevelopmentDependencies:
|
||||
EnforcedStyle: gemspec
|
||||
|
||||
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:
|
||||
Enabled: false
|
||||
|
||||
RSpec/SpecFilePathFormat:
|
||||
CustomTransform:
|
||||
OpenVPNStatusWeb: openvpn-status-web
|
||||
|
||||
RSpec/MultipleExpectations:
|
||||
Max: 5
|
|
@ -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,7 +0,0 @@
|
|||
---
|
||||
sudo: false
|
||||
language: ruby
|
||||
rvm:
|
||||
- 2.5
|
||||
- 2.4
|
||||
- 2.3
|
2
Gemfile
2
Gemfile
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gemspec
|
||||
|
|
34
README.md
34
README.md
|
@ -1,6 +1,6 @@
|
|||
# openvpn-status-web
|
||||
|
||||
[![Build Status](https://travis-ci.org/cmur2/openvpn-status-web.png)](https://travis-ci.org/cmur2/openvpn-status-web)
|
||||
![ci](https://github.com/cmur2/openvpn-status-web/workflows/ci/badge.svg)
|
||||
|
||||
## Description
|
||||
|
||||
|
@ -57,10 +57,36 @@ For more information about OpenVPN status file and version, see their [man page]
|
|||
|
||||
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.
|
||||
|
||||
### Init scripts
|
||||
### Startup
|
||||
|
||||
The [Debian 6 init.d script](init.d/debian-6-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.
|
||||
There is a [Dockerfile](docs/Dockerfile) that can be used to build a Docker image for running openvpn-status-web.
|
||||
|
||||
This can for example be used with `docker-compose` via:
|
||||
|
||||
```yaml
|
||||
version: "2.4"
|
||||
services:
|
||||
openvpn-status-web:
|
||||
image: your-selfbuilt-docker-image
|
||||
user: root # needed since the default status files are chmod 600
|
||||
volumes:
|
||||
- /path/to/host/config.yml:/etc/openvpn-status-web/config.yml:ro
|
||||
- /run/openvpn-server:/run/openvpn-server
|
||||
ports:
|
||||
- "8080:8080"
|
||||
```
|
||||
|
||||
The `/path/to/host/config.yml` could be:
|
||||
|
||||
```yaml
|
||||
host: "0.0.0.0"
|
||||
port: "8080"
|
||||
vpns:
|
||||
my-cool-vpn: # the following depends on your setup
|
||||
version: 2
|
||||
status_file: "/run/openvpn-server/status-my-cool-vpn.log"
|
||||
```
|
||||
|
||||
## 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 'rspec/core/rake_task'
|
||||
require 'rubocop/rake_task'
|
||||
require 'bundler/audit/task'
|
||||
|
||||
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]
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
FROM alpine:3.19
|
||||
|
||||
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"]
|
|
@ -1,8 +1,8 @@
|
|||
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
|
||||
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,bar,1.2.3.5:1235,512,2048,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,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)
|
||||
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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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
|
||||
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 bar 1.2.3.5:1235 512 2048 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 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)
|
||||
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
|
||||
|
|
|
@ -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'
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'date'
|
||||
require 'etc'
|
||||
|
@ -6,9 +7,10 @@ require 'logger'
|
|||
require 'ipaddr'
|
||||
require 'yaml'
|
||||
require 'rack'
|
||||
require 'rackup'
|
||||
require 'erb'
|
||||
require 'metriks'
|
||||
require 'better_errors' if ENV['RACK_ENV'] == "development"
|
||||
require 'better_errors' if ENV.fetch('RACK_ENV', nil) == 'development'
|
||||
|
||||
require 'openvpn-status-web/status'
|
||||
require 'openvpn-status-web/parser/v1'
|
||||
|
@ -18,17 +20,25 @@ require 'openvpn-status-web/int_patch'
|
|||
require 'openvpn-status-web/version'
|
||||
|
||||
module OpenVPNStatusWeb
|
||||
# @return [Logger]
|
||||
def self.logger
|
||||
@logger
|
||||
end
|
||||
|
||||
# @param logger [Logger]
|
||||
# @return [Logger]
|
||||
def self.logger=(logger)
|
||||
@logger = logger
|
||||
end
|
||||
|
||||
class LogFormatter
|
||||
def call(lvl, time, progname, msg)
|
||||
"[%s] %-5s %s\n" % [Time.now.strftime('%Y-%m-%d %H:%M:%S'), lvl, msg.to_s]
|
||||
# @param lvl [Object]
|
||||
# @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
|
||||
|
||||
|
@ -40,29 +50,29 @@ module OpenVPNStatusWeb
|
|||
end
|
||||
|
||||
def call(env)
|
||||
return [405, {"Content-Type" => "text/plain"}, ["Method Not Allowed"]] if env["REQUEST_METHOD"] != "GET"
|
||||
return [404, {"Content-Type" => "text/plain"}, ["Not Found"]] if env["PATH_INFO"] != "/"
|
||||
return [405, {'Content-Type' => 'text/plain'}, ['Method Not Allowed']] if env['REQUEST_METHOD'] != 'GET'
|
||||
return [404, {'Content-Type' => 'text/plain'}, ['Not Found']] if env['PATH_INFO'] != '/'
|
||||
|
||||
# variables for template
|
||||
vpns = @vpns
|
||||
stati = {}
|
||||
@vpns.each do |name,config|
|
||||
@vpns.each do |name, config|
|
||||
stati[name] = parse_status_log(config)
|
||||
end
|
||||
# eval
|
||||
html = @main_tmpl.result(binding)
|
||||
|
||||
[200, {"Content-Type" => "text/html"}, [html]]
|
||||
[200, {'Content-Type' => 'text/html'}, [html]]
|
||||
end
|
||||
|
||||
def read_template(file)
|
||||
text = File.open(file, 'rb') do |f| f.read end
|
||||
|
||||
text = File.read(file, mode: 'rb')
|
||||
|
||||
ERB.new(text)
|
||||
end
|
||||
|
||||
|
||||
def parse_status_log(vpn)
|
||||
text = File.open(vpn['status_file'], 'rb') do |f| f.read end
|
||||
text = File.read(vpn['status_file'], mode: 'rb')
|
||||
|
||||
case vpn['version']
|
||||
when 1
|
||||
|
@ -76,56 +86,64 @@ module OpenVPNStatusWeb
|
|||
end
|
||||
end
|
||||
|
||||
# @return [void]
|
||||
def self.run!
|
||||
if ARGV.length != 1
|
||||
puts "Usage: openvpn-status-web config_file"
|
||||
puts 'Usage: openvpn-status-web config_file'
|
||||
exit 1
|
||||
end
|
||||
|
||||
config_file = ARGV[0]
|
||||
|
||||
if not File.file?(config_file)
|
||||
puts "Config file not found!"
|
||||
if !File.file?(config_file)
|
||||
puts 'Config file not found!'
|
||||
exit 1
|
||||
end
|
||||
|
||||
|
||||
puts "openvpn-status-web version #{OpenVPNStatusWeb::VERSION}"
|
||||
puts "Using config file #{config_file}"
|
||||
|
||||
config = YAML::load(File.open(config_file, 'r') { |f| f.read })
|
||||
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)
|
||||
OpenVPNStatusWeb.logger = Logger.new($stdout)
|
||||
end
|
||||
|
||||
OpenVPNStatusWeb.logger.progname = "openvpn-status-web"
|
||||
OpenVPNStatusWeb.logger.progname = 'openvpn-status-web'
|
||||
OpenVPNStatusWeb.logger.formatter = LogFormatter.new
|
||||
|
||||
OpenVPNStatusWeb.logger.info "Starting..."
|
||||
OpenVPNStatusWeb.logger.info 'Starting...'
|
||||
|
||||
# drop privs (first change group than user)
|
||||
Process::Sys.setgid(Etc.getgrnam(config['group']).gid) if config['group']
|
||||
Process::Sys.setuid(Etc.getpwnam(config['user']).uid) if config['user']
|
||||
# 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['RACK_ENV'] == "development"
|
||||
if ENV.fetch('RACK_ENV', nil) == 'development'
|
||||
app = BetterErrors::Middleware.new(app)
|
||||
BetterErrors.application_root = File.expand_path("..", __FILE__)
|
||||
BetterErrors.application_root = File.expand_path(__dir__)
|
||||
end
|
||||
|
||||
Signal.trap('INT') do
|
||||
OpenVPNStatusWeb.logger.info "Quitting..."
|
||||
Rack::Handler::WEBrick.shutdown
|
||||
OpenVPNStatusWeb.logger.info 'Quitting...'
|
||||
Rackup::Handler::WEBrick.shutdown
|
||||
end
|
||||
Signal.trap('TERM') do
|
||||
OpenVPNStatusWeb.logger.info "Quitting..."
|
||||
Rack::Handler::WEBrick.shutdown
|
||||
OpenVPNStatusWeb.logger.info 'Quitting...'
|
||||
Rackup::Handler::WEBrick.shutdown
|
||||
end
|
||||
|
||||
Rack::Handler::WEBrick.run app, :Host => config['host'], :Port => config['port']
|
||||
|
||||
Rackup::Handler::WEBrick.run app, Host: config['host'], Port: config['port']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Integer
|
||||
def as_bytes
|
||||
return "1 Byte" if self == 1
|
||||
|
||||
label = ["Bytes", "KiB", "MiB", "GiB", "TiB"]
|
||||
return '1 Byte' if self == 1
|
||||
|
||||
label = %w[Bytes KiB MiB GiB TiB]
|
||||
i = 0
|
||||
num = self.to_f
|
||||
while num >= 1024 do
|
||||
num = num / 1024
|
||||
num = to_f
|
||||
while num >= 1024
|
||||
num /= 1024
|
||||
i += 1
|
||||
end
|
||||
|
||||
|
||||
"#{format('%.2f', num)} #{label[i]}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,20 +50,36 @@ thead {
|
|||
<div>
|
||||
<table>
|
||||
<thead>
|
||||
<td class="first">Common Name</td>
|
||||
<td class="middle">Real Address</td>
|
||||
<td class="middle">Data Received</td>
|
||||
<td class="middle">Data Sent</td>
|
||||
<td class="last">Connected Since</td>
|
||||
<% status.client_list_headers.each_with_index do |header,i| %>
|
||||
<% if i == 0 %>
|
||||
<td class="first">
|
||||
<% elsif i == status.client_list_headers.size-1 %>
|
||||
<td class="last">
|
||||
<% else %>
|
||||
<td class="middle">
|
||||
<% end %>
|
||||
<%= header %></td>
|
||||
<% end %>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% status.client_list.each do |client| %>
|
||||
<tr>
|
||||
<td class="first"><%= client[0] %></td>
|
||||
<td class="middle"><%= client[1] %></td>
|
||||
<td class="middle"><%= client[2].to_i.as_bytes %></td>
|
||||
<td class="middle"><%= client[3].to_i.as_bytes %></td>
|
||||
<td class="last"><%= client[4].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
||||
<% status.client_list_headers.each_with_index do |header,i| %>
|
||||
<% if i == 0 %>
|
||||
<td class="first">
|
||||
<% elsif i == status.client_list_headers.size-1 %>
|
||||
<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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
@ -74,18 +90,34 @@ thead {
|
|||
<div>
|
||||
<table>
|
||||
<thead>
|
||||
<td class="first">Virtual Address</td>
|
||||
<td class="middle">Common Name</td>
|
||||
<td class="middle">Real Address</td>
|
||||
<td class="last">Last Ref</td>
|
||||
<% status.routing_table_headers.each_with_index do |header,i| %>
|
||||
<% if i == 0 %>
|
||||
<td class="first">
|
||||
<% elsif i == status.routing_table_headers.size-1 %>
|
||||
<td class="last">
|
||||
<% else %>
|
||||
<td class="middle">
|
||||
<% end %>
|
||||
<%= header %></td>
|
||||
<% end %>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% status.routing_table.each do |route| %>
|
||||
<tr>
|
||||
<td class="first"><%= route[0] %></td>
|
||||
<td class="middle"><%= route[1] %></td>
|
||||
<td class="middle"><%= route[2] %></td>
|
||||
<td class="last"><%= route[3].strftime('%-d.%-m.%Y %H:%M:%S') %></td>
|
||||
<% status.routing_table_headers.each_with_index do |header,i| %>
|
||||
<% if i == 0 %>
|
||||
<td class="first">
|
||||
<% 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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
@ -1,41 +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 << parse_client(parts[1..5]) if parts[0] == "CLIENT_LIST"
|
||||
status.routing_table << parse_route(parts[1..4]) if parts[0] == "ROUTING_TABLE"
|
||||
status.global_stats << parse_global(parts[1..2]) if parts[0] == "GLOBAL_STATS"
|
||||
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
|
||||
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
|
||||
|
||||
def self.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 self.parse_route(route)
|
||||
route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y')
|
||||
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
|
||||
|
||||
def self.parse_global(global)
|
||||
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
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module OpenVPNStatusWeb
|
||||
module Parser
|
||||
|
@ -13,7 +14,7 @@ module OpenVPNStatusWeb
|
|||
(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(',')
|
||||
|
@ -25,8 +26,10 @@ module OpenVPNStatusWeb
|
|||
end
|
||||
|
||||
status = Status.new
|
||||
status.client_list = client_list[2..-1].map { |client| parse_client(client) }
|
||||
status.routing_table = routing_table[1..-1].map { |route| parse_route(route) }
|
||||
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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'openvpn-status-web/parser/modern_stateless'
|
||||
require_relative 'modern_stateless'
|
||||
|
||||
module OpenVPNStatusWeb
|
||||
module Parser
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'openvpn-status-web/parser/modern_stateless'
|
||||
require_relative 'modern_stateless'
|
||||
|
||||
module OpenVPNStatusWeb
|
||||
module Parser
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# 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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module OpenVPNStatusWeb
|
||||
VERSION = "2.0.0"
|
||||
VERSION = '3.4.0'
|
||||
end
|
||||
|
|
|
@ -1,32 +1,45 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
||||
|
||||
require 'openvpn-status-web/version'
|
||||
require_relative 'lib/openvpn-status-web/version'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'openvpn-status-web'
|
||||
s.name = 'openvpn-status-web'
|
||||
s.version = OpenVPNStatusWeb::VERSION
|
||||
s.summary = 'openvpn-status-web'
|
||||
s.description = 'Small Rack (Ruby) application serving OpenVPN status file.'
|
||||
s.author = 'Christian Nicolai'
|
||||
s.email = 'chrnicolai@gmail.com'
|
||||
s.homepage = 'https://github.com/cmur2/dyndnsd'
|
||||
|
||||
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($INPUT_RECORD_SEPARATOR)
|
||||
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
||||
s.files = `git ls-files -z`.split("\x0").select do |f|
|
||||
f.match(%r{^(init.d|lib)/})
|
||||
end
|
||||
s.require_paths = ['lib']
|
||||
s.bindir = 'exe'
|
||||
s.executables = ['openvpn-status-web']
|
||||
s.extra_rdoc_files = Dir['README.md', 'LICENSE']
|
||||
|
||||
s.required_ruby_version = '>= 2.3'
|
||||
s.required_ruby_version = '>= 3.0'
|
||||
|
||||
s.add_runtime_dependency 'rack', '~> 2.0'
|
||||
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'
|
||||
s.add_development_dependency 'rake'
|
||||
s.add_development_dependency 'rspec'
|
||||
s.add_development_dependency 'rack-test'
|
||||
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 'rspec'
|
||||
s.add_development_dependency 'rubocop', '~> 1.63.5'
|
||||
s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
||||
s.add_development_dependency 'rubocop-rspec', '~> 2.29.2'
|
||||
s.add_development_dependency 'solargraph', '~> 0.50.0'
|
||||
end
|
||||
|
|
|
@ -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 "when 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
|
|
@ -1,50 +1,71 @@
|
|||
require 'spec_helper'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../spec_helper'
|
||||
|
||||
describe OpenVPNStatusWeb::Parser::V1 do
|
||||
def status; status_v1; end
|
||||
def status
|
||||
status_v1
|
||||
end
|
||||
|
||||
context 'for client list' do
|
||||
context 'with client list' do
|
||||
it 'parses common names' do
|
||||
expect(status.client_list.map { |client| client[0] }).to eq(["foo", "bar"])
|
||||
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"])
|
||||
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([11811160064, 512])
|
||||
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([4194304, 2048])
|
||||
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)])
|
||||
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 'for routing table' do
|
||||
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"])
|
||||
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(["foo", "bar", "foo", "bar"])
|
||||
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"])
|
||||
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)])
|
||||
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])
|
||||
expect(status.global_stats.first).to eq(['Max bcast/mcast queue length', 42])
|
||||
end
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe OpenVPNStatusWeb::Parser::ModernStateless do
|
||||
{
|
||||
2 => status_v2,
|
||||
3 => status_v3
|
||||
}.each do |version, status|
|
||||
context "for status-version #{version}" do
|
||||
context 'for client list' do
|
||||
it 'parses common names' do
|
||||
expect(status.client_list.map { |client| client[0] }).to eq(["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([11811160064, 512])
|
||||
end
|
||||
|
||||
it 'parses sent bytes' do
|
||||
expect(status.client_list.map { |client| client[3] }).to eq([4194304, 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
|
||||
end
|
||||
|
||||
context 'for 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(["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
|
||||
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
|
||||
end
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rubygems'
|
||||
require 'bundler/setup'
|
||||
|
@ -6,16 +7,21 @@ require 'rack/test'
|
|||
require 'openvpn-status-web'
|
||||
|
||||
def status_v1
|
||||
text = File.open('examples/status.v1', 'rb') do |f| f.read end
|
||||
text = File.binread('examples/status.v1')
|
||||
OpenVPNStatusWeb::Parser::V1.new.parse_status_log text
|
||||
end
|
||||
|
||||
def status_v2
|
||||
text = File.open('examples/status.v2', 'rb') do |f| f.read end
|
||||
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.open('examples/status.v3', 'rb') do |f| f.read end
|
||||
text = File.binread('examples/status.v3')
|
||||
OpenVPNStatusWeb::Parser::V3.new.parse_status_log text
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue