├── .gitignore ├── Gemfile ├── lib ├── openvpn-status-web │ ├── version.rb │ ├── status.rb │ ├── parser │ │ ├── v2.rb │ │ ├── v3.rb │ │ ├── v1.rb │ │ └── modern_stateless.rb │ ├── int_patch.rb │ └── main.html.erb └── openvpn-status-web.rb ├── exe └── openvpn-status-web ├── .editorconfig ├── .solargraph.yml ├── .github ├── dependabot.yml ├── workflows │ └── ci.yml └── renovate.json5 ├── docs ├── Dockerfile └── debian-init-openvpn-status-web ├── examples ├── status.v1 ├── status2_5.v2 ├── status.v2 └── status.v3 ├── spec ├── spec_helper.rb └── openvpn-status-web │ └── parser │ ├── v1_spec.rb │ └── modern_stateless_spec.rb ├── Rakefile ├── openvpn-status-web.gemspec ├── .rubocop.yml ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.lock 3 | pkg/* 4 | .yardoc 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module OpenVPNStatusWeb 4 | VERSION = '3.4.0' 5 | end 6 | -------------------------------------------------------------------------------- /exe/openvpn-status-web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'openvpn-status-web' 5 | 6 | OpenVPNStatusWeb::Daemon.run! 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.solargraph.yml: -------------------------------------------------------------------------------- 1 | --- 2 | include: 3 | - "**/*.rb" 4 | - "bin/openvpn-status-web" 5 | exclude: 6 | - spec/**/* 7 | - test/**/* 8 | - vendor/**/* 9 | - ".bundle/**/*" 10 | require: [] 11 | domains: [] 12 | reporters: 13 | - rubocop 14 | - require_not_found 15 | require_paths: [] 16 | max_files: 5000 17 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/status.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module OpenVPNStatusWeb 4 | class Status 5 | attr_accessor :client_list_headers 6 | attr_accessor :client_list 7 | attr_accessor :routing_table_headers 8 | attr_accessor :routing_table 9 | attr_accessor :global_stats 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | updates: 4 | - package-ecosystem: "bundler" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | commit-message: 9 | prefix: "gems" 10 | labels: ["dependabot"] 11 | open-pull-requests-limit: 10 12 | pull-request-branch-name: 13 | separator: "-" 14 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/parser/v2.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'modern_stateless' 4 | 5 | module OpenVPNStatusWeb 6 | module Parser 7 | class V2 8 | def parse_status_log(text) 9 | OpenVPNStatusWeb::Parser::ModernStateless.parse_status_log(text, ',') 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/parser/v3.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'modern_stateless' 4 | 5 | module OpenVPNStatusWeb 6 | module Parser 7 | class V3 8 | def parse_status_log(text) 9 | OpenVPNStatusWeb::Parser::ModernStateless.parse_status_log(text, "\t") 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/int_patch.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Integer 4 | def as_bytes 5 | return '1 Byte' if self == 1 6 | 7 | label = %w[Bytes KiB MiB GiB TiB] 8 | i = 0 9 | num = to_f 10 | while num >= 1024 11 | num /= 1024 12 | i += 1 13 | end 14 | 15 | "#{format('%.2f', num)} #{label[i]}" 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /docs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.22 2 | 3 | EXPOSE 8080 4 | 5 | ENV VERSION=3.4.0 6 | 7 | RUN apk --no-cache add openssl ca-certificates && \ 8 | apk --no-cache add ruby ruby-webrick && \ 9 | apk --no-cache add --virtual .build-deps ruby-dev build-base tzdata && \ 10 | gem install --no-document openvpn-status-web -v ${VERSION} && \ 11 | # set timezone to Berlin 12 | cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \ 13 | apk del .build-deps 14 | 15 | ENTRYPOINT ["openvpn-status-web", "/etc/openvpn-status-web/config.yml"] 16 | -------------------------------------------------------------------------------- /examples/status.v1: -------------------------------------------------------------------------------- 1 | OpenVPN CLIENT LIST 2 | Updated,Sun Jan 1 23:42:00 2012 3 | Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since 4 | foo,1.2.3.4:1234,11811160064,4194304,Sun Jan 1 23:42:00 2012 5 | bar,1.2.3.5:1235,512,2048,Sun Jan 1 23:42:00 2012 6 | ROUTING TABLE 7 | Virtual Address,Common Name,Real Address,Last Ref 8 | 192.168.0.0/24,foo,1.2.3.4:1234,Sun Jan 1 23:42:00 2012 9 | 192.168.66.2,bar,1.2.3.5:1235,Sun Jan 1 23:42:00 2012 10 | 192.168.66.3,foo,1.2.3.4:1234,Sun Jan 1 23:42:00 2012 11 | 2001:db8:0:0::1000,bar,1.2.3.5:1235,Sun Jan 1 23:42:00 2012 12 | GLOBAL STATS 13 | Max bcast/mcast queue length,42 14 | END 15 | -------------------------------------------------------------------------------- /examples/status2_5.v2: -------------------------------------------------------------------------------- 1 | TITLE,OpenVPN 2.5.1 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2021 2 | TIME,2012-01-01 23:42:00,1238702330 3 | HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Virtual IPv6 Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username,Client ID,Peer ID,Data Channel Cipher 4 | CLIENT_LIST,foo,1.2.3.4:1234,192.168.66.2,,11811160064,4194304,2012-01-01 23:42:00,1238702330,UNDEF,1,0,AES-256-GCM 5 | HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t) 6 | ROUTING_TABLE,192.168.66.2,foo,1.2.3.4:1234,2012-01-01 23:42:00,1238702330 7 | GLOBAL_STATS,Max bcast/mcast queue length,42 8 | END 9 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rubygems' 4 | require 'bundler/setup' 5 | require 'rack/test' 6 | 7 | require 'openvpn-status-web' 8 | 9 | def status_v1 10 | text = File.binread('examples/status.v1') 11 | OpenVPNStatusWeb::Parser::V1.new.parse_status_log text 12 | end 13 | 14 | def status_v2 15 | text = File.binread('examples/status.v2') 16 | OpenVPNStatusWeb::Parser::V2.new.parse_status_log text 17 | end 18 | 19 | def status_2_5_v2 20 | text = File.binread('examples/status2_5.v2') 21 | OpenVPNStatusWeb::Parser::V2.new.parse_status_log text 22 | end 23 | 24 | def status_v3 25 | text = File.binread('examples/status.v3') 26 | OpenVPNStatusWeb::Parser::V3.new.parse_status_log text 27 | end 28 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ci 3 | 4 | on: 5 | push: 6 | branches: [master] 7 | pull_request: 8 | branches: [master] 9 | workflow_dispatch: 10 | schedule: 11 | - cron: '35 4 * * 4' # weekly on thursday morning 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | ruby-version: 20 | - '3.0' 21 | - '3.1' 22 | - '3.2' 23 | - '3.3' 24 | - '3.4' 25 | steps: 26 | - uses: actions/checkout@v6 27 | - name: Set up Ruby ${{ matrix.ruby-version }} 28 | uses: ruby/setup-ruby@v1 29 | with: 30 | ruby-version: ${{ matrix.ruby-version }} 31 | bundler-cache: true # runs 'bundle install' and caches installed gems automatically 32 | - name: Lint and Test 33 | run: | 34 | bundle exec rake ci 35 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/gem_tasks' 4 | require 'rspec/core/rake_task' 5 | require 'rubocop/rake_task' 6 | 7 | RSpec::Core::RakeTask.new(:spec) 8 | RuboCop::RakeTask.new 9 | 10 | desc 'Run experimental solargraph type checker' 11 | task :solargraph do 12 | sh 'solargraph typecheck' 13 | end 14 | 15 | namespace :solargraph do 16 | desc 'Should be run by developer once to prepare initial solargraph usage (fill caches etc.)' 17 | task :init do 18 | sh 'solargraph download-core' 19 | end 20 | end 21 | 22 | namespace :bundle do 23 | desc 'Check for vulnerabilities with bundler-audit' 24 | task :audit do 25 | sh 'bundler-audit check --ignore GHSA-vvfq-8hwr-qm4m' if !RUBY_VERSION.start_with?('3.0') 26 | end 27 | end 28 | 29 | task default: [:rubocop, :spec, 'bundle:audit'] 30 | 31 | desc 'Run all tasks desired for CI' 32 | task ci: ['solargraph:init', :default] 33 | -------------------------------------------------------------------------------- /examples/status.v2: -------------------------------------------------------------------------------- 1 | TITLE,OpenVPN 2.1_rc15 mipsel-unknown-linux-gnu [SSL] [LZO1] [EPOLL] built on Mar 27 2009 2 | TIME,Sun Jan 1 23:42:00 2012,1238702330 3 | HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t) 4 | CLIENT_LIST,foo,1.2.3.4:1234,192.168.66.2,11811160064,4194304,Sun Jan 1 23:42:00 2012,1238702330 5 | CLIENT_LIST,bar,1.2.3.5:1235,2001:db8:0:0::1000,512,2048,Sun Jan 1 23:42:00 2012,1238702330 6 | HEADER,ROUTING_TABLE,Virtual Address,Common Name,Real Address,Last Ref,Last Ref (time_t) 7 | ROUTING_TABLE,192.168.0.0/24,foo,1.2.3.4:1234,Sun Jan 1 23:42:00 2012,1238702330 8 | ROUTING_TABLE,192.168.66.2,bar,1.2.3.5:1235,Sun Jan 1 23:42:00 2012,1238702330 9 | ROUTING_TABLE,192.168.66.3,foo,1.2.3.4:1234,Sun Jan 1 23:42:00 2012,1238702330 10 | ROUTING_TABLE,2001:db8:0:0::1000,bar,1.2.3.5:1235,Sun Jan 1 23:42:00 2012,1238702330 11 | GLOBAL_STATS,Max bcast/mcast queue length,42 12 | END 13 | -------------------------------------------------------------------------------- /examples/status.v3: -------------------------------------------------------------------------------- 1 | TITLE OpenVPN 2.1_rc15 mipsel-unknown-linux-gnu [SSL] [LZO1] [EPOLL] built on Mar 27 2009 2 | TIME Sun Jan 1 23:42:00 2012 1238702330 3 | HEADER CLIENT_LIST Common Name Real Address Virtual Address Bytes Received Bytes Sent Connected Since Connected Since (time_t) 4 | CLIENT_LIST foo 1.2.3.4:1234 192.168.66.2 11811160064 4194304 Sun Jan 1 23:42:00 2012 1238702330 5 | CLIENT_LIST bar 1.2.3.5:1235 2001:db8:0:0::1000 512 2048 Sun Jan 1 23:42:00 2012 1238702330 6 | HEADER ROUTING_TABLE Virtual Address Common Name Real Address Last Ref Last Ref (time_t) 7 | ROUTING_TABLE 192.168.0.0/24 foo 1.2.3.4:1234 Sun Jan 1 23:42:00 2012 1238702330 8 | ROUTING_TABLE 192.168.66.2 bar 1.2.3.5:1235 Sun Jan 1 23:42:00 2012 1238702330 9 | ROUTING_TABLE 192.168.66.3 foo 1.2.3.4:1234 Sun Jan 1 23:42:00 2012 1238702330 10 | ROUTING_TABLE 2001:db8:0:0::1000 bar 1.2.3.5:1235 Sun Jan 1 23:42:00 2012 1238702330 11 | GLOBAL_STATS Max bcast/mcast queue length 42 12 | END 13 | -------------------------------------------------------------------------------- /.github/renovate.json5: -------------------------------------------------------------------------------- 1 | { 2 | extends: [ 3 | "config:recommended", 4 | ":dependencyDashboard", 5 | ":prHourlyLimitNone", 6 | ":prConcurrentLimitNone", 7 | ":label(dependency-upgrade)", 8 | ], 9 | schedule: ["before 8am on thursday"], 10 | branchPrefix: "renovate-", 11 | dependencyDashboardHeader: "View repository job log [here](https://app.renovatebot.com/dashboard#github/cmur2/dyndnsd).", 12 | separateMinorPatch: true, 13 | commitMessagePrefix: "project: ", 14 | commitMessageAction: "update", 15 | commitMessageTopic: "{{depName}}", 16 | commitMessageExtra: "to {{#if isSingleVersion}}v{{{newVersion}}}{{else}}{{{newValue}}}{{/if}}", 17 | packageRules: [ 18 | // Ruby dependencies are managed by dependabot (previously depfu, until PR creation failed) 19 | { 20 | matchManagers: ["bundler"], 21 | enabled: false, 22 | }, 23 | // Commit message formats 24 | { 25 | matchDatasources: ["docker"], 26 | commitMessagePrefix: "docker: ", 27 | }, 28 | { 29 | matchManagers: ["github-actions"], 30 | commitMessagePrefix: "ci: ", 31 | }, 32 | ], 33 | customManagers: [ 34 | { 35 | customType: "regex", 36 | fileMatch: ["\.rb$", "^Rakefile$"], 37 | matchStrings: [ 38 | "renovate: datasource=(?.*?) depName=(?.*?)\\s.*_version = '(?.*)'\\s" 39 | ] 40 | }, 41 | ], 42 | } 43 | -------------------------------------------------------------------------------- /docs/debian-init-openvpn-status-web: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: openvpn-status-web 4 | # Required-Start: $remote_fs $syslog 5 | # Required-Stop: $remote_fs $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: Handle openvpn-status-web gem 9 | ### END INIT INFO 10 | 11 | # using the system ruby's gem binaries directory 12 | DAEMON="/var/lib/gems/1.8/bin/openvpn-status-web" 13 | 14 | CONFIG_FILE="/opt/openvpn-status-web/config.yaml" 15 | 16 | DAEMON_OPTS="$CONFIG_FILE" 17 | 18 | test -x $DAEMON || exit 0 19 | 20 | . /lib/lsb/init-functions 21 | 22 | case "$1" in 23 | start) 24 | log_daemon_msg "Starting openvpn-web-status" "openvpn-web-status" 25 | start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/openvpn-web-status.pid" --background --exec $DAEMON -- $DAEMON_OPTS 26 | ;; 27 | stop) 28 | log_daemon_msg "Stopping openvpn-web-status" "openvpn-web-status" 29 | start-stop-daemon --stop --quiet --oknodo --pidfile "/var/run/openvpn-web-status.pid" 30 | ;; 31 | restart|force-reload) 32 | log_daemon_msg "Restarting openvpn-web-status" "openvpn-web-status" 33 | start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile "/var/run/openvpn-web-status.pid" 34 | start-stop-daemon --start --quiet --oknodo --make-pidfile --pidfile "/var/run/openvpn-web-status.pid" --background --exec $DAEMON -- $DAEMON_OPTS 35 | ;; 36 | *) 37 | echo "Usage: $0 {start|stop|restart|force-reload}" >&2 38 | exit 1 39 | ;; 40 | esac 41 | -------------------------------------------------------------------------------- /openvpn-status-web.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'lib/openvpn-status-web/version' 4 | 5 | Gem::Specification.new do |s| 6 | s.name = 'openvpn-status-web' 7 | s.version = OpenVPNStatusWeb::VERSION 8 | s.summary = 'openvpn-status-web' 9 | s.description = 'Small Rack (Ruby) application serving OpenVPN status file.' 10 | s.author = 'Christian Nicolai' 11 | 12 | s.homepage = 'https://github.com/cmur2/openvpn-status-web' 13 | s.license = 'Apache-2.0' 14 | s.metadata = { 15 | 'bug_tracker_uri' => "#{s.homepage}/issues", 16 | 'source_code_uri' => s.homepage 17 | } 18 | 19 | s.files = `git ls-files -z`.split("\x0").select do |f| 20 | f.match(%r{^(init.d|lib)/}) 21 | end 22 | s.require_paths = ['lib'] 23 | s.bindir = 'exe' 24 | s.executables = ['openvpn-status-web'] 25 | s.extra_rdoc_files = Dir['README.md', 'LICENSE'] 26 | 27 | s.required_ruby_version = '>= 3.0' 28 | 29 | s.add_dependency 'metriks' 30 | s.add_dependency 'rack', '~> 3.0' 31 | s.add_dependency 'rackup', '~> 2' 32 | s.add_dependency 'webrick', '>= 1.6.1' 33 | 34 | s.add_development_dependency 'better_errors' 35 | s.add_development_dependency 'binding_of_caller' 36 | s.add_development_dependency 'bundler' 37 | s.add_development_dependency 'bundler-audit', '~> 0.9.0' 38 | s.add_development_dependency 'rack-test' 39 | s.add_development_dependency 'rake' 40 | s.add_development_dependency 'rspec' 41 | s.add_development_dependency 'rubocop', '~> 1.81.1' 42 | s.add_development_dependency 'rubocop-rake', '~> 0.7.1' 43 | s.add_development_dependency 'rubocop-rspec', '~> 3.8.0' 44 | s.add_development_dependency 'solargraph', '~> 0.50.0' 45 | end 46 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/parser/v1.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module OpenVPNStatusWeb 4 | module Parser 5 | class V1 6 | def parse_status_log(text) 7 | current_section = :none 8 | client_list = [] 9 | routing_table = [] 10 | global_stats = [] 11 | 12 | text.lines.each do |line| 13 | (current_section = :cl; next) if line == "OpenVPN CLIENT LIST\n" 14 | (current_section = :rt; next) if line == "ROUTING TABLE\n" 15 | (current_section = :gs; next) if line == "GLOBAL STATS\n" 16 | (current_section = :end; next) if line == "END\n" 17 | 18 | case current_section 19 | when :cl 20 | client_list << line.strip.split(',') 21 | when :rt 22 | routing_table << line.strip.split(',') 23 | when :gs 24 | global_stats << line.strip.split(',') 25 | end 26 | end 27 | 28 | status = Status.new 29 | status.client_list_headers = ['Common Name', 'Real Address', 'Data Received', 'Data Sent', 'Connected Since'] 30 | status.client_list = client_list[2..].map { |client| parse_client(client) } 31 | status.routing_table_headers = ['Virtual Address', 'Common Name', 'Real Address', 'Last Ref'] 32 | status.routing_table = routing_table[1..].map { |route| parse_route(route) } 33 | status.global_stats = global_stats.map { |global| parse_global(global) } 34 | status 35 | end 36 | 37 | private 38 | 39 | def parse_client(client) 40 | client[2] = client[2].to_i 41 | client[3] = client[3].to_i 42 | client[4] = DateTime.strptime(client[4], '%a %b %d %k:%M:%S %Y') 43 | client 44 | end 45 | 46 | def parse_route(route) 47 | route[3] = DateTime.strptime(route[3], '%a %b %d %k:%M:%S %Y') 48 | route 49 | end 50 | 51 | def parse_global(global) 52 | global[1] = global[1].to_i 53 | global 54 | end 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/parser/modern_stateless.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module OpenVPNStatusWeb 4 | module Parser 5 | class ModernStateless 6 | def self.parse_status_log(text, sep) 7 | status = Status.new 8 | status.client_list_headers = [] 9 | status.client_list = [] 10 | status.routing_table_headers = [] 11 | status.routing_table = [] 12 | status.global_stats = [] 13 | 14 | text.lines.each do |line| 15 | parts = line.strip.split(sep) 16 | status.client_list_headers = parts[2..] if parts[0] == 'HEADER' && parts[1] == 'CLIENT_LIST' 17 | status.client_list << parse_client(parts[1..], status.client_list_headers) if parts[0] == 'CLIENT_LIST' 18 | status.routing_table_headers = parts[2..] if parts[0] == 'HEADER' && parts[1] == 'ROUTING_TABLE' 19 | status.routing_table << parse_route(parts[1..], status.routing_table_headers) if parts[0] == 'ROUTING_TABLE' 20 | status.global_stats << parse_global(parts[1..2]) if parts[0] == 'GLOBAL_STATS' 21 | end 22 | 23 | status 24 | end 25 | 26 | private_class_method def self.parse_client(client, headers) 27 | headers.each_with_index do |header, i| 28 | client[i] = parse_date(client[i]) if header.end_with?('Since') 29 | client[i] = client[i].to_i if header.start_with?('Bytes') 30 | end 31 | 32 | client 33 | end 34 | 35 | private_class_method def self.parse_route(route, headers) 36 | headers.each_with_index do |header, i| 37 | route[i] = parse_date(route[i]) if header.end_with?('Last Ref') 38 | end 39 | 40 | route 41 | end 42 | 43 | private_class_method def self.parse_global(global) 44 | global[1] = global[1].to_i 45 | global 46 | end 47 | 48 | private_class_method def self.parse_date(date_string) 49 | DateTime.strptime(date_string, '%a %b %d %k:%M:%S %Y') 50 | rescue ArgumentError 51 | DateTime.strptime(date_string, '%Y-%m-%d %k:%M:%S') 52 | end 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | plugins: 2 | - rubocop-rake 3 | - rubocop-rspec 4 | 5 | AllCops: 6 | TargetRubyVersion: 3.0' 7 | NewCops: enable 8 | 9 | Gemspec/DevelopmentDependencies: 10 | EnforcedStyle: gemspec 11 | 12 | Gemspec/RequireMFA: 13 | Enabled: false 14 | 15 | Layout/EmptyLineAfterGuardClause: 16 | Enabled: false 17 | 18 | # allows nicer usage of private_class_method 19 | Layout/EmptyLinesAroundArguments: 20 | Enabled: false 21 | 22 | Layout/HashAlignment: 23 | Enabled: false 24 | 25 | Layout/LeadingEmptyLines: 26 | Enabled: false 27 | 28 | Layout/LineLength: 29 | Max: 200 30 | 31 | Layout/SpaceInsideHashLiteralBraces: 32 | Enabled: false 33 | 34 | Metrics/AbcSize: 35 | Enabled: false 36 | 37 | Metrics/BlockLength: 38 | Enabled: false 39 | 40 | Metrics/ClassLength: 41 | Enabled: false 42 | 43 | Metrics/CyclomaticComplexity: 44 | Enabled: false 45 | 46 | Metrics/MethodLength: 47 | Enabled: false 48 | 49 | Metrics/PerceivedComplexity: 50 | Enabled: false 51 | 52 | Naming/MethodParameterName: 53 | Enabled: false 54 | 55 | Naming/MemoizedInstanceVariableName: 56 | Enabled: false 57 | 58 | Style/AccessorGrouping: 59 | Enabled: false 60 | 61 | Style/ConditionalAssignment: 62 | Enabled: false 63 | 64 | Style/Documentation: 65 | Enabled: false 66 | 67 | Style/FormatStringToken: 68 | Enabled: false 69 | 70 | Style/GuardClause: 71 | Enabled: false 72 | 73 | Style/HashEachMethods: 74 | Enabled: true 75 | 76 | Style/HashTransformKeys: 77 | Enabled: true 78 | 79 | Style/HashTransformValues: 80 | Enabled: true 81 | 82 | Style/IdenticalConditionalBranches: 83 | Enabled: false 84 | 85 | Style/InverseMethods: 86 | Enabled: false 87 | 88 | Style/NegatedIf: 89 | Enabled: false 90 | 91 | Style/RescueModifier: 92 | Enabled: false 93 | 94 | Style/Semicolon: 95 | AllowAsExpressionSeparator: true 96 | 97 | Style/SymbolArray: 98 | Enabled: false 99 | 100 | RSpec/ExampleLength: 101 | Max: 10 102 | 103 | #RSpec/FilePath: 104 | # Enabled: false 105 | 106 | RSpec/SpecFilePathFormat: 107 | CustomTransform: 108 | OpenVPNStatusWeb: openvpn-status-web 109 | 110 | RSpec/MultipleExpectations: 111 | Max: 5 112 | -------------------------------------------------------------------------------- /spec/openvpn-status-web/parser/v1_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative '../../spec_helper' 4 | 5 | describe OpenVPNStatusWeb::Parser::V1 do 6 | def status 7 | status_v1 8 | end 9 | 10 | context 'with client list' do 11 | it 'parses common names' do 12 | expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar]) 13 | end 14 | 15 | it 'parses real addresses' do 16 | expect(status.client_list.map { |client| client[1] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235']) 17 | end 18 | 19 | it 'parses received bytes' do 20 | expect(status.client_list.map { |client| client[2] }).to eq([11_811_160_064, 512]) 21 | end 22 | 23 | it 'parses sent bytes' do 24 | expect(status.client_list.map { |client| client[3] }).to eq([4_194_304, 2048]) 25 | end 26 | 27 | it 'parses connected since date' do 28 | expect(status.client_list.map { |client| client[4] }).to eq( 29 | [ 30 | DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0) 31 | ] 32 | ) 33 | end 34 | 35 | it 'has the same number of headers' do 36 | expect(status.client_list[0].length).to eq(status.client_list_headers.length) 37 | end 38 | end 39 | 40 | context 'with routing table' do 41 | it 'parses virtual addresses' do 42 | expect(status.routing_table.map { |route| route[0] }).to eq(['192.168.0.0/24', '192.168.66.2', '192.168.66.3', '2001:db8:0:0::1000']) 43 | end 44 | 45 | it 'parses common names' do 46 | expect(status.routing_table.map { |route| route[1] }).to eq(%w[foo bar foo bar]) 47 | end 48 | 49 | it 'parses real addresses' do 50 | expect(status.routing_table.map { |route| route[2] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235', '1.2.3.4:1234', '1.2.3.5:1235']) 51 | end 52 | 53 | it 'parses last ref date' do 54 | expect(status.routing_table.map { |route| route[3] }).to eq( 55 | [ 56 | DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0), 57 | DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0) 58 | ] 59 | ) 60 | end 61 | 62 | it 'has the same number of headers' do 63 | expect(status.routing_table[0].length).to eq(status.routing_table_headers.length) 64 | end 65 | end 66 | 67 | it 'parses global stats' do 68 | expect(status.global_stats.size).to eq(1) 69 | expect(status.global_stats.first).to eq(['Max bcast/mcast queue length', 42]) 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # openvpn-status-web 2 | 3 | ![ci](https://github.com/cmur2/openvpn-status-web/workflows/ci/badge.svg) 4 | 5 | ## Description 6 | 7 | Small (another word for naive in this case, it's simple and serves my needs) [Rack](http://rack.github.com/) application providing the information an [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, ...). 8 | 9 | It lacks: 10 | 11 | * caching (parses file on each request, page does auto-refresh every minute as OpenVPN updates the status file these often by default) 12 | * management interface support 13 | * *possibly more...* 14 | 15 | ## Usage 16 | 17 | Install the gem: 18 | 19 | gem install openvpn-status-web 20 | 21 | Create a configuration file in YAML format somewhere: 22 | 23 | ```yaml 24 | # listen address and port 25 | host: "0.0.0.0" 26 | port: "8080" 27 | # optional: drop priviliges in case you want to but you should give this user at least read access on the log files 28 | user: "nobody" 29 | group: "nogroup" 30 | # logfile is optional, logs to STDOUT else 31 | logfile: "openvpn-status-web.log" 32 | # hash with each VPNs display name for humans as key and further config as value 33 | vpns: 34 | My Small VPN: 35 | # the status file path and status file format version are required 36 | version: 1 37 | status_file: "/var/log/openvpn-status.log" 38 | My Other VPN: 39 | version: 3 40 | status_file: "/var/log/other-openvpn-status.log" 41 | ``` 42 | 43 | Your OpenVPN configuration should contain something like this: 44 | 45 | ``` 46 | # ...snip... 47 | status /var/log/openvpn-status.log 48 | status-version 1 49 | # ...snip... 50 | ``` 51 | 52 | For more information about OpenVPN status file and version, see their [man page](https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage). openvpn-status-web is able to parse all versions from 1 to 3. 53 | 54 | ## Advanced topics 55 | 56 | ### Authentication 57 | 58 | If the information exposed is important to you serve it via the VPN or use a webserver as a proxy to handle SSL and/or HTTP authentication. 59 | 60 | ### Startup 61 | 62 | There is a [Dockerfile](docs/Dockerfile) that can be used to build a Docker image for running openvpn-status-web. 63 | 64 | This can for example be used with `docker-compose` via: 65 | 66 | ```yaml 67 | version: "2.4" 68 | services: 69 | openvpn-status-web: 70 | image: your-selfbuilt-docker-image 71 | user: root # needed since the default status files are chmod 600 72 | volumes: 73 | - /path/to/host/config.yml:/etc/openvpn-status-web/config.yml:ro 74 | - /run/openvpn-server:/run/openvpn-server 75 | ports: 76 | - "8080:8080" 77 | ``` 78 | 79 | The `/path/to/host/config.yml` could be: 80 | 81 | ```yaml 82 | host: "0.0.0.0" 83 | port: "8080" 84 | vpns: 85 | my-cool-vpn: # the following depends on your setup 86 | version: 2 87 | status_file: "/run/openvpn-server/status-my-cool-vpn.log" 88 | ``` 89 | 90 | ## License 91 | 92 | openvpn-status-web is licensed under the Apache License, Version 2.0. See LICENSE for more information. 93 | -------------------------------------------------------------------------------- /spec/openvpn-status-web/parser/modern_stateless_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative '../../spec_helper' 4 | 5 | describe OpenVPNStatusWeb::Parser::ModernStateless do 6 | { 7 | 2 => status_v2, 8 | 3 => status_v3 9 | }.each do |version, status| 10 | context "when status-version #{version}" do 11 | context 'with client list' do 12 | it 'parses common names' do 13 | expect(status.client_list.map { |client| client[0] }).to eq(%w[foo bar]) 14 | end 15 | 16 | it 'parses real addresses' do 17 | expect(status.client_list.map { |client| client[1] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235']) 18 | end 19 | 20 | it 'parses virtual addresses' do 21 | expect(status.client_list.map { |client| client[2] }).to eq(['192.168.66.2', '2001:db8:0:0::1000']) 22 | end 23 | 24 | it 'parses received bytes' do 25 | expect(status.client_list.map { |client| client[3] }).to eq([11_811_160_064, 512]) 26 | end 27 | 28 | it 'parses sent bytes' do 29 | expect(status.client_list.map { |client| client[4] }).to eq([4_194_304, 2048]) 30 | end 31 | 32 | it 'parses connected since date' do 33 | expect(status.client_list.map { |client| client[5] }).to eq( 34 | [ 35 | DateTime.new(2012, 1, 1, 23, 42, 0), 36 | DateTime.new(2012, 1, 1, 23, 42, 0) 37 | ] 38 | ) 39 | end 40 | 41 | it 'has the same number of headers' do 42 | expect(status.client_list[0].size).to eq(status.client_list_headers.size) 43 | end 44 | end 45 | 46 | context 'with routing table' do 47 | it 'parses virtual addresses' do 48 | expect(status.routing_table.map { |route| route[0] }).to eq(['192.168.0.0/24', '192.168.66.2', '192.168.66.3', '2001:db8:0:0::1000']) 49 | end 50 | 51 | it 'parses common names' do 52 | expect(status.routing_table.map { |route| route[1] }).to eq(%w[foo bar foo bar]) 53 | end 54 | 55 | it 'parses real addresses' do 56 | expect(status.routing_table.map { |route| route[2] }).to eq(['1.2.3.4:1234', '1.2.3.5:1235', '1.2.3.4:1234', '1.2.3.5:1235']) 57 | end 58 | 59 | it 'parses last ref date' do 60 | expect(status.routing_table.map { |route| route[3] }).to eq( 61 | [ 62 | DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0), 63 | DateTime.new(2012, 1, 1, 23, 42, 0), DateTime.new(2012, 1, 1, 23, 42, 0) 64 | ] 65 | ) 66 | end 67 | 68 | it 'has the same number of headers' do 69 | expect(status.routing_table[0].size).to eq(status.routing_table_headers.size) 70 | end 71 | end 72 | 73 | it 'parses global stats' do 74 | expect(status.global_stats.size).to eq(1) 75 | expect(status.global_stats.first).to eq(['Max bcast/mcast queue length', 42]) 76 | end 77 | end 78 | end 79 | 80 | it 'parses status-version 2 of OpenVPN 2.5' do 81 | expect(status_2_5_v2).not_to be_nil 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /lib/openvpn-status-web/main.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | OpenVPN Status 7 | 42 | 43 | 44 | 45 | <% vpns.each do |name,config| %> 46 | <% status = stati[name] %> 47 |

OpenVPN Status for <%= name %>

48 | 49 |

Client List

50 |
51 | 52 | 53 | <% status.client_list_headers.each_with_index do |header,i| %> 54 | <% if i == 0 %> 55 | 62 | <% end %> 63 | 64 | 65 | <% status.client_list.each do |client| %> 66 | 67 | <% status.client_list_headers.each_with_index do |header,i| %> 68 | <% if i == 0 %> 69 | 77 | <% elsif client[i].is_a? DateTime %> 78 | <%= client[i].strftime('%-d.%-m.%Y %H:%M:%S') %> 79 | <% else %> 80 | <%= client[i] %> 81 | <% end %> 82 | <% end %> 83 | 84 | <% end %> 85 | 86 |
56 | <% elsif i == status.client_list_headers.size-1 %> 57 | 58 | <% else %> 59 | 60 | <% end %> 61 | <%= header %>
70 | <% elsif i == status.client_list_headers.size-1 %> 71 | 72 | <% else %> 73 | 74 | <% end %> 75 | <% if header =~ /(Received|Sent)/ %> 76 | <%= client[i].as_bytes %>
87 |
88 | 89 |

Routing Table

90 |
91 | 92 | 93 | <% status.routing_table_headers.each_with_index do |header,i| %> 94 | <% if i == 0 %> 95 | 102 | <% end %> 103 | 104 | 105 | <% status.routing_table.each do |route| %> 106 | 107 | <% status.routing_table_headers.each_with_index do |header,i| %> 108 | <% if i == 0 %> 109 | 117 | <% else %> 118 | <%= route[i] %> 119 | <% end %> 120 | <% end %> 121 | 122 | <% end %> 123 | 124 |
96 | <% elsif i == status.routing_table_headers.size-1 %> 97 | 98 | <% else %> 99 | 100 | <% end %> 101 | <%= header %>
110 | <% elsif i == status.routing_table_headers.size-1 %> 111 | 112 | <% else %> 113 | 114 | <% end %> 115 | <% if route[i].is_a? DateTime %> 116 | <%= route[i].strftime('%-d.%-m.%Y %H:%M:%S') %>
125 |
126 | 127 |

Global Stats

128 |
129 | 130 | 131 | <% status.global_stats.each do |global| %> 132 | 133 | 134 | 135 | 136 | <% end %> 137 | 138 |
<%= global[0] %>:<%= global[1] %>
139 |
140 | <% end %> 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /lib/openvpn-status-web.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'date' 5 | require 'etc' 6 | require 'logger' 7 | require 'ipaddr' 8 | require 'yaml' 9 | require 'rack' 10 | require 'rackup' 11 | require 'erb' 12 | require 'metriks' 13 | require 'better_errors' if ENV.fetch('RACK_ENV', nil) == 'development' 14 | 15 | require 'openvpn-status-web/status' 16 | require 'openvpn-status-web/parser/v1' 17 | require 'openvpn-status-web/parser/v2' 18 | require 'openvpn-status-web/parser/v3' 19 | require 'openvpn-status-web/int_patch' 20 | require 'openvpn-status-web/version' 21 | 22 | module OpenVPNStatusWeb 23 | # @return [Logger] 24 | def self.logger 25 | @logger 26 | end 27 | 28 | # @param logger [Logger] 29 | # @return [Logger] 30 | def self.logger=(logger) 31 | @logger = logger 32 | end 33 | 34 | class LogFormatter 35 | # @param lvl [Object] 36 | # @param _time [DateTime] 37 | # @param _progname [String] 38 | # @param msg [Object] 39 | # @return [String] 40 | def call(lvl, _time, _progname, msg) 41 | format("[%s] %-5s %s\n", Time.now.strftime('%Y-%m-%d %H:%M:%S'), lvl, msg.to_s) 42 | end 43 | end 44 | 45 | class Daemon 46 | def initialize(vpns) 47 | @vpns = vpns 48 | 49 | @main_tmpl = read_template(File.join(File.dirname(__FILE__), 'openvpn-status-web/main.html.erb')) 50 | end 51 | 52 | def call(env) 53 | return [405, {'Content-Type' => 'text/plain'}, ['Method Not Allowed']] if env['REQUEST_METHOD'] != 'GET' 54 | return [404, {'Content-Type' => 'text/plain'}, ['Not Found']] if env['PATH_INFO'] != '/' 55 | 56 | # variables for template 57 | vpns = @vpns 58 | stati = {} 59 | @vpns.each do |name, config| 60 | stati[name] = parse_status_log(config) 61 | end 62 | # eval 63 | html = @main_tmpl.result(binding) 64 | 65 | [200, {'Content-Type' => 'text/html'}, [html]] 66 | end 67 | 68 | def read_template(file) 69 | text = File.read(file, mode: 'rb') 70 | 71 | ERB.new(text) 72 | end 73 | 74 | def parse_status_log(vpn) 75 | text = File.read(vpn['status_file'], mode: 'rb') 76 | 77 | case vpn['version'] 78 | when 1 79 | OpenVPNStatusWeb::Parser::V1.new.parse_status_log(text) 80 | when 2 81 | OpenVPNStatusWeb::Parser::V2.new.parse_status_log(text) 82 | when 3 83 | OpenVPNStatusWeb::Parser::V3.new.parse_status_log(text) 84 | else 85 | raise "No suitable parser for status-version #{vpn['version']}" 86 | end 87 | end 88 | 89 | # @return [void] 90 | def self.run! 91 | if ARGV.length != 1 92 | puts 'Usage: openvpn-status-web config_file' 93 | exit 1 94 | end 95 | 96 | config_file = ARGV[0] 97 | 98 | if !File.file?(config_file) 99 | puts 'Config file not found!' 100 | exit 1 101 | end 102 | 103 | puts "openvpn-status-web version #{OpenVPNStatusWeb::VERSION}" 104 | puts "Using config file #{config_file}" 105 | 106 | config = YAML.safe_load(File.read(config_file, mode: 'r')) 107 | 108 | if config['logfile'] 109 | OpenVPNStatusWeb.logger = Logger.new(config['logfile']) 110 | else 111 | OpenVPNStatusWeb.logger = Logger.new($stdout) 112 | end 113 | 114 | OpenVPNStatusWeb.logger.progname = 'openvpn-status-web' 115 | OpenVPNStatusWeb.logger.formatter = LogFormatter.new 116 | 117 | OpenVPNStatusWeb.logger.info 'Starting...' 118 | 119 | # drop priviliges as soon as possible 120 | # NOTE: first change group than user 121 | if config['group'] 122 | group = Etc.getgrnam(config['group']) 123 | Process::Sys.setgid(group.gid) if group 124 | end 125 | if config['user'] 126 | user = Etc.getpwnam(config['user']) 127 | Process::Sys.setuid(user.uid) if user 128 | end 129 | 130 | # configure rack 131 | app = Daemon.new(config['vpns']) 132 | if ENV.fetch('RACK_ENV', nil) == 'development' 133 | app = BetterErrors::Middleware.new(app) 134 | BetterErrors.application_root = File.expand_path(__dir__) 135 | end 136 | 137 | Signal.trap('INT') do 138 | OpenVPNStatusWeb.logger.info 'Quitting...' 139 | Rackup::Handler::WEBrick.shutdown 140 | end 141 | Signal.trap('TERM') do 142 | OpenVPNStatusWeb.logger.info 'Quitting...' 143 | Rackup::Handler::WEBrick.shutdown 144 | end 145 | 146 | Rackup::Handler::WEBrick.run app, Host: config['host'], Port: config['port'] 147 | end 148 | end 149 | end 150 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | --------------------------------------------------------------------------------