Project

General

Profile

Download (23.8 KB) Statistics
| Branch: | Tag: | Revision:
1 64cc39d3 Matthew Grooms
<?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 1d333258 Scott Ullrich
/*
30
	pfSense_MODULE:	certificate_managaer
31
*/
32 64cc39d3 Matthew Grooms
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 742d9c2d Ermal Lu?i
require_once("certs.inc");
42 64cc39d3 Matthew Grooms
43
$ca_methods = array(
44 a37753d7 Vinicius Coque
	"existing" => gettext("Import an existing Certificate Authority"),
45 95c8cf48 Evgeny Yurchenko
	"internal" => gettext("Create an internal Certificate Authority"),
46
	"intermediate" => gettext("Create an intermediate Certificate Authority"));
47 64cc39d3 Matthew Grooms
48
$ca_keylens = array( "512", "1024", "2048", "4096");
49
50 a37753d7 Vinicius Coque
$pgtitle = array(gettext("System"), gettext("Certificate Authority Manager"));
51 64cc39d3 Matthew Grooms
52
$id = $_GET['id'];
53
if (isset($_POST['id']))
54
	$id = $_POST['id'];
55
56 b4e6524c jim-p
if (!is_array($config['ca']))
57
	$config['ca'] = array();
58 64cc39d3 Matthew Grooms
59 b4e6524c jim-p
$a_ca =& $config['ca'];
60 64cc39d3 Matthew Grooms
61 b4e6524c jim-p
if (!is_array($config['cert']))
62
	$config['cert'] = array();
63 64cc39d3 Matthew Grooms
64 b4e6524c jim-p
$a_cert =& $config['cert'];
65 64cc39d3 Matthew Grooms
66 461aa9d0 jim-p
if (!is_array($config['crl']))
67
	$config['crl'] = array();
68
69
$a_crl =& $config['crl'];
70
71 64cc39d3 Matthew Grooms
$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 461aa9d0 jim-p
	$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 f2a86ca9 jim-p
	$name = $a_ca[$id]['descr'];
93 64cc39d3 Matthew Grooms
	unset($a_ca[$id]);
94
	write_config();
95 461aa9d0 jim-p
	$savemsg = sprintf(gettext("Certificate Authority %s and its CRLs (if any) successfully deleted"), $name) . "<br/>";
96 2f51259b jim-p
	pfSenseHeader("system_camanager.php");
97
	exit;
98 64cc39d3 Matthew Grooms
}
99
100 bfa992bc jim-p
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 64cc39d3 Matthew Grooms
if ($act == "new") {
114
	$pconfig['method'] = $_GET['method'];
115
	$pconfig['keylen'] = "2048";
116 cf360495 Chris Buechler
	$pconfig['lifetime'] = "3650";
117 64cc39d3 Matthew Grooms
	$pconfig['dn_commonname'] = "internal-ca";
118
}
119
120 93823b10 Matthew Grooms
if ($act == "exp") {
121
122
	if (!$a_ca[$id]) {
123
		pfSenseHeader("system_camanager.php");
124
		exit;
125
	}
126
127 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_ca[$id]['descr']}.crt");
128 93823b10 Matthew Grooms
	$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 ecefc738 jim-p
if ($act == "expkey") {
139
140
	if (!$a_ca[$id]) {
141
		pfSenseHeader("system_camanager.php");
142
		exit;
143
	}
144
145 f2a86ca9 jim-p
	$exp_name = urlencode("{$a_ca[$id]['descr']}.key");
146 ecefc738 jim-p
	$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 64cc39d3 Matthew Grooms
if ($_POST) {
157
158 95c8cf48 Evgeny Yurchenko
	unset($input_errors);
159 64cc39d3 Matthew Grooms
	$pconfig = $_POST;
160
161
	/* input validation */
162
	if ($pconfig['method'] == "existing") {
163 5293bfec jim-p
		$reqdfields = explode(" ", "descr cert");
164 38fb1109 Vinicius Coque
		$reqdfieldsn = array(
165
				gettext("Descriptive name"),
166
				gettext("Certificate data"));
167 396cfe2e jim-p
		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 46698c3f jim-p
		if ($_POST['key'] && strstr($_POST['key'], "ENCRYPTED"))
170
			$input_errors[] = gettext("Encrypted private keys are not yet supported.");
171 64cc39d3 Matthew Grooms
	}
172
	if ($pconfig['method'] == "internal") {
173
		$reqdfields = explode(" ",
174 5293bfec jim-p
				"descr keylen lifetime dn_country dn_state dn_city ".
175 64cc39d3 Matthew Grooms
				"dn_organization dn_email dn_commonname");
176 38fb1109 Vinicius Coque
		$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 a37753d7 Vinicius Coque
				gettext("Distinguished name Common Name"));
186 64cc39d3 Matthew Grooms
	}
187 95c8cf48 Evgeny Yurchenko
	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 64cc39d3 Matthew Grooms
204
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
205 21cc2faa Evgeny Yurchenko
	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 64cc39d3 Matthew Grooms
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 bfa992bc jim-p
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
229
			$ca['refid'] = uniqid();
230
		else
231
			$ca['refid'] = $pconfig['refid'];
232
233 64cc39d3 Matthew Grooms
		if (isset($id) && $a_ca[$id])
234
			$ca = $a_ca[$id];
235
236 bfa992bc jim-p
		$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 1b6d9fa5 Evgeny Yurchenko
			$old_err_level = error_reporting(0); /* otherwise openssl_ functions throw warings directly to a page screwing menu tab */
247 bfa992bc jim-p
			if ($pconfig['method'] == "existing")
248
				ca_import($ca, $pconfig['cert'], $pconfig['key'], $pconfig['serial']);
249
250 95c8cf48 Evgeny Yurchenko
			else if ($pconfig['method'] == "internal") {
251 bfa992bc jim-p
				$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 1b6d9fa5 Evgeny Yurchenko
				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 bfa992bc jim-p
			}
265 95c8cf48 Evgeny Yurchenko
			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 1b6d9fa5 Evgeny Yurchenko
			error_reporting($old_err_level);
281 64cc39d3 Matthew Grooms
		}
282
283
		if (isset($id) && $a_ca[$id])
284
			$a_ca[$id] = $ca;
285
		else
286
			$a_ca[] = $ca;
287
288 95c8cf48 Evgeny Yurchenko
		if (!$input_errors)
289
			write_config();
290 64cc39d3 Matthew Grooms
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 95c8cf48 Evgeny Yurchenko
			document.getElementById("intermediate").style.display="none";
312 64cc39d3 Matthew Grooms
			break;
313
		case 1:
314
			document.getElementById("existing").style.display="none";
315
			document.getElementById("internal").style.display="";
316 95c8cf48 Evgeny Yurchenko
			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 64cc39d3 Matthew Grooms
			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 9d2d65f3 Evgeny Yurchenko
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 64cc39d3 Matthew Grooms
?>
343
<table width="100%" border="0" cellpadding="0" cellspacing="0">
344
	<tr>
345 96c7a492 Matthew Grooms
		<td>
346 64cc39d3 Matthew Grooms
		<?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 3d57d2d5 jim-p
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
351 64cc39d3 Matthew Grooms
			display_top_tabs($tab_array);
352
		?>
353
		</td>
354
	</tr>
355
	<tr>
356 96c7a492 Matthew Grooms
		<td id="mainarea">
357
			<div class="tabcont">
358
359 bfa992bc jim-p
				<?php if ($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors): ?>
360 96c7a492 Matthew Grooms
361
				<form action="system_camanager.php" method="post" name="iform" id="iform">
362 bfa992bc jim-p
					<?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 96c7a492 Matthew Grooms
					<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 f2a86ca9 jim-p
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
372 96c7a492 Matthew Grooms
							</td>
373
						</tr>
374 bfa992bc jim-p
						<?php if (!isset($id) || $act == "edit"): ?>
375 96c7a492 Matthew Grooms
						<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 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate Authority");?></td>
399 96c7a492 Matthew Grooms
						</tr>
400
401
						<tr>
402 a37753d7 Vinicius Coque
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
403 96c7a492 Matthew Grooms
							<td width="78%" class="vtable">
404 dd5bf424 Scott Ullrich
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
405 96c7a492 Matthew Grooms
								<br>
406 a37753d7 Vinicius Coque
								<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
407 96c7a492 Matthew Grooms
							</td>
408
						</tr>
409 ecefc738 jim-p
						<tr>
410
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate Private Key");?><br/><?=gettext("(optional)");?></td>
411
							<td width="78%" class="vtable">
412 dd5bf424 Scott Ullrich
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
413 ecefc738 jim-p
								<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 bfa992bc jim-p
418
					<?php if (!isset($id) || $act == "edit"): ?>
419
						<tr>
420 51c24cf6 jim-p
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Serial for next certificate");?></td>
421 bfa992bc jim-p
							<td width="78%" class="vtable">
422
								<input name="serial" type="text" class="formfld unknown" id="serial" size="20" value="<?=htmlspecialchars($pconfig['serial']);?>"/>
423 51c24cf6 jim-p
								<br/><?=gettext("Enter a decimal number to be used as the serial number for the next certificate to be created using this CA.");?>
424 bfa992bc jim-p
							</td>
425
						</tr>
426
					<?php endif; ?>
427 96c7a492 Matthew Grooms
					</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 a37753d7 Vinicius Coque
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate Authority");?></td>
435 96c7a492 Matthew Grooms
						</tr>
436 95c8cf48 Evgeny Yurchenko
						<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 96c7a492 Matthew Grooms
						<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 ea53e38f Renato Botelho
								<?=gettext("bits");?>
467 96c7a492 Matthew Grooms
							</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 ea53e38f Renato Botelho
								<?=gettext("days");?>
474 96c7a492 Matthew Grooms
							</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 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
482 96c7a492 Matthew Grooms
										<td align="left">
483 9d2d65f3 Evgeny Yurchenko
											<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 96c7a492 Matthew Grooms
										</td>
493
									</tr>
494
									<tr>
495 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
496 96c7a492 Matthew Grooms
										<td align="left">
497
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>"/>
498
											&nbsp;
499 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
500 96c7a492 Matthew Grooms
											&nbsp;
501 a37753d7 Vinicius Coque
											<?=gettext("Texas");?>
502 96c7a492 Matthew Grooms
										</td>
503
									</tr>
504
									<tr>
505 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
506 96c7a492 Matthew Grooms
										<td align="left">
507
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>"/>
508
											&nbsp;
509 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
510 96c7a492 Matthew Grooms
											&nbsp;
511 a37753d7 Vinicius Coque
											<?=gettext("Austin");?>
512 96c7a492 Matthew Grooms
										</td>
513
									</tr>
514
									<tr>
515 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
516 96c7a492 Matthew Grooms
										<td align="left">
517
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>"/>
518
											&nbsp;
519 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
520 96c7a492 Matthew Grooms
											&nbsp;
521 a37753d7 Vinicius Coque
											<?=gettext("My Company Inc.");?>
522 96c7a492 Matthew Grooms
										</td>
523
									</tr>
524
									<tr>
525 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
526 96c7a492 Matthew Grooms
										<td align="left">
527
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
528
											&nbsp;
529 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
530 96c7a492 Matthew Grooms
											&nbsp;
531 a37753d7 Vinicius Coque
											<?=gettext("admin@mycompany.com");?>
532 96c7a492 Matthew Grooms
										</td>
533
									</tr>
534
									<tr>
535 a37753d7 Vinicius Coque
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
536 96c7a492 Matthew Grooms
										<td align="left">
537
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
538
											&nbsp;
539 ea53e38f Renato Botelho
											<em><?=gettext("ex:");?></em>
540 96c7a492 Matthew Grooms
											&nbsp;
541 a37753d7 Vinicius Coque
											<?=gettext("internal-ca");?>
542 96c7a492 Matthew Grooms
										</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 443ddf6f Carlos Eduardo Ramos
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
554 96c7a492 Matthew Grooms
								<?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 64cc39d3 Matthew Grooms
					<tr>
566 a37753d7 Vinicius Coque
						<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 96c7a492 Matthew Grooms
						<td width="10%" class="list"></td>
572 64cc39d3 Matthew Grooms
					</tr>
573 96c7a492 Matthew Grooms
					<?php
574
						$i = 0;
575
						foreach($a_ca as $ca):
576 f2a86ca9 jim-p
							$name = htmlspecialchars($ca['descr']);
577 96c7a492 Matthew Grooms
							$subj = cert_get_subject($ca['crt']);
578 2cf6ddcb Nigel Graham
							$issuer = cert_get_issuer($ca['crt']);
579
							if($subj == $issuer)
580 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("self-signed") . "</em>";
581 2cf6ddcb Nigel Graham
							else
582 a37753d7 Vinicius Coque
							  $issuer_name = "<em>" . gettext("external") . "</em>";
583 96c7a492 Matthew Grooms
							$subj = htmlspecialchars($subj);
584 2cf6ddcb Nigel Graham
							$issuer = htmlspecialchars($issuer);
585 96c7a492 Matthew Grooms
							$certcount = 0;
586
587 2cf6ddcb Nigel Graham
							$issuer_ca = lookup_ca($ca['caref']);
588
							if ($issuer_ca)
589 f2a86ca9 jim-p
								$issuer_name = $issuer_ca['descr'];
590 2cf6ddcb Nigel Graham
591 96c7a492 Matthew Grooms
							// 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 2cf6ddcb Nigel Graham
							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 96c7a492 Matthew Grooms
					?>
608 64cc39d3 Matthew Grooms
					<tr>
609 96c7a492 Matthew Grooms
						<td class="listlr">
610
							<table border="0" cellpadding="0" cellspacing="0">
611 64cc39d3 Matthew Grooms
								<tr>
612 96c7a492 Matthew Grooms
									<td align="left" valign="center">
613
										<img src="<?=$caimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
614 64cc39d3 Matthew Grooms
									</td>
615 96c7a492 Matthew Grooms
									<td align="left" valign="middle">
616
										<?=$name;?>
617 64cc39d3 Matthew Grooms
									</td>
618
								</tr>
619
							</table>
620
						</td>
621 96c7a492 Matthew Grooms
						<td class="listr"><?=$internal;?>&nbsp;</td>
622 2cf6ddcb Nigel Graham
						<td class="listr"><?=$issuer_name;?>&nbsp;</td>
623 96c7a492 Matthew Grooms
						<td class="listr"><?=$certcount;?>&nbsp;</td>
624
						<td class="listr"><?=$subj;?>&nbsp;</td>
625
						<td valign="middle" nowrap class="list">
626 bfa992bc jim-p
							<a href="system_camanager.php?act=edit&id=<?=$i;?>")">
627 73800013 Chris Buechler
								<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 bfa992bc jim-p
							</a>
629 96c7a492 Matthew Grooms
							<a href="system_camanager.php?act=exp&id=<?=$i;?>")">
630 73800013 Chris Buechler
								<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 96c7a492 Matthew Grooms
							</a>
632 ecefc738 jim-p
							<?php if ($ca['prv']): ?>
633
							<a href="system_camanager.php?act=expkey&id=<?=$i;?>")">
634 73800013 Chris Buechler
								<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 ecefc738 jim-p
							</a>
636
							<?php endif; ?>
637 461aa9d0 jim-p
							<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 2b33f342 Renato Botelho
								<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 96c7a492 Matthew Grooms
							</a>
640
						</td>
641
					</tr>
642
					<?php
643
							$i++;
644
						endforeach;
645
					?>
646
					<tr>
647 2cf6ddcb Nigel Graham
						<td class="list" colspan="5"></td>
648 96c7a492 Matthew Grooms
						<td class="list">
649
							<a href="system_camanager.php?act=new">
650 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" />
651 96c7a492 Matthew Grooms
							</a>
652
						</td>
653 64cc39d3 Matthew Grooms
					</tr>
654
					<tr>
655 2cf6ddcb Nigel Graham
						<td colspan="5">
656 96c7a492 Matthew Grooms
							<p>
657 22a11a58 Larry Gilbert
								<?=gettext("Additional trusted Certificate Authorities can be added here.");?>
658 96c7a492 Matthew Grooms
							</p>
659 64cc39d3 Matthew Grooms
						</td>
660
					</tr>
661
				</table>
662
663 96c7a492 Matthew Grooms
				<?php endif; ?>
664
665
			</div>
666 64cc39d3 Matthew Grooms
		</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>