diff --git a/lib/openvpn-status-web.rb b/lib/openvpn-status-web.rb index 2803723..61ef56a 100644 --- a/lib/openvpn-status-web.rb +++ b/lib/openvpn-status-web.rb @@ -12,6 +12,7 @@ require 'better_errors' require 'openvpn-status-web/status' require 'openvpn-status-web/parser/v1' require 'openvpn-status-web/parser/v2' +require 'openvpn-status-web/parser/v3' require 'openvpn-status-web/int_patch' require 'openvpn-status-web/version' @@ -64,6 +65,8 @@ module OpenVPNStatusWeb OpenVPNStatusWeb::Parser::V1.new.parse_status_log(text) when 2 OpenVPNStatusWeb::Parser::V2.new.parse_status_log(text) + when 3 + OpenVPNStatusWeb::Parser::V3.new.parse_status_log(text) else raise "No suitable parser for status-version #{vpn['version']}" end diff --git a/lib/openvpn-status-web/parser/modern_stateless.rb b/lib/openvpn-status-web/parser/modern_stateless.rb new file mode 100644 index 0000000..a6afc7f --- /dev/null +++ b/lib/openvpn-status-web/parser/modern_stateless.rb @@ -0,0 +1,22 @@ + +module OpenVPNStatusWeb + module Parser + class ModernStateless + def self.parse_status_log(text, sep) + status = Status.new + status.client_list = [] + status.routing_table = [] + status.global_stats = [] + + text.lines.each do |line| + parts = line.strip.split(sep) + status.client_list << parts[1..5] if parts[0] == "CLIENT_LIST" + status.routing_table << parts[1..4] if parts[0] == "ROUTING_TABLE" + status.global_stats << parts[1..2] if parts[0] == "GLOBAL_STATS" + end + + status + end + end + end +end diff --git a/lib/openvpn-status-web/parser/v2.rb b/lib/openvpn-status-web/parser/v2.rb index 03bc1b5..79723e3 100644 --- a/lib/openvpn-status-web/parser/v2.rb +++ b/lib/openvpn-status-web/parser/v2.rb @@ -1,24 +1,11 @@ +require 'openvpn-status-web/parser/modern_stateless' + module OpenVPNStatusWeb module Parser class V2 def parse_status_log(text) - client_list = [] - routing_table = [] - global_stats = [] - - text.lines.each do |line| - parts = line.strip.split(',') - client_list << parts[1..5] if parts[0] == "CLIENT_LIST" - routing_table << parts[1..4] if parts[0] == "ROUTING_TABLE" - global_stats << parts[1..2] if parts[0] == "GLOBAL_STATS" - end - - status = Status.new - status.client_list = client_list - status.routing_table = routing_table - status.global_stats = global_stats - status + OpenVPNStatusWeb::Parser::ModernStateless.parse_status_log(text, ',') end end end diff --git a/lib/openvpn-status-web/parser/v3.rb b/lib/openvpn-status-web/parser/v3.rb new file mode 100644 index 0000000..f85b3e0 --- /dev/null +++ b/lib/openvpn-status-web/parser/v3.rb @@ -0,0 +1,12 @@ + +require 'openvpn-status-web/parser/modern_stateless' + +module OpenVPNStatusWeb + module Parser + class V3 + def parse_status_log(text) + OpenVPNStatusWeb::Parser::ModernStateless.parse_status_log(text, "\t") + end + end + end +end