Project

General

Profile

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