Project

General

Profile

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