-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSSH_win.py
More file actions
executable file
·187 lines (152 loc) · 6.29 KB
/
Copy pathquickSSH_win.py
File metadata and controls
executable file
·187 lines (152 loc) · 6.29 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
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
import os, sys, paramiko
import tkinter.messagebox
from scp import SCPClient
from tkinter import *
from PIL import ImageTk, Image
__author__ = "The One & Only Javi"
__version__ = "1.0.0"
__start_date__ = "June 2019"
__end_date__ = ""
__maintainer__ = "me"
__email__ = "little_kh@hotmail.com.com"
__requirements__ = "tkinter, Pillow, SSH access"
__status__ = "Testing on different OS"
__description__ = "This script creates a software that launches SSH commands"
#Notice there are random examples to launch scripts inside the servers
window = Tk()
window.title('SSH Remote Support Software 1.0 BETA Windows Version')
window.geometry("1000x320")
# Insert here the credentials, WATCH OUT!
port = 22
username = 'root'
password = ''
# main function to bypass SSH orders
def print_output(order):
global ssh
t2.delete("1.0", END) # we erase the buffer_file after each call
try:
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect(e1_value.get() + '.yourdomain.com', port, username, password)
stdin, stdout, stderr = ssh.exec_command(order)
stdoutstring = stdout.readlines()
t2.insert(END, stdoutstring)
finally:
ssh.close()
def execute_not_print(order):
global ssh
t2.delete("1.0", END) # we erase the buffer_file after each call
try:
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(e1_value.get() + '.yourdomain.com', port, username, password)
stdin, stdout, stderr = ssh.exec_command(order)
finally:
ssh.close()
def download():
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(e1_value.get() + '.yourdomain.com', port, username, password)
# SCPCLient takes a paramiko transport as an argument
scp = SCPClient(ssh.get_transport())
# we read the outputs, as we can't download more than 1 file with this 'hack'
stdin, stdout, stderr = ssh.exec_command('ls /var/tmp/test-*.mp4')
file_list = stdout.read().split()
for listed_file in file_list:
scp.get(listed_file)
scp.close()
def list_num_pend_upload():
order = 'ls /home/user/record | wc -l'
print_output(order)
def list_pend_upload():
order = 'ls /home/user/record'
print_output(order)
def list_rec_channels():
order = 'bash /usr/lib/check_mk_agent/plugins/rec_channels'
print_output(order)
def dvbrecd_restart():
order = 'service dvbrecd restart'
execute_not_print(order)
def streams_restart():
order = 'bash /home/user/restartStoppedStreams.sh'
print_output(order)
def analogtvd_restart():
order = 'service analogtvd restart'
execute_not_print(order)
data = "Done! Please check again in 5 minutes"
t2.insert(END, data)
def analogtvd_testrecord():
t2.delete("1.0", END)
order = 'bash /home/user/newconfig/check_channels.sh'
tkinter.messagebox.showinfo(message="Please check after 5 minutes", title="Command launched")
execute_not_print(order)
download()
data = "Done!"
t2.insert(END, data)
def dvbrecd_testrecord():
t2.delete("1.0", END)
tkinter.messagebox.showinfo(message="Warning! Don't close the program while it does the operation"
"\nPlease wait until a new window appears",
title="Command launched")
order = 'bash /home/user/newconfig/check_dvb_channels.sh'
print_output(order)
download()
tkinter.messagebox.showinfo(message="Done! Please check files in same folder", title="Command launched")
data = "Done!"
t2.insert(END, data)
def reboot_server():
t2.delete("1.0", END)
# we ask a question to proceed
result = tkinter.messagebox.askquestion("Rebooting sever",
"Are You Sure?\n\nYou can lose access to the server\n\nPlease proceed "
"only if necessary",
icon='warning')
if result == 'yes':
order = 'shutdown -rf now && exit'
print_output(order)
data = "Setup rebooted"
t2.insert(END, data)
else:
t2.delete("1.0", END)
data = "Setup not rebooted"
t2.insert(END, data)
# Frontend buttons, each calls operation
b1 = Button(window, text="List number of files pending to upload (rec folder)", bg='IndianRed2', fg='snow',
command=list_num_pend_upload)
b1.grid(row=1, column=0)
b2 = Button(window, text="List files pending to upload (rec folder)", bg='IndianRed2', fg='snow',
command=list_pend_upload)
b2.grid(row=2, column=0)
b3 = Button(window, text="List channels being recorded", bg='IndianRed2', fg='snow', command=list_rec_channels)
b3.grid(row=3, column=0)
b4 = Button(window, text="Restart Digital TV & IPTV recording", bg='IndianRed2', fg='snow', command=dvbrecd_restart)
b4.grid(row=4, column=0)
b5 = Button(window, text="Restart streams recording", bg='IndianRed2', fg='snow', command=streams_restart)
b5.grid(row=5, column=0)
b6 = Button(window, text="Restart Analog TV recording", bg='IndianRed2', fg='snow', command=analogtvd_restart)
b6.grid(row=6, column=0)
b7 = Button(window, text="Record 10 seconds Analog TV", bg='IndianRed2', fg='snow', command=analogtvd_testrecord)
b7.grid(row=7, column=0)
b8 = Button(window, text="Record 10 seconds Digital TV & IPTV module", bg='IndianRed2', fg='snow',
command=dvbrecd_testrecord)
b8.grid(row=8, column=0)
b9 = Button(window, text="Reboot server", bg='IndianRed2', fg='snow', command=reboot_server)
b9.grid(row=9, column=0)
# IMPORTANT: entry of text by user
e1_value = StringVar()
e1 = Entry(window, textvariable=e1_value)
e1.grid(row=0, column=1)
l1 = Label(window, text="Please insert the server name here ->")
l1.grid(row=0, column=0)
# Outputs of the operations!
t2 = Text(window, height=1, width=100)
t2.grid(row=1, column=1, rowspan=20, columnspan=8, sticky=W + E + N + S, padx=5, pady=5)
# Company Logo
logo_path = 'company_logo.jpg'
img = ImageTk.PhotoImage(Image.open("company_logo.jpg"))
# imglabel = Label(window, image=img).grid(row=0, column=3, rowspan=5, sticky=W+E+N+S, padx=5, pady=5)
imglabel = Label(window, image=img).grid(row=0, column=3, sticky=E + N, rowspan=10)
# C.pack()
window.mainloop()