Setting Up Remote WOL (Wake On LAN)

wol.pl - Web Access
wol.pl – Web Access

Save energy and put your unused computers immediately to sleep if they support power-saving mode (most do) then wake them up when you need to connect remotely. If you have lots of devices to manage then this guide might be useful.

Not only that, some internet or mobile connections doesn’t support WOL because the UDP port (usually UDP port 9) to forward the magic packet is blocked. I’ve encountered several times that WOL apps doesn’t work because of this even when I’ve already opened the UDP port in my router. The only way is to connect (i.e. via SSH) into one of your waked device and issue the wake command manually to the computer you need to wakeup.

To ease this process, setup WOL web access on your NAS, in this case the WDMyCloud. You’ll need to ensure your computers are able to wake up by magic packets. Go to your network adapter properties in the “Device Manager” and make sure your LAN adapter is allowed to wake the computer. Note that these wake up settings might revert to default if you update/downgrade your LAN adapter drivers or upgrade/restore your OS.

LAN Adapter
LAN Adapter

Then setup your computer to sleep after a while in the “Power Options” found in the “Control Panel”. Also change the power button to sleep instead of shutdown to quickly put it to sleep. Note that these power options might revert to default if you upgrade/restore your OS.

Next is to install my universal “wol.pl” Perl script in a webserver. It works for any webserver with Perl-CGI in this case Apache2 which is the pre-installed webserver in WDMyCloud. This requires modifications to the WDMyCloud Apache2 webserver. But if you’re not comfortable doing this yourself, you can also perform the automated install of Nginx from my post WebHosting on WDMyCloud V4 Firmwares and then symlink the “wol.pl” Perl script to your installed Nginx’s webroot path. Symlink sample is stated at the last point. Note, if you have installed Nginx from my “WebHosting Mods” installer post link above, do not modify Apache2’s configurations as below because it’s using a different incompatible “MPM_Event” module! Instead just follow the part where it doesn’t involves Apache2 changes.

Disclaimer: As I’m frequently updating the original guides and installers here on TeaNazaR.com, I will not be responsible for any brick issues if you were to follow my obsolete guides copied elsewhere. Thus subscribe to this post to get latest updates. Modifying any part of a device may void its warranty.

Modifications to WDMyCloud WebServer to enable Perl CGI

Open TCP port 80 on your router to the WDMyCloud, similarly you would have done for SSH port 22 and FTP port 21. This depends on your router, search online on how to do it for your specific router, if necessary. If you’re lucky, the port 80 maybe already selected and opened in the WDMyCloud Dashboard. For Nginx, note the port route stated in my guide was  Router:80 -> WDMyCloud:5080.

For Apache2, create a new CGI config file nano /etc/apache2/conf.d/cgi.conf then copy & paste below:

Then “CTRL+x” to exit and “y” to save.

Enable the Apache2 CGI module, issue  a2enmod cgi  then reload Apache2 server daemon, issue service apache2 reload . Remember once again to skip the above if you already have Nginx installed from my installer.

Copy the “wol.pl” Perl script found at the bottom of this post to any path on your WDMyCloud, give it an executable permission chmod 755 /shares/scripts/wol.pl and HTTPD ownership chown www-data:www-data /shares/scripts/wol.pl.

It’s recommended to hide the script from public, best password protected, path e.g. here ./private/. This method is also applicable if you had installed Nginx from my installer except the default webroot for Nginx is  cd /var/www/html/ and Apache is cd /var/www/htdocs/. After changing to the appropriate webroot path above, now create a new  ./private/ folder in the webroot, issue mkdir -pm755 ./private/. Then password protect the path for user e.g. “username”, issue  htpasswd -c ./private/.htpasswd username and enter a “password”, enter again to confirm.

Next is to enable the access control for this path.

For Apache2, create a new “.htaccess” file,   nano /var/www/htdocs/private/.htaccess then copy & paste below:

For Nginx, instead of “.htaccess” file, add below to your server directive config i.e. nano /etc/nginx/sites-enabled/default:

Then reload Nginx server daemon, issue service nginx reload. For either above, remember to “CTRL+x” to exit and “y” to save.

And finally, symlink the original “wol.pl” Perl script you had created earlier to the webserver’s webroot, issue ln -s /shares/scripts/wol.pl ./private/.

Now to wakeup your computer, simply access the script on your webserver e.g.  http://wdmycloud.your.isp.ip.or.domain/private/wol.pl then login using the “username” and “password” you had created earlier. How to remember your dynamic ISP address? Checkout the first part of my post in WebHosting on WDMyCloud V4 Firmwares.

Enjoy (-:

wol.pl

8 thoughts on “Setting Up Remote WOL (Wake On LAN)”

  1. wol.pl Updated!
    v1.2 – 20151112 – Added pings for offline hosts to help build arp list.

  2. wol.pl Updated!
    v1.3 – 20160520 – Fixed UDP input on certain browsers. Display saved hosts over active IPs.

    1. Another source about WOL for myCloud says that “older” version of MyCloud don’t support WOL. I have tried other WOL solutions (just sending broadcasting the magic packet 255.255.255.0 and other similar ideas) but haven’t had any luck so far.

      Is there some command I can issue to determine if my 4TB MyCloud Firmware V4* will do WOL?
      (What a great resource you are!)
      Thanks
      Neil
      Chicago, IL

      1. Hello Neil,

        This variant of MyCloud does not support WOL. The post is about setting up to wake up other devices within the network that support WOL.

        1. Nazar,

          Thanks very much for clarifying. At least I won’t spend any more time trying to get WOL to work!

          Neil
          Chicago, Illinois

          1. Hello Neil,

            No problem, do let me know if you need any other help 🙂

  3. This is awesome Nazar!!!
    Do you think you can provide some guidance on how to apply your script to a RPi with already installed with nginx?

    1. Hello egas,

      Firstly you’ll need to setup some stuffs…

      Get the fcgi wrapper:
      wget http://nginxlibrary.com/downloads/perl-fcgi/fastcgi-wrapper -O /usr/bin/fastcgi-wrapper.pl

      Get the fcgi service starter:
      wget http://nginxlibrary.com/downloads/perl-fcgi/perl-fcgi -O /etc/init.d/perl-fcgi

      Give executable permission to the files above:
      chmod +x /usr/bin/fastcgi-wrapper.pl /etc/init.d/perl-fcgi

      Setup perl-fcgi to run on boot:
      update-rc.d perl-fcgi defaults

      Start the perl-fcgi service:
      service perl-fcgi start

      Add below to your nginx’s config:
      location ~ \.pl|cgi$ {
      fastcgi_pass 127.0.0.1:8999;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
      }

      Reload nginx:
      service nginx reload

      Then finally place my script anywhere in your nginx’s www root.

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax