-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
72 lines (58 loc) · 2.04 KB
/
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
68
69
70
71
72
import argparse
import logging
import logging.handlers
import os
import os.path
import sys
from configparser import ConfigParser
from flask import (Flask, redirect, render_template, request,
send_from_directory, url_for)
config = ConfigParser()
try:
with open('settings.conf', 'r') as fp:
config.readfp(fp)
except IOError:
print("Unable to read settings.conf, file may be missing.")
sys.exit(1)
except:
print("Error in settings.conf:", sys.exc_info()[0])
sys.exit(1)
log = logging.getLogger('Wireless Host')
log.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler()
consoleHandler.setLevel(logging.getLevelName(
config.get('logging', 'consoleLevel')))
consoleFormatter = logging.Formatter(
'%(asctime)s - %(name)s %(levelname)s: %(message)s', '%H:%M:%S')
consoleHandler.setFormatter(consoleFormatter)
try:
fileHandler = logging.handlers.RotatingFileHandler(config.get('logging', 'file'),
maxBytes=config.getint('logging', 'maxSize'),
backupCount=config.getint('logging', 'numBackup'))
except IOError:
print("Error: unable to write to log files. Check permissions are correct.")
sys.exit(1)
fileHandler.setLevel(logging.getLevelName(
config.get('logging', 'fileLevel')))
fileFormatter = logging.Formatter(
'%(asctime)s %(name)s %(levelname)s - %(message)s', '%Y-%m-%d %H:%M:%S')
fileHandler.setFormatter(fileFormatter)
log.addHandler(consoleHandler)
log.addHandler(fileHandler)
app = Flask(__name__)
serverPort = config.getint('server', 'port')
serverDebug = config.getboolean('server', 'debug')
networkInterface = config.get('network', 'interface')
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html'), 200
@app.route('/submit', methods=['POST'])
def submit():
ssid = request.form['ssid']
psk = request.form['psk']
log.debug("SSID: {}\tPSK: {}".format(ssid, psk))
return "got", 200
if __name__ == "__main__":
log.critical('Starting network module')
app.run(debug=serverDebug, host="0.0.0.0", port=serverPort)