Forráskód Böngészése

Merge pull request #6 from OpenGamePanel/master

Update repo
rocco27 7 éve
szülő
commit
70ad62cfdb

+ 0 - 19
js/modules/cron.js

@@ -1,19 +0,0 @@
-$(document).ready(function(){
-    $("select[name='homeid_ip_port']").change(function(e){
-		checkSteamSupportAutoUpdate($(this));
-	});
-	
-	checkSteamSupportAutoUpdate($("select[name='homeid_ip_port']").first());
-});
-
-function checkSteamSupportAutoUpdate(elem){
-	var curOpt = $("option:selected", $(elem));
-	if(curOpt.attr('steam')){
-		$("option[value='steam_auto_update']", $("select[name='action']", $(elem).parent().prev())).removeAttr('disabled');
-	}else{
-		$("option[value='steam_auto_update']", $("select[name='action']", $(elem).parent().prev())).attr('disabled','disabled');
-		if($("option[value='steam_auto_update']", $("select[name='action']", $(elem).parent().prev())).is(':selected')){
-			$("select[name='action'] option:enabled:first", $(elem).parent().prev()).prop('selected', 'selected').change();
-		}
-	}
-}

+ 0 - 0
js/new file


+ 2 - 2
lang/Russian/modules/cron.php

@@ -41,8 +41,8 @@ define('OGP_LANG_scheduled_jobs', "Запланированные задания
 define('OGP_LANG_there_are_no_scheduled_jobs', "Запланированных заданий нет");
 define('OGP_LANG_cron_events', "События задания");
 define('OGP_LANG_refresh_interval', "Интервал обновления консоли");
-define('OGP_LANG_cron_no_servers_tied_to_account', "There are no servers directly assigned to your account.");
+define('OGP_LANG_cron_no_servers_tied_to_account', "Нет серверов назначенных специально для вашего аккаунта.");
 define('OGP_LANG_cron_admin_link_display_text', "Администрирование Планировщика (все сервера)");
-define('OGP_LANG_cron_admin_no_ogp_servers_to_display', "There aren't any servers currently configured in OGP.");
+define('OGP_LANG_cron_admin_no_ogp_servers_to_display', "Сейчас нет никаких сконфигурированных серверов в OGP.");
 define('OGP_LANG_bad_inputs', "Поле запланированного времени содержит недопустимые символы.");
 ?>

+ 4 - 4
lang/Turkish(Turkey)/modules/cron.php

@@ -39,10 +39,10 @@ define('OGP_LANG_now', "Şimdi");
 define('OGP_LANG_schedule_new_job', "Yeni bir iş planla");
 define('OGP_LANG_scheduled_jobs', "Planlanmış işler");
 define('OGP_LANG_there_are_no_scheduled_jobs', "Planlanmış iş yok");
-define('OGP_LANG_cron_events', "Cron Events");
+define('OGP_LANG_cron_events', "İş Olayları");
 define('OGP_LANG_refresh_interval', "Yenileme Sıklığı");
-define('OGP_LANG_cron_no_servers_tied_to_account', "There are no servers directly assigned to your account.");
-define('OGP_LANG_cron_admin_link_display_text', "Cron Administration (All Servers)");
+define('OGP_LANG_cron_no_servers_tied_to_account', "Doğrudan hesabınıza atanan sunucu yok.");
+define('OGP_LANG_cron_admin_link_display_text', "Cron Yönetimi (Tüm Sunucular)");
 define('OGP_LANG_cron_admin_no_ogp_servers_to_display', "OGP'de yapılandırılmış hiç sunucu yok.");
-define('OGP_LANG_bad_inputs', "Scheduled time contains invalid characters.");
+define('OGP_LANG_bad_inputs', "Zamanlanmış olay geçersiz karakterler içeriyor.");
 ?>

+ 34 - 56
modules/cron/cron.php

@@ -1,4 +1,3 @@
-<script type="text/javascript" src="js/modules/cron.js"></script>
 <?php
 /*
  *
@@ -22,10 +21,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  */
-error_reporting(E_ALL);
 require_once('includes/lib_remote.php');
-require_once('modules/gamemanager/home_handling_functions.php');
-require_once('modules/config_games/server_config_parser.php');
 require_once('modules/cron/shared_cron_functions.php');
 
 function exec_ogp_module() 
@@ -52,61 +48,52 @@ function exec_ogp_module()
 		$remote_servers[$id] = $r_server;
 	}
 	
+	updateCronJobsToNewApi();	
+	
 	list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers);
 	
 	if( isset($_POST['addJob']) or isset($_POST['editJob']) )
 	{
-		if ( isset( $_POST['homeid_ip_port'] ) and isset($server_homes[$_POST['homeid_ip_port']]) )
+		if(!checkCronInput($_POST['minute'], $_POST['hour'], $_POST['dayOfTheMonth'], $_POST['month'], $_POST['dayOfTheWeek']))
+		{
+			print_failure(get_lang('OGP_LANG_bad_inputs'));
+			$view->refresh('?m=cron&p=cron',2);
+			return;
+		}
+		
+		if(isset($_POST['homeid_ip_port']) and isset($server_homes[$_POST['homeid_ip_port']]))
 		{
-			$game_home = $server_homes[$_POST['homeid_ip_port']];
-			$server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$game_home['home_cfg_file']);
-			$remote = new OGPRemoteLibrary( $game_home['agent_ip'], $game_home['agent_port'],
-											$game_home['encryption_key'], $game_home['timeout'] );
-			$home_id = $game_home['home_id'];
-			$ip = $game_home['ip'];
-			$port = $game_home['port'];
-			$control_protocol = $server_xml->control_protocol;
-			$control_password = $game_home['control_password'];
-			$control_type = $server_xml->control_protocol_type;
-			$home_path = $game_home['home_path'];
-			$server_exe = $server_xml->server_exec_name;
-			$run_dir = $server_xml->exe_location;
-			$game_home['mods'][$game_home['mod_id']] = Array ("mod_cfg_id" => $game_home['mod_cfg_id'],
-															  "max_players" => $game_home['max_players'],
-															  "extra_params" => $game_home['extra_params'],
-															  "cpu_affinity" => $game_home['cpu_affinity'],
-															  "nice" => $game_home['nice'],
-															  "precmd" => $game_home['precmd'],
-															  "postcmd" => $game_home['postcmd'],
-															  "home_cfg_id" => $game_home['home_cfg_id'],
-															  "mod_key" => $game_home['mod_key'],
-															  "mod_name" => $game_home['mod_name'],
-															  "def_precmd" => $game_home['def_precmd'],
-															  "def_postcmd" => $game_home['def_postcmd']);
-			$startup_cmd = get_start_cmd($remote,$server_xml,$game_home,$game_home['mod_id'],$game_home['ip'],$game_home['port'], $db);
-			$cpu = $game_home['cpu_affinity'];
-			$nice = $game_home['nice'];
-			
 			$panelURL = getOGPSiteURL();
-			if($panelURL === false){
+			if($panelURL === false)
+			{
 				print_failure('Failed to retrieve panel URL.');
-				return 0;
+				$view->refresh('?m=cron&p=cron',2);
+				return;
 			}
 			
+			$game_home = $server_homes[$_POST['homeid_ip_port']];
+			$ip = $game_home['ip'];
+			$port = $game_home['port'];
+			$mod_key = $game_home['mod_key'];
+			$token = $db->getApiToken($_SESSION['user_id']);
+				
 			switch ($_POST['action']) {
 				case "stop":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=stopServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/stop&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
 					break;
 				case "start":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=startServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/start&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
 					break;
 				case "restart":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=restartServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/restart&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
 					break;
 				case "steam_auto_update":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=autoUpdateSteamHome&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/update&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}&type=steam\" --no-check-certificate > /dev/null 2>&1";
 					break;
 			}
+			
+			$remote = new OGPRemoteLibrary( $game_home['agent_ip'], $game_home['agent_port'],
+											$game_home['encryption_key'], $game_home['timeout'] );
 		}
 		else
 		{
@@ -117,13 +104,6 @@ function exec_ogp_module()
 											$remote_servers[$r_server_id]['timeout']);
 			$command = strip_real_escape_string($_POST['command']);
 		}
-
-		if (!checkCronInput($_POST['minute'], $_POST['hour'], $_POST['dayOfTheMonth'], $_POST['month'], $_POST['dayOfTheWeek'])) {
-			print_failure(get_lang('OGP_LANG_bad_inputs'));
-			$view->refresh('?m=cron&p=cron');
-
-			return;
-		}
 		
 		$job = $_POST['minute']." ".
 			   $_POST['hour']." ".
@@ -216,10 +196,10 @@ function exec_ogp_module()
 			<input style="width: 30px;" type="text" name="dayOfTheWeek" value="*" />
 		</td>
 		<td>
-			<?php echo get_action_selector();?>
+			<?php echo get_action_selector(false, $server_homes, $homeid_ip_port);?>
 		</td>
 		<td>
-			<?php echo get_server_selector($server_homes, $homeid_ip_port, FALSE, true);?>
+			<?php echo get_server_selector($server_homes, $homeid_ip_port, true, true);?>
 		</td>
 		<td>
 			<input style="" type="submit" name="addJob" value="<?php echo get_lang("add"); ?>" />
@@ -336,13 +316,11 @@ function exec_ogp_module()
 				if(isset($job['action'])){	
 					if(array_key_exists('home_id', $job) && array_key_exists('ip', $job) && array_key_exists('port', $job) && hasValue($job['home_id']) && hasValue($job['ip']) && hasValue($job['port'])){
 						$idStr = $job['home_id']."_".$job['ip']."_".$job['port'];				
-					}else if(hasValue($job['home_id'])){
-						$idStr = $job['home_id'];
 					}else{
 						$idStr = false;
 					}
 								
-					$task = get_action_selector($job['action'])."</td><td>".
+					$task = get_action_selector($job['action'], $server_homes, $idStr)."</td><td>".
 							get_server_selector($server_homes, $idStr, FALSE, TRUE);
 				}
 				else
@@ -385,11 +363,11 @@ function exec_ogp_module()
 <?php
 	}
 	else
-	{
 		echo "<h3>". get_lang("there_are_no_scheduled_jobs") ."</h3>";
-	}
+
+	echo '<table class="center hundred" ><tr><td><a href="home.php?m=cron&p=user_cron">'.
+		 get_lang('back').'</a></td></tr></table>';
 ?>
-<table class='center hundred' ><tr><td><a href='javascript:history.go(-1)' > << <?php echo get_lang("back") ?></a></td></tr></table>
 <script type="text/javascript">
 $(document).ready(function() 
 	{
@@ -399,4 +377,4 @@ $(document).ready(function()
 </script>
 <?php
 }
-?>
+?>

+ 2 - 5
modules/cron/events.php

@@ -1,4 +1,3 @@
-<script type="text/javascript" src="js/jquery/jquery-1.11.0.min.js"></script>
 <?php
 /*
  *
@@ -23,8 +22,6 @@
  *
  */
 
-error_reporting(E_ALL);
-
 function exec_ogp_module() 
 {	
 	// Using the refreshed class
@@ -40,7 +37,7 @@ function exec_ogp_module()
 			print_failure(get_lang("agent_offline"));
 			return;
 		}
-		$remote->remote_readfile('scheduler.log', $events);
+		$remote->remote_readfile('scheduler.log',$events);
 		if ($events != "")
 			echo "<pre class='log' >$events</pre>";
 		else
@@ -97,4 +94,4 @@ function exec_ogp_module()
 		echo create_back_button( $_GET['m'], 'cron' );
 	}
 }
-?>
+?>

+ 103 - 139
modules/cron/shared_cron_functions.php

@@ -26,10 +26,9 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
 	global $db;
 	$remote_servers_offline = array();
 	$jobsArray = array();
-	foreach( $remote_servers as $remote_server )
+	foreach( $remote_servers as $rhost_id => $remote_server )
 	{
 		$remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key'], $remote_server['timeout']);
-		$rhost_id = $remote_server['remote_server_id'];
 		if($remote->status_chk() != 1)
 		{
 			$remote_servers_offline[$rhost_id] = $remote_server;
@@ -42,72 +41,30 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
 			{
 				foreach($jobs as $jobId => $job)
 				{
-					$parts = explode(" ", $job);
-					$minute = $parts[0];
-					$hour = $parts[1];
-					$dayOfTheMonth = $parts[2];
-					$month = $parts[3];
-					$dayOfTheWeek = $parts[4];
-					unset($parts[0],$parts[1],$parts[2],$parts[3],$parts[4]);
-					$command = implode(" ", $parts);
-					$retval = preg_match_all("/^%ACTION=(start|restart|stop)\|%\|(.*)$/", $command, $job_info );
-					if($retval and !empty($job_info[1][0]))
+					list($minute,$hour,$dayOfTheMonth,$month,$dayOfTheWeek,$command) = explode(" ", $job, 6);
+					if(preg_match('/'.preg_quote('wget -qO- "','/').'([^"]+)'.preg_quote('" --no-check-certificate > /dev/null 2>&1','/').'/', $command))
 					{
-						//print_r($job_info);
-						$action = $job_info[1][0];
-						$server_args = explode("|%|", $job_info[2][0]);
-						switch ($action) {
-							case 'start':
-								list($home_id, $home_path, $server_exe, $run_dir,
-									 $startup_cmd, $port, $ip, $cpu, $nice) = $server_args;
-								break;
-							case 'restart':
-								list($home_id, $ip, $port, $control_protocol, 
-									 $control_password, $control_type, $home_path, 
-									 $server_exe, $run_dir, $startup_cmd, $cpu, $nice) = $server_args;
-								break;
-							case 'stop':
-								list($home_id, $ip, $port, $control_protocol, 
-									 $control_password, $control_type, $home_path) = $server_args;
-								break;
-						}
-						if(!isset($server_homes[$home_id."_".$ip."_".$port])) continue;
-						
-						if(!$getAllJobs && !hasAccessToCronjobHomeId($home_id)){
-							continue;
-						}
+						list($wget,$wget_args,$url,$wget_nocert,$gt,$devnull,$err2out) =  explode(" ", $command, 7);
 						
+						parse_str(parse_url(trim($url,'"'), PHP_URL_QUERY), $url_query);
 						
-						$jobsArray[$rhost_id][$jobId] = array( 'job' => $job, 
-															   'minute' => $minute, 
-															   'hour' => $hour, 
-															   'dayOfTheMonth' => $dayOfTheMonth, 
-															   'month' => $month, 
-															   'dayOfTheWeek' => $dayOfTheWeek,
-															   'action' => $action,
-															   'home_id' => $home_id,
-															   'ip' => $ip,
-															   'port' => $port);
-					}
-					else if(getURLParam("homeid=", $command) !== false){
-						$homeId = getURLParam("homeid=", $command);
-						if(!$getAllJobs && !hasAccessToCronjobHomeId($homeId)){
+						if(!isset($url_query['ip']) or !isset($url_query['port']))
+							continue;
+						$home_info = $db->getGameHomeByIP($url_query['ip'], $url_query['port']);
+						if(!$getAllJobs && !hasAccess($home_info))
 							continue;
-						}
 						
-						$action = getURLParam("action=", $command);
-						if($action == "autoUpdateSteamHome"){
+						$action = key($url_query);
+						if($action == "gamemanager/update"){
 							$action = "steam_auto_update";
-						}else if($action == "stopServer"){
+						}else if($action == "gamemanager/stop"){
 							$action = "stop";
-						}else if($action == "startServer"){
+						}else if($action == "gamemanager/start"){
 							$action = "start";
-						}else if($action == "restartServer"){
+						}else if($action == "gamemanager/restart"){
 							$action = "restart";
 						}
 						
-						
-						
 						$jobsArray[$rhost_id][$jobId] = array( 'job' => $job, 
 															   'minute' => $minute, 
 															   'hour' => $hour, 
@@ -116,7 +73,10 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
 															   'dayOfTheWeek' => $dayOfTheWeek,
 															   'command' => $command,
 															   'action' => $action,
-															   'home_id' => $homeId);
+															   'home_id' => $home_info['home_id'],
+															   'ip' => $home_info['ip'],
+															   'port' => $home_info['port'],
+															   'mod_key' => $url_query['mod_key']);
 					}
 					else
 					{	
@@ -139,82 +99,31 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
 	return array($jobsArray, $remote_servers_offline);
 }
 
-function updateCronJobPasswords($db, $remote, $changedHomeId){
-	$homes = $db->getIpPorts();
-
-	foreach( $homes as $home )
+function updateCronJobTokens($old_token, $token){
+	global $db;
+	$remote_servers = $db->getRemoteServers();
+	foreach($remote_servers as $remote_server)
 	{
-		$id = $home['home_id']."_".$home['ip']."_".$home['port'];
-		$server_homes[$id] = $home;
-		$server_id = $home['remote_server_id'];
-		$remote_servers[$server_id] = array("remote_server_id" => $home['remote_server_id'],
-											"remote_server_name" => $home['remote_server_name'],
-											"ogp_user" => $home['ogp_user'],
-											"agent_ip" => $home['agent_ip'],
-											"agent_port" => $home['agent_port'],
-											"ftp_port" => $home['ftp_port'],
-											"encryption_key" => $home['encryption_key'],
-											"timeout" => $home['timeout'],
-											"use_nat" => $home['use_nat'],
-											"ftp_ip" => $home['ftp_ip']);
-	}
-
-	list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers);
-
-	$homes = customShift($homes, "home_id", $changedHomeId);
-	$homeIdStr = "homeid=";
-	$actionStr = "action=";
-	$cPassStr = "controlpass=";
-
-	if(count($homes) > 0){
-		$home = $homes[0];
-		if($home["home_id"] == $changedHomeId){ 
-			$control_password = $home['control_password'];
-			
-			foreach( $jobsArray as $remote_server_id => $jobs )
+		$remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key'], $remote_server['timeout']);
+		$jobs = $remote->scheduler_list_tasks();
+		foreach($jobs as $job_id => $job)
+		{
+			if(strstr($job, $old_token))
 			{
-				if($home['remote_server_id'] == $remote_server_id){
-					foreach($jobs as $jobId => $job)
-					{
-						$command = $job['command'];
-						$homeId = getURLParam($homeIdStr, $command);
-						$action = getURLParam($actionStr, $command);
-						if($homeId !== false && $action !== false){
-							if($homeId == $changedHomeId){
-								$curPass = getURLParam($cPassStr, $command);
-								if(stripos($curPass, '" --no-check-certificate') !== false){
-									$curPass = substr($curPass, 0, stripos($curPass, '" --no-check-certificate'));
-								}else if(strrpos($curPass, '"') !== false){
-									$curPass = substr($curPass, 0, strrpos($curPass, '"'));
-								}								
-								if($curPass != $control_password){
-									$command = str_replace($cPassStr . $curPass, $cPassStr . $control_password, $command);
-									$minute = $job['minute'];
-									$hour = $job['hour'];
-									$dayOfTheMonth = $job['dayOfTheMonth'];
-									$month = $job['month'];
-									$dayOfTheWeek = $job['dayOfTheWeek'];
-									
-									$job = $minute." ".
-										$hour ." ".
-										$dayOfTheMonth." ".
-										$month." ".
-										$dayOfTheWeek." ".
-										$command;
-										
-									$remote->scheduler_edit_task($jobId, $job);						
-								}
-							}
-						}
-					}
-				}
+				$remote->scheduler_edit_task($job_id, str_replace($old_token, $token, $job));
 			}
 		}
 	}
 }
 
-function get_action_selector($action = false) {
-	$server_actions = array('restart','stop','start','steam_auto_update');
+function get_action_selector($action = false, $server_homes = false, $homeid_ip_port = false) {
+	$server_actions = array('restart','stop','start');
+	if($server_homes and $homeid_ip_port)
+	{
+		$server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$server_homes[$homeid_ip_port]['home_cfg_file']);
+		if( $server_xml->installer == "steamcmd" )
+			$server_actions[] = 'steam_auto_update';
+	}
 	$select_action = '<select name="action" style="width: 100%;">';
 	foreach($server_actions as $server_action)
 	{
@@ -229,19 +138,11 @@ function get_server_selector($server_homes, $homeid_ip_port = FALSE, $onchange =
 	$select_game = "<select style='text-overflow: ellipsis; width: 100%;' name='homeid_ip_port' $onchange_this_form_submit>\n";
 	if($server_homes != FALSE)
 	{
-		
 		foreach ( $server_homes as $server_home )
 		{
-			// Find out if it's a steamcmd server
-			$additionalMarkup = "";
-			$server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$server_home['home_cfg_file']);
-			if( $server_xml->installer == "steamcmd" ){
-				$additionalMarkup = 'steam="1"';
-			}			
-			
 			$selected = ($homeid_ip_port and ($homeid_ip_port == $server_home['home_id']."_".$server_home['ip']."_".$server_home['port'] || trim($homeid_ip_port) == trim($server_home['home_id']))) ? 'selected="selected"' : '';
 			$select_game .= "<option value='". $server_home['home_id'] . "_" . $server_home['ip'] .
-							"_" . $server_home['port'] . "' $selected " . $additionalMarkup . ">" . $server_home['home_name'] . 
+							"_" . $server_home['port'] . "' $selected >" . $server_home['home_name'] . 
 							" - " . checkDisplayPublicIP($server_home['display_public_ip'],$server_home['ip'] != $server_home['agent_ip'] ? $server_home['ip'] : $server_home['agent_ip']) . ":" .$server_home['port'];
 			if($includeRemoteName){
 				$select_game .= " ( " . $server_home['remote_server_name'] . " )";
@@ -281,10 +182,73 @@ function checkCronInput($min, $hour, $day, $month, $dayOfWeek) {
     return (empty($returns) ? true : false);
 }
 
-function hasAccessToCronjobHomeId($home_id){
+function hasAccess($home_info){
 	global $db;
-	$hasAccess = ($db->isAdmin($_SESSION['user_id'])) ? true : $db->getUserGameHome($_SESSION['user_id'], $home_id);
-	return $hasAccess;
+	return ($home_info and $db->isAdmin($_SESSION['user_id'])) ? true : ($home_info and $db->getUserGameHome($_SESSION['user_id'], $home_info['home_id']));
+}
+
+function updateCronJobsToNewApi()
+{
+	$check_file = "modules/cron/update.check";
+	if(!file_exists($check_file))
+	{
+		require_once 'includes/lib_remote.php';
+		
+		$panelURL = getOGPSiteURL();
+		if($panelURL === false)
+			return false;
+		
+		global $db;
+		$remote_servers = $db->getRemoteServers();
+		$regex = '/'.preg_quote('action=','/').'([a-zA-Z]+)'.preg_quote('&homeid=','/').'([0-9]+)'.preg_quote('&controlpass=','/').'([^"]+)/';
+		$token = $db->getApiToken($_SESSION['user_id']);
+		$mod_key = '';
+		foreach($remote_servers as $remote_server)
+		{
+			$remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key'], $remote_server['timeout']);
+			$jobs = $remote->scheduler_list_tasks();
+			if(!is_array($jobs))
+				continue;
+			foreach($jobs as $job_id => $job)
+			{
+				if(preg_match($regex, $job, $matches))
+				{
+					list($full_match, $action, $home_id, $control_password) = $matches;
+					$home_ip_ports = $db->getHomeIpPorts($home_id);
+					if(isset($home_ip_ports[0]))
+					{
+						$port = $home_ip_ports[0]["port"];
+						$ip = $home_ip_ports[0]["ip"];
+						
+						switch ($action) {
+							case "stopServer":
+								$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/stop&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
+								break;
+							case "startServer":
+								$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/start&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
+								break;
+							case "restartServer":
+								$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/restart&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
+								break;
+							case "autoUpdateSteamHome":
+								$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/update&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}&type=steam\" --no-check-certificate > /dev/null 2>&1";
+								break;
+						}
+						list($minute,$hour,$dayOfTheMonth,$month,$dayOfTheWeek,$old_command) = explode(" ", $job, 6);
+						$new_job = $minute." ".
+								   $hour." ".
+								   $dayOfTheMonth." ".
+								   $month." ".
+								   $dayOfTheWeek." ".
+								   $command;
+						
+						$remote->scheduler_edit_task($job_id, $new_job);
+					}
+				}
+			}
+		}
+		file_put_contents($check_file, "updated");
+	}
 }
 
 ?>

+ 41 - 67
modules/cron/user_cron.php

@@ -1,4 +1,3 @@
-<script type="text/javascript" src="js/modules/cron.js"></script>
 <?php
 /*
  *
@@ -24,8 +23,6 @@
  */
 error_reporting(E_ALL);
 require_once('includes/lib_remote.php');
-require_once('modules/gamemanager/home_handling_functions.php');
-require_once('modules/config_games/server_config_parser.php');
 require_once('modules/cron/shared_cron_functions.php');
 
 function exec_ogp_module() 
@@ -47,86 +44,55 @@ function exec_ogp_module()
 	
 	foreach( $homes as $home )
 	{
-		$id = $home['home_id']."_".$home['ip']."_".$home['port'];
-		$server_homes[$id] = $home;
-		$server_id = $home['remote_server_id'];
-		$remote_servers[$server_id] = array("remote_server_id" => $home['remote_server_id'],
-											"remote_server_name" => $home['remote_server_name'],
-											"ogp_user" => $home['ogp_user'],
-											"agent_ip" => $home['agent_ip'],
-											"agent_port" => $home['agent_port'],
-											"ftp_port" => $home['ftp_port'],
-											"encryption_key" => $home['encryption_key'],
-											"timeout" => $home['timeout'],
-											"use_nat" => $home['use_nat'],
-											"ftp_ip" => $home['ftp_ip']);
+		$server_homes[$home['home_id']."_".$home['ip']."_".$home['port']] = $home;
+		$remote_servers[$home['remote_server_id']] = array( "agent_ip" => $home['agent_ip'],
+															"agent_port" => $home['agent_port'],
+															"encryption_key" => $home['encryption_key'],
+															"timeout" => $home['timeout']);
 	}
 	
 	list($jobsArray, $remote_servers_offline) = reloadJobs($server_homes, $remote_servers, false);
 	
 	if( isset($_POST['addJob']) or isset($_POST['editJob']) )
 	{
+		if(!checkCronInput($_POST['minute'], $_POST['hour'], $_POST['dayOfTheMonth'], $_POST['month'], $_POST['dayOfTheWeek']))
+		{
+			print_failure(get_lang('OGP_LANG_bad_inputs'));
+			$view->refresh('?m=cron&p=user_cron',2);
+			return;
+		}
+		
 		if ( isset( $_POST['homeid_ip_port'] ) and isset($server_homes[$_POST['homeid_ip_port']]) )
 		{
-			$game_home = $server_homes[$_POST['homeid_ip_port']];
-			$server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$game_home['home_cfg_file']);
-			$remote = new OGPRemoteLibrary( $game_home['agent_ip'],
-											$game_home['agent_port'],
-											$game_home['encryption_key'],
-											$game_home['timeout']);
-			$home_id = $game_home['home_id'];
-			$ip = $game_home['ip'];
-			$port = $game_home['port'];
-			$control_protocol = $server_xml->control_protocol;
-			$control_password = $game_home['control_password'];
-			$control_type = $server_xml->control_protocol_type;
-			$home_path = $game_home['home_path'];
-			$server_exe = $server_xml->server_exec_name;
-			$run_dir = $server_xml->exe_location;
-			$game_home['mods'][$game_home['mod_id']] = Array ("mod_cfg_id" => $game_home['mod_cfg_id'],
-															  "max_players" => $game_home['max_players'],
-															  "extra_params" => $game_home['extra_params'],
-															  "cpu_affinity" => $game_home['cpu_affinity'],
-															  "nice" => $game_home['nice'],
-															  "precmd" => $game_home['precmd'],
-															  "postcmd" => $game_home['postcmd'],
-															  "home_cfg_id" => $game_home['home_cfg_id'],
-															  "mod_key" => $game_home['mod_key'],
-															  "mod_name" => $game_home['mod_name'],
-															  "def_precmd" => $game_home['def_precmd'],
-															  "def_postcmd" => $game_home['def_postcmd']);
-			$startup_cmd = get_start_cmd($remote,$server_xml,$game_home,$game_home['mod_id'],$game_home['ip'],$game_home['port'], $db);
-			$cpu = $game_home['cpu_affinity'];
-			$nice = $game_home['nice'];
-			
 			$panelURL = getOGPSiteURL();
-			if($panelURL === false){
+			if($panelURL === false)
+			{
 				print_failure('Failed to retrieve panel URL.');
-				return 0;
+				$view->refresh('?m=cron&p=user_cron',2);
+				return;
 			}
 			
+			$game_home = $server_homes[$_POST['homeid_ip_port']];
+			$ip = $game_home['ip'];
+			$port = $game_home['port'];
+			$mod_key = $game_home['mod_key'];
+			$token = $db->getApiToken($_SESSION['user_id']);
+			
 			switch ($_POST['action']) {
 				case "stop":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=stopServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/stop&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
 					break;
 				case "start":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=startServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/start&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
 					break;
 				case "restart":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=restartServer&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/restart&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}\" --no-check-certificate > /dev/null 2>&1";
 					break;
 				case "steam_auto_update":
-					$command = "wget -qO- \"" . $panelURL . "/ogp_api.php?action=autoUpdateSteamHome&homeid=" . $home_id . "&controlpass=" . $control_password . "\" --no-check-certificate > /dev/null 2>&1";
+					$command = "wget -qO- \"${panelURL}/ogp_api.php?gamemanager/update&token=${token}&ip=${ip}&port=${port}&mod_key=${mod_key}&type=steam\" --no-check-certificate > /dev/null 2>&1";
 					break;
 			}
-
-			if (!checkCronInput($_POST['minute'], $_POST['hour'], $_POST['dayOfTheMonth'], $_POST['month'], $_POST['dayOfTheWeek'])) {
-				print_failure(get_lang('OGP_LANG_bad_inputs'));
-				$view->refresh('?m=cron&p=user_cron');
-
-				return;
-			}
-
+			
 			$job = $_POST['minute']." ".
 				   $_POST['hour']." ".
 				   $_POST['dayOfTheMonth']." ".
@@ -134,6 +100,11 @@ function exec_ogp_module()
 				   $_POST['dayOfTheWeek']." ".
 				   $command;
 			
+			$remote = new OGPRemoteLibrary( $game_home['agent_ip'],
+											$game_home['agent_port'],
+											$game_home['encryption_key'],
+											$game_home['timeout']);
+			
 			if( isset($_POST['editJob']) and isset($jobsArray[$_POST['r_server_id']][$_POST['job_id']]) ) 
 				$remote->scheduler_edit_task($_POST['job_id'], $job);
 			elseif( isset($_POST['addJob']) ) 
@@ -203,10 +174,10 @@ function exec_ogp_module()
 			<input style="width: 30px;" type="text" name="dayOfTheWeek" value="*" />
 		</td>
 		<td>
-			<?php echo get_action_selector();?>
+			<?php echo get_action_selector(false, $server_homes, $homeid_ip_port);?>
 		</td>
 		<td>
-			<?php echo get_server_selector($server_homes, $homeid_ip_port);?>
+			<?php echo get_server_selector($server_homes, $homeid_ip_port, true);?>
 		</td>
 		<td style="width: 132px;">
 			<input style="" type="submit" name="addJob" value="<?php echo get_lang("add"); ?>" />
@@ -255,8 +226,8 @@ function exec_ogp_module()
 				{
 					if(array_key_exists('home_id', $job) && array_key_exists('ip', $job) && array_key_exists('port', $job) && hasValue($job['home_id']) && hasValue($job['ip']) && hasValue($job['port'])){
 						$uniqueStr = $job['home_id']."_".$job['ip']."_".$job['port'];
-					}else if(hasValue($job['home_id'])){
-						$uniqueStr = $job['home_id'];
+					}else{
+						$uniqueStr = false;
 					}
 					
 					if(hasValue(@$uniqueStr)){
@@ -278,7 +249,7 @@ function exec_ogp_module()
 											<input style="width: 30px;" type="text" name="dayOfTheWeek" value="'.$job['dayOfTheWeek'].'" />
 										</td>
 										<td>
-											'.get_action_selector($job['action'])."</td><td>".
+											'.get_action_selector($job['action'], $server_homes, $uniqueStr)."</td><td>".
 											  get_server_selector($server_homes, $uniqueStr).'
 										</td>
 										<td style="width: 132px;">
@@ -300,8 +271,11 @@ function exec_ogp_module()
 	}
 	else
 		echo "<h3>". get_lang("there_are_no_scheduled_jobs") ."</h3>";
+	
+	if(!$boolShowedAdminLink && $isAdmin)
+		echo '<table class="center hundred" ><tr><td><a href="home.php?m=cron&p=cron">'.
+		get_lang('cron_admin_link_display_text') . '</a></td></tr></table>';
 ?>
-<table class='center hundred' ><tr><td><a href='javascript:history.go(-1)' > << <?php echo get_lang("back") ?></a><?php if(!$boolShowedAdminLink && $isAdmin){ echo '&nbsp; &nbsp; | &nbsp; &nbsp; ' . '<a href="home.php?m=cron&p=cron">' . get_lang('cron_admin_link_display_text') . '</a>'; }?></td></tr></table>
 <script type="text/javascript">
 $(document).ready(function() 
 	{