You are not logged in.
Pages: 1
Topic closed
Hello
Rather than having to use wifi-menu every time i want to connect to the wifi I would like to add a pipe menu to openboxs right click menu. I have googled it but can only find pipe menus using netcfg. can the netcfg pipe menu be modified to use netctl?
Thanks
Offline
Yes, it's possible. Write a script in the language of your choice that generates the proper XML to provide the things you would like as menu items. Then you have to edit your menu.xml file to have it run your script.
What items would you like to appear in your menu?
Offline
Hi, thanks for the reply
It doesn't need to be fancy, just need it to display the network name and signal strength, plus it needs to connect to the network which is clicked on.
Offline
I don't have netctl installed as I have only a single wired ethernet network connection. How would you get the signal strength by using netctl, by doing a 'netctl status <profile>'? If so, could you post the output of such a command?
Also, post an example output by doing a 'netctl list'.
I looked at https://github.com/joukewitteveen/netct … tctl.1.txt, which talks about profiles which are "active". Do you know if this means if the given profile has been "started", or instead if it has been only "enabled"?
Offline
Should work in theory (emphasis on the "should" ):
#!/bin/bash
#
# based on https://github.com/pbrisbin/wifi-pipe
#
net='/ESSID/ { id=substr($2,2,length($2)-2) }
/^ *Quality/ { split($1,q,"[=/]") }
/^ *Enc.*:on/ { sec="wep" }
/^ *IE.*WPA/ { sec="wpa" }
/^ *Auth.*802/ { sec="ent" }
/^ *Mode/ { mode=$2 }
/^ *Cell|^$/ { if(id) print q[2]/q[3]*100"="id"="sec"="mode; sec="none" }'
err() {
echo "<openbox_pipe_menu>
<item label=\"$*\" />
</openbox_pipe_menu>"
exit
}
z() { zenity --$1 --title="$id" --text="$2" $3; }
check() {
if [[ $(wpa_cli -i "$iface" ping 2>/dev/null) = "PONG" ]]; then
is_up=1
else
ip link set $iface up || err "$iface unavailable"
while ! ip link show "$iface" | grep -q UP; do sleep 0.25; done
fi
}
menu() {
check
n=$(iwlist $iface scan | awk -F: "$net" | sort -t= -ruk2 | sort -rn)
(( is_up )) || ip link set $iface down
[[ $n ]] || err "no networks found"
echo "<openbox_pipe_menu>"
while IFS='=' read qual id sec mode; do echo "\
<item label=\"$id ($sec) ${qual%.*}%\">
<action name=\"Execute\">
<command>sudo $0 $iface connect \"$id\" $sec $mode</command>
</action>
</item>"
done <<< "$n"
echo "</openbox_pipe_menu>"
}
create_pfile() {
pfile=$PDIR/$id
case $sec in
ent)
u=$(z entry Username) || exit
p=$(z entry Password --hide-text) || exit
sec=wpa-configsection
key="WPAConfigSection=(
'ssid=\"$id\"'
'key_mgmt=WPA-EAP'
'eap=PEAP'
'phase2=\"auth=MSCHAPV2\"'
'identity=\"$u\"'
'password=\"$p\"')";;
wep|wpa)
key="Key='$(z entry "Enter $sec key" --hide-text)'" || exit;;
esac
cat > "$pfile" << EOF
Connection=wireless
Interface=$iface
IP=dhcp
ESSID="$id"
Security=$sec
$key
EOF
[[ $mode = Ad-Hoc ]] && printf "WPADriver=wext\nAdHoc=1\n" >> "$pfile"
chmod 600 "$pfile"
}
connect() {
id=$3 sec=$4 mode=$5 pfile=$(grep -rEl "ESSID=[\"']?$id" $PDIR | head -1)
[[ $pfile ]] || create_pfile
netctl switch-to "${pfile##*/}" |
z progress Connecting... "--pulsate --no-cancel --auto-close"
if (( PIPESTATUS )); then
z question "Connection failed\n\nKeep $pfile?" \
"--ok-label=Keep --cancel-label=Remove" || rm "$pfile"
else
z info "Connection established"
fi
}
PDIR=/etc/netctl
iface=$1
[[ $2 = connect ]] && connect "$@" || menu
Requires wireless_tools for scanning and an entry in sudoers so that you can run the script without password. Then create an openbox pipe menu entry that runs "sudo /path/to/wifi-pipe interface"
Last edited by Gusar (2013-11-11 21:34:40)
Offline
How would you get the signal strength by using netctl, by doing a 'netctl status <profile>'? If so, could you post the output of such a command?
I have no idea how to get the signal strength by using netctl. If I run netctl status <profile> I get the below:
netctl@wlp2s0\x2dVFI_GUEST.service - Networking for netctl profile wlp2s0-VFI_GUEST
Loaded: loaded (/usr/lib/systemd/system/netctl@.service; static)
Active: active (exited) since Fri 2013-11-01 16:55:24 GMT; 8min ago
Docs: man:netctl.profile(5)
Process: 544 ExecStart=/usr/lib/network/network start %I (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/netctl@.service/netctl@wlp2s0\x2dVFI_GUEST.service
└─556 wpa_supplicant -B -P /run/wpa_supplicant_wlp2s0.pid -i wlp2s...
Also, post an example output by doing a 'netctl list'.
wlp2s0-PlusnetWirelessD17423
wlp2s0-belkin.843c
* wlp2s0-VFI_GUEST
I looked at https://github.com/joukewitteveen/netct … tctl.1.txt, which talks about profiles which are "active". Do you know if this means if the given profile has been "started", or instead if it has been only "enabled"?
I realy dont know that much about netctl which is why I am asking here!
Should work in theory (emphasis on the "should" smile):
Your right, im sure it works in theory, but in practice it just freezes my system, not even an error! I would realy appreciate further help with this as I have tried working out what your script does and I have no idea!
Offline
Your right, im sure it works in theory, but in practice it just freezes my system, not even an error!
That happens if you don't do what I said you should - configure sudo so you can run the script without needing to specify a password.
I would realy appreciate further help with this as I have tried working out what your script does and I have no idea!
Learn. You think I had a clue the first time I saw the original wifi-pipe? I stared at that awk snippet for hours. But eventually I got it. Shell scripting is something that's very nice to know, comes in handy quite a lot.
Offline
The script has definitely been added to the sudoers file, im pretty sure thats not the issue.
Offline
No idea then. I do know about the freeze when the script is not in the sudoers file. What happens if you run the script in a console? It should print out the XML code for the menu.
Offline
I'm not that familiar with managing wireless networks, but you can try this script and see if it works for you:
#!/bin/bash
to_xml() {
printf ' <item label="%s">\n' "$1"
printf ' <action name="Execute"><command>netctl %s</command></action>\n' "$1"
printf ' </item>\n'
}
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<openbox_pipe_menu>'
to_xml 'stop-all'
IFS=$'\n'
profiles=($(netctl list))
regex="^[ \*]"
for p in "${profiles[@]}"; do
cmd="restart"
[[ $p =~ ^\* ]] && cmd="stop"
while [[ "$p" =~ $regex ]]; do p=${p:1}; done
to_xml "$cmd $p"
done
echo '</openbox_pipe_menu>'
Then add something like the following to your menu.xml:
<menu id="wireless-menu" label="Wireless" execute="~/path/to/script"/>
replace '~/path/to/script' with the path to the above script.
It would also be possible to incorporate signal strength information to the above. My computer doesn't have wireless, so I can't do this, but post the output of
$ cat /proc/net/wireless
and maybe we can figure out how to do this.
Offline
Hi rockin turtle!
I setup the second script the same way as I did the first and it works perfectly. However, I will say it seems to display only saved profile instead of all available networks? Im assuming thats going to be a bit more difficult? not a major issue I guess as I am now able to connect to my saved networks which is cool.
$ cat /proc/net/wireless produces:
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
wls1: 0000 35. -75. -256 0 0 0 0 37 0
Thanks for your help! its much apreciated!
EDIT: just tested out the pipe menu by selecting a profile and it doesnt appear to connect, so at the moment its just a list of saved profiles.
Last edited by LazaRuss (2013-11-02 22:11:24)
Offline
Can you control your connections from a terminal using netctl?
In other words, does running
$ netctl restart <profile>
$ netctl stop <profile>
from a terminal do what you expect?
If not, does
$ netctl switch-to <profile>
work better?
Also, when you say all available networks, are you talking about the profile files located in /etc/netctl?
Offline
Also, when you say all available networks, are you talking about the profile files located in /etc/netctl?
He means all networks that are around, even those for which profiles don't exist yet. That's what my script does, it scans for networks, and creates a new profile if one doesn't exist yet.
LazaRuss, I really think you're not configuring sudo correctly. Show us your sudoers file.
Edit: Ok, I figured out why my script freezes - if you didn't specify an interface, the call to wpa_cli will stall (that code was a last minute addition I did, so of course it was buggy ). Simply quoting the variable avoids that, I've edited the script accordingly, so download it again. But anyway, specify the interface - in your case it seems to be wlp2s0, so the openbox menu should call "sudo /path/to/wifi-pipe wlp2s0"
Last edited by Gusar (2013-11-03 12:55:27)
Offline
This is really old so I HOPE I don't re-open this or something, but this was very useful. Just got it to work with my openbox system.
Offline
Closing
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Necrobumping with an empty post? Don't do that:
https://wiki.archlinux.org/index.php/Co … mpty_posts
https://wiki.archlinux.org/index.php/Co … bumping.22
Closing
Offline
Pages: 1
Topic closed