1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
<?php
/*
vpn_openvpn_ccd_edit.php
Copyright (C) 2005 Peter Allgeyer (allgeyer@web.de).
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
$pgtitle = array("VPN", "OpenVPN", "Edit client-specific configuration");
require("guiconfig.inc");
require_once("openvpn.inc");
if (!is_array($config['ovpn']))
$config['ovpn'] = array();
if (!is_array($config['ovpn']['server']))
$config['ovpn']['server'] = array();
if (!is_array($config['ovpn']['server']['ccd']))
$config['ovpn']['server']['ccd'] = array();
$ovpnccd =& $config['ovpn']['server']['ccd'];
$id = $_GET['id'];
if (isset($_POST['id']))
$id = $_POST['id'];
if (isset($id) && $ovpnccd[$id]) {
$pconfig = $config['ovpn']['server']['ccd'][$id];
if (isset($ovpnccd[$id]['enable']))
$pconfig['enable'] = true;
if (is_array($config['ovpn']['server']['ccd'][$id]['options'])) {
$pconfig['options'] = "";
foreach ($ovpnccd[$id]['options']['option'] as $optent) {
$pconfig['options'] .= $optent . "\n";
}
$pconfig['options'] = rtrim($pconfig['options']);
}
} else {
/* creating - set defaults */
$pconfig = array();
$pconfig['enable'] = true;
}
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "cn");
$reqdfieldsn = explode(",", "Common name");
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
if (preg_match("/[^a-zA-Z0-9\.\-_\:\/\@]/", $_POST['cn']))
$input_errors[] = "The common name contains invalid characters.";
if ($_POST['psh_pingrst'] && $_POST['psh_pingexit'])
$input_errors[] = "Ping-restart and Ping-exit are mutually exclusive and cannot be used together";
if ($_POST['psh_rtedelay'] && !is_numeric($_POST['psh_rtedelay_int']))
$input_errors[] = "Route-delay needs a numerical interval setting.";
if ($_POST['psh_inact'] && !is_numeric($_POST['psh_inact_int']))
$input_errors[] = "Inactive needs a numerical interval setting.";
if ($_POST['psh_ping'] && !is_numeric($_POST['psh_ping_int']))
$input_errors[] = "Ping needs a numerical interval setting.";
if ($_POST['psh_pingexit'] && !is_numeric($_POST['psh_pingexit_int']))
$input_errors[] = "Ping-exit needs a numerical interval setting.";
if ($_POST['psh_pingrst'] && !is_numeric($_POST['psh_pingrst_int']))
$input_errors[] = "Ping-restart needs a numerical interval setting.";
/* Editing an existing entry? */
if (!$input_errors && !(isset($id) && $ovpnccd[$id])) {
/* make sure there are no dupes */
foreach ($ovpnccd as $ccdent) {
if ($ccdent['cn'] == $_POST['cn']) {
$input_errors[] = "Another entry with the same common name already exists.";
break;
}
}
}
if (isset($id) && $ovpnccd[$id]) {
$ccdent = $ovpnccd[$id];
/* Has the enable/disable state changed? */
if (isset($ccdent['enable']) && isset($_POST['disabled'])) {
/* status changed to disabled */
touch($d_ovpnccddirty_path);
}
/* status changed to enable */
if (!isset($ccdent['enable']) && !isset($_POST['disabled'])) {
/* touch($d_sysrebootreqd_path); */
touch($d_ovpnccddirty_path);
}
}
if (!$input_errors) {
$ccdent = array();
if (isset($id) && $ovpnccd[$id])
$ccdent = $ovpnccd[$id];
$ccdent['cn'] = $_POST['cn'];
$ccdent['descr'] = $_POST['descr'];
$ccdent['enable'] = $_POST['disabled'] ? false : true;
$ccdent['disable'] = $_POST['disable'] ? true : false;
if (!is_array($options))
$options = array();
if (!is_array($ccdent['options']))
$ccdent['options'] = array();
$options['option'] = array_map('trim', explode("\n", trim($_POST['options'])));
$ccdent['options'] = $options;
$ccdent['psh_reset'] = $_POST['psh_reset'] ? true : false;
$ccdent['psh_options']['redir'] = $_POST['psh_redir'] ? true : false;
$ccdent['psh_options']['redir_loc'] = $_POST['psh_redir_loc'] ? true : false;
$ccdent['psh_options']['rtedelay'] = $_POST['psh_rtedelay'] ? true : false;
$ccdent['psh_options']['inact'] = $_POST['psh_inact'] ? true : false;
$ccdent['psh_options']['ping'] = $_POST['psh_ping'] ? true : false;
$ccdent['psh_options']['pingrst'] = $_POST['psh_pingrst'] ? true : false;
$ccdent['psh_options']['pingexit'] = $_POST['psh_pingexit'] ? true : false;
unset($ccdent['psh_options']['rtedelay_int']);
unset($ccdent['psh_options']['inact_int']);
unset($ccdent['psh_options']['ping_int']);
unset($ccdent['psh_options']['pingrst_int']);
unset($ccdent['psh_options']['pingexit_int']);
if ($_POST['psh_rtedelay_int'])
$ccdent['psh_options']['rtedelay_int'] = $_POST['psh_rtedelay_int'];
if ($_POST['psh_inact_int'])
$ccdent['psh_options']['inact_int'] = $_POST['psh_inact_int'];
if ($_POST['psh_ping_int'])
$ccdent['psh_options']['ping_int'] = $_POST['psh_ping_int'];
if ($_POST['psh_pingrst_int'])
$ccdent['psh_options']['pingrst_int'] = $_POST['psh_pingrst_int'];
if ($_POST['psh_pingexit_int'])
$ccdent['psh_options']['pingexit_int'] = $_POST['psh_pingexit_int'];
if (isset($id) && $ovpnccd[$id])
$ovpnccd[$id] = $ccdent;
else
$ovpnccd[] = $ccdent;
write_config();
touch($d_ovpnccddirty_path);
header("Location: vpn_openvpn_ccd.php");
exit;
} else {
$pconfig = $_POST;
$pconfig['enable'] = "true";
if (isset($_POST['disabled']))
unset($pconfig['enable']);
$pconfig['psh_reset'] = $_POST['psh_reset'];
$pconfig['psh_options']['redir'] = $_POST['psh_redir'];
$pconfig['psh_options']['redir_loc'] = $_POST['psh_redir_loc'];
$pconfig['psh_options']['rtedelay'] = $_POST['psh_rtedelay'];
$pconfig['psh_options']['inact'] = $_POST['psh_inact'];
$pconfig['psh_options']['ping'] = $_POST['psh_ping'];
$pconfig['psh_options']['pingrst'] = $_POST['psh_pingrst'];
$pconfig['psh_options']['pingexit'] = $_POST['psh_pingexit'];
$pconfig['psh_options']['rtedelay_int'] = $_POST['psh_rtedelay_int'];
$pconfig['psh_options']['inact_int'] = $_POST['psh_inact_int'];
$pconfig['psh_options']['ping_int'] = $_POST['psh_ping_int'];
$pconfig['psh_options']['pingrst_int'] = $_POST['psh_pingrst_int'];
$pconfig['psh_options']['pingexit_int'] = $_POST['psh_pingexit_int'];
}
}
$pgtitle = "VPN: OpenVPN: Edit client-specific configuration";
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<?php if ($input_errors) print_input_errors($input_errors);?>
<script language="JavaScript">
function enable_change(enable_over) {
var endis;
endis = !(!document.iform.disabled.checked || enable_over);
document.iform.cn.disabled = endis;
document.iform.disable.disabled = endis;
document.iform.descr.disabled = endis;
document.iform.psh_reset.disabled = endis;
document.iform.psh_redir.disabled = endis;
document.iform.psh_redir_loc.disabled = endis;
document.iform.psh_rtedelay.disabled = endis;
document.iform.psh_rtedelay_int.disabled = endis;
document.iform.psh_inact.disabled = endis;
document.iform.psh_inact_int.disabled = endis;
document.iform.psh_ping.disabled = endis;
document.iform.psh_ping_int.disabled = endis;
document.iform.psh_pingexit.disabled = endis;
document.iform.psh_pingexit_int.disabled = endis;
document.iform.psh_pingrst.disabled = endis;
document.iform.psh_pingrst_int.disabled = endis;
document.iform.options.disabled = endis;
if (!document.iform.disabled.checked) {
push_change(false);
disable_change(false);
}
}
function disable_change(enable_over) {
var endis;
endis = !(!document.iform.disable.checked || enable_over);
document.iform.psh_reset.disabled = endis;
document.iform.psh_redir.disabled = endis;
document.iform.psh_redir_loc.disabled = endis;
document.iform.psh_rtedelay.disabled = endis;
document.iform.psh_rtedelay_int.disabled = endis;
document.iform.psh_inact.disabled = endis;
document.iform.psh_inact_int.disabled = endis;
document.iform.psh_ping.disabled = endis;
document.iform.psh_ping_int.disabled = endis;
document.iform.psh_pingexit.disabled = endis;
document.iform.psh_pingexit_int.disabled = endis;
document.iform.psh_pingrst.disabled = endis;
document.iform.psh_pingrst_int.disabled = endis;
document.iform.options.disabled = endis;
if (!document.iform.disable.checked) {
push_change(enable_over);
}
}
function push_change(enable_over) {
var endis;
endis = !(document.iform.psh_reset.checked || enable_over);
document.iform.psh_redir.disabled = endis;
document.iform.psh_redir_loc.disabled = endis;
document.iform.psh_rtedelay.disabled = endis;
document.iform.psh_rtedelay_int.disabled = endis;
document.iform.psh_inact.disabled = endis;
document.iform.psh_inact_int.disabled = endis;
document.iform.psh_ping.disabled = endis;
document.iform.psh_ping_int.disabled = endis;
document.iform.psh_pingexit.disabled = endis;
document.iform.psh_pingexit_int.disabled = endis;
document.iform.psh_pingrst.disabled = endis;
document.iform.psh_pingrst_int.disabled = endis;
}
//-->
</script>
<form action="vpn_openvpn_ccd_edit.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
<strong><span class="red">WARNING: This feature is experimental and modifies your optional interface configuration.
Backup your configuration before using OpenVPN, and restore it before upgrading.<br> <br>
</span></strong>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
<td width="22%" valign="top" class="vncellreq">Disabled</td>
<td width="78%" class="vtable">
<input name="disabled" type="checkbox" value="yes" onclick="enable_change(false)" <?php if (!isset($pconfig['enable'])) echo "checked"; ?>>
<strong>Disable this entry</strong><br>
<span class="vexpl">Set this option to disable this client-specific configuration
without removing it from the list.</span></td>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">Common Name</td>
<td width="78%" class="vtable">
<input name="cn" type="text" class="formfld" id="cn" size="40" value="<?=htmlspecialchars($pconfig['cn']);?>">
<br><span class="vexpl">Enter client's X.509 common name here.</span></td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Description</td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
<br><span class="vexpl">You may enter a description here for your reference (not parsed).</span></td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Block client</td>
<td width="78%" class="vtable">
<input name="disable" type="checkbox" value="yes" onclick="disable_change(false)" <?php if (isset($pconfig['disable'])) echo "checked"; ?>>
<strong>Disable this client from connecting</strong><br>
<span class="vexpl">Disable a particular client (based on the common name) from connecting.
Don't use this option to disable a client due to key
or password compromise. Use a CRL (certificate revocation list)
instead.</span></td>
</td>
</tr>
<tr>
<tr>
<td colspan="2" valign="top" height="16"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic">Push options</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Client-Push Inheritation</td>
<td width="78%" class="vtable">
<input type="checkbox" name="psh_reset" value="yes" onchange="push_change(false)" <?php if (isset($pconfig['psh_reset'])) echo "checked"; ?>>Push reset
<br><span class="vexpl">Set this option to on, if you don't want to inherit
the global push list for this client from the server page.</span>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Client-push options</td>
<td width="78%" class="vtable">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="checkbox" name="psh_redir" value="yes" <?php if (isset($pconfig['psh_options']['redir'])) echo "checked"; ?>>
Redirect-gateway</td>
<td> </td>
<td><input type="checkbox" name="psh_redir_loc" value="yes" <?php if (isset($pconfig['psh_options']['redir_loc'])) echo "checked"; ?>>
Local</td>
</tr>
<tr>
<td><input type="checkbox" name="psh_rtedelay" value="yes" <?php if (isset($pconfig['psh_options']['rtedelay'])) echo "checked"; ?>> Route-delay</td>
<td width="16"> </td>
<td><input type="text" name="psh_rtedelay_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['rtedelay_int']?>"> seconds</td>
</tr>
<tr>
<td><input type="checkbox" name="psh_inact" value="yes" <?php if (isset($pconfig['psh_options']['inact'])) echo "checked"; ?>>
Inactive</td>
<td> </td>
<td><input type="text" name="psh_inact_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['inact_int']?>">
seconds</td>
</tr>
<tr>
<td><input type="checkbox" name="psh_ping" value="yes" <?php if (isset($pconfig['psh_options']['ping'])) echo "checked"; ?>> Ping</td>
<td> </td>
<td>Interval: <input type="text" name="psh_ping_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['ping_int']?>"> seconds</td>
</tr>
<tr>
<td><input type="checkbox" name="psh_pingexit" value="yes" <?php if (isset($pconfig['psh_options']['pingexit'])) echo "checked"; ?>> Ping-exit</td>
<td> </td>
<td>Interval: <input type="text" name="psh_pingexit_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingexit_int']?>"> seconds</td>
</tr>
<tr>
<td><input type="checkbox" name="psh_pingrst" value="yes" <?php if (isset($pconfig['psh_options']['pingrst'])) echo "checked"; ?>> Ping-restart</td>
<td> </td>
<td>Interval: <input type="text" name="psh_pingrst_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingrst_int']?>"> seconds</td>
</tr>
</table></td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell">Custom client options</td>
<td width="78%" class="vtable">
<span>The following options are legal in a client-specific context:<br>
push, push-reset, iroute, ifconfig-push and config.</span><br>
<textarea name="options" id="options" cols="65" rows="4" class="formpre"><?=htmlspecialchars($pconfig['options']);?></textarea>
<strong><span class="red">Note:</span></strong><br>
Commands in here aren't supported.</span></strong>
</td>
</tr>
<tr>
<td width="22%" valign="top"> </td>
<td width="78%">
<input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true);disable_change(true)">
<?php if (isset($id)): ?>
<input name="id" type="hidden" value="<?=$id;?>">
<?php endif; ?>
</td>
</tr>
</table>
</form>
<script language="JavaScript">
<!--
disable_change(false);
push_change(false);
enable_change(false);
//-->
</script>
<?php include("fend.inc");
?>
|