Repository navigation
Expand file tree
/
Copy pathslave.py
More file actions
75 lines (60 loc) · 1.66 KB
/
Copy pathslave.py
File metadata and controls
75 lines (60 loc) · 1.66 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
import bin.com as com
import bin.functs as exts
import bin.shell as shell
import bin.httpServer as httphost
ip = com.IP
print(f"ip: {ip}")
s = com.server(ip=ip, port=2233, nclients=1)
s.start()
@exts.critical
def send(client, msg):
s.send(client, f"{msg}\n{shell.os.getcwd()}")
@exts.critical
def recv(client, dsize=1024):
result = s.recv(client, dsize)
return result
def main():
global client, send, recv, is_terminated
while True:
cmd = recv(client)
if cmd == "exit":
is_terminated = True
send(client, "exit [0]")
break
elif cmd[0] == "#":
try:
port = int(cmd[1:])
httphost.server(path="./", port=port).start()
send(client, f"access [{shell.os.getcwd()}] at http://{ip}:{port}")
except Exception as e:
send(client, f"Error: {e}")
else:
result = shell.run_command(cmd)
r = send(client, result)
if r not in [None, ""]:
print(r)
is_terminated = False
try:
while s.clients == []:
pass
client = s.clients[0][0]
send(client, "")
print("connection established")
while not is_terminated:
try:
main()
except Exception as e:
print("Error:", e)
try:
s.send(client, f"Runtime Error: {e}")
except BrokenPipeError:
is_terminated = True
except KeyboardInterrupt:
r = send(client, "exit [1]")
if r not in [None, ""]:
print(r)
finally:
s.close(client)
s.end()
print("connection terminated")
shell.os.system("clear")