Project

General

Profile

Download (5.77 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
	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

    
32
##|+PRIV
33
##|*IDENT=page-services-wakeonlan-edit
34
##|*NAME=Services: Wake on LAN: Edit page
35
##|*DESCR=Allow access to the 'Services: Wake on LAN: Edit' page.
36
##|*MATCH=services_wol_edit.php*
37
##|-PRIV
38

    
39
function wolcmp($a, $b) {
40
	return strcmp($a['descr'], $b['descr']);
41
}
42

    
43
function wol_sort() {
44
        global $config;
45

    
46
        usort($config['wol']['wolentry'], "wolcmp");
47
}
48

    
49
require("guiconfig.inc");
50

    
51
if (!is_array($config['wol']['wolentry'])) {
52
	$config['wol']['wolentry'] = array();
53
}
54
wol_sort();
55
$a_wol = &$config['wol']['wolentry'];
56

    
57
$id = $_GET['id'];
58
if (isset($_POST['id']))
59
	$id = $_POST['id'];
60

    
61
if (isset($id) && $a_wol[$id]) {
62
	$pconfig['interface'] = $a_wol[$id]['interface'];
63
	$pconfig['mac'] = $a_wol[$id]['mac'];
64
	$pconfig['descr'] = $a_wol[$id]['descr'];
65
}
66
else
67
{
68
	$pconfig['interface'] = $_GET['if'];
69
	$pconfig['mac'] = $_GET['mac'];
70
	$pconfig['descr'] = $_GET['descr'];
71
}
72

    
73
if ($_POST) {
74

    
75
	unset($input_errors);
76
	$pconfig = $_POST;
77

    
78
	/* input validation */
79
	$reqdfields = explode(" ", "interface mac");
80
	$reqdfieldsn = explode(",", "Interface,MAC address");
81
	
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
83

    
84
        /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
85
        $_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
86
	
87
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
88
		$input_errors[] = "A valid MAC address must be specified.";
89
	}
90

    
91
	if (!$input_errors) {
92
		$wolent = array();
93
		$wolent['interface'] = $_POST['interface'];
94
		$wolent['mac'] = $_POST['mac'];
95
		$wolent['descr'] = $_POST['descr'];
96

    
97
		wol_sort();
98
		if (isset($id) && $a_wol[$id])
99
			$a_wol[$id] = $wolent;
100
		else
101
			$a_wol[] = $wolent;
102
		
103
		write_config();
104
		
105
		header("Location: services_wol.php");
106
		exit;
107
	}
108
}
109

    
110
$pgtitle = array("Services","Wake on LAN","Edit");
111
include("head.inc");
112

    
113
?>
114

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