Project

General

Profile

Download (23.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
    system_camanager.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
/*
30
	pfSense_MODULE:	certificate_managaer
31
*/
32

    
33
##|+PRIV
34
##|*IDENT=page-system-camanager
35
##|*NAME=System: CA Manager
36
##|*DESCR=Allow access to the 'System: CA Manager' page.
37
##|*MATCH=system_camanager.php*
38
##|-PRIV
39

    
40
require("guiconfig.inc");
41
require_once("certs.inc");
42

    
43
$ca_methods = array(
44
	"existing" => gettext("Import an existing Certificate Authority"),
45
	"internal" => gettext("Create an internal Certificate Authority"),
46
	"intermediate" => gettext("Create an intermediate Certificate Authority"));
47

    
48
$ca_keylens = array( "512", "1024", "2048", "4096");
49

    
50
$pgtitle = array(gettext("System"), gettext("Certificate Authority Manager"));
51

    
52
$id = $_GET['id'];
53
if (isset($_POST['id']))
54
	$id = $_POST['id'];
55

    
56
if (!is_array($config['ca']))
57
	$config['ca'] = array();
58

    
59
$a_ca =& $config['ca'];
60

    
61
if (!is_array($config['cert']))
62
	$config['cert'] = array();
63

    
64
$a_cert =& $config['cert'];
65

    
66
if (!is_array($config['crl']))
67
	$config['crl'] = array();
68

    
69
$a_crl =& $config['crl'];
70

    
71
$act = $_GET['act'];
72
if ($_POST['act'])
73
	$act = $_POST['act'];
74

    
75
if ($act == "del") {
76

    
77
	if (!$a_ca[$id]) {
78
		pfSenseHeader("system_camanager.php");
79
		exit;
80
	}
81

    
82
	$index = count($a_cert) - 1;
83
	for (;$index >=0; $index--)
84
		if ($a_cert[$index]['caref'] == $a_ca[$id]['refid'])
85
			unset($a_cert[$index]);
86

    
87
	$index = count($a_crl) - 1;
88
	for (;$index >=0; $index--)
89
		if ($a_crl[$index]['caref'] == $a_ca[$id]['refid'])
90
			unset($a_crl[$index]);
91

    
92
	$name = $a_ca[$id]['descr'];
93
	unset($a_ca[$id]);
94
	write_config();
95
	$savemsg = sprintf(gettext("Certificate Authority %s and its CRLs (if any) successfully deleted"), $name) . "<br/>";
96
	pfSenseHeader("system_camanager.php");
97
	exit;
98
}
99

    
100
if ($act == "edit") {
101
	if (!$a_ca[$id]) {
102
		pfSenseHeader("system_camanager.php");
103
		exit;
104
	}
105
	$pconfig['descr']  = $a_ca[$id]['descr'];
106
	$pconfig['refid']  = $a_ca[$id]['refid'];
107
	$pconfig['cert']   = base64_decode($a_ca[$id]['crt']);
108
	$pconfig['serial'] = $a_ca[$id]['serial'];
109
	if (!empty($a_ca[$id]['prv']))
110
		$pconfig['key'] = base64_decode($a_ca[$id]['prv']);
111
}
112

    
113
if ($act == "new") {
114
	$pconfig['method'] = $_GET['method'];
115
	$pconfig['keylen'] = "2048";
116
	$pconfig['lifetime'] = "3650";
117
	$pconfig['dn_commonname'] = "internal-ca";
118
}
119

    
120
if ($act == "exp") {
121

    
122
	if (!$a_ca[$id]) {
123
		pfSenseHeader("system_camanager.php");
124
		exit;
125
	}
126

    
127
	$exp_name = urlencode("{$a_ca[$id]['descr']}.crt");
128
	$exp_data = base64_decode($a_ca[$id]['crt']);
129
	$exp_size = strlen($exp_data);
130

    
131
	header("Content-Type: application/octet-stream");
132
	header("Content-Disposition: attachment; filename={$exp_name}");
133
	header("Content-Length: $exp_size");
134
	echo $exp_data;
135
	exit;
136
}
137

    
138
if ($act == "expkey") {
139

    
140
	if (!$a_ca[$id]) {
141
		pfSenseHeader("system_camanager.php");
142
		exit;
143
	}
144

    
145
	$exp_name = urlencode("{$a_ca[$id]['descr']}.key");
146
	$exp_data = base64_decode($a_ca[$id]['prv']);
147
	$exp_size = strlen($exp_data);
148

    
149
	header("Content-Type: application/octet-stream");
150
	header("Content-Disposition: attachment; filename={$exp_name}");
151
	header("Content-Length: $exp_size");
152
	echo $exp_data;
153
	exit;
154
}
155

    
156
if ($_POST) {
157

    
158
	unset($input_errors);
159
	$pconfig = $_POST;
160

    
161
	/* input validation */
162
	if ($pconfig['method'] == "existing") {
163
		$reqdfields = explode(" ", "descr cert");
164
		$reqdfieldsn = array(
165
				gettext("Descriptive name"),
166
				gettext("Certificate data"));
167
		if ($_POST['cert'] && (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE")))
168
			$input_errors[] = gettext("This certificate does not appear to be valid.");
169
		if ($_POST['key'] && strstr($_POST['key'], "ENCRYPTED"))
170
			$input_errors[] = gettext("Encrypted private keys are not yet supported.");
171
	}
172
	if ($pconfig['method'] == "internal") {
173
		$reqdfields = explode(" ",
174
				"descr keylen lifetime dn_country dn_state dn_city ".
175
				"dn_organization dn_email dn_commonname");
176
		$reqdfieldsn = array(
177
				gettext("Descriptive name"),
178
				gettext("Key length"),
179
				gettext("Lifetime"),
180
				gettext("Distinguished name Country Code"),
181
				gettext("Distinguished name State or Province"),
182
				gettext("Distinguished name City"),
183
				gettext("Distinguished name Organization"),
184
				gettext("Distinguished name Email Address"),
185
				gettext("Distinguished name Common Name"));
186
	}
187
	if ($pconfig['method'] == "intermediate") {
188
		$reqdfields = explode(" ",
189
				"descr caref keylen lifetime dn_country dn_state dn_city ".
190
				"dn_organization dn_email dn_commonname");
191
		$reqdfieldsn = array(
192
				gettext("Descriptive name"),
193
				gettext("Signing Certificate Authority"),
194
				gettext("Key length"),
195
				gettext("Lifetime"),
196
				gettext("Distinguished name Country Code"),
197
				gettext("Distinguished name State or Province"),
198
				gettext("Distinguished name City"),
199
				gettext("Distinguished name Organization"),
200
				gettext("Distinguished name Email Address"),
201
				gettext("Distinguished name Common Name"));
202
	}
203

    
204
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
205
	if ($pconfig['method'] != "existing")
206
		/* Make sure we do not have invalid characters in the fields for the certificate */
207
		for ($i = 0; $i < count($reqdfields); $i++) {
208
			if ($reqdfields[$i] == 'dn_email'){
209
				if (preg_match("/[\!\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_email"]))
210
					array_push($input_errors, "The field 'Distinguished name Email Address' contains invalid characters.");
211
			}else if ($reqdfields[$i] == 'dn_commonname'){
212
				if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_commonname"]))
213
					array_push($input_errors, "The field 'Distinguished name Common Name' contains invalid characters.");
214
			}else if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\.\"\']/", $_POST["$reqdfields[$i]"]))
215
				array_push($input_errors, "The field '" . $reqdfieldsn[$i] . "' contains invalid characters.");
216
		}
217

    
218
	/* if this is an AJAX caller then handle via JSON */
219
	if (isAjax() && is_array($input_errors)) {
220
		input_errors2Ajax($input_errors);
221
		exit;
222
	}
223

    
224
	/* save modifications */
225
	if (!$input_errors) {
226

    
227
		$ca = array();
228
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
229
			$ca['refid'] = uniqid();
230
		else
231
			$ca['refid'] = $pconfig['refid'];
232

    
233
		if (isset($id) && $a_ca[$id])
234
			$ca = $a_ca[$id];
235

    
236
		$ca['descr'] = $pconfig['descr'];
237

    
238
		if ($_POST['edit'] == "edit") {
239
			$ca['descr']  = $pconfig['descr'];
240
			$ca['refid']  = $pconfig['refid'];
241
			$ca['serial'] = $pconfig['serial'];
242
			$ca['crt']    = base64_encode($pconfig['cert']);
243
			if (!empty($pconfig['key']))
244
				$ca['prv']    = base64_encode($pconfig['key']);
245
		} else {
246
			$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
247
			if ($pconfig['method'] == "existing")
248
				ca_import($ca, $pconfig['cert'], $pconfig['key'], $pconfig['serial']);
249

    
250
			else if ($pconfig['method'] == "internal") {
251
				$dn = array(
252
					'countryName' => $pconfig['dn_country'],
253
					'stateOrProvinceName' => $pconfig['dn_state'],
254
					'localityName' => $pconfig['dn_city'],
255
					'organizationName' => $pconfig['dn_organization'],
256
					'emailAddress' => $pconfig['dn_email'],
257
					'commonName' => $pconfig['dn_commonname']);
258
				if (!ca_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn)){
259
					while($ssl_err = openssl_error_string()){
260
						$input_errors = array();
261
						array_push($input_errors, "openssl library returns: " . $ssl_err);
262
					}
263
				}
264
			}
265
			else if ($pconfig['method'] == "intermediate") {
266
				$dn = array(
267
					'countryName' => $pconfig['dn_country'],
268
					'stateOrProvinceName' => $pconfig['dn_state'],
269
					'localityName' => $pconfig['dn_city'],
270
					'organizationName' => $pconfig['dn_organization'],
271
					'emailAddress' => $pconfig['dn_email'],
272
					'commonName' => $pconfig['dn_commonname']);
273
				if (!ca_inter_create($ca, $pconfig['keylen'], $pconfig['lifetime'], $dn, $pconfig['caref'])){
274
					while($ssl_err = openssl_error_string()){
275
						$input_errors = array();
276
						array_push($input_errors, "openssl library returns: " . $ssl_err);
277
					}
278
				}
279
			}
280
			error_reporting($old_err_level);
281
		}
282

    
283
		if (isset($id) && $a_ca[$id])
284
			$a_ca[$id] = $ca;
285
		else
286
			$a_ca[] = $ca;
287

    
288
		if (!$input_errors)
289
			write_config();
290

    
291
//		pfSenseHeader("system_camanager.php");
292
	}
293
}
294

    
295
include("head.inc");
296
?>
297

    
298
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
299
<?php include("fbegin.inc"); ?>
300
<script type="text/javascript">
301
<!--
302

    
303
function method_change() {
304

    
305
	method = document.iform.method.selectedIndex;
306

    
307
	switch (method) {
308
		case 0:
309
			document.getElementById("existing").style.display="";
310
			document.getElementById("internal").style.display="none";
311
			document.getElementById("intermediate").style.display="none";
312
			break;
313
		case 1:
314
			document.getElementById("existing").style.display="none";
315
			document.getElementById("internal").style.display="";
316
			document.getElementById("intermediate").style.display="none";
317
			break;
318
		case 2:
319
			document.getElementById("existing").style.display="none";
320
			document.getElementById("internal").style.display="";
321
			document.getElementById("intermediate").style.display="";
322
			break;
323
	}
324
}
325

    
326
//-->
327
</script>
328
<?php
329
	if ($input_errors)
330
		print_input_errors($input_errors);
331
	if ($savemsg)
332
		print_info_box($savemsg);
333

    
334
	// Load valid country codes
335
	$dn_cc = array();
336
	if (file_exists("/etc/ca_countries")){
337
		$dn_cc_file=file("/etc/ca_countries");
338
		foreach($dn_cc_file as $line)
339
			if (preg_match('/^(\S*)\s(.*)$/', $line, $matches))
340
				array_push($dn_cc, $matches[1]);
341
	}
342
?>
343
<table width="100%" border="0" cellpadding="0" cellspacing="0">
344
	<tr>
345
		<td>
346
		<?php
347
			$tab_array = array();
348
			$tab_array[] = array(gettext("CAs"), true, "system_camanager.php");
349
			$tab_array[] = array(gettext("Certificates"), false, "system_certmanager.php");
350
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
351
			display_top_tabs($tab_array);
352
		?>
353
		</td>
354
	</tr>
355
	<tr>
356
		<td id="mainarea">
357
			<div class="tabcont">
358

    
359
				<?php if ($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors): ?>
360

    
361
				<form action="system_camanager.php" method="post" name="iform" id="iform">
362
					<?php if ($act == "edit"): ?>
363
					<input type="hidden" name="edit" value="edit" id="edit">
364
					<input type="hidden" name="id" value="<?php echo $id; ?>" id="id">
365
					<input type="hidden" name="refid" value="<?php echo $pconfig['refid']; ?>" id="refid">
366
					<?php endif; ?>
367
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
368
						<tr>
369
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
370
							<td width="78%" class="vtable">
371
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
372
							</td>
373
						</tr>
374
						<?php if (!isset($id) || $act == "edit"): ?>
375
						<tr>
376
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
377
							<td width="78%" class="vtable">
378
								<select name='method' id='method' class="formselect" onchange='method_change()'>
379
								<?php
380
									foreach($ca_methods as $method => $desc):
381
									$selected = "";
382
									if ($pconfig['method'] == $method)
383
										$selected = "selected";
384
								?>
385
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
386
								<?php endforeach; ?>
387
								</select>
388
							</td>
389
						</tr>
390
						<?php endif; ?>
391
					</table>
392

    
393
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
394
						<tr>
395
							<td colspan="2" class="list" height="12"></td>
396
						</tr>
397
						<tr>
398
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Authority");?></td>
399
						</tr>
400

    
401
						<tr>
402
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
403
							<td width="78%" class="vtable">
404
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
405
								<br>
406
								<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
407
							</td>
408
						</tr>
409
						<tr>
410
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br/><?=gettext("(optional)");?></td>
411
							<td width="78%" class="vtable">
412
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
413
								<br>
414
								<?=gettext("Paste the private key for the above certificate here. This is optional in most cases, but required if you need to generate a Certificate Revocation List (CRL).");?></td>
415
							</td>
416
						</tr>
417

    
418
					<?php if (!isset($id) || $act == "edit"): ?>
419
						<tr>
420
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Serial for next certificate");?></td>
421
							<td width="78%" class="vtable">
422
								<input name="serial" type="text" class="formfld unknown" id="serial" size="20" value="<?=htmlspecialchars($pconfig['serial']);?>"/>
423
								<br/><?=gettext("Enter a decimal number to be used as the serial number for the next certificate to be created using this CA.");?>
424
							</td>
425
						</tr>
426
					<?php endif; ?>
427
					</table>
428

    
429
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
430
						<tr>
431
							<td colspan="2" class="list" height="12"></td>
432
						</tr>
433
						<tr>
434
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate Authority");?></td>
435
						</tr>
436
						<tr id='intermediate'>
437
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Certificate Authority");?></td>
438
							<td width="78%" class="vtable">
439
                                                                <select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
440
                                                                <?php
441
                                                                        foreach( $a_ca as $ca):
442
                                                                        if (!$ca['prv'])
443
                                                                                continue;
444
                                                                        $selected = "";
445
                                                                        if ($pconfig['caref'] == $ca['refid'])
446
                                                                                $selected = "selected";
447
                                                                ?>
448
                                                                        <option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
449
                                                                <?php endforeach; ?>
450
                                                                </select>
451
							</td>
452
						</tr>
453
						<tr>
454
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
455
							<td width="78%" class="vtable">
456
								<select name='keylen' id='keylen' class="formselect">
457
								<?php
458
									foreach( $ca_keylens as $len):
459
									$selected = "";
460
									if ($pconfig['keylen'] == $len)
461
										$selected = "selected";
462
								?>
463
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
464
								<?php endforeach; ?>
465
								</select>
466
								<?=gettext("bits");?>
467
							</td>
468
						</tr>
469
						<tr>
470
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
471
							<td width="78%" class="vtable">
472
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
473
								<?=gettext("days");?>
474
							</td>
475
						</tr>
476
						<tr>
477
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
478
							<td width="78%" class="vtable">
479
								<table border="0" cellspacing="0" cellpadding="2">
480
									<tr>
481
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
482
										<td align="left">
483
											<select name='dn_country' class="formselect">
484
											<?php
485
											foreach( $dn_cc as $cc){
486
												$selected = "";
487
												if ($pconfig['dn_country'] == $cc) $selected = "selected";
488
												print "<option value=\"$cc\" $selected>$cc</option>";
489
												}
490
											?>
491
											</select>
492
										</td>
493
									</tr>
494
									<tr>
495
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
496
										<td align="left">
497
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>"/>
498
											&nbsp;
499
											<em><?=gettext("ex:");?></em>
500
											&nbsp;
501
											<?=gettext("Texas");?>
502
										</td>
503
									</tr>
504
									<tr>
505
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
506
										<td align="left">
507
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>"/>
508
											&nbsp;
509
											<em><?=gettext("ex:");?></em>
510
											&nbsp;
511
											<?=gettext("Austin");?>
512
										</td>
513
									</tr>
514
									<tr>
515
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
516
										<td align="left">
517
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>"/>
518
											&nbsp;
519
											<em><?=gettext("ex:");?></em>
520
											&nbsp;
521
											<?=gettext("My Company Inc.");?>
522
										</td>
523
									</tr>
524
									<tr>
525
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
526
										<td align="left">
527
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
528
											&nbsp;
529
											<em><?=gettext("ex:");?></em>
530
											&nbsp;
531
											<?=gettext("admin@mycompany.com");?>
532
										</td>
533
									</tr>
534
									<tr>
535
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
536
										<td align="left">
537
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
538
											&nbsp;
539
											<em><?=gettext("ex:");?></em>
540
											&nbsp;
541
											<?=gettext("internal-ca");?>
542
										</td>
543
									</tr>
544
								</table>
545
							</td>
546
						</tr>
547
					</table>
548

    
549
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
550
						<tr>
551
							<td width="22%" valign="top">&nbsp;</td>
552
							<td width="78%">
553
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
554
								<?php if (isset($id) && $a_ca[$id]): ?>
555
								<input name="id" type="hidden" value="<?=$id;?>" />
556
								<?php endif;?>
557
							</td>
558
						</tr>
559
					</table>
560
				</form>
561

    
562
				<?php else: ?>
563

    
564
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
565
					<tr>
566
						<td width="20%" class="listhdrr"><?=gettext("Name");?></td>
567
						<td width="10%" class="listhdrr"><?=gettext("Internal");?></td>
568
						<td width="10%" class="listhdrr"><?=gettext("Issuer");?></td>
569
						<td width="10%" class="listhdrr"><?=gettext("Certificates");?></td>
570
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
571
						<td width="10%" class="list"></td>
572
					</tr>
573
					<?php
574
						$i = 0;
575
						foreach($a_ca as $ca):
576
							$name = htmlspecialchars($ca['descr']);
577
							$subj = cert_get_subject($ca['crt']);
578
							$issuer = cert_get_issuer($ca['crt']);
579
							if($subj == $issuer)
580
							  $issuer_name = "<em>" . gettext("self-signed") . "</em>";
581
							else
582
							  $issuer_name = "<em>" . gettext("external") . "</em>";
583
							$subj = htmlspecialchars($subj);
584
							$issuer = htmlspecialchars($issuer);
585
							$certcount = 0;
586

    
587
							$issuer_ca = lookup_ca($ca['caref']);
588
							if ($issuer_ca)
589
								$issuer_name = $issuer_ca['descr'];
590

    
591
							// TODO : Need gray certificate icon
592

    
593
							if($ca['prv']) {
594
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
595
								$internal = "YES";
596

    
597
							} else {
598
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
599
								$internal = "NO";
600
							}
601
							foreach ($a_cert as $cert)
602
								if ($cert['caref'] == $ca['refid'])
603
									$certcount++;
604
  						foreach ($a_ca as $cert)
605
  							if ($cert['caref'] == $ca['refid'])
606
  								$certcount++;
607
					?>
608
					<tr>
609
						<td class="listlr">
610
							<table border="0" cellpadding="0" cellspacing="0">
611
								<tr>
612
									<td align="left" valign="center">
613
										<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
614
									</td>
615
									<td align="left" valign="middle">
616
										<?=$name;?>
617
									</td>
618
								</tr>
619
							</table>
620
						</td>
621
						<td class="listr"><?=$internal;?>&nbsp;</td>
622
						<td class="listr"><?=$issuer_name;?>&nbsp;</td>
623
						<td class="listr"><?=$certcount;?>&nbsp;</td>
624
						<td class="listr"><?=$subj;?>&nbsp;</td>
625
						<td valign="middle" nowrap class="list">
626
							<a href="system_camanager.php?act=edit&id=<?=$i;?>")">
627
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit CA");?>" alt="<?=gettext("edit CA");?>" width="17" height="17" border="0" />
628
							</a>
629
							<a href="system_camanager.php?act=exp&id=<?=$i;?>")">
630
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export CA cert");?>" alt="<?=gettext("export CA cert");?>" width="17" height="17" border="0" />
631
							</a>
632
							<?php if ($ca['prv']): ?>
633
							<a href="system_camanager.php?act=expkey&id=<?=$i;?>")">
634
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export CA private key");?>" alt="<?=gettext("export CA private key");?>" width="17" height="17" border="0" />
635
							</a>
636
							<?php endif; ?>
637
							<a href="system_camanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Certificate Authority and its CRLs, and unreference any associated certificates?");?>')">
638
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete ca");?>" alt="<?=gettext("delete ca"); ?>" width="17" height="17" border="0" />
639
							</a>
640
						</td>
641
					</tr>
642
					<?php
643
							$i++;
644
						endforeach;
645
					?>
646
					<tr>
647
						<td class="list" colspan="5"></td>
648
						<td class="list">
649
							<a href="system_camanager.php?act=new">
650
								<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" />
651
							</a>
652
						</td>
653
					</tr>
654
					<tr>
655
						<td colspan="5">
656
							<p>
657
								<?=gettext("Additional trusted Certificate Authorities can be added here.");?>
658
							</p>
659
						</td>
660
					</tr>
661
				</table>
662

    
663
				<?php endif; ?>
664

    
665
			</div>
666
		</td>
667
	</tr>
668
</table>
669
<?php include("fend.inc");?>
670
<script type="text/javascript">
671
<!--
672

    
673
method_change();
674

    
675
//-->
676
</script>
677

    
678
</body>
(196-196/239)