-
-
Save Adjokip/6f28cee88e364fc13bcd00ce2d5e809d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function reloadJobs($server_homes, $remote_servers, $adminCronPage, $db) | |
{ | |
$remote_servers_offline = array(); | |
$jobsArray = array(); | |
foreach( $remote_servers as $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; | |
continue; | |
} | |
else | |
{ | |
$jobs = $remote->scheduler_list_tasks(); | |
if($jobs != -1) | |
{ | |
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])) | |
{ | |
//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; | |
$hasAccess = ($db->isAdmin($_SESSION['user_id'])) ? $db->getGameHome($home_id) : $db->getUserGameHome($_SESSION['user_id'], $home_id); | |
if ($hasAccess) { | |
$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); | |
$action = getURLParam("action=", $command); | |
if($action == "autoUpdateSteamHome"){ | |
$action = "steam_auto_update"; | |
}else if($action == "stopServer"){ | |
$action = "stop"; | |
}else if($action == "startServer"){ | |
$action = "start"; | |
}else if($action == "restartServer"){ | |
$action = "restart"; | |
} | |
$hasAccess = ($db->isAdmin($_SESSION['user_id'])) ? $db->getGameHome($homeId) : $db->getUserGameHome($_SESSION['user_id'], $homeId); | |
if ($hasAccess) { | |
$jobsArray[$rhost_id][$jobId] = array( 'job' => $job, | |
'minute' => $minute, | |
'hour' => $hour, | |
'dayOfTheMonth' => $dayOfTheMonth, | |
'month' => $month, | |
'dayOfTheWeek' => $dayOfTheWeek, | |
'command' => $command, | |
'action' => $action, | |
'home_id' => $homeId); | |
} | |
} | |
else | |
{ | |
if ($adminCronPage) { | |
$jobsArray[$rhost_id][$jobId] = array( 'job' => $job, | |
'minute' => $minute, | |
'hour' => $hour, | |
'dayOfTheMonth' => $dayOfTheMonth, | |
'month' => $month, | |
'dayOfTheWeek' => $dayOfTheWeek, | |
'command' => $command); | |
} | |
} | |
} | |
} | |
} | |
} | |
return array($jobsArray, $remote_servers_offline); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment