summaryrefslogtreecommitdiffstats
path: root/usr/local/www/vpn_openvpn_crl_edit.php
blob: 9c5c484064d817bbbef2f6ba1a056c6a7325c042 (plain)
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
<?php 
/*
	vpn_openvpn_crl_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.
*/

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']['crl']))
	$config['ovpn']['server']['crl'] = array();

$ovpncrl =& $config['ovpn']['server']['crl'];

$id = $_GET['id'];
if (isset($_POST['id']))
	$id = $_POST['id'];

if (isset($id) && $ovpncrl[$id]) {

	$pconfig = $config['ovpn']['server']['crl'][$id];

	if (isset($ovpncrl[$id]['enable']))
		$pconfig['enable'] = true;

} else {
	/* creating - set defaults */
	$pconfig = array();
	$pconfig['enable'] = true;
}

if ($_POST) {

	unset($input_errors);
	$pconfig = $_POST;

	/* input validation */
	$reqdfields = explode(" ", "crlname");
	$reqdfieldsn = explode(",", "Name");

	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);

	if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['crlname']))
		$input_errors[] = "The name contains invalid characters.";

	/* Editing an existing entry? */
	if (!$input_errors && !(isset($id) && $ovpncrl[$id])) {
		/* make sure there are no dupes */
		foreach ($ovpncrl as $crlent) {
			if ($crlent['crlname'] == $_POST['crlname']) {
				$input_errors[] = "Another entry with the same name already exists.";
				break;
			}
		}
	}

	/* check if a crl was given */
	if (is_uploaded_file($_FILES['filename']['tmp_name']) && !empty($_FILES['filename']['size'])) {
		$content = file_get_contents($_FILES['filename']['tmp_name']);
	} else if (!empty($_POST['crl_list'])) {
		$content = $_POST['crl_list'];
	} else {
		$content = "";
		$input_errors[] = "A valid X.509 CRL is required.";
	}

	/* check if crl is valid */
	if (!empty($content) &&
	   (!strstr($content, "BEGIN X509 CRL") ||
	    !strstr($content, "END X509 CRL")))
		$input_errors[] = "The X.509 CRL file content does not appear to be valid.";

	if (isset($id) && $ovpncrl[$id]) {
		$crlent = $ovpncrl[$id];

		/* Has the enable/disable state changed? */
		if (isset($crlent['enable']) && isset($_POST['disabled'])) {
			/* status changed to disabled */
			ovpn_crl_dirty($ovpncrl['crlname']);
		} else if (!isset($crlent['enable']) && !isset($_POST['disabled'])) {
			/* status changed to enable */
			ovpn_crl_dirty($ovpncrl['crlname']);
		}
	}

	if (!$input_errors) {
        
		$crlent = array();

		if (isset($id) && $ovpncrl[$id])
			$crlent = $ovpncrl[$id];
        
                $crlent['crlname'] = $_POST['crlname'];
		$crlent['descr'] = $_POST['descr'];
		$crlent['enable'] = $_POST['disabled'] ? false : true;

		/* file upload? */
		if ($_POST['crlname'] && is_uploaded_file($_FILES['filename']['tmp_name']))
			$crlent['crl_list'] = base64_encode(file_get_contents($_FILES['filename']['tmp_name']));
		else if (!empty($_POST['crl_list']))
			$crlent['crl_list'] = base64_encode($_POST['crl_list']);

                if (isset($id) && $ovpncrl[$id])
                        $ovpncrl[$id] = $crlent;
                else
                        $ovpncrl[] = $crlent;
                
                write_config();
		ovpn_crl_dirty($ovpncrl['crlname']);
                
                header("Location: vpn_openvpn_crl.php");
                exit;

	} else {

		$pconfig = $_POST;

		$pconfig['enable'] = "true";
		if (isset($_POST['disabled']))
			unset($pconfig['enable']);

		$pconfig['crl_list'] = base64_encode($_POST['crl_list']);
	}
}

$pgtitle = "VPN: OpenVPN: Edit CRL";
include("head.inc");

?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<p class="pgtitle"><?=$pgtitle?></p>
<?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.crlname.disabled = endis;
	document.iform.descr.disabled = endis;
	document.iform.crl_list.disabled = endis;
	document.iform.filename.disabled = endis;

}

//-->
</script>
<form action="vpn_openvpn_crl_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>&nbsp;<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 X.509 CRL list</strong><br>
	<span class="vexpl">Set this option to on to disable this X.509 CRL file
	without removing it from the list.</span></td>
      </td>
    </tr>
   
    <tr> 
      <td width="22%" valign="top" class="vncellreq">Name</td>
      <td width="78%" class="vtable"> 
        <input name="crlname" type="text" class="formfld" id="crlname" size="40" value="<?=htmlspecialchars($pconfig['crlname']);?>"> 
        <br><span class="vexpl">Enter a unique name here, to describe the X.509 CRL list.</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 valign="top" class="vncellreq">X.509 CRL file content</td>
      <td class="vtable">
        <textarea name="crl_list" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['crl_list']));?></textarea>
        <br>
	Paste the contents of a X.509 CRL file in PEM format here.</td>
    </tr>

    <tr>
      <td width="22%" valign="top" class="vncell">X.509 CRL file</td>
      <td class="vtable">
	<input name="filename" type="file" class="formfld" id="filename"><br>
	Instead of pasting the contents of a X.509 CRL file above,
	you can upload a X.509 CRL file in PEM format here. It will
	overwrite the values entered in the "X.509 CRL file content"
	field.
      </td>
    </tr>

    <tr>
      <td width="22%" valign="top">&nbsp;</td>
      <td width="78%">
        <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
        <?php if (isset($id)): ?>
        <input name="id" type="hidden" value="<?=$id;?>"> 
        <?php endif; ?>
      </td>
    </tr>
</table>
</form>
<script language="JavaScript">
<!--
enable_change(false);
//-->
</script>
<?php include("fend.inc");
?>
OpenPOWER on IntegriCloud