Project

General

Profile

Download (24.7 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
	"existing" => "Import an existing Certificate",
45
	"internal" => "Create an internal Certificate",
46
	"external" => "Create a Certificate Signing Request");
47
48
$cert_keylens = array( "512", "1024", "2048", "4096");
49
50
$pgtitle = array("System", "Certificate Manager");
51
52
$id = $_GET['id'];
53
if (isset($_POST['id']))
54
	$id = $_POST['id'];
55
56
if (!is_array($config['system']['ca']))
57
	$config['system']['ca'] = array();
58
59
$a_ca =& $config['system']['ca'];
60
61
if (!is_array($config['system']['cert']))
62
	$config['system']['cert'] = array();
63
64
$a_cert =& $config['system']['cert'];
65
66
$internal_ca_count = 0;
67
foreach ($a_ca as $ca)
68
	if ($ca['prv'])	
69
		$internal_ca_count++;
70
71
$act = $_GET['act'];
72
if ($_POST['act'])
73
	$act = $_POST['act'];
74
75
if ($act == "del") {
76
77
	if (!$a_cert[$id]) {
78
		pfSenseHeader("system_certmanager.php");
79
		exit;
80
	}
81
82
	$name = $a_cert[$id]['name'];
83
	unset($a_cert[$id]);
84
	write_config();
85
	$savemsg = gettext("Certificate")." {$name} ".
86
				gettext("successfully deleted")."<br/>";
87
}
88
89
if ($act == "new") {
90
	$pconfig['method'] = $_GET['method'];
91
	$pconfig['keylen'] = "2048";
92 cf360495 Chris Buechler
	$pconfig['lifetime'] = "3650";
93 64cc39d3 Matthew Grooms
}
94
95 93823b10 Matthew Grooms
if ($act == "exp") {
96
97
	if (!$a_cert[$id]) {
98
		pfSenseHeader("system_certmanager.php");
99
		exit;
100
	}
101
102
	$exp_name = urlencode("{$a_cert[$id]['name']}.crt");
103
	$exp_data = base64_decode($a_cert[$id]['crt']);
104
	$exp_size = strlen($exp_data);
105
106
	header("Content-Type: application/octet-stream");
107
	header("Content-Disposition: attachment; filename={$exp_name}");
108
	header("Content-Length: $exp_size");
109
	echo $exp_data;
110
	exit;
111
}
112
113 73fbece8 mgrooms
if ($act == "key") {
114
115
	if (!$a_cert[$id]) {
116
		pfSenseHeader("system_certmanager.php");
117
		exit;
118
	}
119
120
	$exp_name = urlencode("{$a_cert[$id]['name']}.key");
121
	$exp_data = base64_decode($a_cert[$id]['prv']);
122
	$exp_size = strlen($exp_data);
123
124
	header("Content-Type: application/octet-stream");
125
	header("Content-Disposition: attachment; filename={$exp_name}");
126
	header("Content-Length: $exp_size");
127
	echo $exp_data;
128
	exit;
129
}
130
131 64cc39d3 Matthew Grooms
if ($act == "csr") {
132
133
	if (!$a_cert[$id]) {
134
		pfSenseHeader("system_certmanager.php");
135
		exit;
136
	}
137
138
	$pconfig['name'] = $a_cert[$id]['name'];
139
	$pconfig['csr'] = base64_decode($a_cert[$id]['csr']);
140
}
141
142
if ($_POST) {
143
144
	if ($_POST['save'] == "Save") {
145
146
		unset($input_errors);
147
		$pconfig = $_POST;
148
149
		/* input validation */
150
		if ($pconfig['method'] == "existing") {
151
			$reqdfields = explode(" ",
152
					"name cert key");
153
			$reqdfieldsn = explode(",",
154 5d55ecfc Chris Buechler
					"Descriptive name,Certificate data,Key data");
155 64cc39d3 Matthew Grooms
		}
156
157
		if ($pconfig['method'] == "internal") {
158
			$reqdfields = explode(" ",
159
					"name caref keylen lifetime dn_country dn_state dn_city ".
160
					"dn_organization dn_email dn_commonname");
161
			$reqdfieldsn = explode(",",
162 5d55ecfc Chris Buechler
					"Descriptive name,Certificate authority,Key length,Lifetime,".
163 64cc39d3 Matthew Grooms
					"Distinguished name Country Code,".
164
					"Distinguished name State or Province,".
165
					"Distinguished name City,".
166
					"Distinguished name Organization,".
167
					"Distinguished name Email Address,".
168
					"Distinguished name Common Name");
169
		}
170
171
		if ($pconfig['method'] == "external") {
172
			$reqdfields = explode(" ",
173
					"name csr_keylen csr_dn_country csr_dn_state csr_dn_city ".
174
					"csr_dn_organization csr_dn_email csr_dn_commonname");
175
			$reqdfieldsn = explode(",",
176 5d55ecfc Chris Buechler
					"Descriptive name,Key length,".
177 64cc39d3 Matthew Grooms
					"Distinguished name Country Code,".
178
					"Distinguished name State or Province,".
179
					"Distinguished name City,".
180
					"Distinguished name Organization,".
181
					"Distinguished name Email Address,".
182
					"Distinguished name Common Name");
183
		}
184
185
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
186
187
		/* if this is an AJAX caller then handle via JSON */
188
		if (isAjax() && is_array($input_errors)) {
189
			input_errors2Ajax($input_errors);
190
			exit;
191
		}
192
193
		/* save modifications */
194
		if (!$input_errors) {
195
196
			$cert = array();
197
			$cert['refid'] = uniqid();
198
			if (isset($id) && $a_cert[$id])
199
				$cert = $a_cert[$id];
200
201
		    $cert['name'] = $pconfig['name'];
202
203
			if ($pconfig['method'] == "existing")
204
				cert_import($cert, $pconfig['cert'], $pconfig['key']);
205
206
			if ($pconfig['method'] == "internal") {
207
				$dn = array(
208
					'countryName' => $pconfig['dn_country'],
209
					'stateOrProvinceName' => $pconfig['dn_state'],
210
					'localityName' => $pconfig['dn_city'],
211
					'organizationName' => $pconfig['dn_organization'],
212
					'emailAddress' => $pconfig['dn_email'],
213
					'commonName' => $pconfig['dn_commonname']);
214
215
				cert_create($cert, $pconfig['caref'], $pconfig['keylen'],
216
					$pconfig['lifetime'], $dn);
217
			}
218
219
			if ($pconfig['method'] == "external") {
220
				$dn = array(
221
					'countryName' => $pconfig['csr_dn_country'],
222
					'stateOrProvinceName' => $pconfig['csr_dn_state'],
223
					'localityName' => $pconfig['csr_dn_city'],
224
					'organizationName' => $pconfig['csr_dn_organization'],
225
					'emailAddress' => $pconfig['csr_dn_email'],
226
					'commonName' => $pconfig['csr_dn_commonname']);
227
228
				csr_generate($cert, $pconfig['csr_keylen'], $dn);
229
			}
230
231
			if (isset($id) && $a_cert[$id])
232
				$a_cert[$id] = $cert;
233
			else
234
				$a_cert[] = $cert;
235
236
			write_config();
237
238
//			pfSenseHeader("system_certmanager.php");
239
		}
240
	}
241
242
	if ($_POST['save'] == "Update") {
243
		unset($input_errors);
244
		$pconfig = $_POST;
245
246
		/* input validation */
247
		$reqdfields = explode(" ", "name cert");
248 5d55ecfc Chris Buechler
		$reqdfieldsn = explode(",", "Descriptive name,Final Certificate data");
249 64cc39d3 Matthew Grooms
250
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
251
252
		/* make sure this csr and certificate subjects match */
253
		$subj_csr = csr_get_subject($pconfig['csr'], false);
254
		$subj_cert = cert_get_subject($pconfig['cert'], false);
255
256
		if (strcmp($subj_csr,$subj_cert))
257
			$input_errors[] = gettext("The certificate subject '{$subj_cert}' does not match the signing request subject.");
258
259
		/* if this is an AJAX caller then handle via JSON */
260
		if (isAjax() && is_array($input_errors)) {
261
			input_errors2Ajax($input_errors);
262
			exit;
263
		}
264
265
		/* save modifications */
266
		if (!$input_errors) {
267
268
			$cert = $a_cert[$id];
269
270
			$cert['name'] = $pconfig['name'];
271
272
			csr_complete($cert, $pconfig['cert']);
273
274
			$a_cert[$id] = $cert;
275
276
			write_config();
277
278
			pfSenseHeader("system_certmanager.php");
279
		}
280
	}
281
}
282
283
include("head.inc");
284
?>
285
286
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
287
<?php include("fbegin.inc"); ?>
288
<script type="text/javascript">
289
<!--
290
291
function method_change() {
292
293
<?php
294
	if ($internal_ca_count)
295
		$submit_style = "";
296
	else
297
		$submit_style = "none";
298
?>
299
300
	method = document.iform.method.selectedIndex;
301
302
	switch (method) {
303
		case 0:
304
			document.getElementById("existing").style.display="";
305
			document.getElementById("internal").style.display="none";
306
			document.getElementById("external").style.display="none";
307 96c7a492 Matthew Grooms
			document.getElementById("submit").style.display="";
308 64cc39d3 Matthew Grooms
			break;
309
		case 1:
310
			document.getElementById("existing").style.display="none";
311
			document.getElementById("internal").style.display="";
312
			document.getElementById("external").style.display="none";
313
			document.getElementById("submit").style.display="<?=$submit_style;?>";
314
			break;
315
		case 2:
316
			document.getElementById("existing").style.display="none";
317
			document.getElementById("internal").style.display="none";
318
			document.getElementById("external").style.display="";
319 96c7a492 Matthew Grooms
			document.getElementById("submit").style.display="";
320 64cc39d3 Matthew Grooms
			break;
321
	}
322
}
323
324
<?php if ($internal_ca_count): ?>
325
function internalca_change() {
326
327
	index = document.iform.caref.selectedIndex;
328
	caref = document.iform.caref[index].value;
329
330
	switch (caref) {
331
<?php
332
		foreach ($a_ca as $ca):
333
			if (!$ca['prv'])
334
				continue;
335
			$subject = cert_get_subject_array($ca['crt']);
336
?>
337
		case "<?=$ca['refid'];?>":
338
			document.iform.dn_country.value = "<?=$subject[0]['v'];?>";
339
			document.iform.dn_state.value = "<?=$subject[1]['v'];?>";
340
			document.iform.dn_city.value = "<?=$subject[2]['v'];?>";
341
			document.iform.dn_organization.value = "<?=$subject[3]['v'];?>";
342
			break;
343
<?php	endforeach; ?>
344
	}
345
}
346
<?php endif; ?>
347
348
//-->
349
</script>
350
<?php
351
	if ($input_errors)
352
		print_input_errors($input_errors);
353
	if ($savemsg)
354
		print_info_box($savemsg);
355
?>
356
<table width="100%" border="0" cellpadding="0" cellspacing="0">
357
	<tr>
358
		<td class="tabnavtbl">
359
		<?php
360
			$tab_array = array();
361
			$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
362
			$tab_array[] = array(gettext("Certificates"), true, "system_certmanager.php");
363
			display_top_tabs($tab_array);
364
		?>
365
		</td>
366
	</tr>
367
	<tr>
368 96c7a492 Matthew Grooms
		<td id="mainarea">
369
			<div class="tabcont">
370
371
				<?php if ($act == "new" || (($_POST['save'] == "Save") && $input_errors)): ?>
372
373
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
374
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
375
						<tr>
376
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
377
							<td width="78%" class="vtable">
378
								<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"/>
379
							</td>
380
						</tr>
381
						<?php if (!isset($id)): ?>
382
						<tr>
383
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
384
							<td width="78%" class="vtable">
385
								<select name='method' id='method' class="formselect" onchange='method_change()'>
386
								<?php
387
									foreach($cert_methods as $method => $desc):
388
									$selected = "";
389
									if ($pconfig['method'] == $method)
390
										$selected = "selected";
391
								?>
392
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
393
								<?php endforeach; ?>
394
								</select>
395
							</td>
396
						</tr>
397
						<?php endif; ?>
398
					</table>
399
400
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
401
						<tr>
402
							<td colspan="2" class="list" height="12"></td>
403
						</tr>
404
						<tr>
405
							<td colspan="2" valign="top" class="listtopic">Existing Certificate</td>
406
						</tr>
407
408
						<tr>
409
							<td width="22%" valign="top" class="vncellreq">Certificate data</td>
410
							<td width="78%" class="vtable">
411
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=$pconfig['cert'];?></textarea>
412
								<br>
413
								Paste a certificate in X.509 PEM format here.</td>
414
							</td>
415
						</tr>
416
						<tr>
417
							<td width="22%" valign="top" class="vncellreq">Private key data</td>
418
							<td width="78%" class="vtable">
419
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=$pconfig['key'];?></textarea>
420
								<br>
421
								Paste a private key in X.509 PEM format here.</td>
422
							</td>
423
						</tr>
424
					</table>
425
426
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
427
						<tr>
428
							<td colspan="2" class="list" height="12"></td>
429
						</tr>
430
						<tr>
431
							<td colspan="2" valign="top" class="listtopic">Internal Certificate</td>
432
						</tr>
433
434
						<?php if (!$internal_ca_count): ?>
435
436
						<tr>
437
							<td colspan="2" align="center" class="vtable">
438
								No internal Certificate Authorities have been defined. You must
439
								<a href="system_camanager.php?act=new&method=internal">create</a>
440
								an internal CA before creating an internal certificate.
441
							</td>
442
						</tr>
443
444
						<?php else: ?>
445
446
						<tr>
447
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
448
							<td width="78%" class="vtable">
449
								<select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
450
								<?php
451
									foreach( $a_ca as $ca):
452
									if (!$ca['prv'])
453
										continue;
454
									$selected = "";
455
									if ($pconfig['caref'] == $ca['refid'])
456
										$selected = "selected";
457
								?>
458
									<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['name'];?></option>
459
								<?php endforeach; ?>
460
								</select>
461
							</td>
462
						</tr>
463
						<tr>
464
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
465
							<td width="78%" class="vtable">
466
								<select name='keylen' class="formselect">
467
								<?php
468
									foreach( $cert_keylens as $len):
469
									$selected = "";
470
									if ($pconfig['keylen'] == $len)
471
										$selected = "selected";
472
								?>
473
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
474
								<?php endforeach; ?>
475
								</select>
476
								bits
477
							</td>
478
						</tr>
479
						<tr>
480
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
481
							<td width="78%" class="vtable">
482
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
483
								days
484
							</td>
485
						</tr>
486
						<tr>
487
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
488
							<td width="78%" class="vtable">
489
								<table border="0" cellspacing="0" cellpadding="2">
490
									<tr>
491
										<td align="right">Country Code : &nbsp;</td>
492
										<td align="left">
493 cee476e8 Ermal Lu?i
											<input name="dn_country" type="text" class="formfld unknown" maxlength="2" size="2" value="<?=htmlspecialchars($pconfig['dn_country']);?>" readonly/>
494 96c7a492 Matthew Grooms
										</td>
495
									</tr>
496
									<tr>
497
										<td align="right">State or Province : &nbsp;</td>
498
										<td align="left">
499
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>" readonly/>
500
										</td>
501
									</tr>
502
									<tr>
503
										<td align="right">City : &nbsp;</td>
504
										<td align="left">
505
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>" readonly/>
506
										</td>
507
									</tr>
508
									<tr>
509
										<td align="right">Organization : &nbsp;</td>
510
										<td align="left">
511
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>" readonly/>
512
										</td>
513
									</tr>
514
									<tr>
515
										<td align="right">Email Address : &nbsp;</td>
516
										<td align="left">
517
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
518
											&nbsp;
519
											<em>ex:</em>
520
											&nbsp;
521
											webadmin@mycompany.com
522
										</td>
523
									</tr>
524
									<tr>
525
										<td align="right">Common Name : &nbsp;</td>
526
										<td align="left">
527
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
528
											&nbsp;
529
											<em>ex:</em>
530
											&nbsp;
531
											www.pfsense.org
532
										</td>
533
									</tr>
534
								</table>
535
							</td>
536
						</tr>
537 64cc39d3 Matthew Grooms
538
					<?php endif; ?>
539
540 96c7a492 Matthew Grooms
					</table>
541
542
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="external">
543
						<tr>
544
							<td colspan="2" class="list" height="12"></td>
545
						</tr>
546
						<tr>
547
							<td colspan="2" valign="top" class="listtopic">External Signing Request</td>
548
						</tr>
549
						<tr>
550
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
551
							<td width="78%" class="vtable">
552
								<select name='csr_keylen' class="formselect">
553
								<?php
554
									foreach( $cert_keylens as $len):
555
									$selected = "";
556
									if ($pconfig['keylen'] == $len)
557
										$selected = "selected";
558
								?>
559
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
560
								<?php endforeach; ?>
561
								</select>
562
								bits
563
							</td>
564
						</tr>
565
						<tr>
566
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
567
							<td width="78%" class="vtable">
568
								<table border="0" cellspacing="0" cellpadding="2">
569
									<tr>
570
										<td align="right">Country Code : &nbsp;</td>
571
										<td align="left">
572
											<input name="csr_dn_country" type="text" class="formfld unknown" size="2" value="<?=htmlspecialchars($pconfig['csr_dn_country']);?>" />
573
											&nbsp;
574
											<em>ex:</em>
575
											&nbsp;
576
											US
577
											&nbsp;
578
											<em>( two letters )</em>
579
										</td>
580
									</tr>
581
									<tr>
582
										<td align="right">State or Province : &nbsp;</td>
583
										<td align="left">
584
											<input name="csr_dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_state']);?>" />
585
											&nbsp;
586
											<em>ex:</em>
587
											&nbsp;
588
											Texas
589
										</td>
590
									</tr>
591
									<tr>
592
										<td align="right">City : &nbsp;</td>
593
										<td align="left">
594
											<input name="csr_dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_city']);?>" />
595
											&nbsp;
596
											<em>ex:</em>
597
											&nbsp;
598
											Austin
599
										</td>
600
									</tr>
601
									<tr>
602
										<td align="right">Organization : &nbsp;</td>
603
										<td align="left">
604
											<input name="csr_dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_organization']);?>" />
605
											&nbsp;
606
											<em>ex:</em>
607
											&nbsp;
608
											My Company Inc.
609
										</td>
610
									</tr>
611
									<tr>
612
										<td align="right">Email Address : &nbsp;</td>
613
										<td align="left">
614
											<input name="csr_dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_email']);?>"/>
615
											&nbsp;
616
											<em>ex:</em>
617
											&nbsp;
618
											webadmin@mycompany.com
619
										</td>
620
									</tr>
621
									<tr>
622
										<td align="right">Common Name : &nbsp;</td>
623
										<td align="left">
624
											<input name="csr_dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_commonname']);?>"/>
625
											&nbsp;
626
											<em>ex:</em>
627
											&nbsp;
628
											www.pfsense.org
629
										</td>
630
									</tr>
631
								</table>
632
							</td>
633
						</tr>
634
					</table>
635
636
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
637
						<tr>
638
							<td width="22%" valign="top">&nbsp;</td>
639
							<td width="78%">
640
								<input id="submit" name="save" type="submit" class="formbtn" value="Save" />
641
								<?php if (isset($id) && $a_cert[$id]): ?>
642
								<input name="id" type="hidden" value="<?=$id;?>" />
643
								<?php endif;?>
644
							</td>
645
						</tr>
646
					</table>
647
				</form>
648
649
				<?php elseif ($act == "csr" || (($_POST['save'] == "Update") && $input_errors)):?>
650
651
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
652
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
653
						<tr>
654
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
655
							<td width="78%" class="vtable">
656
								<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"/>
657
							</td>
658
						</tr>
659
						<tr>
660
							<td colspan="2" class="list" height="12"></td>
661
						</tr>
662
						<tr>
663
							<td colspan="2" valign="top" class="listtopic">Complete Signing Request</td>
664
						</tr>
665
666
						<tr>
667
							<td width="22%" valign="top" class="vncellreq">Signing Request data</td>
668
							<td width="78%" class="vtable">
669
								<textarea name="csr" id="csr" cols="65" rows="7" class="formfld_cert" readonly><?=$pconfig['csr'];?></textarea>
670
								<br>
671
								Copy the certificate signing data from here and forward it to your certificate authority for singing.</td>
672
							</td>
673
						</tr>
674
						<tr>
675
							<td width="22%" valign="top" class="vncellreq">Final Certificate data</td>
676
							<td width="78%" class="vtable">
677
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=$pconfig['cert'];?></textarea>
678
								<br>
679
								Paste the certificate received from your cerificate authority here.</td>
680
							</td>
681
						</tr>
682
						<tr>
683
							<td width="22%" valign="top">&nbsp;</td>
684
							<td width="78%">
685
								<input id="submit" name="save" type="submit" class="formbtn" value="Update" />
686
								<?php if (isset($id) && $a_cert[$id]): ?>
687
								<input name="id" type="hidden" value="<?=$id;?>" />
688
								<input name="act" type="hidden" value="csr" />
689
								<?php endif;?>
690
							</td>
691
						</tr>
692
					</table>
693
				</form>
694
695
				<?php else:?>
696
697
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
698 64cc39d3 Matthew Grooms
					<tr>
699 96c7a492 Matthew Grooms
						<td width="20%" class="listhdrr">Name</td>
700 2cf6ddcb Nigel Graham
						<td width="20%" class="listhdrr">Issuer</td>
701 96c7a492 Matthew Grooms
						<td width="40%" class="listhdrr">Distinguished Name</td>
702
						<td width="10%" class="list"></td>
703 64cc39d3 Matthew Grooms
					</tr>
704 96c7a492 Matthew Grooms
					<?php
705
						$i = 0;
706
						foreach($a_cert as $cert):
707
							$name = htmlspecialchars($cert['name']);
708
709
							if ($cert['crt']) {
710 2cf6ddcb Nigel Graham
								$subj = cert_get_subject($cert['crt']);
711
								$issuer = cert_get_issuer($cert['crt']);
712
								if($subj==$issuer)
713
								  $caname = "<em>self-signed</em>";
714
								else
715
							    $caname = "<em>external</em>";
716
							  $subj = htmlspecialchars($subj);
717 96c7a492 Matthew Grooms
							}
718
719
							if ($cert['csr']) {
720
								$subj = htmlspecialchars(csr_get_subject($cert['csr']));
721
								$caname = "<em>external - signature pending</em>";
722
							}
723
724
							$ca = lookup_ca($cert['caref']);
725
							if ($ca)
726
								$caname = $ca['name'];
727
728
							if($cert['prv'])
729
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
730
							else
731
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
732
					?>
733 64cc39d3 Matthew Grooms
					<tr>
734 96c7a492 Matthew Grooms
						<td class="listlr">
735
							<table border="0" cellpadding="0" cellspacing="0">
736 64cc39d3 Matthew Grooms
								<tr>
737 96c7a492 Matthew Grooms
									<td align="left" valign="center">
738
										<img src="<?=$certimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
739 64cc39d3 Matthew Grooms
									</td>
740 96c7a492 Matthew Grooms
									<td align="left" valign="middle">
741
										<?=$name;?>
742 64cc39d3 Matthew Grooms
									</td>
743
								</tr>
744
							</table>
745
						</td>
746 96c7a492 Matthew Grooms
						<td class="listr"><?=$caname;?>&nbsp;</td>
747
						<td class="listr"><?=$subj;?>&nbsp;</td>
748
						<td valign="middle" nowrap class="list">
749
							<a href="system_certmanager.php?act=exp&id=<?=$i;?>")">
750
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="export cert" alt="export ca" width="17" height="17" border="0" />
751
							</a>
752 73fbece8 mgrooms
							<a href="system_certmanager.php?act=key&id=<?=$i;?>")">
753
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="export key" alt="export ca" width="17" height="17" border="0" />
754
							</a>
755 96c7a492 Matthew Grooms
							<a href="system_certmanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Certificate?");?>')">
756
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="delete cert" alt="delete cert" width="17" height="17" border="0" />
757
							</a>
758
							<?php	if ($cert['csr']): ?>
759
							&nbsp;
760
								<a href="system_certmanager.php?act=csr&id=<?=$i;?>">
761
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="update csr" alt="update csr" width="17" height="17" border="0" />
762
							</a>
763
							<?php	endif; ?>
764 64cc39d3 Matthew Grooms
						</td>
765
					</tr>
766 96c7a492 Matthew Grooms
					<?php
767
							$i++;
768
						endforeach;
769
					?>
770 64cc39d3 Matthew Grooms
					<tr>
771 96c7a492 Matthew Grooms
						<td class="list" colspan="3"></td>
772
						<td class="list">
773
							<a href="system_certmanager.php?act=new">
774
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="add or import ca" alt="add ca" width="17" height="17" border="0" />
775
							</a>
776 64cc39d3 Matthew Grooms
						</td>
777
					</tr>
778
				</table>
779
780 96c7a492 Matthew Grooms
				<?php endif; ?>
781 64cc39d3 Matthew Grooms
782 96c7a492 Matthew Grooms
			</div>
783 64cc39d3 Matthew Grooms
		</td>
784
	</tr>
785
</table>
786
<?php include("fend.inc");?>
787
<script type="text/javascript">
788
<!--
789
790
method_change();
791
internalca_change();
792
793
//-->
794
</script>
795
796
</body>