Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed style to bootstrap #93

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__pycache__
libs/configuration_app/.idea
/.idea
56 changes: 15 additions & 41 deletions initial_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,35 @@
if os.getuid():
sys.exit('You need root access to install!')


os.system('clear')
print()
print()
print("###################################")
print("##### RaspiWiFi Intial Setup #####")
print("##### SymphonistWiFi Config Intial Setup #####")
print("###################################")
print()
print()
entered_ssid = input("Would you like to specify an SSID you'd like to use \nfor Host/Configuration mode? [default: RaspiWiFi Setup]: ")
print()
wpa_enabled_choice = input("Would you like WPA encryption enabled on the hotspot \nwhile in Configuration Mode? [y/N]:")
print()
wpa_entered_key = input("What password would you like to for WPA hotspot \naccess (if enabled above, \nMust be at least 8 characters) [default: NO PASSWORD]:")
print()
auto_config_choice = input("Would you like to enable \nauto-reconfiguration mode [y/N]?: ")
print()
auto_config_delay = input("How long of a delay would you like without an active connection \nbefore auto-reconfiguration triggers (seconds)? [default: 300]: ")
print()
server_port_choice = input("Which port would you like to use for the Configuration Page? [default: 80]: ")
print()
ssl_enabled_choice = input("Would you like to enable SSL during configuration mode \n(NOTICE: you will get a certificate ID error \nwhen connecting, but traffic will be encrypted) [y/N]?: ")
entered_ssid = "symphonistWiFi Config"
wpa_enabled_choice = "y"
wpa_entered_key = "symphonist"
auto_config_choice = "N"
auto_config_delay = "300"
server_port_choice = "80"
ssl_enabled_choice = "N"
os.system('clear')
print()
print()
install_ans = input("Are you ready to commit changes to the system? [y/N]: ")

if(install_ans.lower() == 'y'):
setup_lib.install_prereqs()
setup_lib.copy_configs(wpa_enabled_choice)
setup_lib.update_main_config_file(entered_ssid, auto_config_choice, auto_config_delay, ssl_enabled_choice, server_port_choice, wpa_enabled_choice, wpa_entered_key)
else:
print()
print()
print("===================================================")
print("---------------------------------------------------")
print()
print("RaspiWiFi installation cancelled. Nothing changed...")
print()
print("---------------------------------------------------")
print("===================================================")
print()
print()
sys.exit()

setup_lib.install_prereqs()
setup_lib.copy_configs(wpa_enabled_choice)
setup_lib.update_main_config_file(entered_ssid, auto_config_choice, auto_config_delay, ssl_enabled_choice, server_port_choice, wpa_enabled_choice, wpa_entered_key)


os.system('clear')
print()
print()
print("#####################################")
print("##### RaspiWiFi Setup Complete #####")
print("##### SymphonistWiFi Setup Complete #####")
print("#####################################")
print()
print()
print("Initial setup is complete. A reboot is required to start in WiFi configuration mode...")
reboot_ans = input("Would you like to do that now? [y/N]: ")

if reboot_ans.lower() == 'y':
os.system('reboot')
os.system('reboot')
140 changes: 140 additions & 0 deletions libs/configuration_app/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
from flask import Flask, render_template, request
import subprocess
import os
import time
from threading import Thread
import fileinput

app = Flask(__name__)
app.debug = True


@app.route('/')
def index():
#wifi_ap_array = scan_wifi_networks()
wifi_ap_array = ['hello','abcd']
config_hash = config_file_hash()

return render_template('app.html', wifi_ap_array = wifi_ap_array, config_hash = config_hash)


@app.route('/manual_ssid_entry')
def manual_ssid_entry():
return render_template('manual_ssid_entry.html')

@app.route('/wpa_settings')
def wpa_settings():
config_hash = config_file_hash()
return render_template('wpa_settings.html', wpa_enabled = config_hash['wpa_enabled'], wpa_key = config_hash['wpa_key'])


@app.route('/save_credentials', methods = ['GET', 'POST'])
def save_credentials():
ssid = request.form['ssid']
wifi_key = request.form['wifi_key']

#create_wpa_supplicant(ssid, wifi_key)

# Call set_ap_client_mode() in a thread otherwise the reboot will prevent
# the response from getting to the browser
def sleep_and_start_ap():
time.sleep(2)
#set_ap_client_mode()
t = Thread(target=sleep_and_start_ap)
t.start()

return render_template('save_credentials.html', ssid = ssid)


@app.route('/save_wpa_credentials', methods = ['GET', 'POST'])
def save_wpa_credentials():
config_hash = config_file_hash()
wpa_enabled = request.form.get('wpa_enabled')
wpa_key = request.form['wpa_key']

#if str(wpa_enabled) == '1':
# update_wpa(1, wpa_key)
#else:
# update_wpa(0, wpa_key)

def sleep_and_reboot_for_wpa():
time.sleep(2)
os.system('reboot')

t = Thread(target=sleep_and_reboot_for_wpa)
t.start()

config_hash = config_file_hash()
return render_template('save_wpa_credentials.html', wpa_enabled = config_hash['wpa_enabled'], wpa_key = config_hash['wpa_key'])




######## FUNCTIONS ##########

def scan_wifi_networks():
iwlist_raw = subprocess.Popen(['iwlist', 'scan'], stdout=subprocess.PIPE)
ap_list, err = iwlist_raw.communicate()
ap_array = []

for line in ap_list.decode('utf-8').rsplit('\n'):
if 'ESSID' in line:
ap_ssid = line[27:-1]
if ap_ssid != '':
ap_array.append(ap_ssid)

return ap_array

#def create_wpa_supplicant(ssid, wifi_key):


#def set_ap_client_mode():

def update_wpa(wpa_enabled, wpa_key):
with fileinput.FileInput('/etc/raspiwifi/raspiwifi.conf', inplace=True) as raspiwifi_conf:
for line in raspiwifi_conf:
if 'wpa_enabled=' in line:
line_array = line.split('=')
line_array[1] = wpa_enabled
print(line_array[0] + '=' + str(line_array[1]))

if 'wpa_key=' in line:
line_array = line.split('=')
line_array[1] = wpa_key
print(line_array[0] + '=' + line_array[1])

if 'wpa_enabled=' not in line and 'wpa_key=' not in line:
print(line, end='')


def config_file_hash():
config_file = open('/etc/raspiwifi/raspiwifi.conf')
config_hash = {}

for line in config_file:
line_key = line.split("=")[0]
line_value = line.split("=")[1].rstrip()
config_hash[line_key] = line_value

return config_hash


def config_file_hash():
config_file = open('raspiwifi.conf')
config_hash = {}

for line in config_file:
line_key = line.split("=")[0]
line_value = line.split("=")[1].rstrip()
config_hash[line_key] = line_value

return config_hash


if __name__ == '__main__':
config_hash = config_file_hash()

if config_hash['ssl_enabled'] == "1":
app.run(host = '0.0.0.0', port = int(config_hash['server_port']), ssl_context='adhoc')
else:
app.run(host = '0.0.0.0', port = int(config_hash['server_port']))
7 changes: 7 additions & 0 deletions libs/configuration_app/static/js/bootstrap.min.js

Large diffs are not rendered by default.

Loading