mirror of
https://github.com/cmur2/openvpn-status-web.git
synced 2024-12-22 12:54:24 +01:00
Add support for multiple status-versions
This commit is contained in:
parent
ed42fc9f30
commit
33013c56f3
@ -11,6 +11,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/int_patch'
|
||||
require 'openvpn-status-web/version'
|
||||
|
||||
@ -42,10 +43,9 @@ module OpenVPNStatusWeb
|
||||
|
||||
# variables for template
|
||||
name = @vpns.keys.first
|
||||
status = read_status_log(@vpns[name]['status_file'])
|
||||
status = parse_status_log(@vpns[name])
|
||||
# eval
|
||||
html = @main_tmpl.result(binding)
|
||||
#html = ""
|
||||
|
||||
[200, {"Content-Type" => "text/html"}, [html]]
|
||||
end
|
||||
@ -56,10 +56,17 @@ module OpenVPNStatusWeb
|
||||
ERB.new(text)
|
||||
end
|
||||
|
||||
def read_status_log(file)
|
||||
text = File.open(file, 'rb') do |f| f.read end
|
||||
def parse_status_log(vpn)
|
||||
text = File.open(vpn['status_file'], 'rb') do |f| f.read end
|
||||
|
||||
OpenVPNStatusWeb::Parser::V1.new.parse_status_log(text)
|
||||
case vpn['version']
|
||||
when 1
|
||||
OpenVPNStatusWeb::Parser::V1.new.parse_status_log(text)
|
||||
when 2
|
||||
OpenVPNStatusWeb::Parser::V2.new.parse_status_log(text)
|
||||
else
|
||||
raise "No suitable parser for status-version #{vpn['version']}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.run!
|
||||
|
25
lib/openvpn-status-web/parser/v2.rb
Normal file
25
lib/openvpn-status-web/parser/v2.rb
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user