Skip to content

Commit a45e38a

Browse files
committed
Added script upload from local machine functionality and a clear button to change the input values
1 parent 226e179 commit a45e38a

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
**/.idea/
44
**/build
55
**/dist
6+
main.spec

main.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
Language : Python
44
File Name : main.py
55
Date Created : 28-12-2019
6-
Last Modified : 28-12-2019
6+
Last Modified : 31-12-2019
77
"""
88

99
from tkinter import Entry, Label, StringVar, Tk, Listbox, Scrollbar, Button, END
10-
from paramiko import SSHClient, AutoAddPolicy
10+
from paramiko import SSHClient, AutoAddPolicy, sftp
11+
from tkinter.filedialog import askopenfile
12+
from os.path import basename
13+
14+
local_script_path = None
1115

1216

1317
def view_command():
@@ -19,17 +23,43 @@ def view_command():
1923

2024
# SSHClient.exec_command() returns the tuple (stdin,stdout,stderr)
2125
try:
22-
stdout = client.exec_command(script_path_text.get())[1]
23-
for line in stdout:
24-
# Process each line in the remote output
25-
# print(line)
26-
server_response.insert(END, line)
26+
global local_script_path
27+
28+
# Setup sftp connection and transmit this script
29+
sftp = client.open_sftp()
30+
sftp.put(local_script_path.name, f'/tmp/{basename(local_script_path.name)}')
31+
sftp.close()
32+
path_to_script_on_server = '/tmp/' + basename(local_script_path.name)
33+
try:
34+
stdout = client.exec_command('chmod +x ' + path_to_script_on_server)
35+
stdout = client.exec_command(path_to_script_on_server)[1]
36+
for line in stdout:
37+
# Process each line in the remote output
38+
# print(line)
39+
server_response.insert(END, line)
40+
except:
41+
print('Error executing the script')
2742
except:
2843
print('Execution failed')
2944
client.close()
3045
server_response.insert(END)
3146

3247

48+
def file_picker():
49+
global local_script_path
50+
local_script_path = askopenfile()
51+
script_path_entry.delete(0, END)
52+
script_path_entry.insert(END, local_script_path.name)
53+
# print(local_script_path.name)
54+
55+
56+
def clear():
57+
host_entry.delete(0, END)
58+
script_path_entry.delete(0, END)
59+
uname_entry.delete(0, END)
60+
password_entry.delete(0, END)
61+
server_response.delete(0, END)
62+
3363
window = Tk()
3464
window.title("Server Script Executer")
3565

@@ -47,6 +77,9 @@ def view_command():
4777
script_path_entry = Entry(window, textvariable=script_path_text)
4878
script_path_entry.grid(row=0, column=4)
4979

80+
file_picker = Button(window, text="Select", width=5, command=file_picker)
81+
file_picker.grid(row=0, column=6)
82+
5083
uname_label = Label(window, text="Username")
5184
uname_label.grid(row=1, column=0)
5285

@@ -59,6 +92,7 @@ def view_command():
5992

6093
password_text = StringVar()
6194
password_entry = Entry(window, textvariable=password_text)
95+
password_entry.config(show='*')
6296
password_entry.grid(row=1, column=4)
6397

6498
server_response = Listbox(window, height=10, width=40)
@@ -73,6 +107,9 @@ def view_command():
73107
# server_response.bind('<<ListboxSelect>>', get_selected_row)
74108

75109
execute_button = Button(window, text="Execute", width=12, command=view_command)
76-
execute_button.grid(row=3, column=4)
110+
execute_button.grid(row=4, column=4)
111+
112+
clear_button = Button(window, text="Clear", width=5, command=clear)
113+
clear_button.grid(row=5, column=4)
77114

78115
window.mainloop()

main.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ exe = EXE(pyz,
3030
upx=True,
3131
upx_exclude=[],
3232
runtime_tmpdir=None,
33-
console=True )
33+
console=False )

0 commit comments

Comments
 (0)