forked from ytti/oxidized
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzynos.rb
76 lines (63 loc) · 2 KB
/
zynos.rb
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
class ZyNOS < Oxidized::Model
using Refinements
prompt /^([\w.@()-<]+[#>]\s?)$/
# if there is something you can not identify after prompt, uncomment next line and comment previous line
# prompt /^([\w.@()-<]+[#>]\s?).*$/
comment '! '
# Used in Zyxel DSLAMs, such as SAM1316. Uncomment next line to enable ftp.
# cmd 'config-0'
# replace next line control sequence with a new line
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
# ignore copyright motd
expect /^(Copyright .*)\n^([\w.@()-<]+[#>]\s?)$/ do
send '\n'
""
end
cmd :all do |cfg|
cfg = cfg.gsub /^\r/, ''
# Additional filtering for elder switches sending vt100 control chars via telnet
cfg.gsub! /\e\[\??\d+(;\d+)*[A-Za-z]/, ''
cfg
end
# remove snmp community, username, password and admin-password
cmd :secret do |cfg|
cfg.gsub! /^(snmp-server get-community) \S+(.*)/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(snmp-server set-community) \S+(.*)/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(logins username) \S+(.*) (password) \S+(.*)/, '\\1 <secret hidden> \\2 \\3 <secret hidden> \\4'
cfg.gsub! /^(admin-password) \S+(.*)/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(password) \S+(.*) (privilege \S+)/, '\\1 <secret hidden> \\2 \\3'
cfg
end
cmd 'show version' do |cfg|
comment cfg
end
cmd 'show system-information' do |cfg|
cfg.gsub! /^([Ss]ystem up [Tt]ime\s*:)(.*)/, '\\1 <time removed>'
comment cfg
end
cmd 'show running-config' do |cfg|
cfg = cfg.split("\n")[4..-2].join("\n")
cfg
end
cfg :telnet do
username /^User name:/i
password /^Password:/i
end
cfg :telnet, :ssh do
post_login do
if vars(:enable) == true
cmd "enable"
elsif vars(:enable)
cmd "enable", /^[pP]assword:/
cmd vars(:enable)
end
end
pre_logout 'exit'
end
end