From d5c7eef0ecc971ce46686373400d6355051e35d9 Mon Sep 17 00:00:00 2001 From: chabisik Date: Wed, 21 Dec 2022 23:22:19 +0100 Subject: [PATCH] Adding internet option --- fail.html | 15 +++++++++++++++ index.html | 26 ++++++++++++++++++++++++++ myapp.py | 25 +++++++++++++++++++------ success.html | 15 +++++++++++++++ 4 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 fail.html create mode 100644 index.html create mode 100644 success.html diff --git a/fail.html b/fail.html new file mode 100644 index 0000000..d07a973 --- /dev/null +++ b/fail.html @@ -0,0 +1,15 @@ + + + + Fail + + + +
+

Something went wrong :(

+

Go Back to main page

+
+ + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..fce1933 --- /dev/null +++ b/index.html @@ -0,0 +1,26 @@ + + + + DomoDoor Page + + + +
+

DomoD--r Project (internet option)

+

+
+
+ + +
+
------------------
+
+ +
+
+

+
+ + \ No newline at end of file diff --git a/myapp.py b/myapp.py index 48fcd51..b2485bc 100644 --- a/myapp.py +++ b/myapp.py @@ -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") \ No newline at end of file + app.run(host="0.0.0.0", debug=True) \ No newline at end of file diff --git a/success.html b/success.html new file mode 100644 index 0000000..9aff93d --- /dev/null +++ b/success.html @@ -0,0 +1,15 @@ + + + + Success + + + +
+

Welcome, go on ;)

+

Go Back to main page

+
+ + \ No newline at end of file