1
0
mirror of https://github.com/cmur2/openvpn-status-web.git synced 2024-12-22 22:54:24 +01:00

First step towards multiple status files

This commit is contained in:
cn 2013-05-03 18:47:32 +02:00
parent 438931f8a6
commit 635e562a3d

View File

@ -5,6 +5,7 @@ require 'logger'
require 'ipaddr' require 'ipaddr'
require 'yaml' require 'yaml'
require 'rack' require 'rack'
require 'erb'
require 'metriks' require 'metriks'
require 'openvpn-status-web/status' require 'openvpn-status-web/status'
@ -28,18 +29,23 @@ module OpenVPNStatusWeb
end end
class Daemon class Daemon
def initialize(name, file) def initialize(vpns)
@name = name @vpns = vpns
@file = file
@main_tmpl = read_template(File.join(File.dirname(__FILE__), 'openvpn-status-web/main.html.erb'))
end end
def call(env) def call(env)
main_tmpl = read_template(File.join(File.dirname(__FILE__), 'openvpn-status-web/main.html.erb')) return [405, {"Content-Type" => "text/plain"}, ["Method Not Allowed"]] if env["REQUEST_METHOD"] != "GET"
# variables for template return [404, {"Content-Type" => "text/plain"}, ["Not Found"]] if env["PATH_INFO"] != "/"
name = @name
status = read_status_log(@file) # variables for template
#name = @vpns.keys.first
#status = read_status_log(@vpns[name]['status_file'])
# eval
#html = @main_tmpl.result(binding)
html = ""
html = main_tmpl.result(binding)
[200, {"Content-Type" => "text/html"}, [html]] [200, {"Content-Type" => "text/html"}, [html]]
end end
@ -84,7 +90,7 @@ module OpenVPNStatusWeb
OpenVPNStatusWeb.logger.info "Starting..." OpenVPNStatusWeb.logger.info "Starting..."
app = Daemon.new(config['name'], config['status_file']) app = Daemon.new(config['vpns'])
Signal.trap('INT') do Signal.trap('INT') do
OpenVPNStatusWeb.logger.info "Quitting..." OpenVPNStatusWeb.logger.info "Quitting..."