vnctv/vnctv-web

97 lines
2.0 KiB
Plaintext
Raw Normal View History

2022-04-06 00:49:19 +02:00
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs
import re
from time import sleep
import socket
hostName = "0.0.0.0"
serverPort = 8080
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
parsed_path = urlparse(self.path)
param=parse_qs(parsed_path.query)
host=str(self.client_address[0])
if "host" in param:
p = re.compile("[a-zA-Z0-9_.-]*")
print(param["host"][0])
if p.match(param["host"][0])[0] == param["host"][0]:
host=param["host"][0]
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1",4444))
s.send(bytes(host,"UTF-8"))
s.close()
except:
pass
else:
host="invalide"
self.wfile.write(bytes("""
<html>
<head>
<title>vnctv</title>
<style>
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
label {
font-weight:bold;
margin-right:10px;
}
.table {
display:table;
text-align:center;
width:100%;
height:100%;
table-layout:fixed;
}
.cell {
display:table-cell;
vertical-align:middle;
}
form {
display:inline-block;
border:8px solid black;
width: 450px;
padding:50px 0;
}
input {
margin-bottom:15px;
}
</style>
</head>
<body>
<div class='table'>
<div class='cell'>
<form id="launch">
<label>Host:</label>
<input type="text" name="host" size="20" maxlength="30" value='""" + host + """' />
<input type="submit" value="Submit" />
<input type="reset" value="Cancel"/>
</form>
<ul>
<li>thomas-XPS15.net.lgy.fr</li>
</ul>
</div>
</div>
</body></html>
""", "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")