Project

General

Profile

Download (30.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/*
30
	pfSense_MODULE:	certificate_managaer
31
*/
32

    
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
require_once("certs.inc");
42

    
43
$cert_methods = array(
44
	"import" => gettext("Import an existing Certificate"),
45
	"internal" => gettext("Create an internal Certificate"),
46
	"external" => gettext("Create a Certificate Signing Request"),
47
);
48

    
49
$cert_keylens = array( "512", "1024", "2048", "4096");
50

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

    
53
$userid = $_GET['userid'];
54
if (isset($_POST['userid']))
55
	$userid = $_POST['userid'];
56
if ($userid) {
57
	$cert_methods["existing"] = gettext("Choose an existing certificate");
58
	if (!is_array($config['system']['user']))
59
		$config['system']['user'] = array();
60
	$a_user =& $config['system']['user'];
61
}
62

    
63
$id = $_GET['id'];
64
if (isset($_POST['id']))
65
	$id = $_POST['id'];
66

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

    
70
$a_ca =& $config['ca'];
71

    
72
if (!is_array($config['cert']))
73
	$config['cert'] = array();
74

    
75
$a_cert =& $config['cert'];
76

    
77
$internal_ca_count = 0;
78
foreach ($a_ca as $ca)
79
	if ($ca['prv'])	
80
		$internal_ca_count++;
81

    
82
$act = $_GET['act'];
83
if ($_POST['act'])
84
	$act = $_POST['act'];
85

    
86
if ($act == "del") {
87

    
88
	if (!$a_cert[$id]) {
89
		pfSenseHeader("system_certmanager.php");
90
		exit;
91
	}
92

    
93
	$name = $a_cert[$id]['descr'];
94
	unset($a_cert[$id]);
95
	write_config();
96
	$savemsg = sprintf(gettext("Certificate %s successfully deleted"), $name) . "<br/>";
97
}
98

    
99
if ($act == "new") {
100
	$pconfig['method'] = $_GET['method'];
101
	$pconfig['keylen'] = "2048";
102
	$pconfig['lifetime'] = "3650";
103
}
104

    
105
if ($act == "exp") {
106

    
107
	if (!$a_cert[$id]) {
108
		pfSenseHeader("system_certmanager.php");
109
		exit;
110
	}
111

    
112
	$exp_name = urlencode("{$a_cert[$id]['descr']}.crt");
113
	$exp_data = base64_decode($a_cert[$id]['crt']);
114
	$exp_size = strlen($exp_data);
115

    
116
	header("Content-Type: application/octet-stream");
117
	header("Content-Disposition: attachment; filename={$exp_name}");
118
	header("Content-Length: $exp_size");
119
	echo $exp_data;
120
	exit;
121
}
122

    
123
if ($act == "key") {
124

    
125
	if (!$a_cert[$id]) {
126
		pfSenseHeader("system_certmanager.php");
127
		exit;
128
	}
129

    
130
	$exp_name = urlencode("{$a_cert[$id]['descr']}.key");
131
	$exp_data = base64_decode($a_cert[$id]['prv']);
132
	$exp_size = strlen($exp_data);
133

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

    
141
if ($act == "csr") {
142

    
143
	if (!$a_cert[$id]) {
144
		pfSenseHeader("system_certmanager.php");
145
		exit;
146
	}
147

    
148
	$pconfig['descr'] = $a_cert[$id]['descr'];
149
	$pconfig['csr'] = base64_decode($a_cert[$id]['csr']);
150
}
151

    
152
if ($_POST) {
153
	if ($_POST['save'] == gettext("Save")) {
154
		unset($input_errors);
155
		$pconfig = $_POST;
156

    
157
		/* input validation */
158
		if ($pconfig['method'] == "import") {
159
			$reqdfields = explode(" ",
160
					"descr cert key");
161
			$reqdfieldsn = array(
162
					gettext("Descriptive name"),
163
					gettext("Certificate data"),
164
					gettext("Key data"));
165
			if ($_POST['cert'] && (!strstr($_POST['cert'], "BEGIN CERTIFICATE") || !strstr($_POST['cert'], "END CERTIFICATE")))
166
				$input_errors[] = gettext("This certificate does not appear to be valid.");
167
		}
168

    
169
		if ($pconfig['method'] == "internal") {
170
			$reqdfields = explode(" ",
171
					"descr caref keylen lifetime dn_country dn_state dn_city ".
172
					"dn_organization dn_email dn_commonname");
173
			$reqdfieldsn = array(
174
					gettext("Descriptive name"),
175
					gettext("Certificate authority"),
176
					gettext("Key length"),
177
					gettext("Lifetime"),
178
					gettext("Distinguished name Country Code"),
179
					gettext("Distinguished name State or Province"),
180
					gettext("Distinguished name City"),
181
					gettext("Distinguished name Organization"),
182
					gettext("Distinguished name Email Address"),
183
					gettext("Distinguished name Common Name"));
184
		}
185

    
186
		if ($pconfig['method'] == "external") {
187
			$reqdfields = explode(" ",
188
					"descr csr_keylen csr_dn_country csr_dn_state csr_dn_city ".
189
					"csr_dn_organization csr_dn_email csr_dn_commonname");
190
			$reqdfieldsn = array(
191
					gettext("Descriptive name"),
192
					gettext("Key length"),
193
					gettext("Distinguished name Country Code"),
194
					gettext("Distinguished name State or Province"),
195
					gettext("Distinguished name City"),
196
					gettext("Distinguished name Organization"),
197
					gettext("Distinguished name Email Address"),
198
					gettext("Distinguished name Common Name"));
199
		}
200

    
201
		if ($pconfig['method'] == "existing") {
202
			$reqdfields = array("certref");
203
			$reqdfieldsn = array(gettext("Existing Certificate Choice"));
204
		}
205

    
206
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
207

    
208
		/* if this is an AJAX caller then handle via JSON */
209
		if (isAjax() && is_array($input_errors)) {
210
			input_errors2Ajax($input_errors);
211
			exit;
212
		}
213

    
214
		/* save modifications */
215
		if (!$input_errors) {
216

    
217
			if ($pconfig['method'] == "existing") {
218
				$cert = lookup_cert($pconfig['certref']);
219
				if ($cert && $a_user)
220
					$a_user[$userid]['cert'][] = $cert['refid'];
221
			} else {
222
				$cert = array();
223
				$cert['refid'] = uniqid();
224
				if (isset($id) && $a_cert[$id])
225
					$cert = $a_cert[$id];
226

    
227
				$cert['descr'] = $pconfig['descr'];
228

    
229
				if ($pconfig['method'] == "import")
230
					cert_import($cert, $pconfig['cert'], $pconfig['key']);
231

    
232
				if ($pconfig['method'] == "internal") {
233
					$dn = array(
234
						'countryName' => $pconfig['dn_country'],
235
						'stateOrProvinceName' => $pconfig['dn_state'],
236
						'localityName' => $pconfig['dn_city'],
237
						'organizationName' => $pconfig['dn_organization'],
238
						'emailAddress' => $pconfig['dn_email'],
239
						'commonName' => $pconfig['dn_commonname']);
240
	
241
					cert_create($cert, $pconfig['caref'], $pconfig['keylen'],
242
						$pconfig['lifetime'], $dn);
243
				}
244

    
245
				if ($pconfig['method'] == "external") {
246
					$dn = array(
247
						'countryName' => $pconfig['csr_dn_country'],
248
						'stateOrProvinceName' => $pconfig['csr_dn_state'],
249
						'localityName' => $pconfig['csr_dn_city'],
250
						'organizationName' => $pconfig['csr_dn_organization'],
251
						'emailAddress' => $pconfig['csr_dn_email'],
252
						'commonName' => $pconfig['csr_dn_commonname']);
253

    
254
					csr_generate($cert, $pconfig['csr_keylen'], $dn);
255
				}
256
				if (isset($id) && $a_cert[$id])
257
					$a_cert[$id] = $cert;
258
				else
259
					$a_cert[] = $cert;
260
				if (isset($a_user) && isset($userid))
261
					$a_user[$userid]['cert'][] = $cert['refid'];
262
			}
263

    
264
			write_config();
265

    
266
			if ($userid)
267
				pfSenseHeader("system_usermanager.php?act=edit&id={$userid}");
268
		}
269
	}
270

    
271
	if ($_POST['save'] == gettext("Update")) {
272
		unset($input_errors);
273
		$pconfig = $_POST;
274

    
275
		/* input validation */
276
		$reqdfields = explode(" ", "descr cert");
277
		$reqdfieldsn = array(
278
			gettext("Descriptive name"),
279
			gettext("Final Certificate data"));
280

    
281
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
282

    
283
		/* make sure this csr and certificate subjects match */
284
		$subj_csr = csr_get_subject($pconfig['csr'], false);
285
		$subj_cert = cert_get_subject($pconfig['cert'], false);
286

    
287
		if (strcmp($subj_csr,$subj_cert))
288
			$input_errors[] = sprintf(gettext("The certificate subject '%s' does not match the signing request subject."),$subj_cert);
289

    
290
		/* if this is an AJAX caller then handle via JSON */
291
		if (isAjax() && is_array($input_errors)) {
292
			input_errors2Ajax($input_errors);
293
			exit;
294
		}
295

    
296
		/* save modifications */
297
		if (!$input_errors) {
298

    
299
			$cert = $a_cert[$id];
300

    
301
			$cert['descr'] = $pconfig['descr'];
302

    
303
			csr_complete($cert, $pconfig['cert']);
304

    
305
			$a_cert[$id] = $cert;
306

    
307
			write_config();
308

    
309
			pfSenseHeader("system_certmanager.php");
310
		}
311
	}
312
}
313

    
314
include("head.inc");
315
?>
316

    
317
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
318
<?php include("fbegin.inc"); ?>
319
<script type="text/javascript">
320
<!--
321

    
322
function method_change() {
323

    
324
<?php
325
	if ($internal_ca_count)
326
		$submit_style = "";
327
	else
328
		$submit_style = "none";
329
?>
330

    
331
	method = document.iform.method.selectedIndex;
332

    
333
	switch (method) {
334
		case 0:
335
			document.getElementById("import").style.display="";
336
			document.getElementById("internal").style.display="none";
337
			document.getElementById("external").style.display="none";
338
			document.getElementById("existing").style.display="none";
339
			document.getElementById("descriptivename").style.display="";
340
			document.getElementById("submit").style.display="";
341
			break;
342
		case 1:
343
			document.getElementById("import").style.display="none";
344
			document.getElementById("internal").style.display="";
345
			document.getElementById("external").style.display="none";
346
			document.getElementById("existing").style.display="none";
347
			document.getElementById("descriptivename").style.display="";
348
			document.getElementById("submit").style.display="<?=$submit_style;?>";
349
			break;
350
		case 2:
351
			document.getElementById("import").style.display="none";
352
			document.getElementById("internal").style.display="none";
353
			document.getElementById("external").style.display="";
354
			document.getElementById("existing").style.display="none";
355
			document.getElementById("descriptivename").style.display="";
356
			document.getElementById("submit").style.display="";
357
			break;
358
		case 3:
359
			document.getElementById("import").style.display="none";
360
			document.getElementById("internal").style.display="none";
361
			document.getElementById("external").style.display="none";
362
			document.getElementById("existing").style.display="";
363
			document.getElementById("descriptivename").style.display="none";
364
			document.getElementById("submit").style.display="";
365
			break;
366
	}
367
}
368

    
369
<?php if ($internal_ca_count): ?>
370
function internalca_change() {
371

    
372
	index = document.iform.caref.selectedIndex;
373
	caref = document.iform.caref[index].value;
374

    
375
	switch (caref) {
376
<?php
377
		foreach ($a_ca as $ca):
378
			if (!$ca['prv'])
379
				continue;
380
			$subject = cert_get_subject_array($ca['crt']);
381
?>
382
		case "<?=$ca['refid'];?>":
383
			document.iform.dn_country.value = "<?=$subject[0]['v'];?>";
384
			document.iform.dn_state.value = "<?=$subject[1]['v'];?>";
385
			document.iform.dn_city.value = "<?=$subject[2]['v'];?>";
386
			document.iform.dn_organization.value = "<?=$subject[3]['v'];?>";
387
			document.iform.dn_email.value = "<?=$subject[4]['v'];?>";
388
			break;
389
<?php	endforeach; ?>
390
	}
391
}
392
<?php endif; ?>
393

    
394
//-->
395
</script>
396
<?php
397
	if ($input_errors)
398
		print_input_errors($input_errors);
399
	if ($savemsg)
400
		print_info_box($savemsg);
401
?>
402
<table width="100%" border="0" cellpadding="0" cellspacing="0">
403
	<tr>
404
		<td class="tabnavtbl">
405
		<?php
406
			$tab_array = array();
407
			$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
408
			$tab_array[] = array(gettext("Certificates"), true, "system_certmanager.php");
409
			$tab_array[] = array(gettext("Certificate Revocation"), false, "system_crlmanager.php");
410
			display_top_tabs($tab_array);
411
		?>
412
		</td>
413
	</tr>
414
	<tr>
415
		<td id="mainarea">
416
			<div class="tabcont">
417

    
418
				<?php if ($act == "new" || (($_POST['save'] == gettext("Save")) && $input_errors)): ?>
419

    
420
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
421
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
422
						<?php if (!isset($id)): ?>
423
						<tr>
424
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
425
							<td width="78%" class="vtable">
426
								<select name='method' id='method' class="formselect" onchange='method_change()'>
427
								<?php
428
									foreach($cert_methods as $method => $desc):
429
									$selected = "";
430
									if ($pconfig['method'] == $method)
431
										$selected = "selected";
432
								?>
433
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
434
								<?php endforeach; ?>
435
								</select>
436
							</td>
437
						</tr>
438
						<?php endif; ?>
439
						<tr id="descriptivename">
440
							<?php
441
							if ($a_user && empty($pconfig['descr']))
442
								$pconfig['descr'] = $a_user[$userid]['name'];
443
							?>
444
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
445
							<td width="78%" class="vtable">
446
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
447
							</td>
448
						</tr>
449
					</table>
450

    
451
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="import">
452
						<tr>
453
							<td colspan="2" class="list" height="12"></td>
454
						</tr>
455
						<tr>
456
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Import Certificate");?></td>
457
						</tr>
458

    
459
						<tr>
460
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
461
							<td width="78%" class="vtable">
462
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
463
								<br>
464
									<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
465
							</td>
466
						</tr>
467
						<tr>
468
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Private key data");?></td>
469
							<td width="78%" class="vtable">
470
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['key']);?></textarea>
471
								<br>
472
								<?=gettext("Paste a private key in X.509 PEM format here.");?></td>
473
							</td>
474
						</tr>
475
					</table>
476

    
477
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
478
						<tr>
479
							<td colspan="2" class="list" height="12"></td>
480
						</tr>
481
						<tr>
482
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate");?></td>
483
						</tr>
484

    
485
						<?php if (!$internal_ca_count): ?>
486

    
487
						<tr>
488
							<td colspan="2" align="center" class="vtable">
489
								<?=gettext("No internal Certificate Authorities have been defined. You must");?>
490
								<a href="system_camanager.php?act=new&method=internal"><?=gettext("create");?></a>
491
								<?=gettext("an internal CA before creating an internal certificate.");?>
492
							</td>
493
						</tr>
494

    
495
						<?php else: ?>
496

    
497
						<tr>
498
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
499
							<td width="78%" class="vtable">
500
								<select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
501
								<?php
502
									foreach( $a_ca as $ca):
503
									if (!$ca['prv'])
504
										continue;
505
									$selected = "";
506
									if ($pconfig['caref'] == $ca['refid'])
507
										$selected = "selected";
508
								?>
509
									<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['descr'];?></option>
510
								<?php endforeach; ?>
511
								</select>
512
							</td>
513
						</tr>
514
						<tr>
515
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
516
							<td width="78%" class="vtable">
517
								<select name='keylen' class="formselect">
518
								<?php
519
									foreach( $cert_keylens as $len):
520
									$selected = "";
521
									if ($pconfig['keylen'] == $len)
522
										$selected = "selected";
523
								?>
524
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
525
								<?php endforeach; ?>
526
								</select>
527
								<?=gettext("bits");?>
528
							</td>
529
						</tr>
530
						<tr>
531
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
532
							<td width="78%" class="vtable">
533
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
534
								<?=gettext("days");?>
535
							</td>
536
						</tr>
537
						<tr>
538
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
539
							<td width="78%" class="vtable">
540
								<table border="0" cellspacing="0" cellpadding="2">
541
									<tr>
542
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
543
										<td align="left">
544
											<input name="dn_country" type="text" class="formfld unknown" maxlength="2" size="2" value="<?=htmlspecialchars($pconfig['dn_country']);?>" readonly/>
545
										</td>
546
									</tr>
547
									<tr>
548
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
549
										<td align="left">
550
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>" readonly/>
551
										</td>
552
									</tr>
553
									<tr>
554
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
555
										<td align="left">
556
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>" readonly/>
557
										</td>
558
									</tr>
559
									<tr>
560
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
561
										<td align="left">
562
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>" readonly/>
563
										</td>
564
									</tr>
565
									<tr>
566
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
567
										<td align="left">
568
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
569
											&nbsp;
570
											<em>ex:</em>
571
											&nbsp;
572
											<?=gettext("webadmin@mycompany.com");?>
573
										</td>
574
									</tr>
575
									<tr>
576
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
577
										<td align="left">
578
											<?php
579
											if ($a_user && empty($pconfig['dn_commonname']))
580
												$pconfig['dn_commonname'] = $a_user[$userid]['name'];
581
											?>
582
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
583
											&nbsp;
584
											<em>ex:</em>
585
											&nbsp;
586
											<?=gettext("www.example.com");?>
587
										</td>
588
									</tr>
589
								</table>
590
							</td>
591
						</tr>
592

    
593
					<?php endif; ?>
594

    
595
					</table>
596

    
597
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="external">
598
						<tr>
599
							<td colspan="2" class="list" height="12"></td>
600
						</tr>
601
						<tr>
602
							<td colspan="2" valign="top" class="listtopic"><?=gettext("External Signing Request");?></td>
603
						</tr>
604
						<tr>
605
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
606
							<td width="78%" class="vtable">
607
								<select name='csr_keylen' class="formselect">
608
								<?php
609
									foreach( $cert_keylens as $len):
610
									$selected = "";
611
									if ($pconfig['keylen'] == $len)
612
										$selected = "selected";
613
								?>
614
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
615
								<?php endforeach; ?>
616
								</select>
617
								bits
618
							</td>
619
						</tr>
620
						<tr>
621
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
622
							<td width="78%" class="vtable">
623
								<table border="0" cellspacing="0" cellpadding="2">
624
									<tr>
625
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
626
										<td align="left">
627
											<input name="csr_dn_country" type="text" class="formfld unknown" size="2" value="<?=htmlspecialchars($pconfig['csr_dn_country']);?>" />
628
											&nbsp;
629
											<em>ex:</em>
630
											&nbsp;
631
											US
632
											&nbsp;
633
											<em><?=gettext("( two letters )");?></em>
634
										</td>
635
									</tr>
636
									<tr>
637
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
638
										<td align="left">
639
											<input name="csr_dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_state']);?>" />
640
											&nbsp;
641
											<em>ex:</em>
642
											&nbsp;
643
											<?=gettext("Texas");?>
644
										</td>
645
									</tr>
646
									<tr>
647
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
648
										<td align="left">
649
											<input name="csr_dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_city']);?>" />
650
											&nbsp;
651
											<em>ex:</em>
652
											&nbsp;
653
											<?=gettext("Austin");?>
654
										</td>
655
									</tr>
656
									<tr>
657
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
658
										<td align="left">
659
											<input name="csr_dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_organization']);?>" />
660
											&nbsp;
661
											<em>ex:</em>
662
											&nbsp;
663
											<?=gettext("My Company Inc.");?>
664
										</td>
665
									</tr>
666
									<tr>
667
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
668
										<td align="left">
669
											<input name="csr_dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_email']);?>"/>
670
											&nbsp;
671
											<em>ex:</em>
672
											&nbsp;
673
											<?=gettext("webadmin@mycompany.com");?>
674
										</td>
675
									</tr>
676
									<tr>
677
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
678
										<td align="left">
679
											<input name="csr_dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_commonname']);?>"/>
680
											&nbsp;
681
											<em>ex:</em>
682
											&nbsp;
683
											<?=gettext("www.example.com");?>
684
										</td>
685
									</tr>
686
								</table>
687
							</td>
688
						</tr>
689
					</table>
690

    
691
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
692
						<tr>
693
							<td colspan="2" class="list" height="12"></td>
694
						</tr>
695
						<tr>
696
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Choose an Existing Certificate");?></td>
697
						</tr>
698
						<tr>
699
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Existing Certificates");?></td>
700
							<td width="78%" class="vtable">
701
								<?php if (isset($userid) && $a_user): ?>
702
								<input name="userid" type="hidden" value="<?=$userid;?>" />
703
								<?php endif;?>
704
								<select name='certref' class="formselect">
705
								<?php
706
									foreach ($config['cert'] as $cert):
707
										$selected = "";
708
										$caname = "";
709
										$inuse = "";
710
										$revoked = "";
711
										if (in_array($cert['refid'], $config['system']['user'][$userid]['cert']))
712
											continue;
713
										$ca = lookup_ca($cert['caref']);
714
										if ($ca)
715
											$caname = " (CA: {$ca['descr']})";
716
										if ($pconfig['certref'] == $cert['refid'])
717
											$selected = "selected";
718
										if (cert_in_use($cert['refid']))
719
											$inuse = " *In Use";
720
											if (is_cert_revoked($cert))
721
											$revoked = " *Revoked";
722
								?>
723
									<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
724
								<?php endforeach; ?>
725
								</select>
726
							</td>
727
						</tr>
728
					</table>
729

    
730
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
731
						<tr>
732
							<td width="22%" valign="top">&nbsp;</td>
733
							<td width="78%">
734
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
735
								<?php if (isset($id) && $a_cert[$id]): ?>
736
								<input name="id" type="hidden" value="<?=$id;?>" />
737
								<?php endif;?>
738
							</td>
739
						</tr>
740
					</table>
741
				</form>
742

    
743
				<?php elseif ($act == "csr" || (($_POST['save'] == gettext("Update")) && $input_errors)):?>
744

    
745
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
746
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
747
						<tr>
748
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
749
							<td width="78%" class="vtable">
750
								<input name="descr" type="text" class="formfld unknown" id="descr" size="20" value="<?=htmlspecialchars($pconfig['descr']);?>"/>
751
							</td>
752
						</tr>
753
						<tr>
754
							<td colspan="2" class="list" height="12"></td>
755
						</tr>
756
						<tr>
757
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Complete Signing Request");?></td>
758
						</tr>
759

    
760
						<tr>
761
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Request data");?></td>
762
							<td width="78%" class="vtable">
763
								<textarea name="csr" id="csr" cols="65" rows="7" class="formfld_cert" readonly><?=htmlspecialchars($pconfig['csr']);?></textarea>
764
								<br>
765
								<?=gettext("Copy the certificate signing data from here and forward it to your certificate authority for signing.");?></td>
766
							</td>
767
						</tr>
768
						<tr>
769
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Final Certificate data");?></td>
770
							<td width="78%" class="vtable">
771
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
772
								<br>
773
								<?=gettext("Paste the certificate received from your cerificate authority here.");?></td>
774
							</td>
775
						</tr>
776
						<tr>
777
							<td width="22%" valign="top">&nbsp;</td>
778
							<td width="78%">
779
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Update");?>" />
780
								<?php if (isset($id) && $a_cert[$id]): ?>
781
								<input name="id" type="hidden" value="<?=$id;?>" />
782
								<input name="act" type="hidden" value="csr" />
783
								<?php endif;?>
784
							</td>
785
						</tr>
786
					</table>
787
				</form>
788

    
789
				<?php else:?>
790

    
791
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
792
					<tr>
793
						<td width="15%" class="listhdrr"><?=gettext("Name");?></td>
794
						<td width="15%" class="listhdrr"><?=gettext("Issuer");?></td>
795
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
796
						<td width="10%" class="listhdrr"><?=gettext("In Use");?></td>
797
						<td width="10%" class="list"></td>
798
					</tr>
799
					<?php
800
						$i = 0;
801
						foreach($a_cert as $cert):
802
							$name = htmlspecialchars($cert['descr']);
803

    
804
							if ($cert['crt']) {
805
								$subj = cert_get_subject($cert['crt']);
806
								$issuer = cert_get_issuer($cert['crt']);
807
								if($subj==$issuer)
808
								  $caname = "<em>" . gettext("self-signed") . "</em>";
809
								else
810
							    $caname = "<em>" . gettext("external"). "</em>";
811
							  $subj = htmlspecialchars($subj);
812
							}
813

    
814
							if ($cert['csr']) {
815
								$subj = htmlspecialchars(csr_get_subject($cert['csr']));
816
								$caname = "<em>" . gettext("external - signature pending") . "</em>";
817
							}
818

    
819
							$ca = lookup_ca($cert['caref']);
820
							if ($ca)
821
								$caname = $ca['descr'];
822

    
823
							if($cert['prv'])
824
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
825
							else
826
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
827
					?>
828
					<tr>
829
						<td class="listlr">
830
							<table border="0" cellpadding="0" cellspacing="0">
831
								<tr>
832
									<td align="left" valign="center">
833
										<img src="<?=$certimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
834
									</td>
835
									<td align="left" valign="middle">
836
										<?=$name;?>
837
									</td>
838
								</tr>
839
							</table>
840
						</td>
841
						<td class="listr"><?=$caname;?>&nbsp;</td>
842
						<td class="listr"><?=$subj;?>&nbsp;</td>
843
						<td class="listr">
844
							<?php if (is_cert_revoked($cert)): ?>
845
							<b>Revoked</b><br/>
846
							<?php endif; ?>
847
							<?php if (is_webgui_cert($cert['refid'])): ?>
848
							webConfigurator<br/>
849
							<?php endif; ?>
850
							<?php if (is_user_cert($cert['refid'])): ?>
851
							User Cert<br/>
852
							<?php endif; ?>
853
							<?php if (is_openvpn_server_cert($cert['refid'])): ?>
854
							OpenVPN Server<br/>
855
							<?php endif; ?>
856
							<?php if (is_openvpn_client_cert($cert['refid'])): ?>
857
							OpenVPN Client<br/>
858
							<?php endif; ?>
859
							<?php if (is_ipsec_cert($cert['refid'])): ?>
860
							IPsec Tunnel<br/>
861
							<?php endif; ?>
862
						</td>
863
						<td valign="middle" nowrap class="list">
864
							<a href="system_certmanager.php?act=exp&id=<?=$i;?>">
865
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export cert");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
866
							</a>
867
							<a href="system_certmanager.php?act=key&id=<?=$i;?>">
868
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export key");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
869
							</a>
870
							<?php	if (!cert_in_use($cert['refid'])): ?>
871
							<a href="system_certmanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Certificate?");?>')">
872
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete cert");?>" alt="<?=gettext("delete cert");?>" width="17" height="17" border="0" />
873
							</a>
874
							<?php	endif; ?>
875
							<?php	if ($cert['csr']): ?>
876
							&nbsp;
877
								<a href="system_certmanager.php?act=csr&id=<?=$i;?>">
878
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("update csr");?>" alt="<?=gettext("update csr");?>" width="17" height="17" border="0" />
879
							</a>
880
							<?php	endif; ?>
881
						</td>
882
					</tr>
883
					<?php
884
							$i++;
885
						endforeach;
886
					?>
887
					<tr>
888
						<td class="list" colspan="4"></td>
889
						<td class="list">
890
							<a href="system_certmanager.php?act=new">
891
								<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" />
892
							</a>
893
						</td>
894
					</tr>
895
					<tr>
896
						<td>&nbsp;</td>
897
						<td colspan="3">NOTE: You can only delete a certificate if it is not currently in use.</td>
898
					</tr>
899
				</table>
900

    
901
				<?php endif; ?>
902

    
903
			</div>
904
		</td>
905
	</tr>
906
</table>
907
<?php include("fend.inc");?>
908
<script type="text/javascript">
909
<!--
910

    
911
method_change();
912
internalca_change();
913

    
914
//-->
915
</script>
916

    
917
</body>
(185-185/225)