Project

General

Profile

Download (7.57 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
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 f0fe3d30 Scott Ullrich
44 5b237745 Scott Ullrich
	if ($_GET['mac']) {
45 4f3401e0 Bill Marquette
        	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
46
        	$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
47 5b237745 Scott Ullrich
		$mac = $_GET['mac'];
48
		$if = $_GET['if'];
49
	} else {
50 4f3401e0 Bill Marquette
        	/* 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 5b237745 Scott Ullrich
		$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 f0fe3d30 Scott Ullrich
	if (!$input_errors) {
63 5b237745 Scott Ullrich
		/* determine broadcast address */
64
		$bcip = gen_subnet_max($config['interfaces'][$if]['ipaddr'],
65
			$config['interfaces'][$if]['subnet']);
66 f0fe3d30 Scott Ullrich
67 5b237745 Scott Ullrich
		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 4df96eff Scott Ullrich
81
$pgtitle = "Services: Wake on LAN";
82
include("head.inc");
83
84 5b237745 Scott Ullrich
?>
85
86
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
87
<?php include("fbegin.inc"); ?>
88 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
89 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
90
<?php if ($savemsg) print_info_box($savemsg); ?>
91
			<form action="services_wol.php" method="post" name="iform" id="iform">
92
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
93 f0fe3d30 Scott Ullrich
			  <tr>
94 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
95
                  <td width="78%" class="vtable">
96 25d3fbd5 Scott Ullrich
		     <select name="interface" class="formfld">
97 5b237745 Scott Ullrich
                      <?php $interfaces = array('lan' => 'LAN');
98
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
99
					    if (isset($config['interfaces']['opt' . $i]['enable']) &&
100
							!$config['interfaces']['opt' . $i]['bridge'])
101
					  		$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
102
					  }
103
					  foreach ($interfaces as $iface => $ifacename): ?>
104 f0fe3d30 Scott Ullrich
                      <option value="<?=$iface;?>" <?php if ($iface == $if) echo "selected"; ?>>
105 5b237745 Scott Ullrich
                      <?=htmlspecialchars($ifacename);?>
106
                      </option>
107
                      <?php endforeach; ?>
108
                    </select> <br>
109
                    <span class="vexpl">Choose which interface the host to be woken up is connected to.</span></td>
110
                </tr>
111
                <tr>
112
				  <td width="22%" valign="top" class="vncellreq">MAC address</td>
113
				  <td width="78%" class="vtable">
114 4f3401e0 Bill Marquette
                      <input name="mac" type="text" class="formfld" id="mac" size="20" value="<?=htmlspecialchars($mac);?>">
115 5b237745 Scott Ullrich
                      <br>
116
                      Enter a MAC address <span class="vexpl"> in the following format: xx:xx:xx:xx:xx:xx</span></td></tr>
117
				<tr>
118
				  <td width="22%" valign="top">&nbsp;</td>
119 f0fe3d30 Scott Ullrich
				  <td width="78%">
120 5b237745 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Send">
121
				</td>
122
				</tr>
123
			</table>
124
			<span class="vexpl"><span class="red"><strong>Note:<br>
125
            </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>
126 f0fe3d30 Scott Ullrich
                      <br>
127 5b237745 Scott Ullrich
                      You may store MAC addresses below for your convenience.
128
Click the MAC address to wake up a computer. <br>
129
&nbsp;
130
<table width="100%" border="0" cellpadding="0" cellspacing="0">
131
                <tr>
132
                  <td width="15%" class="listhdrr">Interface</td>
133
                  <td width="25%" class="listhdrr">MAC address</td>
134
                  <td width="50%" class="listhdr">Description</td>
135
                  <td width="10%" class="list"></td>
136
				</tr>
137
			  <?php $i = 0; foreach ($a_wol as $wolent): ?>
138
                <tr>
139 5f9c0e68 Bill Marquette
                  <td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
140 5b237745 Scott Ullrich
                    <?php if ($wolent['interface'] == "lan")
141
							   echo "LAN";
142
						   else
143
						       echo $config['interfaces'][$wolent['interface']]['descr'];
144
					?>&nbsp;
145
                  </td>
146 5f9c0e68 Bill Marquette
                  <td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
147 5b237745 Scott Ullrich
                    <a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>&nbsp;
148
                  </td>
149 5f9c0e68 Bill Marquette
                  <td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
150 f0fe3d30 Scott Ullrich
                    <font color="#FFFFFF"><?=htmlspecialchars($wolent['descr']);?>&nbsp;
151 5b237745 Scott Ullrich
                  </td>
152 2d4a7bb1 Bill Marquette
                  <td valign="middle" nowrap class="list">
153
                    <table border="0" cellspacing="0" cellpadding="1">
154
                      <tr>
155 677c0869 Erik Kristensen
                        <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>
156
                        <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>
157 2d4a7bb1 Bill Marquette
                      </tr>
158
                    </table>
159
                  </td>
160
		</tr>
161
	        <?php $i++; endforeach; ?>
162 f0fe3d30 Scott Ullrich
                <tr>
163 5b237745 Scott Ullrich
                  <td class="list" colspan="3"></td>
164 2d4a7bb1 Bill Marquette
                  <td class="list">
165
                    <table border="0" cellspacing="0" cellpadding="1">
166
                      <tr>
167 677c0869 Erik Kristensen
                        <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"></a></td>
168 2d4a7bb1 Bill Marquette
                      </tr>
169
                    </table>
170
                  </td>
171
		</tr>
172 5b237745 Scott Ullrich
              </table>
173
</form>
174
<?php include("fend.inc"); ?>
175
</body>
176
</html>