mirror of
https://github.com/cmur2/openvpn-status-web.git
synced 2025-09-28 21:52:05 +02:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
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
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
*.lock
|
*.lock
|
||||||
pkg/*
|
pkg/*
|
||||||
|
.yardoc
|
||||||
|
88
.rubocop.yml
Normal file
88
.rubocop.yml
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
AllCops:
|
||||||
|
TargetRubyVersion: '2.5'
|
||||||
|
NewCops: enable
|
||||||
|
|
||||||
|
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
|
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
|
12
.travis.yml
12
.travis.yml
@@ -1,8 +1,10 @@
|
|||||||
|
---
|
||||||
|
os: linux
|
||||||
language: ruby
|
language: ruby
|
||||||
|
|
||||||
rvm:
|
rvm:
|
||||||
- 2.0.0
|
- 2.7
|
||||||
- 1.9.3
|
- 2.6
|
||||||
|
- 2.5
|
||||||
|
|
||||||
gemfile:
|
script:
|
||||||
- Gemfile
|
- bundle exec rake travis
|
||||||
|
2
Gemfile
2
Gemfile
@@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
|||||||
# openvpn-status-web
|
# openvpn-status-web
|
||||||
|
|
||||||
[](https://travis-ci.org/cmur2/openvpn-status-web)
|
[](https://travis-ci.org/cmur2/openvpn-status-web) [](https://depfu.com/github/cmur2/openvpn-status-web?project_id=6194)
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
@@ -57,10 +57,12 @@ 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.
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
20
Rakefile
20
Rakefile
@@ -1,6 +1,24 @@
|
|||||||
|
# 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 'Should be run by developer once to prepare initial solargraph usage (fill caches etc.)'
|
||||||
|
task :'solargraph:init' do
|
||||||
|
sh 'solargraph download-core'
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Run experimental solargraph type checker'
|
||||||
|
task :'solargraph:tc' do
|
||||||
|
sh 'solargraph typecheck'
|
||||||
|
end
|
||||||
|
|
||||||
|
task default: [:rubocop, :spec, 'bundle:audit']
|
||||||
|
|
||||||
|
task travis: [:default, :'solargraph:init', :'solargraph:tc']
|
||||||
|
15
docs/Dockerfile
Normal file
15
docs/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM alpine:3.12
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
ENV VERSION=3.0.1
|
||||||
|
|
||||||
|
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,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'openvpn-status-web'
|
require 'openvpn-status-web'
|
||||||
|
|
75
lib/openvpn-status-web.rb
Normal file → Executable file
75
lib/openvpn-status-web.rb
Normal file → Executable file
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'date'
|
require 'date'
|
||||||
require 'etc'
|
require 'etc'
|
||||||
@@ -8,7 +9,7 @@ require 'yaml'
|
|||||||
require 'rack'
|
require 'rack'
|
||||||
require 'erb'
|
require 'erb'
|
||||||
require 'metriks'
|
require 'metriks'
|
||||||
require 'better_errors' if ENV['RACK_ENV'] == "development"
|
require 'better_errors' if ENV['RACK_ENV'] == 'development'
|
||||||
|
|
||||||
require 'openvpn-status-web/status'
|
require 'openvpn-status-web/status'
|
||||||
require 'openvpn-status-web/parser/v1'
|
require 'openvpn-status-web/parser/v1'
|
||||||
@@ -18,17 +19,25 @@ 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
|
||||||
|
|
||||||
@@ -40,29 +49,29 @@ module OpenVPNStatusWeb
|
|||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
return [405, {"Content-Type" => "text/plain"}, ["Method Not Allowed"]] if env["REQUEST_METHOD"] != "GET"
|
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 [404, {'Content-Type' => 'text/plain'}, ['Not Found']] if env['PATH_INFO'] != '/'
|
||||||
|
|
||||||
# variables for template
|
# variables for template
|
||||||
vpns = @vpns
|
vpns = @vpns
|
||||||
stati = {}
|
stati = {}
|
||||||
@vpns.each do |name,config|
|
@vpns.each do |name, config|
|
||||||
stati[name] = parse_status_log(config)
|
stati[name] = parse_status_log(config)
|
||||||
end
|
end
|
||||||
# eval
|
# eval
|
||||||
html = @main_tmpl.result(binding)
|
html = @main_tmpl.result(binding)
|
||||||
|
|
||||||
[200, {"Content-Type" => "text/html"}, [html]]
|
[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 parse_status_log(vpn)
|
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']
|
case vpn['version']
|
||||||
when 1
|
when 1
|
||||||
@@ -76,52 +85,64 @@ module OpenVPNStatusWeb
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [void]
|
||||||
def self.run!
|
def self.run!
|
||||||
if ARGV.length != 1
|
if ARGV.length != 1
|
||||||
puts "Usage: openvpn-status-web config_file"
|
puts 'Usage: openvpn-status-web config_file'
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
config_file = ARGV[0]
|
config_file = ARGV[0]
|
||||||
|
|
||||||
if not File.file?(config_file)
|
if !File.file?(config_file)
|
||||||
puts "Config file not found!"
|
puts 'Config file not found!'
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "openvpn-status-web version #{OpenVPNStatusWeb::VERSION}"
|
puts "openvpn-status-web version #{OpenVPNStatusWeb::VERSION}"
|
||||||
puts "Using config file #{config_file}"
|
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']
|
if config['logfile']
|
||||||
OpenVPNStatusWeb.logger = Logger.new(config['logfile'])
|
OpenVPNStatusWeb.logger = Logger.new(config['logfile'])
|
||||||
else
|
else
|
||||||
OpenVPNStatusWeb.logger = Logger.new(STDOUT)
|
OpenVPNStatusWeb.logger = Logger.new($stdout)
|
||||||
end
|
end
|
||||||
|
|
||||||
OpenVPNStatusWeb.logger.progname = "openvpn-status-web"
|
OpenVPNStatusWeb.logger.progname = 'openvpn-status-web'
|
||||||
OpenVPNStatusWeb.logger.formatter = LogFormatter.new
|
OpenVPNStatusWeb.logger.formatter = LogFormatter.new
|
||||||
|
|
||||||
OpenVPNStatusWeb.logger.info "Starting..."
|
OpenVPNStatusWeb.logger.info 'Starting...'
|
||||||
|
|
||||||
# drop privs (first change group than user)
|
# drop priviliges as soon as possible
|
||||||
Process::Sys.setgid(Etc.getgrnam(config['group']).gid) if config['group']
|
# NOTE: first change group than user
|
||||||
Process::Sys.setuid(Etc.getpwnam(config['user']).uid) if config['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
|
# configure rack
|
||||||
app = Daemon.new(config['vpns'])
|
app = Daemon.new(config['vpns'])
|
||||||
if ENV['RACK_ENV'] == "development"
|
if ENV['RACK_ENV'] == 'development'
|
||||||
app = BetterErrors::Middleware.new(app)
|
app = BetterErrors::Middleware.new(app)
|
||||||
BetterErrors.application_root = File.expand_path("..", __FILE__)
|
BetterErrors.application_root = File.expand_path(__dir__)
|
||||||
end
|
end
|
||||||
|
|
||||||
Signal.trap('INT') do
|
Signal.trap('INT') do
|
||||||
OpenVPNStatusWeb.logger.info "Quitting..."
|
OpenVPNStatusWeb.logger.info 'Quitting...'
|
||||||
Rack::Handler::WEBrick.shutdown
|
Rack::Handler::WEBrick.shutdown
|
||||||
end
|
end
|
||||||
|
Signal.trap('TERM') do
|
||||||
Rack::Handler::WEBrick.run app, :Host => config['host'], :Port => config['port']
|
OpenVPNStatusWeb.logger.info 'Quitting...'
|
||||||
|
Rack::Handler::WEBrick.shutdown
|
||||||
|
end
|
||||||
|
|
||||||
|
Rack::Handler::WEBrick.run app, Host: config['host'], Port: config['port']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -1,16 +1,17 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
"#{format('%.2f', num)} #{label[i]}"
|
"#{format('%.2f', num)} #{label[i]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
module Parser
|
module Parser
|
||||||
@@ -10,29 +11,27 @@ module OpenVPNStatusWeb
|
|||||||
|
|
||||||
text.lines.each do |line|
|
text.lines.each do |line|
|
||||||
parts = line.strip.split(sep)
|
parts = line.strip.split(sep)
|
||||||
status.client_list << parse_client(parts[1..5]) if parts[0] == "CLIENT_LIST"
|
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.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.global_stats << parse_global(parts[1..2]) if parts[0] == 'GLOBAL_STATS'
|
||||||
end
|
end
|
||||||
|
|
||||||
status
|
status
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private_class_method def self.parse_client(client)
|
||||||
|
|
||||||
def self.parse_client(client)
|
|
||||||
client[2] = client[2].to_i
|
client[2] = client[2].to_i
|
||||||
client[3] = client[3].to_i
|
client[3] = client[3].to_i
|
||||||
client[4] = DateTime.strptime(client[4], '%a %b %d %k:%M:%S %Y')
|
client[4] = DateTime.strptime(client[4], '%a %b %d %k:%M:%S %Y')
|
||||||
client
|
client
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parse_route(route)
|
private_class_method def self.parse_route(route)
|
||||||
route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y')
|
route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y')
|
||||||
route
|
route
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parse_global(global)
|
private_class_method def self.parse_global(global)
|
||||||
global[1] = global[1].to_i
|
global[1] = global[1].to_i
|
||||||
global
|
global
|
||||||
end
|
end
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
module Parser
|
module Parser
|
||||||
@@ -13,7 +14,7 @@ module OpenVPNStatusWeb
|
|||||||
(current_section = :rt; next) if line == "ROUTING TABLE\n"
|
(current_section = :rt; next) if line == "ROUTING TABLE\n"
|
||||||
(current_section = :gs; next) if line == "GLOBAL STATS\n"
|
(current_section = :gs; next) if line == "GLOBAL STATS\n"
|
||||||
(current_section = :end; next) if line == "END\n"
|
(current_section = :end; next) if line == "END\n"
|
||||||
|
|
||||||
case current_section
|
case current_section
|
||||||
when :cl
|
when :cl
|
||||||
client_list << line.strip.split(',')
|
client_list << line.strip.split(',')
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'openvpn-status-web/parser/modern_stateless'
|
require_relative 'modern_stateless'
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
module Parser
|
module Parser
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'openvpn-status-web/parser/modern_stateless'
|
require_relative 'modern_stateless'
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
module Parser
|
module Parser
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
class Status
|
class Status
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module OpenVPNStatusWeb
|
module OpenVPNStatusWeb
|
||||||
VERSION = "1.0.1"
|
VERSION = '3.0.1'
|
||||||
end
|
end
|
||||||
|
@@ -1,32 +1,42 @@
|
|||||||
|
# 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 (Ruby) application serving 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.files = `git ls-files`.split($/)
|
s.homepage = 'https://github.com/cmur2/openvpn-status-web'
|
||||||
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
s.license = 'Apache-2.0'
|
||||||
|
s.metadata = {
|
||||||
|
'bug_tracker_uri' => "#{s.homepage}/issues",
|
||||||
|
'source_code_uri' => s.homepage
|
||||||
|
}
|
||||||
|
|
||||||
|
s.files = `git ls-files -z`.split("\x0").select do |f|
|
||||||
|
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.5'
|
||||||
|
|
||||||
s.add_runtime_dependency 'rack'
|
|
||||||
s.add_runtime_dependency 'metriks'
|
s.add_runtime_dependency 'metriks'
|
||||||
|
s.add_runtime_dependency 'rack', '~> 2.0'
|
||||||
|
s.add_runtime_dependency 'webrick', '>= 1.6.1'
|
||||||
|
|
||||||
s.add_development_dependency 'bundler', '~> 1.3'
|
|
||||||
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 'better_errors'
|
||||||
s.add_development_dependency 'binding_of_caller'
|
s.add_development_dependency 'binding_of_caller'
|
||||||
|
s.add_development_dependency 'bundler'
|
||||||
|
s.add_development_dependency 'bundler-audit', '~> 0.7.0'
|
||||||
|
s.add_development_dependency 'rack-test'
|
||||||
|
s.add_development_dependency 'rake'
|
||||||
|
s.add_development_dependency 'rspec'
|
||||||
|
s.add_development_dependency 'rubocop', '~> 0.92.0'
|
||||||
|
s.add_development_dependency 'solargraph'
|
||||||
end
|
end
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
require 'spec_helper'
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe OpenVPNStatusWeb::Parser::ModernStateless do
|
describe OpenVPNStatusWeb::Parser::ModernStateless do
|
||||||
{
|
{
|
||||||
@@ -8,47 +10,56 @@ describe OpenVPNStatusWeb::Parser::ModernStateless do
|
|||||||
context "for status-version #{version}" do
|
context "for status-version #{version}" do
|
||||||
context 'for client list' do
|
context 'for client list' do
|
||||||
it 'parses common names' do
|
it 'parses common names' do
|
||||||
status.client_list.map { |client| client[0] }.should be == ["foo", "bar"]
|
expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses real addresses' do
|
it 'parses real addresses' do
|
||||||
status.client_list.map { |client| client[1] }.should be == ["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
|
end
|
||||||
|
|
||||||
it 'parses received bytes' do
|
it 'parses received bytes' do
|
||||||
status.client_list.map { |client| client[2] }.should be == [11811160064, 512]
|
expect(status.client_list.map { |client| client[2] }).to eq([11_811_160_064, 512])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses sent bytes' do
|
it 'parses sent bytes' do
|
||||||
status.client_list.map { |client| client[3] }.should be == [4194304, 2048]
|
expect(status.client_list.map { |client| client[3] }).to eq([4_194_304, 2048])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses connected since date' do
|
it 'parses connected since date' do
|
||||||
status.client_list.map { |client| client[4] }.should be == [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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for routing table' do
|
context 'for routing table' do
|
||||||
it 'parses virtual addresses' do
|
it 'parses virtual addresses' do
|
||||||
status.routing_table.map { |route| route[0] }.should be == ["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
|
end
|
||||||
|
|
||||||
it 'parses common names' do
|
it 'parses common names' do
|
||||||
status.routing_table.map { |route| route[1] }.should be == ["foo", "bar", "foo", "bar"]
|
expect(status.routing_table.map { |route| route[1] }).to eq(%w[foo bar foo bar])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses real addresses' do
|
it 'parses real addresses' do
|
||||||
status.routing_table.map { |route| route[2] }.should be == ["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
|
end
|
||||||
|
|
||||||
it 'parses last ref date' do
|
it 'parses last ref date' do
|
||||||
status.routing_table.map { |route| route[3] }.should be == [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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses global stats' do
|
it 'parses global stats' do
|
||||||
status.global_stats.size.should be == 1
|
expect(status.global_stats.size).to eq(1)
|
||||||
status.global_stats.first.should be == ["Max bcast/mcast queue length", 42]
|
expect(status.global_stats.first).to eq(['Max bcast/mcast queue length', 42])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -1,50 +1,63 @@
|
|||||||
require 'spec_helper'
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
describe OpenVPNStatusWeb::Parser::V1 do
|
describe OpenVPNStatusWeb::Parser::V1 do
|
||||||
def status; status_v1; end
|
def status
|
||||||
|
status_v1
|
||||||
|
end
|
||||||
|
|
||||||
context 'for client list' do
|
context 'for client list' do
|
||||||
it 'parses common names' do
|
it 'parses common names' do
|
||||||
status.client_list.map { |client| client[0] }.should be == ["foo", "bar"]
|
expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses real addresses' do
|
it 'parses real addresses' do
|
||||||
status.client_list.map { |client| client[1] }.should be == ["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
|
end
|
||||||
|
|
||||||
it 'parses received bytes' do
|
it 'parses received bytes' do
|
||||||
status.client_list.map { |client| client[2] }.should be == [11811160064, 512]
|
expect(status.client_list.map { |client| client[2] }).to eq([11_811_160_064, 512])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses sent bytes' do
|
it 'parses sent bytes' do
|
||||||
status.client_list.map { |client| client[3] }.should be == [4194304, 2048]
|
expect(status.client_list.map { |client| client[3] }).to eq([4_194_304, 2048])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses connected since date' do
|
it 'parses connected since date' do
|
||||||
status.client_list.map { |client| client[4] }.should be == [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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for routing table' do
|
context 'for routing table' do
|
||||||
it 'parses virtual addresses' do
|
it 'parses virtual addresses' do
|
||||||
status.routing_table.map { |route| route[0] }.should be == ["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
|
end
|
||||||
|
|
||||||
it 'parses common names' do
|
it 'parses common names' do
|
||||||
status.routing_table.map { |route| route[1] }.should be == ["foo", "bar", "foo", "bar"]
|
expect(status.routing_table.map { |route| route[1] }).to eq(%w[foo bar foo bar])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses real addresses' do
|
it 'parses real addresses' do
|
||||||
status.routing_table.map { |route| route[2] }.should be == ["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
|
end
|
||||||
|
|
||||||
it 'parses last ref date' do
|
it 'parses last ref date' do
|
||||||
status.routing_table.map { |route| route[3] }.should be == [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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'parses global stats' do
|
it 'parses global stats' do
|
||||||
status.global_stats.size.should be == 1
|
expect(status.global_stats.size).to eq(1)
|
||||||
status.global_stats.first.should be == ["Max bcast/mcast queue length", 42]
|
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 'rubygems'
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
@@ -6,16 +7,16 @@ require 'rack/test'
|
|||||||
require 'openvpn-status-web'
|
require 'openvpn-status-web'
|
||||||
|
|
||||||
def status_v1
|
def status_v1
|
||||||
text = File.open('examples/status.v1', 'rb') do |f| f.read end
|
text = File.open('examples/status.v1', 'rb', &:read)
|
||||||
OpenVPNStatusWeb::Parser::V1.new.parse_status_log text
|
OpenVPNStatusWeb::Parser::V1.new.parse_status_log text
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_v2
|
def status_v2
|
||||||
text = File.open('examples/status.v2', 'rb') do |f| f.read end
|
text = File.open('examples/status.v2', 'rb', &:read)
|
||||||
OpenVPNStatusWeb::Parser::V2.new.parse_status_log text
|
OpenVPNStatusWeb::Parser::V2.new.parse_status_log text
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_v3
|
def status_v3
|
||||||
text = File.open('examples/status.v3', 'rb') do |f| f.read end
|
text = File.open('examples/status.v3', 'rb', &:read)
|
||||||
OpenVPNStatusWeb::Parser::V3.new.parse_status_log text
|
OpenVPNStatusWeb::Parser::V3.new.parse_status_log text
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user