diff --git a/src/www/system_crlmanager.php b/src/www/system_crlmanager.php
index b6ee35006..a44893913 100644
--- a/src/www/system_crlmanager.php
+++ b/src/www/system_crlmanager.php
@@ -1,204 +1,204 @@
$rcert) {
- if (($rcert['refid'] == $cert['refid']) || ($rcert['descr'] == $cert['descr'])) {
- unset($crl['cert'][$id]);
- if (count($crl['cert']) == 0) {
- // Protect against accidentally switching the type to imported, for older CRLs
- if (!isset($crl['method']))
- $crl['method'] = "internal";
- crl_update($crl);
- } else
- crl_update($crl);
- return true;
- }
- }
- return false;
-}
+ global $config;
+ if (!is_crl_internal($crl)) {
+ return false;
+ }
-// Keep this general to allow for future expansion. See cert_in_use() above.
-function crl_in_use($crlref) {
- return (is_openvpn_server_crl($crlref));
+ foreach ($crl['cert'] as $id => $rcert) {
+ if (($rcert['refid'] == $cert['refid']) || ($rcert['descr'] == $cert['descr'])) {
+ unset($crl['cert'][$id]);
+ if (count($crl['cert']) == 0) {
+ // Protect against accidentally switching the type to imported, for older CRLs
+ if (!isset($crl['method'])) {
+ $crl['method'] = "internal";
+ }
+ crl_update($crl);
+ } else {
+ crl_update($crl);
+ }
+ return true;
+ }
+ }
+ return false;
}
-
+// openssl_crl_status messages from certs.inc
global $openssl_crl_status;
-$crl_methods = array(
- "internal" => gettext("Create an internal Certificate Revocation List"),
- "existing" => gettext("Import an existing Certificate Revocation List"));
-
-if (isset($_GET['id']) && ctype_alnum($_GET['id'])) {
- $id = $_GET['id'];
-} elseif (isset($_POST['id']) && ctype_alnum($_POST['id'])) {
- $id = $_POST['id'];
-}
-
-if (!is_array($config['ca'])) {
+// prepare config types
+if (!isset($config['ca']) || !is_array($config['ca'])) {
$config['ca'] = array();
}
-
-$a_ca =& $config['ca'];
-
-if (!is_array($config['cert'])) {
+if (!isset($config['cert']) || !is_array($config['cert'])) {
$config['cert'] = array();
}
-
-$a_cert =& $config['cert'];
-
if (!isset($config['crl']) || !is_array($config['crl'])) {
$config['crl'] = array();
}
-
$a_crl =& $config['crl'];
-foreach ($a_crl as $cid => $acrl) {
- if (!isset($acrl['refid'])) {
- unset ($a_crl[$cid]);
- }
-}
+$thiscrl = false;
$act=null;
-if (isset($_GET['act'])) {
- $act = $_GET['act'];
-} elseif (isset($_POST['act'])) {
- $act = $_POST['act'];
-}
+if ($_SERVER['REQUEST_METHOD'] === 'GET') {
+ // locate cert by refid, returns false when not found
+ if (isset($_GET['id'])) {
+ $thiscrl =& lookup_crl($_GET['id']);
+ if ($thiscrl !== false) {
+ $id = $_GET['id'];
+ }
+ }
+ if (isset($_GET['act'])) {
+ $act = $_GET['act'];
+ }
-if (!empty($id)) {
- $thiscrl =& lookup_crl($id);
-}
+ if ($act == "exp") {
+ crl_update($thiscrl);
+ $exp_name = urlencode("{$thiscrl['descr']}.crl");
+ $exp_data = base64_decode($thiscrl['text']);
+ $exp_size = strlen($exp_data);
-// If we were given an invalid crlref in the id, no sense in continuing as it would only cause errors.
-if (!isset($thiscrl) && (($act != "") && ($act != "new"))) {
- header("Location: system_crlmanager.php");
- $act="";
- $savemsg = gettext("Invalid CRL reference.");
-}
+ header("Content-Type: application/octet-stream");
+ header("Content-Disposition: attachment; filename={$exp_name}");
+ header("Content-Length: $exp_size");
+ echo $exp_data;
+ exit;
+ } elseif ($act == "new") {
+ $pconfig = array();
+ $pconfig['descr'] = null;
+ $pconfig['crltext'] = null;
+ $pconfig['crlmethod'] = !empty($_GET['method']) ? $_GET['method'] : null;
+ $pconfig['caref'] = !empty($_GET['caref']) ? $_GET['caref'] : null;
+ $pconfig['lifetime'] = "9999";
+ $pconfig['serial'] = "0";
+ }
+} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $pconfig = $_POST;
+ // locate cert by refid, returns false when not found
+ if (isset($_POST['id'])) {
+ $thiscrl =& lookup_crl($_POST['id']);
+ if ($thiscrl !== false) {
+ $id = $_POST['id'];
+ }
+ }
+ if (isset($_POST['act'])) {
+ $act = $_POST['act'];
+ }
-if ($act == "del") {
- $name = $thiscrl['descr'];
- if (crl_in_use($id)) {
- $savemsg = sprintf(gettext("Certificate Revocation List %s is in use and cannot be deleted"), $name) . "
";
- } else {
- foreach ($a_crl as $cid => $acrl) {
- if ($acrl['refid'] == $thiscrl['refid']) {
- unset($a_crl[$cid]);
+ if ($act == "del" && isset($id)) {
+ $name = $thiscrl['descr'];
+ if (is_openvpn_server_crl($id)) {
+ $savemsg = sprintf(gettext("Certificate Revocation List %s is in use and cannot be deleted"), $name) . "
";
+ } else {
+ foreach ($a_crl as $cid => $acrl) {
+ if ($acrl['refid'] == $thiscrl['refid']) {
+ unset($a_crl[$cid]);
+ }
+ }
+ write_config("Deleted CRL {$name}.");
+ header("Location: system_crlmanager.php");
+ exit;
+ }
+ } elseif ($act == "delcert" && isset($id)) {
+ if (!isset($thiscrl['cert']) || !is_array($thiscrl['cert'])) {
+ header("Location: system_crlmanager.php");
+ exit;
+ }
+ $found = false;
+ foreach ($thiscrl['cert'] as $acert) {
+ if ($acert['refid'] == $pconfig['certref']) {
+ $found = true;
+ $thiscert = $acert;
}
}
- write_config("Deleted CRL {$name}.");
- $savemsg = sprintf(gettext("Certificate Revocation List %s successfully deleted"), $name) . "
";
- }
-}
-
-if ($act == "new") {
- if (isset($_GET['method'])) {
- $pconfig['method'] = $_GET['method'];
- } else {
- $pconfig['method'] = null;
- }
- if (isset($_GET['caref'])) {
- $pconfig['caref'] = $_GET['caref'];
- } else {
- $pconfig['caref'] = null;
- }
- $pconfig['lifetime'] = "9999";
- $pconfig['serial'] = "0";
-}
-
-if ($act == "exp") {
- crl_update($thiscrl);
- $exp_name = urlencode("{$thiscrl['descr']}.crl");
- $exp_data = base64_decode($thiscrl['text']);
- $exp_size = strlen($exp_data);
-
- header("Content-Type: application/octet-stream");
- header("Content-Disposition: attachment; filename={$exp_name}");
- header("Content-Length: $exp_size");
- echo $exp_data;
- exit;
-}
-
-if ($act == "addcert") {
- if ($_POST) {
- $input_errors = array();
- $pconfig = $_POST;
-
- if (!$pconfig['crlref'] || !$pconfig['certref']) {
+ if (!$found) {
+ header("Location: system_crlmanager.php");
+ exit;
+ }
+ $name = $thiscert['descr'];
+ if (cert_unrevoke($thiscert, $thiscrl)) {
+ openvpn_refresh_crls();
+ write_config(sprintf(gettext("Deleted Certificate %s from CRL %s"), $name, $thiscrl['descr']));
+ header("Location: system_crlmanager.php");
+ exit;
+ } else {
+ $savemsg = sprintf(gettext("Failed to delete Certificate %s from CRL %s"), $name, $thiscrl['descr']) . "
";
+ }
+ $act="edit";
+ } elseif ($act == "addcert") {
+ $input_errors = array();
+ if (!isset($id)) {
header("Location: system_crlmanager.php");
exit;
}
// certref, crlref
- $crl =& lookup_crl($pconfig['crlref']);
+ $crl =& lookup_crl($id);
$cert = lookup_cert($pconfig['certref']);
- if (!$crl['caref'] || !$cert['caref']) {
+ if (empty($crl['caref']) || empty($cert['caref'])) {
$input_errors[] = gettext("Both the Certificate and CRL must be specified.");
}
@@ -217,556 +217,486 @@ if ($act == "addcert") {
header("Location: system_crlmanager.php");
exit;
}
- }
-}
-
-if ($act == "delcert") {
- if (!is_array($thiscrl['cert'])) {
- header("Location: system_crlmanager.php");
- exit;
- }
- $found = false;
- foreach ($thiscrl['cert'] as $acert) {
- if ($acert['refid'] == $_GET['certref']) {
- $found = true;
- $thiscert = $acert;
- }
- }
- if (!$found) {
- header("Location: system_crlmanager.php");
- exit;
- }
- $name = $thiscert['descr'];
- if (cert_unrevoke($thiscert, $thiscrl)) {
- $savemsg = sprintf(gettext("Deleted Certificate %s from CRL %s"), $name, $thiscrl['descr']) . "
";
- openvpn_refresh_crls();
- write_config(sprintf(gettext("Deleted Certificate %s from CRL %s"), $name, $thiscrl['descr']));
} else {
- $savemsg = sprintf(gettext("Failed to delete Certificate %s from CRL %s"), $name, $thiscrl['descr']) . "
";
- }
- $act="edit";
-}
-
-if ($_POST) {
- unset($input_errors);
- $pconfig = $_POST;
-
- /* input validation */
- if (($pconfig['method'] == "existing") || ($act == "editimported")) {
- $reqdfields = explode(" ", "descr crltext");
- $reqdfieldsn = array(
- gettext("Descriptive name"),
- gettext("Certificate Revocation List data"));
- }
- if ($pconfig['method'] == "internal") {
- $reqdfields = explode(
- " ",
- "descr caref"
- );
- $reqdfieldsn = array(
- gettext("Descriptive name"),
- gettext("Certificate Authority"));
- }
-
- do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
-
- /* save modifications */
- if (!$input_errors) {
- $result = false;
-
- if (isset($thiscrl)) {
- $crl =& $thiscrl;
- } else {
- $crl = array();
- $crl['refid'] = uniqid();
- }
-
- $crl['descr'] = $pconfig['descr'];
- if ($act != "editimported") {
- $crl['caref'] = $pconfig['caref'];
- $crl['method'] = $pconfig['method'];
- }
-
- if (($pconfig['method'] == "existing") || ($act == "editimported")) {
- $crl['text'] = base64_encode($pconfig['crltext']);
- }
-
- if ($pconfig['method'] == "internal") {
- $crl['serial'] = empty($pconfig['serial']) ? 9999 : $pconfig['serial'];
- $crl['lifetime'] = empty($pconfig['lifetime']) ? 9999 : $pconfig['lifetime'];
- $crl['cert'] = array();
- }
-
- if (!isset($thiscrl)) {
- $a_crl[] = $crl;
- }
-
- write_config("Saved CRL {$crl['descr']}");
- openvpn_refresh_crls();
- header("Location: system_crlmanager.php");
+ $input_errors = array();
+ $pconfig = $_POST;
+
+ /* input validation */
+ if (($pconfig['crlmethod'] == "existing") || ($act == "editimported")) {
+ $reqdfields = explode(" ", "descr crltext");
+ $reqdfieldsn = array(
+ gettext("Descriptive name"),
+ gettext("Certificate Revocation List data"));
+ } elseif ($pconfig['crlmethod'] == "internal") {
+ $reqdfields = explode(
+ " ",
+ "descr caref"
+ );
+ $reqdfieldsn = array(
+ gettext("Descriptive name"),
+ gettext("Certificate Authority"));
+ }
+
+ do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
+
+ /* save modifications */
+ if (count($input_errors) == 0) {
+ if (isset($id)) {
+ $crl =& $thiscrl;
+ } else {
+ $crl = array();
+ $crl['refid'] = uniqid();
+ }
+
+ foreach (array("descr", "caref", "crlmethod") as $fieldname) {
+ if (isset($pconfig[$fieldname])) {
+ $crl[$fieldname] = $pconfig[$fieldname];
+ }
+ }
+
+ if (($pconfig['crlmethod'] == "existing") || ($act == "editimported")) {
+ $crl['text'] = base64_encode($pconfig['crltext']);
+ }
+
+ if ($pconfig['crlmethod'] == "internal") {
+ $crl['serial'] = empty($pconfig['serial']) ? 9999 : $pconfig['serial'];
+ $crl['lifetime'] = empty($pconfig['lifetime']) ? 9999 : $pconfig['lifetime'];
+ $crl['cert'] = array();
+ }
+
+ if (!isset($id)) {
+ $a_crl[] = $crl;
+ }
+
+ write_config("Saved CRL {$crl['descr']}");
+ openvpn_refresh_crls();
+ header("Location: system_crlmanager.php");
+ exit;
+ }
}
+
}
+legacy_html_escape_form_data($pconfig);
+legacy_html_escape_form_data($thiscrl);
include("head.inc");
?>
-
-
-
-
-
-
-
-
-
- 0) {
- print_input_errors($input_errors);
- }
- if (isset($savemsg)) {
- print_info_box($savemsg);
- }
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
+
-
-
-