Refactor SSL requires div to use template

Signed-off-by: Deven Bansod <devenbansod.bits@gmail.com>
This commit is contained in:
Deven Bansod 2016-11-24 00:20:09 +05:30
parent 8b7171c969
commit f9ee9d1ddf
4 changed files with 137 additions and 142 deletions

View File

@ -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);
}

View File

@ -699,148 +699,104 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*',
*/
function PMA_getHtmlForRequires($row)
{
$html_output = '<fieldset>';
$html_output .= '<legend>SSL</legend>';
$html_output .= '<div id="require_ssl_div">';
// REQUIRE NONE
$html_output .= '<div class="item">';
$html_output .= '<input type="radio" name="ssl_type" id="ssl_type_NONE"'
. ' value="NONE" title="'
. __(
'Does not require SSL-encrypted connections.'
)
. '"'
. ((isset($row['ssl_type'])
&& ($row['ssl_type'] == 'NONE'
|| $row['ssl_type'] == ''))
? ' checked="checked"'
: ''
)
. '/>';
$html_output .= '<label for="ssl_type_NONE"><code>'
. 'REQUIRE NONE'
. '</code></label>';
$html_output .= '</div>';
// REQUIRE SSL
$html_output .= '<div class="item">';
$html_output .= '<input type="radio" name="ssl_type" id="ssl_type_ANY"'
. ' value="ANY" title="'
. __(
'Requires SSL-encrypted connections.'
)
. '"'
. ((isset($row['ssl_type'])
&& $row['ssl_type'] == 'ANY')
? ' checked="checked"'
: ''
)
. '/>';
$html_output .= '<label for="ssl_type_ANY"><code>'
. 'REQUIRE SSL'
. '</code></label>';
$html_output .= '</div>';
// REQUIRE X509
$html_output .= '<div class="item">';
$html_output .= '<input type="radio" name="ssl_type" id="ssl_type_X509"'
. ' value="X509" title="'
. __(
'Requires a valid X509 certificate.'
)
. '"'
. ((isset($row['ssl_type']) && $row['ssl_type'] == 'X509')
? ' checked="checked"'
: ''
)
. '/>';
$html_output .= '<label for="ssl_type_X509"><code>'
. 'REQUIRE X509'
. '</code></label>';
$html_output .= '</div>';
// Specified
$specified = (isset($row['ssl_type']) && $row['ssl_type'] == 'SPECIFIED');
$html_output .= '<div class="item">';
$html_output .= '<input type="radio" name="ssl_type" id="ssl_type_specified"'
. ' value="SPECIFIED"' . ($specified ? ' checked="checked"' : '') . '/>';
$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 .= '<label for="ssl_type_specified"><code>'
. 'SPECIFIED'
. '</code></label>';
$html_output .= '</div>';
$html_output .= '<div id="specified_div" style="padding-left:20px;">';
// REQUIRE CIPHER
$html_output .= '<div class="item">';
$html_output .= '<label for="text_ssl_cipher">'
. '<code><dfn title="'
. __(
'Requires that a specific cipher method be used for a connection.'
)
. '">'
. 'REQUIRE CIPHER'
. '</dfn></code></label>';
$html_output .= '<input type="text" name="ssl_cipher" id="text_ssl_cipher" '
. 'value="' . (isset($row['ssl_cipher']) ? htmlspecialchars($row['ssl_cipher']) : '') . '" '
. 'size=80" title="'
. __(
'Requires that a specific cipher method be used for a connection.'
) . '"'
. (! $specified ? ' disabled' : '')
. ' />';
$html_output .= '</div>';
// REQUIRE ISSUER
$html_output .= '<div class="item">';
$html_output .= '<label for="text_x509_issuer">'
. '<code><dfn title="'
. __(
'Requires that a valid X509 certificate issued by this CA be presented.'
)
. '">'
. 'REQUIRE ISSUER'
. '</dfn></code></label>';
$html_output .= '<input type="text" name="x509_issuer" id="text_x509_issuer" '
. 'value="' . (isset($row['x509_issuer']) ? htmlspecialchars($row['x509_issuer']) : '') . '" '
. 'size=80" title="'
. __(
'Requires that a valid X509 certificate issued by this CA be presented.'
) . '"'
. (! $specified ? ' disabled' : '')
. ' />';
$html_output .= '</div>';
// REQUIRE SUBJECT
$html_output .= '<div class="item">';
$html_output .= '<label for="text_x509_subject">'
. '<code><dfn title="'
. __(
'Requires that a valid X509 certificate with this subject be presented.'
)
. '">'
. 'REQUIRE SUBJECT'
. '</dfn></code></label>';
$html_output .= '<input type="text" name="x509_subject" id="text_x509_subject" '
. 'value="' . (isset($row['x509_subject']) ? htmlspecialchars($row['x509_subject']) : '')
. '" size=80" title="'
. __(
'Requires that a valid X509 certificate with this subject be presented.'
) . '"'
. (! $specified ? ' disabled' : '')
. ' />';
$html_output .= '</div>';
$html_output .= '</div>';
$html_output .= '</div>';
$html_output .= '</fieldset>';
$html_output = Template::get('privileges/require_options')
->render(array('require_options' => $require_options));
return $html_output;
}

View File

@ -0,0 +1,16 @@
<fieldset>
<legend>SSL</legend>
<div id="require_ssl_div">
<?php foreach ($require_options as $require_option) : ?>
<?php if ($require_option['name'] === 'ssl_cipher') : ?>
<div id="specified_div" style="padding-left:20px;">
<?php endif; ?>
<?=
PMA\libraries\Template::get('privileges/require_options_item')->render(
array('require_option' => $require_option)
);
?>
<?php endforeach; ?>
</div> <!-- END specified_div -->
</div> <!-- END require_ssl_div -->
</fieldset>

View File

@ -0,0 +1,23 @@
<div class="item">
<?php if ($require_option['radio']) : ?>
<input type="radio" name="ssl_type"
id="<?= $require_option['name'] . '_' . $require_option['value'] ?>"
title="<?= $require_option['description'] ?>"
value="<?= $require_option['value'] ?>" <?= $require_option['checked']?>
/>
<label for="<?= $require_option['name'] . '_' . $require_option['value'] ?>">
<code><?= $require_option['label'] ?></code>
</label>
<?php else : ?>
<label for="text_<?= $require_option['name'] ?>">
<code><?= $require_option['label'] ?></code>
</label>
<input type="text" name="<?= $require_option['name'] ?>"
id="text_<?= $require_option['name'] ?>" value="<?= $require_option['value'] ?>"
size="80" title="<?= $require_option['description'] ?>"
<?php if ($require_option['disabled']) : ?>
disabled
<?php endif; ?>
/>
<?php endif; ?>
</div>