diff --git a/lib/openvpn-status-web.rb b/lib/openvpn-status-web.rb index 5333427..eb6dd76 100644 --- a/lib/openvpn-status-web.rb +++ b/lib/openvpn-status-web.rb @@ -7,7 +7,9 @@ require 'yaml' require 'rack' require 'metriks' +require 'openvpn-status-web/parser/v1' require 'openvpn-status-web/int_patch' +require 'openvpn-status-web/status' require 'openvpn-status-web/version' module OpenVPNStatusWeb @@ -50,25 +52,7 @@ module OpenVPNStatusWeb def read_status_log(file) text = File.open(file, 'rb') do |f| f.read end - current_section = :none - client_list = [] - routing_table = [] - global_stats = [] - - text.lines.each do |line| - (current_section = :cl; next) if line == "OpenVPN CLIENT LIST\n" - (current_section = :rt; next) if line == "ROUTING TABLE\n" - (current_section = :gs; next) if line == "GLOBAL STATS\n" - (current_section = :end; next) if line == "END\n" - - case current_section - when :cl then client_list << line.strip.split(',') - when :rt then routing_table << line.strip.split(',') - when :gs then global_stats << line.strip.split(',') - end - end - - [client_list[2..-1], routing_table[1..-1], global_stats] + OpenVPNStatusWeb::Parser::V1.new.parse_status_log(text) end def self.run! diff --git a/lib/openvpn-status-web/parser/v1.rb b/lib/openvpn-status-web/parser/v1.rb new file mode 100644 index 0000000..f9485a8 --- /dev/null +++ b/lib/openvpn-status-web/parser/v1.rb @@ -0,0 +1,28 @@ + +module OpenVPNStatusWeb + module Parser + class V1 + def parse_status_log(text) + current_section = :none + client_list = [] + routing_table = [] + global_stats = [] + + text.lines.each do |line| + (current_section = :cl; next) if line == "OpenVPN CLIENT LIST\n" + (current_section = :rt; next) if line == "ROUTING TABLE\n" + (current_section = :gs; next) if line == "GLOBAL STATS\n" + (current_section = :end; next) if line == "END\n" + + case current_section + when :cl then client_list << line.strip.split(',') + when :rt then routing_table << line.strip.split(',') + when :gs then global_stats << line.strip.split(',') + end + end + + [client_list[2..-1], routing_table[1..-1], global_stats] + end + end + end +end diff --git a/lib/openvpn-status-web/status.rb b/lib/openvpn-status-web/status.rb new file mode 100644 index 0000000..e69de29 diff --git a/openvpn-status-web.gemspec b/openvpn-status-web.gemspec index 5baaf4a..a7de756 100644 --- a/openvpn-status-web.gemspec +++ b/openvpn-status-web.gemspec @@ -21,7 +21,6 @@ Gem::Specification.new do |s| s.executables = ['openvpn-status-web'] s.add_runtime_dependency 'rack' - s.add_runtime_dependency 'json' s.add_runtime_dependency 'metriks' s.add_development_dependency 'bundler', '~> 1.3'