Wake On Lan From an Extension

Can anyone help me.

I am looking for a simple solution to set up an extension number that will send send out a WOL packet on the local LAN when rung and then disconnect the call,

I am using FreePBX 2.0.76.2 with Asterisk 13.5

Thankyou in advance for any help you can give me.

Sorry, I’m having trouble understanding, what hardware needs to be told to be awoken?

Its a another server on the Lan.

In simple terms I can run “ether-wake D0:27:88:77:D4:68 -i eth0” from the command line on the PBX and the other server starts. I want to be able to run that command by calling an extension number on the PBX.

I would suggest that a “Server” being offline is pretty dumb, no? how can it serve?

Its just an old file server, it is only used occasionally so it would be ideal to be able to dial it on line when it is need need rather than having to login with a putty session to send the command.

well , if your nic supports it, then you can do that, but depending on the state of the underlying machine’s status S1,S3,off then it might not “wake up” in time. None of this is FreePBX appropriate though

I guess the question I am asking is, is it possible to set up a a special extension to run a command on the PBX when it is called rather than being an actual extension.

Well yes, but most everybody will tell you not to, running stuff with root privileges is a bad thing. If you want to do that, then google will “clue you up” so you will have to do all that in a non-gui fashion. If you are ready for that, then a non-gui “custom” extension can do that with exec() or if really necessary tryexec() and the asterisk user will need such privilege.

Yes. Your custom extension would run some dialplan that does AGI("/your/command").

However, the bad news is that crafting wake-on-lan requires root when running the command, and there’s a very strict privilege separation.

What you want to do is not as easy as it seems, sorry 8-\

Your best idea is to write a script that uses sudo, and then add a line to /etc/sudoers to grant asterisk permission to use ether-wake. Call that script by AGI in Asterisk.

Hi,

Try to run this dial plan:

[from-internal-custom]
exten => 2345,1,Answer()
same => n,TrySystem(sudo /sbin/ether-wake D0:27:88:77:D4:68 -i eth0)
same => n,NoOp(Status of TrySystem is: ${SYSTEMSTATUS})
same => n,Hangup

After adding this to your extensions_custom.conf file please reload the Asterisk dial plan (asterisk -rx'dialplan reload').

Do not forget to add these lines to the end of the sudoers file (visudo):

#Allow asterisk user to run eter-wake command
Cmnd_Alias ETHER_WAKE = /sbin/ether-wake
asterisk        ALL = NOPASSWD: ETHER_WAKE

Thank you,

Daniel Friedman
Trixton LTD.

2 Likes

Daniel,

Thank you very much for that, the perfect solution, works great, many thanks for your help

Paul

Just on final question, please forgive my Linux knowledge as my history is primarily windows.

I note from a quick search that the sudoers file should only be edited with vusudo.

I only had remote access to the system so added the extra code to sudoers with WinSCP, this appears to have worked fine but from a search of google afterwards looks to be a dangerous habit.

How much of a risk did I take, could I have knackered the system altogether.

Hi,

I am glad it is working for you.

As for the direct editing of the sudoers file:

The visudo is a wrapper that checks the spelling before editing and keeps from others to edit the sudoers file if you are already editing it. So, if you are editing the sudoers file directly just make sure you are not making any typos in the file.

Thank you,

Daniel Friedman
Trixton LTD.

1 Like