From 30356cc7e07ff16d49bbcede93712675e640c78e Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 6 Jul 2015 16:55:12 +0000 Subject: [PATCH] (legacy) more legacy code fixes --- src/www/system_camanager.php | 94 +++++++++++++++++++--------------- src/www/system_certmanager.php | 87 +++++++++++++++++-------------- 2 files changed, 102 insertions(+), 79 deletions(-) diff --git a/src/www/system_camanager.php b/src/www/system_camanager.php index ec14c9fce..aa615c8f3 100644 --- a/src/www/system_camanager.php +++ b/src/www/system_camanager.php @@ -40,14 +40,14 @@ $openssl_digest_algs = array("sha1", "sha224", "sha256", "sha384", "sha512"); $pgtitle = array(gettext("System"), gettext("Certificate Authority Manager")); -if (is_numericint($_GET['id'])) { +if (isset($_GET['id']) && is_numericint($_GET['id'])) { $id = $_GET['id']; } if (isset($_POST['id']) && is_numericint($_POST['id'])) { $id = $_POST['id']; } -if (!is_array($config['ca'])) { +if (!isset($config['ca']) || !is_array($config['ca'])) { $config['ca'] = array(); } @@ -59,14 +59,16 @@ if (!is_array($config['cert'])) { $a_cert =& $config['cert']; -if (!is_array($config['crl'])) { +if (!isset($config['crl']) || !is_array($config['crl'])) { $config['crl'] = array(); } $a_crl =& $config['crl']; -$act = $_GET['act']; -if ($_POST['act']) { +$act=null; +if (isset($_GET['act'])) { + $act = $_GET['act']; +} elseif (isset($_POST['act'])) { $act = $_POST['act']; } @@ -99,7 +101,7 @@ if ($act == "del") { } if ($act == "edit") { - if (!$a_ca[$id]) { + if (!isset($a_ca[$id])) { redirectHeader("system_camanager.php"); exit; } @@ -113,7 +115,11 @@ if ($act == "edit") { } if ($act == "new") { - $pconfig['method'] = $_GET['method']; + if (isset($_GET['method'])) { + $pconfig['method'] = $_GET['method']; + } else { + $pconfig['method'] = null ; + } $pconfig['keylen'] = "2048"; $pconfig['digest_alg'] = "sha256"; $pconfig['lifetime'] = "365"; @@ -251,9 +257,13 @@ if ($_POST) { $ca = $a_ca[$id]; } - $ca['descr'] = $pconfig['descr']; + if (isset($pconfig['descr'])) { + $ca['descr'] = $pconfig['descr']; + } else { + $ca['descr'] = null; + } - if ($_POST['edit'] == "edit") { + if (isset($_POST['edit']) && $_POST['edit'] == "edit") { $ca['descr'] = $pconfig['descr']; $ca['refid'] = $pconfig['refid']; $ca['serial'] = $pconfig['serial']; @@ -305,12 +315,12 @@ if ($_POST) { if (!$input_errors) { write_config(); + unset($input_errors); } // redirectHeader("system_camanager.php"); } } - include("head.inc"); $main_buttons = array( @@ -373,7 +383,7 @@ function method_change() {
-
@@ -390,7 +400,7 @@ endif; ?> - + @@ -403,7 +413,7 @@ endif; ?> $desc) : $selected = ""; - if ($pconfig['method'] == $method) { + if (isset($pconfig['method']) && $pconfig['method'] == $method) { $selected = " selected=\"selected\""; } ?> @@ -431,7 +441,7 @@ endif; ?> - +
@@ -440,7 +450,7 @@ endif; ?>
- +
@@ -451,7 +461,7 @@ endif; ?> - +
@@ -480,7 +490,7 @@ endif; ?> continue; } $selected = ""; - if ($pconfig['caref'] == $ca['refid']) { + if (isset($pconfig['caref']) && isset($ca['refid']) && $pconfig['caref'] == $ca['refid']) { $selected = " selected=\"selected\""; } ?> @@ -499,7 +509,7 @@ endif; ?> @@ -519,7 +529,7 @@ endif; ?> @@ -535,7 +545,7 @@ endif; ?> - + @@ -551,7 +561,7 @@ endif; ?> $dn_cc = get_country_codes(); foreach ($dn_cc as $cc => $cn) { $selected = ''; - if ($pconfig['dn_country'] == $cc) { + if (isset($pconfig['dn_country']) && $pconfig['dn_country'] == $cc) { $selected = ' selected="selected"'; } print ""; @@ -563,7 +573,7 @@ endif; ?> :   - +     @@ -573,7 +583,7 @@ endif; ?> :   - +     @@ -583,7 +593,7 @@ endif; ?> :   - +     @@ -593,7 +603,7 @@ endif; ?> :   - +     @@ -603,7 +613,7 @@ endif; ?> :   - +     @@ -664,11 +674,23 @@ else : $subj = htmlspecialchars($subj); $issuer = htmlspecialchars($issuer); $certcount = 0; - - $issuer_ca = lookup_ca($ca['caref']); - if ($issuer_ca) { - $issuer_name = $issuer_ca['descr']; - } + + if (isset($ca['caref'])) { + $issuer_ca = lookup_ca($ca['caref']); + if ($issuer_ca) { + $issuer_name = $issuer_ca['descr']; + } + foreach ($a_cert as $cert) { + if ($cert['caref'] == $ca['refid']) { + $certcount++; + } + } + foreach ($a_ca as $cert) { + if ($cert['caref'] == $ca['refid']) { + $certcount++; + } + } + } // TODO : Need gray certificate icon @@ -680,16 +702,6 @@ else : $caimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png"; $internal = "NO"; } - foreach ($a_cert as $cert) { - if ($cert['caref'] == $ca['refid']) { - $certcount++; - } - } - foreach ($a_ca as $cert) { - if ($cert['caref'] == $ca['refid']) { - $certcount++; - } - } ?> diff --git a/src/www/system_certmanager.php b/src/www/system_certmanager.php index 14fb459b3..461a76c96 100644 --- a/src/www/system_certmanager.php +++ b/src/www/system_certmanager.php @@ -84,8 +84,10 @@ foreach ($a_ca as $ca) { } } -$act = $_GET['act']; -if ($_POST['act']) { +$act = null; +if (isset($_GET['act'])) { + $act = $_GET['act']; +} elseif (isset($_POST['act'])) { $act = $_POST['act']; } @@ -104,7 +106,11 @@ if ($act == "del") { } if ($act == "new") { - $pconfig['method'] = $_GET['method']; + if (isset($_GET['method'])) { + $pconfig['method'] = $_GET['method']; + } else { + $pconfig['method'] = null; + } $pconfig['keylen'] = "2048"; $pconfig['digest_alg'] = "sha256"; $pconfig['csr_keylen'] = "2048"; @@ -425,7 +431,7 @@ if ($_POST) { write_config(); } - if ($userid) { + if (isset($userid)) { post_redirect("system_usermanager.php", array('act' => 'edit', 'userid' => $userid)); exit; } @@ -614,7 +620,7 @@ endif; ?>
- @@ -644,13 +650,13 @@ endif; ?> endif; ?> - + @@ -666,7 +672,7 @@ endif; ?> - +
@@ -674,7 +680,7 @@ endif; ?> - +
@@ -715,7 +721,7 @@ else : continue; } $selected = ""; - if ($pconfig['caref'] == $ca['refid']) { + if (isset($pconfig['caref']) && isset($ca['refid']) && $pconfig['caref'] == $ca['refid']) { $selected = " selected=\"selected\""; } ?> @@ -781,31 +787,31 @@ else : :   - + :   - + :   - + :   - + :   - +   ex:   @@ -816,11 +822,11 @@ else : :   - +   ex:   @@ -840,7 +846,7 @@ else : $dn_cc = get_country_codes(); foreach ($dn_cc as $cc => $cn) { $selected = ''; - if ($pconfig['csr_dn_country'] == $cc) { + if (isset($pconfig['csr_dn_country']) && $pconfig['csr_dn_country'] == $cc) { $selected = ' selected="selected"'; } print ""; @@ -962,7 +968,7 @@ endif; ?> :   - +   ex:   @@ -972,7 +978,7 @@ endif; ?> :   - +   ex:   @@ -982,7 +988,7 @@ endif; ?> :   - +   ex:   @@ -992,7 +998,7 @@ endif; ?> :   - +   ex:   @@ -1002,7 +1008,7 @@ endif; ?> :   - +   ex:   @@ -1040,14 +1046,18 @@ endif;?> if (isset($userid) && in_array($cert['refid'], $config['system']['user'][$userid]['cert'])) { continue; } - $ca = lookup_ca($cert['caref']); - if ($ca) { - $caname = " (CA: {$ca['descr']})"; - } - if ($pconfig['certref'] == $cert['refid']) { + if (isset($cert['caref'])) { + $ca = lookup_ca($cert['caref']); + if ($ca) { + $caname = " (CA: {$ca['descr']})"; + } + } else { + $ca = null; + } + if (isset($pconfig['certref']) && isset($cert['refid']) && $pconfig['certref'] == $cert['refid']) { $selected = " selected=\"selected\""; } - if (cert_in_use($cert['refid'])) { + if (isset($cert['refid']) && cert_in_use($cert['refid'])) { $inuse = " *In Use"; } if (is_cert_revoked($cert)) { @@ -1081,7 +1091,7 @@ endif;?>
@@ -1170,15 +1180,16 @@ else : $subj = htmlspecialchars($subj); } - if ($cert['csr']) { + if (isset($cert['csr'])) { $subj = htmlspecialchars(csr_get_subject($cert['csr'])); $caname = "" . gettext("external - signature pending") . ""; } - - $ca = lookup_ca($cert['caref']); - if ($ca) { - $caname = $ca['descr']; - } + if (isset($cert['caref'])) { + $ca = lookup_ca($cert['caref']); + if ($ca) { + $caname = $ca['descr']; + } + } // was: $certimg = "/themes/{$g['theme']}/images/icons/icon_frmfld_cert.png"; @@ -1284,7 +1295,7 @@ endif; ?> -