diff --git a/.gitignore b/.gitignore index a91167b13f74a4dff9162fe22cb1761d7e7c786e..44a7f85fa5d0e6805c26dba0338240fce46aede0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.bak storage/ __pycache__ +*.pyc diff --git a/app.py b/app.py index 46c113d95cbc7dfd5a36ccb77fe1b2aa81efa3e5..e7c69ac30b76ca3e7b378ba32f0686ddd4a31974 100644 --- a/app.py +++ b/app.py @@ -76,7 +76,8 @@ def wifi_pass(ssid): if(cell is not None): return render_template('index.html', data=ssid,isEnc=is_encrypted(cell)) else: - return redirect(url_for('index')) + return render_template('index.html', data="None",isEnc=True) + #return redirect(url_for('index')) @app.route('/wifi_select/', methods=['GET']) def pass_without_ssid(): @@ -112,6 +113,18 @@ def pin_store(): @app.route("/main_page", methods=['GET']) def main_page(): return render_template("main_page.html") +@app.route("/<string:otp>", methods=['GET']) +def otp(otp): + return render_template("otp.html", data=otp) + +@app.route("/otp_check", methods=['POST']) +def check_otp(): + otp_type = request.form.get('type') + otp = request.form.get('pin') + print(otp_type, otp) + return redirect(url_for('index')) + + if __name__ == '__main__': - app.run(host='0.0.0.0', port=8080, debug=True) + app.run(host='0.0.0.0', port=8080, debug=True) diff --git a/otp.py b/otp.py new file mode 100644 index 0000000000000000000000000000000000000000..a64f5f7ab487fc089e7ba7369b5b5603b871450c --- /dev/null +++ b/otp.py @@ -0,0 +1,11 @@ +import pyotp +import base64 + +class otp_utils: + + def __init__(self,secret): + self.otp_checker = pyotp.TOTP(base64.b32encode(secret.encode('utf-8')), interval=60, digits=6) + def check(self,totp): + return self.otp_checker.verify(totp); + def generate(self): + return self.otp_checker.now() diff --git a/requirement.txt b/requirement.txt index 11bf8280494c8821211f2d5a37fc52ec756bcef7..917662f8aaef95a97bd9ea38d1dc533598b3ba0d 100644 --- a/requirement.txt +++ b/requirement.txt @@ -1,4 +1,5 @@ flask flask-bootstrap sqlite3 +pyotp diff --git a/simple_sql.pyc b/simple_sql.pyc deleted file mode 100644 index 443fab394d5fe360cbcfd3737e98844efe6ef2c1..0000000000000000000000000000000000000000 Binary files a/simple_sql.pyc and /dev/null differ diff --git a/static/css/main.css b/static/css/main.css index 5ac1ba53d6ce64f08de3742bd9f1d55f3a238327..b2f16738e563fdd90650d05e8c8c07bdbf43de03 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -6,7 +6,7 @@ } .scrollbar{ position:relative; - height: 300px; + height: 200px; overflow: auto; } input { diff --git a/templates/index.html b/templates/index.html index 597ff803a2db7c884523bc666ca002c438866094..51d7078f51c814f84c7ffce4ef70a4ae5a2a0ebb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -29,26 +29,26 @@ {% endblock head %} {% block content%} -<body class="bg-light m-5"> +<body class="bg-light ml-1 mr-1"> <div> <p style="visibility:hidden" id="ssid">{{data}}</p> - <h2 class="text-muted text-center m-5">Wifi Password</h2> + <button type="submit" class="btn btn-primary btn-lg btn-font" id="prev" >Previous</button> + <h2 class="text-muted text-center">Wifi Password</h2> <center> {% if isEnc is sameas true%} - <div class="row align-items-center m-5 col-8"> + <div class="row align-items-center m-1 col-8"> <div class="col-10 inline "> <input type="password" class="form-control input btn-font" id="wifi-password" placeholder="Tap on the virtual keyboard to start"> </div> + <div class="col-2 inline"> + <button type="submit" class="btn btn-primary btn-lg btn-font" id="conn" >Connect</button> + </div> {% endif%} </div> - <div class="container m-5"> - <button type="submit" class="btn btn-primary btn-danger btn-lg pull-left btn-font" id="prev" >Previous</button> - <button type="submit" class="btn btn-primary btn-danger btn-lg pull-right btn-font" id="conn" >Connect</button> - </div> <div class="row align-items-center"> - <div class="col m-5 inline"> - <div class="simple-keyboard" id="keyboard" style="visibility: visible"></div> + <div class="col inline"> + <div class="simple-keyboard" id="keyboard" style="visibility: hidden"></div> </div> </div> </center> diff --git a/templates/main_page.html b/templates/main_page.html index 0ef0c622db92a2f08d01bd1958438efb147c9b82..e852093da037ce91f8401748997cd8942fbe26eb 100644 --- a/templates/main_page.html +++ b/templates/main_page.html @@ -16,6 +16,8 @@ <center> <button type="submit" id="pin_setup" class="btn btn-primary btn-danger btn-lg btn-font">Pincode Setup</button> <button type="submit" id="setting" class="btn btn-primary btn-danger btn-lg btn-font">Preference</button> + <button type="submit" id="totp" class="btn btn-primary btn-danger btn-lg btn-font">Input TOTP</button> + <button type="submit" id="otp" class="btn btn-primary btn-danger btn-lg btn-font">Input OTP</button> </center> </div> {% block footer %} @@ -32,6 +34,12 @@ $("#pin_setup").click(function(){ window.location.href="http://localhost:8080/pin_setup"; }); + $("#totp").click(function(){ + window.location.href="http://localhost:8080/totp"; + }); + $("#otp").click(function(){ + window.location.href="http://localhost:8080/otp"; + }); </script> {% endblock scripts %} {% endblock content %} diff --git a/templates/otp.html b/templates/otp.html new file mode 100644 index 0000000000000000000000000000000000000000..7795e2ba96531da5d8a75174b949a8ce62a47588 --- /dev/null +++ b/templates/otp.html @@ -0,0 +1,93 @@ +{% extends "bootstrap/base.html" %} + + +{% block head %} +{{super()}} + + + + <!-- bootstrap --> + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" + integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> + <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" + integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" + crossorigin="anonymous"></script> + <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" + integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" + crossorigin="anonymous"></script> + <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" + integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" + crossorigin="anonymous"></script> + + <!-- keyboard css--> + <link rel="stylesheet" href="{{url_for('static',filename='css/keyboard.css')}}"> + <link rel="stylesheet" href="{{url_for('static',filename='css/main.css')}}"> + <script> + $(document).ready(function () { + document.getElementById("keyboard").style.visibility = 'visible'; + }); + + </script> +{% endblock head %} + +{% block content%} +<body class="container mx-auto bg-light m-2"> + + <h2 class="text-muted text-center m-5">{{data}} Input</h2> + <center> + <div class="row col mx-auto m-2 col-8"> + <div class="col-sm"> + {% for i in range(6) %} + <input type="password" class="form-control input float-left col-sm-2 text-center input_margin btn-font" id="slot-{{loop.index}}" disabled="true" maxlength="1"> + {% endfor %} + </div> + <div class="col-2 inline"> + <button type="submit" class="btn btn-primary btn-font" id="setup" >Confirm</button> + </div> + </div> + <div class="row align-items-center"> + <div class="col m-2 inline"> + <div class="simple-keyboard" id="keyboard" style="visibility: hidden"></div> + </div> + </div> + </center> + <script src="{{url_for('static', filename='js/keyboard.min.js')}}"></script> + <script src="{{url_for('static', filename='js/pincode.js')}}"></script> + <script> + $('#setup') .click(function(){ + if( pin_code.length == 6 ){ + console.log(pin_code); + pin = pin_code.join(''); + data="type={{data}}&pin="+pin + $.ajax({ + type:"POST", + url:"http://localhost:8080/otp_check", + data:data, + success:function(data, status){ + alert("PIN CODE SETUP SUCCESS"); + window.location.href="http://localhost:8080/main_page"; + }, + error:function(data, status){ + alert("PIN CODE SETUP FAILED") + } + }); + }else{ + alert('PINCODE LENGTH MUST BE 6'); + } + }) + </script> + <!-- keyboard js--> +</body> +{% block footer %} +<footer class="footer" > + <div class="footer navbar-fixed-bottom text-center"> + <p class="text-muted">© NTUST PRLAB</p> + </div> +</footer> +{% endblock footer %} +{% endblock %} + + + + + diff --git a/templates/pincode.html b/templates/pincode.html index 843e5716bc89bbd165fcb98fb6b911c2efd8e667..6df1c5ae2c657e166b3057b3510245b9cd500a73 100644 --- a/templates/pincode.html +++ b/templates/pincode.html @@ -31,21 +31,21 @@ {% endblock head %} {% block content%} -<body class="container mx-auto bg-light m-5"> +<body class="container mx-auto bg-light m-2"> <h2 class="text-muted text-center m-5">PinCode Setup</h2> <center> - <div class="row col mx-auto m-5 col-8"> + <div class="row col mx-auto m-2 col-8"> <div class="col-sm"> {% for i in range(6) %} - <input type="password" class="form-control input float-left col-sm-1 text-center input_margin" id="slot-{{loop.index}}" disabled="true" maxlength="1"> + <input type="password" class="form-control input float-left col-sm-2 text-center input_margin btn-font" id="slot-{{loop.index}}" disabled="true" maxlength="1"> {% endfor %} </div> <div class="col-2 inline"> - <button type="submit" class="btn btn-primary" id="setup" style="height:50px">Confirm</button> + <button type="submit" class="btn btn-primary btn-font" id="setup" >Confirm</button> </div> </div> <div class="row align-items-center"> - <div class="col m-5 inline"> + <div class="col m-2 inline"> <div class="simple-keyboard" id="keyboard" style="visibility: hidden"></div> </div> </div> diff --git a/test.py b/test.py new file mode 100644 index 0000000000000000000000000000000000000000..96a648d5085e4885d4c681add861778219ffff93 --- /dev/null +++ b/test.py @@ -0,0 +1,11 @@ +from otp import * + +otper = otp_utils('rewrewr') + +otp = otper.generate() + +print("otp is {}".format(otp)) + +ret = otper.check(otp) + +print("Check OTP {} is {}".format(otp, ret)) diff --git a/wifi_utils.pyc b/wifi_utils.pyc deleted file mode 100644 index 67f8858494bf6e7ceca6edd5c435cd9a4c11ea06..0000000000000000000000000000000000000000 Binary files a/wifi_utils.pyc and /dev/null differ