You are not logged in.

#1 2013-10-31 22:45:20

LazaRuss
Member
Registered: 2013-07-13
Posts: 12

openbox wifi pipe menu - netctl

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

#2 2013-11-01 02:04:05

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 218

Re: openbox wifi pipe menu - netctl

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

#3 2013-11-01 17:25:09

LazaRuss
Member
Registered: 2013-07-13
Posts: 12

Re: openbox wifi pipe menu - netctl

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

#4 2013-11-01 18:26:20

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 218

Re: openbox wifi pipe menu - netctl

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

#5 2013-11-01 18:50:48

Gusar
Member
Registered: 2009-08-25
Posts: 3,466

Re: openbox wifi pipe menu - netctl

Should work in theory (emphasis on the "should" smile):

#!/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

#6 2013-11-02 00:19:31

LazaRuss
Member
Registered: 2013-07-13
Posts: 12

Re: openbox wifi pipe menu - netctl

rockin turtle wrote:

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...

rockin turtle wrote:

Also, post an example output by doing a 'netctl list'.

  wlp2s0-PlusnetWirelessD17423
  wlp2s0-belkin.843c
* wlp2s0-VFI_GUEST

rockin turtle wrote:

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! smile

Gusar wrote:

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! smile

Offline

#7 2013-11-02 00:34:52

Gusar
Member
Registered: 2009-08-25
Posts: 3,466

Re: openbox wifi pipe menu - netctl

LazaRuss wrote:

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.

LazaRuss wrote:

I would realy appreciate further help with this as I have tried working out what your script does and I have no idea! smile

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

#8 2013-11-02 06:30:36

LazaRuss
Member
Registered: 2013-07-13
Posts: 12

Re: openbox wifi pipe menu - netctl

The script has definitely been added to the sudoers file, im pretty sure thats not the issue.

Offline

#9 2013-11-02 10:27:52

Gusar
Member
Registered: 2009-08-25
Posts: 3,466

Re: openbox wifi pipe menu - netctl

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

#10 2013-11-02 18:57:01

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 218

Re: openbox wifi pipe menu - netctl

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

#11 2013-11-02 21:57:59

LazaRuss
Member
Registered: 2013-07-13
Posts: 12

Re: openbox wifi pipe menu - netctl

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

#12 2013-11-03 01:34:40

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 218

Re: openbox wifi pipe menu - netctl

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

#13 2013-11-03 10:52:55

Gusar
Member
Registered: 2009-08-25
Posts: 3,466

Re: openbox wifi pipe menu - netctl

rockin turtle wrote:

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 smile). 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

Board footer

Powered by FluxBB