Project

General

Profile

Download (16.5 KB) Statistics
| Branch: | Tag: | Revision:
1 81bfb231 jim-p
<?php
2
/*
3 c5d81585 Renato Botelho
 * system_crlmanager.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8
 *
9 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12 c5d81585 Renato Botelho
 *
13 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
14 c5d81585 Renato Botelho
 *
15 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20 3a9f3078 Stephen Beaver
 */
21 81bfb231 jim-p
22
##|+PRIV
23
##|*IDENT=page-system-crlmanager
24
##|*NAME=System: CRL Manager
25
##|*DESCR=Allow access to the 'System: CRL Manager' page.
26
##|*MATCH=system_crlmanager.php*
27
##|-PRIV
28
29 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
30 81bfb231 jim-p
require_once("certs.inc");
31 0dea741f Chris Buechler
require_once("openvpn.inc");
32 0661622a doktornotor
require_once("pfsense-utils.inc");
33 0dea741f Chris Buechler
require_once("vpn.inc");
34 81bfb231 jim-p
35 fc54f29b jim-p
global $openssl_crl_status;
36
37 81bfb231 jim-p
$crl_methods = array(
38
	"internal" => gettext("Create an internal Certificate Revocation List"),
39
	"existing" => gettext("Import an existing Certificate Revocation List"));
40
41 4611e283 Steve Beaver
if (isset($_REQUEST['id']) && ctype_alnum($_REQUEST['id'])) {
42
	$id = $_REQUEST['id'];
43 56b1ed39 Phil Davis
}
44 81bfb231 jim-p
45 56b1ed39 Phil Davis
if (!is_array($config['ca'])) {
46 81bfb231 jim-p
	$config['ca'] = array();
47 56b1ed39 Phil Davis
}
48 81bfb231 jim-p
49
$a_ca =& $config['ca'];
50
51 56b1ed39 Phil Davis
if (!is_array($config['cert'])) {
52 81bfb231 jim-p
	$config['cert'] = array();
53 56b1ed39 Phil Davis
}
54 81bfb231 jim-p
55
$a_cert =& $config['cert'];
56
57 56b1ed39 Phil Davis
if (!is_array($config['crl'])) {
58 81bfb231 jim-p
	$config['crl'] = array();
59 56b1ed39 Phil Davis
}
60 81bfb231 jim-p
61
$a_crl =& $config['crl'];
62
63 56b1ed39 Phil Davis
foreach ($a_crl as $cid => $acrl) {
64
	if (!isset($acrl['refid'])) {
65 c1f95f5c jim-p
		unset ($a_crl[$cid]);
66 56b1ed39 Phil Davis
	}
67
}
68 c1f95f5c jim-p
69 4611e283 Steve Beaver
$act = $_REQUEST['act'];
70 d565c182 Steve Beaver
71 81bfb231 jim-p
72 56b1ed39 Phil Davis
if (!empty($id)) {
73 c1f95f5c jim-p
	$thiscrl =& lookup_crl($id);
74 56b1ed39 Phil Davis
}
75 81bfb231 jim-p
76 c1f95f5c jim-p
// If we were given an invalid crlref in the id, no sense in continuing as it would only cause errors.
77
if (!$thiscrl && (($act != "") && ($act != "new"))) {
78
	pfSenseHeader("system_crlmanager.php");
79
	$act="";
80
	$savemsg = gettext("Invalid CRL reference.");
81 61d1ca3e Phil Davis
	$class = "danger";
82 3a9f3078 Stephen Beaver
}
83 c1f95f5c jim-p
84 4611e283 Steve Beaver
if ($_POST['act'] == "del") {
85 234cde4b jim-p
	$name = htmlspecialchars($thiscrl['descr']);
86 c1f95f5c jim-p
	if (crl_in_use($id)) {
87 8545adde k-paulius
		$savemsg = sprintf(gettext("Certificate Revocation List %s is in use and cannot be deleted."), $name);
88 61d1ca3e Phil Davis
		$class = "danger";
89 ad8df715 jim-p
	} else {
90 56b1ed39 Phil Davis
		foreach ($a_crl as $cid => $acrl) {
91
			if ($acrl['refid'] == $thiscrl['refid']) {
92 c1f95f5c jim-p
				unset($a_crl[$cid]);
93 56b1ed39 Phil Davis
			}
94
		}
95 ad08687b jim-p
		write_config("Deleted CRL {$name}.");
96 8545adde k-paulius
		$savemsg = sprintf(gettext("Certificate Revocation List %s successfully deleted."), $name);
97 61d1ca3e Phil Davis
		$class = "success";
98 ad8df715 jim-p
	}
99 81bfb231 jim-p
}
100
101
if ($act == "new") {
102 4611e283 Steve Beaver
	$pconfig['method'] = $_REQUEST['method'];
103
	$pconfig['caref'] = $_REQUEST['caref'];
104 81bfb231 jim-p
	$pconfig['lifetime'] = "9999";
105
	$pconfig['serial'] = "0";
106
}
107
108
if ($act == "exp") {
109 45508803 jim-p
	crl_update($thiscrl);
110 c1f95f5c jim-p
	$exp_name = urlencode("{$thiscrl['descr']}.crl");
111
	$exp_data = base64_decode($thiscrl['text']);
112 81bfb231 jim-p
	$exp_size = strlen($exp_data);
113
114
	header("Content-Type: application/octet-stream");
115
	header("Content-Disposition: attachment; filename={$exp_name}");
116
	header("Content-Length: $exp_size");
117
	echo $exp_data;
118
	exit;
119
}
120
121 28ff7ace jim-p
if ($act == "addcert") {
122
123 d565c182 Steve Beaver
	unset($input_errors);
124 4611e283 Steve Beaver
	$pconfig = $_REQUEST;
125 28ff7ace jim-p
126 d565c182 Steve Beaver
	if (!$pconfig['crlref'] || !$pconfig['certref']) {
127
		pfSenseHeader("system_crlmanager.php");
128
		exit;
129
	}
130 28ff7ace jim-p
131 d565c182 Steve Beaver
	// certref, crlref
132
	$crl =& lookup_crl($pconfig['crlref']);
133
	$cert = lookup_cert($pconfig['certref']);
134 28ff7ace jim-p
135 d565c182 Steve Beaver
	if (!$crl['caref'] || !$cert['caref']) {
136
		$input_errors[] = gettext("Both the Certificate and CRL must be specified.");
137
	}
138 28ff7ace jim-p
139 d565c182 Steve Beaver
	if ($crl['caref'] != $cert['caref']) {
140
		$input_errors[] = gettext("CA mismatch between the Certificate and CRL. Unable to Revoke.");
141
	}
142
	if (!is_crl_internal($crl)) {
143
		$input_errors[] = gettext("Cannot revoke certificates for an imported/external CRL.");
144
	}
145
146
	if (!$input_errors) {
147 981d6364 jim-p
		$reason = (empty($pconfig['crlreason'])) ? 0 : $pconfig['crlreason'];
148 d565c182 Steve Beaver
		cert_revoke($cert, $crl, $reason);
149
		// refresh IPsec and OpenVPN CRLs
150
		openvpn_refresh_crls();
151
		vpn_ipsec_configure();
152
		write_config("Revoked cert {$cert['descr']} in CRL {$crl['descr']}.");
153
		pfSenseHeader("system_crlmanager.php");
154
		exit;
155 28ff7ace jim-p
	}
156
}
157
158
if ($act == "delcert") {
159 c1f95f5c jim-p
	if (!is_array($thiscrl['cert'])) {
160 28ff7ace jim-p
		pfSenseHeader("system_crlmanager.php");
161
		exit;
162
	}
163 c1f95f5c jim-p
	$found = false;
164
	foreach ($thiscrl['cert'] as $acert) {
165 4611e283 Steve Beaver
		if ($acert['refid'] == $_REQUEST['certref']) {
166 c1f95f5c jim-p
			$found = true;
167
			$thiscert = $acert;
168
		}
169
	}
170
	if (!$found) {
171
		pfSenseHeader("system_crlmanager.php");
172
		exit;
173
	}
174 234cde4b jim-p
	$certname = htmlspecialchars($thiscert['descr']);
175
	$crlname = htmlspecialchars($thiscrl['descr']);
176 c1f95f5c jim-p
	if (cert_unrevoke($thiscert, $thiscrl)) {
177 702fa4d0 Phil Davis
		$savemsg = sprintf(gettext('Deleted Certificate %1$s from CRL %2$s.'), $certname, $crlname);
178 61d1ca3e Phil Davis
		$class = "success";
179 3a9f3078 Stephen Beaver
		// refresh IPsec and OpenVPN CRLs
180 c1f95f5c jim-p
		openvpn_refresh_crls();
181 6141f51a Chris Buechler
		vpn_ipsec_configure();
182 762faef5 Phil Davis
		write_config($savemsg);
183 c1f95f5c jim-p
	} else {
184 702fa4d0 Phil Davis
		$savemsg = sprintf(gettext('Failed to delete Certificate %1$s from CRL %2$s.'), $certname, $crlname);
185 61d1ca3e Phil Davis
		$class = "danger";
186 c1f95f5c jim-p
	}
187
	$act="edit";
188 28ff7ace jim-p
}
189
190 d565c182 Steve Beaver
if ($_POST['save']) {
191 234cde4b jim-p
	$input_errors = array();
192 81bfb231 jim-p
	$pconfig = $_POST;
193
194
	/* input validation */
195 6f3d3a07 jim-p
	if (($pconfig['method'] == "existing") || ($act == "editimported")) {
196 5293bfec jim-p
		$reqdfields = explode(" ", "descr crltext");
197 81bfb231 jim-p
		$reqdfieldsn = array(
198 6c07db48 Phil Davis
			gettext("Descriptive name"),
199
			gettext("Certificate Revocation List data"));
200 81bfb231 jim-p
	}
201
	if ($pconfig['method'] == "internal") {
202 6c07db48 Phil Davis
		$reqdfields = explode(" ", "descr caref");
203 81bfb231 jim-p
		$reqdfieldsn = array(
204 6c07db48 Phil Davis
			gettext("Descriptive name"),
205
			gettext("Certificate Authority"));
206 81bfb231 jim-p
	}
207
208 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
209 81bfb231 jim-p
210 234cde4b jim-p
	if (preg_match("/[\?\>\<\&\/\\\"\']/", $pconfig['descr'])) {
211
		array_push($input_errors, "The field 'Descriptive Name' contains invalid characters.");
212
	}
213
214 81bfb231 jim-p
	/* save modifications */
215
	if (!$input_errors) {
216
		$result = false;
217
218 304af9d8 jim-p
		if ($thiscrl) {
219 c1f95f5c jim-p
			$crl =& $thiscrl;
220 304af9d8 jim-p
		} else {
221
			$crl = array();
222
			$crl['refid'] = uniqid();
223
		}
224 81bfb231 jim-p
225 f2a86ca9 jim-p
		$crl['descr'] = $pconfig['descr'];
226 6f3d3a07 jim-p
		if ($act != "editimported") {
227
			$crl['caref'] = $pconfig['caref'];
228
			$crl['method'] = $pconfig['method'];
229
		}
230 81bfb231 jim-p
231 6f3d3a07 jim-p
		if (($pconfig['method'] == "existing") || ($act == "editimported")) {
232 304af9d8 jim-p
			$crl['text'] = base64_encode($pconfig['crltext']);
233 81bfb231 jim-p
		}
234
235
		if ($pconfig['method'] == "internal") {
236
			$crl['serial'] = empty($pconfig['serial']) ? 9999 : $pconfig['serial'];
237
			$crl['lifetime'] = empty($pconfig['lifetime']) ? 9999 : $pconfig['lifetime'];
238
			$crl['cert'] = array();
239
		}
240
241 56b1ed39 Phil Davis
		if (!$thiscrl) {
242 81bfb231 jim-p
			$a_crl[] = $crl;
243 56b1ed39 Phil Davis
		}
244 81bfb231 jim-p
245 304af9d8 jim-p
		write_config("Saved CRL {$crl['descr']}");
246 3a9f3078 Stephen Beaver
		// refresh IPsec and OpenVPN CRLs
247 6f3d3a07 jim-p
		openvpn_refresh_crls();
248 6141f51a Chris Buechler
		vpn_ipsec_configure();
249 81bfb231 jim-p
		pfSenseHeader("system_crlmanager.php");
250
	}
251
}
252
253 56c6b1cb k-paulius
$pgtitle = array(gettext("System"), gettext("Certificate Manager"), gettext("Certificate Revocation"));
254 edcd7535 Phil Davis
$pglinks = array("", "system_camanager.php", "system_crlmanager.php");
255 56c6b1cb k-paulius
256
if ($act == "new" || $act == gettext("Save") || $input_errors || $act == "edit") {
257
	$pgtitle[] = gettext('Edit');
258 edcd7535 Phil Davis
	$pglinks[] = "@self";
259 56c6b1cb k-paulius
}
260 81bfb231 jim-p
include("head.inc");
261
?>
262
263
<script type="text/javascript">
264 0d15afff Colin Fleming
//<![CDATA[
265 81bfb231 jim-p
266
function method_change() {
267
268 44bcc1be jim-p
	method = document.iform.method.value;
269 81bfb231 jim-p
270
	switch (method) {
271 44bcc1be jim-p
		case "internal":
272 81bfb231 jim-p
			document.getElementById("existing").style.display="none";
273
			document.getElementById("internal").style.display="";
274
			break;
275 44bcc1be jim-p
		case "existing":
276 81bfb231 jim-p
			document.getElementById("existing").style.display="";
277
			document.getElementById("internal").style.display="none";
278
			break;
279
	}
280
}
281
282 0d15afff Colin Fleming
//]]>
283 81bfb231 jim-p
</script>
284 f9ee8994 Stephen Beaver
285 81bfb231 jim-p
<?php
286 f9ee8994 Stephen Beaver
287
function build_method_list() {
288 bda120a4 Steve Beaver
	global $_POST, $crl_methods;
289 3a9f3078 Stephen Beaver
290 f9ee8994 Stephen Beaver
	$list = array();
291 3a9f3078 Stephen Beaver
292 78863416 Phil Davis
	foreach ($crl_methods as $method => $desc) {
293 bda120a4 Steve Beaver
		if (($_POST['importonly'] == "yes") && ($method != "existing")) {
294 f9ee8994 Stephen Beaver
			continue;
295 78863416 Phil Davis
		}
296 3a9f3078 Stephen Beaver
297 f9ee8994 Stephen Beaver
		$list[$method] = $desc;
298 3a9f3078 Stephen Beaver
	}
299
300
	return($list);
301 f9ee8994 Stephen Beaver
}
302
303
function build_ca_list() {
304
	global $a_ca;
305 3a9f3078 Stephen Beaver
306 f9ee8994 Stephen Beaver
	$list = array();
307 3a9f3078 Stephen Beaver
308 78863416 Phil Davis
	foreach ($a_ca as $ca) {
309 f9ee8994 Stephen Beaver
		$list[$ca['refid']] = $ca['descr'];
310 78863416 Phil Davis
	}
311 f9ee8994 Stephen Beaver
312
	return($list);
313
}
314
315
function build_cacert_list() {
316
	global $ca_certs;
317 3a9f3078 Stephen Beaver
318 f9ee8994 Stephen Beaver
	$list = array();
319
320 9d3e8723 Phil Davis
	foreach ($ca_certs as $cert) {
321 3a9f3078 Stephen Beaver
		$list[$cert['refid']] = $cert['descr'];
322 78863416 Phil Davis
	}
323 f9ee8994 Stephen Beaver
324
	return($list);
325 3a9f3078 Stephen Beaver
}
326 f9ee8994 Stephen Beaver
327 78863416 Phil Davis
if ($input_errors) {
328 f9ee8994 Stephen Beaver
	print_input_errors($input_errors);
329 78863416 Phil Davis
}
330 3a9f3078 Stephen Beaver
331 78863416 Phil Davis
if ($savemsg) {
332 61d1ca3e Phil Davis
	print_info_box($savemsg, $class);
333 78863416 Phil Davis
}
334 3a9f3078 Stephen Beaver
335 f9ee8994 Stephen Beaver
$tab_array = array();
336
$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
337
$tab_array[] = array(gettext("Certificates"), false, "system_certmanager.php");
338
$tab_array[] = array(gettext("Certificate Revocation"), true, "system_crlmanager.php");
339
display_top_tabs($tab_array);
340
341
if ($act == "new" || $act == gettext("Save") || $input_errors) {
342
	if (!isset($id)) {
343
		$form = new Form();
344 3a9f3078 Stephen Beaver
345 5f88f964 k-paulius
		$section = new Form_Section('Create new Revocation List');
346 3a9f3078 Stephen Beaver
347 f9ee8994 Stephen Beaver
		$section->addInput(new Form_Select(
348
			'method',
349 153c3aa6 Phil Davis
			'*Method',
350 f9ee8994 Stephen Beaver
			$pconfig['method'],
351
			build_method_list()
352
		));
353 3a9f3078 Stephen Beaver
354 f9ee8994 Stephen Beaver
	}
355 3a9f3078 Stephen Beaver
356 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Input(
357
		'descr',
358 153c3aa6 Phil Davis
		'*Descriptive name',
359 f9ee8994 Stephen Beaver
		'text',
360
		$pconfig['descr']
361
	));
362
363
	$section->addInput(new Form_Select(
364
		'caref',
365 153c3aa6 Phil Davis
		'*Certificate Authority',
366 f9ee8994 Stephen Beaver
		$pconfig['caref'],
367
		build_ca_list()
368
	));
369 3a9f3078 Stephen Beaver
370 f9ee8994 Stephen Beaver
	$form->add($section);
371 3a9f3078 Stephen Beaver
372 f9ee8994 Stephen Beaver
	$section = new Form_Section('Existing Certificate Revocation List');
373
	$section->addClass('existing');
374 3a9f3078 Stephen Beaver
375 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Textarea(
376
		'crltext',
377 153c3aa6 Phil Davis
		'*CRL data',
378 f9ee8994 Stephen Beaver
		$pconfig['crltext']
379
		))->setHelp('Paste a Certificate Revocation List in X.509 CRL format here.');
380 3a9f3078 Stephen Beaver
381 f9ee8994 Stephen Beaver
	$form->add($section);
382 3a9f3078 Stephen Beaver
383 f9ee8994 Stephen Beaver
	$section = new Form_Section('Internal Certificate Revocation List');
384
	$section->addClass('internal');
385 3a9f3078 Stephen Beaver
386 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Input(
387
		'lifetime',
388
		'Lifetime (Days)',
389
		'number',
390
		$pconfig['lifetime'],
391 e13172fe Steve Beaver
		['max' => '9999']
392 f9ee8994 Stephen Beaver
	));
393 3a9f3078 Stephen Beaver
394 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Input(
395
		'serial',
396
		'Serial',
397
		'number',
398
		$pconfig['serial'],
399 d0c62202 BBcan177
		['min' => '0', 'max' => '9999']
400 f9ee8994 Stephen Beaver
	));
401 3a9f3078 Stephen Beaver
402
	$form->add($section);
403
404 f9ee8994 Stephen Beaver
	if (isset($id) && $thiscrl) {
405
		$section->addInput(new Form_Input(
406
			'id',
407
			null,
408
			'hidden',
409
			$id
410 3a9f3078 Stephen Beaver
		));
411 f9ee8994 Stephen Beaver
	}
412 3a9f3078 Stephen Beaver
413 f9ee8994 Stephen Beaver
	print($form);
414
415
} elseif ($act == "editimported") {
416 3a9f3078 Stephen Beaver
417 f9ee8994 Stephen Beaver
	$form = new Form();
418 3a9f3078 Stephen Beaver
419
	$section = new Form_Section('Edit Imported Certificate Revocation List');
420
421 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Input(
422
		'descr',
423 153c3aa6 Phil Davis
		'*Descriptive name',
424 f9ee8994 Stephen Beaver
		'text',
425
		$pconfig['descr']
426
	));
427 3a9f3078 Stephen Beaver
428 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Textarea(
429
		'crltext',
430 153c3aa6 Phil Davis
		'*CRL data',
431 f9ee8994 Stephen Beaver
		$pconfig['crltext']
432
	))->setHelp('Paste a Certificate Revocation List in X.509 CRL format here.');
433 3a9f3078 Stephen Beaver
434 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Input(
435
		'id',
436
		null,
437
		'hidden',
438
		$id
439
	));
440 3a9f3078 Stephen Beaver
441 f9ee8994 Stephen Beaver
	$section->addInput(new Form_Input(
442
		'act',
443
		null,
444
		'hidden',
445
		'editimported'
446
	));
447 3a9f3078 Stephen Beaver
448 f9ee8994 Stephen Beaver
	$form->add($section);
449 3a9f3078 Stephen Beaver
450 f9ee8994 Stephen Beaver
	print($form);
451 3a9f3078 Stephen Beaver
452 f9ee8994 Stephen Beaver
} elseif ($act == "edit") {
453
	$crl = $thiscrl;
454 3a9f3078 Stephen Beaver
455 f9ee8994 Stephen Beaver
	$form = new Form(false);
456 81bfb231 jim-p
?>
457 3a9f3078 Stephen Beaver
458 f9ee8994 Stephen Beaver
	<div class="panel panel-default">
459
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Currently Revoked Certificates for CRL") . ': ' . $crl['descr']?></h2></div>
460
		<div class="panel-body table-responsive">
461 3a9f3078 Stephen Beaver
<?php
462 78863416 Phil Davis
	if (!is_array($crl['cert']) || (count($crl['cert']) == 0)) {
463 8545adde k-paulius
		print_info_box(gettext("No certificates found for this CRL."), 'danger');
464 78863416 Phil Davis
	} else {
465 3a9f3078 Stephen Beaver
?>
466 f9ee8994 Stephen Beaver
			<table class="table table-striped table-hover table-condensed">
467
				<thead>
468 fc54f29b jim-p
					<tr>
469 f9ee8994 Stephen Beaver
						<th><?=gettext("Certificate Name")?></th>
470
						<th><?=gettext("Revocation Reason")?></th>
471
						<th><?=gettext("Revoked At")?></th>
472
						<th></th>
473 28ff7ace jim-p
					</tr>
474 f9ee8994 Stephen Beaver
				</thead>
475
				<tbody>
476 3a9f3078 Stephen Beaver
<?php
477 78863416 Phil Davis
		foreach ($crl['cert'] as $i => $cert):
478 f9ee8994 Stephen Beaver
			$name = htmlspecialchars($cert['descr']);
479
?>
480 28ff7ace jim-p
					<tr>
481
						<td class="listlr">
482 f9ee8994 Stephen Beaver
							<?=$name; ?>
483 28ff7ace jim-p
						</td>
484 fc54f29b jim-p
						<td class="listlr">
485 f9ee8994 Stephen Beaver
							<?=$openssl_crl_status[$cert["reason"]]; ?>
486 fc54f29b jim-p
						</td>
487
						<td class="listlr">
488 f9ee8994 Stephen Beaver
							<?=date("D M j G:i:s T Y", $cert["revoke_time"]); ?>
489 fc54f29b jim-p
						</td>
490 28ff7ace jim-p
						<td class="list">
491 d565c182 Steve Beaver
							<a href="system_crlmanager.php?act=delcert&amp;id=<?=$crl['refid']; ?>&amp;certref=<?=$cert['refid']; ?>" usepost>
492 15b6dcac jim-p
								<i class="fa fa-trash" title="<?=gettext("Delete this certificate from the CRL")?>" alt="<?=gettext("Delete this certificate from the CRL")?>"></i>
493 28ff7ace jim-p
							</a>
494
						</td>
495
					</tr>
496 f9ee8994 Stephen Beaver
<?php
497
		endforeach;
498
?>
499
				</tbody>
500
			</table>
501 f6fac5ac Phil Davis
<?php
502
	}
503
?>
504 f9ee8994 Stephen Beaver
		</div>
505
	</div>
506
<?php
507
508
	$ca_certs = array();
509 78863416 Phil Davis
	foreach ($a_cert as $cert) {
510 63844c33 skrude61
		if ($cert['caref'] == $crl['caref'] && !is_cert_revoked($cert, $id)) {
511 f9ee8994 Stephen Beaver
			$ca_certs[] = $cert;
512 78863416 Phil Davis
		}
513
	}
514 3a9f3078 Stephen Beaver
515 f6fac5ac Phil Davis
	if (count($ca_certs) == 0) {
516 8545adde k-paulius
		print_info_box(gettext("No certificates found for this CA."), 'danger');
517 f6fac5ac Phil Davis
	} else {
518 5f88f964 k-paulius
		$section = new Form_Section('Choose a Certificate to Revoke');
519 f6fac5ac Phil Davis
		$group = new Form_Group(null);
520 3a9f3078 Stephen Beaver
521 f6fac5ac Phil Davis
		$group->add(new Form_Select(
522
			'certref',
523
			null,
524
			$pconfig['certref'],
525
			build_cacert_list()
526
			))->setWidth(4)->setHelp('Certificate');
527 3a9f3078 Stephen Beaver
528 f6fac5ac Phil Davis
		$group->add(new Form_Select(
529
			'crlreason',
530
			null,
531
			-1,
532
			$openssl_crl_status
533
			))->setHelp('Reason');
534 3a9f3078 Stephen Beaver
535 f6fac5ac Phil Davis
		$group->add(new Form_Button(
536
			'submit',
537 faab522f Renato Botelho
			'Add',
538 827a3812 jim-p
			null,
539
			'fa-plus'
540
			))->addClass('btn-success btn-sm');
541 3a9f3078 Stephen Beaver
542 f6fac5ac Phil Davis
		$section->add($group);
543 3a9f3078 Stephen Beaver
544 f6fac5ac Phil Davis
		$section->addInput(new Form_Input(
545
			'id',
546
			null,
547
			'hidden',
548
			$crl['refid']
549
		));
550 3a9f3078 Stephen Beaver
551 f6fac5ac Phil Davis
		$section->addInput(new Form_Input(
552
			'act',
553
			null,
554
			'hidden',
555
			'addcert'
556
		));
557 3a9f3078 Stephen Beaver
558 f6fac5ac Phil Davis
		$section->addInput(new Form_Input(
559
			'crlref',
560
			null,
561
			'hidden',
562
			$crl['refid']
563
		));
564 3a9f3078 Stephen Beaver
565 f6fac5ac Phil Davis
		$form->add($section);
566
	}
567 3a9f3078 Stephen Beaver
568 f9ee8994 Stephen Beaver
	print($form);
569
} else {
570
?>
571
572
	<div class="panel panel-default">
573
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Additional Certificate Revocation Lists")?></h2></div>
574
		<div class="panel-body table-responsive">
575 1c10ce97 PiBa-NL
			<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
576 f9ee8994 Stephen Beaver
				<thead>
577 0d15afff Colin Fleming
					<tr>
578 f9ee8994 Stephen Beaver
						<th><?=gettext("Name")?></th>
579
						<th><?=gettext("Internal")?></th>
580
						<th><?=gettext("Certificates")?></th>
581
						<th><?=gettext("In Use")?></th>
582 b1466a09 Phil Davis
						<th><?=gettext("Actions")?></th>
583 0d15afff Colin Fleming
					</tr>
584 f9ee8994 Stephen Beaver
				</thead>
585
				<tbody>
586
<?php
587 3bde5cdd PiBa-NL
	$pluginparams = array();
588
	$pluginparams['type'] = 'certificates';
589
	$pluginparams['event'] = 'used_crl';
590
	$certificates_used_by_packages = pkg_call_plugins('plugin_certificates', $pluginparams);
591 f9ee8994 Stephen Beaver
	// Map CRLs to CAs in one pass
592
	$ca_crl_map = array();
593 78863416 Phil Davis
	foreach ($a_crl as $crl) {
594 f9ee8994 Stephen Beaver
		$ca_crl_map[$crl['caref']][] = $crl['refid'];
595 78863416 Phil Davis
	}
596 f9ee8994 Stephen Beaver
597
	$i = 0;
598 78863416 Phil Davis
	foreach ($a_ca as $ca):
599 f9ee8994 Stephen Beaver
		$name = htmlspecialchars($ca['descr']);
600
601 78863416 Phil Davis
		if ($ca['prv']) {
602 f9ee8994 Stephen Beaver
			$cainternal = "YES";
603 78863416 Phil Davis
		} else {
604 f9ee8994 Stephen Beaver
			$cainternal = "NO";
605 78863416 Phil Davis
		}
606 3a9f3078 Stephen Beaver
?>
607 81bfb231 jim-p
					<tr>
608 f9ee8994 Stephen Beaver
						<td colspan="4">
609
							<?=$name?>
610 81bfb231 jim-p
						</td>
611 f9ee8994 Stephen Beaver
						<td>
612 3a9f3078 Stephen Beaver
<?php
613 78863416 Phil Davis
		if ($cainternal == "YES"):
614
?>
615 4611e283 Steve Beaver
							<a href="system_crlmanager.php?act=new&amp;caref=<?=$ca['refid']; ?>" class="btn btn-xs btn-success">
616 15b6dcac jim-p
								<i class="fa fa-plus icon-embed-btn"></i>
617 c4e97dbe Chris Buechler
								<?=gettext("Add or Import CRL")?>
618 44bcc1be jim-p
							</a>
619 3a9f3078 Stephen Beaver
<?php
620 78863416 Phil Davis
		else:
621
?>
622 4611e283 Steve Beaver
							<a href="system_crlmanager.php?act=new&amp;caref=<?=$ca['refid']; ?>&amp;importonly=yes" class="btn btn-xs btn-success">
623 15b6dcac jim-p
								<i class="fa fa-plus icon-embed-btn"></i>
624 c4e97dbe Chris Buechler
								<?=gettext("Add or Import CRL")?>
625 3a9f3078 Stephen Beaver
							</a>
626
<?php
627 78863416 Phil Davis
		endif;
628
?>
629 81bfb231 jim-p
						</td>
630
					</tr>
631 f9ee8994 Stephen Beaver
<?php
632
		if (is_array($ca_crl_map[$ca['refid']])):
633 78863416 Phil Davis
			foreach ($ca_crl_map[$ca['refid']] as $crl):
634 f9ee8994 Stephen Beaver
				$tmpcrl = lookup_crl($crl);
635
				$internal = is_crl_internal($tmpcrl);
636 3d9d84d4 jim-p
				if ($internal && (!isset($tmpcrl['cert']) || empty($tmpcrl['cert'])) ) {
637
					$tmpcrl['cert'] = array();
638
				}
639 f9ee8994 Stephen Beaver
				$inuse = crl_in_use($tmpcrl['refid']);
640
?>
641 81bfb231 jim-p
					<tr>
642 f9ee8994 Stephen Beaver
						<td><?=$tmpcrl['descr']; ?></td>
643 ce883f9f jim-p
						<td><i class="fa fa-<?=($internal) ? "check" : "times"; ?>"></i></td>
644 f9ee8994 Stephen Beaver
						<td><?=($internal) ? count($tmpcrl['cert']) : "Unknown (imported)"; ?></td>
645 3bde5cdd PiBa-NL
						<td><i class="fa fa-<?=($inuse) ? "check" : "times"; ?>"></i>
646
						<?php echo cert_usedby_description($tmpcrl['refid'], $certificates_used_by_packages); ?>
647
						</td>
648 f9ee8994 Stephen Beaver
						<td>
649 4611e283 Steve Beaver
							<a href="system_crlmanager.php?act=exp&amp;id=<?=$tmpcrl['refid']?>" class="fa fa-download" title="<?=gettext("Export CRL")?>" ></a>
650 3a9f3078 Stephen Beaver
<?php
651 f9ee8994 Stephen Beaver
				if ($internal): ?>
652 4611e283 Steve Beaver
							<a href="system_crlmanager.php?act=edit&amp;id=<?=$tmpcrl['refid']?>" class="fa fa-pencil" title="<?=gettext("Edit CRL")?>"></a>
653 3a9f3078 Stephen Beaver
<?php
654 78863416 Phil Davis
				else:
655
?>
656 4611e283 Steve Beaver
							<a href="system_crlmanager.php?act=editimported&amp;id=<?=$tmpcrl['refid']?>" class="fa fa-pencil" title="<?=gettext("Edit CRL")?>"></a>
657 3a9f3078 Stephen Beaver
<?php			endif;
658 78863416 Phil Davis
				if (!$inuse):
659
?>
660 d565c182 Steve Beaver
							<a href="system_crlmanager.php?act=del&amp;id=<?=$tmpcrl['refid']?>" class="fa fa-trash" title="<?=gettext("Delete CRL")?>" usepost></a>
661 3a9f3078 Stephen Beaver
<?php
662 78863416 Phil Davis
				endif;
663
?>
664 81bfb231 jim-p
						</td>
665
					</tr>
666 f9ee8994 Stephen Beaver
<?php
667
				$i++;
668
				endforeach;
669
			endif;
670
			$i++;
671
		endforeach;
672 3a9f3078 Stephen Beaver
?>
673 f9ee8994 Stephen Beaver
				</tbody>
674
			</table>
675
		</div>
676
	</div>
677 3a9f3078 Stephen Beaver
678
679
<?php
680 f9ee8994 Stephen Beaver
}
681
?>
682 81bfb231 jim-p
683 46345696 Colin Fleming
<script type="text/javascript">
684 3a9f3078 Stephen Beaver
//<![CDATA[
685 78863416 Phil Davis
events.push(function() {
686 3a9f3078 Stephen Beaver
687
	// Hides all elements of the specified class. This will usually be a section or group
688
	function hideClass(s_class, hide) {
689 78863416 Phil Davis
		if (hide) {
690 3a9f3078 Stephen Beaver
			$('.' + s_class).hide();
691 78863416 Phil Davis
		} else {
692 3a9f3078 Stephen Beaver
			$('.' + s_class).show();
693 78863416 Phil Davis
		}
694 3a9f3078 Stephen Beaver
	}
695
696
	// When the 'method" selector is changed, we show/hide certain sections
697
	$('#method').on('change', function() {
698
		hideClass('internal', ($('#method').val() == 'existing'));
699
		hideClass('existing', ($('#method').val() == 'internal'));
700
	});
701
702 f9ee8994 Stephen Beaver
	hideClass('internal', ($('#method').val() == 'existing'));
703
	hideClass('existing', ($('#method').val() == 'internal'));
704
});
705 3a9f3078 Stephen Beaver
//]]>
706 81bfb231 jim-p
</script>
707
708 f9ee8994 Stephen Beaver
<?php include("foot.inc");