Project

General

Profile

Download (30.2 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
		}
166

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

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

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

    
204
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
205

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

    
212
		/* save modifications */
213
		if (!$input_errors) {
214

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

    
225
				$cert['descr'] = $pconfig['descr'];
226

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

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

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

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

    
262
			write_config();
263

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

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

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

    
279
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
280

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

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

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

    
294
		/* save modifications */
295
		if (!$input_errors) {
296

    
297
			$cert = $a_cert[$id];
298

    
299
			$cert['descr'] = $pconfig['descr'];
300

    
301
			csr_complete($cert, $pconfig['cert']);
302

    
303
			$a_cert[$id] = $cert;
304

    
305
			write_config();
306

    
307
			pfSenseHeader("system_certmanager.php");
308
		}
309
	}
310
}
311

    
312
include("head.inc");
313
?>
314

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

    
320
function method_change() {
321

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

    
329
	method = document.iform.method.selectedIndex;
330

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

    
367
<?php if ($internal_ca_count): ?>
368
function internalca_change() {
369

    
370
	index = document.iform.caref.selectedIndex;
371
	caref = document.iform.caref[index].value;
372

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

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

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

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

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

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

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

    
483
						<?php if (!$internal_ca_count): ?>
484

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

    
493
						<?php else: ?>
494

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

    
591
					<?php endif; ?>
592

    
593
					</table>
594

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

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

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

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

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

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

    
787
				<?php else:?>
788

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

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

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

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

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

    
899
				<?php endif; ?>
900

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

    
909
method_change();
910
internalca_change();
911

    
912
//-->
913
</script>
914

    
915
</body>
(180-180/220)