1
0
mirror of https://github.com/cmur2/openvpn-status-web.git synced 2025-06-29 00:30:24 +02:00

Use config file

This commit is contained in:
cn
2013-05-03 16:06:30 +02:00
parent addc1cf45a
commit d6a7b8c0ee
4 changed files with 93 additions and 59 deletions

View File

@ -72,25 +72,42 @@ module OpenVPNStatusWeb
end
def self.run!
if ARGV.length != 4
puts "Usage: openvpn-status-web vpn-name status-log listen-host listen-port"
if ARGV.length != 1
puts "Usage: openvpn-status-web config_file"
exit 1
end
OpenVPNStatusWeb.logger = Logger.new(STDOUT)
config_file = ARGV[0]
if not File.file?(config_file)
puts "Config file not found!"
exit 1
end
puts "openvpn-status-web version #{OpenVPNStatusWeb::VERSION}"
puts "Using config file #{config_file}"
config = YAML::load(File.open(config_file, 'r') { |f| f.read })
if config['logfile']
OpenVPNStatusWeb.logger = Logger.new(config['logfile'])
else
OpenVPNStatusWeb.logger = Logger.new(STDOUT)
end
OpenVPNStatusWeb.logger.progname = "openvpn-status-web"
OpenVPNStatusWeb.logger.formatter = LogFormatter.new
OpenVPNStatusWeb.logger.info "Starting..."
app = Daemon.new(config['name'], config['status_file'])
Signal.trap('INT') do
OpenVPNStatusWeb.logger.info "Quitting..."
Rack::Handler::WEBrick.shutdown
end
app = Daemon.new(ARGV[0], ARGV[1])
Rack::Handler::WEBrick.run app, :Host => ARGV[2], :Port => ARGV[3]
Rack::Handler::WEBrick.run app, :Host => config['host'], :Port => config['port']
end
end
end