diff --git a/CHANGELOG.md b/CHANGELOG.md index eb566534e..7095cacb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] ### Added +- procurve: model unit test (@thanegill) + +### Changed +- procurve: rstrip trailing whitespace from commented command sections; add `String#rstrip_lines` refinement (@thanegill) +- procurve: remove ANSI escape codes with `clean :escape_codes` and simplify the prompt regexp (@thanegill) +- procurve: redact the additional credentials exposed by `include-credentials` / `encrypt-credentials`, with unit tests (@thanegill) + +### Fixed +- procurve: hide the SNMP community on `snmp-server host community ""` lines (@thanegill) +- procurve: hide local user password hashes (`password ... sha1 ""`) when remove_secret is true (@thanegill) - source/sql: support defining port in configuration. Closes #3853 (@ytti) ### Changed diff --git a/docs/Model-Notes/HPEAruba.md b/docs/Model-Notes/HPEAruba.md index fcacd00a4..c2a7c0dc0 100644 --- a/docs/Model-Notes/HPEAruba.md +++ b/docs/Model-Notes/HPEAruba.md @@ -30,3 +30,8 @@ Older Devices like [ProCurve](/lib/oxidized/model/procurve.rb) or 3Com/Comware are listed under the Vendor "HP" in the [Supported OS Types](/docs/Supported-OS-Types.md) list. +HPE Aruba switches running ArubaOS-Switch (the line that succeeded ProCurve - +e.g. the 2530, 2540, 2920, 2930F/2930M, 3810 and 5400R series) also use the +[procurve](/lib/oxidized/model/procurve.rb) model, even though they are branded +"Aruba". + diff --git a/docs/Supported-OS-Types.md b/docs/Supported-OS-Types.md index 3022e222a..b908496b0 100644 --- a/docs/Supported-OS-Types.md +++ b/docs/Supported-OS-Types.md @@ -114,7 +114,7 @@ |Hirschmann |Classic |[hirschmann](/lib/oxidized/model/hirschmann.rb) | |HiOS |[hios](/lib/oxidized/model/hios.rb) |HP |Comware (HP A-series, H3C, 3Com)|[comware](/lib/oxidized/model/comware.rb) |@robertcheramy |[Comware](Model-Notes/Comware.md) -| |Procurve |[procurve](/lib/oxidized/model/procurve.rb) |@robertcheramy +| |Procurve |[procurve](/lib/oxidized/model/procurve.rb) |@robertcheramy, @thanegill | |BladeSystem (Onboard Administrator)|[hpebladesystem](/lib/oxidized/model/hpebladesystem.rb) | |MSA |[hpemsa](/lib/oxidized/model/hpemsa.rb) | |MSM (Wireless Controller) |[hpmsm](/lib/oxidized/model/hpmsm.rb) diff --git a/lib/oxidized/model/adtran.rb b/lib/oxidized/model/adtran.rb index 90cd0c580..e2283b764 100644 --- a/lib/oxidized/model/adtran.rb +++ b/lib/oxidized/model/adtran.rb @@ -6,7 +6,7 @@ class Adtran < Oxidized::Model prompt /([\w.@-]+[#>]\s?)$/ cmd :all do |cfg| - cfg.each_line.to_a[2..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" + cfg.delete("\r").cut_both(2, 1).rstrip_lines end cmd :secret do |cfg| diff --git a/lib/oxidized/model/aosw.rb b/lib/oxidized/model/aosw.rb index fd5972180..dd02fd35a 100644 --- a/lib/oxidized/model/aosw.rb +++ b/lib/oxidized/model/aosw.rb @@ -52,31 +52,31 @@ class AOSW < Oxidized::Model /(Switch|AP) uptime/i, /Reboot Time and Cause/i ] - rstrip_cfg comment cfg + clean_comment cfg end cmd 'show inventory' do |cfg| # Don't show for unsupported devices (IAP and MAS) cfg = "" if cfg =~ /(Invalid input detected at '\^' marker|Parse error)/ - rstrip_cfg clean cfg + clean(cfg).rstrip_lines end cmd 'show slots' do |cfg| # Don't show for unsupported devices (IAP and MAS) cfg = "" if cfg =~ /(Invalid input detected at '\^' marker|Parse error)/ - rstrip_cfg comment cfg + clean_comment cfg end cmd 'show license' do |cfg| # Don't show for unsupported devices (IAP and MAS) cfg = "" if cfg =~ /(Invalid input detected at '\^' marker|Parse error)/ - rstrip_cfg comment cfg + clean_comment cfg end cmd 'show license passphrase' do |cfg| # Don't show for unsupported devices (IAP and MAS) cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/ - rstrip_cfg comment cfg + clean_comment cfg end cmd 'show running-config' do |cfg| @@ -84,7 +84,7 @@ class AOSW < Oxidized::Model /^controller config \d+$/, /^Building Configuration/ ] - rstrip_cfg cfg + cfg.rstrip_lines end cfg :telnet do @@ -105,13 +105,8 @@ class AOSW < Oxidized::Model pre_logout 'exit' end - def rstrip_cfg(cfg) - out = [] - cfg.each_line do |line| - out << line.rstrip - end - out = out.join "\n" - out << "\n" + def clean_comment(lines) + comment(lines).rstrip_lines end def clean(cfg) diff --git a/lib/oxidized/model/c4cmts.rb b/lib/oxidized/model/c4cmts.rb index 2bc8baeb6..d53441f2b 100644 --- a/lib/oxidized/model/c4cmts.rb +++ b/lib/oxidized/model/c4cmts.rb @@ -7,7 +7,7 @@ class C4CMTS < Oxidized::Model comment '! ' cmd :all do |cfg| - cfg.each_line.to_a[1..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" + cfg.delete("\r").cut_both.rstrip_lines end cmd :secret do |cfg| diff --git a/lib/oxidized/model/coriantgroove.rb b/lib/oxidized/model/coriantgroove.rb index b9eb9e2a4..bc68264f6 100644 --- a/lib/oxidized/model/coriantgroove.rb +++ b/lib/oxidized/model/coriantgroove.rb @@ -6,7 +6,7 @@ class CoriantGroove < Oxidized::Model prompt /^(\w+@.*>\s*)$/ cmd :all do |cfg| - cfg.each_line.to_a[1..-3].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" + cfg.delete("\r").cut_both(1, 2).rstrip_lines end cmd 'show inventory' do |cfg| diff --git a/lib/oxidized/model/dlink.rb b/lib/oxidized/model/dlink.rb index 01319bdb1..7caf102ff 100644 --- a/lib/oxidized/model/dlink.rb +++ b/lib/oxidized/model/dlink.rb @@ -13,7 +13,7 @@ class Dlink < Oxidized::Model end cmd :all do |cfg| - cfg.each_line.to_a[2..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" + cfg.delete("\r").cut_both(2, 1).rstrip_lines end cmd 'show switch' do |cfg| diff --git a/lib/oxidized/model/dlinknextgen.rb b/lib/oxidized/model/dlinknextgen.rb index ead9c9397..cb68299ae 100644 --- a/lib/oxidized/model/dlinknextgen.rb +++ b/lib/oxidized/model/dlinknextgen.rb @@ -9,7 +9,7 @@ class DlinkNextGen < Oxidized::Model cmd :all do |cfg| cfg.gsub!("\0", "") # Remove NULL bytes that cause Git to detect the file as binary - cfg.each_line.to_a[2..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" + cfg.delete("\r").cut_both(2, 1).rstrip_lines end cmd :secret do |cfg| diff --git a/lib/oxidized/model/enterasys.rb b/lib/oxidized/model/enterasys.rb index ec8e7886a..1fd46cdc4 100644 --- a/lib/oxidized/model/enterasys.rb +++ b/lib/oxidized/model/enterasys.rb @@ -14,7 +14,7 @@ class Enterasys < Oxidized::Model end cmd :all do |cfg| - cfg.each_line.to_a[2..-3].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" + cfg.delete("\r").cut_both(2, 2).rstrip_lines end cmd 'show system hardware' do |cfg| diff --git a/lib/oxidized/model/hpebladesystem.rb b/lib/oxidized/model/hpebladesystem.rb index 5410d09d7..227612325 100644 --- a/lib/oxidized/model/hpebladesystem.rb +++ b/lib/oxidized/model/hpebladesystem.rb @@ -12,7 +12,7 @@ class HPEBladeSystem < Oxidized::Model # end cmd :all do |cfg| - cfg = cfg.delete("\r").each_line.to_a[0..-1].map { |line| line.rstrip }.join("\n") + "\n" + cfg = cfg.delete("\r").rstrip_lines cfg.cut_tail end diff --git a/lib/oxidized/model/junos.rb b/lib/oxidized/model/junos.rb index 482faec40..9fd728edf 100644 --- a/lib/oxidized/model/junos.rb +++ b/lib/oxidized/model/junos.rb @@ -12,7 +12,7 @@ def telnet cfg = cfg.cut_both if screenscrape cfg.gsub!(/ scale-subscriber (\s+)(\d+)/, ' scale-subscriber ') cfg.gsub!(/VMX-BANDWIDTH\s+(\d+) (.*)/, 'VMX-BANDWIDTH \2') - cfg.lines.map { |line| line.rstrip }.join("\n") + "\n" + cfg.rstrip_lines end cmd :secret do |cfg| diff --git a/lib/oxidized/model/mtrlrfs.rb b/lib/oxidized/model/mtrlrfs.rb index 63b756043..d6b7d3d01 100644 --- a/lib/oxidized/model/mtrlrfs.rb +++ b/lib/oxidized/model/mtrlrfs.rb @@ -9,7 +9,7 @@ class Mtrlrfs < Oxidized::Model cmd :all do |cfg| # xos inserts leading \r characters and other trailing white space. # this deletes extraneous \r and trailing white space. - cfg.each_line.to_a[1..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" + cfg.delete("\r").cut_both.rstrip_lines end cmd 'show version' do |cfg| diff --git a/lib/oxidized/model/procurve.rb b/lib/oxidized/model/procurve.rb index a1d80fddf..b1d7268d2 100644 --- a/lib/oxidized/model/procurve.rb +++ b/lib/oxidized/model/procurve.rb @@ -1,26 +1,26 @@ class Procurve < Oxidized::Model using Refinements - # previous command is repeated followed by "\eE", which sometimes ends up on last line - # ssh switches prompt may start with \r, followed by the prompt itself, regex ([\w\s.-]+[#>] ), which ends the line - # telnet switches may start with various vt100 control characters, regex (\e\[24;[0-9][hH]), followed by the prompt, followed - # by at least 3 other vt100 characters - prompt /(^\r|\e\[24;[0-9][hH])?([\w\s.-]+[#>] )($|(\e\[24;[0-9][0-9]?[hH]){3})/ + # The prompt is the device name followed by '#' or '>' and a + # space, optionally preceded by a carriage return on ssh. + prompt /(^\r)?([\w\s.-]+[#>] )$/ comment '! ' - # replace next line control sequence with a new line + # These sequences are line breaks in the terminal stream: \e[1M...\e[1L is a + # delete-line/insert-line redraw and \eE is NEL (next line). They must be + # converted to newlines, not stripped, or the surrounding text concatenates. + # This has to run before clean :escape_codes, which would otherwise remove the + # \e[1M / \e[1L sequences (and does not match \eE at all). expect /(\e\[1M\e\[\??\d+(;\d+)*[A-Za-z]\e\[1L)|(\eE)/ do |data, re| data.gsub re, "\n" end - # replace all used vt100 control sequences - expect /\e\[\??\d+(;\d+)*[A-Za-z]/ do |data, re| - data.gsub re, '' - end + # remove all other vt100 control sequences + clean :escape_codes - expect /Press any key to continue(\e\[\??\d+(;\d+)*[A-Za-z])*$/ do - send ' ' + expect /Press any key to continue$/ do + send "\n" "" end @@ -32,8 +32,6 @@ class Procurve < Oxidized::Model cmd :all do |cfg| cfg = cfg.cut_both cfg = cfg.gsub /^\r/, '' - # Additional filtering for elder switches sending vt100 control chars via telnet - cfg.gsub! /\e\[\??\d+(;\d+)*[A-Za-z]/, '' # Additional filtering for power usage reporting which obviously changes over time cfg.gsub! /^(.*AC [0-9]{3}V\/?([0-9]{3}V)?) *([0-9]{1,3}) (.*)/, '\\1 \\4' # Remove failed commands that are not supported on all models @@ -41,45 +39,73 @@ class Procurve < Oxidized::Model cfg end + # Most of these credentials only appear in the running-config when + # include-credentials (and/or encrypt-credentials) is enabled; see the + # ArubaOS-Switch Access Security Guide. encrypt-credentials renames the + # plaintext keyword to an encrypted- variant (key -> encrypted-key, etc.) and + # stores an AES blob in place of the cleartext/hashed value. cmd :secret do |cfg| + # SNMPv1 community names cfg.gsub! /^(snmp-server community) \S+(.*)/, '\\1