Explorar el Código

Show API Links Initial

own3mall hace 7 años
padre
commit
45d7ee5593
Se han modificado 3 ficheros con 63 adiciones y 19 borrados
  1. 51 13
      js/global.js
  2. 3 1
      lang/English/modules/gamemanager.php
  3. 9 5
      modules/gamemanager/monitor_buttons.php

+ 51 - 13
js/global.js

@@ -9,8 +9,8 @@ function wireClicks(){
 		handleVersionClick();
 	});
 	
-	$(".getAutoUpdateLink").click(function(e){
-		showSteamUpdateLink($(this));
+	$(".getAPILinks").click(function(e){
+		showAPILinks($(this));
 	});
 	
 	$(".serverIdToggle").click(function(e){
@@ -46,21 +46,59 @@ function animateProgressBars(){
 	});
 }
 
-function showSteamUpdateLink(elem){
+function showAPILinks(elem){
 	$("div.mangificWrapper .magnificTitle").text($(elem).attr('autoupdatetext'));
-	$("div.mangificWrapper .magnificContentsDiv").html('<p>' + $(elem).attr('autoupdatehtml') + '</p><p><input class="updateLink" style="width: 75%;" type="text" value="' + $(elem).attr('autoupdatelink') + '"><button class="copyButton">' + $(elem).attr('copyme') + '</button>&nbsp; <span class="copyStatus"></span></p>');
+	
+	var apiToken = elem.attr('token');
+	var ipAddr = elem.attr('ip');
+	var port = elem.attr('port');
+	var modKey = elem.attr('modkey');
+	var panelURL = elem.attr('panelurl');
+	
+	if(apiToken && ipAddr && port && modKey && panelURL){
 		
-	showPopup(function(){
-		$("input.updateLink").click(function(e){
-			$(this).select();
-		});
+		var actions = new Array(
+			{url: 'ogp_api.php?gamemanager/start', lang: 'start_server'}, 
+			{url: 'ogp_api.php?gamemanager/stop', lang: 'stop_server'},
+			{url: 'ogp_api.php?gamemanager/restart', lang: 'restart_server'},
+			{url: 'ogp_api.php?gamemanager/rcon', lang: 'rcon_command_title', additional: '&command={YOUR_RCON_COMMAND}'}
+		); 
+		
+		var isSteam = elem.attr('hassteam');
+		if(isSteam && isSteam === 'true'){
+			actions.push({url: 'ogp_api.php?gamemanager/update', lang: 'get_steam_autoupdate_api_link', additional: '&type=steam', selected: true});
+		}
 		
-		$(".copyButton").click(function(e){
+		var selectListHTML = '<select class="ogpAPIActions">';
+		for(var i = 0; i < actions.length; i++){
+			selectListHTML += '<option value="' + actions[i]["url"] + '" ' + (actions[i].hasOwnProperty('additional') && actions[i].additional ? 'additional="' + actions[i].additional + '"' : '') + ' ' + (actions[i].hasOwnProperty('selected') && actions[i]["selected"] && actions[i]["selected"] == true ? 'selected' : '') + '>' + getLang(actions[i]["lang"]) + '</option>'; 
+		}
+		selectListHTML += '</select>';
+	
+		$("div.mangificWrapper .magnificContentsDiv").html(getLang('api_links_popup_html') + '<p>' + getLang('actions') +':&nbsp; ' + selectListHTML + '</p><p><input class="updateLink" style="width: 75%;" type="text" value="' + $(elem).attr('autoupdatelink') + '"><button class="copyButton">' + $(elem).attr('copyme') + '</button>&nbsp; <span class="copyStatus"></span></p>');
+			
+		showPopup(function(){
+			$(".ogpAPIActions", elem).change(function(e){
+				var newActionValue = $(this).val();
+				var apiURL = panelURL + '/' + newActionValue + '&token=' + apiToken + '&ip=' + ipAddr + '&port=' + port + '&mod_key=' + modKey;
+				var additionalParamsToAdd = $(this).attr('additional');
+				if(additionalParamsToAdd){
+					apiURL += additionalParamsToAdd;
+				}
+				$("input.updateLink", elem).val(apiURL);
+			});
+			
+			$("input.updateLink", elem).click(function(e){
+				$(this).select();
+			});
+			
+			$(".copyButton", elem).click(function(e){
+				copyInput($("input.updateLink"), $("span.copyStatus"), elem);
+			});
+			
 			copyInput($("input.updateLink"), $("span.copyStatus"), elem);
 		});
-		
-		copyInput($("input.updateLink"), $("span.copyStatus"), elem);
-	});
+	}
 }
 
 function copyInput(input, resultArea, elemWithAttr){
@@ -180,7 +218,7 @@ function toggleEvents(){
 		cssDesc: "headerSortDown",
 		cssChildRow: "expand-child",
 		sortInitialOrder: "asc",
-		sortMultiSortKey: "shiftKey",
+		sortMultiSortKey: "shiftKey"
 	});
 }
 

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

@@ -188,10 +188,12 @@ define('OGP_LANG_no_online_players', "There are no online players.");
 define('OGP_LANG_invalid_game_mod_id', "Invalid Game/Mod ID specified.");
 define('OGP_LANG_auto_update_title_popup', "Steam Auto Update Link");
 define('OGP_LANG_auto_update_popup_html', "<p>Use the link below to check and automatically update your game server via Steam if needed.&nbsp; You can query it using a cronjob or manually initiate the process.</p>");
+define('OGP_LANG_api_links_popup_html', "<p>Select an action you would like to perform using the OGP API for this game server.&nbsp; Then, use the link below to perform your desired action.&nbsp; You can run your desired action using a cronjob or making a direct request to it.</p>");
 define('OGP_LANG_auto_update_copy_me', "Copy");
 define('OGP_LANG_auto_update_copy_me_success', "Copied!");
 define('OGP_LANG_auto_update_copy_me_fail', "Failed to copy. Please, manually copy the link.");
 define('OGP_LANG_get_steam_autoupdate_api_link', "Auto Update Link");
+define('OGP_LANG_show_api_actions', "Show API Actions");
 define('OGP_LANG_update_attempt_from_nonmaster_server', "User %s attempted to update home_id %d from a non-master server. (Home ID: %d)");
 define('OGP_LANG_attempting_nonmaster_update', "You are attempting to update this server from a non-master server.");
 define('OGP_LANG_cannot_update_from_own_self', "Local server update may not run on a Master server.");
@@ -204,4 +206,4 @@ define('OGP_LANG_phan', "Phantom");
 define('OGP_LANG_sec', "Seconds");
 define('OGP_LANG_unknown_rsync_mirror', "You attempted to start an update from a mirror which doesn't exist.");
 define('OGP_LANG_custom_fields', "Custom Fields");
-?>
+?>

+ 9 - 5
modules/gamemanager/monitor_buttons.php

@@ -36,6 +36,7 @@ $module_buttons = array(
 
 if (preg_match("/u/",$server_home['access_rights']))
 {
+	$hasSteamAutoUpdate = false;
 	$master_server_home_id = $db->getMasterServer( $server_home['remote_server_id'], $server_home['home_cfg_id'] );
 	if ( $master_server_home_id != FALSE )
 	{
@@ -60,10 +61,8 @@ if (preg_match("/u/",$server_home['access_rights']))
 			<img src='" . check_theme_image("images/steam.png") ."' title='". get_lang("install_update_steam") ."'>
 			<span>". get_lang("install_update_steam") ."</span>
 		</a>";
-		$module_buttons[] = "<a class='monitorbutton getAutoUpdateLink' copyfail='" . get_lang("auto_update_copy_me_fail") . "' copysuccess='" . get_lang("auto_update_copy_me_success") . "' autoupdatetext='" . get_lang("auto_update_title_popup") . "' autoupdatehtml='" . htmlentities(get_lang("auto_update_popup_html")) . "' copyme='" . get_lang("auto_update_copy_me") . "' autoupdatelink='" . getOGPSiteURL() . "/ogp_api.php?gamemanager/update&token=".$db->getApiToken($_SESSION['user_id'])."&ip=".$server_home['ip']."&port=".$server_home['port']."&mod_key=".$server_home['mod_key']."&type=steam'>
-			<img src='" . check_theme_image("images/auto_update.png") . "' title='". get_lang("get_steam_autoupdate_api_link") . "'>
-			<span>". get_lang("get_steam_autoupdate_api_link") . "</span>
-		</a>";
+		
+		$hasSteamAutoUpdate = true;
 	}
 	// In other cases manual update is provided.
 	else
@@ -83,6 +82,11 @@ if (preg_match("/u/",$server_home['access_rights']))
 			</a>";
 		}
 	}
+	
+	$module_buttons[] = "<a class='monitorbutton getAPILinks' hassteam='" . ($hasSteamAutoUpdate ? 'true' : 'false') . "' copyfail='" . get_lang("auto_update_copy_me_fail") . "' copysuccess='" . get_lang("auto_update_copy_me_success") . "' autoupdatetext='" . get_lang("auto_update_title_popup") . "' copyme='" . get_lang("auto_update_copy_me") . "' token='".$db->getApiToken($_SESSION['user_id'])."' ip='".$server_home['ip']."' port='".$server_home['port']."' modkey='".$server_home['mod_key']."' panelurl='" . getOGPSiteURL() . "'>
+		<img src='" . check_theme_image("images/auto_update.png") . "' title='". get_lang("show_api_actions") . "'>
+		<span>". get_lang("show_api_actions") . "</span>
+		</a>";
 }
 
 
@@ -97,4 +101,4 @@ if($_SESSION['users_role'] == "admin")
 		</a>";
 	}
 }
-?>
+?>