Merge pull request #138 from noon92/working

Fix issue with PSKs not interpreting special characters correctly
This commit is contained in:
noon92 2025-01-05 00:56:07 +02:00 • committed by GitHub
commit 13fd47eccf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 133 additions and 81 deletions

View file

@ -15,8 +15,8 @@ fi
foxbuntu_version=$(grep -oP 'major=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'minor=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'patch=\K[0-9]+' /etc/foxbuntu-release)$(grep -oP 'hotfix=\K[a-z]+' /etc/foxbuntu-release)
spaces=$((11 - ${#foxbuntu_version}))
printf " For settings, run \`sudo femto-config\`\n"
printf " For settings, run \`\033[0;31msudo femto-config\033[0m\`\n"
printf " Made for Femtofox https://www.femtofox.com\n"
printf " Foxbuntu v$foxbuntu_version%*s%s(%s)\n\n" $spaces "" "$DISTRIB_DESCRIPTION" "$(uname -r)"
printf "IP address: $(hostname -I | sed 's/ / /g') Uptime:$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')\n"
printf "IP address: $(hostname -I | sed 's/ / /g') Uptime:$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')\n"

View file

@ -2,9 +2,10 @@ ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
# the first network in this file is the one edited by the various UIs and tools (USB config, femto-config, web UI, femto-network-config.sh...)
network={
ssid="home"
ssid="ssid"
psk="password"
key_mgmt=WPA-PSK
priority=100
priority=100
}

View file

@ -16,13 +16,37 @@ pause() {
read -n 1 -s -r
}
#│ ^[[0;30m Black^[[0m ^[[0;31m Red^[[0m ^[[0;32m │
#│ Green^[[0m ^[[0;33m Yellow^[[0m ^[[0;34m Blue^[[0m │
#│ ^[[0;35m Magenta^[[0m ^[[0;36m Cyan^[[0m ^[[0;37m │
#│ White^[[0m ^[[4m Underlined^[[0m ^[[7m Inverted^[[0m
replace_colors() {
input="$1"
input="${input//$(echo -e '\033[0;30m')/\\Z0}" # black
input="${input//$(echo -e '\033[0;31m')/\\Z1}" # red
input="${input//$(echo -e '\033[0;32m')/\\Z2}" # green
input="${input//$(echo -e '\033[0;33m')/\\Z3}" # yellow
input="${input//$(echo -e '\033[0;34m')/\\Z4}" # blue
input="${input//$(echo -e '\033[0;35m')/\\Z5}" # magenta
input="${input//$(echo -e '\033[0;36m')/\\Z6}" # cyan
input="${input//$(echo -e '\033[0;37m')/\\Z7}" # white
input="${input//$(echo -e '\033[7m')/\\Zr}" # invert
input="${input//$(echo -e '\033[4m')/\\Zu}" # underline
input="${input//$(echo -e '\033[0m')/\\Zn}" # reset
echo "$input"
}
wifi_config() {
local wifi_ssid=""
local wifi_psk=""
local wifi_country=""
wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi SSID:" 8 40 3>&1 1>&2 2>&3)
wifi_ssid=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi SSID:" 8 40 "$(grep -oP '^ *ssid="\K[^"]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current SSID
wifi_psk=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Wi-Fi Password:" 8 40 3>&1 1>&2 2>&3)
wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (e.g., US, DE) - optional:" 9 40 3>&1 1>&2 2>&3)
wifi_country=$(dialog --title "$title2" --cancel-label "Skip" --inputbox "Enter Country Code (US, DE...):" 9 40 "$(grep -oP '^ *country=\K[^ ]+' /etc/wpa_supplicant/wpa_supplicant.conf)" 3>&1 1>&2 2>&3) # display current country
cmd="femto-network-config.sh -s \"$wifi_ssid\" -p \"$wifi_psk\""
[ -n "$wifi_country" ] && cmd="$cmd -c \"$wifi_country\""
cmd="$cmd -r"
@ -31,7 +55,10 @@ wifi_config() {
return
fi
eval $cmd
dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: $wifi_psk\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 40
dialog --title "$title2" --msgbox "Wi-Fi Settings Saved:\nSSID: $wifi_ssid\nPassword: (hidden)\nCountry: $wifi_country\nMeshtastic Wi-Fi setting set to ON" 9 40
if [ "$1" = "-w" ]; then
exit 0
fi
}
# Function to handle Wi-Fi settings
@ -41,14 +68,15 @@ networking_settings() {
wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
while true; do
local option=""
option=$(dialog --menu "$title" 15 40 4 \
1 "View Wi-Fi settings" \
2 "Change Wi-Fi settings" \
3 "Restart Wi-Fi" \
option=$(dialog --cancel-label "Back" --menu "$title" 15 40 4 \
1 "Turn Wi-Fi on/off" \
2 "View Wi-Fi settings" \
3 "Change Wi-Fi settings" \
4 "View ethernet settings" \
5 "Set hostname" \
6 "Test internet connection" \
7 "Back to Main Menu" 3>&1 1>&2 2>&3)
5 "Restart networking" \
6 "Set hostname" \
7 "Test internet connection" \
8 "Back to Main Menu" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
@ -56,35 +84,55 @@ networking_settings() {
fi
case $option in
1)
echo "Getting Wi-Fi configuration..."
dialog --title "$title2" --msgbox "$(femto-network-config.sh -w)" 0 0
1) # Turn Wi-Fi on/off)
if ! ip link show wlan0 &>/dev/null; then
dialog --colors --msgbox "\Z1Network adapter wlan0 does not exist.\Zn\n\nIs a wifi adapter connected?" 8 40
else
while true; do
choice=$(dialog --cancel-label "Back" --title "Wi-Fi Status" --menu "Enable/disable Wi-Fi" 9 40 5 \
1 "Turn Wi-Fi on" \
2 "Turn Wi-Fi off" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
1) femto-network-config.sh -x "up" && break ;;
2) femto-network-config.sh -x "down" && break ;;
*) dialog --msgbox "Invalid choice, please try again." 8 40 ;;
esac
done
fi
;;
2)
2) # View Wi-Fi settings)
echo "Getting Wi-Fi configuration..."
dialog --title "$title2" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -w)")" 0 0
;;
3) # Change Wi-Fi settings)
wifi_config
;;
3)
dialog --title "$title2" --yesno "Wi-Fi and Ethernet will be restarted.\nMeshtastic Wi-Fi setting will be set to ON." 7 50
4) # View ethernet settings)
echo "Getting ethernet configuration..."
dialog --title "Ethernet (eth0) settings" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -e)")" 0 0
;;
5) # Restart networking)
dialog --title "$title2" --yesno "Wi-Fi and Ethernet will be restarted.\nMeshtastic Wi-Fi setting will be set to ON.\n\nProceed?" 8 40
if [ $? -eq 0 ]; then #unless cancel/no
femto-network-config.sh -r
fi
;;
4)
echo "Getting ethernet configuration..."
dialog --title "Ethernet (eth0) settings" --msgbox "$(femto-network-config.sh -e)" 0 0
;;
5) # set hostname)
6) # set hostname)
new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter new hostname:" 8 40 $(hostname) 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then #unless cancel/no
femto-network-config.sh -n "$new_hostname"
dialog --title "$title" --msgbox "Femtofox is now reachable at\n$new_hostname.local" 8 40
fi
;;
6)
7) # Test internet connection)
echo "Testing internet connection..."
dialog --title "Ethernet (eth0) settings" --msgbox "$(femto-network-config.sh -t)" 8 40
dialog --title "Internet connectivity test" --colors --msgbox "$(replace_colors "$(femto-network-config.sh -t)")" 8 40
;;
7)
8)
return
;;
esac
@ -95,7 +143,7 @@ networking_settings() {
femto_pinouts() {
while true; do
local option=""
option=$(dialog --menu "Pinouts" 15 40 5 \
option=$(dialog --cancel-label "Back" --menu "Pinouts" 15 40 5 \
1 "Femtofox" \
2 "Femtofox Zero" \
3 "Femtofox Tiny" \
@ -124,7 +172,7 @@ misc_settings() {
local title="Misc Settings"
while true; do
local option=""
option=$(dialog --menu "Misc Settings" 15 40 4 \
option=$(dialog --cancel-label "Back" --menu "Misc Settings" 15 40 4 \
1 "Set system timezone" \
2 "Ham radio support" \
3 "Re-run first-boot script" \
@ -176,18 +224,13 @@ TEF6862 Car Radio Enhanced Selectivity Tuner\n\
Texas Instruments WL1273 I2C FM Radio\n\
Renesas Digital Radio Interface (DRIF)" 20 65
dialog --title "$title" --msgbox "To add support, kernel modules for all these will be copied to \`/lib/modules/5.10.160/\`,\
then \`depmod\` will be run. To remove support, those modules will be deleted.\n\nAfter installation, many redundant network interfaces will appear." 11 50
then \`depmod\` will be run. To remove support, those modules will be deleted.\n\nAfter installation, many redundant network interfaces will appear." 11 40
#add code to choose add or remove
cp /oem/usr/ko/ham/* /lib/modules/5.10.160/
depmod -a 5.10.160
;;
3)
dialog --title "$title" --yesno "Rerunning the first-boot script will add support for RTC (real time clock), \
set the eth0 MAC address and Meshtastic nodeID to a derivative of the CPU serial number and enable Wi-Fi in Meshtastic settings. \
Rerunning the script will not cause any issues if these things are already in place. Femtofox will reboot after execution.\n\nConfirm?" 12 60
if [ $? -eq 0 ]; then #unless cancel/no
runonce.sh
fi
femto-runonce.sh
;;
4)
luckfox-config
@ -273,7 +316,7 @@ meshtasticd_settings() {
local title="Meshtasticd Settings"
while true; do
local option=""
option=$(dialog --menu "$title" 22 50 4 \
option=$(dialog --cancel-label "Back" --menu "$title" 22 50 4 \
1 "View current configuration URL & QR code" \
2 "Set new configuration URL" \
3 "View current lora radio selection" \
@ -301,7 +344,7 @@ meshtasticd_settings() {
pause
;;
2)
newurl=$(dialog --title "Meshtastic URL" --cancel-label "Skip" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3)
newurl=$(dialog --title "Meshtastic URL" --cancel-label "Skip" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 40 3>&1 1>&2 2>&3)
if [ -n "$newurl" ]; then #if a URL was entered
dialog --title "$title" --yesno "New Meshtasticd URL:\n$newurl\n\nConfirm?" 15 60
if [ $? -eq 0 ]; then #unless cancel/no
@ -321,7 +364,7 @@ meshtasticd_settings() {
dialog --title "Admin keys" --msgbox "Up to 3 admin keys are permitted, more will be ignored.\n\nKeys:$(femto-meshtasticd-config.sh -v | tail -n 1 | sed 's/|n/\\n/g')" 0 0
;;
6) #set admin key)
key=$(dialog --title "Meshtastic Admin Key" --cancel-label "Skip" --inputbox "Meshtastic admin key - up to 3, more will be ignored.\n\n(SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3)
key=$(dialog --title "Meshtastic Admin Key" --cancel-label "Skip" --inputbox "Meshtastic admin key - up to 3, more will be ignored.\n\n(SHIFT+INS to paste):" 8 40 3>&1 1>&2 2>&3)
if [ -n "$key" ]; then #if a URL was entered
femto-meshtasticd-config.sh -a "$key"
pause
@ -376,7 +419,7 @@ meshtasticd_settings() {
dialog --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed." 0 0
if [ $? -eq 0 ]; then
femto-meshtasticd-config.sh -x
dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run \`sudo runonce.sh\`." 8 40
dialog --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 40
fi
;;
15)
@ -391,7 +434,7 @@ software_settings() {
while true; do
local title="Software"
local option=""
option=$(dialog --menu "$title" 0 0 6 \
option=$(dialog --cancel-label "Back" --menu "$title" 0 0 6 \
1 "Meshing Around by SpudGudMan" \
2 "The Comms Channel BBS (TC2BBS)" \
"" ""\
@ -435,7 +478,7 @@ help_menu() {
while true; do
local title="Help / About"
local option=""
option=$(dialog --menu "$title" 0 0 6 \
option=$(dialog --cancel-label "Back" --menu "$title" 0 0 6 \
1 "About Femtofox" \
2 "Display pinout" \
3 "Femtofox licensing info - short" \
@ -492,14 +535,12 @@ while getopts ":lw" opt; do
;;
esac
done
if [ -n "$1" ]; then
exit
fi
# Main menu
while true; do
choice=$(dialog --title "$(date)" --menu "Femtofox Config" 15 40 5 \
choice=$(dialog --title "$(date)" --cancel-label "Exit" --menu "Femtofox Config" 15 40 5 \
1 "Settings wizard" \
2 "Networking" \
3 "Meshtasticd" \

View file

@ -8,6 +8,7 @@ wpa_supplicant_conf="/etc/wpa_supplicant/wpa_supplicant.conf"
help=$(cat <<EOF
Options are:
-h This message
-x "up" Set wifi status (options are "up" or "down")
-s "SSID" Set Wi-Fi SSID
-p "PSK" Set Wi-Fi PSK (password)
-c "COUNTRY" Set Wi-Fi 2-letter country code (such as US, DE)
@ -35,19 +36,26 @@ if [ $# -eq 0 ]; then
fi
# Parse options
while getopts ":hs:p:c:ewn:tr" opt; do
while getopts ":hx:s:p:c:ewn:tr" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
s) # Option -s (ssid)
x) # Option -x (set wifi status)
if [ $OPTARG = "up" ]; then
ip link set wlan0 up
elif [ $OPTARG = "down" ]; then
ip link set wlan0 down
fi
;;
s) # Option -s (ssid)
sed -i "/ssid=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf"
echo "Setting SSID to $OPTARG."
updated_wifi="true"
;;
p) # Option -p (psk)
sed -i "/psk=/s/\".*\"/\"$OPTARG\"/" "$wpa_supplicant_conf"
echo "Setting PSK to $OPTARG."
sed -i "/psk=/s/\".*\"/\"$(echo "$OPTARG" | sed 's/&/\\&/g')\"/" "$wpa_supplicant_conf"
echo "Setting PSK to (hidden)."
updated_wifi="true"
;;
c) # Option -c (country)
@ -56,32 +64,40 @@ while getopts ":hs:p:c:ewn:tr" opt; do
updated_wifi="true"
;;
e) # Option -e (ethernet settings)
echo "Hostname: $(hostname).local\n\
IPv4 Address: $(ifconfig eth0 | grep 'inet ' | awk '{print $2}')\n
IPv6 Address: $(ifconfig eth0 | grep 'inet6 ' | awk '{print $2}')\n\
MAC Address: $(ifconfig eth0 | grep 'ether ' | awk '{print $2}')\n\
"
status=$(ip link show eth0 | grep -o 'state [A-Za-z]*' | awk '{print $2}')
echo -e "Ethernet status: $([ "$status" == "UP" ] && echo -e "\033[4m\033[0;32mconnected\033[0m" || echo -e "\033[0;31mdisconnected\033[0m")"
if [ "$status" == "UP" ]; then
echo "\nIPv4 Address: $(ifconfig eth0 | grep 'inet ' | awk '{print $2}')\n\
IPv6 Address: $(ifconfig eth0 | grep 'inet6 ' | awk '{print $2}')"
fi
echo "\nMAC Address: $(ifconfig eth0 | grep 'ether ' | awk '{print $2}')\n\
Hostname: $(hostname).local"
;;
w) # Option -w (wifi settings)
wifi_country=$(grep -m 1 "^country=" "$wpa_supplicant_conf" | cut -d '=' -f 2)
wifi_ssid=$(grep -m 1 '^\s*ssid=' "$wpa_supplicant_conf" | cut -d '"' -f 2)
wifi_psk=$(grep -m 1 '^\s*psk=' "$wpa_supplicant_conf" | cut -d '"' -f 2)
if [ "$(cat /root/.portduino/default/prefs/config.proto | protoc --decode_raw | awk '/4 {/, /}/ {if ($1 == "1:") print $2}')" -eq 1 ]; then
mesh_wifi_status="enabled"
if [ "$(cat /etc/wifi_state.txt)" = "up" ]; then
wifi_status="\033[4m\033[0;32menabled\033[0m"
else
mesh_wifi_status="disabled"
if ip link show wlan0 &>/dev/null; then # if wlan0 exists
wifi_status="\033[0;31mdisabled\033[0m"
mac_address_line="MAC address: $(ifconfig wlan0 | grep ether | awk '{print $2}')\n\n"
else
wifi_status="\033[0;31mwlan0 not detected\033[0m"
fi
fi
echo "\
SSID: $wifi_ssid\n\
Password: $wifi_psk\n\
Country: $wifi_country\n\
Meshtastic Wi-Fi: $mesh_wifi_status\n\
echo -e "\
$(echo -e "\
SSID: $(grep -m 1 '^\s*ssid=' "$wpa_supplicant_conf" | cut -d '"' -f 2)\n\
Password: (hidden)\n\
Country: $(grep -m 1 "^country=" "$wpa_supplicant_conf" | cut -d '=' -f 2)\n\
WiFi status: $wifi_status\
\n\
Connected to: $(iwconfig 2>/dev/null | grep -i 'ESSID' | awk -F 'ESSID:"' '{print $2}' | awk -F '"' '{print $1}')\n\
$(if [[ "$wifi_status" == *"enabled"* ]]; then
echo -e "\nConnected to: $(iwconfig 2>/dev/null | grep -i 'ESSID' | awk -F 'ESSID:\"' '{print $2}' | awk -F '\"' '{print $1}')\n\
Signal Strength: $(iwconfig 2>/dev/null | grep -i 'Signal level' | awk -F 'Signal level=' '{print $2}' | awk '{print $1}')\n\
MAC address: $(ifconfig wlan0 | grep ether | awk '{print $2}')\n\
Current IP: $(hostname -I | awk '{print $1}')\n\
Current IP: $(hostname -I | awk '{print $1}')\n"
fi)")\n\
Hostname: $(hostname).local\n\
$mac_address_line
For more details, enter \`iwconfig\`."
;;
t) # Option -t (test internet connection)
@ -92,15 +108,15 @@ For more details, enter \`iwconfig\`."
total=0
# Ping each target 5 times and count successful pings
for target in "${targets[@]}"; do
count=$(ping -c 5 -W 1 "$target" | grep -c 'bytes from') # Count lines with successful pings
count=$(ping -c 5 -W 1 "$target" | grep -c 'time') # Count lines with successful pings
successful=$((successful + count))
((total+=5))
done
# Use dialog to display message based on successful pings count
if [ "$successful" -eq 0 ]; then
echo "No internet connection detected."
echo -e "\033[0;31mNo internet connection detected.\033[0m"
else
echo "Internet connection is up.\n\nPinged $(echo "${targets[*]}" | sed 's/ /, /g').\nReceived $successful/$total responses."
echo -e "Internet connection is \033[4m\033[0;32mup\033[0m.\n\nPinged $(echo "${targets[*]}" | sed 's/ /, /g').\nReceived $successful/$total responses."
fi
;;
r) # Option -r (restart Wi-Fi)
@ -125,16 +141,10 @@ For more details, enter \`iwconfig\`."
done
if [ "$updated_wifi" = true ]; then
ip link set wlan0 up
systemctl restart wpa_supplicant
wpa_cli -i wlan0 reconfigure # <-------- add watch for FAIL response, error out
timeout 30s dhclient -v
echo " Wi-Fi restarted. Enabling Meshtastic Wi-Fi setting."
femto-meshtasticd-config.sh -m "--set network.wifi_enabled true" 10 "USB config" #| tee -a /tmp/femtofox-config.log
# if [ $? -eq 1 ]; then
# echo "Update of Meshtastic FAILED."
# exit 1
# else
# echo "Updated Meshtastic successfully."
# exit 0
# fi
echo " Wi-Fi enabled and restarted. Enabling Meshtastic Wi-Fi setting."
#femto-meshtasticd-config.sh -m "--set network.wifi_enabled true" 10 "USB config" #| tee -a /tmp/femtofox-config.log
fi