Project

General

Profile

Download (24.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
global $openssl_digest_algs;
50

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
157
if ($_POST) {
158

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

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

    
205
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
206
	if ($pconfig['method'] != "existing") {
207
		/* Make sure we do not have invalid characters in the fields for the certificate */
208
		for ($i = 0; $i < count($reqdfields); $i++) {
209
			if ($reqdfields[$i] == 'dn_email'){
210
				if (preg_match("/[\!\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_email"]))
211
					array_push($input_errors, "The field 'Distinguished name Email Address' contains invalid characters.");
212
			}else if ($reqdfields[$i] == 'dn_commonname'){
213
				if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\"\']/", $_POST["dn_commonname"]))
214
					array_push($input_errors, "The field 'Distinguished name Common Name' contains invalid characters.");
215
			}else if (preg_match("/[\!\@\#\$\%\^\(\)\~\?\>\<\&\/\\\,\.\"\']/", $_POST["$reqdfields[$i]"]))
216
				array_push($input_errors, "The field '" . $reqdfieldsn[$i] . "' contains invalid characters.");
217
		}
218
		if (!in_array($_POST["keylen"], $ca_keylens))
219
			array_push($input_errors, gettext("Please select a valid Key Length."));
220
		if (!in_array($_POST["digest_alg"], $openssl_digest_algs))
221
			array_push($input_errors, gettext("Please select a valid Digest Algorithm."));
222
	}
223

    
224
	/* if this is an AJAX caller then handle via JSON */
225
	if (isAjax() && is_array($input_errors)) {
226
		input_errors2Ajax($input_errors);
227
		exit;
228
	}
229

    
230
	/* save modifications */
231
	if (!$input_errors) {
232

    
233
		$ca = array();
234
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
235
			$ca['refid'] = uniqid();
236
		else
237
			$ca['refid'] = $pconfig['refid'];
238

    
239
		if (isset($id) && $a_ca[$id])
240
			$ca = $a_ca[$id];
241

    
242
		$ca['descr'] = $pconfig['descr'];
243

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

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

    
289
		if (isset($id) && $a_ca[$id])
290
			$a_ca[$id] = $ca;
291
		else
292
			$a_ca[] = $ca;
293

    
294
		if (!$input_errors)
295
			write_config();
296

    
297
//		pfSenseHeader("system_camanager.php");
298
	}
299
}
300

    
301
include("head.inc");
302
?>
303

    
304
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
305
<?php include("fbegin.inc"); ?>
306
<script type="text/javascript">
307
<!--
308

    
309
function method_change() {
310

    
311
	method = document.iform.method.selectedIndex;
312

    
313
	switch (method) {
314
		case 0:
315
			document.getElementById("existing").style.display="";
316
			document.getElementById("internal").style.display="none";
317
			document.getElementById("intermediate").style.display="none";
318
			break;
319
		case 1:
320
			document.getElementById("existing").style.display="none";
321
			document.getElementById("internal").style.display="";
322
			document.getElementById("intermediate").style.display="none";
323
			break;
324
		case 2:
325
			document.getElementById("existing").style.display="none";
326
			document.getElementById("internal").style.display="";
327
			document.getElementById("intermediate").style.display="";
328
			break;
329
	}
330
}
331

    
332
//-->
333
</script>
334
<?php
335
	if ($input_errors)
336
		print_input_errors($input_errors);
337
	if ($savemsg)
338
		print_info_box($savemsg);
339

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

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

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

    
399
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
400
						<tr>
401
							<td colspan="2" class="list" height="12"></td>
402
						</tr>
403
						<tr>
404
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Authority");?></td>
405
						</tr>
406

    
407
						<tr>
408
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
409
							<td width="78%" class="vtable">
410
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
411
								<br>
412
								<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
413
							</td>
414
						</tr>
415
						<tr>
416
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br/><?=gettext("(optional)");?></td>
417
							<td width="78%" class="vtable">
418
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
419
								<br>
420
								<?=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>
421
							</td>
422
						</tr>
423

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

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

    
571
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
572
						<tr>
573
							<td width="22%" valign="top">&nbsp;</td>
574
							<td width="78%">
575
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
576
								<?php if (isset($id) && $a_ca[$id]): ?>
577
								<input name="id" type="hidden" value="<?=$id;?>" />
578
								<?php endif;?>
579
							</td>
580
						</tr>
581
					</table>
582
				</form>
583

    
584
				<?php else: ?>
585

    
586
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
587
					<tr>
588
						<td width="20%" class="listhdrr"><?=gettext("Name");?></td>
589
						<td width="10%" class="listhdrr"><?=gettext("Internal");?></td>
590
						<td width="10%" class="listhdrr"><?=gettext("Issuer");?></td>
591
						<td width="10%" class="listhdrr"><?=gettext("Certificates");?></td>
592
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
593
						<td width="10%" class="list"></td>
594
					</tr>
595
					<?php
596
						$i = 0;
597
						foreach($a_ca as $ca):
598
							$name = htmlspecialchars($ca['descr']);
599
							$subj = cert_get_subject($ca['crt']);
600
							$issuer = cert_get_issuer($ca['crt']);
601
							if($subj == $issuer)
602
							  $issuer_name = "<em>" . gettext("self-signed") . "</em>";
603
							else
604
							  $issuer_name = "<em>" . gettext("external") . "</em>";
605
							$subj = htmlspecialchars($subj);
606
							$issuer = htmlspecialchars($issuer);
607
							$certcount = 0;
608

    
609
							$issuer_ca = lookup_ca($ca['caref']);
610
							if ($issuer_ca)
611
								$issuer_name = $issuer_ca['descr'];
612

    
613
							// TODO : Need gray certificate icon
614

    
615
							if($ca['prv']) {
616
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
617
								$internal = "YES";
618

    
619
							} else {
620
								$caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
621
								$internal = "NO";
622
							}
623
							foreach ($a_cert as $cert)
624
								if ($cert['caref'] == $ca['refid'])
625
									$certcount++;
626
  						foreach ($a_ca as $cert)
627
  							if ($cert['caref'] == $ca['refid'])
628
  								$certcount++;
629
					?>
630
					<tr>
631
						<td class="listlr">
632
							<table border="0" cellpadding="0" cellspacing="0">
633
								<tr>
634
									<td align="left" valign="center">
635
										<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
636
									</td>
637
									<td align="left" valign="middle">
638
										<?=$name;?>
639
									</td>
640
								</tr>
641
							</table>
642
						</td>
643
						<td class="listr"><?=$internal;?>&nbsp;</td>
644
						<td class="listr"><?=$issuer_name;?>&nbsp;</td>
645
						<td class="listr"><?=$certcount;?>&nbsp;</td>
646
						<td class="listr"><?=$subj;?>&nbsp;</td>
647
						<td valign="middle" nowrap class="list">
648
							<a href="system_camanager.php?act=edit&id=<?=$i;?>")">
649
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit CA");?>" alt="<?=gettext("edit CA");?>" width="17" height="17" border="0" />
650
							</a>
651
							<a href="system_camanager.php?act=exp&id=<?=$i;?>")">
652
								<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" />
653
							</a>
654
							<?php if ($ca['prv']): ?>
655
							<a href="system_camanager.php?act=expkey&id=<?=$i;?>")">
656
								<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" />
657
							</a>
658
							<?php endif; ?>
659
							<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?");?>')">
660
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete ca");?>" alt="<?=gettext("delete ca"); ?>" width="17" height="17" border="0" />
661
							</a>
662
						</td>
663
					</tr>
664
					<?php
665
							$i++;
666
						endforeach;
667
					?>
668
					<tr>
669
						<td class="list" colspan="5"></td>
670
						<td class="list">
671
							<a href="system_camanager.php?act=new">
672
								<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" />
673
							</a>
674
						</td>
675
					</tr>
676
					<tr>
677
						<td colspan="5">
678
							<p>
679
								<?=gettext("Additional trusted Certificate Authorities can be added here.");?>
680
							</p>
681
						</td>
682
					</tr>
683
				</table>
684

    
685
				<?php endif; ?>
686

    
687
			</div>
688
		</td>
689
	</tr>
690
</table>
691
<?php include("fend.inc");?>
692
<script type="text/javascript">
693
<!--
694

    
695
method_change();
696

    
697
//-->
698
</script>
699

    
700
</body>
(206-206/249)