diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2012-06-21 12:08:44 +0200 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2012-06-21 12:08:44 +0200 |
commit | 5e6d2bab4138c2be491488e574baf17e32f8679c (patch) | |
tree | 796c3b7710dd4475008997aabcc7f70f07d20208 | |
parent | 6140564a3463e949ba1f00b03a45ba94802353f6 (diff) | |
download | netctl-5e6d2bab4138c2be491488e574baf17e32f8679c.tar.gz netctl-5e6d2bab4138c2be491488e574baf17e32f8679c.tar.xz |
Support weird characters in wifi-menu (FS#30342)
This adds support for weird characters in ESSIDs and passwords.
-rwxr-xr-x | scripts/wifi-menu | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/scripts/wifi-menu b/scripts/wifi-menu index 1f0e423..e182f25 100755 --- a/scripts/wifi-menu +++ b/scripts/wifi-menu @@ -30,7 +30,7 @@ END init_profiles() { local i=0 essid profile - for profile in $(list_profiles); do + while read profile; do essid=$( unset INTERFACE ESSID . "$PROFILE_DIR/$profile" &> /dev/null @@ -54,7 +54,7 @@ init_profiles() (( ++i )) ;; esac - done + done < <(list_profiles) } # Builds ENTRIES as an argument list for dialog based on scan results in $1. @@ -102,9 +102,9 @@ ssid_to_profile() # Creates a profile for ssid $1. create_profile() { - local flags key msg security + local box flags key msg security PROFILE="$INTERFACE-$1" - [[ -f "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu" + [[ -e "$PROFILE_DIR/$PROFILE" ]] && PROFILE+=".wifi-menu" flags=$(grep -m 1 $'\t'"$1\$" "$NETWORKS" | cut -f 2) if [[ "$flags" =~ WPA|WEP ]]; then security=${BASH_REMATCH[0],,} @@ -112,25 +112,23 @@ create_profile() security=none fi if [[ "$flags" =~ PSK|WEP ]]; then + [[ "$OBSCURE" ]] && box="--insecure --passwordbox" || box="--inputbox" msg="Enter $security security key for\n'$1'" + key=$(dialog $box "$msg" 10 40 --stdout) || return $? + [[ "${#KEY}" -ge 8 && "${#KEY}" -le 63 ]] || return 4 if [[ "$OBSCURE" ]]; then - key=$(wpa_passphrase "$1" "$(dialog --insecure --passwordbox \ - "$msg" 10 40 --stdout)" \ - | grep "^[[:space:]]*psk=") - RETURN=$? + key=$(wpa_passphrase "$1" "$key" | grep -m 1 "^[[:space:]]*psk=") key="KEY=${key#*psk=}" else - key="KEY='$(dialog --inputbox "$msg" 10 40 --stdout)'" - RETURN=$? + key="KEY=$(printf "%q" "$key")" fi - (( RETURN == 0 )) || return $RETURN fi - cat << EOF > "$PROFILE_DIR/$PROFILE" || return 4 + cat << EOF > "$PROFILE_DIR/$PROFILE" CONNECTION='wireless' DESCRIPTION='Automatically generated profile by wifi-menu' INTERFACE='$INTERFACE' SECURITY='$security' -ESSID='$1' +ESSID=$(printf "%q" "$1") IP='dhcp' $key EOF @@ -212,11 +210,11 @@ if ! interface_is_up "$INTERFACE"; then SPAWNED_INTERFACE=1 fi +init_profiles "$INTERFACE" report_try "Scanning for networks" CONNECTION=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status 2> /dev/null \ - | grep "^ssid=") + | grep -m 1 "^ssid=") CONNECTION=${CONNECTION#ssid=} -init_profiles "$INTERFACE" NETWORKS=$(wpa_supplicant_scan_info "$INTERFACE" 3,4,5) [[ $? -eq 0 ]] && init_entries "$NETWORKS" if [[ ${#ENTRIES[@]} -eq 0 ]]; then @@ -247,8 +245,9 @@ case $RETURN in 3) # No networks found report_err "No networks found" ;; - 4) # Unable to create profile - report_err "Could not create a profile for '$CHOICE'" + 4) # Invalid passphrase length (WEP keys have tighter restrictions) + clear + report_err "Passphrase must be 8..63 characters" ;; 255) # ESC or error clear |