Project

General

Profile

Download (6.46 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
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
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
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
	pfSense_MODULE:	wol
34
*/
35

    
36
##|+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
function wolcmp($a, $b) {
44
	return strcmp($a['descr'], $b['descr']);
45
}
46

    
47
function wol_sort() {
48
        global $config;
49

    
50
        usort($config['wol']['wolentry'], "wolcmp");
51
}
52

    
53
require("guiconfig.inc");
54

    
55
if (isset($_POST['referer'])) {
56
	$referer = $_POST['referer'];
57
} else {
58
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_wol.php');
59
}
60

    
61
if (!is_array($config['wol']['wolentry'])) {
62
	$config['wol']['wolentry'] = array();
63
}
64
$a_wol = &$config['wol']['wolentry'];
65

    
66
if (is_numericint($_GET['id']))
67
	$id = $_GET['id'];
68
if (isset($_POST['id']) && is_numericint($_POST['id']))
69
	$id = $_POST['id'];
70

    
71
if (isset($id) && $a_wol[$id]) {
72
	$pconfig['interface'] = $a_wol[$id]['interface'];
73
	$pconfig['mac'] = $a_wol[$id]['mac'];
74
	$pconfig['descr'] = $a_wol[$id]['descr'];
75
}
76
else
77
{
78
	$pconfig['interface'] = $_GET['if'];
79
	$pconfig['mac'] = $_GET['mac'];
80
	$pconfig['descr'] = $_GET['descr'];
81
}
82

    
83
if ($_POST) {
84

    
85
	unset($input_errors);
86
	$pconfig = $_POST;
87

    
88
	/* input validation */
89
	$reqdfields = explode(" ", "interface mac");
90
	$reqdfieldsn = array(gettext("Interface"),gettext("MAC address"));
91
	
92
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
93

    
94
        /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
95
        $_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
96
	
97
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
98
		$input_errors[] = gettext("A valid MAC address must be specified.");
99
	}
100

    
101
	if (!$input_errors) {
102
		$wolent = array();
103
		$wolent['interface'] = $_POST['interface'];
104
		$wolent['mac'] = $_POST['mac'];
105
		$wolent['descr'] = $_POST['descr'];
106

    
107
		if (isset($id) && $a_wol[$id])
108
			$a_wol[$id] = $wolent;
109
		else
110
			$a_wol[] = $wolent;
111
		wol_sort();
112
		
113
		write_config();
114
		
115
		header("Location: services_wol.php");
116
		exit;
117
	}
118
}
119

    
120
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"),gettext("Edit"));
121
include("head.inc");
122

    
123
?>
124

    
125
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
126
<?php include("fbegin.inc"); ?>
127
<?php if ($input_errors) print_input_errors($input_errors); ?>
128
            <form action="services_wol_edit.php" method="post" name="iform" id="iform">
129
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="wol edit">
130
				<tr>
131
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit WOL entry");?></td>
132
				</tr>	
133
			  <tr> 
134
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
135
                  <td width="78%" class="vtable">
136
<select name="interface" class="formfld">
137
                      <?php 
138
					  $interfaces = get_configured_interface_with_descr();
139
					  foreach ($interfaces as $iface => $ifacename): ?>
140
                      <option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $pconfig['interface']) echo "selected=\"selected\""; ?>> 
141
                      <?=htmlspecialchars($ifacename);?>
142
                      </option>
143
                      <?php endforeach; ?>
144
                    </select> <br />
145
                    <span class="vexpl"><?=gettext("Choose which interface this host is connected to.");?></span></td>
146
                </tr>
147
				<tr>
148
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
149
                  <td width="78%" class="vtable"> 
150
                    <input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($pconfig['mac']);?>" />
151
                    <br /> 
152
                    <span class="vexpl"><?=gettext("Enter a MAC address  in the following format: ".
153
                    "xx:xx:xx:xx:xx:xx");?></span></td>
154
                </tr>
155
				<tr>
156
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
157
                  <td width="78%" class="vtable"> 
158
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
159
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here".
160
                   " for your reference (not parsed).");?></span></td>
161
                </tr>
162
                <tr>
163
                  <td width="22%" valign="top">&nbsp;</td>
164
                  <td width="78%"> 
165
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
166
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
167
                    <input name="referer" type="hidden" value="<?=$referer;?>" />
168
                    <?php if (isset($id) && $a_wol[$id]): ?>
169
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
170
                    <?php endif; ?>
171
                  </td>
172
                </tr>
173
              </table>
174
</form>
175
<?php include("fend.inc"); ?>
176
</body>
177
</html>
(172-172/252)