1
0
mirror of https://github.com/cmur2/openvpn-status-web.git synced 2024-12-22 12:54:24 +01:00

gem: support date format used by OpenVPN 2.5

- smooth fallback
This commit is contained in:
cn 2022-01-18 01:56:49 +01:00 committed by Christian Nicolai
parent 528709c895
commit 9ad59194bd
4 changed files with 19 additions and 0 deletions

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

@ -45,6 +45,8 @@ module OpenVPNStatusWeb
private_class_method def self.parse_date(date_string) private_class_method def self.parse_date(date_string)
DateTime.strptime(date_string, '%a %b %d %k:%M:%S %Y') DateTime.strptime(date_string, '%a %b %d %k:%M:%S %Y')
rescue Date::Error
DateTime.strptime(date_string, '%Y-%m-%d %k:%M:%S')
end end
end end
end end

View File

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

@ -16,6 +16,11 @@ def status_v2
OpenVPNStatusWeb::Parser::V2.new.parse_status_log text OpenVPNStatusWeb::Parser::V2.new.parse_status_log text
end 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 def status_v3
text = File.binread('examples/status.v3') text = File.binread('examples/status.v3')
OpenVPNStatusWeb::Parser::V3.new.parse_status_log text OpenVPNStatusWeb::Parser::V3.new.parse_status_log text