Project

General

Profile

Download (30.2 KB) Statistics
| Branch: | Tag: | Revision:
1 64cc39d3 Matthew Grooms
<?php
2
/*
3
    system_certmanager.php
4
5
    Copyright (C) 2008 Shrew Soft Inc.
6
    All rights reserved.
7
8
    Redistribution and use in source and binary forms, with or without
9
    modification, are permitted provided that the following conditions are met:
10
11
    1. Redistributions of source code must retain the above copyright notice,
12
       this list of conditions and the following disclaimer.
13
14
    2. Redistributions in binary form must reproduce the above copyright
15
       notice, this list of conditions and the following disclaimer in the
16
       documentation and/or other materials provided with the distribution.
17
18
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
    POSSIBILITY OF SUCH DAMAGE.
28
*/
29 1d333258 Scott Ullrich
/*
30
	pfSense_MODULE:	certificate_managaer
31
*/
32 64cc39d3 Matthew Grooms
33
##|+PRIV
34
##|*IDENT=page-system-certmanager
35
##|*NAME=System: Certificate Manager
36
##|*DESCR=Allow access to the 'System: Certificate Manager' page.
37
##|*MATCH=system_certmanager.php*
38
##|-PRIV
39
40
require("guiconfig.inc");
41 14f5ae08 Ermal Lu?i
require_once("certs.inc");
42 64cc39d3 Matthew Grooms
43
$cert_methods = array(
44 ad9b5c67 jim-p
	"import" => gettext("Import an existing Certificate"),
45 a37753d7 Vinicius Coque
	"internal" => gettext("Create an internal Certificate"),
46 ad9b5c67 jim-p
	"external" => gettext("Create a Certificate Signing Request"),
47
);
48 64cc39d3 Matthew Grooms
49
$cert_keylens = array( "512", "1024", "2048", "4096");
50
51 51e4f7a3 Vinicius Coque
$pgtitle = array(gettext("System"), gettext("Certificate Manager"));
52 64cc39d3 Matthew Grooms
53 ad9b5c67 jim-p
$userid = $_GET['userid'];
54
if (isset($_POST['userid']))
55
	$userid = $_POST['userid'];
56
if ($userid) {
57
	$cert_methods["existing"] = gettext("Choose an existing certificate");
58
	if (!is_array($config['system']['user']))
59
		$config['system']['user'] = array();
60
	$a_user =& $config['system']['user'];
61
}
62
63 64cc39d3 Matthew Grooms
$id = $_GET['id'];
64
if (isset($_POST['id']))
65
	$id = $_POST['id'];
66
67 b4e6524c jim-p
if (!is_array($config['ca']))
68
	$config['ca'] = array();
69 64cc39d3 Matthew Grooms
70 b4e6524c jim-p
$a_ca =& $config['ca'];
71 64cc39d3 Matthew Grooms
72 b4e6524c jim-p
if (!is_array($config['cert']))
73
	$config['cert'] = array();
74 64cc39d3 Matthew Grooms
75 b4e6524c jim-p
$a_cert =& $config['cert'];
76 64cc39d3 Matthew Grooms
77
$internal_ca_count = 0;
78
foreach ($a_ca as $ca)
79
	if ($ca['prv'])	
80
		$internal_ca_count++;
81
82
$act = $_GET['act'];
83
if ($_POST['act'])
84
	$act = $_POST['act'];
85
86
if ($act == "del") {
87
88
	if (!$a_cert[$id]) {
89
		pfSenseHeader("system_certmanager.php");
90
		exit;
91
	}
92
93 f2a86ca9 jim-p
	$name = $a_cert[$id]['descr'];
94 64cc39d3 Matthew Grooms
	unset($a_cert[$id]);
95
	write_config();
96 ea53e38f Renato Botelho
	$savemsg = sprintf(gettext("Certificate %s successfully deleted"), $name) . "<br/>";
97 64cc39d3 Matthew Grooms
}
98
99
if ($act == "new") {
100
	$pconfig['method'] = $_GET['method'];
101
	$pconfig['keylen'] = "2048";
102 cf360495 Chris Buechler
	$pconfig['lifetime'] = "3650";
103 64cc39d3 Matthew Grooms
}
104
105 93823b10 Matthew Grooms
if ($act == "exp") {
106
107
	if (!$a_cert[$id]) {
108
		pfSenseHeader("system_certmanager.php");
109
		exit;
110
	}
111
112 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_cert[$id]['descr']}.crt");
113 93823b10 Matthew Grooms
	$exp_data = base64_decode($a_cert[$id]['crt']);
114
	$exp_size = strlen($exp_data);
115
116
	header("Content-Type: application/octet-stream");
117
	header("Content-Disposition: attachment; filename={$exp_name}");
118
	header("Content-Length: $exp_size");
119
	echo $exp_data;
120
	exit;
121
}
122
123 73fbece8 mgrooms
if ($act == "key") {
124
125
	if (!$a_cert[$id]) {
126
		pfSenseHeader("system_certmanager.php");
127
		exit;
128
	}
129
130 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_cert[$id]['descr']}.key");
131 73fbece8 mgrooms
	$exp_data = base64_decode($a_cert[$id]['prv']);
132
	$exp_size = strlen($exp_data);
133
134
	header("Content-Type: application/octet-stream");
135
	header("Content-Disposition: attachment; filename={$exp_name}");
136
	header("Content-Length: $exp_size");
137
	echo $exp_data;
138
	exit;
139
}
140
141 64cc39d3 Matthew Grooms
if ($act == "csr") {
142
143
	if (!$a_cert[$id]) {
144
		pfSenseHeader("system_certmanager.php");
145
		exit;
146
	}
147
148 f2a86ca9 jim-p
	$pconfig['descr'] = $a_cert[$id]['descr'];
149 64cc39d3 Matthew Grooms
	$pconfig['csr'] = base64_decode($a_cert[$id]['csr']);
150
}
151
152
if ($_POST) {
153 e64aa6f8 Carlos Eduardo Ramos
	if ($_POST['save'] == gettext("Save")) {
154 64cc39d3 Matthew Grooms
		unset($input_errors);
155
		$pconfig = $_POST;
156
157
		/* input validation */
158 ad9b5c67 jim-p
		if ($pconfig['method'] == "import") {
159 64cc39d3 Matthew Grooms
			$reqdfields = explode(" ",
160 5293bfec jim-p
					"descr cert key");
161 38fb1109 Vinicius Coque
			$reqdfieldsn = array(
162
					gettext("Descriptive name"),
163
					gettext("Certificate data"),
164
					gettext("Key data"));
165 64cc39d3 Matthew Grooms
		}
166
167
		if ($pconfig['method'] == "internal") {
168
			$reqdfields = explode(" ",
169 5293bfec jim-p
					"descr caref keylen lifetime dn_country dn_state dn_city ".
170 64cc39d3 Matthew Grooms
					"dn_organization dn_email dn_commonname");
171 38fb1109 Vinicius Coque
			$reqdfieldsn = array(
172
					gettext("Descriptive name"),
173
					gettext("Certificate authority"),
174
					gettext("Key length"),
175
					gettext("Lifetime"),
176
					gettext("Distinguished name Country Code"),
177
					gettext("Distinguished name State or Province"),
178
					gettext("Distinguished name City"),
179
					gettext("Distinguished name Organization"),
180
					gettext("Distinguished name Email Address"),
181 a37753d7 Vinicius Coque
					gettext("Distinguished name Common Name"));
182 64cc39d3 Matthew Grooms
		}
183
184
		if ($pconfig['method'] == "external") {
185
			$reqdfields = explode(" ",
186 5293bfec jim-p
					"descr csr_keylen csr_dn_country csr_dn_state csr_dn_city ".
187 64cc39d3 Matthew Grooms
					"csr_dn_organization csr_dn_email csr_dn_commonname");
188 38fb1109 Vinicius Coque
			$reqdfieldsn = array(
189
					gettext("Descriptive name"),
190
					gettext("Key length"),
191
					gettext("Distinguished name Country Code"),
192
					gettext("Distinguished name State or Province"),
193
					gettext("Distinguished name City"),
194
					gettext("Distinguished name Organization"),
195
					gettext("Distinguished name Email Address"),
196 a37753d7 Vinicius Coque
					gettext("Distinguished name Common Name"));
197 64cc39d3 Matthew Grooms
		}
198
199 ad9b5c67 jim-p
		if ($pconfig['method'] == "existing") {
200
			$reqdfields = array("certref");
201
			$reqdfieldsn = array(gettext("Existing Certificate Choice"));
202
		}
203
204 64cc39d3 Matthew Grooms
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
205
206
		/* if this is an AJAX caller then handle via JSON */
207
		if (isAjax() && is_array($input_errors)) {
208
			input_errors2Ajax($input_errors);
209
			exit;
210
		}
211
212
		/* save modifications */
213
		if (!$input_errors) {
214
215 ad9b5c67 jim-p
			if ($pconfig['method'] == "existing") {
216
				$cert = lookup_cert($pconfig['certref']);
217
				if ($cert && $a_user)
218
					$a_user[$userid]['cert'][] = $cert['refid'];
219
			} else {
220
				$cert = array();
221
				$cert['refid'] = uniqid();
222
				if (isset($id) && $a_cert[$id])
223
					$cert = $a_cert[$id];
224
225 f2a86ca9 jim-p
				$cert['descr'] = $pconfig['descr'];
226 ad9b5c67 jim-p
227
				if ($pconfig['method'] == "import")
228
					cert_import($cert, $pconfig['cert'], $pconfig['key']);
229
230
				if ($pconfig['method'] == "internal") {
231
					$dn = array(
232
						'countryName' => $pconfig['dn_country'],
233
						'stateOrProvinceName' => $pconfig['dn_state'],
234
						'localityName' => $pconfig['dn_city'],
235
						'organizationName' => $pconfig['dn_organization'],
236
						'emailAddress' => $pconfig['dn_email'],
237
						'commonName' => $pconfig['dn_commonname']);
238
	
239
					cert_create($cert, $pconfig['caref'], $pconfig['keylen'],
240
						$pconfig['lifetime'], $dn);
241
				}
242
243
				if ($pconfig['method'] == "external") {
244
					$dn = array(
245
						'countryName' => $pconfig['csr_dn_country'],
246
						'stateOrProvinceName' => $pconfig['csr_dn_state'],
247
						'localityName' => $pconfig['csr_dn_city'],
248
						'organizationName' => $pconfig['csr_dn_organization'],
249
						'emailAddress' => $pconfig['csr_dn_email'],
250
						'commonName' => $pconfig['csr_dn_commonname']);
251
252
					csr_generate($cert, $pconfig['csr_keylen'], $dn);
253
				}
254
				if (isset($id) && $a_cert[$id])
255
					$a_cert[$id] = $cert;
256
				else
257
					$a_cert[] = $cert;
258
				if (isset($a_user) && isset($userid))
259
					$a_user[$userid]['cert'][] = $cert['refid'];
260 64cc39d3 Matthew Grooms
			}
261
262
			write_config();
263
264 ad9b5c67 jim-p
			if ($userid)
265
				pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
266 64cc39d3 Matthew Grooms
		}
267
	}
268
269 a37753d7 Vinicius Coque
	if ($_POST['save'] == gettext("Update")) {
270 64cc39d3 Matthew Grooms
		unset($input_errors);
271
		$pconfig = $_POST;
272
273
		/* input validation */
274 5293bfec jim-p
		$reqdfields = explode(" ", "descr cert");
275 76d49f20 Renato Botelho
		$reqdfieldsn = array(
276
			gettext("Descriptive name"),
277
			gettext("Final Certificate data"));
278 64cc39d3 Matthew Grooms
279
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
280
281
		/* make sure this csr and certificate subjects match */
282
		$subj_csr = csr_get_subject($pconfig['csr'], false);
283
		$subj_cert = cert_get_subject($pconfig['cert'], false);
284
285
		if (strcmp($subj_csr,$subj_cert))
286 a37753d7 Vinicius Coque
			$input_errors[] = sprintf(gettext("The certificate subject '%s' does not match the signing request subject."),$subj_cert);
287 64cc39d3 Matthew Grooms
288
		/* if this is an AJAX caller then handle via JSON */
289
		if (isAjax() && is_array($input_errors)) {
290
			input_errors2Ajax($input_errors);
291
			exit;
292
		}
293
294
		/* save modifications */
295
		if (!$input_errors) {
296
297
			$cert = $a_cert[$id];
298
299 f2a86ca9 jim-p
			$cert['descr'] = $pconfig['descr'];
300 64cc39d3 Matthew Grooms
301
			csr_complete($cert, $pconfig['cert']);
302
303
			$a_cert[$id] = $cert;
304
305
			write_config();
306
307
			pfSenseHeader("system_certmanager.php");
308
		}
309
	}
310
}
311
312
include("head.inc");
313
?>
314
315
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
316
<?php include("fbegin.inc"); ?>
317
<script type="text/javascript">
318
<!--
319
320
function method_change() {
321
322
<?php
323
	if ($internal_ca_count)
324
		$submit_style = "";
325
	else
326
		$submit_style = "none";
327
?>
328
329
	method = document.iform.method.selectedIndex;
330
331
	switch (method) {
332
		case 0:
333 ad9b5c67 jim-p
			document.getElementById("import").style.display="";
334 64cc39d3 Matthew Grooms
			document.getElementById("internal").style.display="none";
335
			document.getElementById("external").style.display="none";
336 ad9b5c67 jim-p
			document.getElementById("existing").style.display="none";
337
			document.getElementById("descriptivename").style.display="";
338 96c7a492 Matthew Grooms
			document.getElementById("submit").style.display="";
339 64cc39d3 Matthew Grooms
			break;
340
		case 1:
341 ad9b5c67 jim-p
			document.getElementById("import").style.display="none";
342 64cc39d3 Matthew Grooms
			document.getElementById("internal").style.display="";
343
			document.getElementById("external").style.display="none";
344 ad9b5c67 jim-p
			document.getElementById("existing").style.display="none";
345
			document.getElementById("descriptivename").style.display="";
346 64cc39d3 Matthew Grooms
			document.getElementById("submit").style.display="<?=$submit_style;?>";
347
			break;
348
		case 2:
349 ad9b5c67 jim-p
			document.getElementById("import").style.display="none";
350 64cc39d3 Matthew Grooms
			document.getElementById("internal").style.display="none";
351
			document.getElementById("external").style.display="";
352 ad9b5c67 jim-p
			document.getElementById("existing").style.display="none";
353
			document.getElementById("descriptivename").style.display="";
354
			document.getElementById("submit").style.display="";
355
			break;
356
		case 3:
357
			document.getElementById("import").style.display="none";
358
			document.getElementById("internal").style.display="none";
359
			document.getElementById("external").style.display="none";
360
			document.getElementById("existing").style.display="";
361
			document.getElementById("descriptivename").style.display="none";
362 96c7a492 Matthew Grooms
			document.getElementById("submit").style.display="";
363 64cc39d3 Matthew Grooms
			break;
364
	}
365
}
366
367
<?php if ($internal_ca_count): ?>
368
function internalca_change() {
369
370
	index = document.iform.caref.selectedIndex;
371
	caref = document.iform.caref[index].value;
372
373
	switch (caref) {
374
<?php
375
		foreach ($a_ca as $ca):
376
			if (!$ca['prv'])
377
				continue;
378
			$subject = cert_get_subject_array($ca['crt']);
379
?>
380
		case "<?=$ca['refid'];?>":
381
			document.iform.dn_country.value = "<?=$subject[0]['v'];?>";
382
			document.iform.dn_state.value = "<?=$subject[1]['v'];?>";
383
			document.iform.dn_city.value = "<?=$subject[2]['v'];?>";
384
			document.iform.dn_organization.value = "<?=$subject[3]['v'];?>";
385 ad9b5c67 jim-p
			document.iform.dn_email.value = "<?=$subject[4]['v'];?>";
386 64cc39d3 Matthew Grooms
			break;
387
<?php	endforeach; ?>
388
	}
389
}
390
<?php endif; ?>
391
392
//-->
393
</script>
394
<?php
395
	if ($input_errors)
396
		print_input_errors($input_errors);
397
	if ($savemsg)
398
		print_info_box($savemsg);
399
?>
400
<table width="100%" border="0" cellpadding="0" cellspacing="0">
401
	<tr>
402
		<td class="tabnavtbl">
403
		<?php
404
			$tab_array = array();
405
			$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
406
			$tab_array[] = array(gettext("Certificates"), true, "system_certmanager.php");
407 3d57d2d5 jim-p
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
408 64cc39d3 Matthew Grooms
			display_top_tabs($tab_array);
409
		?>
410
		</td>
411
	</tr>
412
	<tr>
413 96c7a492 Matthew Grooms
		<td id="mainarea">
414
			<div class="tabcont">
415
416 e64aa6f8 Carlos Eduardo Ramos
				<?php if ($act == "new" || (($_POST['save'] == gettext("Save")) && $input_errors)): ?>
417 96c7a492 Matthew Grooms
418
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
419
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
420
						<?php if (!isset($id)): ?>
421
						<tr>
422
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
423
							<td width="78%" class="vtable">
424
								<select name='method' id='method' class="formselect" onchange='method_change()'>
425
								<?php
426
									foreach($cert_methods as $method => $desc):
427
									$selected = "";
428
									if ($pconfig['method'] == $method)
429
										$selected = "selected";
430
								?>
431
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
432
								<?php endforeach; ?>
433
								</select>
434
							</td>
435
						</tr>
436
						<?php endif; ?>
437 ad9b5c67 jim-p
						<tr id="descriptivename">
438
							<?php
439 f2a86ca9 jim-p
							if ($a_user && empty($pconfig['descr']))
440
								$pconfig['descr'] = $a_user[$userid]['name'];
441 ad9b5c67 jim-p
							?>
442
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
443
							<td width="78%" class="vtable">
444 f2a86ca9 jim-p
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
445 ad9b5c67 jim-p
							</td>
446
						</tr>
447 96c7a492 Matthew Grooms
					</table>
448
449 ad9b5c67 jim-p
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="import">
450 96c7a492 Matthew Grooms
						<tr>
451
							<td colspan="2" class="list" height="12"></td>
452
						</tr>
453
						<tr>
454 ad9b5c67 jim-p
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Import Certificate");?></td>
455 96c7a492 Matthew Grooms
						</tr>
456
457
						<tr>
458 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
459 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
460 dd5bf424 Scott Ullrich
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
461 96c7a492 Matthew Grooms
								<br>
462 a37753d7 Vinicius Coque
									<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
463 96c7a492 Matthew Grooms
							</td>
464
						</tr>
465
						<tr>
466 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Private key data");?></td>
467 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
468 dd5bf424 Scott Ullrich
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
469 96c7a492 Matthew Grooms
								<br>
470 a37753d7 Vinicius Coque
								<?=gettext("Paste a private key in X.509 PEM format here.");?></td>
471 96c7a492 Matthew Grooms
							</td>
472
						</tr>
473
					</table>
474
475
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
476
						<tr>
477
							<td colspan="2" class="list" height="12"></td>
478
						</tr>
479
						<tr>
480 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate");?></td>
481 96c7a492 Matthew Grooms
						</tr>
482
483
						<?php if (!$internal_ca_count): ?>
484
485
						<tr>
486
							<td colspan="2" align="center" class="vtable">
487 a37753d7 Vinicius Coque
								<?=gettext("No internal Certificate Authorities have been defined. You must");?>
488
								<a href="system_camanager.php?act=new&method=internal"><?=gettext("create");?></a>
489
								<?=gettext("an internal CA before creating an internal certificate.");?>
490 96c7a492 Matthew Grooms
							</td>
491
						</tr>
492
493
						<?php else: ?>
494
495
						<tr>
496
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
497
							<td width="78%" class="vtable">
498
								<select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
499
								<?php
500
									foreach( $a_ca as $ca):
501
									if (!$ca['prv'])
502
										continue;
503
									$selected = "";
504
									if ($pconfig['caref'] == $ca['refid'])
505
										$selected = "selected";
506
								?>
507 f2a86ca9 jim-p
									<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
508 96c7a492 Matthew Grooms
								<?php endforeach; ?>
509
								</select>
510
							</td>
511
						</tr>
512
						<tr>
513
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
514
							<td width="78%" class="vtable">
515
								<select name='keylen' class="formselect">
516
								<?php
517
									foreach( $cert_keylens as $len):
518
									$selected = "";
519
									if ($pconfig['keylen'] == $len)
520
										$selected = "selected";
521
								?>
522
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
523
								<?php endforeach; ?>
524
								</select>
525 a37753d7 Vinicius Coque
								<?=gettext("bits");?>
526 96c7a492 Matthew Grooms
							</td>
527
						</tr>
528
						<tr>
529
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
530
							<td width="78%" class="vtable">
531
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
532 a37753d7 Vinicius Coque
								<?=gettext("days");?>
533 96c7a492 Matthew Grooms
							</td>
534
						</tr>
535
						<tr>
536
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
537
							<td width="78%" class="vtable">
538
								<table border="0" cellspacing="0" cellpadding="2">
539
									<tr>
540 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
541 96c7a492 Matthew Grooms
										<td align="left">
542 cee476e8 Ermal Lu?i
											<input name="dn_country" type="text" class="formfld unknown" maxlength="2" size="2" value="<?=htmlspecialchars($pconfig['dn_country']);?>" readonly/>
543 96c7a492 Matthew Grooms
										</td>
544
									</tr>
545
									<tr>
546 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
547 96c7a492 Matthew Grooms
										<td align="left">
548
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>" readonly/>
549
										</td>
550
									</tr>
551
									<tr>
552 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
553 96c7a492 Matthew Grooms
										<td align="left">
554
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>" readonly/>
555
										</td>
556
									</tr>
557
									<tr>
558 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
559 96c7a492 Matthew Grooms
										<td align="left">
560
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>" readonly/>
561
										</td>
562
									</tr>
563
									<tr>
564 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
565 96c7a492 Matthew Grooms
										<td align="left">
566
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
567
											&nbsp;
568
											<em>ex:</em>
569
											&nbsp;
570 a37753d7 Vinicius Coque
											<?=gettext("webadmin@mycompany.com");?>
571 96c7a492 Matthew Grooms
										</td>
572
									</tr>
573
									<tr>
574 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
575 96c7a492 Matthew Grooms
										<td align="left">
576 ad9b5c67 jim-p
											<?php
577
											if ($a_user && empty($pconfig['dn_commonname']))
578
												$pconfig['dn_commonname'] = $a_user[$userid]['name'];
579
											?>
580 96c7a492 Matthew Grooms
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
581
											&nbsp;
582
											<em>ex:</em>
583
											&nbsp;
584 a37753d7 Vinicius Coque
											<?=gettext("www.example.com");?>
585 96c7a492 Matthew Grooms
										</td>
586
									</tr>
587
								</table>
588
							</td>
589
						</tr>
590 64cc39d3 Matthew Grooms
591
					<?php endif; ?>
592
593 96c7a492 Matthew Grooms
					</table>
594
595
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="external">
596
						<tr>
597
							<td colspan="2" class="list" height="12"></td>
598
						</tr>
599
						<tr>
600 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("External Signing Request");?></td>
601 96c7a492 Matthew Grooms
						</tr>
602
						<tr>
603
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
604
							<td width="78%" class="vtable">
605
								<select name='csr_keylen' class="formselect">
606
								<?php
607
									foreach( $cert_keylens as $len):
608
									$selected = "";
609
									if ($pconfig['keylen'] == $len)
610
										$selected = "selected";
611
								?>
612
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
613
								<?php endforeach; ?>
614
								</select>
615
								bits
616
							</td>
617
						</tr>
618
						<tr>
619
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
620
							<td width="78%" class="vtable">
621
								<table border="0" cellspacing="0" cellpadding="2">
622
									<tr>
623 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
624 96c7a492 Matthew Grooms
										<td align="left">
625
											<input name="csr_dn_country" type="text" class="formfld unknown" size="2" value="<?=htmlspecialchars($pconfig['csr_dn_country']);?>" />
626
											&nbsp;
627
											<em>ex:</em>
628
											&nbsp;
629
											US
630
											&nbsp;
631 a37753d7 Vinicius Coque
											<em><?=gettext("( two letters )");?></em>
632 96c7a492 Matthew Grooms
										</td>
633
									</tr>
634
									<tr>
635 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
636 96c7a492 Matthew Grooms
										<td align="left">
637
											<input name="csr_dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_state']);?>" />
638
											&nbsp;
639
											<em>ex:</em>
640
											&nbsp;
641 a37753d7 Vinicius Coque
											<?=gettext("Texas");?>
642 96c7a492 Matthew Grooms
										</td>
643
									</tr>
644
									<tr>
645 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
646 96c7a492 Matthew Grooms
										<td align="left">
647
											<input name="csr_dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_city']);?>" />
648
											&nbsp;
649
											<em>ex:</em>
650
											&nbsp;
651 a37753d7 Vinicius Coque
											<?=gettext("Austin");?>
652 96c7a492 Matthew Grooms
										</td>
653
									</tr>
654
									<tr>
655 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
656 96c7a492 Matthew Grooms
										<td align="left">
657
											<input name="csr_dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_organization']);?>" />
658
											&nbsp;
659
											<em>ex:</em>
660
											&nbsp;
661 a37753d7 Vinicius Coque
											<?=gettext("My Company Inc.");?>
662 96c7a492 Matthew Grooms
										</td>
663
									</tr>
664
									<tr>
665 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
666 96c7a492 Matthew Grooms
										<td align="left">
667
											<input name="csr_dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_email']);?>"/>
668
											&nbsp;
669
											<em>ex:</em>
670
											&nbsp;
671 a37753d7 Vinicius Coque
											<?=gettext("webadmin@mycompany.com");?>
672 96c7a492 Matthew Grooms
										</td>
673
									</tr>
674
									<tr>
675 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
676 96c7a492 Matthew Grooms
										<td align="left">
677
											<input name="csr_dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_commonname']);?>"/>
678
											&nbsp;
679
											<em>ex:</em>
680
											&nbsp;
681 a37753d7 Vinicius Coque
											<?=gettext("www.example.com");?>
682 96c7a492 Matthew Grooms
										</td>
683
									</tr>
684
								</table>
685
							</td>
686
						</tr>
687
					</table>
688
689 ad9b5c67 jim-p
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
690
						<tr>
691
							<td colspan="2" class="list" height="12"></td>
692
						</tr>
693
						<tr>
694
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Choose an Existing Certificate");?></td>
695
						</tr>
696
						<tr>
697
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Existing Certificates");?></td>
698
							<td width="78%" class="vtable">
699
								<?php if (isset($userid) && $a_user): ?>
700
								<input name="userid" type="hidden" value="<?=$userid;?>" />
701
								<?php endif;?>
702
								<select name='certref' class="formselect">
703
								<?php
704
									foreach ($config['cert'] as $cert):
705
										$selected = "";
706
										$caname = "";
707
										$inuse = "";
708 6a0b3ea4 jim-p
										$revoked = "";
709 ad9b5c67 jim-p
										if (in_array($cert['refid'], $config['system']['user'][$userid]['cert']))
710
											continue;
711
										$ca = lookup_ca($cert['caref']);
712
										if ($ca)
713 f2a86ca9 jim-p
											$caname = " (CA: {$ca['descr']})";
714 ad9b5c67 jim-p
										if ($pconfig['certref'] == $cert['refid'])
715
											$selected = "selected";
716
										if (cert_in_use($cert['refid']))
717
											$inuse = " *In Use";
718 6a0b3ea4 jim-p
											if (is_cert_revoked($cert))
719
											$revoked = " *Revoked";
720 ad9b5c67 jim-p
								?>
721 6a0b3ea4 jim-p
									<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
722 ad9b5c67 jim-p
								<?php endforeach; ?>
723
								</select>
724
							</td>
725
						</tr>
726
					</table>
727
728 96c7a492 Matthew Grooms
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
729
						<tr>
730
							<td width="22%" valign="top">&nbsp;</td>
731
							<td width="78%">
732 e64aa6f8 Carlos Eduardo Ramos
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
733 96c7a492 Matthew Grooms
								<?php if (isset($id) && $a_cert[$id]): ?>
734
								<input name="id" type="hidden" value="<?=$id;?>" />
735
								<?php endif;?>
736
							</td>
737
						</tr>
738
					</table>
739
				</form>
740
741 e64aa6f8 Carlos Eduardo Ramos
				<?php elseif ($act == "csr" || (($_POST['save'] == gettext("Update")) && $input_errors)):?>
742 96c7a492 Matthew Grooms
743
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
744
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
745
						<tr>
746
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
747
							<td width="78%" class="vtable">
748 f2a86ca9 jim-p
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
749 96c7a492 Matthew Grooms
							</td>
750
						</tr>
751
						<tr>
752
							<td colspan="2" class="list" height="12"></td>
753
						</tr>
754
						<tr>
755 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Complete Signing Request");?></td>
756 96c7a492 Matthew Grooms
						</tr>
757
758
						<tr>
759 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Request data");?></td>
760 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
761 dd5bf424 Scott Ullrich
								<textarea name="csr" id="csr" cols="65" rows="7" class="formfld_cert" readonly><?=htmlspecialchars($pconfig['csr']);?></textarea>
762 96c7a492 Matthew Grooms
								<br>
763 a37753d7 Vinicius Coque
								<?=gettext("Copy the certificate signing data from here and forward it to your certificate authority for signing.");?></td>
764 96c7a492 Matthew Grooms
							</td>
765
						</tr>
766
						<tr>
767 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Final Certificate data");?></td>
768 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
769 dd5bf424 Scott Ullrich
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
770 96c7a492 Matthew Grooms
								<br>
771 a37753d7 Vinicius Coque
								<?=gettext("Paste the certificate received from your cerificate authority here.");?></td>
772 96c7a492 Matthew Grooms
							</td>
773
						</tr>
774
						<tr>
775
							<td width="22%" valign="top">&nbsp;</td>
776
							<td width="78%">
777 e64aa6f8 Carlos Eduardo Ramos
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Update");?>" />
778 96c7a492 Matthew Grooms
								<?php if (isset($id) && $a_cert[$id]): ?>
779
								<input name="id" type="hidden" value="<?=$id;?>" />
780
								<input name="act" type="hidden" value="csr" />
781
								<?php endif;?>
782
							</td>
783
						</tr>
784
					</table>
785
				</form>
786
787
				<?php else:?>
788
789
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
790 64cc39d3 Matthew Grooms
					<tr>
791 d590fa20 jim-p
						<td width="15%" class="listhdrr"><?=gettext("Name");?></td>
792
						<td width="15%" class="listhdrr"><?=gettext("Issuer");?></td>
793 a37753d7 Vinicius Coque
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
794 d590fa20 jim-p
						<td width="10%" class="listhdrr"><?=gettext("In Use");?></td>
795 96c7a492 Matthew Grooms
						<td width="10%" class="list"></td>
796 64cc39d3 Matthew Grooms
					</tr>
797 96c7a492 Matthew Grooms
					<?php
798
						$i = 0;
799
						foreach($a_cert as $cert):
800 f2a86ca9 jim-p
							$name = htmlspecialchars($cert['descr']);
801 96c7a492 Matthew Grooms
802
							if ($cert['crt']) {
803 2cf6ddcb Nigel Graham
								$subj = cert_get_subject($cert['crt']);
804
								$issuer = cert_get_issuer($cert['crt']);
805
								if($subj==$issuer)
806 a37753d7 Vinicius Coque
								  $caname = "<em>" . gettext("self-signed") . "</em>";
807 2cf6ddcb Nigel Graham
								else
808 a37753d7 Vinicius Coque
							    $caname = "<em>" . gettext("external"). "</em>";
809 2cf6ddcb Nigel Graham
							  $subj = htmlspecialchars($subj);
810 96c7a492 Matthew Grooms
							}
811
812
							if ($cert['csr']) {
813
								$subj = htmlspecialchars(csr_get_subject($cert['csr']));
814 a37753d7 Vinicius Coque
								$caname = "<em>" . gettext("external - signature pending") . "</em>";
815 96c7a492 Matthew Grooms
							}
816
817
							$ca = lookup_ca($cert['caref']);
818
							if ($ca)
819 f2a86ca9 jim-p
								$caname = $ca['descr'];
820 96c7a492 Matthew Grooms
821
							if($cert['prv'])
822
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
823
							else
824
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
825
					?>
826 64cc39d3 Matthew Grooms
					<tr>
827 96c7a492 Matthew Grooms
						<td class="listlr">
828
							<table border="0" cellpadding="0" cellspacing="0">
829 64cc39d3 Matthew Grooms
								<tr>
830 96c7a492 Matthew Grooms
									<td align="left" valign="center">
831
										<img src="<?=$certimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
832 64cc39d3 Matthew Grooms
									</td>
833 96c7a492 Matthew Grooms
									<td align="left" valign="middle">
834
										<?=$name;?>
835 64cc39d3 Matthew Grooms
									</td>
836
								</tr>
837
							</table>
838
						</td>
839 96c7a492 Matthew Grooms
						<td class="listr"><?=$caname;?>&nbsp;</td>
840
						<td class="listr"><?=$subj;?>&nbsp;</td>
841 d590fa20 jim-p
						<td class="listr">
842 150bbe09 jim-p
							<?php if (is_cert_revoked($cert)): ?>
843
							<b>Revoked</b><br/>
844
							<?php endif; ?>
845 d590fa20 jim-p
							<?php if (is_webgui_cert($cert['refid'])): ?>
846
							webConfigurator<br/>
847
							<?php endif; ?>
848
							<?php if (is_user_cert($cert['refid'])): ?>
849
							User Cert<br/>
850
							<?php endif; ?>
851
							<?php if (is_openvpn_server_cert($cert['refid'])): ?>
852
							OpenVPN Server<br/>
853
							<?php endif; ?>
854
							<?php if (is_openvpn_client_cert($cert['refid'])): ?>
855
							OpenVPN Client<br/>
856
							<?php endif; ?>
857
							<?php if (is_ipsec_cert($cert['refid'])): ?>
858
							IPsec Tunnel<br/>
859
							<?php endif; ?>
860
						</td>
861 96c7a492 Matthew Grooms
						<td valign="middle" nowrap class="list">
862 ea53e38f Renato Botelho
							<a href="system_certmanager.php?act=exp&id=<?=$i;?>">
863 a37753d7 Vinicius Coque
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export cert");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
864 96c7a492 Matthew Grooms
							</a>
865 ea53e38f Renato Botelho
							<a href="system_certmanager.php?act=key&id=<?=$i;?>">
866 a37753d7 Vinicius Coque
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export key");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
867 73fbece8 mgrooms
							</a>
868 0879599c jim-p
							<?php	if (!cert_in_use($cert['refid'])): ?>
869 96c7a492 Matthew Grooms
							<a href="system_certmanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Certificate?");?>')">
870 a37753d7 Vinicius Coque
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete cert");?>" alt="<?=gettext("delete cert");?>" width="17" height="17" border="0" />
871 96c7a492 Matthew Grooms
							</a>
872 0879599c jim-p
							<?php	endif; ?>
873 96c7a492 Matthew Grooms
							<?php	if ($cert['csr']): ?>
874
							&nbsp;
875
								<a href="system_certmanager.php?act=csr&id=<?=$i;?>">
876 a37753d7 Vinicius Coque
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("update csr");?>" alt="<?=gettext("update csr");?>" width="17" height="17" border="0" />
877 96c7a492 Matthew Grooms
							</a>
878
							<?php	endif; ?>
879 64cc39d3 Matthew Grooms
						</td>
880
					</tr>
881 96c7a492 Matthew Grooms
					<?php
882
							$i++;
883
						endforeach;
884
					?>
885 64cc39d3 Matthew Grooms
					<tr>
886 0879599c jim-p
						<td class="list" colspan="4"></td>
887 96c7a492 Matthew Grooms
						<td class="list">
888
							<a href="system_certmanager.php?act=new">
889 a37753d7 Vinicius Coque
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add or import ca");?>" alt="<?=gettext("add ca");?>" width="17" height="17" border="0" />
890 96c7a492 Matthew Grooms
							</a>
891 64cc39d3 Matthew Grooms
						</td>
892
					</tr>
893 0879599c jim-p
					<tr>
894
						<td>&nbsp;</td>
895
						<td colspan="3">NOTE: You can only delete a certificate if it is not currently in use.</td>
896
					</tr>
897 64cc39d3 Matthew Grooms
				</table>
898
899 96c7a492 Matthew Grooms
				<?php endif; ?>
900 64cc39d3 Matthew Grooms
901 96c7a492 Matthew Grooms
			</div>
902 64cc39d3 Matthew Grooms
		</td>
903
	</tr>
904
</table>
905
<?php include("fend.inc");?>
906
<script type="text/javascript">
907
<!--
908
909
method_change();
910
internalca_change();
911
912
//-->
913
</script>
914
915
</body>