oxidized 0.37.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 (139) 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_todo.yml +2 -8
  11. data/AGENTS.md +174 -0
  12. data/CHANGELOG.md +101 -0
  13. data/CONTRIBUTING.md +78 -44
  14. data/Dockerfile +8 -4
  15. data/README.md +8 -1
  16. data/docs/Creating-Models.md +5 -5
  17. data/docs/DeviceSimulation.md +80 -51
  18. data/docs/Docker.md +49 -0
  19. data/docs/Inputs.md +81 -5
  20. data/docs/Issues.md +49 -13
  21. data/docs/Model-Notes/FTD.md +64 -0
  22. data/docs/Model-Notes/HPEAruba.md +5 -0
  23. data/docs/Model-Notes/ITMGOS.md +40 -0
  24. data/docs/Model-Notes/PanOS_API.md +20 -1
  25. data/docs/Model-Notes/TPLink.md +75 -0
  26. data/docs/Outputs.md +1 -0
  27. data/docs/Release.md +43 -21
  28. data/docs/Ruby-API.md +231 -9
  29. data/docs/Supported-OS-Types.md +10 -5
  30. data/docs/Troubleshooting.md +8 -9
  31. data/extra/device2yaml.rb +21 -5
  32. data/extra/hooks/modelrulesadvanced.rb +2 -3
  33. data/extra/oxidized.service +0 -1
  34. data/extra/syslog.rb +1 -1
  35. data/lib/oxidized/cli/support.rb +4 -7
  36. data/lib/oxidized/config/vars.rb +2 -1
  37. data/lib/oxidized/core.rb +20 -0
  38. data/lib/oxidized/hook/ciscosparkdiff.rb +1 -1
  39. data/lib/oxidized/hook/slackdiff.rb +1 -1
  40. data/lib/oxidized/hook/xmppdiff.rb +2 -2
  41. data/lib/oxidized/input/cli.rb +14 -2
  42. data/lib/oxidized/input/http.rb +22 -7
  43. data/lib/oxidized/input/scp.rb +3 -1
  44. data/lib/oxidized/input/sshbase.rb +43 -12
  45. data/lib/oxidized/input/telnet.rb +2 -2
  46. data/lib/oxidized/model/acos.rb +2 -2
  47. data/lib/oxidized/model/acsw.rb +1 -1
  48. data/lib/oxidized/model/adtran.rb +1 -1
  49. data/lib/oxidized/model/aireos.rb +3 -3
  50. data/lib/oxidized/model/aoscx.rb +7 -3
  51. data/lib/oxidized/model/aosw.rb +8 -13
  52. data/lib/oxidized/model/arbos.rb +1 -1
  53. data/lib/oxidized/model/aricentiss.rb +1 -1
  54. data/lib/oxidized/model/asa.rb +1 -1
  55. data/lib/oxidized/model/asternos.rb +1 -1
  56. data/lib/oxidized/model/audiocodesmp.rb +1 -1
  57. data/lib/oxidized/model/awplus.rb +4 -3
  58. data/lib/oxidized/model/bdcom.rb +1 -1
  59. data/lib/oxidized/model/br6910.rb +1 -1
  60. data/lib/oxidized/model/c4cmts.rb +1 -1
  61. data/lib/oxidized/model/ciscosmb.rb +0 -1
  62. data/lib/oxidized/model/cnos.rb +10 -1
  63. data/lib/oxidized/model/comnetms.rb +1 -1
  64. data/lib/oxidized/model/coriantgroove.rb +1 -1
  65. data/lib/oxidized/model/dellx.rb +1 -1
  66. data/lib/oxidized/model/dlink.rb +1 -1
  67. data/lib/oxidized/model/dlinknextgen.rb +1 -1
  68. data/lib/oxidized/model/dnos.rb +2 -2
  69. data/lib/oxidized/model/eatonnetwork.rb +33 -32
  70. data/lib/oxidized/model/eciapollo.rb +1 -1
  71. data/lib/oxidized/model/edgeos.rb +3 -3
  72. data/lib/oxidized/model/enterasys.rb +1 -1
  73. data/lib/oxidized/model/eos.rb +1 -0
  74. data/lib/oxidized/model/fastiron.rb +10 -1
  75. data/lib/oxidized/model/fiberdriver.rb +1 -1
  76. data/lib/oxidized/model/firelinuxos.rb +1 -1
  77. data/lib/oxidized/model/fortigate.rb +15 -2
  78. data/lib/oxidized/model/fortios.rb +1 -1
  79. data/lib/oxidized/model/ftd.rb +183 -0
  80. data/lib/oxidized/model/ftos.rb +2 -2
  81. data/lib/oxidized/model/garderos.rb +16 -5
  82. data/lib/oxidized/model/hpebladesystem.rb +1 -1
  83. data/lib/oxidized/model/ibos.rb +1 -2
  84. data/lib/oxidized/model/ingate.rb +15 -1
  85. data/lib/oxidized/model/iosxr.rb +9 -3
  86. data/lib/oxidized/model/ironware.rb +1 -1
  87. data/lib/oxidized/model/itmgos.rb +74 -0
  88. data/lib/oxidized/model/junos.rb +8 -2
  89. data/lib/oxidized/model/kornfeldos.rb +2 -4
  90. data/lib/oxidized/model/lancom.rb +2 -2
  91. data/lib/oxidized/model/masteros.rb +1 -1
  92. data/lib/oxidized/model/mlnxos.rb +1 -1
  93. data/lib/oxidized/model/model.rb +5 -2
  94. data/lib/oxidized/model/mtrlrfs.rb +1 -1
  95. data/lib/oxidized/model/ndms.rb +1 -1
  96. data/lib/oxidized/model/necix.rb +1 -1
  97. data/lib/oxidized/model/netgear.rb +1 -1
  98. data/lib/oxidized/model/netscaler.rb +1 -1
  99. data/lib/oxidized/model/nxos.rb +11 -2
  100. data/lib/oxidized/model/ocnos.rb +1 -1
  101. data/lib/oxidized/model/onefinity.rb +1 -1
  102. data/lib/oxidized/model/oneos.rb +0 -1
  103. data/lib/oxidized/model/openbsd.rb +1 -1
  104. data/lib/oxidized/model/os10.rb +2 -2
  105. data/lib/oxidized/model/os6.rb +3 -2
  106. data/lib/oxidized/model/panos.rb +1 -1
  107. data/lib/oxidized/model/panos_api.rb +42 -14
  108. data/lib/oxidized/model/procurve.rb +63 -31
  109. data/lib/oxidized/model/routeros.rb +2 -1
  110. data/lib/oxidized/model/screenos.rb +2 -2
  111. data/lib/oxidized/model/sgos.rb +1 -1
  112. data/lib/oxidized/model/siklu.rb +2 -2
  113. data/lib/oxidized/model/slxos.rb +1 -1
  114. data/lib/oxidized/model/sonicos.rb +2 -2
  115. data/lib/oxidized/model/tdre.rb +2 -2
  116. data/lib/oxidized/model/telco.rb +1 -1
  117. data/lib/oxidized/model/tmos.rb +11 -2
  118. data/lib/oxidized/model/tplink.rb +4 -4
  119. data/lib/oxidized/model/viptela.rb +1 -1
  120. data/lib/oxidized/model/voltaire.rb +1 -1
  121. data/lib/oxidized/model/vrp.rb +14 -8
  122. data/lib/oxidized/model/vsololt.rb +93 -0
  123. data/lib/oxidized/model/vyatta.rb +3 -3
  124. data/lib/oxidized/model/vyos.rb +5 -1
  125. data/lib/oxidized/model/xos.rb +1 -1
  126. data/lib/oxidized/model/zhoneolt.rb +1 -1
  127. data/lib/oxidized/node.rb +9 -9
  128. data/lib/oxidized/nodes.rb +5 -13
  129. data/lib/oxidized/output/git.rb +72 -81
  130. data/lib/oxidized/output/gitcrypt.rb +13 -32
  131. data/lib/oxidized/redact.rb +18 -0
  132. data/lib/oxidized/signals.rb +2 -16
  133. data/lib/oxidized/source/source.rb +5 -1
  134. data/lib/oxidized/source/sql.rb +1 -0
  135. data/lib/oxidized/version.rb +2 -2
  136. data/lib/oxidized.rb +1 -0
  137. data/lib/refinements.rb +7 -3
  138. data/oxidized.gemspec +20 -11
  139. metadata +69 -29
@@ -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/, '')
@@ -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
 
@@ -12,7 +12,7 @@ class HPEBladeSystem < Oxidized::Model
12
12
  # end
13
13
 
14
14
  cmd :all do |cfg|
15
- cfg = cfg.delete("\r").each_line.to_a[0..-1].map { |line| line.rstrip }.join("\n") + "\n"
15
+ cfg = cfg.delete("\r").rstrip_lines
16
16
  cfg.cut_tail
17
17
  end
18
18
 
@@ -8,7 +8,7 @@ class IBOS < 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|
@@ -31,7 +31,6 @@ class IBOS < Oxidized::Model
31
31
  end
32
32
 
33
33
  cmd 'show running-config' do |cfg|
34
- cfg = cfg.each_line.to_a[0..-1].join
35
34
  cfg.gsub! /.*!volatile.*/, ''
36
35
  cfg
37
36
  end
@@ -22,7 +22,21 @@ class Ingate < Oxidized::Model
22
22
  end
23
23
 
24
24
  cmd cfg_cb do |cfg|
25
- cfg.gsub! /^# Timestamp:.*$/, ''
25
+ cfg.gsub(/^# Timestamp:.*$/, '')
26
+ end
27
+
28
+ cmd :secret do |cfg|
29
+ # Private keys: any *key field whose quoted value is a PEM private key block
30
+ # (the value spans multiple lines).
31
+ cfg.gsub!(/\b([a-z_]*key)="-----BEGIN [A-Z ]*PRIVATE KEY-----.*?-----END [A-Z ]*PRIVATE KEY-----"/m,
32
+ '\1="<secret hidden>"')
33
+ # Ingate spreads credentials across many fields. Match by suffix so we cover
34
+ # them all (e.g. trunkuserpassword, snmppassword, radiussecret,
35
+ # configencpassphrase, xauth_psk, eabhmackey, api_token) without touching
36
+ # lookalikes such as passwordtimeout or enable_psk_rw.
37
+ cfg.gsub!(/\b([a-z_]*(?:password|secret|passphrase|psk|hmackey|api_token|authtoken))=(?:"[^"]*"|\S+)/,
38
+ '\1=<secret hidden>')
39
+ cfg.gsub!(/\bcommunity=(?:"[^"]*"|\S+)/, 'community=<secret hidden>')
26
40
  cfg
27
41
  end
28
42
 
@@ -7,7 +7,8 @@ class IOSXR < Oxidized::Model
7
7
  comment '! '
8
8
 
9
9
  cmd :all do |cfg|
10
- cfg.each_line.to_a[2..-2].join
10
+ cfg.gsub! /\r\n?/, "\n"
11
+ cfg.cut_both
11
12
  end
12
13
 
13
14
  cmd :secret do |cfg|
@@ -16,6 +17,11 @@ class IOSXR < Oxidized::Model
16
17
  cfg
17
18
  end
18
19
 
20
+ cmd 'show version' do |cfg|
21
+ cfg.gsub! /^System\suptime.*\n?/, ''
22
+ comment cfg
23
+ end
24
+
19
25
  cmd 'show inventory all' do |cfg|
20
26
  comment cfg
21
27
  end
@@ -25,8 +31,8 @@ class IOSXR < Oxidized::Model
25
31
  end
26
32
 
27
33
  cmd 'show running-config' do |cfg|
28
- cfg = cfg.each_line.to_a[1..-1].join
29
- cfg
34
+ cfg.gsub! /^Building\sconfiguration\.{3}\n?/, ''
35
+ cfg.cut_head
30
36
  end
31
37
 
32
38
  cfg :telnet do
@@ -66,7 +66,7 @@ class IronWare < Oxidized::Model
66
66
 
67
67
  cmd 'show running-config' do |cfg|
68
68
  arr = cfg.each_line.to_a
69
- arr[2..-1].join unless arr.length < 2
69
+ arr[2..].join unless arr.length < 2
70
70
  end
71
71
 
72
72
  cfg :telnet do
@@ -0,0 +1,74 @@
1
+ class ITMGOS < Oxidized::Model
2
+ using Refinements
3
+
4
+ # Lantronix IT Management Gateway OS: SLC 8000, SLC 9000, EMG 8500/7500 and SLB.
5
+ # The configuration is the device's own CLI export, which it can restore with
6
+ # "admin config batch".
7
+
8
+ prompt /^(\[[\w.-]{1,64}\]>\s?)$/
9
+ comment '# '
10
+
11
+ # The export asks before printing secrets in cleartext; :secret below removes them.
12
+ expect /Do you want to continue\? \[no\] $/ do |data, re|
13
+ send "yes\n"
14
+ data.sub re, ''
15
+ end
16
+
17
+ cmd :all do |cfg|
18
+ cfg = cfg.gsub(/\r\n?/, "\n")
19
+ cfg.cut_both
20
+ end
21
+
22
+ # Prompted secrets are exported as the command, then the value and its confirmation on
23
+ # the next two lines: "set tacacs+ secret", "admin ftp password", "set site chapsecret
24
+ # <site>" and so on. Those two lines are hidden whatever they contain.
25
+ PROMPTED_SECRET = /^(?:set|admin) (?:.*(?:password|phrase|secret|key)|site (?:dialoutpassword|chapsecret) \S.*?)\s*$/
26
+
27
+ # Lines the export prints before the first command.
28
+ EXPORT_PREAMBLE = /^(?:\s*|The configuration will be output.*|yes|One moment while the file is generated.*)$/
29
+
30
+ cmd :secret do |cfg|
31
+ lines = cfg.lines
32
+ i = 0
33
+ while i < lines.length
34
+ if lines[i].match?(PROMPTED_SECRET)
35
+ lines[i + 1, 2] = lines[i + 1, 2].map { |line| line.end_with?("\n") ? "<secret hidden>\n" : '<secret hidden>' }
36
+ i += 3
37
+ else
38
+ i += 1
39
+ end
40
+ end
41
+ cfg = lines.join
42
+ # All three communities can share one line, quoted: rocommunity 'public' rwcommunity ...
43
+ cfg.gsub!(/\b((?:ro|rw|trap)community) (?:'[^'\n]*'|"[^"\n]*"|\S+)/, "\\1 '<secret hidden>'")
44
+ # Event actions that send traps carry their own community.
45
+ cfg.gsub!(/(\saction snmptrap\b[^\n]*?\scommunity) (?:'[^'\n]*'|"[^"\n]*"|\S+)/, '\1 <secret hidden>')
46
+ cfg.gsub!(/^(set localusers password \S+ enc) \S+/, '\1 <secret hidden>')
47
+ cfg
48
+ end
49
+
50
+ cmd 'admin version' do |cfg|
51
+ cfg = cfg.reject_lines [
52
+ /^Uptime:/,
53
+ /^Last (Boot|Restart Reason|Power Outage)/
54
+ ]
55
+ comment cfg + "\n"
56
+ end
57
+
58
+ cmd 'admin config commands copypaste' do |cfg|
59
+ # Only the preamble is dropped, so a secret whose value is "yes" stays in the export.
60
+ lines = cfg.lines
61
+ lines.shift while lines.any? && lines.first.match?(EXPORT_PREAMBLE)
62
+ lines.join
63
+ end
64
+
65
+ cfg :ssh, :telnet do
66
+ post_login 'set cli terminallines disable'
67
+ pre_logout 'logout'
68
+ end
69
+
70
+ cfg :telnet do
71
+ username /^login:\s*$/i
72
+ password /^password:\s*$/i
73
+ end
74
+ end
@@ -12,13 +12,17 @@ class JunOS < Oxidized::Model
12
12
  cfg = cfg.cut_both if screenscrape
13
13
  cfg.gsub!(/ scale-subscriber (\s+)(\d+)/, ' scale-subscriber <count>')
14
14
  cfg.gsub!(/VMX-BANDWIDTH\s+(\d+) (.*)/, 'VMX-BANDWIDTH <count> \2')
15
- cfg.lines.map { |line| line.rstrip }.join("\n") + "\n"
15
+ cfg.rstrip_lines
16
16
  end
17
17
 
18
18
  cmd :secret do |cfg|
19
19
  cfg.gsub!(/community (\S+) {/, 'community <hidden> {')
20
20
  cfg.gsub!(/(ssh-(rsa|dsa|ecdsa|ecdsa-sk|ed25519|ed25519-sk) )".*; ## SECRET-DATA/, '<secret removed>')
21
21
  cfg.gsub!(/ "\$\d\$\S+; ## SECRET-DATA/, ' <secret removed>;')
22
+ # archive-site URLs may carry a cleartext password (user:pass@host) that
23
+ # Junos does not tag with "## SECRET-DATA", e.g. under
24
+ # system archival configuration archive-sites
25
+ cfg.gsub!(/((?:ftp|pasvftp|sftp|scp|https?):\/\/[^\/@":]+):[^@"]+@/, '\1:<secret removed>@')
22
26
  cfg
23
27
  end
24
28
 
@@ -33,7 +37,9 @@ class JunOS < Oxidized::Model
33
37
  when 'mx960'
34
38
  out << cmd('show chassis fabric reachability') { |cfg| comment cfg }
35
39
  when /^(ex22|ex3[34]|ex4|ex8|qfx)/
36
- out << cmd('show virtual-chassis') { |cfg| comment cfg }
40
+ out << cmd('show virtual-chassis') do |cfg|
41
+ cfg.include?("error:") ? String.new : comment(cfg)
42
+ end
37
43
  when /^srx/
38
44
  out << cmd('show chassis cluster status') do |cfg|
39
45
  cfg.lines.count <= 1 && cfg.include?("error:") ? String.new : comment(cfg)