Jump to content

Wake up a homeserver with WOL & PHP if someone try to access the MediaBrowser Site


Guest

Recommended Posts

Hi, 
 
I've been here for some time going to try to wake up my home server with WOL if someone visits the MB Homepage. Unfortunately, all attempts with various PHP or DD-WRT scripts were previously unsuccessful  :mellow:
 
But maybe someone in this community have a good tip for me  ;)
 
The background is as follows: 
I have at home a amall home server which is hosting various sites such as the TV-Webinterface of Argus TV, MediaBrowser3 or the OwnCloud web interface. Since I do not need the home server 24/7, it automatically switches off to hibernation after 10 minutes. As a router I use a Cisco EA6500 with DD-WRT firmware. WOL is set up and working also fine from outside. Currently I wake up the router as needed by WOL with my phone or the web interface of the router. 
While this is functional, but of course not quite as comfortable  :P
 
In addition to the Home Server I have a "real" web hosting package with some page redirections to the server at home. My idea was to simply set up a PHP script there to wake the server at home via WOL if the requested site is not directly available, and then to forward after a successful wake up via WOL. 
 
I've tried various scripts. The query of the online status of a page and forwarding to it is working. Unfortunately it fails when sending the WOL packet. Can it be that PHP does not support this feature by default? Did I miss something here? What other options are there still for me? How is your solution at home? 
 
 
The script / function should therefore look something like this:
 
Call of site X 
-> Checks if page Y online 

If Y Online 
-> Forwarding on page Y 

If Y is Offline 
-> WOL packet is sent and online status (after a certain timeout) re-examined by page Y 
-> Output to users, that the server is woken 

If Y after WOL shipping online 
-> Forwarding on page Y 

If Y after WOL shipping online 
-> Error message, the page Y unavailable / server could not be awakened

Best regards and thank you in advance for your tips  ;)

 

Link to comment
Share on other sites

 

Thank you very much for your help :)

 

The php script from this link I already know, but unfortunately it does not help me. It's a little too complex and hosts a complete  Homepage for WOL with a User Interface. But In principle, this is the same thing I can do now already on my routers web interface.  :mellow:

 

I want do do things more automatically, without any input options for the users. It should work in the background (like I descriped in the first post) with just a few output messages

Link to comment
Share on other sites

Have you looked into accessing WMI?

 

I had some great Head way using WMI to wake up the server when my kinect app started remotely.

Link to comment
Share on other sites

Interesting solution, newer heard of it. How can I wake up a PC with WMI and especially over an external webiste?

 

 

But for now I got it work with my DD-WRT Router.

I will write down a short How-To. It's a bit tricky, but works very well  :)

Maybe someone is interested in that too

 

You only need a Router which is capable of DD-WRT and has USB Support! 

 

First thing you have to do ist to enable JFFS2 Support under the Administration(Management) Tab:

nl487lp7.png

 

Second, you have to enable USB Support under Services(USB) and mount a USB drive (with a Linux Fileformat like ext3) under jffs. Maybe a restart is required for mounting:

ot7xu4ay.png

 

Next we have to enable a few Syslog option for the Script to work correctly.

Go under Services(Services) and enable Syslogd. Leave the Remote Server blank:

tpnq799q.png

 

At next go to Security(Firewall) and enable log there, set the loglevel to high and enable Accepted under options:

w5lvm9am.png

 

Now you have to login to your router via SFTP and place the following Script under the jffs folder.

Just open a textfile and copy the following code into it. After that rename the testfile to XYZ.sh (in my case I named is startup.sh).

Of course you have to edit the Port Number, the Targeting Machine and the Mac Adress to your needs.  ;)

#!/bin/sh
#Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
#You can check the log from http://192.168.1.1/user/wol.html

INTERVAL=5
NUMP=3
OLD=""
PORT=8096
WOLPORT=9
TARGET=192.168.1.100
BROADCAST=192.168.1.255
MAC=XX:XX:XX:XX:XX:XX
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"

echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "AUTO WOL Script started at" `date` "<br>" >> $LOGFILE

while sleep $INTERVAL;do
NEW=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print }' | tail -1`
SRC=`dmesg | awk -F'[=| ]' '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print $7}' | tail -1`
LINE=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/'`
                                                                                                                             
if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then                                                
   if ping -qc $NUMP $TARGET >/dev/null; then                                                  
      echo "NOWAKE $TARGET was accessed by $SRC and is already alive at" `date` "<br>">> $LOGFILE     
   else                                                                                         
      echo "WAKE $SRC causes wake on lan at" `date` "<br>">> $LOGFILE                          
      $WOL -i $BROADCAST -p $WOLPORT $MAC >> $LOGFILE                                              
      echo "<br>" >> $LOGFILE                                                                   
      sleep 5                                                                                   
   fi                                                                                           
   OLD=$NEW                                                                                   
fi                                                                                                                                                                                
done

Now place the sript under jffs with a SFTP program like WinSCP:

gkdi4vuz.png

 

Ok, almost done. But we now have to go back to the Router webinterface first.

Go to Administration(commands) and run the following command to make the script executable: chmod +x /jffs/startup.sh

 

ezb578em.png

 

Ok, now the scipt is executable and you can run it simply with the command: /jffs/startup.sh

If you want that the script gets startet after every reboot of you router you just have to save the command as a sartup command:

l64yrvq9.png

 

That, it, Now you Server should be wake up anytime you try to visit your MediaBrowser Homepage  B)

If you want to xheck the current status of the script you can do that by going to: http://192.168.1.1/user/wol.html

622pvjhv.png

 

 

 

 

Hope it helps someone. Have fun  ;)

Edited by CM000n
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...