WakeOnLan from Extension (for Dummies)

Hello,
I’d like to setup FreePBX, so I can start my PC via an extension.
I’ve found this post, in which they’ve achieved exactly that, just that I don’t have the knowledge to understand how.
If anyone could explain it for a beginner like me, I’d be very grateful.

1 Like

ether-wake is a program included with most Linux distributions that sends a Wake-On-LAN packet.

Test that first: With your PC asleep, from a root shell prompt on your PBX (using a device other than the PC you’re trying to wake), type
ether-wake 11:22:33:44:55:66
(replace 11:22:33:44:55:66 with the actual MAC address of the PC to be awakened).

If the PC wakes up, great. Otherwise, you may need to change parameters for its NIC, Windows power options, or possibly even in the BIOS. Consult documentation for your PC.

The post outlines how to permit Asterisk to run the ether-wake command (which ordinarily requires root privileges) and how to set up a custom extension that runs the command when you dial it.

This all assumes that your PBX is on the same LAN as the PC to be awakened, with both using a wired Ethernet connection.

If this isn’t clear, please ask specific questions.

My PC is configured for WoL, succesfully tested. The PBX is on the same LAN as the PC, that shouldn’t be a problem.
I just don’t understand how to integrate that script into FreePBX, so that if I call a specific extension (presumably a virtual extension) it executes that.

You put the code in
/etc/asterisk/extensions_custom.conf
at the end (if there is already stuff there) or as the only content. Then restart Asterisk so it re-reads the file. Dial 2345 (or whatever you replaced it with) and your PC should wake up.

If it doesn’t the Asterisk logfile will likely show what is wrong.

Well, it actually didn’t work out. In the post is advised to add two lines of code to the " sudoers file ( visudo )", but I’m honestly not sure where to find that.

[2018-12-28 18:59:15] VERBOSE[2221] pbx_variables.c: Setting global variable 'SIPDOMAIN' to '192.168.1.10'
[2018-12-28 18:59:15] VERBOSE[2221] netsock2.c: Using SIP RTP Audio TOS bits 184
[2018-12-28 18:59:15] VERBOSE[2221] netsock2.c: Using SIP RTP Audio TOS bits 184 in TCLASS field.
[2018-12-28 18:59:15] VERBOSE[2221] netsock2.c: Using SIP RTP Audio CoS mark 5
[2018-12-28 18:59:15] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:1] Answer("PJSIP/201-00000020", "") in new stack
[2018-12-28 18:59:15] NOTICE[2221] res_pjsip_exten_state.c: Endpoint '201' state subscription failed: Extension '249' does not exist in context 'from-internal' or has no associated hint
[2018-12-28 18:59:15] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:2] TrySystem("PJSIP/201-00000020", "sudo /sbin/ether-wake [MAC ADRESS CENSORED] -i eth0") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:3] NoOp("PJSIP/201-00000020", "Status of TrySystem is: APPERROR") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:4] Hangup("PJSIP/201-00000020", "") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Spawn extension (from-internal, 249, 4) exited non-zero on 'PJSIP/201-00000020'
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:1] Macro("PJSIP/201-00000020", "hangupcall") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:1] GotoIf("PJSIP/201-00000020", "1?theend") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx_builtins.c: Goto (macro-hangupcall,s,3)
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:3] ExecIf("PJSIP/201-00000020", "0?Set(CDR(recordingfile)=)") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:4] NoOp("PJSIP/201-00000020", " monior file= ") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:5] AGI("PJSIP/201-00000020", "attendedtransfer-rec-restart.php,,") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] res_agi.c: Launched AGI Script /var/lib/asterisk/agi-bin/attendedtransfer-rec-restart.php
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] res_agi.c: <PJSIP/201-00000020>AGI Script attendedtransfer-rec-restart.php completed, returning 0
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Executing [[email protected]:6] Hangup("PJSIP/201-00000020", "") in new stack
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] app_macro.c: Spawn extension (macro-hangupcall, s, 6) exited non-zero on 'PJSIP/201-00000020' in macro 'hangupcall'
[2018-12-28 18:59:16] VERBOSE[4548][C-00000021] pbx.c: Spawn extension (from-internal, h, 1) exited non-zero on 'PJSIP/201-00000020'

At a root shell, just type
visudo
You should see the present content of the sudoers file. You edit that and write out the modified file as if you were using the vi editor. Possibly http://www.lagmonster.org/docs/vi.html will help.

Or, if you are careful not to introduce any errors, edit /etc/sudoers with another tool, or (if it has #includedir /etc/sudoers.d), create a new file in that directory to grant Asterisk access to ether-wake.

Thank you, it works perfectly fine now!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.