Project

General

Profile

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

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
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
require("guiconfig.inc");
34

    
35
if (!is_array($config['wol']['wolentry'])) {
36
	$config['wol']['wolentry'] = array();
37
}
38
wol_sort();
39
$a_wol = &$config['wol']['wolentry'];
40

    
41
if ($_POST || $_GET['mac']) {
42
	unset($input_errors);
43

    
44
	if ($_GET['mac']) {
45
        	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
46
        	$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
47
		$mac = $_GET['mac'];
48
		$if = $_GET['if'];
49
	} else {
50
        	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
51
        	$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
52
		$mac = $_POST['mac'];
53
		$if = $_POST['interface'];
54
	}
55

    
56
	/* input validation */
57
	if (!$mac || !is_macaddr($mac))
58
		$input_errors[] = "A valid MAC address must be specified.";
59
	if (!$if)
60
		$input_errors[] = "A valid interface must be specified.";
61

    
62
	if($_GET['wakeall'] <> "") {
63
		$i = 0;
64
		$savemsg = "";
65
		foreach ($a_wol as $wolent) {
66
			$mac = $wolent['mac'];
67
			$if = $wolent['interface'];
68
			$bcip = gen_subnet_max($config['interfaces'][$if]['ipaddr'],
69
				$config['interfaces'][$if]['subnet']);
70
			mwexec("/usr/local/bin/wol -i {$bcip} {$mac}");
71
			$savemsg .= "Sent magic packet to {$mac}.<br>";
72
		}
73
	}
74

    
75
	if (!$input_errors) {
76
		/* determine broadcast address */
77
		$bcip = gen_subnet_max($config['interfaces'][$if]['ipaddr'],
78
			$config['interfaces'][$if]['subnet']);
79

    
80
		mwexec("/usr/local/bin/wol -i {$bcip} {$mac}");
81
		$savemsg = "Sent magic packet to {$mac}.";
82
	}
83
}
84

    
85
if ($_GET['act'] == "del") {
86
	if ($a_wol[$_GET['id']]) {
87
		unset($a_wol[$_GET['id']]);
88
		write_config();
89
		header("Location: services_wol.php");
90
		exit;
91
	}
92
}
93

    
94
$pgtitle = "Services: Wake on LAN";
95
include("head.inc");
96

    
97
?>
98

    
99
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
100
<?php include("fbegin.inc"); ?>
101
<p class="pgtitle"><?=$pgtitle?></p>
102
<?php if ($input_errors) print_input_errors($input_errors); ?>
103
<?php if ($savemsg) print_info_box($savemsg); ?>
104
			<form action="services_wol.php" method="post" name="iform" id="iform">
105
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
106
			  <tr>
107
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
108
                  <td width="78%" class="vtable">
109
		     <select name="interface" class="formfld">
110
                      <?php $interfaces = array('lan' => 'LAN');
111
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
112
					    if (isset($config['interfaces']['opt' . $i]['enable']) &&
113
							!$config['interfaces']['opt' . $i]['bridge'])
114
					  		$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
115
					  }
116
					  foreach ($interfaces as $iface => $ifacename): ?>
117
                      <option value="<?=$iface;?>" <?php if ($iface == $if) echo "selected"; ?>>
118
                      <?=htmlspecialchars($ifacename);?>
119
                      </option>
120
                      <?php endforeach; ?>
121
                    </select> <br>
122
                    <span class="vexpl">Choose which interface the host to be woken up is connected to.</span></td>
123
                </tr>
124
                <tr>
125
				  <td width="22%" valign="top" class="vncellreq">MAC address</td>
126
				  <td width="78%" class="vtable">
127
                      <input name="mac" type="text" class="formfld" id="mac" size="20" value="<?=htmlspecialchars($mac);?>">
128
                      <br>
129
                      Enter a MAC address <span class="vexpl"> in the following format: xx:xx:xx:xx:xx:xx</span></td></tr>
130
				<tr>
131
				  <td width="22%" valign="top">&nbsp;</td>
132
				  <td width="78%">
133
                    <input name="Submit" type="submit" class="formbtn" value="Send">
134
				</td>
135
				</tr>
136
			</table>
137
			<span class="vexpl"><span class="red"><strong>Note:<br>
138
            </strong></span>This service can be used to wake up (power on) computers by sending special &quot;Magic Packets&quot;. 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). </span><br>
139
                      <br>
140
                      You may store MAC addresses below for your convenience.
141
Click the MAC address to wake up a computer. <br>
142
&nbsp;<br>
143
You also can 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"></a><br>
144
&nbsp;<br>
145
<table width="100%" border="0" cellpadding="0" cellspacing="0">
146
                <tr>
147
                  <td width="15%" class="listhdrr">Interface</td>
148
                  <td width="25%" class="listhdrr">MAC address</td>
149
                  <td width="50%" class="listhdr">Description</td>
150
                  <td width="10%" class="list"></td>
151
				</tr>
152
			  <?php $i = 0; foreach ($a_wol as $wolent): ?>
153
                <tr>
154
                  <td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
155
                    <?php if ($wolent['interface'] == "lan")
156
							   echo "LAN";
157
						   else
158
						       echo $config['interfaces'][$wolent['interface']]['descr'];
159
					?>&nbsp;
160
                  </td>
161
                  <td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
162
                    <a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>&nbsp;
163
                  </td>
164
                  <td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
165
                    <font color="#FFFFFF"><?=htmlspecialchars($wolent['descr']);?>&nbsp;
166
                  </td>
167
                  <td valign="middle" nowrap class="list">
168
                    <table border="0" cellspacing="0" cellpadding="1">
169
                      <tr>
170
                        <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"></a></td>
171
                        <td valign="middle"><a href="services_wol.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this entry?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
172
                      </tr>
173
                    </table>
174
                  </td>
175
		</tr>
176
	        <?php $i++; endforeach; ?>
177
                <tr>
178
                  <td class="list" colspan="3"></td>
179
                  <td class="list">
180
                    <table border="0" cellspacing="0" cellpadding="1">
181
                      <tr>
182
                        <td valign="middle">
183
				<a href="services_wol_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a>
184
				
185
			</td>
186

    
187
                      </tr>
188
                    </table>
189
                  </td>
190
                  			
191
		</tr>
192
              </table>
193
</form>
194
<?php include("fend.inc"); ?>
195
</body>
196
</html>
(108-108/147)