When you are in a public space like a train station, there exist several wifi access points with the same name. In the moment, sxmo shows all of them to add a wpa network. It would be enough to show it once.
Also, we do not know if a network is open or closed, which is annoying on public places.
Following modification of sxmo_networks.sh hides duplicated wifi ssid's and shows the security:
addnetworkwpamenu() {
SSID="$(cat <<EOF | sxmo_dmenu.sh -p "SSID"
$icon_cls Close Menu
$(nmcli -f SSID,SECURITY dev wifi | tail -n +2 | awk '!seen[$0]++' | sed '/^--/d' )
EOF
)"
[ -z "$SSID" ] && return
echo "$SSID" | grep -q "Close Menu" && return
PASSPHRASE="$(cat <<EOF | sxmo_dmenu.sh -p "Passphrase"
$icon_cls Close Menu
None
EOF
)"
if [ -z "$PASSPHRASE" ] || [ "None" = "$PASSPHRASE" ]; then
unset PASSPHRASE
fi
echo "$PASSPHRASE" | grep -q "Close Menu" && return
notify_sucess "Adding connection" \
nmcli c add type wifi ifname wlan0 con-name "${SSID%% *}" ssid "${SSID%% *}" \
${PASSPHRASE:+802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$PASSPHRASE"}
}
That's seems good changes! Can you send a patch to apply this?
i am currently on the street testing this
and there is the issue that the security value only show up as expected when i am already connected to a wifi
when the ssids are too long, the security does not show in bmenu... depending on a scaling, no big deal.
i do not send a patch, the last few times i messed it up with git-mail.. feel free to add it to the code.
i think there is now an issue that when you want to add a WPA network with a white space in the name, it will only take the first part of the name... to be fixed soon
now it does what it should, also with wifis having white spaces or emojis in its name starting on line 145 in sxmo-utils/scripts/core/sxmo_networks.sh
addnetworkwpamenu() { SSID="$(cat <<EOF | sxmo_dmenu.sh -p "SSID" $icon_cls Close Menu $(nmcli -f SSID,SECURITY dev wifi | tail -n +2 | awk '!seen[$0]++' | sed '/^--/d' ) EOF )" [ -z "$SSID" ] && return echo "$SSID" | grep -q "Close Menu" && return PASSPHRASE="$(cat <<EOF | sxmo_dmenu.sh -p "Passphrase" $icon_cls Close Menu None EOF )" if [ -z "$PASSPHRASE" ] || [ "None" = "$PASSPHRASE" ]; then unset PASSPHRASE fi echo "$PASSPHRASE" | grep -q "Close Menu" && return # NAMES splits $SSID name from Security, even if there are whitespaces NAMES=$(echo "$SSID" | awk -F ' ' '{ $NF=""; print $0 }' | sed 's/[[:space:]]*$//') notify_sucess "Adding connection" \ nmcli c add type wifi ifname wlan0 con-name "$NAMES" ssid "$NAMES" \ ${PASSPHRASE:+802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$PASSPHRASE"} }
#Fix and Patch
Following modification of sxmo_networks.sh hides duplicated wifi ssid's and shows the security, if you select to connect to a wifi without security, it will not ask you for a password anymore.
here is the patch:
--- sxmo_networks.sh.original 2024-05-20 11:42:12.557487928 -0300 +++ sxmo_networks.sh.patch 2024-09-13 23:41:42.277220175 -0300 @@ -143,30 +143,39 @@ } addnetworkwpamenu() { - SSID="$(cat <<EOF | sxmo_dmenu.sh -p "SSID" + SSID="$(cat <<EOF | sxmo_dmenu.sh -p "SSID" $icon_cls Close Menu -$(nmcli d wifi list | tail -n +2 | grep -v '^\*' | awk -F' ' '{ print $6 }' | grep -v '\-\-') +$(nmcli -f SSID,SECURITY dev wifi | tail -n +2 | awk '!seen[$0]++' | sed '/^--/d') EOF - )" - [ -z "$SSID" ] && return - echo "$SSID" | grep -q "Close Menu" && return + )" + [ -z "$SSID" ] && return + echo "$SSID" | grep -q "Close Menu" && return - PASSPHRASE="$(cat <<EOF | sxmo_dmenu.sh -p "Passphrase" + SECURITY_TYPE="$(echo "$SSID" | awk '{print $NF}')" + + # If security type is '--', skip passphrase input + if [ "$SECURITY_TYPE" != "--" ]; then + PASSPHRASE="$(cat <<EOF | sxmo_dmenu.sh -p "Passphrase" $icon_cls Close Menu None EOF - )" + )" + + if [ -z "$PASSPHRASE" ] || [ "None" = "$PASSPHRASE" ]; then + unset PASSPHRASE + fi + echo "$PASSPHRASE" | grep -q "Close Menu" && return + fi - if [ -z "$PASSPHRASE" ] || [ "None" = "$PASSPHRASE" ]; then - unset PASSPHRASE - fi - echo "$PASSPHRASE" | grep -q "Close Menu" && return - - notify_sucess "Adding connection" \ - nmcli c add type wifi ifname wlan0 con-name "$SSID" ssid "$SSID" \ - ${PASSPHRASE:+802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$PASSPHRASE"} + # splits $SSID name from Security + NAMES=$(echo "$SSID" | awk -F ' ' '{ $NF=""; print $0 }' | sed 's/[[:space:]]*$//') + + notify_sucess "Adding connection" \ + nmcli c add type wifi ifname wlan0 con-name "$NAMES" ssid "$NAMES" \ + ${PASSPHRASE:+802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$PASSPHRASE"} } + addhotspotusbmenu() { CONNNAME="$( echo "$icon_cls Close Menu" |
If you tell me how to send the patch without git send-email i am happy to send it, otherwise i am sure you now how to apply.
and here the code for copy-pasta:
addnetworkwpamenu() { SSID="$(cat <<EOF | sxmo_dmenu.sh -p "SSID" $icon_cls Close Menu $(nmcli -f SSID,SECURITY dev wifi | tail -n +2 | awk '!seen[$0]++' | sed '/^--/d') EOF )" [ -z "$SSID" ] && return echo "$SSID" | grep -q "Close Menu" && return SECURITY_TYPE="$(echo "$SSID" | awk '{print $NF}')" # If security type is '--', skip passphrase input if [ "$SECURITY_TYPE" != "--" ]; then PASSPHRASE="$(cat <<EOF | sxmo_dmenu.sh -p "Passphrase" $icon_cls Close Menu None EOF )" if [ -z "$PASSPHRASE" ] || [ "None" = "$PASSPHRASE" ]; then unset PASSPHRASE fi echo "$PASSPHRASE" | grep -q "Close Menu" && return fi # splits $SSID name from Security NAMES=$(echo "$SSID" | awk -F ' ' '{ $NF=""; print $0 }' | sed 's/[[:space:]]*$//') notify_sucess "Adding connection" \ nmcli c add type wifi ifname wlan0 con-name "$NAMES" ssid "$NAMES" \ ${PASSPHRASE:+802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$PASSPHRASE"} }
Thanks, sorry it took a while. This looks good to me. I sent the patch to the mailing list for a last round of scrutiny, hopefully we can merge it quickly then: https://lists.sr.ht/~mil/sxmo-devel/patches/55861
On 2024-11-07 18:33, ~proycon wrote:
Thanks, sorry it took a while. This looks good to me. I sent the patch to the mailing list for a last round of scrutiny, hopefully we can merge it quickly then: https://lists.sr.ht/~mil/sxmo-devel/patches/55861
Thanks for your replay. there is one bug in this patch! when there exists a WEP secured wifi, it will not be able to connect. the correct and tested line to fix all the trouble is:
NAMES=$(echo "$SSID" | awk -F ' ' '{ $NF=""; print $0 }' | sed 's/[[:space:]]*$//' | sed 's/ WPA\w//g')
On Sun Nov 10, 2024 at 5:36 AM CET, ~magdesign wrote:
Thanks for your replay. there is one bug in this patch! when there exists a WEP secured wifi, it will not be able to connect. the correct and tested line to fix all the trouble is:
NAMES=$(echo "$SSID" | awk -F ' ' '{ $NF=""; print $0 }' | sed 's/[[:space:]]*$//' | sed 's/ WPA\w//g')
Thanks, I sent a v2 patch with this fix included: https://lists.sr.ht/~mil/sxmo-devel/patches/55964
the tab character you use to separate the SSID and security info is rendered as tofu (replacement "box" character) by dmenu, i guess this was only tested on wayland?
you can easily verify this:
$ echo -e 'x\tx' | dmenu