-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.py
61 lines (48 loc) · 1.21 KB
/
api.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
########
# Nick Bild
# nick.bild@gmail.com
#
# This is a REST API server that will simulate keystrokes on the host machine
# when API endpoints are requested. It allows a remote machine to effectively
# press buttons on the server's keyboard and control any arbitrary application.
# Yes, that is a security risk. A big huge one. This should only be used
# on a firewalled machine by those that understand the risks.
#
# Required libraries:
# flask
# flask-restful
# autopy
#
# Developed on Python 3.7.0.
#
# Starting the server:
# python3 api.py
#
# Accessing an endpoint:
# curl http://[SERVER_IP]:5000/[ENDPOINT_NAME]
########
from flask import Flask
from flask_restful import Resource, Api
import autopy
import time
key_hold_time_sec = 0.1
app = Flask(__name__)
api = Api(app)
###
# Define endpoint actions.
###
class VideoMute(Resource):
def get(self):
autopy.key.toggle(autopy.key.Code.SPACE, True, [], 0)
time.sleep(key_hold_time_sec)
autopy.key.toggle(autopy.key.Code.SPACE, False, [], 0)
return None
###
# Attach endpoints.
###
api.add_resource(VideoMute, '/video_mute_toggle')
###
# Start server.
###
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')