1
0
mirror of https://github.com/cmur2/openvpn-status-web.git synced 2025-09-28 21:52:05 +02:00

59 Commits

Author SHA1 Message Date
cn
ea7b3a947c gem: release 3.2.1 2022-01-18 23:18:00 +01:00
cn
eb2bb4d632 gem: initialize new status attributes with default values
- prevents 'undefined method each_with_index for nil:NilClass' errors
2022-01-18 23:17:42 +01:00
cn
2a9bacf196 gem: release 3.2.0 2022-01-18 17:09:03 +01:00
cn
39adc74fbc gem: Date::Error is not in Ruby 2.6 and older, use ArgumentError 2022-01-18 17:07:33 +01:00
cn
9ad59194bd gem: support date format used by OpenVPN 2.5
- smooth fallback
2022-01-18 17:07:33 +01:00
cn
528709c895 gem: parse any number of list headers in status-version 2/3 2022-01-18 17:07:33 +01:00
cn
39d2b3ce94 gem: refactor to prepare supporting flexible list headers 2022-01-18 17:07:33 +01:00
406ed867f7 gem: add Ruby 3.1 support 2022-01-07 09:31:53 +01:00
depfu[bot]
22d9797f55 gems: update rubocop-rspec to version 2.7.0 2021-12-28 00:29:52 +01:00
depfu[bot]
55aecedef7 gems: update rubocop to version 1.24.0 2021-12-24 16:21:27 +01:00
depfu[bot]
d401074524 gems: update rubocop to version 1.23.0 2021-11-17 13:53:41 +01:00
depfu[bot]
ff6572bdac gems: update rubocop-rspec to version 2.6.0 2021-11-09 09:24:58 +01:00
depfu[bot]
b4bf74240b gems: update rubocop to version 1.22.0 2021-09-30 12:09:33 +02:00
depfu[bot]
fb4b3ca461 gems: update solargraph to version 0.44.0 2021-09-28 11:42:56 +02:00
depfu[bot]
8a6722f981 gems: update rubocop-rspec to version 2.5.0 2021-09-23 08:35:49 +02:00
depfu[bot]
8249b01c95 gems: update rubocop to version 1.21.0 2021-09-14 22:17:23 +02:00
depfu[bot]
5d04255a95 gems: update bundler-audit to version 0.9.0.1 2021-09-02 00:53:22 +02:00
depfu[bot]
846d41d35d gems: update rubocop to version 1.20.0 2021-08-27 12:50:41 +02:00
depfu[bot]
ce0e80f35f gems: update rubocop to version 1.19.0 2021-08-13 15:43:58 +02:00
depfu[bot]
0ec3faf5b4 gems: update solargraph to version 0.43.0 2021-07-27 00:54:44 +02:00
depfu[bot]
10a4e757f3 gems: update rubocop to version 1.18.1 2021-07-01 09:58:43 +02:00
depfu[bot]
f95134c315 gems: update rubocop-rake to version 0.6.0 2021-06-29 22:24:25 +02:00
depfu[bot]
7da4cb910f gems: update rubocop to version 1.17.0 2021-06-16 16:13:00 +02:00
depfu[bot]
382daa34c6 gems: update solargraph to version 0.42.1 2021-06-12 15:25:00 +02:00
depfu[bot]
5338b30e32 gems: update rubocop-rspec to version 2.4.0 2021-06-10 23:59:30 +02:00
depfu[bot]
47ee407af2 gems: update solargraph to version 0.41.1 2021-06-02 19:59:48 +02:00
depfu[bot]
281750d6ea gems: update rubocop to version 1.16.0 2021-06-02 19:55:34 +02:00
depfu[bot]
42743a1786 gems: update rubocop to version 1.15.0 2021-05-18 12:05:21 +02:00
depfu[bot]
7c94192765 gems: update rubocop to version 1.14.0 2021-05-06 12:44:25 +02:00
depfu[bot]
a3a65f05bc gems: update rubocop-rspec to version 2.3.0 2021-04-29 15:09:21 +02:00
depfu[bot]
e87a4d86f6 gems: update rubocop to version 1.13.0 2021-04-21 12:29:53 +02:00
depfu[bot]
2145e183e3 gems: update rubocop to version 1.12.0 2021-03-25 17:22:09 +01:00
depfu[bot]
9e5aa1ff71 gems: update bundler-audit to version 0.8.0 2021-03-11 17:18:44 +01:00
depfu[bot]
a99ba901c9 gems: update rubocop to version 1.11.0 2021-03-02 12:31:48 +01:00
depfu[bot]
cc21291a5c gems: update rubocop to version 1.10.0 2021-02-16 16:59:41 +01:00
depfu[bot]
ba00407d55 gems: update rubocop-rspec to version 2.2.0 2021-02-04 10:11:43 +01:00
depfu[bot]
80bd4f8584 gems: update rubocop to version 1.9.0 2021-01-29 14:29:43 +01:00
cn
e4034073a6 release: 3.1.0
- Ruby 3.0
- move from Travis CI to Github Actions
- dependency updates
2021-01-18 20:56:53 +01:00
depfu[bot]
f4d17809a2 gems: update rubocop to version 1.8.1 2021-01-18 20:51:39 +01:00
cn
08b50d5974 docs: update Dockerfile to Alpine 3.13 2021-01-18 15:00:41 +01:00
depfu[bot]
f287906240 gems: update rubocop to version 1.7.0 2020-12-28 21:42:19 +01:00
cn
27306b831f ci: use bundler cache to save resources
- see https://github.com/ruby/setup-ruby#caching-bundle-install-automatically
2020-12-26 15:17:06 +01:00
cn
1e12701fc3 gems: include rubocop-rspec and fix linting 2020-12-25 18:17:01 +01:00
cn
597b619b0b gems: include rubocop-rake and fix linting 2020-12-25 18:16:27 +01:00
cn
61f7cbd76c gem: add Ruby 3.0 support 2020-12-25 17:52:10 +01:00
cn
2628c08975 gems: revert back to upstream solargraph now with rubocop 1.0 compat
See https://github.com/castwide/solargraph/issues/380 and previous commit 0ffe369ef1
2020-12-25 17:51:25 +01:00
depfu[bot]
7343081406 gems: update rubocop to version 1.6.1 2020-12-11 12:15:59 +01:00
cn
ec4d028c03 ci: drop Travis CI
- end of an era
2020-12-10 11:03:44 +01:00
cn
12b5153604 gem: refactor Rakefile solargraph tasks, include in default task 2020-12-04 09:17:11 +01:00
cn
7c0722e875 ci: use Github Actions in parallel to Travis CI
- this adds a new workflow for Github Actions that mirrors what the existing Travis CI workflow tests
- Travis CI might become unfriendly to opensource soonish so migration might be necessary
2020-12-04 09:14:32 +01:00
depfu[bot]
afd7f4fa98 gems: update rubocop to version 1.5.1 2020-12-03 21:23:22 +01:00
depfu[bot]
63272da3e3 gems: update rubocop to version 1.4.1 2020-11-24 20:56:04 +01:00
depfu[bot]
ae7fc1137b gems: update rubocop to version 1.3.0 2020-11-13 13:09:57 +01:00
depfu[bot]
1f69dabf5f gems: update rubocop to version 1.2.0 2020-11-06 12:28:33 +01:00
cn
0e9c9fea68 docs: use travis-ci.com links 2020-10-31 00:05:28 +01:00
cn
0ffe369ef1 gems: use solargraph fork until gem metadata allows rubocop 1.0 compat
See https://github.com/castwide/solargraph/issues/380
2020-10-30 23:59:05 +01:00
depfu[bot]
c2cac319ae gems: update rubocop to version 1.1.0 2020-10-30 22:56:37 +01:00
depfu[bot]
5f343d7873 gems: update rubocop to version 1.0.0 2020-10-22 15:56:12 +02:00
depfu[bot]
0a45726857 gems: update rubocop to version 0.93.0 2020-10-10 16:46:18 +02:00
18 changed files with 202 additions and 68 deletions

33
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,33 @@
---
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.5'
- '2.6'
- '2.7'
- '3.0'
- '3.1'
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

View File

@@ -1,7 +1,14 @@
require:
- rubocop-rake
- rubocop-rspec
AllCops: AllCops:
TargetRubyVersion: '2.5' TargetRubyVersion: '2.5'
NewCops: enable NewCops: enable
Gemspec/RequireMFA:
Enabled: false
Layout/EmptyLineAfterGuardClause: Layout/EmptyLineAfterGuardClause:
Enabled: false Enabled: false
@@ -86,3 +93,13 @@ Style/Semicolon:
Style/SymbolArray: Style/SymbolArray:
Enabled: false Enabled: false
RSpec/ExampleLength:
Max: 10
RSpec/FilePath:
CustomTransform:
OpenVPNStatusWeb: openvpn-status-web
RSpec/MultipleExpectations:
Max: 5

View File

@@ -1,10 +0,0 @@
---
os: linux
language: ruby
rvm:
- 2.7
- 2.6
- 2.5
script:
- bundle exec rake travis

View File

@@ -1,6 +1,6 @@
# openvpn-status-web # openvpn-status-web
[![Build Status](https://travis-ci.org/cmur2/openvpn-status-web.svg?branch=master)](https://travis-ci.org/cmur2/openvpn-status-web) [![Depfu](https://badges.depfu.com/badges/c264e2f70f2a19c43f880ddcb4a12ba8/overview.svg)](https://depfu.com/github/cmur2/openvpn-status-web?project_id=6194) ![ci](https://github.com/cmur2/openvpn-status-web/workflows/ci/badge.svg) [![Depfu](https://badges.depfu.com/badges/c264e2f70f2a19c43f880ddcb4a12ba8/overview.svg)](https://depfu.com/github/cmur2/openvpn-status-web?project_id=6194)
## Description ## Description

View File

@@ -9,16 +9,19 @@ RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new RuboCop::RakeTask.new
Bundler::Audit::Task.new Bundler::Audit::Task.new
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' desc 'Run experimental solargraph type checker'
task :'solargraph:tc' do task :solargraph do
sh 'solargraph typecheck' sh 'solargraph typecheck'
end end
task default: [:rubocop, :spec, 'bundle:audit'] 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 travis: [:default, :'solargraph:init', :'solargraph:tc'] task default: [:rubocop, :spec, 'bundle:audit', :solargraph]
desc 'Run all tasks desired for CI'
task ci: ['solargraph:init', :default]

View File

@@ -1,8 +1,8 @@
FROM alpine:3.12 FROM alpine:3.13
EXPOSE 8080 EXPOSE 8080
ENV VERSION=3.0.1 ENV VERSION=3.2.1
RUN apk --no-cache add openssl ca-certificates && \ RUN apk --no-cache add openssl ca-certificates && \
apk --no-cache add ruby ruby-etc ruby-webrick && \ apk --no-cache add ruby ruby-etc ruby-webrick && \

View File

@@ -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

View File

@@ -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
View 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

View File

@@ -50,20 +50,36 @@ thead {
<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>
<% status.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].strftime('%-d.%-m.%Y %H:%M:%S') %></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>
@@ -74,18 +90,34 @@ thead {
<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>
<% status.routing_table.each do |route| %> <% status.routing_table.each do |route| %>
<tr> <tr>
<td class="first"><%= route[0] %></td> <% status.routing_table_headers.each_with_index do |header,i| %>
<td class="middle"><%= route[1] %></td> <% if i == 0 %>
<td class="middle"><%= route[2] %></td> <td class="first">
<td class="last"><%= route[3].strftime('%-d.%-m.%Y %H:%M:%S') %></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>

View File

@@ -5,29 +5,38 @@ module OpenVPNStatusWeb
class ModernStateless class ModernStateless
def self.parse_status_log(text, sep) def self.parse_status_log(text, sep)
status = Status.new status = Status.new
status.client_list_headers = []
status.client_list = [] status.client_list = []
status.routing_table_headers = []
status.routing_table = [] status.routing_table = []
status.global_stats = [] status.global_stats = []
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_headers = parts[2..-1] if parts[0] == 'HEADER' && parts[1] == 'CLIENT_LIST'
status.routing_table << parse_route(parts[1..4]) if parts[0] == 'ROUTING_TABLE' status.client_list << parse_client(parts[1..-1], status.client_list_headers) if parts[0] == 'CLIENT_LIST'
status.routing_table_headers = parts[2..-1] if parts[0] == 'HEADER' && parts[1] == 'ROUTING_TABLE'
status.routing_table << parse_route(parts[1..-1], status.routing_table_headers) 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_class_method def self.parse_client(client) private_class_method def self.parse_client(client, headers)
client[2] = client[2].to_i headers.each_with_index do |header, i|
client[3] = client[3].to_i client[i] = parse_date(client[i]) if header.end_with?('Since')
client[4] = DateTime.strptime(client[4], '%a %b %d %k:%M:%S %Y') client[i] = client[i].to_i if header.start_with?('Bytes')
end
client client
end end
private_class_method def self.parse_route(route) private_class_method def self.parse_route(route, headers)
route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y') headers.each_with_index do |header, i|
route[i] = parse_date(route[i]) if header.end_with?('Last Ref')
end
route route
end end
@@ -35,6 +44,12 @@ module OpenVPNStatusWeb
global[1] = global[1].to_i global[1] = global[1].to_i
global global
end 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 end
end end

View File

@@ -26,7 +26,9 @@ module OpenVPNStatusWeb
end end
status = Status.new status = Status.new
status.client_list_headers = ['Common Name', 'Real Address', 'Data Received', 'Data Sent', 'Connected Since']
status.client_list = client_list[2..-1].map { |client| parse_client(client) } status.client_list = client_list[2..-1].map { |client| parse_client(client) }
status.routing_table_headers = ['Virtual Address', 'Common Name', 'Real Address', 'Last Ref']
status.routing_table = routing_table[1..-1].map { |route| parse_route(route) } status.routing_table = routing_table[1..-1].map { |route| parse_route(route) }
status.global_stats = global_stats.map { |global| parse_global(global) } status.global_stats = global_stats.map { |global| parse_global(global) }
status status

View File

@@ -2,7 +2,9 @@
module OpenVPNStatusWeb module OpenVPNStatusWeb
class Status class Status
attr_accessor :client_list_headers
attr_accessor :client_list attr_accessor :client_list
attr_accessor :routing_table_headers
attr_accessor :routing_table attr_accessor :routing_table
attr_accessor :global_stats attr_accessor :global_stats
end end

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module OpenVPNStatusWeb module OpenVPNStatusWeb
VERSION = '3.0.1' VERSION = '3.2.1'
end end

View File

@@ -33,10 +33,12 @@ Gem::Specification.new do |s|
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'
s.add_development_dependency 'bundler-audit', '~> 0.7.0' s.add_development_dependency 'bundler-audit', '~> 0.9.0'
s.add_development_dependency 'rack-test' 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 'rubocop', '~> 0.92.0' s.add_development_dependency 'rubocop', '~> 1.24.0'
s.add_development_dependency 'solargraph' s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
s.add_development_dependency 'rubocop-rspec', '~> 2.7.0'
s.add_development_dependency 'solargraph', '~> 0.44.0'
end end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../spec_helper' require_relative '../../spec_helper'
describe OpenVPNStatusWeb::Parser::ModernStateless do describe OpenVPNStatusWeb::Parser::ModernStateless do
{ {
@@ -8,7 +8,7 @@ describe OpenVPNStatusWeb::Parser::ModernStateless do
3 => status_v3 3 => status_v3
}.each do |version, status| }.each do |version, status|
context "for status-version #{version}" do context "for status-version #{version}" do
context 'for client list' do context 'with client list' do
it 'parses common names' do it 'parses common names' do
expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar]) expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar])
end end
@@ -17,24 +17,33 @@ describe OpenVPNStatusWeb::Parser::ModernStateless 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 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 it 'parses received bytes' do
expect(status.client_list.map { |client| client[2] }).to eq([11_811_160_064, 512]) expect(status.client_list.map { |client| client[3] }).to eq([11_811_160_064, 512])
end end
it 'parses sent bytes' do it 'parses sent bytes' do
expect(status.client_list.map { |client| client[3] }).to eq([4_194_304, 2048]) expect(status.client_list.map { |client| client[4] }).to eq([4_194_304, 2048])
end end
it 'parses connected since date' do it 'parses connected since date' do
expect(status.client_list.map { |client| client[4] }).to eq( 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) DateTime.new(2012, 1, 1, 23, 42, 0),
DateTime.new(2012, 1, 1, 23, 42, 0)
] ]
) )
end end
it 'has the same number of headers' do
expect(status.client_list[0].size).to eq(status.client_list_headers.size)
end
end end
context 'for routing table' do context 'with routing table' do
it 'parses virtual addresses' 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 end
@@ -55,6 +64,10 @@ describe OpenVPNStatusWeb::Parser::ModernStateless do
] ]
) )
end end
it 'has the same number of headers' do
expect(status.routing_table[0].size).to eq(status.routing_table_headers.size)
end
end end
it 'parses global stats' do it 'parses global stats' do
@@ -63,4 +76,8 @@ describe OpenVPNStatusWeb::Parser::ModernStateless do
end end
end end
end end
it 'parses status-version 2 of OpenVPN 2.5' do
expect(status_2_5_v2).not_to be_nil
end
end end

View File

@@ -1,13 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative '../spec_helper' require_relative '../../spec_helper'
describe OpenVPNStatusWeb::Parser::V1 do describe OpenVPNStatusWeb::Parser::V1 do
def status def status
status_v1 status_v1
end end
context 'for client list' do context 'with client list' do
it 'parses common names' do it 'parses common names' do
expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar]) expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar])
end end
@@ -31,9 +31,13 @@ describe OpenVPNStatusWeb::Parser::V1 do
] ]
) )
end end
it 'has the same number of headers' do
expect(status.client_list[0].length).to eq(status.client_list_headers.length)
end
end end
context 'for routing table' do context 'with routing table' do
it 'parses virtual addresses' 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 end
@@ -54,6 +58,10 @@ describe OpenVPNStatusWeb::Parser::V1 do
] ]
) )
end end
it 'has the same number of headers' do
expect(status.routing_table[0].length).to eq(status.routing_table_headers.length)
end
end end
it 'parses global stats' do it 'parses global stats' do

View File

@@ -7,16 +7,21 @@ require 'rack/test'
require 'openvpn-status-web' require 'openvpn-status-web'
def status_v1 def status_v1
text = File.open('examples/status.v1', 'rb', &:read) text = File.binread('examples/status.v1')
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', &:read) 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 OpenVPNStatusWeb::Parser::V2.new.parse_status_log text
end end
def status_v3 def status_v3
text = File.open('examples/status.v3', 'rb', &:read) text = File.binread('examples/status.v3')
OpenVPNStatusWeb::Parser::V3.new.parse_status_log text OpenVPNStatusWeb::Parser::V3.new.parse_status_log text
end end