mirror of
https://github.com/cmur2/openvpn-status-web.git
synced 2024-12-22 12:54:24 +01:00
Refactoring
This commit is contained in:
parent
87d9ea302f
commit
cd6e41fcfa
@ -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!
|
||||
|
28
lib/openvpn-status-web/parser/v1.rb
Normal file
28
lib/openvpn-status-web/parser/v1.rb
Normal file
@ -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
|
0
lib/openvpn-status-web/status.rb
Normal file
0
lib/openvpn-status-web/status.rb
Normal file
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user