Project

General

Profile

Download (31.1 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 ( !isset($_POST['ignoresubjectmismatch']) && !($_POST['ignoresubjectmismatch'] == "yes") ) {
288
			if (strcmp($subj_csr,$subj_cert)) {
289
				$input_errors[] = sprintf(gettext("The certificate subject '%s' does not match the signing request subject."),$subj_cert);
290
				$subject_mismatch = true;
291
			}
292
		} 
293

    
294
		/* if this is an AJAX caller then handle via JSON */
295
		if (isAjax() && is_array($input_errors)) {
296
			input_errors2Ajax($input_errors);
297
			exit;
298
		}
299

    
300
		/* save modifications */
301
		if (!$input_errors) {
302

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

    
305
			$cert['descr'] = $pconfig['descr'];
306

    
307
			csr_complete($cert, $pconfig['cert']);
308

    
309
			$a_cert[$id] = $cert;
310

    
311
			write_config();
312

    
313
			pfSenseHeader("system_certmanager.php");
314
		}
315
	}
316
}
317

    
318
include("head.inc");
319
?>
320

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

    
326
function method_change() {
327

    
328
<?php
329
	if ($internal_ca_count)
330
		$submit_style = "";
331
	else
332
		$submit_style = "none";
333
?>
334

    
335
	method = document.iform.method.selectedIndex;
336

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

    
373
<?php if ($internal_ca_count): ?>
374
function internalca_change() {
375

    
376
	index = document.iform.caref.selectedIndex;
377
	caref = document.iform.caref[index].value;
378

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

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

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

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

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

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

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

    
489
						<?php if (!$internal_ca_count): ?>
490

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

    
499
						<?php else: ?>
500

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

    
597
					<?php endif; ?>
598

    
599
					</table>
600

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

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

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

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

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

    
764
						<tr>
765
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Request data");?></td>
766
							<td width="78%" class="vtable">
767
								<textarea name="csr" id="csr" cols="65" rows="7" class="formfld_cert" readonly><?=htmlspecialchars($pconfig['csr']);?></textarea>
768
								<br>
769
								<?=gettext("Copy the certificate signing data from here and forward it to your certificate authority for signing.");?></td>
770
							</td>
771
						</tr>
772
						<tr>
773
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Final Certificate data");?></td>
774
							<td width="78%" class="vtable">
775
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=htmlspecialchars($pconfig['cert']);?></textarea>
776
								<br>
777
								<?=gettext("Paste the certificate received from your cerificate authority here.");?></td>
778
							</td>
779
						</tr>
780
						<tr>
781
							<td width="22%" valign="top">&nbsp;</td>
782
							<td width="78%">
783
								<?php if ( isset($subject_mismatch) && $subject_mismatch === true): ?>
784
								<input id="ignoresubjectmismatch" name="ignoresubjectmismatch" type="checkbox" class="formbtn" value="yes" />
785
								<label for="ignoresubjectmismatch"><strong><?=gettext("Ignore certificate subject mismatch"); ?></strong></label><br />
786
								<?php echo gettext("Warning: Using this option may create an " .
787
								"invalid certificate.  Check this box to disable the request -> " .
788
								"response subject verification. ");
789
								?><br/>
790
								<?php endif;?>
791
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Update");?>" />
792
								<?php if (isset($id) && $a_cert[$id]): ?>
793
								<input name="id" type="hidden" value="<?=$id;?>" />
794
								<input name="act" type="hidden" value="csr" />
795
								<?php endif;?>
796
							</td>
797
						</tr>
798
					</table>
799
				</form>
800

    
801
				<?php else:?>
802

    
803
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
804
					<tr>
805
						<td width="15%" class="listhdrr"><?=gettext("Name");?></td>
806
						<td width="15%" class="listhdrr"><?=gettext("Issuer");?></td>
807
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
808
						<td width="10%" class="listhdrr"><?=gettext("In Use");?></td>
809
						<td width="10%" class="list"></td>
810
					</tr>
811
					<?php
812
						$i = 0;
813
						foreach($a_cert as $cert):
814
							$name = htmlspecialchars($cert['descr']);
815

    
816
							if ($cert['crt']) {
817
								$subj = cert_get_subject($cert['crt']);
818
								$issuer = cert_get_issuer($cert['crt']);
819
								if($subj==$issuer)
820
								  $caname = "<em>" . gettext("self-signed") . "</em>";
821
								else
822
							    $caname = "<em>" . gettext("external"). "</em>";
823
							  $subj = htmlspecialchars($subj);
824
							}
825

    
826
							if ($cert['csr']) {
827
								$subj = htmlspecialchars(csr_get_subject($cert['csr']));
828
								$caname = "<em>" . gettext("external - signature pending") . "</em>";
829
							}
830

    
831
							$ca = lookup_ca($cert['caref']);
832
							if ($ca)
833
								$caname = $ca['descr'];
834

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

    
913
				<?php endif; ?>
914

    
915
			</div>
916
		</td>
917
	</tr>
918
</table>
919
<?php include("fend.inc");?>
920
<script type="text/javascript">
921
<!--
922

    
923
method_change();
924
internalca_change();
925

    
926
//-->
927
</script>
928

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