diff --git a/COPYING b/COPYING deleted file mode 100755 index c13fd166..00000000 --- a/COPYING +++ /dev/null @@ -1,15 +0,0 @@ -Guided WiFi configuration software for the Raspberry Pi -Copyright (C) 2015 Jason Burgett jasbur@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see diff --git a/gpl.txt b/LICENSE old mode 100755 new mode 100644 similarity index 99% rename from gpl.txt rename to LICENSE index 94a9ed02..f288702d --- a/gpl.txt +++ b/LICENSE @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. diff --git a/Readme.md b/Readme.md new file mode 100644 index 00000000..3037f238 --- /dev/null +++ b/Readme.md @@ -0,0 +1,55 @@ +# OTA Wifi Configuration + +OTA Wifi Configuration is a program to headlessly configure a Raspberry Pi's WiFi +connection using using any other WiFi-enabled device (much like the way +a Chromecast or similar device can be configured). + +### OTA Wifi Configuration has been tested with + +- Raspberry Pi 4b Running Raspberry Pi Os Buster Lite + +### OTA Wifi Configuration should work with + +- Any rasberry Pi running Raspberry Pi Os Buster or Bullseye + +## Installation Instructions: + +- Navigate to the directory where you downloaded or cloned OTA Wifi Configuration + +- Run: `sudo python3 setup.py`, **Must be run with sudo or as root** + +- This script will install all necessary prerequisites and copy all necessary + config and library files, then reboot. +- Wait for it to finish booting then go back to the directory that you cloned or downloaded OTA Wifi Configuration and run `sudo python3 app.py` +- It should + present itself in _Configuration Mode_ as a WiFi access point with the + name **Device [xxxx]**. The Xs being replaced with the last four digits of your raspberry pi's serial number. + +## Usage: + +- Connect to the **Device [xxxx]** access point using any other WiFi enabled + device. + +- Make an http request to [**192.168.50.10**] or [**setup.com**] on port 5000 + +## Api: + +### **/connected** - Attempts to set the wifi on the device. It will set the credentials then restart the device. Will return a 200 status code if succeeded. + +- **Params** - The params must be passed in as JSON data. Mimetype must indicate JSON (application/json). + - **SSID** - String - The ssid of the wifi you wish to connect to. + - **wifi_key** - String - The wpa key of the wifi you wish to connect to. +- **Returns** - **{"status": "success", "status_code": 200}** if succeeded or **{"status": "failed", "status_code": 500}** if failed + +### **/save_credentials** - will return a 200 status code if succeeded. + +- **Params** - None +- **Returns** - {"status_code": 200} + +## Resetting the device: + +### You can reset the device by running setup.py again as root or with sudo. + +## Stopping access point + +## You can disable the access point by running disable_access_point.py as root or with sudo. diff --git a/Readme.txt b/Readme.txt deleted file mode 100755 index 746ac152..00000000 --- a/Readme.txt +++ /dev/null @@ -1,142 +0,0 @@ -RaspiWiFi - -RaspiWiFi is a program to headlessly configure a Raspberry Pi's WiFi -connection using using any other WiFi-enabled device (much like the way -a Chromecast or similar device can be configured). - -It can also be used as a method to connect wirelessly point-to-point with your -Pi when a network is not available or you do not want to connect to one. Just -leave it in Configuration Mode, connect to the "RaspiWiFi[xxxx] Setup" access -point. The Pi will be addressable at 10.0.0.1 using all the normal methods you -might use while connected through a network. - -RaspiWiFi has been -tested with the Raspberry Pi B+, Raspberry Pi 3, and Raspberry Pi Zero W. - - - -OS IMAGE USAGE: - -== Just burn the ".IMG" file attached to this release to an 8GB+ SD card. Boot -your Raspberry Pi with the SD card and it will automatically boot into its AP -Host (broadcast) mode with an SSID based on a unique id (the last four of your -Pi's serial number). No input devices or displays necessary. Otherwise this is -a base install of the current Raspbian Stretch, up to date as of the date of -this release. - - - - SCRIPT-BASED INSTALLATION INSTRUCTIONS: - -== Navigate to the directory where you downloaded or cloned RaspiWiFi - -== Run: - -sudo python3 initial_setup.py - -== This script will install all necessary prerequisites and copy all necessary -config and library files, then reboot. When it finishes booting it should -present itself in "Configuration Mode" as a WiFi access point with the -name "RaspiWiFi[xxxx] Setup". - -== The original RaspiWiFi directory that you ran the Initial Setup is no longer -needed after installation and can be safely deleted. All necessary files are -copied to /usr/lib/raspiwifi/ on setup. - - -CONFIGURATION: - -== You will be prompted to set a few variables during the Initial Setup script: - -==== "SSID Prefix" [default: "RaspiWiFi Setup"]: This is the prefix of the SSID - that your Pi will broadcast for you to connect to during - Configuration Mode (Host Mode). The last four of you Pi's serial number - will be appended to whatever you enter here. - -==== "WPA Encryption" [default: No]: If oyu enable this setting the Access Point - created during Configuration Mode will be encrypted using WPA2 encryption. - The prompt following this one will let you specify the Wireless Key to be - used. You can leave the password blank if you chose 'N' to this option. - -==== "Auto-Config mode" [default: n]: If you choose to enable this mode your Pi - will check for an active connection while in normal operation mode (Client Mode). - If an active connection has been determined to be lost, the Pi will reboot - back into Configuration Mode (Host Mode) automatically. - -==== "Auto-Config delay" [default: 300 seconds]: This is the time in consecutive - seconds to wait with an inactive connection before triggering a reset into - Configuration Mode (Host Mode). This is only applicable if the - "Auto-Config mode" mentioned above is set to active. - -==== "Server port" [default: 80]: This is the server port that the web server - hosting the Configuration App page will be listening on. If you change - this port make sure to add it to the end of the address when you're - connecting to it. For example, if you speficiy 12345 as the port number - you would navigate to the page like this: http://10.0.0.1:12345 If you - leave the port at the default setting [80] there is no need to specify the - port when navigating to the page. - -==== "SSL Mode" [default: n]: With this option enabled your RaspiWifi - configuration page will be sent over an SSL encrypted connection (don't - forget the "s" when navigating to https://10.0.0.1:9191 when using - this mode). You will get a certificate error from your web browser when - connecting. The error is just a warning that the certificate has not been - verified by a third party but everything will be properly encrypted anyway. - -== All of these variables can be set at any time after the Initial Setup has -been running by editing the /etc/raspiwifi/raspiwifi.conf - - -USAGE: - -== Connect to the "RaspiWiFi[xxxx] Setup" access point using any other WiFi enabled -device. - -== Navigate to [10.0.0.1], [raspiwifisetup.com], or -[idliketoconfigurethewifionthisdevicenowplease.com] (I was debating whether this -was funny or not and, yes, it was) using any web browser on the device you -connected with. (don't forget to manually start with [https://] when using SSL mode) - -== Select the WiFi connection you'd like your Raspberry Pi to connect to from -the drop down list and enter its wireless password on the page provided. If no -encryption is enabled, leave the password box blank. You may also manually -specify your network information by clicking on the "manual SSID entry ->" link. - -== Click the "Connect" button. - -== At this point your Raspberry Pi will reboot and connect to the access point -specified. - -== You can view the current WPA encryption settings and change them from the main Web -Configuration interface. The current settings are visible in a panel in the upper -left corner of the screen. If you click the values in this display you will be taken -to a page where you can change them. If you change them your device will reboot to -enable the new configuration. - -== You can also use the Pi in a point-to-point connection mode by leaving it in -Configuration Mode. All services will be addresible in their normal way at -10.0.0.1 while connected to the "RaspiWiFi[xxxx] Setup" AP. - - - -RESETTING THE DEVICE: - -== If GPIO 18 is pulled HIGH for 10 seconds or more the Raspberry Pi will reset -all settings, reboot, and enter "Configuration Mode" again. It's useful to have -a simple button wired on GPIO 18 to reset easily if moving to a new location, -or if incorrect connection information is ever entered. Just press and hold for -10 seconds or longer. - -== You can also reset the device by running the manual_reset.py in the -/usr/lib/raspiwifi/reset_device directory as root or with sudo. - - -UNINSTALLATION: - -== You can uninstall RaspiWiFi at any time by running: - - sudo python3 /usr/lib/raspiwifi/uninstall.python3 - - You can also run it from the "libs/" directory from a fresh clone if you've - installed from a previous version and don't have /usr/lib/raspiwifi/uninstall.py - available. \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 00000000..025e4263 --- /dev/null +++ b/app.py @@ -0,0 +1,62 @@ +from flask import Flask, render_template, request +import subprocess +import os +import time +from threading import Thread +from disable_access_point import disable_access_point +import fileinput + +app = Flask(__name__) +app.debug = True + + +def set_wifi_credentials(ssid, password): + try: + config_lines = [ + "country=US", # Replace 'US' with the appropriate country code for your region + "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev", + "update_config=1", + "", + "network={", + f'\tssid="{ssid}"', + "\tscan_ssid=1", + f'\tpsk="{password}"', + "\tkey_mgmt=WPA-PSK", + "}", + ] + + # Join the configuration lines into a single string + config_data = "\n".join(config_lines) + + # Write the configuration to the wpa_supplicant file + with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as wpafile: + wpafile.write(config_data) + + t = Thread(target=disable_access_point) + t.start() + + return True + except Exception as e: + print(e) + return False + + +@app.route("/save_credentials", methods=["GET", "POST"]) +def save_credentials(): + ssid = request.json["ssid"] + wifi_key = request.json["wifi_key"] + + if set_wifi_credentials(ssid, wifi_key): + return {"status": "success", "status_code": 200} + else: + return {"status": "failed", "status_code": 500} + + +@app.route("/connected", methods=["GET", "POST"]) +def conncected(): + response = {"status_code": 200} + return response + + +def run_api(): + app.run(host="0.0.0.0", port=5000) diff --git a/disable_access_point.py b/disable_access_point.py new file mode 100644 index 00000000..b737c988 --- /dev/null +++ b/disable_access_point.py @@ -0,0 +1,11 @@ +import os + + +def disable_access_point(): + os.system("systemctl disable dnsmasq") + os.system("systemctl disableg hostapd") + + os.system("sudo cp /etc/dnsmasq.conf.copy /etc/dnsmasq.conf") + os.system("sudo cp /etc/dhcpcd.conf.copy /etc/dhcpcd.conf") + + os.system("reboot") diff --git a/initial_setup.py b/initial_setup.py deleted file mode 100644 index e792e3a4..00000000 --- a/initial_setup.py +++ /dev/null @@ -1,66 +0,0 @@ -import os -import sys -import setup_lib - - -if os.getuid(): - sys.exit('You need root access to install!') - - -os.system('clear') -print() -print() -print("###################################") -print("##### RaspiWiFi 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]?: ") -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() - -os.system('clear') -print() -print() -print("#####################################") -print("##### RaspiWiFi 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') diff --git a/libs/configuration_app/app.py b/libs/configuration_app/app.py deleted file mode 100644 index 677a42fb..00000000 --- a/libs/configuration_app/app.py +++ /dev/null @@ -1,151 +0,0 @@ -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() - 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): - temp_conf_file = open('wpa_supplicant.conf.tmp', 'w') - - temp_conf_file.write('ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n') - temp_conf_file.write('update_config=1\n') - temp_conf_file.write('\n') - temp_conf_file.write('network={\n') - temp_conf_file.write(' ssid="' + ssid + '"\n') - - if wifi_key == '': - temp_conf_file.write(' key_mgmt=NONE\n') - else: - temp_conf_file.write(' psk="' + wifi_key + '"\n') - - temp_conf_file.write(' }') - - temp_conf_file.close - - os.system('mv wpa_supplicant.conf.tmp /etc/wpa_supplicant/wpa_supplicant.conf') - -def set_ap_client_mode(): - os.system('rm -f /etc/raspiwifi/host_mode') - os.system('rm /etc/cron.raspiwifi/aphost_bootstrapper') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/apclient_bootstrapper /etc/cron.raspiwifi/') - os.system('chmod +x /etc/cron.raspiwifi/apclient_bootstrapper') - os.system('mv /etc/dnsmasq.conf.original /etc/dnsmasq.conf') - os.system('mv /etc/dhcpcd.conf.original /etc/dhcpcd.conf') - os.system('reboot') - -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 - - -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'])) diff --git a/libs/configuration_app/static/stylesheets/app.css b/libs/configuration_app/static/stylesheets/app.css deleted file mode 100644 index c4a86602..00000000 --- a/libs/configuration_app/static/stylesheets/app.css +++ /dev/null @@ -1,192 +0,0 @@ -/* General ----------------------------------------------------------*/ -*, :after, :before { -box-sizing: border-box; -} -body, -html { -margin:0; -padding:0; -} - -body{ - background-color: #000; - margin:0; - color: white; -} - -div#mainContent{ - padding:.3em; - background-color: #000; - width: 100%; - margin: 0 auto; - text-align: center; - font-size: 3.5rem; - color: #fff; -} - -div#mainContent h1 { - margin:0 0 .5em 0; - font-size:3rem; -} - -div#mainContent ul{ - list-style: none; - margin: 0; - padding: 0; -} - -div#mainContent form { - margin-top:-2em; -} - -div#wpaStatus{ - padding: 4px; - margin: 0 0 10px 0; - width: 250px; - background-color: #928043; - text-align: left; - font-size: .3em; -} - -div#wpaStatus a{ - color: #fff; -} - -label[for=ssid], -label[for=wifi_key]{ - font-size:1.9rem; -} - -/* Select ----------------------------------------------------------*/ - -li label { - display:inline-block; - margin: 0.5em 0; - padding: 0.5em 0; -} - -li.wifiNetwork { - position: relative; - margin: 0; -} - -li.wifiNetwork:after { - content: '▼'; - position: absolute; - width: 25px; - color: #deab04; - font-weight: bold; - font-size: 1.4rem; - right: 0px; - top: 40%; - border-radius: 3px; - pointer-events: none; - z-index: 2; -} - -select.wifiNetworkInputs { - position: relative; - width: 100%; - background: #111; - color: #999; - border: none; - outline: none; - font-size: 1.5rem; - padding: 1em; - margin: 0; - border-radius: 3px; - cursor: pointer; - height: auto; - -webkit-appearance: none; - -moz-appearance: none; - appearance: none; -} - -.wifiNetworkInputs{ - width: 100%; - padding:1em; - font-size: 1.4rem; - color: #999; - background: #111; - border:#999 solid 1px; -} - -.wifiConnectButton{ - width: 100%; - margin:2em 0; - padding:.5em; - background-color: #deab04; - font-size: 2rem; - color: #fff; -} - -.manualSSIDEntry{ - font-size: 1rem; - color: #fff; -} - -div#wpaCredentialsForm{ - margin: 60px 0 0 0; -} - -.wpaEnabledCheckbox{ - height: 46px; - width: 46px; -} - -div#saveCredentialsOutput{ - width: 60%; - margin: 0 0 0 20%; - text-align: center; - font-size: 1.7em; -} - -.saveCredentialsSSID{ - color: #deab04; - font-size: 2em; -} - -/* Wifi Icon ----------------------------------------------------------*/ - -.wifiIcon { - padding: 10px; -} -.wifiIcon, .wifiIcon:before { - display: inline-block; - border: 40px double transparent; - border-top-color: currentColor; - border-radius: 50%; -} -.wifiIcon:before { - content: ''; - width: 0; height: 0; -} - -/* Desktop ----------------------------------------------------------*/ - -@media (min-width: 800px) { - div#mainContent h1 { - font-size:4.5rem; - } - div#mainContent { - max-width:768px; - } - li.wifiNetwork:after { - content: '▼'; - position: absolute; - width: 50px; - color: #deab04; - font-weight: bold; - font-size: 2rem; - right: 0px; - bottom: 50px; - border-radius: 3px; - pointer-events: none; - z-index: 2; - } - -} diff --git a/libs/configuration_app/templates/app.html b/libs/configuration_app/templates/app.html deleted file mode 100644 index 419419bf..00000000 --- a/libs/configuration_app/templates/app.html +++ /dev/null @@ -1,42 +0,0 @@ -{% extends 'layout.html' %} - -{% block body %} -
-
- -
- -

WiFi Setup

-
- -
-
    -
  • - -
  • - -
  • - -
  • manual SSID entry ->
  • - -
  • -
  • - - -
-
-
-{% endblock %} diff --git a/libs/configuration_app/templates/layout.html b/libs/configuration_app/templates/layout.html deleted file mode 100644 index f2398a6d..00000000 --- a/libs/configuration_app/templates/layout.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - RaspiWiFi Setup - - - {% block body %} - {% endblock %} - - diff --git a/libs/configuration_app/templates/manual_ssid_entry.html b/libs/configuration_app/templates/manual_ssid_entry.html deleted file mode 100644 index 16ecb08a..00000000 --- a/libs/configuration_app/templates/manual_ssid_entry.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'layout.html' %} - -{% block body %} -
-

WiFi Setup

-
- -
-
    -
  • -
  • - -
  • -
  • - - -
-
-
-{% endblock %} diff --git a/libs/configuration_app/templates/save_credentials.html b/libs/configuration_app/templates/save_credentials.html deleted file mode 100644 index 27ea1c12..00000000 --- a/libs/configuration_app/templates/save_credentials.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends 'layout.html' %} - -{% block body %} -
-

Wifi connection configured for:

- {{ ssid }} -

Your device will now reboot and should be connected to your access point soon.

-
-{% endblock %} diff --git a/libs/configuration_app/templates/save_wpa_credentials.html b/libs/configuration_app/templates/save_wpa_credentials.html deleted file mode 100644 index c8821337..00000000 --- a/libs/configuration_app/templates/save_wpa_credentials.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends 'layout.html' %} - -{% block body %} -
-

WPA in Confirguration Mode set to:

- WPA Enabled: - {% if wpa_enabled == '1': %} - Yes
-
- - WPA Key: {{wpa_key}} -

Your device will now reboot. You can connect to it using the WPA Key above for further configuration.

- {% else: %} - No
-

Your device will now reboot. A WPA Key will NOT be required for further configuration.

- {% endif %} -
-{% endblock %} diff --git a/libs/configuration_app/templates/wpa_settings.html b/libs/configuration_app/templates/wpa_settings.html deleted file mode 100644 index 14b51e4c..00000000 --- a/libs/configuration_app/templates/wpa_settings.html +++ /dev/null @@ -1,25 +0,0 @@ -{% extends 'layout.html' %} - -{% block body %} -
-

WPA for Configuration Mode

-
- -
-
-
    - {% if wpa_enabled == '1': %} -
  • WPA On/Off
  • - {% else: %} -
  • WPA On/Off
  • - {% endif %} - -
  • -
  • - - -
-
-
-
-{% endblock %} diff --git a/libs/reset_device/button_chime.wav b/libs/reset_device/button_chime.wav deleted file mode 100644 index 7123fe15..00000000 Binary files a/libs/reset_device/button_chime.wav and /dev/null differ diff --git a/libs/reset_device/connection_monitor.py b/libs/reset_device/connection_monitor.py deleted file mode 100644 index 4918ccf1..00000000 --- a/libs/reset_device/connection_monitor.py +++ /dev/null @@ -1,39 +0,0 @@ -import time -import sys -import os -import reset_lib - -no_conn_counter = 0 -consecutive_active_reports = 0 -config_hash = reset_lib.config_file_hash() - -# If auto_config is set to 0 in /etc/raspiwifi/raspiwifi.conf exit this script -if config_hash['auto_config'] == "0": - sys.exit() -else: - # Main connection monitoring loop at 10 second interval - while True: - time.sleep(10) - - # If iwconfig report no association with an AP add 10 to the "No - # Connection Couter" - if reset_lib.is_wifi_active() == False: - no_conn_counter += 10 - consecutive_active_reports = 0 - # If iwconfig report association with an AP add 1 to the - # consecutive_active_reports counter and 10 to the no_conn_counter - else: - consecutive_active_reports += 1 - no_conn_counter += 10 - # Since wpa_supplicant seems to breifly associate with an AP for - # 6-8 seconds to check the network key the below will reset the - # no_conn_counter to 0 only if two 10 second checks have come up active. - if consecutive_active_reports >= 2: - no_conn_counter = 0 - consecutive_active_reports = 0 - - # If the number of seconds not associated with an AP is greater or - # equal to the auto_config_delay specified in the /etc/raspiwifi/raspiwifi.conf - # trigger a reset into AP Host (Configuration) mode. - if no_conn_counter >= int(config_hash['auto_config_delay']): - reset_lib.reset_to_host_mode() diff --git a/libs/reset_device/manual_reset.py b/libs/reset_device/manual_reset.py deleted file mode 100644 index 9a1c5702..00000000 --- a/libs/reset_device/manual_reset.py +++ /dev/null @@ -1,3 +0,0 @@ -import reset_lib - -reset_lib.reset_to_host_mode() diff --git a/libs/reset_device/reset.py b/libs/reset_device/reset.py deleted file mode 100644 index 950db042..00000000 --- a/libs/reset_device/reset.py +++ /dev/null @@ -1,40 +0,0 @@ -import RPi.GPIO as GPIO -import os -import time -import subprocess -import reset_lib - -GPIO.setmode(GPIO.BCM) -GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) - -counter = 0 -serial_last_four = subprocess.check_output(['cat', '/proc/cpuinfo'])[-5:-1].decode('utf-8') -config_hash = reset_lib.config_file_hash() -ssid_prefix = config_hash['ssid_prefix'] + " " -reboot_required = False - - -reboot_required = reset_lib.wpa_check_activate(config_hash['wpa_enabled'], config_hash['wpa_key']) - -reboot_required = reset_lib.update_ssid(ssid_prefix, serial_last_four) - -if reboot_required == True: - os.system('reboot') - -# This is the main logic loop waiting for a button to be pressed on GPIO 18 for 10 seconds. -# If that happens the device will reset to its AP Host mode allowing for reconfiguration on a new network. -while True: - while GPIO.input(18) == 1: - time.sleep(1) - counter = counter + 1 - - print(counter) - - if counter == 9: - reset_lib.reset_to_host_mode() - - if GPIO.input(18) == 0: - counter = 0 - break - - time.sleep(1) diff --git a/libs/reset_device/reset_lib.py b/libs/reset_device/reset_lib.py deleted file mode 100644 index 73d180e5..00000000 --- a/libs/reset_device/reset_lib.py +++ /dev/null @@ -1,93 +0,0 @@ -import os -import fileinput -import subprocess - -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 wpa_check_activate(wpa_enabled, wpa_key): - wpa_active = False - reboot_required = False - - with open('/etc/hostapd/hostapd.conf') as hostapd_conf: - for line in hostapd_conf: - if 'wpa_passphrase' in line: - wpa_active = True - - if wpa_enabled == '1' and wpa_active == False: - reboot_required = True - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/hostapd.conf.wpa /etc/hostapd/hostapd.conf') - - if wpa_enabled == '1': - with fileinput.FileInput('/etc/hostapd/hostapd.conf', inplace=True) as hostapd_conf: - for line in hostapd_conf: - if 'wpa_passphrase' in line: - if 'wpa_passphrase=' + wpa_key not in line: - print('wpa_passphrase=' + wpa_key) - os.system('reboot') - else: - print(line, end = '') - else: - print(line, end = '') - - if wpa_enabled == '0' and wpa_active == True: - reboot_required = True - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/hostapd.conf.nowpa /etc/hostapd/hostapd.conf') - - return reboot_required - -def update_ssid(ssid_prefix, serial_last_four): - reboot_required = False - ssid_correct = False - - with open('/etc/hostapd/hostapd.conf') as hostapd_conf: - for line in hostapd_conf: - if ssid_prefix in line: - ssid_correct = True - - if ssid_correct == False: - with fileinput.FileInput("/etc/hostapd/hostapd.conf", inplace=True) as file: - for line in file: - if 'ssid=' in line: - line_array = line.split('=') - line_array[1] = ssid_prefix + ' ' + serial_last_four - print(line_array[0] + '=' + line_array[1]) - else: - print(line, end = '') - - reboot_required = True - - return reboot_required - -def is_wifi_active(): - iwconfig_out = subprocess.check_output(['iwconfig']).decode('utf-8') - wifi_active = True - - if "Access Point: Not-Associated" in iwconfig_out: - wifi_active = False - - return wifi_active - -def reset_to_host_mode(): - if not os.path.isfile('/etc/raspiwifi/host_mode'): - os.system('aplay /usr/lib/raspiwifi/reset_device/button_chime.wav') - os.system('rm -f /etc/wpa_supplicant/wpa_supplicant.conf') - os.system('rm -f /home/pi/Projects/RaspiWifi/tmp/*') - os.system('rm /etc/cron.raspiwifi/apclient_bootstrapper') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/aphost_bootstrapper /etc/cron.raspiwifi/') - os.system('chmod +x /etc/cron.raspiwifi/aphost_bootstrapper') - os.system('mv /etc/dhcpcd.conf /etc/dhcpcd.conf.original') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/dhcpcd.conf /etc/') - os.system('mv /etc/dnsmasq.conf /etc/dnsmasq.conf.original') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/dnsmasq.conf /etc/') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/dhcpcd.conf /etc/') - os.system('touch /etc/raspiwifi/host_mode') - os.system('reboot') diff --git a/libs/reset_device/static_files/apclient_bootstrapper b/libs/reset_device/static_files/apclient_bootstrapper deleted file mode 100644 index 51a9e98e..00000000 --- a/libs/reset_device/static_files/apclient_bootstrapper +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -python3 /usr/lib/raspiwifi/reset_device/reset.py & - -python3 /usr/lib/raspiwifi/reset_device/connection_monitor.py & diff --git a/libs/reset_device/static_files/aphost_bootstrapper b/libs/reset_device/static_files/aphost_bootstrapper deleted file mode 100644 index 6911a352..00000000 --- a/libs/reset_device/static_files/aphost_bootstrapper +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -python3 /usr/lib/raspiwifi/reset_device/reset.py & - -python3 /usr/lib/raspiwifi/configuration_app/app.py & - -hostapd -dd /etc/hostapd/hostapd.conf & diff --git a/libs/reset_device/static_files/dhcpcd.conf b/libs/reset_device/static_files/dhcpcd.conf deleted file mode 100644 index 8de17851..00000000 --- a/libs/reset_device/static_files/dhcpcd.conf +++ /dev/null @@ -1,2 +0,0 @@ -interface wlan0 -static ip_address=10.0.0.1/24 diff --git a/libs/reset_device/static_files/dnsmasq.conf b/libs/reset_device/static_files/dnsmasq.conf deleted file mode 100644 index 7ee6b803..00000000 --- a/libs/reset_device/static_files/dnsmasq.conf +++ /dev/null @@ -1,11 +0,0 @@ -interface=wlan0 -dhcp-range=10.0.0.10,10.0.0.15,12h -#dhcp-option=option:router,10.0.0.1 -#dhcp-option=option:netmask,255.255.255.0 - -# Delays sending DHCPOFFER and proxydhcp replies for at least the specified number of seconds. -dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:* -dhcp-reply-delay=tag:client_is_a_pi,2 - -address=/raspiwifisetup.com/10.0.0.1 -address=/idliketoconfigurethewifionthisdevicenowplease.com/10.0.0.1 diff --git a/libs/reset_device/static_files/hostapd.conf.nowpa b/libs/reset_device/static_files/hostapd.conf.nowpa deleted file mode 100644 index 2613e796..00000000 --- a/libs/reset_device/static_files/hostapd.conf.nowpa +++ /dev/null @@ -1,4 +0,0 @@ -interface=wlan0 -driver=nl80211 -ssid=temp-ssid -channel=1 \ No newline at end of file diff --git a/libs/reset_device/static_files/hostapd.conf.wpa b/libs/reset_device/static_files/hostapd.conf.wpa deleted file mode 100644 index 39fd1979..00000000 --- a/libs/reset_device/static_files/hostapd.conf.wpa +++ /dev/null @@ -1,9 +0,0 @@ -interface=wlan0 -driver=nl80211 -ssid=temp-ssid -channel=1 -auth_algs=1 -wpa=2 -wpa_key_mgmt=WPA-PSK -rsn_pairwise=CCMP -wpa_passphrase=0 \ No newline at end of file diff --git a/libs/reset_device/static_files/raspiwifi.conf b/libs/reset_device/static_files/raspiwifi.conf deleted file mode 100644 index 9addf6c6..00000000 --- a/libs/reset_device/static_files/raspiwifi.conf +++ /dev/null @@ -1,7 +0,0 @@ -ssid_prefix=RaspiWiFi Setup -auto_config=0 -auto_config_delay=300 -ssl_enabled=0 -server_port=80 -wpa_enabled=0 -wpa_key=0 \ No newline at end of file diff --git a/libs/reset_device/static_files/wpa_supplicant.conf.default b/libs/reset_device/static_files/wpa_supplicant.conf.default deleted file mode 100644 index 71912ec7..00000000 --- a/libs/reset_device/static_files/wpa_supplicant.conf.default +++ /dev/null @@ -1,2 +0,0 @@ -ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev -update_config=1 \ No newline at end of file diff --git a/libs/uninstall.py b/libs/uninstall.py deleted file mode 100644 index 73371eb5..00000000 --- a/libs/uninstall.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import sys - -os.system('clear') -print() -print() -print("#################################") -print("##### RaspiWiFi Uninstaller #####") -print("#################################") -print() -print() -uninstall_answer = input("Would you like to uninstall RaspiWiFi? [y/N]: ") -print() - -if (uninstall_answer.lower() == "y"): - print('Uninstalling RaspiWiFi from your system...') - - os.system('cp ' + os.path.dirname(os.path.realpath(__file__)) + '/reset_device/static_files/wpa_supplicant.conf.default /etc/wpa_supplicant/wpa_supplicant.conf') - os.system('chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf') - os.system('mv /etc/wpa_supplicant/wpa_supplicant.conf.original /etc/wpa_supplicant/wpa_supplicant.conf 2>/dev/null') - os.system('rm -rf /etc/raspiwifi') - os.system('rm -rf /usr/lib/raspiwifi') - os.system('rm -rf /etc/cron.raspiwifi') - os.system('rm /etc/dnsmasq.conf') - os.system('mv /etc/dnsmasq.conf.original /etc/dnsmasq.conf 2>/dev/null') - os.system('rm /etc/hostapd/hostapd.conf') - os.system('rm /etc/dhcpcd.conf') - os.system('mv /etc/dhcpcd.conf.original /etc/dhcpcd.conf 2>/dev/null') - os.system('sed -i \'s/# RaspiWiFi Startup//\' /etc/crontab') - os.system('sed -i \'s/@reboot root run-parts \/etc\/cron.raspiwifi\///\' /etc/crontab') - - print() - print() - reboot_answer = input('Uninstallation is complete. Would you like to reboot the system now?: ') - - if(reboot_answer.lower() == "y"): - os.system('reboot') -else: - print() - print('No changes made. Exiting unistaller...') \ No newline at end of file diff --git a/put_in_ap_mode.py b/put_in_ap_mode.py new file mode 100644 index 00000000..3f602ecb --- /dev/null +++ b/put_in_ap_mode.py @@ -0,0 +1,74 @@ +import os +import subprocess + + +def put_in_ap_mode(): + os.system("apt update") + os.system("apt upgrade -y") + os.system("apt install hostapd -y") + os.system("apt install dnsmasq -y") + os.system("systemctl stop hostapd") + os.system("systemctl stop dnsmasq") + os.system("apt install python3-pip -y") + os.system("pip3 install flask") + + serial_last_four = subprocess.check_output(["cat", "/proc/cpuinfo"])[-5:-1].decode( + "utf-8" + ) + + with open("/etc/hostapd/hostapd.conf", "w") as file: + lines = [ + "interface=wlan0", + "driver=nl80211", + f"ssid=Device {serial_last_four}", + "hw_mode=g", + "channel=6", + "wmm_enabled=0", + "macaddr_acl=0", + "ignore_broadcast_ssid=0", + ] + file.write("\n".join(lines)) + + os.system("systemctl unmask hostapd") + os.system("systemctl enable hostapd") + + if not os.path.exists("/etc/dnsmasq.conf"): + open("/etc/dnsmasq.conf", "w").close() + + if os.path.exists("/etc/dnsmasq.conf.copy"): + os.system("sudo cp /etc/dnsmasq.conf.copy /etc/dnsmasq.conf") + + os.system("cp /etc/dnsmasq.conf /etc/dnsmasq.conf.copy") + + with open("/etc/dnsmasq.conf", "a") as file: + lines = [ + "#RPiHotspot config - No Intenet", + "interface=wlan0", + "domain-needed", + "bogus-priv", + "dhcp-range=192.168.50.150,192.168.50.200,255.255.255.0,12h", + "address=/setup.com/192.168.50.10", + ] + file.write("\n".join(lines)) + + if os.path.exists("/etc/dhcpcd.conf.copy"): + os.system("sudo cp /etc/dhcpcd.conf.copy /etc/dhcpcd.conf") + + if not os.path.exists("/etc/dhcpcd.conf"): + open("/etc/dhcpcd.conf", "w").close() + + os.system("cp /etc/dhcpcd.conf /etc/dhcpcd.conf.copy") + + with open("/etc/dhcpcd.conf", "a") as file: + lines = [ + "interface wlan0", + "nohook wpa_supplicant", + "static ip_address=192.168.50.10/24", + "static routers=192.168.50.1", + ] + file.write("\n".join(lines)) + + os.system("raspi-config nonint do_wifi_country US") + os.system("rfkill unblock wifi") + + os.system("reboot") diff --git a/setup_lib.py b/setup_lib.py deleted file mode 100644 index fa6e3664..00000000 --- a/setup_lib.py +++ /dev/null @@ -1,51 +0,0 @@ -import os - -def install_prereqs(): - os.system('clear') - os.system('apt update') - os.system('clear') - os.system('apt install python3 python3-rpi.gpio python3-pip dnsmasq hostapd -y') - os.system('clear') - print("Installing Flask web server...") - print() - os.system('pip3 install flask pyopenssl') - os.system('clear') - -def copy_configs(wpa_enabled_choice): - os.system('mkdir /usr/lib/raspiwifi') - os.system('mkdir /etc/raspiwifi') - os.system('cp -a libs/* /usr/lib/raspiwifi/') - os.system('mv /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.original') - os.system('rm -f ./tmp/*') - os.system('mv /etc/dnsmasq.conf /etc/dnsmasq.conf.original') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/dnsmasq.conf /etc/') - - if wpa_enabled_choice.lower() == "y": - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/hostapd.conf.wpa /etc/hostapd/hostapd.conf') - else: - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/hostapd.conf.nowpa /etc/hostapd/hostapd.conf') - - os.system('mv /etc/dhcpcd.conf /etc/dhcpcd.conf.original') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/dhcpcd.conf /etc/') - os.system('mkdir /etc/cron.raspiwifi') - os.system('cp /usr/lib/raspiwifi/reset_device/static_files/aphost_bootstrapper /etc/cron.raspiwifi') - os.system('chmod +x /etc/cron.raspiwifi/aphost_bootstrapper') - os.system('echo "# RaspiWiFi Startup" >> /etc/crontab') - os.system('echo "@reboot root run-parts /etc/cron.raspiwifi/" >> /etc/crontab') - os.system('mv /usr/lib/raspiwifi/reset_device/static_files/raspiwifi.conf /etc/raspiwifi') - os.system('touch /etc/raspiwifi/host_mode') - -def update_main_config_file(entered_ssid, auto_config_choice, auto_config_delay, ssl_enabled_choice, server_port_choice, wpa_enabled_choice, wpa_entered_key): - if entered_ssid != "": - os.system('sed -i \'s/RaspiWiFi Setup/' + entered_ssid + '/\' /etc/raspiwifi/raspiwifi.conf') - if wpa_enabled_choice.lower() == "y": - os.system('sed -i \'s/wpa_enabled=0/wpa_enabled=1/\' /etc/raspiwifi/raspiwifi.conf') - os.system('sed -i \'s/wpa_key=0/wpa_key=' + wpa_entered_key + '/\' /etc/raspiwifi/raspiwifi.conf') - if auto_config_choice.lower() == "y": - os.system('sed -i \'s/auto_config=0/auto_config=1/\' /etc/raspiwifi/raspiwifi.conf') - if auto_config_delay != "": - os.system('sed -i \'s/auto_config_delay=300/auto_config_delay=' + auto_config_delay + '/\' /etc/raspiwifi/raspiwifi.conf') - if ssl_enabled_choice.lower() == "y": - os.system('sed -i \'s/ssl_enabled=0/ssl_enabled=1/\' /etc/raspiwifi/raspiwifi.conf') - if server_port_choice != "": - os.system('sed -i \'s/server_port=80/server_port=' + server_port_choice + '/\' /etc/raspiwifi/raspiwifi.conf')