Browse Source

Adding internet option

chabisik 1 year ago
parent
commit
d5c7eef0ec
4 changed files with 75 additions and 6 deletions
  1. 15
    0
      fail.html
  2. 26
    0
      index.html
  3. 19
    6
      myapp.py
  4. 15
    0
      success.html

+ 15
- 0
fail.html View File

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

+ 26
- 0
index.html View File

@@ -0,0 +1,26 @@
1
+<!DOCTYPE html>
2
+<html>
3
+    <head>
4
+        <title>DomoDoor Page</title>
5
+    </head>
6
+    <style>
7
+        .whole {max-width: 500px; margin: auto;}
8
+    </style>
9
+    <body>
10
+        <div class="whole">
11
+            <h1 style="color: green;">DomoD--r Project (internet option)</h1>
12
+            <h1>
13
+            <form action="/from_internet" method="post">
14
+                <div>
15
+                    <label for="name">Enter Password :</label>
16
+                    <input type="password" id="pwd" name="pwd_retriever" style="width: 5cm; height: 0.8cm;">
17
+                </div>
18
+                <div style="text-align: center;">------------------</div>
19
+                <div class="button" style="text-align:center;">
20
+                    <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>
21
+                </div>
22
+            </form>
23
+            </h1>
24
+        </div>
25
+    </body>
26
+</html>

+ 19
- 6
myapp.py View File

@@ -8,7 +8,7 @@ import threading
8 8
 import subprocess
9 9
 import urllib.parse
10 10
 
11
-app = flask.Flask(import_name=__name__)
11
+app = flask.Flask(import_name=__name__, template_folder=".")
12 12
 
13 13
 try:
14 14
     sys.path.insert(0,'/home/pi/information')
@@ -22,7 +22,7 @@ def opener(lck):
22 22
             requests.get("http://192.168.0.103/open")
23 23
 
24 24
 def localtunnel_launcher(port=8000, wanted_subdomain="open-domodoor"):
25
-    result = subprocess.run(args="lt --port {} --subdomain {}".format(port,wanted_subdomain))
25
+    result = subprocess.run(args="lt --port {} --subdomain {}".format(port,wanted_subdomain), shell=True, executable="/bin/bash")
26 26
     print("Process returned:", result)
27 27
 
28 28
 def remote_handler(lck):
@@ -53,14 +53,27 @@ def remote_handler(lck):
53 53
         print("Attempt "+str(n_attempts)+" fails in finding remote")
54 54
         time.sleep(3)
55 55
 
56
+#------ENDPOINTS------
57
+
56 58
 @app.route(rule="/")
57 59
 def index():
60
+    return flask.render_template("index.html")
61
+
62
+@app.route(rule="/state")
63
+def state_checker():
58 64
     return "200 OK (working)\n"
59 65
 
60
-@app.route(rule="/receiving", methods=["GET"])
66
+@app.route(rule="/from_internet", methods=["POST"])
61 67
 def receiver_from_internet():
62
-    op = threading.Thread(target=opener, args=(lock,))
63
-    op.start()
68
+    data = flask.request.get_data(as_text=True)
69
+    data_dict = urllib.parse.parse_qs(qs=data)
70
+    print(data_dict)
71
+    if "pwd_retriever" in data_dict and data_dict["pwd_retriever"][0]=='please':
72
+        #op = threading.Thread(target=opener, args=(lock,))
73
+        #op.start()
74
+        return flask.render_template("success.html")
75
+    else:
76
+        return flask.render_template("fail.html")
64 77
 
65 78
 @app.route(rule="/receiving", methods=["POST"])
66 79
 def receiver():
@@ -103,4 +116,4 @@ if __name__=="__main__":
103 116
     remote_handler_thread.start()
104 117
     localtunnel_thread = threading.Thread(target=localtunnel_launcher)
105 118
     localtunnel_thread.start()
106
-    app.run(host="0.0.0.0")
119
+    app.run(host="0.0.0.0", debug=True)

+ 15
- 0
success.html View File

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

Loading…
Cancel
Save