-
Notifications
You must be signed in to change notification settings - Fork 0
/
batphone_setup.py
82 lines (69 loc) · 2.27 KB
/
batphone_setup.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
73
74
75
76
77
78
79
80
81
82
from datetime import datetime
from flask import (
Flask,
abort,
flash,
redirect,
render_template,
request,
url_for,
)
from flask.ext.stormpath import (
StormpathError,
StormpathManager,
User,
login_required,
login_user,
logout_user,
user,
)
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'nananananananana'
app.config['STORMPATH_API_KEY_FILE'] = 'apiKey-YVVIY4R3LM986736KU1OS4LNX.properties'
app.config['STORMPATH_APPLICATION'] = 'batphone_setup'
stormpath_manager = StormpathManager(app)
@app.route('/')
def show_index():
return render_template('index.html')
@app.route('/setup', methods=['POST'])
def setup():
import sys
sys.path.append('..')
from application_management import database_clone
import threading
from sockets import TCPServerSocket
from read_ip_address import read_ip_address
from join_batman_network import join_batman_network
from post_network_device import post_network_device
# Pull info from form
dev_name = request.form['name']
longitude = request.form['longitude']
latitude = request.form['latitude']
description = request.form['description']
notes = request.form['notes']
ssid = request.form['ssid']
mac = request.form['mac']
# Join the BATMAN network in the DHCP/Web App Host spot
join_batman_network(interface = 'wlan0', network_name = ssid, ap_mac = mac)
# Creates a thread to manage new network devices and
# dish out open IP addresses.
ip = read_ip_address('bat0')
socket = TCPServerSocket.TCPServerSocket(ip, 3000)
dhcp_thread = threading.Thread(target = socket.start_server)
dhcp_thread.start()
# Get the data from the server
data = database_clone.database_clone()
# Add the device's information to the database
post_network_device(ssid = ssid, publickey = 'pgp', dev_name = dev_name,
IP_address = '192.168.2.4', MAC = mac, Gateway_mode = 'client',
description = description, longitude = longitude, latitude = latitude,
notes = notes)
# Start hosting the web app, add the info to the database
# Start managing the database syncing
application_management.host_web_app.host_web_app()
application_management.populate_db.populate_db(data)
application_management.manage_db.manage_db()
return 'OK'
if __name__ == '__main__':
app.run(host='10.0.0.1')