Project

General

Profile

Download (7.65 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 (!$input_errors) {
63
		/* determine broadcast address */
64
		$bcip = gen_subnet_max($config['interfaces'][$if]['ipaddr'],
65
			$config['interfaces'][$if]['subnet']);
66

    
67
		mwexec("/usr/local/bin/wol -i {$bcip} {$mac}");
68
		$savemsg = "Sent magic packet to {$mac}.";
69
	}
70
}
71

    
72
if ($_GET['act'] == "del") {
73
	if ($a_wol[$_GET['id']]) {
74
		unset($a_wol[$_GET['id']]);
75
		write_config();
76
		header("Location: services_wol.php");
77
		exit;
78
	}
79
}
80
?>
81
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
82
<html>
83
<head>
84
<title><?=gentitle("Services: Wake on LAN");?></title>
85
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
86
<link href="gui.css" rel="stylesheet" type="text/css">
87
</head>
88

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