-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_app.py
executable file
·67 lines (57 loc) · 2.29 KB
/
flask_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import print_function
import datetime, time, os
import P17_003, P17_022R2_A
from flask import Flask, abort, render_template
from flask import url_for, redirect, request, make_response, session, send_from_directory
from flask_app_pi import pi_blueprint
import parse_iwlist
import os
dBase32 = '0123456789ABCDEFGHJKLMNPRSTUVWXY'
app = Flask(__name__, static_url_path='/static')
app.register_blueprint(pi_blueprint)
app.secret_key = "not a secret key"
@app.route('/')
def index():
return render_template('base.html', name = "base")
@app.route('/download_log',methods=['GET'])
def download_log():
filename = "userLog.txt"
with open(filename, 'w') as f:
f.truncate()
with open('tmp1.out') as f:
lines = f.readlines()
output_content = (request.cookies.get('Output Content') if(request.cookies.get('Output Content')) else "")
with open(filename, 'w') as f:
f.write(output_content)
f.writelines(lines)
#return flask_app.app.send_static_file('userLog.txt')
return send_from_directory(directory=app.root_path, filename=filename, as_attachment=True)
@app.route('/wifi_config', methods = ['GET'])
def wifi_page():
os.system("sudo iwlist wlan0 scan")
wifi_list = parse_iwlist.get_interfaces(interface = "wlan0");
return render_template('wifi_config.html', name = "wifi", wifi_list = wifi_list)
@app.route('/select_wifi', methods = ['GET', 'POST'])
def select():
ssid, password = request.form.get('ap_info'), request.form.get('psw')
print(ssid)
print("\n")
print(password)
if(not password):
password = ""
with open("wpa_supplicant.conf", 'a') as f:
f.write("\nnetwork = {\n")
f.write("\tssid=\""+ssid+"\"\n")
f.write("\tpsk=\""+password+"\"\n")
f.write("}")
os.system("sudo cp wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf")
os.system("sudo ifdown wlan0")
os.system("sudo ifup wlan0")
return render_template('wifi_config.html', name = "wifi")
@app.route('/refresh', methods = ['GET', 'POST'])
def refresh():
os.system("sudo iwlist wlan0 scan")
wifi_list = parse_iwlist.get_interfaces(interface = "wlan0");
return render_template('wifi_config.html', name = "wifi", wifi_list = wifi_list)
if __name__ == '__main__':
app.run()