mirror of
https://github.com/cmur2/openvpn-status-web.git
synced 2024-12-22 12:54:24 +01:00
Use config file
This commit is contained in:
parent
addc1cf45a
commit
d6a7b8c0ee
35
README.md
35
README.md
@ -1,17 +1,42 @@
|
||||
# openvpn-status-web
|
||||
|
||||
Small (another word for naive in this case, it's simple and serves my needs) [rack](http://rack.github.com/) app
|
||||
providing the information the [OpenVPN](http://openvpn.net/index.php/open-source.html) server collects in it's status file
|
||||
especially including a list of currently connected clients (common name, remote address, traffic, ...).
|
||||
It comes with a Debian 6 compatible init.d file.
|
||||
Small (another word for naive in this case, it's simple and serves my needs) [Rack](http://rack.github.com/) application providing the information the [OpenVPN](http://openvpn.net/index.php/open-source.html) server collects in it's status file especially including a list of currently connected clients (common name, remote address, traffic, ...).
|
||||
|
||||
It lacks:
|
||||
|
||||
* authentication
|
||||
* caching (parses file on each request, page does auto-refresh every minute as OpenVPN updates the status file these often)
|
||||
* newer status file versions than v1
|
||||
* management interface support
|
||||
* tracking multiple status at the same time
|
||||
* *possibly more...*
|
||||
|
||||
## Usage
|
||||
|
||||
Install the gem:
|
||||
|
||||
gem install openvpn-status-web
|
||||
|
||||
Create a configuration file in YAML format somewhere:
|
||||
|
||||
```yaml
|
||||
# listen address and port
|
||||
host: "0.0.0.0"
|
||||
port: "8080"
|
||||
# logfile is optional, logs to STDOUT else
|
||||
logfile: "openvpn-status-web.log"
|
||||
# display name for humans and the status file path
|
||||
name: "My Small VPN"
|
||||
status_file: "/var/log/openvpn-status.log"
|
||||
```
|
||||
|
||||
## Advanced topics
|
||||
|
||||
## Authentication
|
||||
|
||||
### Init scripts
|
||||
|
||||
The [Debian 6 init.d script](init.d/debian-6-openvpn-status-web) assumes that openvpn-status-web is installed into the system ruby (no RVM support) and the config.yaml is at /opt/openvpn-status-web/config.yaml. Modify to your needs.
|
||||
|
||||
## License
|
||||
|
||||
openvpn-statsu-web is licensed under the Apache License, Version 2.0. See LICENSE for more information.
|
||||
|
40
init.d/debian-6-openvpn-status-web
Executable file
40
init.d/debian-6-openvpn-status-web
Executable file
@ -0,0 +1,40 @@
|
||||
#! /bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: openvpn-status-web
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Handle openvpn-status-web gem
|
||||
### END INIT INFO
|
||||
|
||||
# using the system ruby's gem binaries directory
|
||||
DAEMON="/var/lib/gems/1.8/bin/openvpn-status-web"
|
||||
|
||||
CONFIG_FILE="/opt/openvpn-status-web/config.yaml"
|
||||
|
||||
DAEMON_OPTS="$CONFIG_FILE"
|
||||
|
||||
test -x $DAEMON || exit 0
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
log_daemon_msg "Starting openvpn-web-status" "openvpn-web-status"
|
||||
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/openvpn-web-status.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
||||
;;
|
||||
stop)
|
||||
log_daemon_msg "Stopping openvpn-web-status" "openvpn-web-status"
|
||||
start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/openvpn-web-status.pid"
|
||||
;;
|
||||
restart|force-reload)
|
||||
log_daemon_msg "Restarting openvpn-web-status" "openvpn-web-status"
|
||||
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "/var/run/openvpn-web-status.pid"
|
||||
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/openvpn-web-status.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -1,48 +0,0 @@
|
||||
#! /bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: openvpn-status-web
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Handle openvpn-status-web
|
||||
### END INIT INFO
|
||||
|
||||
# your ruby interpreter
|
||||
DAEMON="/usr/bin/ruby"
|
||||
|
||||
# some unique name identifying your VPN
|
||||
VPN_NAME="vpn.example.org"
|
||||
|
||||
# path to the OpenVPN status log file
|
||||
STATUS_PATH="/var/log/openvpn-status.log"
|
||||
|
||||
# host and port for this daemon to listen on
|
||||
HOST="127.0.0.1"
|
||||
PORT="3000"
|
||||
|
||||
DAEMON_OPTS="/opt/openvpn-status-web/status.rb $VPN_NAME $STATUS_PATH $HOST $PORT"
|
||||
|
||||
test -x $DAEMON || exit 0
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
log_daemon_msg "Starting openvpn-web-status for $VPN_NAME" "openvpn-web-status"
|
||||
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/$VPN_NAME.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
||||
;;
|
||||
stop)
|
||||
log_daemon_msg "Stopping openvpn-web-status for $VPN_NAME" "openvpn-web-status"
|
||||
start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/$VPN_NAME.pid"
|
||||
;;
|
||||
restart|force-reload)
|
||||
log_daemon_msg "Restarting openvpn-web-status for $VPN_NAME" "openvpn-web-status"
|
||||
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "/var/run/$VPN_NAME.pid"
|
||||
start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/$VPN_NAME.pid" --background --exec $DAEMON -- $DAEMON_OPTS
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -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
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user