Repository navigation
Expand file tree
/
Copy pathlinuxgeneric.rb
More file actions
78 lines (60 loc) · 1.63 KB
/
Copy pathlinuxgeneric.rb
File metadata and controls
78 lines (60 loc) · 1.63 KB
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
class LinuxGeneric < Oxidized::Model
using Refinements
prompt /^\S.*[#$] $/
comment '# '
clean :escape_codes
# add a comment in the final conf
def add_comment(comment)
"\n###### #{comment} ######\n"
end
cmd :all do |cfg|
cfg.gsub! /^(default (\S+).* (expires) ).*/, '\\1 <redacted>'
cfg.cut_both
end
# show the persistent configuration
pre do
cfg = add_comment 'THE HOSTNAME'
cfg += cmd 'cat /etc/hostname'
cfg += add_comment 'THE HOSTS'
cfg += cmd 'cat /etc/hosts'
cfg += add_comment 'THE INTERFACES'
cfg += cmd 'ip link'
cfg += add_comment 'RESOLV.CONF'
cfg += cmd 'cat /etc/resolv.conf'
cfg += add_comment 'IP Routes'
cfg += cmd 'ip route'
cfg += add_comment 'IPv6 Routes'
cfg += cmd 'ip -6 route'
cfg += add_comment 'MOTD'
cfg += cmd 'cat /etc/motd'
cfg += add_comment 'PASSWD'
cfg += cmd 'cat /etc/passwd'
cfg += add_comment 'GROUP'
cfg += cmd 'cat /etc/group'
cfg += add_comment 'nsswitch.conf'
cfg += cmd 'cat /etc/nsswitch.conf'
cfg += add_comment 'VERSION'
cfg += cmd 'cat /etc/issue'
cfg
end
cfg :telnet do
username /(Username|[Ll]ogin):/
password /^Password:/
end
cfg :telnet, :ssh do
post_login do
if vars(:enable) == true
cmd "sudo su -", /^\[sudo\] password/
cmd @node.auth[:password]
elsif vars(:enable)
# This will only work without localisation (de: "Passwort:", fr: "Mot de passe :"...)
cmd "su -", /^Password:/
cmd vars(:enable)
end
end
pre_logout do
cmd "exit" if vars(:enable)
end
pre_logout 'exit'
end
end