1
0
mirror of https://github.com/cmur2/openvpn-status-web.git synced 2025-04-04 09:34:14 +02: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"
return [404, {"Content-Type" => "text/plain"}, ["Not Found"]] if env["PATH_INFO"] != "/"
# variables for template # variables for template
name = @name #name = @vpns.keys.first
status = read_status_log(@file) #status = read_status_log(@vpns[name]['status_file'])
# eval
html = main_tmpl.result(binding) #html = @main_tmpl.result(binding)
html = ""
[200, {"Content-Type" => "text/html"}, [html]] [200, {"Content-Type" => "text/html"}, [html]]
end end
@ -72,7 +78,7 @@ module OpenVPNStatusWeb
puts "Using config file #{config_file}" puts "Using config file #{config_file}"
config = YAML::load(File.open(config_file, 'r') { |f| f.read }) config = YAML::load(File.open(config_file, 'r') { |f| f.read })
if config['logfile'] if config['logfile']
OpenVPNStatusWeb.logger = Logger.new(config['logfile']) OpenVPNStatusWeb.logger = Logger.new(config['logfile'])
else else
@ -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..."