Project

General

Profile

« Previous | Next » 

Revision 26308930

Added by Marcos M about 1 year ago

Use config accessors in certificate functions

View differences:

src/usr/local/www/system_camanager.php
47 47
$openssl_ecnames = cert_build_curve_list();
48 48
$class = "success";
49 49

  
50
init_config_arr(array('ca'));
51
$a_ca = &$config['ca'];
52

  
53
init_config_arr(array('cert'));
54
$a_cert = &$config['cert'];
55

  
56
init_config_arr(array('crl'));
57
$a_crl = &$config['crl'];
50
config_init_path('ca');
51
config_init_path('cert');
52
config_init_path('crl');
58 53

  
59 54
$act = $_REQUEST['act'];
60 55

  
......
62 57
	$id = $_REQUEST['id'];
63 58
}
64 59
if (!empty($id)) {
65
	$thisca =& lookup_ca($id);
60
	$ca_item_config = lookup_ca($id);
61
	$thisca = &$ca_item_config['item'];
66 62
}
67 63

  
68 64
/* Actions other than 'new' require an ID.
......
83 79
			$class = "danger";
84 80
		} else {
85 81
			/* Only remove CA reference when deleting. It can be reconnected if a new matching CA is imported */
86
			foreach ($a_cert as $cid => $acrt) {
82
			foreach (config_get_path('cert', []) as $cid => $acrt) {
87 83
				if ($acrt['caref'] == $thisca['refid']) {
88
					unset($a_cert[$cid]['caref']);
84
					config_del_path("cert/{$cid}/caref");
89 85
				}
90 86
			}
91 87
			/* Remove any CRLs for this CA, there is no way to recover the connection once the CA has been removed. */
92
			foreach ($a_crl as $cid => $acrl) {
88
			foreach (config_get_path('crl', []) as $cid => $acrl) {
93 89
				if ($acrl['caref'] == $thisca['refid']) {
94
					unset($a_crl[$cid]);
90
					config_del_path("crl/{$cid}");
95 91
				}
96 92
			}
97 93
			/* Delete the CA */
98
			foreach ($a_ca as $cid => $aca) {
94
			foreach (config_get_path('ca', []) as $cid => $aca) {
99 95
				if ($aca['refid'] == $thisca['refid']) {
100
					unset($a_ca[$cid]);
96
					config_del_path("ca/{$cid}");
101 97
				}
102 98
			}
103 99
			$savemsg = sprintf(gettext("Deleted Certificate Authority %s and associated CRLs"), htmlspecialchars($name));
......
332 328
		}
333 329

  
334 330
		if (isset($id) && $thisca) {
335
			$thisca = $ca;
331
			config_set_path("ca/{$ca_item_config['item']}", $ca);
336 332
		} else {
337
			$a_ca[] = $ca;
333
			config_set_path('ca/', $ca);
338 334
		}
339 335

  
340 336
		if (!$input_errors) {
......
428 424
$pluginparams['event'] = 'used_ca';
429 425
$certificates_used_by_packages = pkg_call_plugins('plugin_certificates', $pluginparams);
430 426

  
431
foreach ($a_ca as $ca):
427
foreach (config_get_path('ca', []) as $ca):
432 428
	$name = htmlspecialchars($ca['descr']);
433 429
	$subj = cert_get_subject($ca['crt']);
434 430
	$issuer = cert_get_issuer($ca['crt']);
......
442 438
	$certcount = 0;
443 439

  
444 440
	$issuer_ca = lookup_ca($ca['caref']);
441
	$issuer_ca = $issuer_ca['item'];
445 442
	if ($issuer_ca) {
446 443
		$issuer_name = htmlspecialchars($issuer_ca['descr']);
447 444
	}
448 445

  
449
	foreach ($a_cert as $cert) {
446
	foreach (config_get_path('cert', []) as $cert) {
450 447
		if ($cert['caref'] == $ca['refid']) {
451 448
			$certcount++;
452 449
		}
453 450
	}
454 451

  
455
	foreach ($a_ca as $cert) {
452
	foreach (config_get_path('ca', []) as $cert) {
456 453
		if ($cert['caref'] == $ca['refid']) {
457 454
			$certcount++;
458 455
		}
......
661 658
$section->addClass('toggle-internal', 'toggle-intermediate', 'collapse');
662 659

  
663 660
$allCas = array();
664
foreach ($a_ca as $ca) {
661
foreach (config_get_path('ca', []) as $ca) {
665 662
	if (!$ca['prv']) {
666 663
			continue;
667 664
	}
......
782 779
print $form;
783 780

  
784 781
$internal_ca_count = 0;
785
foreach ($a_ca as $ca) {
782
foreach (config_get_path('ca', []) as $ca) {
786 783
	if ($ca['prv']) {
787 784
		$internal_ca_count++;
788 785
	}

Also available in: Unified diff