-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraSSHopper.rb
97 lines (89 loc) · 3.25 KB
/
graSSHopper.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
$brain = "empty"
heart = File.read('/usr/share/grasshopper/commands.cfg')
def think()
$brain = File.readlines('/usr/share/grasshopper/servers.cfg').map do |line|
k, *v = line.split(',').map(&:strip)
[k, v]
end.to_h
end
def sshsetup(servers)
system("rm /usr/share/grasshopper/servers.meta")
system("ssh-keygen")
print("Generate new servers.cfg [y] or use current one [n]? ")
choice = gets.chomp
if choice == "y"
creating = true
while creating == true
print ("Server name / IP?: ")
sshserver = gets.chomp
print ("Your username?: ")
username = gets.chomp
print ("Port for #{sshserver}?: ")
port = gets.chomp
open('/usr/share/grasshopper/servers.meta', 'a') do |f|
f.puts ("#{sshserver}, #{username}, #{port}")
system("ssh-copy-id -p #{port} #{username}@#{sshserver}")
end
puts("Add another server? [n/y]: ")
addanother = gets.chomp
if addanother != "y"
creating = false
end
end
else
servers.each do |server, settings|
user = settings[0]
port = settings[1]
system("ssh-copy-id -p #{port} #{user}@#{server}")
end
end
if choice == "y"
puts "Generate new config with this session's servers? Previous config will be overwritten."
answer = gets.chomp
if answer == "y"
system("cp -f /usr/share/grasshopper/servers.meta /usr/share/grasshopper/servers.cfg")
end
end
puts "Keygen process completed."
sleep(2)
end
puts `clear`
puts <<-'EOF'
┌─┐┬─┐┌─┐╔═╗╔═╗╦ ╦┌─┐┌─┐┌─┐┌─┐┬─┐
│ ┬├┬┘├─┤╚═╗╚═╗╠═╣│ │├─┘├─┘├┤ ├┬┘
└─┘┴└─┴ ┴╚═╝╚═╝╩ ╩└─┘┴ ┴ └─┘┴└─
|----------------------------------|
** MAKE SURE TO SETUP commands.cfg**
** and servers.cfg BEFORE PROCEED **
** ING, FOR YOUR OWN SAFETY <3 **
|----------------------------------|
EOF
sleep(2)
print("Do you need to run the ssh-keygen setup? Requires you to have correctly configured your servers.cfg file. [y/n]: ")
sshsetup = gets.chomp
if sshsetup == 'y'
think()
sshsetup($brain)
elsif
puts "Continuing without ssh key generation."
end
puts `date >> /usr/share/grasshopper/checker.txt`
puts `echo "---------------------" >> /usr/share/grasshopper/checker.txt`
puts `echo "Command: #{heart}" >> /usr/share/grasshopper/checker.txt`
puts `echo "---------------------" >> /usr/share/grasshopper/checker.txt`
think()
puts `clear`
puts "Command:"
print "--------:"
what = gets.chomp
$brain.each do |server, settings|
puts "Nuking #{server}"
puts `echo "#{server}" >> /usr/share/grasshopper/checker.txt`
user = settings[0]
port = settings[1]
system("ssh -t -p #{port} #{user}@#{server} '( #{what} )' | tee -a /usr/share/grasshopper/checker.txt ")
puts `echo "______" >> /usr/share/grasshopper/checker.txt`
puts `clear`
end
puts `echo "~-~-~-~-~-~END OF THIS CHECKING SESSION~-~-~-~-~-~" >> /usr/share/grasshopper/checker.txt`
system("cat /usr/share/grasshopper/checker.txt")