This repository has been archived by the owner on May 5, 2020. It is now read-only.
forked from miken32/rancid-aruba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharuba.pm
520 lines (438 loc) · 14.9 KB
/
aruba.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
package aruba;
##
## rancid 3.1
## Copyright (c) 1997-2014 by Terrapin Communications, Inc.
## All rights reserved.
##
## This code is derived from software contributed to and maintained by
## Terrapin Communications, Inc. by Henry Kilmer, John Heasley, Andrew Partan,
## Pete Whiting, Austin Schutz, and Andrew Fort.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## are met:
## 1. Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## 2. Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
## 3. All advertising materials mentioning features or use of this software
## must display the following acknowledgement:
## This product includes software developed by Terrapin Communications,
## Inc. and its contributors for RANCID.
## 4. Neither the name of Terrapin Communications, Inc. nor the names of its
## contributors may be used to endorse or promote products derived from
## this software without specific prior written permission.
## 5. It is requested that non-binding fixes and modifications be contributed
## back to Terrapin Communications, Inc.
##
## THIS SOFTWARE IS PROVIDED BY Terrapin Communications, INC. AND CONTRIBUTORS
## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COMPANY OR CONTRIBUTORS
## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
## POSSIBILITY OF SUCH DAMAGE.
#
# RANCID - Really Awesome New Cisco confIg Differ
#
# aruba.pm - ArubaOS rancid procedures
use 5.005;
use strict 'vars';
use warnings;
no warnings 'uninitialized';
require(Exporter);
our @ISA = qw(Exporter);
use rancid;
@ISA = qw(Exporter rancid main);
# load-time initialization
sub import {
0;
}
# post-open(collection file) initialization
sub init {
# add content lines and separators
ProcessHistory("","","","!RANCID-CONTENT-TYPE: $devtype\n!\n");
ProcessHistory("COMMENTS","keysort","A0","!\n");
ProcessHistory("COMMENTS","keysort","B0","!\n");
ProcessHistory("COMMENTS","keysort","C0","!\n");
ProcessHistory("COMMENTS","keysort","D0","!\n");
ProcessHistory("COMMENTS","keysort","E0","!\n");
ProcessHistory("COMMENTS","keysort","F0","!\n");
ProcessHistory("COMMENTS","keysort","G0","!\n");
ProcessHistory("COMMENTS","keysort","H0","!\n");
ProcessHistory("COMMENTS","keysort","I0","!\n");
0;
}
# main loop of input of device output
sub inloop {
my($INPUT, $OUTPUT) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
my($cmd, $rval);
TOP: while(<$INPUT>) {
tr/\015//d;
if (/[>#]\s?exit/) {
$clean_run = 1;
last;
}
if (/^Error:/) {
print STDOUT ("$host clogin error: $_");
print STDERR ("$host clogin error: $_") if ($debug);
$clean_run = 0;
last;
}
while (/[>#]\s*($cmds_regexp)\s*$/) {
$cmd = $1;
if (!defined($prompt)) {
$prompt = ($_ =~ /^([^#>]+[#>])/)[0];
$prompt =~ s/([][}{)(\\])/\\$1/g;
print STDERR ("PROMPT MATCH: $prompt\n") if ($debug);
}
print STDERR ("HIT COMMAND:$_") if ($debug);
if (! defined($commands{$cmd})) {
print STDERR "$host: found unexpected command - \"$cmd\"\n";
$clean_run = 0;
last TOP;
}
$rval = &{$commands{$cmd}}($INPUT, $OUTPUT, $cmd);
delete($commands{$cmd});
if ($rval == -1) {
$clean_run = 0;
last TOP;
}
}
}
}
# This routine parses "show version"
sub ShowVersion {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
/^ArubaOS \(MODEL: ([A-Za-z0-9_-]*)\), .*Version\s+(.*)$/ &&
ProcessHistory("COMMENTS","keysort","A1","!Model: $1\n") &&
ProcessHistory("COMMENTS","keysort","D1","!Image: Software: $2\n") && next;
/^Compiled (.*)$/ &&
ProcessHistory("COMMENTS","keysort","D2","!Image: Compiled: $1\n") && next;
/^ROM: (System )?Bootstrap.*(Version.*)$/ &&
ProcessHistory("COMMENTS","keysort","C1","!ROM Bootstrap: $2\n") && next;
/^Processor (.+) with (\d+) bytes/ &&
ProcessHistory("COMMENTS","keysort","A2","!CPU: $1\n") &&
ProcessHistory("COMMENTS","keysort","B1","!Memory: $2 bytes\n") && next;
/^(\d+[gmk]) bytes of (.* flash)/i &&
ProcessHistory("COMMENTS","keysort","B2", "!Memory: $2 $1 bytes\n") && next;
}
return(0);
}
# This routine parses "show master-redundancy"
sub ShowMasterRedundancy {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
/^Master switch redundancy is not configured$/ &&
ProcessHistory("COMMENTS","keysort","E1","!Redundancy: Not configured\n") && return(0);
/^\s+?VRRP Id (\d+) current state is (.*)$/ &&
ProcessHistory("COMMENTS","keysort","E1","!Redundancy: Role is $2\n") &&
ProcessHistory("COMMENTS","keysort","E2","!Redundancy: VRRP ID $1\n") && next;
/^\s+?Peer's IP Address is (.+)$/ &&
ProcessHistory("COMMENTS","keysort","E4","!Redundancy: Peer IP $1\n") && next;
/^\s+?Peer's IPSEC Key is (.+)$/ &&
$filter_pwds >= 1 &&
ProcessHistory("COMMENTS","keysort","E3","!Redundancy: IPSEC key $1\n") && next;
}
return(0);
}
# This routine parses "show interface transceivers"
sub ShowInterfaceTransceivers {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
my($int, $mfg, $sn, $pn, $typ);
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
next if (/^-+$/);
next if (/^Transceiver information not present$/);
/^([A-Z0-9\/]+)$/ &&
($int && ProcessHistory("COMMENTS","keysort","F1","!Transceiver: $int: $mfg $pn (serial $sn) $typ\n")) &&
($int = $1) && next;
/^Vendor Name\s+:\s+(.*)$/ &&
($mfg = $1) && next;
/^Vendor Serial Number\s+:\s+(.*)$/ &&
($sn = $1) && next;
/^Vendor Part Number\s+:\s+(.*)$/ &&
($pn = $1) && next;
/^Cable Type\s+:\s+(.*)$/ &&
($typ = $1) && next;
/^Connector Type\s+:\s+(.*)$/ &&
($typ .= " $1") && next;
}
return(0);
}
# This routine parses "show boot"
sub ShowBoot {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
my ($file, $part) = "";
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
/^Config File: (.*)$/ &&
($file=$1) && next;
/^Boot Partition: PARTITION (\d+)$/ &&
($part=$1) && next;
}
ProcessHistory("COMMENTS","keysort","D3","!Boot: Partition$part:$file\n");
return(0);
}
# This routine parses "show image version"
sub ShowImageVersion {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
ProcessHistory("COMMENTS","keysort","D99","!$_");
}
return(0);
}
# This routine parses "dir"
sub Dir {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
/^[-d](?:[-r][-w][-x]){3}\s+\d+\s+\S+\s+\S+\s+(\d+)\s+[A-Za-z]{3}\s+\d+\s+[\d:]+\s+(.*)$/ &&
ProcessHistory("FLASH","","","!Flash: $2\n");
}
ProcessHistory("FLASH","","","!\n");
return(0);
}
# This routine parses "show inventory".
sub ShowInventory {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
/^SC Model(?: Name|#)\s+:\s+(.*)$/ &&
ProcessHistory("INVENTORY","keysort","A0", "!Inventory: Model: $1\n") && next;
/^((.*) (Serial|Assembly|Revision) ?#?)\s+:\s+(.*)$/ &&
ProcessHistory("INVENTORY","keysort","A0$2", "!Inventory: $1: $4\n") && next;
}
ProcessHistory("INVENTORY","","","!\n");
return(0);
}
# This routine parses "show packet-capture"
sub ShowPacketCapture {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
my $capture_type = "";
my $capture_found = 0;
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
next if (/^-+$/);
/^Active Capture Destination$/ &&
($capture_type = "") && next;
/^Active Capture (Controlpath)$/ &&
($capture_type = "Controlpath") && next;
/^Active Capture (Datapath)$/ &&
($capture_type = "Datapath") && next;
/^(.*)\s+Enabled\s+(.*)$/ &&
ProcessHistory("CAPTURE","","","!Capture: $capture_type $1: $2\n") && next;
$capture_found = 1
}
($capture_found) && ProcessHistory("CAPTURE","","","!\n");
return(0);
}
# This routine parses "show vlan"
sub ShowVLAN {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
my ($vlan, $vlan_name, $ports, $aaa_profile, $temp) = "";
my @vlan_ports;
my $has_aaa = 0;
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
/AAA Profile$/ && ($has_aaa = 1) && next;
/^VLAN/ && next;
/^-+/ && next;
if (/^(\d+)\s+(\S+)\s+(.*)$/) {
if ($vlan) {
$ports = join(", ", sort @vlan_ports);
ProcessHistory("COMMENTS","keysort","I$vlan","!VLAN $vlan ($vlan_name): $ports\n");
}
$vlan=$1;
$vlan_name=$2;
$temp = $3;
#trimming port list before split by spaces
$temp =~ s/^\s+|\s+$//g;
if ($has_aaa) {
($ports, $aaa_profile) = split(/\s{2,}/, $temp);
} else {
$ports = $temp;
}
@vlan_ports=split(/ /, $ports);
next;
}
if (/^\s+(.*)$/) {
$temp = $1;
$temp =~ s/^\s+|\s+$//g;
if ($has_aaa) {
($ports, $aaa_profile) = split(/\s{2,}/, $temp);
} else {
$ports = $temp;
}
#adding to existing array
@vlan_ports = (@vlan_ports, split(/ /, $ports));
next;
}
}
ProcessHistory("COMMENTS","","","!\n");
return(0);
}
# This routine processes a "write term"
sub WriteTerm {
my($INPUT, $OUTPUT, $cmd) = @_;
my $sub_name = (caller(0))[3];
print STDERR " In $sub_name: $_" if ($debug);
my($lineauto, $comment, $linecnt) = (0,0,0);
while (<$INPUT>) {
tr/\015//d;
last if (/^$prompt/);
return(1) if (/^\s*($cmd|\^)\s*$/);
return(1) if (/invalid input detected/i);
return(1) if (/do not have permission/i);
return(0) if ($found_end);
# skip emtpy lines at the beginning
if (!$linecnt && /^\s*$/) {
next;
}
$linecnt++;
$lineauto = 0 if (/^[^ ]/);
# skip the crap
if (/^(##+|(building|current) configuration)/i) {
while (<$INPUT>) {
next if (/^Current configuration\s*:/i);
next if (/^:/);
next if (/^([%!#].*|\s*)$/);
last;
}
tr/\015//d;
}
# skip consecutive comment lines to avoid oscillating extra comment
# line on some access servers. grrr.
if (/^!\s*$/) {
next if ($comment);
ProcessHistory("","","",$_);
$comment++;
next;
}
$comment = 0;
if ($filter_pwds >= 2) {
#removing any passwords
/^(enable secret )/ &&
ProcessHistory("ENABLE","","","!$1<removed>\n") && next;
/^mgmt-user (\S+) (\S+) (.*)$/ &&
ProcessHistory("USER","keysort","$1","!mgmt-user $1 $2 <removed>\n") && next;
#within redundancy-master settings
/^(\s+peer-ip-address \S+ ipsec )/ &&
ProcessHistory("","","","!$1<removed>\n") && next;
#within aaa-server details
/^(\s+key )[0-9a-f]{16,}/ &&
ProcessHistory("","","","!$1<removed>\n") && next;
}
if ($filter_pwds >= 1) {
#removing reversible passwords
/^(\s+wpa-passphrase )/ &&
ProcessHistory("","","","!$1<removed>\n") && next;
#not editable, but we'll treat it like a password
/^(\s+arm-rf-domain-key )/ &&
ProcessHistory("","","","!$1<removed>\n") && next;
#stored in plain text!
/^(ntp authentication-key \S+ md5 )/ &&
ProcessHistory("","","","!$1<removed>\n") && next;
#auth password only
/^(snmp-server user \S+ auth-prot \S+ )\S+$/ &&
ProcessHistory("","","","!$1<removed>\n") && next;
#priv password also
/^(snmp-server user \S+ auth-prot \S+ )\S+( priv-prot \S+ )\S+$/ &&
ProcessHistory("","","","!$1<removed>$2<removed>\n") && next;
/^(ap mesh-recovery-profile cluster \S+ wpa-hexkey )/ &&
ProcessHistory("","","","!$1<removed>\n") && next;
}
#removing no passwords but still treating differently
/^(enable secret )/ &&
ProcessHistory("ENABLE","","","$_") && next;
/^mgmt-user (\S+) (\S+) (.*)$/ &&
ProcessHistory("USER","keysort","$1","$_") && next;
# order and prune snmp-server host statements
if ($filter_commstr) {
/^(snmp-server community )/ &&
ProcessHistory("","","","$1 <removed>\n") && next;
/^(snmp-server host (\d+\.\d+\.\d+\.\d+) version [1-3]c? )\S+(.*)?$/ &&
ProcessHistory("SNMPSERVERHOST","ipsort","$2","!$1<removed>$2\n") && next;
} else {
/^snmp-server host (\d+\.\d+\.\d+\.\d+)/ &&
ProcessHistory("SNMPSERVERHOST","ipsort","$1","$_") && next;
}
# order ntp servers
/^ntp server (\d+\.\d+\.\d+\.\d+)/ &&
ProcessHistory("NTP","ipsort",$1,"$_") && next;
# catch anything that wasnt matched above.
ProcessHistory("","","","$_");
# end of config.
if (/^end$/) {
$found_end = 1;
return(0);
}
}
return(0);
}
1;