Project

General

Profile

Download (6.31 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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_wol.php');
56

    
57
if (!is_array($config['wol']['wolentry'])) {
58
	$config['wol']['wolentry'] = array();
59
}
60
$a_wol = &$config['wol']['wolentry'];
61

    
62
if (is_numericint($_GET['id']))
63
	$id = $_GET['id'];
64
if (isset($_POST['id']) && is_numericint($_POST['id']))
65
	$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
else
73
{
74
	$pconfig['interface'] = $_GET['if'];
75
	$pconfig['mac'] = $_GET['mac'];
76
	$pconfig['descr'] = $_GET['descr'];
77
}
78

    
79
if ($_POST) {
80

    
81
	unset($input_errors);
82
	$pconfig = $_POST;
83

    
84
	/* input validation */
85
	$reqdfields = explode(" ", "interface mac");
86
	$reqdfieldsn = array(gettext("Interface"),gettext("MAC address"));
87
	
88
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
89

    
90
        /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
91
        $_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
92
	
93
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
94
		$input_errors[] = gettext("A valid MAC address must be specified.");
95
	}
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
		wol_sort();
108
		
109
		write_config();
110
		
111
		header("Location: services_wol.php");
112
		exit;
113
	}
114
}
115

    
116
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"),gettext("Edit"));
117
include("head.inc");
118

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