-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrc3cmd.py
94 lines (71 loc) · 3.05 KB
/
rc3cmd.py
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
#!/usr/bin/python3
import ssh
from term import bcolors
import os
import time
import translate as t
"""
This Python module executes a given command on all machines.
"""
def cmd(password):
print(t.translate("longrun"))
command = input(t.translate("inputcomm"))
cmdrun(command, password)
def cmdrun(command, password):
for host in ssh.gethostnames():
print(t.translate("executing").format(command, host), end="")
try:
output = ssh.run(host, 22, "rc3-admin", password, ssh.suwrap(password, command))
print(bcolors.OKGREEN + "OK" + bcolors.ENDC)
print("Output: {}".format(output[31:]))
except:
print(bcolors.FAIL + t.translate("off") + bcolors.ENDC)
print(t.translate("finished"))
def vnc(password):
host = "rc3-" + input(t.translate("vnchost")).replace("rc3-", "")
print(t.translate("loggedin"))
who = ssh.run(host, 22, "rc3-admin", password, ssh.suwrap(password, "'who | grep -v rc3-admin'"))[33:]
if len(who.split("\n")) > 1:
print(who)
user = input(t.translate("vncuser"))
tty = ":0"
for str in who.split("\n"):
if user in str:
tty = str.split()[4].strip().replace("(", "").replace(")", "")
break
else:
user = who.split()[0].strip()
tty = who.split()[4].strip().replace("(", "").replace(")", "")
vncconnect(tty, user, host, password)
print(t.translate("finished"))
def vncone(password):
vncall(password, [ input(t.translate("vnchost")) ], True)
def vncall(password, hosts, skipRemmina):
user = input(t.translate("vncuser"))
for host in hosts:
print("VNC start: '{}:5566'... ".format(host), end="")
try:
who = ssh.run(host, 22, "rc3-admin", password, ssh.suwrap(password, "'who | grep -v rc3-admin'"))[33:]
tty = ":0"
for str in who.split("\n"):
if user in str:
tty = str.split()[4].strip().replace("(", "").replace(")", "")
break
vncstart(tty, user, host, password)
print(bcolors.OKGREEN + "OK" + bcolors.ENDC)
except:
print(bcolors.FAIL + t.translate("off") + bcolors.ENDC)
if not skipRemmina:
print("rc3-admin login:")
print(t.translate("loginpromptremind"))
os.system("su - rc3-admin -c 'remmina'")
def vncstart(tty, user, host, password):
command = 'nohup x11vnc -noxdamage -display {} -rfbport 5566 -auth /run/user/`id -u {}`/gdm/Xauthority &'.format(tty, user)
_ = ssh.run(host, 22, "rc3-admin", password, ssh.suwrap(password, command))
def vncconnect(tty, user, host, password):
command = 'nohup x11vnc -noxdamage -display {} -rfbport 5566 -auth /run/user/`id -u {}`/gdm/Xauthority &'.format(tty, user)
_ = ssh.run(host, 22, "rc3-admin", password, ssh.suwrap(password, command))
time.sleep(1)
os.system("nohup vncviewer -ViewOnly {}:5566 >/dev/null 2>&1 &".format(host))
if __name__ == "__main__":
cmd(ssh.getpassword())