oxidized 0.36.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +30 -4
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +10 -3
  4. data/.github/ISSUE_TEMPLATE/support-request.md +30 -4
  5. data/.github/PULL_REQUEST_TEMPLATE.md +3 -1
  6. data/.github/workflows/codeql.yml +4 -4
  7. data/.github/workflows/publishdocker.yml +2 -2
  8. data/.github/workflows/ruby.yml +10 -3
  9. data/.github/workflows/stale.yml +1 -1
  10. data/.rubocop.yml +3 -0
  11. data/.rubocop_todo.yml +2 -8
  12. data/AGENTS.md +174 -0
  13. data/CHANGELOG.md +127 -0
  14. data/CONTRIBUTING.md +78 -44
  15. data/Dockerfile +8 -4
  16. data/README.md +8 -1
  17. data/Rakefile +1 -1
  18. data/docs/Configuration.md +10 -1
  19. data/docs/Creating-Models.md +6 -6
  20. data/docs/DeviceSimulation.md +80 -51
  21. data/docs/Docker.md +49 -0
  22. data/docs/Hooks.md +92 -67
  23. data/docs/Inputs.md +95 -16
  24. data/docs/Issues.md +49 -13
  25. data/docs/Model-Notes/FTD.md +64 -0
  26. data/docs/Model-Notes/GrandstreamHT8xx.md +8 -0
  27. data/docs/Model-Notes/HPEAruba.md +5 -0
  28. data/docs/Model-Notes/ITMGOS.md +40 -0
  29. data/docs/Model-Notes/PanOS_API.md +20 -1
  30. data/docs/Model-Notes/RouterOS.md +13 -0
  31. data/docs/Model-Notes/TPLink.md +75 -0
  32. data/docs/Model-Notes/TrueNAS.md +11 -7
  33. data/docs/Outputs.md +1 -0
  34. data/docs/Release.md +49 -22
  35. data/docs/Ruby-API.md +231 -9
  36. data/docs/Supported-OS-Types.md +10 -4
  37. data/docs/Troubleshooting.md +8 -9
  38. data/extra/device2yaml.rb +21 -5
  39. data/extra/hooks/modelrulesadvanced.rb +2 -4
  40. data/extra/oxidized.service +0 -1
  41. data/extra/syslog.rb +1 -1
  42. data/lib/oxidized/cli/support.rb +149 -0
  43. data/lib/oxidized/cli.rb +9 -0
  44. data/lib/oxidized/config/vars.rb +2 -1
  45. data/lib/oxidized/core.rb +20 -0
  46. data/lib/oxidized/hook/ciscosparkdiff.rb +1 -1
  47. data/lib/oxidized/hook/slackdiff.rb +1 -1
  48. data/lib/oxidized/hook/xmppdiff.rb +2 -2
  49. data/lib/oxidized/hook.rb +2 -0
  50. data/lib/oxidized/input/cli.rb +14 -2
  51. data/lib/oxidized/input/debugtext.rb +40 -0
  52. data/lib/oxidized/input/debugyaml.rb +82 -0
  53. data/lib/oxidized/input/exec.rb +1 -6
  54. data/lib/oxidized/input/ftp.rb +0 -4
  55. data/lib/oxidized/input/http.rb +23 -15
  56. data/lib/oxidized/input/scp.rb +3 -1
  57. data/lib/oxidized/input/ssh.rb +28 -21
  58. data/lib/oxidized/input/sshbase.rb +50 -24
  59. data/lib/oxidized/input/telnet.rb +14 -11
  60. data/lib/oxidized/input/tftp.rb +0 -4
  61. data/lib/oxidized/model/acos.rb +2 -2
  62. data/lib/oxidized/model/acsw.rb +1 -1
  63. data/lib/oxidized/model/adtran.rb +1 -1
  64. data/lib/oxidized/model/aireos.rb +3 -3
  65. data/lib/oxidized/model/aoscx.rb +20 -12
  66. data/lib/oxidized/model/aosw.rb +8 -13
  67. data/lib/oxidized/model/arbos.rb +1 -1
  68. data/lib/oxidized/model/aricentiss.rb +1 -1
  69. data/lib/oxidized/model/asa.rb +1 -1
  70. data/lib/oxidized/model/asternos.rb +1 -1
  71. data/lib/oxidized/model/audiocodesmp.rb +1 -1
  72. data/lib/oxidized/model/awplus.rb +4 -3
  73. data/lib/oxidized/model/bdcom.rb +1 -1
  74. data/lib/oxidized/model/br6910.rb +1 -1
  75. data/lib/oxidized/model/c4cmts.rb +1 -1
  76. data/lib/oxidized/model/ciscosmb.rb +0 -1
  77. data/lib/oxidized/model/cnos.rb +10 -1
  78. data/lib/oxidized/model/comnetms.rb +1 -1
  79. data/lib/oxidized/model/coriantgroove.rb +1 -1
  80. data/lib/oxidized/model/cumulus.rb +3 -3
  81. data/lib/oxidized/model/dellx.rb +1 -1
  82. data/lib/oxidized/model/dlink.rb +1 -1
  83. data/lib/oxidized/model/dlinknextgen.rb +2 -1
  84. data/lib/oxidized/model/dnos.rb +2 -2
  85. data/lib/oxidized/model/eatonnetwork.rb +33 -32
  86. data/lib/oxidized/model/eciapollo.rb +1 -1
  87. data/lib/oxidized/model/edgeos.rb +3 -3
  88. data/lib/oxidized/model/enterasys.rb +1 -1
  89. data/lib/oxidized/model/eos.rb +1 -0
  90. data/lib/oxidized/model/fastiron.rb +10 -1
  91. data/lib/oxidized/model/fiberdriver.rb +1 -1
  92. data/lib/oxidized/model/firelinuxos.rb +1 -1
  93. data/lib/oxidized/model/fortigate.rb +16 -3
  94. data/lib/oxidized/model/fortios.rb +1 -1
  95. data/lib/oxidized/model/ftd.rb +183 -0
  96. data/lib/oxidized/model/ftos.rb +2 -2
  97. data/lib/oxidized/model/garderos.rb +16 -5
  98. data/lib/oxidized/model/grandstreamht8xx.rb +19 -0
  99. data/lib/oxidized/model/hpebladesystem.rb +1 -1
  100. data/lib/oxidized/model/ibos.rb +1 -2
  101. data/lib/oxidized/model/ingate.rb +15 -1
  102. data/lib/oxidized/model/ios.rb +2 -0
  103. data/lib/oxidized/model/iosxr.rb +9 -3
  104. data/lib/oxidized/model/ironware.rb +1 -1
  105. data/lib/oxidized/model/itmgos.rb +74 -0
  106. data/lib/oxidized/model/junos.rb +10 -4
  107. data/lib/oxidized/model/kornfeldos.rb +2 -4
  108. data/lib/oxidized/model/lancom.rb +2 -2
  109. data/lib/oxidized/model/linuxgeneric.rb +4 -2
  110. data/lib/oxidized/model/masteros.rb +1 -1
  111. data/lib/oxidized/model/mlnxos.rb +1 -1
  112. data/lib/oxidized/model/model.rb +5 -2
  113. data/lib/oxidized/model/mtrlrfs.rb +1 -1
  114. data/lib/oxidized/model/ndms.rb +1 -1
  115. data/lib/oxidized/model/necix.rb +1 -1
  116. data/lib/oxidized/model/netgear.rb +1 -1
  117. data/lib/oxidized/model/netscaler.rb +1 -1
  118. data/lib/oxidized/model/nxos.rb +13 -1
  119. data/lib/oxidized/model/ocnos.rb +1 -1
  120. data/lib/oxidized/model/onefinity.rb +1 -1
  121. data/lib/oxidized/model/oneos.rb +0 -1
  122. data/lib/oxidized/model/openbsd.rb +1 -1
  123. data/lib/oxidized/model/os10.rb +2 -2
  124. data/lib/oxidized/model/os6.rb +3 -2
  125. data/lib/oxidized/model/panos.rb +1 -1
  126. data/lib/oxidized/model/panos_api.rb +42 -14
  127. data/lib/oxidized/model/procurve.rb +63 -31
  128. data/lib/oxidized/model/routeros.rb +6 -1
  129. data/lib/oxidized/model/screenos.rb +2 -2
  130. data/lib/oxidized/model/sgos.rb +1 -1
  131. data/lib/oxidized/model/siklu.rb +2 -2
  132. data/lib/oxidized/model/slxos.rb +1 -1
  133. data/lib/oxidized/model/sonicos.rb +2 -2
  134. data/lib/oxidized/model/tdre.rb +2 -2
  135. data/lib/oxidized/model/telco.rb +1 -1
  136. data/lib/oxidized/model/tmos.rb +11 -2
  137. data/lib/oxidized/model/tplink.rb +8 -10
  138. data/lib/oxidized/model/truenas.rb +56 -5
  139. data/lib/oxidized/model/viptela.rb +1 -1
  140. data/lib/oxidized/model/voltaire.rb +1 -1
  141. data/lib/oxidized/model/vrp.rb +14 -8
  142. data/lib/oxidized/model/vsololt.rb +93 -0
  143. data/lib/oxidized/model/vyatta.rb +3 -3
  144. data/lib/oxidized/model/vyos.rb +6 -1
  145. data/lib/oxidized/model/xos.rb +1 -1
  146. data/lib/oxidized/model/zhoneolt.rb +1 -1
  147. data/lib/oxidized/node.rb +9 -9
  148. data/lib/oxidized/nodes.rb +5 -13
  149. data/lib/oxidized/output/git.rb +72 -81
  150. data/lib/oxidized/output/gitcrypt.rb +13 -32
  151. data/lib/oxidized/redact.rb +18 -0
  152. data/lib/oxidized/signals.rb +2 -16
  153. data/lib/oxidized/source/source.rb +5 -1
  154. data/lib/oxidized/source/sql.rb +1 -0
  155. data/lib/oxidized/version.rb +2 -2
  156. data/lib/oxidized.rb +1 -0
  157. data/lib/refinements.rb +7 -3
  158. data/oxidized.gemspec +20 -11
  159. metadata +74 -29
@@ -15,9 +15,10 @@ class AWPlus < Oxidized::Model
15
15
 
16
16
  # Removes gibberish pager output e.g. VT100 escape codes
17
17
  cmd :all do |cfg|
18
- cfg.gsub! "\e[K", '' # example how to handle pager - cleareol EL0
19
- cfg.gsub! "\e[7m\e[m", '' # example how to handle pager - Reverse SGR7
20
- cfg.delete! "\r" # Filters rogue ^M - see issue #415
18
+ cfg.gsub! "\e[K", '' # remove pager erase to end of line (EL0)
19
+ cfg.gsub! "\e[7m\e[m", '' # remove pager reverse video on/off (SGR 7)
20
+ cfg.delete! "\r" # Filters rogue ^M - see issue #415
21
+ cfg.delete! "\a" # Filters stray BEL left after --More-- pager redraw - issue #3919
21
22
  cfg.cut_both
22
23
  end
23
24
 
@@ -10,7 +10,7 @@ class BDCOM < Oxidized::Model
10
10
  end
11
11
 
12
12
  cmd :all do |cfg|
13
- cfg.each_line.to_a[0..-2].join
13
+ cfg.cut_tail
14
14
  end
15
15
 
16
16
  cmd 'show running-config'
@@ -28,7 +28,7 @@ class BR6910 < Oxidized::Model
28
28
 
29
29
  cmd 'show running-config' do |cfg|
30
30
  arr = cfg.each_line.to_a
31
- arr[2..-1].join unless arr.length < 2
31
+ arr[2..].join unless arr.length < 2
32
32
  end
33
33
 
34
34
  cfg :telnet do
@@ -7,7 +7,7 @@ class C4CMTS < Oxidized::Model
7
7
  comment '! '
8
8
 
9
9
  cmd :all do |cfg|
10
- cfg.each_line.to_a[1..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n"
10
+ cfg.delete("\r").cut_both.rstrip_lines
11
11
  end
12
12
 
13
13
  cmd :secret do |cfg|
@@ -44,7 +44,6 @@ class CiscoSMB < Oxidized::Model
44
44
  end
45
45
 
46
46
  cmd 'show running-config' do |cfg|
47
- cfg = cfg.each_line.to_a[0..-1].join
48
47
  cfg.gsub! /^Current configuration : [^\n]*\n/, ''
49
48
  cfg.sub! /^(ntp clock-period).*/, '! \1'
50
49
  cfg.gsub! /^ tunnel mpls traffic-eng bandwidth[^\n]*\n*(
@@ -21,7 +21,16 @@ class CNOS < Oxidized::Model
21
21
  comment cfg
22
22
  end
23
23
 
24
+ # show license in combination with terminal length 0 is broken on older software versions (missing new line at the end of the output)
25
+ cmd 'show license' do |cfg|
26
+ comment cfg
27
+ end
28
+
29
+ # set terminal length 0 after show license to support older software versions
30
+ cmd 'terminal length 0'
31
+
24
32
  cmd 'show transceiver' do |cfg|
33
+ cfg.gsub! /^Port \S+ Transceiver Diagnostic:([\s\S]*?-{79}){3}/m, ''
25
34
  comment cfg
26
35
  end
27
36
 
@@ -32,7 +41,7 @@ class CNOS < Oxidized::Model
32
41
  end
33
42
 
34
43
  cfg :telnet, :ssh do
35
- post_login 'terminal length 0'
44
+ post_login 'terminal length 512'
36
45
  pre_logout 'exit'
37
46
  end
38
47
  end
@@ -6,7 +6,7 @@ class ComnetMS < Oxidized::Model
6
6
  comment '! '
7
7
 
8
8
  cmd :all do |cfg|
9
- cfg.each_line.to_a[1..-2].join
9
+ cfg.cut_both
10
10
  end
11
11
 
12
12
  cmd 'show running-config' do |cfg|
@@ -6,7 +6,7 @@ class CoriantGroove < Oxidized::Model
6
6
  prompt /^(\w+@.*>\s*)$/
7
7
 
8
8
  cmd :all do |cfg|
9
- cfg.each_line.to_a[1..-3].map { |line| line.delete("\r").rstrip }.join("\n") + "\n"
9
+ cfg.delete("\r").cut_both(1, 2).rstrip_lines
10
10
  end
11
11
 
12
12
  cmd 'show inventory' do |cfg|
@@ -5,9 +5,9 @@ class Cumulus < Oxidized::Model
5
5
  # ^ : match begin of line, to have the most specific prompt
6
6
  # [\w.-]+@[\w.-]+ : user@hostname
7
7
  # (:mgmt)? : optional when logged in out of band
8
- # :~[#$] $ : end of prompt, containing the linux path,
9
- # which is always "~" in our context
10
- prompt /^[\w.-]+@[\w.-]+(:mgmt)?:~[#$] $/
8
+ # :?~[#$] ?$ : end of prompt, containing the linux path,
9
+ # which is always "~" in our context.
10
+ prompt /^[\w.-]+@[\w.-]+(:mgmt)?:?~[#$] ?$/
11
11
  clean :escape_codes
12
12
  comment '# '
13
13
 
@@ -13,7 +13,7 @@ class DellX < Oxidized::Model
13
13
  end
14
14
 
15
15
  cmd :all do |cfg|
16
- cfg.each_line.to_a[1..-3].join
16
+ cfg.cut_both(1, 2)
17
17
  end
18
18
 
19
19
  cmd :secret do |cfg|
@@ -13,7 +13,7 @@ class Dlink < Oxidized::Model
13
13
  end
14
14
 
15
15
  cmd :all do |cfg|
16
- cfg.each_line.to_a[2..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n"
16
+ cfg.delete("\r").cut_both(2, 1).rstrip_lines
17
17
  end
18
18
 
19
19
  cmd 'show switch' do |cfg|
@@ -8,7 +8,8 @@ class DlinkNextGen < Oxidized::Model
8
8
  comment '# '
9
9
 
10
10
  cmd :all do |cfg|
11
- cfg.each_line.to_a[2..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n"
11
+ cfg.gsub!("\0", "") # Remove NULL bytes that cause Git to detect the file as binary
12
+ cfg.delete("\r").cut_both(2, 1).rstrip_lines
12
13
  end
13
14
 
14
15
  cmd :secret do |cfg|
@@ -8,7 +8,7 @@ class DNOS < Oxidized::Model
8
8
  cmd :all do |cfg|
9
9
  cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
10
10
  cfg.gsub! /(uptime is)(\s.+)/, '\\1 <removed>' # Omit changing uptime info
11
- cfg.each_line.to_a[2..-2].join
11
+ cfg.cut_both(2)
12
12
  end
13
13
 
14
14
  cmd :secret do |cfg|
@@ -35,7 +35,7 @@ class DNOS < Oxidized::Model
35
35
  end
36
36
 
37
37
  cmd 'show running-config' do |cfg|
38
- cfg = cfg.each_line.to_a[3..-1].join
38
+ cfg = cfg.cut_head(3)
39
39
  cfg
40
40
  end
41
41
 
@@ -9,27 +9,22 @@ class EatonNetwork < Oxidized::Model
9
9
  # See docs/Model-Notes/EatonNetwork.md for more info
10
10
  post do
11
11
  # Get config in post to allow passing auth password to cmd.
12
- cfg = cmd "save_configuration -p #{@node.auth[:password]}"
13
- cfg
12
+ cmd "save_configuration -p #{@node.auth[:password]}"
14
13
  end
15
14
 
16
15
  cmd :all do |cfg|
17
- # `save_configuration` echos the command back, outputs date time info, with
18
- # last line is the prompt again.
19
- json_str = cfg.each_line.select { |line| line.match /^\{/ }.join
20
- json = JSON.parse(json_str)
16
+ # save_configuration echoes the command and date/time around the JSON
17
+ # config (a single line) and ends with the prompt; keep only the JSON.
18
+ json = JSON.parse(cfg.keep_lines([/^\{/]))
21
19
 
22
- json['features']['userAndSessionManagement']['data']['settings']['all']['1.0']['local']['1.0']['predefinedAccounts'].each do |n|
23
- n.delete('attemptLogin')
24
- n['password'].delete('history')
25
- end
26
- json['features']['userAndSessionManagement']['data']['settings']['all']['1.0']['local']['1.0']['createdAccounts'].each do |n|
27
- n.delete('attemptLogin')
28
- n['password'].delete('history')
20
+ json.dig('features', 'userAndSessionManagement', 'data', 'settings', 'all', '1.0', 'local', '1.0').tap do |key|
21
+ (key['predefinedAccounts'] + key['createdAccounts']).each do |account|
22
+ account.delete('attemptLogin')
23
+ account['password'].delete('history')
24
+ end
29
25
  end
30
26
 
31
- cfg = JSON.pretty_generate(json)
32
- cfg
27
+ JSON.pretty_generate(json)
33
28
  end
34
29
 
35
30
  cmd :secret do |cfg|
@@ -37,30 +32,36 @@ class EatonNetwork < Oxidized::Model
37
32
  json = JSON.parse(cfg)
38
33
 
39
34
  json.delete('passphrase')
40
- json['features']['rms']['data']['settings'].delete('proxyUsername')
41
- json['features']['rms']['data']['settings'].delete('proxyPassword')
42
- json['features']['rms']['data']['settings'].delete('username')
43
- json['features']['rms']['data']['settings'].delete('password')
44
- json['features']['rms']['data']['settings'].delete('defaultPassword')
45
35
 
46
- json['features']['smtp']['data']['dmeData'].delete('password')
36
+ json.dig('features', 'rms', 'data', 'settings').tap do |key|
37
+ key.delete('proxyUsername')
38
+ key.delete('proxyPassword')
39
+ key.delete('username')
40
+ key.delete('password')
41
+ key.delete('defaultPassword')
42
+ end
43
+
44
+ json.dig('features', 'smtp', 'data', 'dmeData').delete('password')
47
45
 
48
- json['features']['snmp']['data']['dmeData']['v3']['users'].each do |n|
49
- n['auth'].delete('password')
50
- n['priv'].delete('password')
46
+ json.dig('features', 'snmp', 'data', 'dmeData', 'v3', 'users').each do |key|
47
+ key['auth'].delete('password')
48
+ key['priv'].delete('password')
51
49
  end
52
50
 
53
- json['features']['userAndSessionManagement']['data']['settings']['all']['1.0']['ldap']['1.0']['settings']['connectivity']['bind'].delete('password')
54
- json['features']['userAndSessionManagement']['data']['settings']['all']['1.0']['radius']['1.0']['settings']['connectivity']['primaryServer'].delete('secret')
55
- json['features']['userAndSessionManagement']['data']['settings']['all']['1.0']['radius']['1.0']['settings']['connectivity']['secondaryServer'].delete('secret')
51
+ json.dig('features', 'userAndSessionManagement', 'data', 'settings', 'all', '1.0').tap do |key|
52
+ key.dig('ldap', '1.0', 'settings', 'connectivity', 'bind').delete('password')
53
+ key.dig('radius', '1.0', 'settings', 'connectivity').tap do |radius|
54
+ radius['primaryServer'].delete('secret')
55
+ radius['secondaryServer'].delete('secret')
56
+ end
57
+ end
56
58
 
57
- # Added in frimware v2.2.0
58
- json['features']['peripherals']['data']['dmeData']['ethernet']['ports'].each do |n|
59
- n.dig('dot1x', 'peap', 'password') && n['dot1x']['peap'].delete('password')
59
+ # Added in firmware v2.2.0
60
+ json.dig('features', 'peripherals', 'data', 'dmeData', 'ethernet', 'ports').each do |key|
61
+ key.dig('dot1x', 'peap', 'password') && key['dot1x']['peap'].delete('password')
60
62
  end
61
63
 
62
- cfg = JSON.pretty_generate(json)
63
- cfg
64
+ JSON.pretty_generate(json)
64
65
  end
65
66
 
66
67
  cfg :ssh do
@@ -8,7 +8,7 @@ class ECIapollo < Oxidized::Model
8
8
  comment '# '
9
9
 
10
10
  cmd :all do |cfg|
11
- cfg.each_line.to_a[1..-2].join
11
+ cfg.cut_both
12
12
  end
13
13
 
14
14
  cmd :secret do |cfg|
@@ -6,7 +6,7 @@ class Edgeos < Oxidized::Model
6
6
  prompt /@.*?:~\$\s/
7
7
 
8
8
  cmd :all do |cfg|
9
- cfg.lines.to_a[1..-2].join
9
+ cfg.cut_both
10
10
  end
11
11
 
12
12
  cmd :secret do |cfg|
@@ -27,8 +27,8 @@ class Edgeos < Oxidized::Model
27
27
  cmd 'show configuration commands | no-more'
28
28
 
29
29
  cfg :telnet do
30
- username /login:\s/
31
- password /^Password:\s/
30
+ username /login:\s/
31
+ password /^Password:\s/
32
32
  end
33
33
 
34
34
  cfg :telnet, :ssh do
@@ -14,7 +14,7 @@ class Enterasys < Oxidized::Model
14
14
  end
15
15
 
16
16
  cmd :all do |cfg|
17
- cfg.each_line.to_a[2..-3].map { |line| line.delete("\r").rstrip }.join("\n") + "\n"
17
+ cfg.delete("\r").cut_both(2, 2).rstrip_lines
18
18
  end
19
19
 
20
20
  cmd 'show system hardware' do |cfg|
@@ -13,6 +13,7 @@ class EOS < Oxidized::Model
13
13
 
14
14
  cmd :secret do |cfg|
15
15
  cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
16
+ cfg.gsub! /^(snmp-server host \S+( vrf \S+)?( informs?| traps?)?( version (1|2c|3 (?:noauth|auth|priv)))?) \S+(.*)/, '\\1 <secret hidden>\\6'
16
17
  cfg.gsub! /(secret \w+) (\S+).*/, '\\1 <secret hidden>'
17
18
  cfg.gsub! /(password \d+) (\S+).*/, '\\1 <secret hidden>'
18
19
  cfg.gsub! /^(enable (?:secret|password)).*/, '\\1 <configuration removed>'
@@ -2,7 +2,16 @@ class FastIron < Oxidized::Model
2
2
  using Refinements
3
3
 
4
4
  prompt /^([\w.@\/()-]+[#>]\s?)$/
5
- comment '! '
5
+ comment '! '
6
+
7
+ # The pager cannot always be disabled with 'skip-page-display', for example
8
+ # when the user has no enable rights. See issue #3819
9
+ expect /--More--|Press any key to continue|Press <space> to continue/i do |data, re|
10
+ send ' '
11
+ data.sub re, ''
12
+ end
13
+
14
+ clean :escape_codes
6
15
 
7
16
  cmd :all do |cfg|
8
17
  # cfg.gsub! /\cH+\s{8}/, '' # example how to handle pager
@@ -12,7 +12,7 @@ class FiberDriver < Oxidized::Model
12
12
  end
13
13
 
14
14
  cmd "show running-config" do |cfg|
15
- cfg.each_line.to_a[3..-1].join
15
+ cfg = cfg.cut_head(3)
16
16
  cfg.gsub! /^Building configuration.*$/, ''
17
17
  cfg.gsub! /^Current configuration:.*$$/, ''
18
18
  cfg.gsub! /^! Configuration (saved|generated) on .*$/, ''
@@ -39,7 +39,7 @@ class FireLinuxOS < Oxidized::Model
39
39
  end
40
40
 
41
41
  cmd 'show running-config all' do |cfg|
42
- cfg = cfg.each_line.to_a[3..-1].join
42
+ cfg = cfg.cut_head(3)
43
43
  cfg.gsub! /^: [^\n]*\n/, ''
44
44
  cfg
45
45
  end
@@ -3,8 +3,14 @@ class FortiGate < Oxidized::Model
3
3
 
4
4
  comment '# '
5
5
 
6
- prompt /^(\(\w\) )?([-\w.~]+(\s[(\w\-.)]+)?~?\s?[#>$]\s?)$/
7
-
6
+ prompt(/
7
+ ^
8
+ (?:\(\w\)\ )? # optional status indicator, e.g. "(M) "
9
+ [-\w.~]+ # hostname
10
+ (?:\(\w+\))? # optional HA cluster status (Primary|Secondary)
11
+ (?:\ \([\w\-.]+\))? # optional VDOM
12
+ ~?\ ?[#>$]\ ?$ # End of prompt
13
+ /x)
8
14
  # When a post-login-banner is enabled, you have to press "a" to log in
9
15
  expect /^\(Press\s'a'\sto\saccept\):/ do |data, re|
10
16
  send 'a'
@@ -16,6 +22,13 @@ class FortiGate < Oxidized::Model
16
22
  data.sub re, ''
17
23
  end
18
24
 
25
+ # Newer FortiOS versions ask for confirmation before low-level firmware
26
+ # access in `diagnose hardware deviceinfo psu`
27
+ expect /Do you want to continue\? \(y\/n\)/i do |data, re|
28
+ send 'y'
29
+ data.sub re, ''
30
+ end
31
+
19
32
  cmd :all do |cfg|
20
33
  # Remove junk after --More-- pager
21
34
  cfg = cfg.gsub(/\r +\r/, '')
@@ -103,7 +116,7 @@ class FortiGate < Oxidized::Model
103
116
  cfg = cfg.keep_lines [
104
117
  /^Interface \w/,
105
118
  "Vendor Name",
106
- "Part No./",
119
+ "Part No.",
107
120
  "Serial No."
108
121
  ]
109
122
  cfg = cfg.reject_lines ["Transceiver is not detected"]
@@ -3,7 +3,7 @@ class FortiOS < Oxidized::Model
3
3
 
4
4
  comment '# '
5
5
 
6
- prompt /^(\(\w\) )?([-\w.~]+(\s[(\w\-.)]+)?~?\s?[#>$]\s?)$/
6
+ prompt /^(\(\w\) )?([-\w.~()]+(\s[(\w\-.)]+)?~?\s?[#>$]\s?)$/
7
7
 
8
8
  # When a post-login-banner is enabled, you have to press "a" to log in
9
9
  expect /^\(Press\s'a'\sto\saccept\):/ do |data, re|
@@ -0,0 +1,183 @@
1
+ require 'json'
2
+ require 'zip'
3
+
4
+ class FTD < Oxidized::Model
5
+ class FTDError < Oxidized::OxidizedError; end
6
+
7
+ # Encapsulates the multi-step FTD configuration export workflow. Given the
8
+ # http input, it drives the Secure Firewall Device Manager (FDM - Firepower
9
+ # Device Manager) REST API: authenticate, schedule a config
10
+ # export job, poll it, download the resulting zip and extract the config.
11
+ class ConfigExporter
12
+ include SemanticLogger::Loggable
13
+
14
+ def initialize(http:, auth:, headers:, settings:)
15
+ @http = http
16
+ @auth = auth
17
+ @headers = headers
18
+ @api_endpoint = settings[:api_endpoint]
19
+ @config_filename = settings[:config_filename]
20
+ @polls = settings[:polls]
21
+ @poll_wait = settings[:poll_wait]
22
+ end
23
+
24
+ def run
25
+ login
26
+ # Delete any pre-existing config file, otherwise the config export will fail.
27
+ delete_config_file
28
+ job_id = schedule_config_export
29
+ job_status = poll_job_status(job_id)
30
+ check_job_status(job_status)
31
+ config_file = download_config_file
32
+ delete_config_file
33
+ extract_config(config_file)
34
+ end
35
+
36
+ private
37
+
38
+ def login
39
+ payload = {
40
+ 'grant_type' => 'password',
41
+ 'username' => @auth[:username],
42
+ 'password' => @auth[:password]
43
+ }.to_json
44
+
45
+ body = @http.post_http("#{@api_endpoint}/fdm/token", payload)
46
+ token = JSON.parse(body)
47
+ @headers['Authorization'] = "#{token['token_type']} #{token['access_token']}"
48
+ rescue StandardError => e
49
+ raise FTDError, "Login failed: #{e.message}"
50
+ end
51
+
52
+ def delete_config_file
53
+ @http.delete_http("#{@api_endpoint}/action/configfiles/#{@config_filename}")
54
+ rescue StandardError => e
55
+ # Try to continue even if deletion fails.
56
+ logger.debug "Deleting config file failed: #{e.message}"
57
+ end
58
+
59
+ def schedule_config_export
60
+ payload = {
61
+ 'type' => 'scheduleconfigexport',
62
+ 'diskFileName' => @config_filename,
63
+ 'doNotEncrypt' => true,
64
+ 'deployedObjectsOnly' => true
65
+ }.to_json
66
+
67
+ body = @http.post_http("#{@api_endpoint}/action/configexport", payload)
68
+ config_export = JSON.parse(body)
69
+ config_export['jobHistoryUuid']
70
+ rescue StandardError => e
71
+ raise FTDError, "Scheduling config export failed: #{e.message}"
72
+ end
73
+
74
+ def poll_job_status(job_id)
75
+ job_status = nil
76
+
77
+ @polls.times do
78
+ sleep(@poll_wait)
79
+
80
+ begin
81
+ body = @http.get_http("#{@api_endpoint}/jobs/configexportstatus/#{job_id}")
82
+ job_status = JSON.parse(body)
83
+ rescue StandardError => e
84
+ # Keep polling if a poll fails.
85
+ logger.debug "Polling job status failed: #{e.message}"
86
+ end
87
+
88
+ break if %w[SUCCESS FAILED].include? job_status&.dig('status')
89
+ end
90
+
91
+ job_status
92
+ end
93
+
94
+ def check_job_status(job_status)
95
+ status = job_status&.dig('status')
96
+ return if status == 'SUCCESS'
97
+
98
+ message = if status == 'FAILED'
99
+ job_status&.dig('statusMessage')
100
+ else
101
+ job_status&.dig('error', 'messages', 0, 'description')
102
+ end
103
+
104
+ message ||= 'unknown error'
105
+ raise FTDError, "Config export job failed: #{message}"
106
+ end
107
+
108
+ def download_config_file
109
+ @http.get_http("#{@api_endpoint}/action/downloadconfigfile/#{@config_filename}")
110
+ rescue StandardError => e
111
+ raise FTDError, "Downloading config file failed: #{e.message}"
112
+ end
113
+
114
+ def extract_config(config_file)
115
+ zipfile = Zip::File.open_buffer(config_file)
116
+ config = zipfile.read('full_config.txt')
117
+ JSON.parse(config)
118
+ rescue Zip::Error => e
119
+ raise FTDError, "Opening zip file failed: #{e.message}"
120
+ rescue Errno::ENOENT
121
+ raise FTDError, 'full_config.txt not found in zip file'
122
+ rescue JSON::ParserError => e
123
+ raise FTDError, "Parsing config JSON failed: #{e.message}"
124
+ rescue StandardError => e
125
+ raise FTDError, "Extracting config failed: #{e.message}"
126
+ end
127
+ end
128
+
129
+ cfg_cb = lambda do
130
+ FTD::ConfigExporter.new(
131
+ # This callback is run via instance_exec on the http input, so `self` is
132
+ # the HTTP input instance providing get_http/post_http/delete_http.
133
+ http: self,
134
+ auth: @node.auth,
135
+ headers: @headers,
136
+ settings: {
137
+ api_endpoint: @api_endpoint,
138
+ config_filename: @config_filename,
139
+ polls: @polls,
140
+ poll_wait: @poll_wait
141
+ }
142
+ ).run
143
+ rescue FTDError => e
144
+ logger.debug e.message
145
+ false
146
+ end
147
+
148
+ cmd cfg_cb do |cfg|
149
+ # generatedOn contains the timestamp of the config export. Delete it to avoid unnecessary differences.
150
+ cfg[0].delete('generatedOn')
151
+
152
+ # This needs to be 'distiniguishedNames', not 'distinguishedNames'.
153
+ sort_list!(cfg, 'distinguishednamegroup', 'distiniguishedNames')
154
+ sort_list!(cfg, 'geolocation', 'locations')
155
+
156
+ JSON.pretty_generate(cfg)
157
+ end
158
+
159
+ cfg :http do
160
+ @api_endpoint = vars(:ftd_api_endpoint) || '/api/fdm/latest'
161
+ @config_filename = vars(:ftd_config_filename) || 'oxidized.zip'
162
+ @polls = [vars(:ftd_polls)&.to_i || 10, 1].max
163
+ @poll_wait = [vars(:ftd_poll_wait)&.to_i || 10, 1].max
164
+
165
+ @secure = true
166
+ @port = vars(:ftd_api_port) || 443
167
+
168
+ @headers = {
169
+ 'Accept' => 'application/json',
170
+ 'Content-Type' => 'application/json'
171
+ }
172
+ end
173
+
174
+ private
175
+
176
+ # Some lists seem to change order between exports. Sort the given list type
177
+ # in-place by id to avoid unnecessary differences.
178
+ def sort_list!(cfg, type, key)
179
+ cfg.each_with_index.select { |element, _| element['type'] == 'identitywrapper' and element['data']['type'] == type }.map(&:last).each do |i|
180
+ cfg[i]['data'][key].sort_by! { |element| element['id'] }
181
+ end
182
+ end
183
+ end
@@ -6,7 +6,7 @@ class FTOS < Oxidized::Model
6
6
  comment '! '
7
7
 
8
8
  cmd :all do |cfg|
9
- cfg.each_line.to_a[2..-2].join
9
+ cfg.cut_both(2)
10
10
  end
11
11
 
12
12
  cmd :secret do |cfg|
@@ -29,7 +29,7 @@ class FTOS < Oxidized::Model
29
29
  end
30
30
 
31
31
  cmd 'show running-config' do |cfg|
32
- cfg = cfg.each_line.to_a[3..-1].join
32
+ cfg = cfg.cut_head(3)
33
33
  cfg
34
34
  end
35
35
 
@@ -13,12 +13,23 @@ class Garderos < Oxidized::Model
13
13
  cfg.cut_both
14
14
  end
15
15
 
16
- cmd 'show system version' do |cfg|
17
- comment "#{cfg}\n"
16
+ cmd 'show system information' do |cfg|
17
+ cfg = cfg.reject_lines [
18
+ /^Uptime +:/,
19
+ /^Config Age +:/,
20
+ /^Startup +/,
21
+ /^Wakeup Int +:/,
22
+ /^Temperature *:/
23
+ ]
24
+ comment cfg + "\n"
18
25
  end
19
26
 
20
- cmd 'show system serial' do |cfg|
21
- comment "#{cfg}\n"
27
+ cmd 'show hardware all' do |cfg|
28
+ cfg = cfg.reject_lines [
29
+ /^ +VLAN \d+/,
30
+ /^ +Port \d+/
31
+ ]
32
+ comment cfg + "\n"
22
33
  end
23
34
 
24
35
  # If we have a radio modem installed, we'd like to list the SIM Card
@@ -26,7 +37,7 @@ class Garderos < Oxidized::Model
26
37
  if cfg.start_with? 'Unknown command'
27
38
  String.new('')
28
39
  else
29
- comment "#{cfg}\n"
40
+ comment cfg + "\n"
30
41
  end
31
42
  end
32
43
 
@@ -0,0 +1,19 @@
1
+ class GrandstreamHT8xx < Oxidized::Model
2
+ using Refinements
3
+
4
+ # Anchored prompt to avoid matching XML content
5
+ prompt /^(GS|CONFIG)>\s?$/
6
+ comment '# '
7
+
8
+ cfg :ssh do
9
+ # After login go to configuration submenu (looks like enabled in other devices)
10
+ post_login 'config'
11
+ # When logout use double exit - first from configuration submenu, and second to disconnect from device
12
+ pre_logout 'exit'
13
+ pre_logout 'exit'
14
+ end
15
+
16
+ cmd 'export' do |cfg|
17
+ cfg.cut_both
18
+ end
19
+ end