summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2017-02-16 17:43:27 +0200
committerGitHub <noreply@github.com>2017-02-16 17:43:27 +0200
commitdeae31cb04c184266e1b9c843325604a90113665 (patch)
tree12f9fe9ba263121d9bf6fdc819444d8c19321a5a
parentde81fdfad86f12318d6ca057018b67102b53b4c0 (diff)
parentcb6e34bf14658bf08d0c1dd67bc5f4168c2c0727 (diff)
Merge pull request #728 from mediumo/tplink
Tplink model
-rw-r--r--README.md2
-rw-r--r--lib/oxidized/model/tplink.rb65
2 files changed, 67 insertions, 0 deletions
diff --git a/README.md b/README.md
index cfc5040..e1d53fc 100644
--- a/README.md
+++ b/README.md
@@ -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/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
+