diff options
-rw-r--r-- | Dockerfile | 17 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | lib/oxidized/model/fortios.rb | 16 | ||||
-rw-r--r-- | lib/oxidized/model/opengear.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/model/timos.rb | 16 | ||||
-rw-r--r-- | lib/oxidized/model/tplink.rb | 65 | ||||
-rw-r--r-- | lib/oxidized/source/http.rb | 2 |
7 files changed, 112 insertions, 8 deletions
@@ -3,9 +3,22 @@ MAINTAINER Samer Abdel-Hafez <sam@arahant.net> RUN add-apt-repository ppa:brightbox/ruby-ng && \ apt-get update && \ - apt-get install -y ruby2.3 ruby2.3-dev libsqlite3-dev libssl-dev pkg-config make cmake libssh2-1-dev + apt-get install -y ruby2.3 ruby2.3-dev libsqlite3-dev libssl-dev pkg-config make cmake libssh2-1-dev git -RUN gem install oxidized oxidized-web --no-ri --no-rdoc +RUN mkdir -p /tmp/oxidized +COPY . /tmp/oxidized/ +WORKDIR /tmp/oxidized + +RUN gem build oxidized.gemspec +RUN gem install oxidized-*.gem + +# web interface +RUN gem install oxidized-web --no-ri --no-rdoc + +# dependencies for hooks +RUN gem install aws-sdk + +RUN rm -rf /tmp/oxidized RUN apt-get remove -y ruby-dev pkg-config make cmake @@ -148,6 +148,8 @@ Oxidized is a network device configuration backup tool. It's a RANCID replacemen * [Supermicro](lib/oxidized/model/supermicro.rb) * Trango Systems * [Trango](lib/oxidized/model/trango.rb) + * TPLink + * [TPLink](lib/oxidized/model/tplink.rb) * Ubiquiti * [AirOS](lib/oxidized/model/airos.rb) * [Edgeos](lib/oxidized/model/edgeos.rb) diff --git a/lib/oxidized/model/fortios.rb b/lib/oxidized/model/fortios.rb index cdb50d5..2415537 100644 --- a/lib/oxidized/model/fortios.rb +++ b/lib/oxidized/model/fortios.rb @@ -15,7 +15,8 @@ class FortiOS < Oxidized::Model end cmd :secret do |cfg| - cfg.gsub! /(set (?:passwd|password)).*/, '\\1 <configuration removed>' + cfg.gsub! /(set (?:passwd|password|psksecret)).*/, '\\1 <configuration removed>' + cfg.gsub! /(set private-key).*-+END ENCRYPTED PRIVATE KEY-*"$/m , '\\1 <configuration removed>' cfg end @@ -30,14 +31,18 @@ class FortiOS < Oxidized::Model cfg << cmd('config global') if @vdom_enabled cfg << cmd('get hardware status') do |cfg| - comment cfg + comment cfg end - cfg << cmd('diagnose autoupdate version') do |cfg| - comment cfg.each_line.reject { |line| line.match /Last Update|Result/ }.join + #default behaviour: include autoupdate output (backwards compatibility) + #do not include if variable "show_autoupdate" is set to false + if defined?(vars(:fortios_autoupdate)).nil? || vars(:fortios_autoupdate) + cfg << cmd('diagnose autoupdate version') do |cfg| + comment cfg.each_line.reject { |line| line.match /Last Update|Result/ }.join + end end - cfg << cmd('end') if @vdom_enabled +cfg << cmd('end') if @vdom_enabled cfg << cmd('show') cfg.join "\n" @@ -53,3 +58,4 @@ class FortiOS < Oxidized::Model end end + diff --git a/lib/oxidized/model/opengear.rb b/lib/oxidized/model/opengear.rb index 7f801f8..b7c697f 100644 --- a/lib/oxidized/model/opengear.rb +++ b/lib/oxidized/model/opengear.rb @@ -1,6 +1,8 @@ class OpenGear < Oxidized::Model comment '# ' + + prompt /^(\$\s)?$/ cmd :secret do |cfg| cfg.gsub!(/password (\S+)/, 'password <secret removed>') diff --git a/lib/oxidized/model/timos.rb b/lib/oxidized/model/timos.rb index d40e845..c230a8f 100644 --- a/lib/oxidized/model/timos.rb +++ b/lib/oxidized/model/timos.rb @@ -18,6 +18,8 @@ class TiMOS < Oxidized::Model # Show the boot options file. # cmd 'show bof' do |cfg| + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' comment cfg end @@ -29,6 +31,8 @@ class TiMOS < Oxidized::Model # Strip uptime. # cfg.sub! /^System Up Time.*\n/, '' + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' comment cfg end @@ -36,6 +40,8 @@ class TiMOS < Oxidized::Model # Show the card state. # cmd 'show card state' do |cfg| + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' comment cfg end @@ -48,6 +54,8 @@ class TiMOS < Oxidized::Model # cfg.gsub! /\r/, '' cfg.gsub! /[\b][\b][\b]/, "\n" + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' comment cfg end @@ -55,6 +63,8 @@ class TiMOS < Oxidized::Model # Show the running debug configuration. # cmd 'show debug' do |cfg| + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' comment cfg end @@ -66,6 +76,8 @@ class TiMOS < Oxidized::Model # Strip carriage returns. # cfg.gsub! /\r/, '' + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' comment cfg end @@ -77,6 +89,8 @@ class TiMOS < Oxidized::Model # Strip carriage returns. # cfg.gsub! /\r/, '' + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' comment cfg end @@ -88,6 +102,8 @@ class TiMOS < Oxidized::Model # Strip carriage returns. # cfg.gsub! /\r/, '' + cfg.gsub! /# Finished .*/, '' + cfg.gsub! /# Generated .*/, '' end cfg :telnet do diff --git a/lib/oxidized/model/tplink.rb b/lib/oxidized/model/tplink.rb new file mode 100644 index 0000000..bf13803 --- /dev/null +++ b/lib/oxidized/model/tplink.rb @@ -0,0 +1,65 @@ +class TPLink < Oxidized::Model + + # tp-link prompt + prompt /^\r?([\w.@()-]+[#>]\s?)$/ + comment '! ' + + # handle paging + # workaround for sometimes missing whitespaces with "\s?" + expect /Press\s?any\s?key\s?to\s?continue\s?\(Q\s?to\s?quit\)/ do |data, re| + send ' ' + data.sub re, '' + end + + # send carriage return because \n with the command is not enough + # checks if line ends with prompt >,# or \r,\nm otherwise send \r + expect /[^>#\r\n]$/ do |data, re| + send "\r" + data.sub re, '' + end + + cmd :all do |cfg| + # normalize linefeeds + cfg.gsub! /(\r|\r\n|\n\r)/,"\n" + # remove empty lines + cfg.each_line.reject { |line| line.match /^[\r\n\s\u0000#]+$/ }.join + end + + cmd :secret do |cfg| + cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>' + cfg.gsub! /secret (\d+) (\S+).*/, '<secret hidden>' + cfg + end + + cmd 'show system-info' do |cfg| + comment cfg.each_line.to_a[3..-3].join + end + + cmd 'show running-config' do |cfg| + lines = cfg.each_line.to_a[1..-1] + # cut config after "end" + lines[0..lines.index("end\n")].join + end + + cfg :telnet, :ssh do + username /^User ?[nN]ame:/ + password /^\r?Password:/ + end + + cfg :telnet, :ssh do + if vars :enable + post_login do + send "enable\r" + cmd vars(:enable) + end + end + + pre_logout do + send "exit\r" + send "logout\r" + end + + end + +end + diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 7186f98..6c12f29 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -29,7 +29,7 @@ class HTTP < Source end request = Net::HTTP::Get.new(uri.request_uri, headers) - if (@cfg.user && @cfg.pass) + if (@cfg.user? && @cfg.pass?) request.basic_auth(@cfg.user,@cfg.pass) end |