Project

General

Profile

Download (6.07 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php 
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_wol_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
	
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
	
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
	
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
	
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 1d333258 Scott Ullrich
/*
32
	pfSense_MODULE:	wol
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-services-wakeonlan-edit
37
##|*NAME=Services: Wake on LAN: Edit page
38
##|*DESCR=Allow access to the 'Services: Wake on LAN: Edit' page.
39
##|*MATCH=services_wol_edit.php*
40
##|-PRIV
41
42 4504a769 Ermal Lu?i
function wolcmp($a, $b) {
43
	return strcmp($a['descr'], $b['descr']);
44
}
45 0d64af59 Ermal Lu?i
46 4504a769 Ermal Lu?i
function wol_sort() {
47
        global $config;
48 0d64af59 Ermal Lu?i
49
        usort($config['wol']['wolentry'], "wolcmp");
50
}
51 6b07c15a Matthew Grooms
52 5b237745 Scott Ullrich
require("guiconfig.inc");
53
54
if (!is_array($config['wol']['wolentry'])) {
55
	$config['wol']['wolentry'] = array();
56
}
57
$a_wol = &$config['wol']['wolentry'];
58
59 0e6cf71b Renato Botelho
if (is_numericint($_GET['id']))
60
	$id = $_GET['id'];
61
if (isset($_POST['id']) && is_numericint($_POST['id']))
62 5b237745 Scott Ullrich
	$id = $_POST['id'];
63
64
if (isset($id) && $a_wol[$id]) {
65
	$pconfig['interface'] = $a_wol[$id]['interface'];
66
	$pconfig['mac'] = $a_wol[$id]['mac'];
67
	$pconfig['descr'] = $a_wol[$id]['descr'];
68
}
69 7477df4f Scott Ullrich
else
70
{
71
	$pconfig['interface'] = $_GET['if'];
72
	$pconfig['mac'] = $_GET['mac'];
73
	$pconfig['descr'] = $_GET['descr'];
74
}
75 5b237745 Scott Ullrich
76
if ($_POST) {
77
78
	unset($input_errors);
79
	$pconfig = $_POST;
80
81
	/* input validation */
82
	$reqdfields = explode(" ", "interface mac");
83 593de5c8 Rafael Lucas
	$reqdfieldsn = array(gettext("Interface"),gettext("MAC address"));
84 5b237745 Scott Ullrich
	
85
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
86 4f3401e0 Bill Marquette
87
        /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
88
        $_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
89 5b237745 Scott Ullrich
	
90
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
91 593de5c8 Rafael Lucas
		$input_errors[] = gettext("A valid MAC address must be specified.");
92 5b237745 Scott Ullrich
	}
93
94
	if (!$input_errors) {
95
		$wolent = array();
96
		$wolent['interface'] = $_POST['interface'];
97
		$wolent['mac'] = $_POST['mac'];
98
		$wolent['descr'] = $_POST['descr'];
99
100
		if (isset($id) && $a_wol[$id])
101
			$a_wol[$id] = $wolent;
102
		else
103
			$a_wol[] = $wolent;
104 0e3aa71c Erik Fonnesbeck
		wol_sort();
105 5b237745 Scott Ullrich
		
106
		write_config();
107
		
108
		header("Location: services_wol.php");
109
		exit;
110
	}
111
}
112 4df96eff Scott Ullrich
113 593de5c8 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"),gettext("Edit"));
114 4df96eff Scott Ullrich
include("head.inc");
115
116 5b237745 Scott Ullrich
?>
117
118
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
119
<?php include("fbegin.inc"); ?>
120
<?php if ($input_errors) print_input_errors($input_errors); ?>
121
            <form action="services_wol_edit.php" method="post" name="iform" id="iform">
122
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
123 56d4e7fb Scott Ullrich
				<tr>
124 593de5c8 Rafael Lucas
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit WOL entry");?></td>
125 56d4e7fb Scott Ullrich
				</tr>	
126 5b237745 Scott Ullrich
			  <tr> 
127 593de5c8 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
128 5b237745 Scott Ullrich
                  <td width="78%" class="vtable">
129
<select name="interface" class="formfld">
130 e47499d5 Scott Ullrich
                      <?php 
131 3e321df2 Ermal Luçi
					  $interfaces = get_configured_interface_with_descr();
132 5b237745 Scott Ullrich
					  foreach ($interfaces as $iface => $ifacename): ?>
133 7ec05d27 Ermal Luçi
                      <option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $pconfig['interface']) echo "selected"; ?>> 
134 5b237745 Scott Ullrich
                      <?=htmlspecialchars($ifacename);?>
135
                      </option>
136
                      <?php endforeach; ?>
137
                    </select> <br>
138 593de5c8 Rafael Lucas
                    <span class="vexpl"><?=gettext("Choose which interface this host is connected to.");?></span></td>
139 5b237745 Scott Ullrich
                </tr>
140
				<tr>
141 593de5c8 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
142 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
143
                    <input name="mac" type="text" class="formfld" id="mac" size="20" value="<?=htmlspecialchars($pconfig['mac']);?>">
144
                    <br> 
145 593de5c8 Rafael Lucas
                    <span class="vexpl"><?=gettext("Enter a MAC address  in the following format: ".
146
                    "xx:xx:xx:xx:xx:xx");?><em></em></span></td>
147 5b237745 Scott Ullrich
                </tr>
148
				<tr>
149 593de5c8 Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
150 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
151
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
152 593de5c8 Rafael Lucas
                    <br> <span class="vexpl"><?=gettext("You may enter a description here".
153
                   " for your reference (not parsed).");?></span></td>
154 5b237745 Scott Ullrich
                </tr>
155
                <tr>
156
                  <td width="22%" valign="top">&nbsp;</td>
157
                  <td width="78%"> 
158 593de5c8 Rafael Lucas
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
159 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_wol[$id]): ?>
160 225a2f0b Scott Ullrich
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
161 5b237745 Scott Ullrich
                    <?php endif; ?>
162
                  </td>
163
                </tr>
164
              </table>
165
</form>
166
<?php include("fend.inc"); ?>
167
</body>
168
</html>