Browse Source

Length Validation

own3mall 8 years ago
parent
commit
97331460c5

+ 3 - 1
lang/English/modules/ftp.php

@@ -31,4 +31,6 @@ define('full_path', "Home directory");
 define('add_ftp_account', "Add FTP account");
 define('remote_server', "Remote server");
 define('server_name', "Server name");
-?>
+define('ftp_account_username_too_long', "FTP username is too long. Try a shorter username no longer than 20 characters.");
+define('ftp_account_password_too_long', "FTP password is too long. Try a shorter password no longer than 20 characters.");
+?>

+ 3 - 1
lang/English/modules/user_games.php

@@ -217,4 +217,6 @@ define('cpu_affinity_info', "Select the CPU core(s) you want to assign to the ga
 define('expiration_date_changed', "Expiration date for selected home has been changed.");
 define('expiration_date_could_not_be_changed', "Expiration date for selected home could not be changed.");
 define('search', "Search");
-?>
+define('ftp_account_username_too_long', "FTP username is too long. Try a shorter username no longer than 20 characters.");
+define('ftp_account_password_too_long', "FTP password is too long. Try a shorter password no longer than 20 characters.");
+?>

+ 17 - 2
modules/ftp/ftp_admin.php

@@ -32,12 +32,25 @@ function exec_ogp_module()
 	
 	if(isset($_POST['add_ftp_user']))
 	{
+		$success = true;
 		$server_row = $db->getRemoteServer($_POST['remote_server_id']);
 		$remote = new OGPRemoteLibrary($server_row['agent_ip'],$server_row['agent_port'],$server_row['encryption_key'],$server_row['timeout']);
-		$post_ftp_login = strip_real_escape_string($_POST['ftp_login']);
+		$post_ftp_login = strip_real_escape_string($_POST['ftp_login']);		
 		$post_ftp_password = strip_real_escape_string($_POST['ftp_password']);
 		$post_full_path = strip_real_escape_string($_POST['full_path']);
 		$host_stat = $remote->status_chk();
+		
+		// Validation
+		if(strlen($post_ftp_login) > 20){
+			print_failure( ftp_account_username_too_long );
+			$success = false;
+		}
+		
+		if(strlen($post_ftp_password) > 20){
+			print_failure( ftp_account_password_too_long );
+			$success = false;
+		}
+		
 		$ftp_accounts_list = $remote->ftp_mgr("list");
 		$ftp_accounts = explode("\n",$ftp_accounts_list);
 		$user_exists = FALSE;
@@ -54,13 +67,15 @@ function exec_ogp_module()
 				}
 			}
 		}
+		
 		if( $user_exists === TRUE )
 		{
 			print_failure( ftp_account_already_exists );
 		}
 		else
 		{
-			$remote->ftp_mgr("useradd", $post_ftp_login, $post_ftp_password, $post_full_path);
+			if($success)
+				$remote->ftp_mgr("useradd", $post_ftp_login, $post_ftp_password, $post_full_path);
 		}
 	}
 

+ 33 - 9
modules/user_games/edit_home.php

@@ -127,12 +127,19 @@ function exec_ogp_module()
 					return;
 				}
 				
+				// Validation
+				
 				// Is the same user old and new?
 				if($old_login == $post_ftp_login)
 				{
 					echo json_encode(array('result' => 'success', 'info' => ''));
 					return;
 				}
+				
+				if(strlen($post_ftp_login) > 20){
+					echo json_encode(array('result' => 'failure', 'info' => ftp_account_username_too_long));
+					return;
+				}
 					
 				$host_stat = $remote->status_chk();
 				$user_exists = FALSE;
@@ -215,6 +222,8 @@ function exec_ogp_module()
 					return;
 				}
 				
+				// Validation
+				
 				// Is the same password old and new?
 				if($home_info['ftp_password'] == $ftp_password)
 				{
@@ -222,6 +231,11 @@ function exec_ogp_module()
 					return;
 				}
 				
+				if(strlen($ftp_password) > 20){
+					echo json_encode(array('result' => 'failure', 'info' => ftp_account_password_too_long));
+					return;
+				}
+				
 				$host_stat = $remote->status_chk();
 				$current_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
 				$login_exists = FALSE;
@@ -308,17 +322,27 @@ function exec_ogp_module()
 		if( isset( $_REQUEST['create_ftp']) )
 		{
 			$login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
-			if ($remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_info['home_path']) === 0)
-			{
-				$result = error_ocurred_on_remote_server ." ". ftp_can_not_be_switched_on;
+			
+			$success = true;
+			if(strlen($login) > 20){
+				$result = ftp_account_username_too_long;
 				$type = "failure";
+				$success = false;
 			}
-			else
-			{
-				$db->changeFtpStatus('enabled',$home_id);
-				$result = successfully_changed_game_server;
-				$type = "success";
-				$db->logger( successfully_changed_game_server ." HOME ID:$home_id - ". change_ftp_account_status .":enabled");
+			
+			if($success){
+				if ($remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_info['home_path']) === 0)
+				{
+					$result = error_ocurred_on_remote_server ." ". ftp_can_not_be_switched_on;
+					$type = "failure";
+				}
+				else
+				{
+					$db->changeFtpStatus('enabled',$home_id);
+					$result = successfully_changed_game_server;
+					$type = "success";
+					$db->logger( successfully_changed_game_server ." HOME ID:$home_id - ". change_ftp_account_status .":enabled");
+				}
 			}
 		}
 		else if( isset( $_REQUEST['delete_ftp']) )