Project

General

Profile

Download (25.9 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
	"existing" => gettext("Import an existing Certificate"),
45
	"internal" => gettext("Create an internal Certificate"),
46
	"external" => gettext("Create a Certificate Signing Request"));
47

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

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

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

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

    
59
$a_ca =& $config['system']['ca'];
60

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

    
64
$a_cert =& $config['system']['cert'];
65

    
66
$internal_ca_count = 0;
67
foreach ($a_ca as $ca)
68
	if ($ca['prv'])	
69
		$internal_ca_count++;
70

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

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

    
77
	if (!$a_cert[$id]) {
78
		pfSenseHeader("system_certmanager.php");
79
		exit;
80
	}
81

    
82
	$name = $a_cert[$id]['name'];
83
	unset($a_cert[$id]);
84
	write_config();
85
	$savemsg = gettext("Certificate")." {$name} ".
86
				gettext("successfully deleted")."<br/>";
87
}
88

    
89
if ($act == "new") {
90
	$pconfig['method'] = $_GET['method'];
91
	$pconfig['keylen'] = "2048";
92
	$pconfig['lifetime'] = "3650";
93
}
94

    
95
if ($act == "exp") {
96

    
97
	if (!$a_cert[$id]) {
98
		pfSenseHeader("system_certmanager.php");
99
		exit;
100
	}
101

    
102
	$exp_name = urlencode("{$a_cert[$id]['name']}.crt");
103
	$exp_data = base64_decode($a_cert[$id]['crt']);
104
	$exp_size = strlen($exp_data);
105

    
106
	header("Content-Type: application/octet-stream");
107
	header("Content-Disposition: attachment; filename={$exp_name}");
108
	header("Content-Length: $exp_size");
109
	echo $exp_data;
110
	exit;
111
}
112

    
113
if ($act == "key") {
114

    
115
	if (!$a_cert[$id]) {
116
		pfSenseHeader("system_certmanager.php");
117
		exit;
118
	}
119

    
120
	$exp_name = urlencode("{$a_cert[$id]['name']}.key");
121
	$exp_data = base64_decode($a_cert[$id]['prv']);
122
	$exp_size = strlen($exp_data);
123

    
124
	header("Content-Type: application/octet-stream");
125
	header("Content-Disposition: attachment; filename={$exp_name}");
126
	header("Content-Length: $exp_size");
127
	echo $exp_data;
128
	exit;
129
}
130

    
131
if ($act == "csr") {
132

    
133
	if (!$a_cert[$id]) {
134
		pfSenseHeader("system_certmanager.php");
135
		exit;
136
	}
137

    
138
	$pconfig['name'] = $a_cert[$id]['name'];
139
	$pconfig['csr'] = base64_decode($a_cert[$id]['csr']);
140
}
141

    
142
if ($_POST) {
143

    
144
	if ($_POST['save'] == gettext("Save")) {
145

    
146
		unset($input_errors);
147
		$pconfig = $_POST;
148

    
149
		/* input validation */
150
		if ($pconfig['method'] == "existing") {
151
			$reqdfields = explode(" ",
152
					"name cert key");
153
			$reqdfieldsn = array(
154
					gettext("Descriptive name"),
155
					gettext("Certificate data"),
156
					gettext("Key data"));
157
		}
158

    
159
		if ($pconfig['method'] == "internal") {
160
			$reqdfields = explode(" ",
161
					"name caref keylen lifetime dn_country dn_state dn_city ".
162
					"dn_organization dn_email dn_commonname");
163
			$reqdfieldsn = array(
164
					gettext("Descriptive name"),
165
					gettext("Certificate authority"),
166
					gettext("Key length"),
167
					gettext("Lifetime"),
168
					gettext("Distinguished name Country Code"),
169
					gettext("Distinguished name State or Province"),
170
					gettext("Distinguished name City"),
171
					gettext("Distinguished name Organization"),
172
					gettext("Distinguished name Email Address"),
173
					gettext("Distinguished name Common Name"));
174
		}
175

    
176
		if ($pconfig['method'] == "external") {
177
			$reqdfields = explode(" ",
178
					"name csr_keylen csr_dn_country csr_dn_state csr_dn_city ".
179
					"csr_dn_organization csr_dn_email csr_dn_commonname");
180
			$reqdfieldsn = array(
181
					gettext("Descriptive name"),
182
					gettext("Key length"),
183
					gettext("Distinguished name Country Code"),
184
					gettext("Distinguished name State or Province"),
185
					gettext("Distinguished name City"),
186
					gettext("Distinguished name Organization"),
187
					gettext("Distinguished name Email Address"),
188
					gettext("Distinguished name Common Name"));
189
		}
190

    
191
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
192

    
193
		/* if this is an AJAX caller then handle via JSON */
194
		if (isAjax() && is_array($input_errors)) {
195
			input_errors2Ajax($input_errors);
196
			exit;
197
		}
198

    
199
		/* save modifications */
200
		if (!$input_errors) {
201

    
202
			$cert = array();
203
			$cert['refid'] = uniqid();
204
			if (isset($id) && $a_cert[$id])
205
				$cert = $a_cert[$id];
206

    
207
		    $cert['name'] = $pconfig['name'];
208

    
209
			if ($pconfig['method'] == "existing")
210
				cert_import($cert, $pconfig['cert'], $pconfig['key']);
211

    
212
			if ($pconfig['method'] == "internal") {
213
				$dn = array(
214
					'countryName' => $pconfig['dn_country'],
215
					'stateOrProvinceName' => $pconfig['dn_state'],
216
					'localityName' => $pconfig['dn_city'],
217
					'organizationName' => $pconfig['dn_organization'],
218
					'emailAddress' => $pconfig['dn_email'],
219
					'commonName' => $pconfig['dn_commonname']);
220

    
221
				cert_create($cert, $pconfig['caref'], $pconfig['keylen'],
222
					$pconfig['lifetime'], $dn);
223
			}
224

    
225
			if ($pconfig['method'] == "external") {
226
				$dn = array(
227
					'countryName' => $pconfig['csr_dn_country'],
228
					'stateOrProvinceName' => $pconfig['csr_dn_state'],
229
					'localityName' => $pconfig['csr_dn_city'],
230
					'organizationName' => $pconfig['csr_dn_organization'],
231
					'emailAddress' => $pconfig['csr_dn_email'],
232
					'commonName' => $pconfig['csr_dn_commonname']);
233

    
234
				csr_generate($cert, $pconfig['csr_keylen'], $dn);
235
			}
236

    
237
			if (isset($id) && $a_cert[$id])
238
				$a_cert[$id] = $cert;
239
			else
240
				$a_cert[] = $cert;
241

    
242
			write_config();
243

    
244
//			pfSenseHeader("system_certmanager.php");
245
		}
246
	}
247

    
248
	if ($_POST['save'] == gettext("Update")) {
249
		unset($input_errors);
250
		$pconfig = $_POST;
251

    
252
		/* input validation */
253
		$reqdfields = explode(" ", "name cert");
254
		$reqdfieldsn = explode(",", gettext("Descriptive name") . "," . gettext("Final Certificate data"));
255

    
256
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
257

    
258
		/* make sure this csr and certificate subjects match */
259
		$subj_csr = csr_get_subject($pconfig['csr'], false);
260
		$subj_cert = cert_get_subject($pconfig['cert'], false);
261

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

    
265
		/* if this is an AJAX caller then handle via JSON */
266
		if (isAjax() && is_array($input_errors)) {
267
			input_errors2Ajax($input_errors);
268
			exit;
269
		}
270

    
271
		/* save modifications */
272
		if (!$input_errors) {
273

    
274
			$cert = $a_cert[$id];
275

    
276
			$cert['name'] = $pconfig['name'];
277

    
278
			csr_complete($cert, $pconfig['cert']);
279

    
280
			$a_cert[$id] = $cert;
281

    
282
			write_config();
283

    
284
			pfSenseHeader("system_certmanager.php");
285
		}
286
	}
287
}
288

    
289
include("head.inc");
290
?>
291

    
292
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
293
<?php include("fbegin.inc"); ?>
294
<script type="text/javascript">
295
<!--
296

    
297
function method_change() {
298

    
299
<?php
300
	if ($internal_ca_count)
301
		$submit_style = "";
302
	else
303
		$submit_style = "none";
304
?>
305

    
306
	method = document.iform.method.selectedIndex;
307

    
308
	switch (method) {
309
		case 0:
310
			document.getElementById("existing").style.display="";
311
			document.getElementById("internal").style.display="none";
312
			document.getElementById("external").style.display="none";
313
			document.getElementById("submit").style.display="";
314
			break;
315
		case 1:
316
			document.getElementById("existing").style.display="none";
317
			document.getElementById("internal").style.display="";
318
			document.getElementById("external").style.display="none";
319
			document.getElementById("submit").style.display="<?=$submit_style;?>";
320
			break;
321
		case 2:
322
			document.getElementById("existing").style.display="none";
323
			document.getElementById("internal").style.display="none";
324
			document.getElementById("external").style.display="";
325
			document.getElementById("submit").style.display="";
326
			break;
327
	}
328
}
329

    
330
<?php if ($internal_ca_count): ?>
331
function internalca_change() {
332

    
333
	index = document.iform.caref.selectedIndex;
334
	caref = document.iform.caref[index].value;
335

    
336
	switch (caref) {
337
<?php
338
		foreach ($a_ca as $ca):
339
			if (!$ca['prv'])
340
				continue;
341
			$subject = cert_get_subject_array($ca['crt']);
342
?>
343
		case "<?=$ca['refid'];?>":
344
			document.iform.dn_country.value = "<?=$subject[0]['v'];?>";
345
			document.iform.dn_state.value = "<?=$subject[1]['v'];?>";
346
			document.iform.dn_city.value = "<?=$subject[2]['v'];?>";
347
			document.iform.dn_organization.value = "<?=$subject[3]['v'];?>";
348
			break;
349
<?php	endforeach; ?>
350
	}
351
}
352
<?php endif; ?>
353

    
354
//-->
355
</script>
356
<?php
357
	if ($input_errors)
358
		print_input_errors($input_errors);
359
	if ($savemsg)
360
		print_info_box($savemsg);
361
?>
362
<table width="100%" border="0" cellpadding="0" cellspacing="0">
363
	<tr>
364
		<td class="tabnavtbl">
365
		<?php
366
			$tab_array = array();
367
			$tab_array[] = array(gettext("CAs"), false, "system_camanager.php");
368
			$tab_array[] = array(gettext("Certificates"), true, "system_certmanager.php");
369
			display_top_tabs($tab_array);
370
		?>
371
		</td>
372
	</tr>
373
	<tr>
374
		<td id="mainarea">
375
			<div class="tabcont">
376

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

    
379
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
380
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
381
						<tr>
382
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
383
							<td width="78%" class="vtable">
384
								<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"/>
385
							</td>
386
						</tr>
387
						<?php if (!isset($id)): ?>
388
						<tr>
389
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Method");?></td>
390
							<td width="78%" class="vtable">
391
								<select name='method' id='method' class="formselect" onchange='method_change()'>
392
								<?php
393
									foreach($cert_methods as $method => $desc):
394
									$selected = "";
395
									if ($pconfig['method'] == $method)
396
										$selected = "selected";
397
								?>
398
									<option value="<?=$method;?>"<?=$selected;?>><?=$desc;?></option>
399
								<?php endforeach; ?>
400
								</select>
401
							</td>
402
						</tr>
403
						<?php endif; ?>
404
					</table>
405

    
406
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing">
407
						<tr>
408
							<td colspan="2" class="list" height="12"></td>
409
						</tr>
410
						<tr>
411
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Existing Certificate");?></td>
412
						</tr>
413

    
414
						<tr>
415
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate data");?></td>
416
							<td width="78%" class="vtable">
417
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=$pconfig['cert'];?></textarea>
418
								<br>
419
									<?=gettext("Paste a certificate in X.509 PEM format here.");?></td>
420
							</td>
421
						</tr>
422
						<tr>
423
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Private key data");?></td>
424
							<td width="78%" class="vtable">
425
								<textarea name="key" id="key" cols="65" rows="7" class="formfld_cert"><?=$pconfig['key'];?></textarea>
426
								<br>
427
								<?=gettext("Paste a private key in X.509 PEM format here.");?></td>
428
							</td>
429
						</tr>
430
					</table>
431

    
432
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="internal">
433
						<tr>
434
							<td colspan="2" class="list" height="12"></td>
435
						</tr>
436
						<tr>
437
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Internal Certificate");?></td>
438
						</tr>
439

    
440
						<?php if (!$internal_ca_count): ?>
441

    
442
						<tr>
443
							<td colspan="2" align="center" class="vtable">
444
								<?=gettext("No internal Certificate Authorities have been defined. You must");?>
445
								<a href="system_camanager.php?act=new&method=internal"><?=gettext("create");?></a>
446
								<?=gettext("an internal CA before creating an internal certificate.");?>
447
							</td>
448
						</tr>
449

    
450
						<?php else: ?>
451

    
452
						<tr>
453
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Certificate authority");?></td>
454
							<td width="78%" class="vtable">
455
								<select name='caref' id='caref' class="formselect" onChange='internalca_change()'>
456
								<?php
457
									foreach( $a_ca as $ca):
458
									if (!$ca['prv'])
459
										continue;
460
									$selected = "";
461
									if ($pconfig['caref'] == $ca['refid'])
462
										$selected = "selected";
463
								?>
464
									<option value="<?=$ca['refid'];?>"<?=$selected;?>><?=$ca['name'];?></option>
465
								<?php endforeach; ?>
466
								</select>
467
							</td>
468
						</tr>
469
						<tr>
470
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
471
							<td width="78%" class="vtable">
472
								<select name='keylen' class="formselect">
473
								<?php
474
									foreach( $cert_keylens as $len):
475
									$selected = "";
476
									if ($pconfig['keylen'] == $len)
477
										$selected = "selected";
478
								?>
479
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
480
								<?php endforeach; ?>
481
								</select>
482
								<?=gettext("bits");?>
483
							</td>
484
						</tr>
485
						<tr>
486
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Lifetime");?></td>
487
							<td width="78%" class="vtable">
488
								<input name="lifetime" type="text" class="formfld unknown" id="lifetime" size="5" value="<?=htmlspecialchars($pconfig['lifetime']);?>"/>
489
								<?=gettext("days");?>
490
							</td>
491
						</tr>
492
						<tr>
493
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
494
							<td width="78%" class="vtable">
495
								<table border="0" cellspacing="0" cellpadding="2">
496
									<tr>
497
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
498
										<td align="left">
499
											<input name="dn_country" type="text" class="formfld unknown" maxlength="2" size="2" value="<?=htmlspecialchars($pconfig['dn_country']);?>" readonly/>
500
										</td>
501
									</tr>
502
									<tr>
503
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
504
										<td align="left">
505
											<input name="dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_state']);?>" readonly/>
506
										</td>
507
									</tr>
508
									<tr>
509
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
510
										<td align="left">
511
											<input name="dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_city']);?>" readonly/>
512
										</td>
513
									</tr>
514
									<tr>
515
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
516
										<td align="left">
517
											<input name="dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['dn_organization']);?>" readonly/>
518
										</td>
519
									</tr>
520
									<tr>
521
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
522
										<td align="left">
523
											<input name="dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_email']);?>"/>
524
											&nbsp;
525
											<em>ex:</em>
526
											&nbsp;
527
											<?=gettext("webadmin@mycompany.com");?>
528
										</td>
529
									</tr>
530
									<tr>
531
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
532
										<td align="left">
533
											<input name="dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['dn_commonname']);?>"/>
534
											&nbsp;
535
											<em>ex:</em>
536
											&nbsp;
537
											<?=gettext("www.example.com");?>
538
										</td>
539
									</tr>
540
								</table>
541
							</td>
542
						</tr>
543

    
544
					<?php endif; ?>
545

    
546
					</table>
547

    
548
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="external">
549
						<tr>
550
							<td colspan="2" class="list" height="12"></td>
551
						</tr>
552
						<tr>
553
							<td colspan="2" valign="top" class="listtopic"><?=gettext("External Signing Request");?></td>
554
						</tr>
555
						<tr>
556
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Key length");?></td>
557
							<td width="78%" class="vtable">
558
								<select name='csr_keylen' class="formselect">
559
								<?php
560
									foreach( $cert_keylens as $len):
561
									$selected = "";
562
									if ($pconfig['keylen'] == $len)
563
										$selected = "selected";
564
								?>
565
									<option value="<?=$len;?>"<?=$selected;?>><?=$len;?></option>
566
								<?php endforeach; ?>
567
								</select>
568
								bits
569
							</td>
570
						</tr>
571
						<tr>
572
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Distinguished name");?></td>
573
							<td width="78%" class="vtable">
574
								<table border="0" cellspacing="0" cellpadding="2">
575
									<tr>
576
										<td align="right"><?=gettext("Country Code");?> : &nbsp;</td>
577
										<td align="left">
578
											<input name="csr_dn_country" type="text" class="formfld unknown" size="2" value="<?=htmlspecialchars($pconfig['csr_dn_country']);?>" />
579
											&nbsp;
580
											<em>ex:</em>
581
											&nbsp;
582
											US
583
											&nbsp;
584
											<em><?=gettext("( two letters )");?></em>
585
										</td>
586
									</tr>
587
									<tr>
588
										<td align="right"><?=gettext("State or Province");?> : &nbsp;</td>
589
										<td align="left">
590
											<input name="csr_dn_state" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_state']);?>" />
591
											&nbsp;
592
											<em>ex:</em>
593
											&nbsp;
594
											<?=gettext("Texas");?>
595
										</td>
596
									</tr>
597
									<tr>
598
										<td align="right"><?=gettext("City");?> : &nbsp;</td>
599
										<td align="left">
600
											<input name="csr_dn_city" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_city']);?>" />
601
											&nbsp;
602
											<em>ex:</em>
603
											&nbsp;
604
											<?=gettext("Austin");?>
605
										</td>
606
									</tr>
607
									<tr>
608
										<td align="right"><?=gettext("Organization");?> : &nbsp;</td>
609
										<td align="left">
610
											<input name="csr_dn_organization" type="text" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['csr_dn_organization']);?>" />
611
											&nbsp;
612
											<em>ex:</em>
613
											&nbsp;
614
											<?=gettext("My Company Inc.");?>
615
										</td>
616
									</tr>
617
									<tr>
618
										<td align="right"><?=gettext("Email Address");?> : &nbsp;</td>
619
										<td align="left">
620
											<input name="csr_dn_email" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_email']);?>"/>
621
											&nbsp;
622
											<em>ex:</em>
623
											&nbsp;
624
											<?=gettext("webadmin@mycompany.com");?>
625
										</td>
626
									</tr>
627
									<tr>
628
										<td align="right"><?=gettext("Common Name");?> : &nbsp;</td>
629
										<td align="left">
630
											<input name="csr_dn_commonname" type="text" class="formfld unknown" size="25" value="<?=htmlspecialchars($pconfig['csr_dn_commonname']);?>"/>
631
											&nbsp;
632
											<em>ex:</em>
633
											&nbsp;
634
											<?=gettext("www.example.com");?>
635
										</td>
636
									</tr>
637
								</table>
638
							</td>
639
						</tr>
640
					</table>
641

    
642
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
643
						<tr>
644
							<td width="22%" valign="top">&nbsp;</td>
645
							<td width="78%">
646
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
647
								<?php if (isset($id) && $a_cert[$id]): ?>
648
								<input name="id" type="hidden" value="<?=$id;?>" />
649
								<?php endif;?>
650
							</td>
651
						</tr>
652
					</table>
653
				</form>
654

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

    
657
				<form action="system_certmanager.php" method="post" name="iform" id="iform">
658
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
659
						<tr>
660
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Descriptive name");?></td>
661
							<td width="78%" class="vtable">
662
								<input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>"/>
663
							</td>
664
						</tr>
665
						<tr>
666
							<td colspan="2" class="list" height="12"></td>
667
						</tr>
668
						<tr>
669
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Complete Signing Request");?></td>
670
						</tr>
671

    
672
						<tr>
673
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Signing Request data");?></td>
674
							<td width="78%" class="vtable">
675
								<textarea name="csr" id="csr" cols="65" rows="7" class="formfld_cert" readonly><?=$pconfig['csr'];?></textarea>
676
								<br>
677
								<?=gettext("Copy the certificate signing data from here and forward it to your certificate authority for signing.");?></td>
678
							</td>
679
						</tr>
680
						<tr>
681
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Final Certificate data");?></td>
682
							<td width="78%" class="vtable">
683
								<textarea name="cert" id="cert" cols="65" rows="7" class="formfld_cert"><?=$pconfig['cert'];?></textarea>
684
								<br>
685
								<?=gettext("Paste the certificate received from your cerificate authority here.");?></td>
686
							</td>
687
						</tr>
688
						<tr>
689
							<td width="22%" valign="top">&nbsp;</td>
690
							<td width="78%">
691
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Update");?>" />
692
								<?php if (isset($id) && $a_cert[$id]): ?>
693
								<input name="id" type="hidden" value="<?=$id;?>" />
694
								<input name="act" type="hidden" value="csr" />
695
								<?php endif;?>
696
							</td>
697
						</tr>
698
					</table>
699
				</form>
700

    
701
				<?php else:?>
702

    
703
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
704
					<tr>
705
						<td width="20%" class="listhdrr"><?=gettext("Name");?></td>
706
						<td width="20%" class="listhdrr"><?=gettext("Issuer");?></td>
707
						<td width="40%" class="listhdrr"><?=gettext("Distinguished Name");?></td>
708
						<td width="10%" class="list"></td>
709
					</tr>
710
					<?php
711
						$i = 0;
712
						foreach($a_cert as $cert):
713
							$name = htmlspecialchars($cert['name']);
714

    
715
							if ($cert['crt']) {
716
								$subj = cert_get_subject($cert['crt']);
717
								$issuer = cert_get_issuer($cert['crt']);
718
								if($subj==$issuer)
719
								  $caname = "<em>" . gettext("self-signed") . "</em>";
720
								else
721
							    $caname = "<em>" . gettext("external"). "</em>";
722
							  $subj = htmlspecialchars($subj);
723
							}
724

    
725
							if ($cert['csr']) {
726
								$subj = htmlspecialchars(csr_get_subject($cert['csr']));
727
								$caname = "<em>" . gettext("external - signature pending") . "</em>";
728
							}
729

    
730
							$ca = lookup_ca($cert['caref']);
731
							if ($ca)
732
								$caname = $ca['name'];
733

    
734
							if($cert['prv'])
735
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
736
							else
737
								$certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png";
738
					?>
739
					<tr>
740
						<td class="listlr">
741
							<table border="0" cellpadding="0" cellspacing="0">
742
								<tr>
743
									<td align="left" valign="center">
744
										<img src="<?=$certimg;?>" alt="CA" title="CA" border="0" height="16" width="16" />
745
									</td>
746
									<td align="left" valign="middle">
747
										<?=$name;?>
748
									</td>
749
								</tr>
750
							</table>
751
						</td>
752
						<td class="listr"><?=$caname;?>&nbsp;</td>
753
						<td class="listr"><?=$subj;?>&nbsp;</td>
754
						<td valign="middle" nowrap class="list">
755
							<a href="system_certmanager.php?act=exp&id=<?=$i;?>")">
756
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export cert");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
757
							</a>
758
							<a href="system_certmanager.php?act=key&id=<?=$i;?>")">
759
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_down.gif" title="<?=gettext("export key");?>" alt="<?=gettext("export ca");?>" width="17" height="17" border="0" />
760
							</a>
761
							<a href="system_certmanager.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Certificate?");?>')">
762
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete cert");?>" alt="<?=gettext("delete cert");?>" width="17" height="17" border="0" />
763
							</a>
764
							<?php	if ($cert['csr']): ?>
765
							&nbsp;
766
								<a href="system_certmanager.php?act=csr&id=<?=$i;?>">
767
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("update csr");?>" alt="<?=gettext("update csr");?>" width="17" height="17" border="0" />
768
							</a>
769
							<?php	endif; ?>
770
						</td>
771
					</tr>
772
					<?php
773
							$i++;
774
						endforeach;
775
					?>
776
					<tr>
777
						<td class="list" colspan="3"></td>
778
						<td class="list">
779
							<a href="system_certmanager.php?act=new">
780
								<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" />
781
							</a>
782
						</td>
783
					</tr>
784
				</table>
785

    
786
				<?php endif; ?>
787

    
788
			</div>
789
		</td>
790
	</tr>
791
</table>
792
<?php include("fend.inc");?>
793
<script type="text/javascript">
794
<!--
795

    
796
method_change();
797
internalca_change();
798

    
799
//-->
800
</script>
801

    
802
</body>
(176-176/216)