Project

General

Profile

Download (6.24 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 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_wol.php');
55
56 5b237745 Scott Ullrich
if (!is_array($config['wol']['wolentry'])) {
57
	$config['wol']['wolentry'] = array();
58
}
59
$a_wol = &$config['wol']['wolentry'];
60
61 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
62
	$id = $_GET['id'];
63
if (isset($_POST['id']) && is_numericint($_POST['id']))
64 5b237745 Scott Ullrich
	$id = $_POST['id'];
65
66
if (isset($id) && $a_wol[$id]) {
67
	$pconfig['interface'] = $a_wol[$id]['interface'];
68
	$pconfig['mac'] = $a_wol[$id]['mac'];
69
	$pconfig['descr'] = $a_wol[$id]['descr'];
70
}
71 7477df4f Scott Ullrich
else
72
{
73
	$pconfig['interface'] = $_GET['if'];
74
	$pconfig['mac'] = $_GET['mac'];
75
	$pconfig['descr'] = $_GET['descr'];
76
}
77 5b237745 Scott Ullrich
78
if ($_POST) {
79
80
	unset($input_errors);
81
	$pconfig = $_POST;
82
83
	/* input validation */
84
	$reqdfields = explode(" ", "interface mac");
85 593de5c8 Rafael Lucas
	$reqdfieldsn = array(gettext("Interface"),gettext("MAC address"));
86 5b237745 Scott Ullrich
	
87 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
88 4f3401e0 Bill Marquette
89
        /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
90
        $_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
91 5b237745 Scott Ullrich
	
92
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
93 593de5c8 Rafael Lucas
		$input_errors[] = gettext("A valid MAC address must be specified.");
94 5b237745 Scott Ullrich
	}
95
96
	if (!$input_errors) {
97
		$wolent = array();
98
		$wolent['interface'] = $_POST['interface'];
99
		$wolent['mac'] = $_POST['mac'];
100
		$wolent['descr'] = $_POST['descr'];
101
102
		if (isset($id) && $a_wol[$id])
103
			$a_wol[$id] = $wolent;
104
		else
105
			$a_wol[] = $wolent;
106 0e3aa71c Erik Fonnesbeck
		wol_sort();
107 5b237745 Scott Ullrich
		
108
		write_config();
109
		
110
		header("Location: services_wol.php");
111
		exit;
112
	}
113
}
114 4df96eff Scott Ullrich
115 593de5c8 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"),gettext("Edit"));
116 4df96eff Scott Ullrich
include("head.inc");
117
118 5b237745 Scott Ullrich
?>
119
120
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
121
<?php include("fbegin.inc"); ?>
122
<?php if ($input_errors) print_input_errors($input_errors); ?>
123
            <form action="services_wol_edit.php" method="post" name="iform" id="iform">
124 cdb782b7 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="wol edit">
125 56d4e7fb Scott Ullrich
				<tr>
126 593de5c8 Rafael Lucas
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit WOL entry");?></td>
127 56d4e7fb Scott Ullrich
				</tr>	
128 5b237745 Scott Ullrich
			  <tr> 
129 593de5c8 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
130 5b237745 Scott Ullrich
                  <td width="78%" class="vtable">
131
<select name="interface" class="formfld">
132 e47499d5 Scott Ullrich
                      <?php 
133 3e321df2 Ermal Luçi
					  $interfaces = get_configured_interface_with_descr();
134 5b237745 Scott Ullrich
					  foreach ($interfaces as $iface => $ifacename): ?>
135 cdb782b7 Colin Fleming
                      <option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $pconfig['interface']) echo "selected=\"selected\""; ?>> 
136 5b237745 Scott Ullrich
                      <?=htmlspecialchars($ifacename);?>
137
                      </option>
138
                      <?php endforeach; ?>
139 8cd558b6 ayvis
                    </select> <br />
140 593de5c8 Rafael Lucas
                    <span class="vexpl"><?=gettext("Choose which interface this host is connected to.");?></span></td>
141 5b237745 Scott Ullrich
                </tr>
142
				<tr>
143 593de5c8 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
144 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
145 cdb782b7 Colin Fleming
                    <input name="mac" type="text" class="formfld" id="mac" size="20" value="<?=htmlspecialchars($pconfig['mac']);?>" />
146 8cd558b6 ayvis
                    <br /> 
147 593de5c8 Rafael Lucas
                    <span class="vexpl"><?=gettext("Enter a MAC address  in the following format: ".
148 cdb782b7 Colin Fleming
                    "xx:xx:xx:xx:xx:xx");?></span></td>
149 5b237745 Scott Ullrich
                </tr>
150
				<tr>
151 593de5c8 Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
152 5b237745 Scott Ullrich
                  <td width="78%" class="vtable"> 
153 cdb782b7 Colin Fleming
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
154 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
155 593de5c8 Rafael Lucas
                   " for your reference (not parsed).");?></span></td>
156 5b237745 Scott Ullrich
                </tr>
157
                <tr>
158
                  <td width="22%" valign="top">&nbsp;</td>
159
                  <td width="78%"> 
160 62424bdb Renato Botelho
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
161
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
162 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_wol[$id]): ?>
163 cdb782b7 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
164 5b237745 Scott Ullrich
                    <?php endif; ?>
165
                  </td>
166
                </tr>
167
              </table>
168
</form>
169
<?php include("fend.inc"); ?>
170
</body>
171
</html>