diff --git a/README.md b/README.md index 2f29d09..ed8c280 100644 --- a/README.md +++ b/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. diff --git a/init.d/debian-6-openvpn-status-web b/init.d/debian-6-openvpn-status-web new file mode 100755 index 0000000..d7b23e3 --- /dev/null +++ b/init.d/debian-6-openvpn-status-web @@ -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 diff --git a/init.d/openvpn-status-web b/init.d/openvpn-status-web deleted file mode 100755 index dbd6cc5..0000000 --- a/init.d/openvpn-status-web +++ /dev/null @@ -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 diff --git a/lib/openvpn-status-web.rb b/lib/openvpn-status-web.rb index 6c0c493..5333427 100644 --- a/lib/openvpn-status-web.rb +++ b/lib/openvpn-status-web.rb @@ -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