Project

General

Profile

Download (5.47 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/* $Id$ */
4
/*
5
	services_wol_edit.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
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
require("guiconfig.inc");
34

    
35
if (!is_array($config['wol']['wolentry'])) {
36
	$config['wol']['wolentry'] = array();
37
}
38
wol_sort();
39
$a_wol = &$config['wol']['wolentry'];
40

    
41
$id = $_GET['id'];
42
if (isset($_POST['id']))
43
	$id = $_POST['id'];
44

    
45
if (isset($id) && $a_wol[$id]) {
46
	$pconfig['interface'] = $a_wol[$id]['interface'];
47
	$pconfig['mac'] = $a_wol[$id]['mac'];
48
	$pconfig['descr'] = $a_wol[$id]['descr'];
49
}
50

    
51
if ($_POST) {
52

    
53
	unset($input_errors);
54
	$pconfig = $_POST;
55

    
56
	/* input validation */
57
	$reqdfields = explode(" ", "interface mac");
58
	$reqdfieldsn = explode(",", "Interface,MAC address");
59
	
60
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
61

    
62
        /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
63
        $_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
64
	
65
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
66
		$input_errors[] = "A valid MAC address must be specified.";
67
	}
68

    
69
	if (!$input_errors) {
70
		$wolent = array();
71
		$wolent['interface'] = $_POST['interface'];
72
		$wolent['mac'] = $_POST['mac'];
73
		$wolent['descr'] = $_POST['descr'];
74

    
75
		if (isset($id) && $a_wol[$id])
76
			$a_wol[$id] = $wolent;
77
		else
78
			$a_wol[] = $wolent;
79
		
80
		write_config();
81
		
82
		header("Location: services_wol.php");
83
		exit;
84
	}
85
}
86

    
87
$pgtitle = "Services: Wake on LAN: Edit entry";
88
include("head.inc");
89

    
90
?>
91

    
92
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
93
<?php include("fbegin.inc"); ?>
94
<p class="pgtitle">Services: Wake on LAN: Edit entry</p>
95
<?php if ($input_errors) print_input_errors($input_errors); ?>
96
            <form action="services_wol_edit.php" method="post" name="iform" id="iform">
97
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
98
			  <tr> 
99
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
100
                  <td width="78%" class="vtable">
101
<select name="interface" class="formfld">
102
                      <?php $interfaces = array('lan' => 'LAN');
103
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
104
					    if (isset($config['interfaces']['opt' . $i]['enable']) &&
105
							!$config['interfaces']['opt' . $i]['bridge'])
106
					  		$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
107
					  }
108
					  foreach ($interfaces as $iface => $ifacename): ?>
109
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
110
                      <?=htmlspecialchars($ifacename);?>
111
                      </option>
112
                      <?php endforeach; ?>
113
                    </select> <br>
114
                    <span class="vexpl">Choose which interface this host is connected to.</span></td>
115
                </tr>
116
				<tr>
117
                  <td width="22%" valign="top" class="vncellreq">MAC address</td>
118
                  <td width="78%" class="vtable"> 
119
                    <input name="mac" type="text" class="formfld" id="mac" size="20" value="<?=htmlspecialchars($pconfig['mac']);?>">
120
                    <br> 
121
                    <span class="vexpl">Enter a MAC address  in the following format: 
122
                    xx:xx:xx:xx:xx:xx<em></em></span></td>
123
                </tr>
124
				<tr>
125
                  <td width="22%" valign="top" class="vncell">Description</td>
126
                  <td width="78%" class="vtable"> 
127
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
128
                    <br> <span class="vexpl">You may enter a description here
129
                    for your reference (not parsed).</span></td>
130
                </tr>
131
                <tr>
132
                  <td width="22%" valign="top">&nbsp;</td>
133
                  <td width="78%"> 
134
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
135
                    <?php if (isset($id) && $a_wol[$id]): ?>
136
                    <input name="id" type="hidden" value="<?=$id;?>">
137
                    <?php endif; ?>
138
                  </td>
139
                </tr>
140
              </table>
141
</form>
142
<?php include("fend.inc"); ?>
143
</body>
144
</html>
(93-93/127)