From 9386a0191bdad7c2d904b477602ee0953bbb9974 Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Tue, 10 Jun 2014 00:29:46 -0400 Subject: [PATCH] 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 --- web/add/db/index.php | 24 ++++++++++++++++++++ web/templates/admin/add_db.html | 39 +++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/web/add/db/index.php b/web/add/db/index.php index a4c1e543e..f2ba11df1 100644 --- a/web/add/db/index.php +++ b/web/add/db/index.php @@ -51,6 +51,30 @@ if (!empty($_POST['ok'])) { $v_host = $_POST['v_host']; $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 if (empty($_SESSION['error_msg'])) { $pw_len = strlen($_POST['v_password']); diff --git a/web/templates/admin/add_db.html b/web/templates/admin/add_db.html index 438824ab3..933b10c12 100644 --- a/web/templates/admin/add_db.html +++ b/web/templates/admin/add_db.html @@ -5,7 +5,7 @@ } else { $back = "location.href='".$back."'"; } - ?> + ?> @@ -60,23 +60,38 @@ - + - + + - + - + @@ -92,7 +107,7 @@ - + @@ -104,13 +119,13 @@ if ((!empty($v_type)) && ( $value == $v_type )) echo ' selected'; echo ">".$value.""; } - ?> + ?> - + @@ -122,14 +137,14 @@ if ((!empty($v_host)) && ( $key == $v_host )) echo ' selected'; echo ">".$key.""; } - ?> + ?> - + @@ -175,7 +190,7 @@ - +