Project

General

Profile

Download (9.75 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_wol.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
9
	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
/*
33
	pfSense_BUILDER_BINARIES:	/usr/local/bin/wol	
34
	pfSense_MODULE:	wol
35
*/
36

    
37
##|+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
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
if($_GET['wakeall'] <> "") {
52
	$i = 0;
53
	$savemsg = "";
54
	foreach ($a_wol as $wolent) {
55
		$mac = $wolent['mac'];
56
		$if = $wolent['interface'];
57
		$description = $wolent['descr'];
58
		$ipaddr = get_interface_ip($if);
59
		if (!is_ipaddr($ipaddr))
60
			continue;
61
		$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
62
		/* Execute wol command and check return code. */
63
		if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}"))
64
			$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'),$mac, $description, ".<br />");
65
		else
66
			$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
	}
68
}
69

    
70
if ($_POST || $_GET['mac']) {
71
	unset($input_errors);
72

    
73
	if ($_GET['mac']) {
74
        	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
75
        	$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
76
		$mac = $_GET['mac'];
77
		$if = $_GET['if'];
78
	} else {
79
        	/* 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
		$if = $_POST['interface'];
83
	}
84

    
85
	/* input validation */
86
	if (!$mac || !is_macaddr($mac))
87
		$input_errors[] = gettext("A valid MAC address must be specified.");
88
	if (!$if)
89
		$input_errors[] = gettext("A valid interface must be specified.");
90

    
91
	if (!$input_errors) {
92
		/* determine broadcast address */
93
		$ipaddr = get_interface_ip($if);
94
		if (!is_ipaddr($ipaddr))
95
			$input_errors[] = gettext("A valid ip could not be found!");
96
		else {
97
			$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
98
			/* Execute wol command and check return code. */
99
			if(!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac)))
100
				$savemsg .= sprintf(gettext("Sent magic packet to %s."),$mac);
101
			else
102
				$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
		}
104
	}
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

    
116
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"));
117
include("head.inc");
118

    
119
?>
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
			  <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="wake on lan">
127
			<tr>
128
				<td colspan="2" valign="top" class="listtopic"><?=gettext("Wake on LAN");?></td>
129
			</tr>
130
			  <tr>
131
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
132
                  <td width="78%" class="vtable">
133
		     		<select name="interface" class="formselect">
134
                      <?php 
135
						$interfaces = get_configured_interface_with_descr();
136
					  	foreach ($interfaces as $iface => $ifacename): ?>
137
                      	<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $if) echo "selected=\"selected\""; ?>>
138
                      <?=htmlspecialchars($ifacename);?>
139
                      </option>
140
                      <?php endforeach; ?>
141
                    </select> <br />
142
                    <span class="vexpl"><?=gettext("Choose which interface the host to be woken up is connected to.");?></span></td>
143
                </tr>
144
                <tr>
145
				  <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
146
				  <td width="78%" class="vtable">
147
                      <input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($mac);?>" />
148
                      <br />
149
                      <?=gettext("Enter a MAC address ");?><span class="vexpl"> <?=gettext("in the following format: xx:xx:xx:xx:xx:xx");?></span></td></tr>
150
				<tr>
151
				  <td width="22%" valign="top">&nbsp;</td>
152
				  <td width="78%">
153
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Send");?>" />
154
				</td>
155
				</tr>
156
			</table>
157
			&nbsp;<br />
158
			<?=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
			<?=gettext("Or Click the MAC address to wake up an individual device:");?>
160
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont" summary="clients">
161
                <tr>
162
                  <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
                  <td width="10%" class="list">
166
                    <table border="0" cellspacing="0" cellpadding="1" summary="add">
167
                      <tr>
168
			<td valign="middle" width="17"></td>
169
                        <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
                      </tr>
171
                    </table>
172
		  </td>
173
		</tr>
174
			  <?php $i = 0; foreach ($a_wol as $wolent): ?>
175
                <tr>
176
                  <td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
177
                    <?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
178
                  </td>
179
                  <td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
180
                    <a href="?mac=<?=$wolent['mac'];?>&amp;if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
181
                  </td>
182
                  <td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
183
                    <?=htmlspecialchars($wolent['descr']);?>
184
                  </td>
185
                  <td valign="middle" class="list nowrap">
186
                    <table border="0" cellspacing="0" cellpadding="1" summary="icons">
187
                      <tr>
188
                        <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
                      </tr>
191
                    </table>
192
                  </td>
193
			</tr>
194
	        <?php $i++; endforeach; ?>
195
                <tr>
196
                  <td class="list" colspan="3"></td>
197
                  <td class="list">
198
                    <table border="0" cellspacing="0" cellpadding="1" summary="add">
199
                      <tr>
200
			<td valign="middle" width="17"></td>
201
                        <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
                      </tr>
203
                    </table>
204
                  </td>
205
                  			
206
			</tr>
207
              </table>
208
			<span class="vexpl">
209
					<span class="red">
210
						<strong>
211
							<?=gettext("Note:");?><br />
212
            			</strong>
213
					</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
			</span>
215

    
216
</form>
217
<?php include("fend.inc"); ?>
218
</body>
219
</html>
(175-175/256)