Adding internet option

This commit is contained in:
chabisik 2022-12-21 23:22:19 +01:00
parent 6473f1ea06
commit d5c7eef0ec
4 changed files with 75 additions and 6 deletions

15
fail.html Normal file
View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Fail</title>
</head>
<style>
.whole {max-width: 500px; margin: auto;}
</style>
<body>
<div class="whole">
<h1 style="color: red;">Something went wrong :(</h1>
<div><a href="javascript:history.back()"><h2>Go Back to main page</h2></a></div>
</div>
</body>
</html>

26
index.html Normal file
View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>DomoDoor Page</title>
</head>
<style>
.whole {max-width: 500px; margin: auto;}
</style>
<body>
<div class="whole">
<h1 style="color: green;">DomoD--r Project (internet option)</h1>
<h1>
<form action="/from_internet" method="post">
<div>
<label for="name">Enter Password :</label>
<input type="password" id="pwd" name="pwd_retriever" style="width: 5cm; height: 0.8cm;">
</div>
<div style="text-align: center;">------------------</div>
<div class="button" style="text-align:center;">
<button type="submit" style="width: 10cm; height: 2cm; background-color: green; border-radius: 8%; border: 2px solid red;"><h2> VALIDATE and GO ON</h2></button>
</div>
</form>
</h1>
</div>
</body>
</html>

View file

@ -8,7 +8,7 @@ import threading
import subprocess
import urllib.parse
app = flask.Flask(import_name=__name__)
app = flask.Flask(import_name=__name__, template_folder=".")
try:
sys.path.insert(0,'/home/pi/information')
@ -22,7 +22,7 @@ def opener(lck):
requests.get("http://192.168.0.103/open")
def localtunnel_launcher(port=8000, wanted_subdomain="open-domodoor"):
result = subprocess.run(args="lt --port {} --subdomain {}".format(port,wanted_subdomain))
result = subprocess.run(args="lt --port {} --subdomain {}".format(port,wanted_subdomain), shell=True, executable="/bin/bash")
print("Process returned:", result)
def remote_handler(lck):
@ -53,14 +53,27 @@ def remote_handler(lck):
print("Attempt "+str(n_attempts)+" fails in finding remote")
time.sleep(3)
#------ENDPOINTS------
@app.route(rule="/")
def index():
return flask.render_template("index.html")
@app.route(rule="/state")
def state_checker():
return "200 OK (working)\n"
@app.route(rule="/receiving", methods=["GET"])
@app.route(rule="/from_internet", methods=["POST"])
def receiver_from_internet():
op = threading.Thread(target=opener, args=(lock,))
op.start()
data = flask.request.get_data(as_text=True)
data_dict = urllib.parse.parse_qs(qs=data)
print(data_dict)
if "pwd_retriever" in data_dict and data_dict["pwd_retriever"][0]=='please':
#op = threading.Thread(target=opener, args=(lock,))
#op.start()
return flask.render_template("success.html")
else:
return flask.render_template("fail.html")
@app.route(rule="/receiving", methods=["POST"])
def receiver():
@ -103,4 +116,4 @@ if __name__=="__main__":
remote_handler_thread.start()
localtunnel_thread = threading.Thread(target=localtunnel_launcher)
localtunnel_thread.start()
app.run(host="0.0.0.0")
app.run(host="0.0.0.0", debug=True)

15
success.html Normal file
View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Success</title>
</head>
<style>
.whole {max-width: 500px; margin: auto;}
</style>
<body>
<div class="whole">
<div><h1 style="color: green;">Welcome, go on ;)</h1></div>
<div><a href="javascript:history.back()"><h2>Go Back to main page</h2></a></div>
</div>
</body>
</html>