PDA

Bekijk de volledige versie : HOWTO: Wake On Lan from internet



mistraller
25-08-2007, 00:02
I have a working Wake On Lan Solution on my asus wl500gx using ether-wake, which is included in Oleg firmware.
It's quite simple, and works with the (also builtin) busybox_httpd webserver, without making NAT rules for wake on lan in your modem!

First: Make your asus webserver accessible from the internet. See other HOWTO's how to do that. In my asus httpd runs on port 81, my modem has a NAT rule to translate external port 80 to internal port 81.

If you want to hide your wake-on-lan webpage behind a password protected area (which you probably want, otherwise everyone could turn on your home pc's) you have to include a line to your config file:



/cgi-bin:user:password

In this example, only the active pages will be protected, you can also protect other folders, with one or more useraccounts:


/adm:admin:setup # Require user admin, pwd setup on urls starting with /adm/
/adm:toor:PaSsWd # or user toor, pwd PaSsWd on urls starting with /adm/
Save your configfile under /opt/etc/httpd.conf

Start busybox_httpd with:

busybox-httpd -c /opt/etc/httpd.conf -p 81 -h /opt/share/www
Replace path to configfile, portname and weblocation to your own values of course.
You can place this into /usr/local/sbin/post-boot

Findout if your pc can be woken up by issueing the command:

ether-wake -i br0 00:11:22:33:44:55
Replace with your own mac adress of course. If it's not working, check if your pc or network settings. Your pc has to be a wired connection to the internal network where the asus is connected. Not all routers pass through the magic packet, so best is to keep it simple, and connect the pc directly to the asus. (this howto is not intended for resolving general WOL problems)

If the pc wakes up, you can place the following file into your cgi-bin folder on the shared weblocation, in my case: /opt/share/www/cgi-bin/wol.cgi


#!/bin/sh
ether-wake -i br0 11:22:33:44:55:66
echo "<HTML><HEAD><title>test</title></head><BODY>Magic Packet Sent</Body></html>"

After creating/placing the file, chmod +x it, to give it a execute permissions.

As you see, you can edit this file as you like, or create multiple cgi-bin files, with a central html page with links to all corresponding files, for multiple pc's.

Now, powerdown the pc, go to another pc and go to www.yoursite.com/cgi-bin/wol.cgi

You will see the password protection if installed, after entering your credentials, the pc will wake up!

Because the magic packet was sent by a device from within your lan, it doesn't have to pass your modem, so a NAT rule is not necessary. Also, remembering your mac adress is history ;)

I also tried this with an available php webserver, php-thttpd, but thttpd is more secure. Because of security, thttpd won't start ether-wake with root permissions, and it will end with a "Cannot create raw socket" error. I tried to su ether-wake, but that was no improvement.

Of course, if there's no external disk, or you don't have an /opt/ mountpoint, you can place your files anywhere.
Remember to

flashfs save && flashfs commit && flashfs enable
If you place files on internal storage.

KGy
25-08-2007, 08:05
Hi and sorry my english.

If you want WoL more computers from net:

1) Add a (more) computer's mac to "Manually Assigned IP List" and "Enable Manual Assignment"

2) Create some script in webserver's cgi-bin folder:

.../cgi-bin/wakeuplist.cgi


#!/bin/sh
cat << __FLUSH
Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">
<title>WebStatus</title>
</head>
<body bgcolor=#5555aa link=#000000 vlink=000000>
<h2>System info for Asus home gateway router</h2>
<hr>
__FLUSH

echo "<form method=\"post\" action=\"/cgi-bin/wakeup.cgi\">"

awk -f wol.awk /etc/ethers "ethlist" >ethlist.$$
cat ethlist.$$

echo "<br><br><input type=\"submit\" value=\"Wake Up\">"
echo "</form>"

rm ethlist.$$
cat << __FLUSH
<hr>
</body>
</html>
__FLUSH


../cgi-bin/wakeup.cgi


#!/bin/sh
cat >> ethselect.$$
cat << __FLUSH
Content-type: text/html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">
<title>WebStatus</title>
</head>
<body bgcolor=#5555aa link=#000000 vlink=000000>
<h2>System info for Asus home gateway router</h2>
<hr><a align=center href=/cgi-bin/wakeuplist>Back</a><hr>
__FLUSH

ETH=`cat ethselect.$$ | sed -e 's/WOL=//g'`
MAC=`awk -f wol.awk /etc/ethers "ethselect" "$ETH"`
if [ "$MAC" == "" ] ; then
echo "<br>Not select computer's eth device...<br><br>"
else
echo "<br>Send WoL packet to ${MAC} ...<br><br>"
ether-wake -i br0 ${MAC}
fi

rm ethselect.$$
cat << __FLUSH
<hr><a align=center href=/cgi-bin/wakeuplist>Back</a><hr>
</body>
</html>
__FLUSH


../cgi-bin/wol.awk


# KGy's wol web interface template handler
# Copyright (C) 2007 by KGy
#
# Based on Seaky CTCS Web interface template handler
# Copyright (C) 2006 by Robert Szakalli <seaky77@gmail.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# version 0.99 alpha

BEGIN{
if (ARGC<2) {
print "Template Handler v1.0 by KGy 2007 (c)\n";
exit(0);
}
if (ARGV[2]=="ethlist") {
l=1;
while ((getline rline < ARGV[1]) > 0) {
if (index(rline,"#")!=1) {
print "<tt><br><input name=\"WOL" "\" type=\"radio\" value=\"" l "\"> " rline "</tt>";
l++;
}
}
} else if (ARGV[2]=="ethselect") {
if (ARGC<3) {
print "Template Handler v1.0 by KGy 2007 (c)\n";
exit(0);
}
x=ARGV[3];
l=1;
while ((getline rline < ARGV[1]) > 0) {
if (index(rline,"#")!=1) {
if (l==x) {
print substr(rline,1,index(rline," ")-1);
}
l++;
}
}
} else {
print "Template Handler v1.0 by KGy 2007 (c)\nUnknown function\n";
exit(0);
}
}


These scripts use mac list from /etc/ethers, but working, if change it other ( /opt/etc/wakuplist.conf) and fill mac and computer name data (format: also /etc/ethers: "mac_addr name"). If you change /etc/ethers, don't forget change a lline "awk.../etc/ethers", too.

3) add +x attribute to wakeuplist and wakeup scripts.


chmod +x wakuplist
chmod +x wakup


To WoL PC, use http://www.yoursite.com/cgi-bin/wakeuplist.cgi url.

George

mistraller
28-08-2007, 07:29
Nice, I'll give it a try.
After searching I found nothing, so I created my own solution. I think mine's more simple, but your solution seems to look better to me.

What do you mean with "Manually Assigned IP List" and "Enable Manual Assignment"?

My Asus is only AP, dhcp, dns is all running on my other adsl modem/router.

KGy
28-08-2007, 07:45
Hi and sorry my english.

You don't need to use dhcp and fix mac<->ip table (/etc/ethers).
You can use other MAC conf file to list computer (/opt/etc/wakeuplist.conf :)).
Save MACs and computers info ("00:11:22:33:44:55 MyComputer") to your config file (/opt/etc/wakeuplist.conf) and change "/etc/ethers" with "/opt/etc/wakeuplist.conf" in scripts.



...
awk -f wol.awk /etc/ethers "ethlist" >ethlist.$$
...


change to


awk -f wol.awk /opt/etc/wakeuplist.conf "ethlist" >ethlist.$$


Good luck to work, bye.

George

mistraller
28-08-2007, 20:18
Hi and sorry my english.

You don't need to use dhcp and fix mac<->ip table (/etc/ethers).
You can use other MAC conf file to list computer (/opt/etc/wakeuplist.conf :)).
Save MACs and computers info ("00:11:22:33:44:55 MyComputer") to your config file (/opt/etc/wakeuplist.conf) and change "/etc/ethers" with "/opt/etc/wakeuplist.conf" in scripts.



...
awk -f wol.awk /etc/ethers "ethlist" >ethlist.$$
...


change to


awk -f wol.awk /opt/etc/wakeuplist.conf "ethlist" >ethlist.$$


Good luck to work, bye.

George
Works great, Thanx!

mistraller
30-08-2007, 22:25
Do you know how I can run the script with php-thttpd? I tried before, but ether-wake won't run with root privileges, and no wol is performed. (Even after I chmod+s ether-wake)

KGy
30-08-2007, 23:42
Hi.

Sorry, I not used php-thttpd. I use only busybox@httpd, two times :)
From lighttpd this cgi-script not working, buf if you change name x to x.cgi, will work.
Idea: If script run from php-thttpd, but not wol, change user in script by su or sudo.

George

mistraller
02-09-2007, 12:15
Hi.

Sorry, I not used php-thttpd. I use only busybox@httpd, two times :)
From lighttpd this cgi-script not working, buf if you change name x to x.cgi, will work.
Idea: If script run from php-thttpd, but not wol, change user in script by su or sudo.

George
Hmm su root doesn't look like a secure solution in a cgi script..? I also tried to set the SUID bit on ether-wake, but that didn't work out unfortunately.