Browse Source

Added a way to update the access rights without reassigning. Improved tasklist

DieFeM 7 years ago
parent
commit
e22ff7026c

+ 30 - 0
includes/database_mysqli.php

@@ -2366,6 +2366,36 @@ class OGPDatabaseMySQL extends OGPDatabase
 
 		return TRUE;
 	}
+	
+	public function updateAccessRightsFor($id_type,$assign_id,$home_id,$access_rights)
+	{
+		if ( $id_type == "user" )
+		{
+			$template = "UPDATE `%suser_homes` SET `access_rights` = '%s' WHERE `user_id` = %d AND home_id = %d";	
+		}
+		else if ( $id_type == "group")
+		{
+			$template = "UPDATE `%suser_group_homes` SET `access_rights` = '%s' WHERE `group_id` = %d AND home_id = %d";
+		}
+		else
+		{
+			return FALSE;
+		}
+
+		$query = sprintf($template,
+			$this->table_prefix,
+			$this->realEscapeSingle($access_rights),
+			$this->realEscapeSingle($assign_id),
+			$this->realEscapeSingle($home_id));
+
+		++$this->queries_;
+		mysqli_query($this->link,$query);
+
+		if ( mysqli_affected_rows($this->link) != 1 )
+			return FALSE;
+
+		return TRUE;
+	}
 
 	public function unassignHomeFrom($id_type, $assign_id, $home_id)
 	{

+ 56 - 0
js/modules/user_games-assign.js

@@ -0,0 +1,56 @@
+function change_access_rights(id_type, assign_id)
+{
+	var rights = $("#dialog").data();
+	var home_ids = [];
+		
+	$(".change_access_rights:checked").each( function( index, element ){
+		home_ids[index] = $(element).data("home_id");
+	});
+	
+	var check_access_rights = '<table>';
+	
+	$.each(rights, function( index, value ) {
+		if(index == 'uiDialog')
+		{
+			return true;
+		}
+		check_access_rights += "<tr><td align='right'><label for='" + value + "'>" + langConsts['OGP_LANG_' + value] + ":</label></td>" +
+							   "<td align='left'><input class='ar_flag' id='" + value + "' type='checkbox' name='" + value + "' value='" + index + "' checked='checked' /></td></tr>" +
+							   "<tr><td colspan='2' class='info'>" + langConsts['OGP_LANG_' + value + '_info'] + "</td></tr>";
+	});
+	
+	check_access_rights += '</table>';
+	
+	var addpost = {};
+	addpost[ 'home_ids' ] = home_ids;
+	addpost[ 'assign_id' ] = assign_id;
+	addpost[ 'id_type' ] = id_type;
+	addpost[ 'change_access_rights' ] = 'true';
+	addpost.flags = [];
+	var destURL = "home.php?m=user_games&p=assign&" + id_type + "_id=" + assign_id + "&type=cleared";
+	$('#dialog').html(check_access_rights);
+	$('#dialog').dialog({
+		autoOpen: true,
+		width: 450,
+		modal: true,
+		buttons: [{ text: "Set Access Rights", click: function(){
+				$('input[class="ar_flag"]:checked').each(function(){
+					var flag = $(this).val();
+					addpost.flags.push(flag);
+				});
+				$.ajax({
+						type: "POST",
+						url: destURL,
+						data: addpost,
+						success: function(data){
+							location.reload(true);
+						}
+				});
+				$( this ).dialog( "close" );
+			}
+		}],
+		close: function() {
+			$( this ).dialog( "close" );
+		}
+	});
+}

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

@@ -219,4 +219,5 @@ define('OGP_LANG_search', "Search");
 define('OGP_LANG_ftp_account_username_too_long', "FTP username is too long. Try a shorter username no longer than 20 characters.");
 define('OGP_LANG_ftp_account_password_too_long', "FTP password is too long. Try a shorter password no longer than 20 characters.");
 define('OGP_LANG_other_servers_exist_with_path_please_change', "Other homes exist with the same path. It is recommended (but not required) that you change this path to something unique. You may have problems if you do NOT.");
- ?>
+define('OGP_LANG_change_access_rights_for_selected_servers', "Change access rights for selected servers");
+?>

+ 1 - 1
modules/status/include/task.php

@@ -39,7 +39,7 @@ if( isset($_GET['remote_server_id']) && $_GET['remote_server_id'] != "webhost")
 	}else{
 		if($os == "linux"){
 			$taskoutput = array();
-			$taskoutput["task"] = shell_exec ("ps aux");
+			$taskoutput["task"] = shell_exec ('ps -p $(ps --no-headers -a -o tty,pid|grep ^[^?] | awk -vORS=, \'{ print $2 }\' | sed \'s/,$/\n/\') -o comm,etime,%cpu,%mem,args');
 		}
 	}
 }

+ 39 - 5
modules/user_games/assign_home.php

@@ -1,3 +1,4 @@
+<script type="text/javascript" src="js/modules/user_games-assign.js"></script>
 <?php
 /*
  *
@@ -37,7 +38,7 @@ function exec_ogp_module()
 	global $db;
 	
 	$isAdmin = $db->isAdmin($_SESSION['user_id']);
-	
+		
 	if(isset($_REQUEST['user_id'])){
 		if(empty($_REQUEST['user_id']) || $db->getUserById($_REQUEST['user_id']) == null)
 		{
@@ -87,6 +88,34 @@ function exec_ogp_module()
 		$full_access .= $ar['flag'];
 	}
 	
+	if(isset($_POST['change_access_rights']))
+	{		
+		if(is_array($_POST['home_ids']))
+		{
+			if($isAdmin)
+				$access_right_flags = implode('',$_POST['flags']);
+			
+			foreach($_POST['home_ids'] as $i => $home_id)
+			{
+				if(!$isAdmin)
+				{
+					$home_info = $db->getUserGameHome($_SESSION['user_id'],$home_id);
+					$access_rights = $home_info['access_rights'];
+					$flags = $_POST['flags'];
+					foreach($flags as $i => $flag)
+					{
+						if(!strstr($access_rights, $flag))
+							unset($flags[$i]);
+					}
+					$access_right_flags = implode('',$flags);
+				}
+				if(!$db->updateAccessRightsFor($_POST['id_type'],$_POST['assign_id'],$home_id,$access_right_flags))
+					print_failure(get_lang_f("failed_to_assign_game_for_",$id_type,$db->getError()));
+			}
+		}
+		return;
+	}
+	
 	if ( isset($_REQUEST['user_id']) )
 	{
 		$assign_id = $_REQUEST['user_id'];
@@ -233,8 +262,7 @@ function exec_ogp_module()
 	else
 	{
 		echo "<h2>".get_lang("no_more_homes_available_that_can_be_assigned_for_this_$id_type")."</h2>";
-		//print_lang('you_can_add_a_new_game_server_from');
-		//echo "<a href='?m=user_games'>".game_servers."</a>.</p>";
+		
 		if( $isAdmin )
 			echo get_lang_f("you_can_add_a_new_game_server_from","<a href='?m=user_games'>".get_lang("game_servers")."</a>")."</p>";
 	}
@@ -260,7 +288,7 @@ function exec_ogp_module()
 			$access_rights = empty($row['access_rights']) ? "-" : $row['access_rights'];
 			$type = $id_type == "group" ? "user_group_expiration_date" : "user_expiration_date";
 			$expiration = $row[$type] == "X" ? "X" : date('d/m/Y H:i:s', $row[$type]);
-			echo "<tr><td>$row[home_id]</td>
+			echo "<tr><td><input type=checkbox class='change_access_rights' data-home_id='$row[home_id]' >$row[home_id]</td>
 				<td>".$row['agent_ip']." (Agent)</td>
 				<td>$row[game_name]</td>
 				<td>$row[home_path]</td>
@@ -275,7 +303,13 @@ function exec_ogp_module()
 				</tr>";
 		}
 		echo "</table>";
-
+		echo "<button onclick=\"change_access_rights('".trim($id_type)."', '".trim($assign_id),"')\">".get_lang('change_access_rights_for_selected_servers')."</button>\n".
+			 "<div id='dialog' ";
+		foreach ( $selections as $selection => $flag)
+		{
+			echo "data-$flag=\"$selection\" ";
+		}
+		echo "></div>";
 	}
 
 	if ( $id_type === "group" )