Project

General

Profile

Download (9.7 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_wol.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	notice, this list of conditions and the following disclaimer in the
18
	documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 1d333258 Scott Ullrich
/*
32
	pfSense_BUILDER_BINARIES:	/usr/local/bin/wol	
33
	pfSense_MODULE:	wol
34
*/
35 5b237745 Scott Ullrich
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-services-wakeonlan
38
##|*NAME=Services: Wake on LAN page
39
##|*DESCR=Allow access to the 'Services: Wake on LAN' page.
40
##|*MATCH=services_wol.php*
41
##|-PRIV
42
43 5b237745 Scott Ullrich
require("guiconfig.inc");
44
45
if (!is_array($config['wol']['wolentry'])) {
46
	$config['wol']['wolentry'] = array();
47
}
48
$a_wol = &$config['wol']['wolentry'];
49
50 4751361d Scott Ullrich
if($_GET['wakeall'] <> "") {
51
	$i = 0;
52
	$savemsg = "";
53
	foreach ($a_wol as $wolent) {
54
		$mac = $wolent['mac'];
55
		$if = $wolent['interface'];
56 1b197e55 stompro
		$description = $wolent['descr'];
57 2bf16ba2 Ermal
		$ipaddr = get_interface_ip($if);
58
		if (!is_ipaddr($ipaddr))
59
			continue;
60
		$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
61 1b197e55 stompro
		/* Execute wol command and check return code. */
62 2bf16ba2 Ermal
		if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}"))
63 8cd558b6 ayvis
			$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'),$mac, $description, ".<br />");
64 2bf16ba2 Ermal
		else
65 8cd558b6 ayvis
			$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s (%4$s) did not complete successfully%5$s'),'<a href="/diag_logs.php">','</a>',$description,$mac,".<br />");
66 4751361d Scott Ullrich
	}
67
}
68
69 5b237745 Scott Ullrich
if ($_POST || $_GET['mac']) {
70
	unset($input_errors);
71 f0fe3d30 Scott Ullrich
72 5b237745 Scott Ullrich
	if ($_GET['mac']) {
73 4f3401e0 Bill Marquette
        	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
74
        	$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
75 5b237745 Scott Ullrich
		$mac = $_GET['mac'];
76
		$if = $_GET['if'];
77
	} else {
78 4f3401e0 Bill Marquette
        	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
79
        	$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
80
		$mac = $_POST['mac'];
81 5b237745 Scott Ullrich
		$if = $_POST['interface'];
82
	}
83
84
	/* input validation */
85
	if (!$mac || !is_macaddr($mac))
86 d58dbf67 Rafael Lucas
		$input_errors[] = gettext("A valid MAC address must be specified.");
87 5b237745 Scott Ullrich
	if (!$if)
88 d58dbf67 Rafael Lucas
		$input_errors[] = gettext("A valid interface must be specified.");
89 5b237745 Scott Ullrich
90 f0fe3d30 Scott Ullrich
	if (!$input_errors) {
91 5b237745 Scott Ullrich
		/* determine broadcast address */
92 2bf16ba2 Ermal
		$ipaddr = get_interface_ip($if);
93
		if (!is_ipaddr($ipaddr))
94
			$input_errors[] = gettext("A valid ip could not be found!");
95 1b197e55 stompro
		else {
96 2bf16ba2 Ermal
			$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
97
			/* Execute wol command and check return code. */
98 d31ca336 Renato Botelho
			if(!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac)))
99 2bf16ba2 Ermal
				$savemsg .= sprintf(gettext("Sent magic packet to %s."),$mac);
100
			else
101 8cd558b6 ayvis
				$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s did not complete successfully%4$s'),'<a href="/diag_logs.php">', '</a>', $mac, ".<br />");
102 1b197e55 stompro
		}
103 5b237745 Scott Ullrich
	}
104
}
105
106
if ($_GET['act'] == "del") {
107
	if ($a_wol[$_GET['id']]) {
108
		unset($a_wol[$_GET['id']]);
109
		write_config();
110
		header("Location: services_wol.php");
111
		exit;
112
	}
113
}
114 4df96eff Scott Ullrich
115 d58dbf67 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"));
116 4df96eff Scott Ullrich
include("head.inc");
117
118 5b237745 Scott Ullrich
?>
119
120
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
121
<?php include("fbegin.inc"); ?>
122
<?php if ($input_errors) print_input_errors($input_errors); ?>
123
<?php if ($savemsg) print_info_box($savemsg); ?>
124
			<form action="services_wol.php" method="post" name="iform" id="iform">
125 cdb782b7 Colin Fleming
			  <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="wake on lan">
126 7f1b26bc Scott Ullrich
			<tr>
127 d58dbf67 Rafael Lucas
				<td colspan="2" valign="top" class="listtopic"><?=gettext("Wake on LAN");?></td>
128 7f1b26bc Scott Ullrich
			</tr>
129 f0fe3d30 Scott Ullrich
			  <tr>
130 d58dbf67 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
131 5b237745 Scott Ullrich
                  <td width="78%" class="vtable">
132 e47499d5 Scott Ullrich
		     		<select name="interface" class="formselect">
133
                      <?php 
134 3e321df2 Ermal Luçi
						$interfaces = get_configured_interface_with_descr();
135 e47499d5 Scott Ullrich
					  	foreach ($interfaces as $iface => $ifacename): ?>
136 cdb782b7 Colin Fleming
                      	<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $if) echo "selected=\"selected\""; ?>>
137 5b237745 Scott Ullrich
                      <?=htmlspecialchars($ifacename);?>
138
                      </option>
139
                      <?php endforeach; ?>
140 8cd558b6 ayvis
                    </select> <br />
141 d58dbf67 Rafael Lucas
                    <span class="vexpl"><?=gettext("Choose which interface the host to be woken up is connected to.");?></span></td>
142 5b237745 Scott Ullrich
                </tr>
143
                <tr>
144 d58dbf67 Rafael Lucas
				  <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
145 5b237745 Scott Ullrich
				  <td width="78%" class="vtable">
146 cdb782b7 Colin Fleming
                      <input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($mac);?>" />
147 8cd558b6 ayvis
                      <br />
148 42256271 Carlos Eduardo Ramos
                      <?=gettext("Enter a MAC address ");?><span class="vexpl"> <?=gettext("in the following format: xx:xx:xx:xx:xx:xx");?></span></td></tr>
149 5b237745 Scott Ullrich
				<tr>
150
				  <td width="22%" valign="top">&nbsp;</td>
151 f0fe3d30 Scott Ullrich
				  <td width="78%">
152 cdb782b7 Colin Fleming
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Send");?>" />
153 5b237745 Scott Ullrich
				</td>
154
				</tr>
155
			</table>
156 8cd558b6 ayvis
			&nbsp;<br />
157 cdb782b7 Colin Fleming
			<?=gettext("Wake all clients at once: ");?><a href="services_wol.php?wakeall=true"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_wol_all.gif" width="17" height="17" border="0" alt="wol all" /></a><br/>
158 d58dbf67 Rafael Lucas
			<?=gettext("Or Click the MAC address to wake up an individual device:");?>
159 cdb782b7 Colin Fleming
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont" summary="clients">
160 5b237745 Scott Ullrich
                <tr>
161 d58dbf67 Rafael Lucas
                  <td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
162
                  <td width="25%" class="listhdrr"><?=gettext("MAC address");?></td>
163
                  <td width="50%" class="listhdr"><?=gettext("Description");?></td>
164 d415d821 Seth Mos
                  <td width="10%" class="list">
165 cdb782b7 Colin Fleming
                    <table border="0" cellspacing="0" cellpadding="1" summary="add">
166 d415d821 Seth Mos
                      <tr>
167
			<td valign="middle" width="17"></td>
168 cdb782b7 Colin Fleming
                        <td valign="middle"><a href="services_wol_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
169 d415d821 Seth Mos
                      </tr>
170
                    </table>
171
		  </td>
172
		</tr>
173 5b237745 Scott Ullrich
			  <?php $i = 0; foreach ($a_wol as $wolent): ?>
174
                <tr>
175 5f9c0e68 Bill Marquette
                  <td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
176 ae92e820 Charlie Marshall
                    <?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
177 5b237745 Scott Ullrich
                  </td>
178 5f9c0e68 Bill Marquette
                  <td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
179 cdb782b7 Colin Fleming
                    <a href="?mac=<?=$wolent['mac'];?>&amp;if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
180 5b237745 Scott Ullrich
                  </td>
181 5f9c0e68 Bill Marquette
                  <td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
182 ae92e820 Charlie Marshall
                    <?=htmlspecialchars($wolent['descr']);?>
183 5b237745 Scott Ullrich
                  </td>
184 cdb782b7 Colin Fleming
                  <td valign="middle" class="list nowrap">
185
                    <table border="0" cellspacing="0" cellpadding="1" summary="icons">
186 2d4a7bb1 Bill Marquette
                      <tr>
187 cdb782b7 Colin Fleming
                        <td valign="middle"><a href="services_wol_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" /></a></td>
188
                        <td valign="middle"><a href="services_wol.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" /></a></td>
189 2d4a7bb1 Bill Marquette
                      </tr>
190
                    </table>
191
                  </td>
192 1d333258 Scott Ullrich
			</tr>
193 2d4a7bb1 Bill Marquette
	        <?php $i++; endforeach; ?>
194 f0fe3d30 Scott Ullrich
                <tr>
195 5b237745 Scott Ullrich
                  <td class="list" colspan="3"></td>
196 2d4a7bb1 Bill Marquette
                  <td class="list">
197 cdb782b7 Colin Fleming
                    <table border="0" cellspacing="0" cellpadding="1" summary="add">
198 2d4a7bb1 Bill Marquette
                      <tr>
199 d415d821 Seth Mos
			<td valign="middle" width="17"></td>
200 cdb782b7 Colin Fleming
                        <td valign="middle"><a href="services_wol_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
201 2d4a7bb1 Bill Marquette
                      </tr>
202
                    </table>
203
                  </td>
204 474d1649 Holger Bauer
                  			
205 1d333258 Scott Ullrich
			</tr>
206 5b237745 Scott Ullrich
              </table>
207 7f1b26bc Scott Ullrich
			<span class="vexpl">
208
					<span class="red">
209
						<strong>
210 8cd558b6 ayvis
							<?=gettext("Note:");?><br />
211 7f1b26bc Scott Ullrich
            			</strong>
212 42256271 Carlos Eduardo Ramos
					</span><?=gettext("This service can be used to wake up (power on) computers by sending special"); ?> &quot;<?=gettext("Magic Packets"); ?>&quot;. <?=gettext("The NIC in the computer that is to be woken up must support Wake on LAN and has to be configured properly (WOL cable, BIOS settings). ");?>
213 7f1b26bc Scott Ullrich
			</span>
214
215 5b237745 Scott Ullrich
</form>
216
<?php include("fend.inc"); ?>
217
</body>
218
</html>