From f9ee9d1ddfac13fa883cdeeb0bc11ab78cb2ca1d Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 24 Nov 2016 00:20:09 +0530 Subject: [PATCH] Refactor SSL requires div to use template Signed-off-by: Deven Bansod --- js/server_privileges.js | 4 +- libraries/server_privileges.lib.php | 236 +++++++----------- templates/privileges/require_options.phtml | 16 ++ .../privileges/require_options_item.phtml | 23 ++ 4 files changed, 137 insertions(+), 142 deletions(-) create mode 100644 templates/privileges/require_options.phtml create mode 100644 templates/privileges/require_options_item.phtml diff --git a/js/server_privileges.js b/js/server_privileges.js index 154f74770e..18c37875f2 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -392,7 +392,7 @@ AJAX.registerOnload('server_privileges.js', function () { $(document).on('change', 'input[name="ssl_type"]', function (e) { var $div = $('#specified_div'); - if ($('#ssl_type_specified').is(':checked')) { + if ($('#ssl_type_SPECIFIED').is(':checked')) { $div.find('input').prop('disabled', false); } else { $div.find('input').prop('disabled', true); @@ -403,7 +403,7 @@ AJAX.registerOnload('server_privileges.js', function () { var $div = $('#require_ssl_div'); if ($(this).is(':checked')) { $div.find('input').prop('disabled', false); - $('#ssl_type_specified').trigger('change'); + $('#ssl_type_SPECIFIED').trigger('change'); } else { $div.find('input').prop('disabled', true); } diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 5488f79770..80dbece16c 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -699,148 +699,104 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*', */ function PMA_getHtmlForRequires($row) { - $html_output = '
'; - $html_output .= 'SSL'; - - $html_output .= '
'; - - // REQUIRE NONE - $html_output .= '
'; - $html_output .= ''; - - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE SSL - $html_output .= '
'; - $html_output .= ''; - - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE X509 - $html_output .= '
'; - $html_output .= ''; - - $html_output .= ''; - $html_output .= '
'; - - // Specified $specified = (isset($row['ssl_type']) && $row['ssl_type'] == 'SPECIFIED'); - $html_output .= '
'; - $html_output .= ''; + $require_options = array( + array( + 'name' => 'ssl_type', + 'value' => 'NONE', + 'description' => __( + 'Does not require SSL-encrypted connections.' + ), + 'label' => 'REQUIRE NONE', + 'checked' => ((isset($row['ssl_type']) + && ($row['ssl_type'] == 'NONE' + || $row['ssl_type'] == '')) + ? 'checked="checked"' + : '' + ), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_type', + 'value' => 'ANY', + 'description' => __( + 'Requires SSL-encrypted connections.' + ), + 'label' => 'REQUIRE SSL', + 'checked' => (isset($row['ssl_type']) && ($row['ssl_type'] == 'ANY') + ? 'checked="checked"' + : '' + ), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_type', + 'value' => 'X509', + 'description' => __( + 'Requires a valid X509 certificate.' + ), + 'label' => 'REQUIRE SSL', + 'checked' => (isset($row['ssl_type']) && ($row['ssl_type'] == 'X509') + ? 'checked="checked"' + : '' + ), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_type', + 'value' => 'SPECIFIED', + 'description' => '', + 'label' => 'SPECIFIED', + 'checked' => ($specified ? 'checked="checked"' : ''), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_cipher', + 'value' => (isset($row['ssl_cipher']) + ? htmlspecialchars($row['ssl_cipher']) : '' + ), + 'description' => __( + 'Requires that a specific cipher method be used for a connection.' + ), + 'label' => 'REQUIRE CIPHER', + 'checked' => '', + 'disabled' => ! $specified, + 'radio' => false + ), + array( + 'name' => 'x509_issuer', + 'value' => (isset($row['x509_issuer']) + ? htmlspecialchars($row['x509_issuer']) : '' + ), + 'description' => __( + 'Requires that a valid X509 certificate issued by this CA be presented.' + ), + 'label' => 'REQUIRE ISSUER', + 'checked' => '', + 'disabled' => ! $specified, + 'radio' => false + ), + array( + 'name' => 'x509_subject', + 'value' => (isset($row['x509_subject']) + ? htmlspecialchars($row['x509_subject']) : '' + ), + 'description' => __( + 'Requires that a valid X509 certificate with this subject be presented.' + ), + 'label' => 'REQUIRE SUBJECT', + 'checked' => '', + 'disabled' => ! $specified, + 'radio' => false + ), + ); - $html_output .= ''; - $html_output .= '
'; - - $html_output .= '
'; - - // REQUIRE CIPHER - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE ISSUER - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE SUBJECT - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - - $html_output .= '
'; - - $html_output .= '
'; - $html_output .= '
'; + $html_output = Template::get('privileges/require_options') + ->render(array('require_options' => $require_options)); return $html_output; } diff --git a/templates/privileges/require_options.phtml b/templates/privileges/require_options.phtml new file mode 100644 index 0000000000..6261786246 --- /dev/null +++ b/templates/privileges/require_options.phtml @@ -0,0 +1,16 @@ +
+ SSL +
+ + +
+ + render( + array('require_option' => $require_option) + ); + ?> + +
+
+
\ No newline at end of file diff --git a/templates/privileges/require_options_item.phtml b/templates/privileges/require_options_item.phtml new file mode 100644 index 0000000000..867fea919e --- /dev/null +++ b/templates/privileges/require_options_item.phtml @@ -0,0 +1,23 @@ +
+ + + /> + + + + + disabled + + /> + +
\ No newline at end of file