1
|
<?php
|
2
|
/*
|
3
|
vpn_ipsec_keys_edit.php
|
4
|
part of m0n0wall (http://m0n0.ch/wall)
|
5
|
|
6
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
19
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
|
31
|
##|+PRIV
|
32
|
##|*IDENT=page-vpn-ipsec-editkeys
|
33
|
##|*NAME=VPN: IPsec: Edit Pre-Shared Keys
|
34
|
##|*DESCR=Allow access to the 'VPN: IPsec: Edit Pre-Shared Keys' page.
|
35
|
##|*MATCH=vpn_ipsec_keys_edit.php*
|
36
|
##|-PRIV
|
37
|
|
38
|
require("functions.inc");
|
39
|
require("guiconfig.inc");
|
40
|
require_once("ipsec.inc");
|
41
|
require_once("vpn.inc");
|
42
|
|
43
|
if (!is_array($config['ipsec']['mobilekey'])) {
|
44
|
$config['ipsec']['mobilekey'] = array();
|
45
|
}
|
46
|
ipsec_mobilekey_sort();
|
47
|
$a_secret = &$config['ipsec']['mobilekey'];
|
48
|
|
49
|
if (is_numericint($_GET['id']))
|
50
|
$id = $_GET['id'];
|
51
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
52
|
$id = $_POST['id'];
|
53
|
|
54
|
if (isset($id) && $a_secret[$id]) {
|
55
|
$pconfig['ident'] = $a_secret[$id]['ident'];
|
56
|
$pconfig['psk'] = $a_secret[$id]['pre-shared-key'];
|
57
|
}
|
58
|
|
59
|
if ($_POST) {
|
60
|
$userids = array();
|
61
|
foreach ($config['system']['user'] as $uid => $user) {
|
62
|
$userids[$user['name']] = $uid;
|
63
|
}
|
64
|
|
65
|
unset($input_errors);
|
66
|
$pconfig = $_POST;
|
67
|
|
68
|
/* input validation */
|
69
|
$reqdfields = explode(" ", "ident psk");
|
70
|
$reqdfieldsn = array(gettext("Identifier"),gettext("Pre-Shared Key"));
|
71
|
|
72
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
73
|
|
74
|
if (preg_match("/[^a-zA-Z0-9@\.\-]/", $_POST['ident']))
|
75
|
$input_errors[] = gettext("The identifier contains invalid characters.");
|
76
|
|
77
|
if (array_key_exists($_POST['ident'], $userids))
|
78
|
$input_errors[] = gettext("A user with this name already exists. Add the key to the user instead.");
|
79
|
unset($userids);
|
80
|
|
81
|
if (isset($_POST['psk']) && !preg_match('/^[[:ascii:]]*$/', $_POST['psk']))
|
82
|
$input_errors[] = gettext("Pre-Shared Key contains invalid characters.");
|
83
|
|
84
|
if (!$input_errors && !(isset($id) && $a_secret[$id])) {
|
85
|
/* make sure there are no dupes */
|
86
|
foreach ($a_secret as $secretent) {
|
87
|
if ($secretent['ident'] == $_POST['ident']) {
|
88
|
$input_errors[] = gettext("Another entry with the same identifier already exists.");
|
89
|
break;
|
90
|
}
|
91
|
}
|
92
|
}
|
93
|
|
94
|
if (!$input_errors) {
|
95
|
|
96
|
if (isset($id) && $a_secret[$id])
|
97
|
$secretent = $a_secret[$id];
|
98
|
|
99
|
$secretent['ident'] = $_POST['ident'];
|
100
|
$secretent['pre-shared-key'] = $_POST['psk'];
|
101
|
$text = "";
|
102
|
|
103
|
if (isset($id) && $a_secret[$id]) {
|
104
|
$a_secret[$id] = $secretent;
|
105
|
$text = gettext("Edited");
|
106
|
} else {
|
107
|
$a_secret[] = $secretent;
|
108
|
$text = gettext("Added");
|
109
|
}
|
110
|
|
111
|
write_config("{$text} IPsec Pre-Shared Keys");
|
112
|
mark_subsystem_dirty('ipsec');
|
113
|
|
114
|
header("Location: vpn_ipsec_keys.php");
|
115
|
exit;
|
116
|
}
|
117
|
}
|
118
|
|
119
|
$pgtitle = gettext("VPN: IPsec: Edit Pre-Shared Key");
|
120
|
$shortcut_section = "ipsec";
|
121
|
|
122
|
include("head.inc");
|
123
|
|
124
|
?>
|
125
|
|
126
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
127
|
<?php include("fbegin.inc"); ?>
|
128
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
129
|
<form action="vpn_ipsec_keys_edit.php" method="post" name="iform" id="iform">
|
130
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="vpn ipsec keys edit">
|
131
|
<tr>
|
132
|
<td valign="top" class="vncellreq"><?=gettext("Identifier"); ?></td>
|
133
|
<td class="vtable">
|
134
|
<?=$mandfldhtml;?><input name="ident" type="text" class="formfld unknown" id="ident" size="30" value="<?=htmlspecialchars($pconfig['ident']);?>" />
|
135
|
<br />
|
136
|
<?=gettext("This can be either an IP address, fully qualified domain name or an e-mail address"); ?>.
|
137
|
</td>
|
138
|
</tr>
|
139
|
<tr>
|
140
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Pre-Shared Key"); ?></td>
|
141
|
<td width="78%" class="vtable">
|
142
|
<?=$mandfldhtml;?><input name="psk" type="text" class="formfld unknown" id="psk" size="40" value="<?=htmlspecialchars($pconfig['psk']);?>" />
|
143
|
</td>
|
144
|
</tr>
|
145
|
<tr>
|
146
|
<td width="22%" valign="top"> </td>
|
147
|
<td width="78%">
|
148
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
|
149
|
<?php if (isset($id) && $a_secret[$id]): ?>
|
150
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
151
|
<?php endif; ?>
|
152
|
</td>
|
153
|
</tr>
|
154
|
<tr>
|
155
|
<td colspan="4">
|
156
|
<p>
|
157
|
<span class="vexpl">
|
158
|
<span class="red">
|
159
|
<strong><?=gettext("Note"); ?>:<br /></strong>
|
160
|
</span>
|
161
|
<?=gettext("PSK for any user can be set by using an identifier of any/ANY");?>
|
162
|
</span>
|
163
|
</p>
|
164
|
</td>
|
165
|
</tr>
|
166
|
</table>
|
167
|
</form>
|
168
|
<?php include("fend.inc"); ?>
|
169
|
</body>
|
170
|
</html>
|