diff --git a/examples/status2_5.v2 b/examples/status2_5.v2 new file mode 100644 index 0000000..7e08df8 --- /dev/null +++ b/examples/status2_5.v2 @@ -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 diff --git a/lib/openvpn-status-web/parser/modern_stateless.rb b/lib/openvpn-status-web/parser/modern_stateless.rb index 78648b5..de01813 100644 --- a/lib/openvpn-status-web/parser/modern_stateless.rb +++ b/lib/openvpn-status-web/parser/modern_stateless.rb @@ -45,6 +45,8 @@ module OpenVPNStatusWeb private_class_method def self.parse_date(date_string) 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 diff --git a/spec/openvpn-status-web/parser/modern_stateless_spec.rb b/spec/openvpn-status-web/parser/modern_stateless_spec.rb index 972dd6a..28bede1 100644 --- a/spec/openvpn-status-web/parser/modern_stateless_spec.rb +++ b/spec/openvpn-status-web/parser/modern_stateless_spec.rb @@ -76,4 +76,8 @@ describe OpenVPNStatusWeb::Parser::ModernStateless do end end end + + it 'parses status-version 2 of OpenVPN 2.5' do + expect(status_2_5_v2).not_to be_nil + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 974a031..220619c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,11 @@ def status_v2 OpenVPNStatusWeb::Parser::V2.new.parse_status_log text end +def status_2_5_v2 + text = File.binread('examples/status2_5.v2') + OpenVPNStatusWeb::Parser::V2.new.parse_status_log text +end + def status_v3 text = File.binread('examples/status.v3') OpenVPNStatusWeb::Parser::V3.new.parse_status_log text