This repository was archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost2ws.py
More file actions
92 lines (83 loc) · 3.15 KB
/
Copy pathpost2ws.py
File metadata and controls
92 lines (83 loc) · 3.15 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
from twisted.web import server, resource
from twisted.internet import reactor, endpoints
from websocket import create_connection
import ssl
import urlparse
import argparse
VERSION= "v0.3"
port = "443"
parser = argparse.ArgumentParser(description="Relay a websocket message")
parser.add_argument("-p", "--port", default="443",
help="443")
parser.add_argument("-l", "--password", required="true",
help="Relay Password")
args = vars(parser.parse_args())
print("LibreConnect WebSocket to HTTP Proxy - " + VERSION)
print("By madnerd.org (https://github.com/madnerdorg/post2ws)")
def sendWebSocket(url,password,message):
"""
Send a message to a websocket
"""
try:
ws = create_connection(url, sslopt={"cert_reqs": ssl.CERT_NONE})
if password:
ws.recv() # @password
ws.send(password)
ws.recv() # @logged
ws.send(message)
returnMessage = ws.recv();
ws.close()
print(returnMessage)
return returnMessage
except Exception as e:
return e
class WebSocketRelay(resource.Resource):
"""
Relay websocket message from HTTP POST request
"""
isLeaf = True
def render_POST(self, request):
"""
Get Post Request
"""
if "url" in request.args and \
"message" in request.args and \
"relayPassword" in request.args and \
"password" not in request.args:
url = request.args["url"][0]
message = request.args["message"][0]
relayPassword = request.args["relayPassword"][0]
if relayPassword == args["password"]:
# return "ok"
sendWebSocket(url,False,message)
return "ok"
else:
return "Invalid Password for relay"
elif "url" in request.args and \
"message" in request.args and \
"relayPassword" not in request.args and \
"password" in request.args:
url = request.args["url"][0]
message = request.args["message"][0]
password = request.args["password"][0]
relayPassword = password
if relayPassword == args["password"]:
return sendWebSocket(url,password,message)
else:
return "Invalid Password for relay"
elif "url" in request.args and \
"message" in request.args and \
"relayPassword" in request.args and \
"password" in request.args:
url = request.args["url"][0]
message = request.args["message"][0]
password = request.args["password"][0]
relayPassword = request.args["relayPassword"][0]
if relayPassword == args["password"]:
return sendWebSocket(url,password,message)
else:
return "Invalid Password for relay"
else:
return "Invalid request (need url/message/password and or relayPassword)"
endpoints.serverFromString(reactor, b"ssl:"+args["port"]+":privateKey=keys/privkey.pem:certKey=keys/cert.pem").listen(server.Site(WebSocketRelay()))
reactor.run()