From a165f6847eca7ea49d3bc55aa09c41d264098308 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Tue, 28 Jan 2020 10:03:23 -0800 Subject: [PATCH] Wifi config error handling --- CHANGELOG.md | 2 ++ scripts/config-wifi | 8 +++++--- src/js/admin-network-view.js | 30 +++++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9005d..d524497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Buildbotics CNC Controller Firmware Changelog ## v0.4.13 - Support for OMRON MX2 VFD. + - Better error handling in WiFi configuration. + - Fix open WiFi access. ## v0.4.12 - Segments straddle arc in linearization. diff --git a/scripts/config-wifi b/scripts/config-wifi index d6be64f..018c676 100755 --- a/scripts/config-wifi +++ b/scripts/config-wifi @@ -53,8 +53,9 @@ function configure_wlan0() { echo " wpa-pairwise CCMP TKIP" echo " wpa-group CCMP TKIP" echo " wpa-ssid \"$SSID\"" + if [ ${#PASS} -ne 0 ]; then - echo " wpa-psk \"$PASS\"" + echo " wpa-psk \"$PASS\"" fi } @@ -230,9 +231,11 @@ else exit 1 fi - if [ ${#PASS} -lt 8 -o 128 -lt ${#PASS} ]; then + if [ ${#PASS} -ne 0 ]; then + if [ ${#PASS} -lt 8 -o 128 -lt ${#PASS} ]; then echo "Invalid passsword" exit 1 + fi fi echo "$CHANNEL" | grep '^[0-9]\{1,2\}' > /dev/null @@ -241,7 +244,6 @@ else exit 1 fi - # Execute if $AP; then echo "Configuring Wifi access point" diff --git a/src/js/admin-network-view.js b/src/js/admin-network-view.js index 4268d35..1dae7b2 100644 --- a/src/js/admin-network-view.js +++ b/src/js/admin-network-view.js @@ -116,12 +116,12 @@ module.exports = { set_password: function () { if (this.password != this.password2) { - api.alert('Passwords to not match'); + alert('Passwords to not match'); return; } if (this.password.length < 6) { - api.alert('Password too short'); + alert('Password too short'); return; } @@ -139,13 +139,33 @@ module.exports = { config_wifi: function () { this.wifiConfirm = false; + if (!this.wifi_ssid.length) { + alert('SSID not set'); + return; + } + + if (32 < this.wifi_ssid.length) { + alert('SSID longer than 32 characters'); + return; + } + + if (this.wifi_pass.length && this.wifi_pass.length < 8) { + alert('WiFi password shorter than 8 characters'); + return; + } + + if (128 < this.wifi_pass.length) { + alert('WiFi password longer than 128 characters'); + return; + } + this.rebooting = true; var config = { - mode: this.wifi_mode, + mode: this.wifi_mode, channel: this.wifi_ch, - ssid: this.wifi_ssid, - pass: this.wifi_pass + ssid: this.wifi_ssid, + pass: this.wifi_pass } api.put('wifi', config).fail(function (error) { -- 2.27.0