|
@@ -26,10 +26,9 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
|
|
|
global $db;
|
|
global $db;
|
|
|
$remote_servers_offline = array();
|
|
$remote_servers_offline = array();
|
|
|
$jobsArray = 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']);
|
|
$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)
|
|
if($remote->status_chk() != 1)
|
|
|
{
|
|
{
|
|
|
$remote_servers_offline[$rhost_id] = $remote_server;
|
|
$remote_servers_offline[$rhost_id] = $remote_server;
|
|
@@ -42,72 +41,30 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
|
|
|
{
|
|
{
|
|
|
foreach($jobs as $jobId => $job)
|
|
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;
|
|
continue;
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- $action = getURLParam("action=", $command);
|
|
|
|
|
- if($action == "autoUpdateSteamHome"){
|
|
|
|
|
|
|
+ $action = key($url_query);
|
|
|
|
|
+ if($action == "gamemanager/update"){
|
|
|
$action = "steam_auto_update";
|
|
$action = "steam_auto_update";
|
|
|
- }else if($action == "stopServer"){
|
|
|
|
|
|
|
+ }else if($action == "gamemanager/stop"){
|
|
|
$action = "stop";
|
|
$action = "stop";
|
|
|
- }else if($action == "startServer"){
|
|
|
|
|
|
|
+ }else if($action == "gamemanager/start"){
|
|
|
$action = "start";
|
|
$action = "start";
|
|
|
- }else if($action == "restartServer"){
|
|
|
|
|
|
|
+ }else if($action == "gamemanager/restart"){
|
|
|
$action = "restart";
|
|
$action = "restart";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
$jobsArray[$rhost_id][$jobId] = array( 'job' => $job,
|
|
$jobsArray[$rhost_id][$jobId] = array( 'job' => $job,
|
|
|
'minute' => $minute,
|
|
'minute' => $minute,
|
|
|
'hour' => $hour,
|
|
'hour' => $hour,
|
|
@@ -116,7 +73,10 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
|
|
|
'dayOfTheWeek' => $dayOfTheWeek,
|
|
'dayOfTheWeek' => $dayOfTheWeek,
|
|
|
'command' => $command,
|
|
'command' => $command,
|
|
|
'action' => $action,
|
|
'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
|
|
else
|
|
|
{
|
|
{
|
|
@@ -139,82 +99,31 @@ function reloadJobs($server_homes, $remote_servers, $getAllJobs = true)
|
|
|
return array($jobsArray, $remote_servers_offline);
|
|
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%;">';
|
|
$select_action = '<select name="action" style="width: 100%;">';
|
|
|
foreach($server_actions as $server_action)
|
|
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";
|
|
$select_game = "<select style='text-overflow: ellipsis; width: 100%;' name='homeid_ip_port' $onchange_this_form_submit>\n";
|
|
|
if($server_homes != FALSE)
|
|
if($server_homes != FALSE)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
foreach ( $server_homes as $server_home )
|
|
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"' : '';
|
|
$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'] .
|
|
$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'];
|
|
" - " . 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){
|
|
if($includeRemoteName){
|
|
|
$select_game .= " ( " . $server_home['remote_server_name'] . " )";
|
|
$select_game .= " ( " . $server_home['remote_server_name'] . " )";
|
|
@@ -281,10 +182,73 @@ function checkCronInput($min, $hour, $day, $month, $dayOfWeek) {
|
|
|
return (empty($returns) ? true : false);
|
|
return (empty($returns) ? true : false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function hasAccessToCronjobHomeId($home_id){
|
|
|
|
|
|
|
+function hasAccess($home_info){
|
|
|
global $db;
|
|
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");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
?>
|