-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart_linux
executable file
·256 lines (184 loc) · 5.43 KB
/
start_linux
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env python
from flask import Flask, request, jsonify, copy_current_request_context
from flask_socketio import SocketIO, send, emit
from tools.keysim import Sim
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
socketio = SocketIO(app)
webpage = open("Index_1.html", "r").read()
s = Sim()
import pyscreeze
import PIL
import os
import base64
from io import BytesIO
import time
from screenshot_optimization import _screenshot_linux_slim as screenshot
import Xlib.threaded
import clipboard
@app.route("/")
def index():
return webpage.encode()
@app.route("/shot")
def handle_screenshot():
print("[screenshot] stored")
screenshot()
return jsonify(msg= "received")
@app.route("/click", methods=["POST"])
def click():
data = (request.json)
posx = data["posx"]
posy = data["posy"]
s.m.click(posx, posy, 1)
return "received"
@app.route("/copy")
def copy():
s.k.press_key(s.k.control_key)
s.k.press_key("c")
s.k.release_key(s.k.control_key)
s.k.release_key("c")
return "copied to clipboard"
@app.route("/visit", methods=["POST"])
def visit():
link = (request.json)["link"]
clipboard.copy(link)
print(link)
s.k.press_key(s.k.control_key)
s.k.press_key("t")
s.k.release_key(s.k.control_key)
s.k.release_key("t")
copy()
s.k.press_key(s.k.control_key)
s.k.press_key("v")
s.k.release_key(s.k.control_key)
s.k.release_key("v")
time.sleep(0.1)
s.k.tap_key("Return")
return "visited"
@app.route("/del", methods=["POST"])
def del_bmark():
idx = int((request.json)["id"])
print(idx)
with open(os.path.join('static', "bookmarks.txt"), 'r') as fin:
data = fin.read().splitlines(True)
data.pop(idx)
print(data)
with open(os.path.join('static', "bookmarks.txt"), 'w') as fout:
fout.writelines(data)
return "success"
@app.route("/bmarks")
def bmarks():
with open(os.path.join("static", "bookmarks.txt"), "r") as myfile:
text = myfile.read()
marks = text.splitlines(True)
return jsonify(bookmarks= marks)
@app.route("/store")
def store():
print("[store] bmark")
bookmark = clipboard.paste()
with open(os.path.join("static", "bookmarks.txt"), "a") as myfile:
myfile.write("\n" + bookmark)
return "copied to clipboard"
@app.route("/scroll", methods=["POST"])
def scroll():
data = (request.json)
posx = data["horizontal"]
posy = data["vertical"]
print("------")
print(posx)
print(posy)
s.m.scroll(posy, posx)
return "received"
@app.route("/simulate", methods=["POST"])
def simulate():
data = (request.json)
val = data["key"]
print(val)
command = {
"left": s.pressLeft,
"right": s.pressRight,
"up": lambda: s.tap(s.k.up_key),
"down": lambda: s.tap(s.k.down_key),
}
selected = command.get(val, lambda: s.k.tap_key(val))
print(selected())
return "received"
@app.route("/text", methods=["POST"])
def type():
data = (request.json)
val = data["text"]
print(val)
print(s.k.type_string(val))
print(s.k.tap_key("Return"))
return "received"
#################################
intervals = dict()
@socketio.on('connect')
def handle_connect():
sid = request.sid
print(f'[socket][/connect] [{sid}]')
@socketio.on('message')
def handle_message(message):
print('received message: ' + message)
send ( "what", broadcast=True )
import threading
stream_timer = None
@socketio.on('stream')
def handle_stream(interval):
@copy_current_request_context
def stream_loop():
global stream_timer
global intervals
if len(intervals) == 0:
return
interval_time = min(intervals.values())/1000
if interval_time == 0:
return
import time
t1 = time.time()
shot = screenshot()
if shot == None:
return
buffered = BytesIO()
shot.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue())
emit ( "image", img_str)
t2 = time.time()
elapsed_ms = (t2-t1) * 1000
print(f"elapsed_ms {elapsed_ms}")
time_left = (min(intervals.values()) - elapsed_ms)
stream_timer = threading.Timer( (time_left if time_left >= 0 else 0)/1000, stream_loop)
stream_timer.start()
sid = request.sid
print(f'[socket][/stream] [{sid}] {str(interval)}')
global intervals
intervals[sid] = interval
if not isinstance (interval, int) or interval == 0:
del intervals[sid]
return "Stream OFF"
#stream_loop()
thread = socketio.start_background_task(target=stream_loop)
return "Stream ON"
#################################
def get_ip():
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0]
except:
IP = '127.0.0.1'
finally:
s.close()
return IP
if __name__ == "__main__":
import qrcode
port = 1337
path = "http://"+(get_ip() + ":" + str(port))+"/"
img = qrcode.make(path)
print(f"Remote on {path}")
img.show()
img.save(os.path.join("static", "qr.jpeg"), "JPEG")
#app.run(host= '0.0.0.0', port=port)
socketio.run(app, host= '0.0.0.0', port=port)