Added user & db length limit according to db type

MySQL: 16 characers
PostgreSQL: 63 characters

Alerts the user in the event their user or database is too long
This commit is contained in:
Stuart Olivera 2014-06-10 00:29:46 -04:00
commit 9386a0191b
2 changed files with 51 additions and 12 deletions

View file

@ -51,6 +51,30 @@ if (!empty($_POST['ok'])) {
$v_host = $_POST['v_host']; $v_host = $_POST['v_host'];
$v_db_email = $_POST['v_db_email']; $v_db_email = $_POST['v_db_email'];
// Check database length
if (empty($_SESSION['error_msg'])) {
$db_len = strlen($user."_".$_POST['v_database']);
if ($_POST['v_type'] == 'pgsql')
$db_maxlen = 63;
elseif ($_POST['v_type'] == 'mysql')
$db_maxlen = 64;
else
$db_maxlen = true; // Allow any length by default
if ($db_len > $db_maxlen) $_SESSION['error_msg'] = __('Database is too long.',$error_msg);
}
// Check user length
if (empty($_SESSION['error_msg'])) {
$dbusr_len = strlen($user."_".$_POST['v_dbuser']);
if ($_POST['v_type'] == 'mysql')
$dbuser_maxlen = 16;
elseif ($_POST['v_type'] == 'pgsql')
$dbuser_maxlen = 63;
else
$dbuser_maxlen = true; // Allow any length by default
if ($dbusr_len > $dbuser_maxlen ) $_SESSION['error_msg'] = __('User is too long.',$error_msg);
}
// Check password length // Check password length
if (empty($_SESSION['error_msg'])) { if (empty($_SESSION['error_msg'])) {
$pw_len = strlen($_POST['v_password']); $pw_len = strlen($_POST['v_password']);

View file

@ -65,7 +65,15 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="text" size="20" class="vst-input" name="v_database" <?php if (!empty($v_database)) echo "value=".$v_database; ?>> <?php
exec (VESTA_CMD."v-list-database-types", $output);
if (strpos($output, "postgresql") !== false)
$database_maxlength = 63 - strlen($user."_");
elseif (strpos($output, "mysql") !== false)
$database_maxlength = 64 - strlen($user."_");
?>
<?php $database_maxlength = 64 - strlen($user."_"); ?>
<input type="text" size="20" class="vst-input" name="v_database" <?php if (!empty($database_maxlength)) echo "maxlength=".$database_maxlength; if (!empty($v_database)) echo "value=".$v_database; ?>>
<small class="hint"></small> <small class="hint"></small>
</td> </td>
</tr> </tr>
@ -76,7 +84,14 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="text" size="20" class="vst-input" name="v_dbuser" <?php if (!empty($v_dbuser)) echo "value=".$v_dbuser; ?>> <?php
exec (VESTA_CMD."v-list-database-types", $output);
if (strpos($output, "mysql") !== false)
$dbuser_maxlength = 16 - strlen($user."_");
elseif (strpos($output, "postgresql") !== false)
$dbuser_maxlength = 63 - strlen($user."_");
?>
<input type="text" size="20" class="vst-input" name="v_dbuser" <?php if (!empty($dbuser_maxlength)) echo "maxlength=".$dbuser_maxlength; if (!empty($v_dbuser)) echo "value=".$v_dbuser; ?>>
<small class="hint"></small> <small class="hint"></small>
</td> </td>
</tr> </tr>