Project

General

Profile

Download (5.54 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
	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
require("guiconfig.inc");
33
34
if (!is_array($config['wol']['wolentry'])) {
35
	$config['wol']['wolentry'] = array();
36
}
37
wol_sort();
38
$a_wol = &$config['wol']['wolentry'];
39
40
$id = $_GET['id'];
41
if (isset($_POST['id']))
42
	$id = $_POST['id'];
43
44
if (isset($id) && $a_wol[$id]) {
45
	$pconfig['interface'] = $a_wol[$id]['interface'];
46
	$pconfig['mac'] = $a_wol[$id]['mac'];
47
	$pconfig['descr'] = $a_wol[$id]['descr'];
48
}
49 7477df4f Scott Ullrich
else
50
{
51
	$pconfig['interface'] = $_GET['if'];
52
	$pconfig['mac'] = $_GET['mac'];
53
	$pconfig['descr'] = $_GET['descr'];
54
}
55 5b237745 Scott Ullrich
56
if ($_POST) {
57
58
	unset($input_errors);
59
	$pconfig = $_POST;
60
61
	/* input validation */
62
	$reqdfields = explode(" ", "interface mac");
63
	$reqdfieldsn = explode(",", "Interface,MAC address");
64
	
65
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
66 4f3401e0 Bill Marquette
67
        /* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
68
        $_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
69 5b237745 Scott Ullrich
	
70
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
71
		$input_errors[] = "A valid MAC address must be specified.";
72
	}
73
74
	if (!$input_errors) {
75
		$wolent = array();
76
		$wolent['interface'] = $_POST['interface'];
77
		$wolent['mac'] = $_POST['mac'];
78
		$wolent['descr'] = $_POST['descr'];
79
80
		if (isset($id) && $a_wol[$id])
81
			$a_wol[$id] = $wolent;
82
		else
83
			$a_wol[] = $wolent;
84
		
85
		write_config();
86
		
87
		header("Location: services_wol.php");
88
		exit;
89
	}
90
}
91 4df96eff Scott Ullrich
92 c44f1bd5 Bill Marquette
$pgtitle = "Services: Wake on LAN: Edit";
93 4df96eff Scott Ullrich
include("head.inc");
94
95 5b237745 Scott Ullrich
?>
96
97
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
98
<?php include("fbegin.inc"); ?>
99 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
100 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
101
            <form action="services_wol_edit.php" method="post" name="iform" id="iform">
102
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
103
			  <tr> 
104
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
105
                  <td width="78%" class="vtable">
106
<select name="interface" class="formfld">
107
                      <?php $interfaces = array('lan' => 'LAN');
108
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
109
					    if (isset($config['interfaces']['opt' . $i]['enable']) &&
110
							!$config['interfaces']['opt' . $i]['bridge'])
111
					  		$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
112
					  }
113
					  foreach ($interfaces as $iface => $ifacename): ?>
114
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
115
                      <?=htmlspecialchars($ifacename);?>
116
                      </option>
117
                      <?php endforeach; ?>
118
                    </select> <br>
119
                    <span class="vexpl">Choose which interface this host is connected to.</span></td>
120
                </tr>
121
				<tr>
122
                  <td width="22%" valign="top" class="vncellreq">MAC address</td>
123
                  <td width="78%" class="vtable"> 
124
                    <input name="mac" type="text" class="formfld" id="mac" size="20" value="<?=htmlspecialchars($pconfig['mac']);?>">
125
                    <br> 
126
                    <span class="vexpl">Enter a MAC address  in the following format: 
127
                    xx:xx:xx:xx:xx:xx<em></em></span></td>
128
                </tr>
129
				<tr>
130
                  <td width="22%" valign="top" class="vncell">Description</td>
131
                  <td width="78%" class="vtable"> 
132
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
133
                    <br> <span class="vexpl">You may enter a description here
134
                    for your reference (not parsed).</span></td>
135
                </tr>
136
                <tr>
137
                  <td width="22%" valign="top">&nbsp;</td>
138
                  <td width="78%"> 
139 fc01e414 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
140 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_wol[$id]): ?>
141
                    <input name="id" type="hidden" value="<?=$id;?>">
142
                    <?php endif; ?>
143
                  </td>
144
                </tr>
145
              </table>
146
</form>
147
<?php include("fend.inc"); ?>
148
</body>
149
</html>