function exec_ogp_module() { global $db; global $view; $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : ""; $mod_id = isset($_REQUEST['mod_id']) ? $_REQUEST['mod_id'] : ""; $isAdmin = $db->isAdmin($_SESSION['user_id']); if ($isAdmin) { $home_info = $db->getGameHome($home_id); } else { $home_info = $db->getUserGameHome($_SESSION['user_id'], $home_id); } if ($home_info === FALSE || preg_match("/u/", $home_info['access_rights']) != 1) { print_failure(get_lang('no_rights')); echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; return; } $game_type = $home_info['game_key']; echo "<h2>Updating game server <em>" . $home_info['home_name'] . "</em></h2>"; $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']); if ($server_xml->installer != "steamcmd") { print_failure(get_lang('xml_steam_error')); return; } $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']); $host_stat = $remote->status_chk(); if ($remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_id) == 1) { print_failure(get_lang('server_running_cant_update')); return; } $log_txt = ''; $update_active = $remote->get_log(OGP_SCREEN_TYPE_UPDATE, $home_id, clean_path($home_info['home_path']), $log_txt); $modkey = $home_info['mods'][$mod_id]['mod_key']; $mod_xml = xml_get_mod($server_xml, $modkey); if (!$mod_xml) { print_failure(get_lang_f('mod_key_not_found_from_xml', $modkey)); return; } if ($update_active === 0) { print_failure(get_lang('agent_offline')); echo "<meta http-equiv='refresh' content='5'>"; return; } else { if ($_REQUEST['update'] == 'update' && $update_active != 1) { $installer_name = $modkey; if (isset($mod_xml->installer_name)) { $installer_name = $mod_xml->installer_name; } $mod_cfg_id = $home_info['mod_cfg_id']; $game_mod_precmd = $db->resultQuery("SELECT DISTINCT precmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'"); if ($game_mod_precmd[0]['precmd'] === NULL or empty($game_mod_precmd[0]['precmd'])) { $config_mod_precmd = $db->resultQuery("SELECT DISTINCT def_precmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'"); if ($config_mod_precmd[0]['def_precmd'] === NULL or empty($config_mod_precmd[0]['def_precmd'])) { $precmd = ""; } else { $precmd = $config_mod_precmd[0]['def_precmd']; } } else { $precmd = $game_mod_precmd[0]['precmd']; } $game_mod_postcmd = $db->resultQuery("SELECT DISTINCT postcmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'"); if ($game_mod_postcmd[0]['postcmd'] === NULL or empty($game_mod_postcmd[0]['postcmd'])) { $config_mod_postcmd = $db->resultQuery("SELECT DISTINCT def_postcmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'"); if ($config_mod_postcmd[0]['def_postcmd'] === NULL or empty($config_mod_postcmd[0]['def_postcmd'])) { $postcmd = ""; } else { $postcmd = $config_mod_postcmd[0]['def_postcmd']; } } else { $postcmd = $game_mod_postcmd[0]['postcmd']; } $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location); $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name); if (isset($_REQUEST['master_server_home_id'])) { $ms_home_id = $_REQUEST['master_server_home_id']; $ms_info = $db->getGameHome($ms_home_id); $steam_out = $remote->masterServerUpdate($home_id, $home_info['home_path'], $ms_home_id, $ms_info['home_path'], $exec_folder_path, $exec_path, $precmd, $postcmd); } else { if (preg_match("/win32/", $server_xml->game_key) or preg_match("/win64/", $server_xml->game_key)) { $cfg_os = "windows"; } elseif (preg_match("/linux/", $server_xml->game_key)) { $cfg_os = "linux"; } $settings = $db->getSettings(); // Some games like L4D2 require anonymous login if ($mod_xml->installer_login) { $login = $mod_xml->installer_login; $pass = ''; } else { $login = $settings['steam_user']; $pass = $settings['steam_pass']; } $modname = ($installer_name == '90' and !preg_match("/(cstrike|valve)/", $modkey)) ? $modkey : ''; $betaname = isset($mod_xml->betaname) ? $mod_xml->betaname : ''; $betapwd = isset($mod_xml->betapwd) ? $mod_xml->betapwd : ''; $steam_out = $remote->steam_cmd($home_id, $home_info['home_path'], $installer_name, $modname, $betaname, $betapwd, $login, $pass, $settings['steam_guard'], $exec_folder_path, $exec_path, $precmd, $postcmd, $cfg_os); } if ($steam_out === 0) { print_failure(get_lang('failed_to_start_steam_update')); return; } else { if ($steam_out === 1) { print_success(get_lang('update_started')); } else { if ($host_stat === 0) { print_failure(get_lang('agent_offline')); $view->refresh("?m=gamemanager&p=update&update=refresh&home_id={$home_id}&mod_id={$mod_id}", 5); return; } echo "Installing Steam... wait."; $steamcmdtrue = isset($_REQUEST['steamcmd']) ? "&steamcmd=true" : ""; $view->refresh("?m=gamemanager&p=update&update=update&home_id={$home_id}&mod_id={$mod_id}{$steamcmdtrue}", 5); return; } } } else { if (isset($_POST['stop_update_x'])) { $stop_update = sprintf("screen -S OGP_UPDATE_%09d -X quit", $home_id); $remote->exec("{$stop_update}"); } $update_complete = false; if ($update_active == 1) { echo "<p class='note'>" . get_lang('update_in_progress') . "</p>\n"; echo "<form method=POST><input type='image' name='stop_update' onsubmit='submit-form();' src='modules/administration/images/remove.gif'>" . get_lang('stop_update') . "</input></form>"; } else { echo "<meta http-equiv='refresh' content='60'>"; print_success(get_lang('update_completed')); echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; $update_complete = true; } if (empty($log_txt)) { $log_txt = get_lang('not_available'); } echo "<pre>" . $log_txt . "</pre>\n"; if ($update_complete) { return; } } } echo "<p><a href=\"?m=gamemanager&p=update&update=refresh&home_id={$home_id}&mod_id={$mod_id}\">"; echo get_lang('refresh_steam_status') . "</a></p>"; $view->refresh("?m=gamemanager&p=update&update=refresh&home_id={$home_id}&mod_id={$mod_id}", 5); return; }
function exec_ogp_module() { //update_local_copies(); #Disabled until the rsync_sites.list file from master servers is corrected. global $db, $view, $settings; if (isset($_REQUEST['url'])) { $url = $_REQUEST['url']; } else { $url = ""; } $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : ""; $mod_id = isset($_REQUEST['mod_id']) ? $_REQUEST['mod_id'] : ""; $state = isset($_POST['state']) ? $_POST['state'] : ""; $update = isset($_GET['update']) ? $_GET['update'] : ""; $isAdmin = $db->isAdmin($_SESSION['user_id']); if ($isAdmin) { $home_info = $db->getGameHome($home_id); } else { $home_info = $db->getUserGameHome($_SESSION['user_id'], $home_id); } if ($home_info === FALSE || preg_match("/u/", $home_info['access_rights']) != 1) { print_failure(get_lang('no_rights')); echo create_back_button("gamemanager", "game_monitor"); return; } $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']); $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']); if (isset($server_xml->lgsl_query_name)) { $lgslname = $server_xml->lgsl_query_name; if ($lgslname == "quake3") { if ($server_xml->game_name == "Quake 3") { $lgslname = "q3"; } } } elseif (isset($server_xml->gameq_query_name)) { $lgslname = $server_xml->gameq_query_name; if ($lgslname == "minecraft") { if ($server_xml->game_name == "Minecraft Tekkit") { $lgslname = "tekkit"; } elseif ($server_xml->game_name == "Minecraft Bukkit") { $lgslname = "bukkit"; } } } elseif (isset($server_xml->protocol)) { $lgslname = $server_xml->protocol; } else { $lgslname = $server_xml->mods->mod['key']; } if (preg_match("/win32/", $server_xml->game_key) or preg_match("/win64/", $server_xml->game_key)) { $os = "windows"; } elseif (preg_match("/linux/", $server_xml->game_key)) { $os = "linux"; } $full_url = $url . "/ogp_game_installer/{$lgslname}/{$os}/"; echo "<h2>Update {$home_info['home_name']}</h2>"; if ($remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_id) == 1) { print_failure(get_lang('server_running_cant_update')); return; } $update_active = $remote->get_log(OGP_SCREEN_TYPE_UPDATE, $home_id, clean_path($home_info['home_path']), $log_txt, 30); if ($update_active === 0) { print_failure(get_lang('agent_offline')); echo "<meta http-equiv='refresh' content='5'>"; return; } elseif ($state == 'start' && $update_active != 1) { $mod_cfg_id = $home_info['mod_cfg_id']; $game_mod_precmd = $db->resultQuery("SELECT DISTINCT precmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'"); if ($game_mod_precmd[0]['precmd'] === NULL or empty($game_mod_precmd[0]['precmd'])) { $config_mod_precmd = $db->resultQuery("SELECT DISTINCT def_precmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'"); if ($config_mod_precmd[0]['def_precmd'] === NULL or empty($config_mod_precmd[0]['def_precmd'])) { $precmd = ""; } else { $precmd = $config_mod_precmd[0]['def_precmd']; } } else { $precmd = $game_mod_precmd[0]['precmd']; } $game_mod_postcmd = $db->resultQuery("SELECT DISTINCT postcmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'"); if ($game_mod_postcmd[0]['postcmd'] === NULL or empty($game_mod_postcmd[0]['postcmd'])) { $config_mod_postcmd = $db->resultQuery("SELECT DISTINCT def_postcmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'"); if ($config_mod_postcmd[0]['def_postcmd'] === NULL or empty($config_mod_postcmd[0]['def_postcmd'])) { $postcmd = ""; } else { $postcmd = $config_mod_postcmd[0]['def_postcmd']; } } else { $postcmd = $game_mod_postcmd[0]['postcmd']; } $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location); $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name); if (isset($_REQUEST['master_server_home_id'])) { $ms_home_id = $_REQUEST['master_server_home_id']; $ms_info = $db->getGameHome($ms_home_id); print_success(get_lang_f("starting_copy_with_master_server_named", $ms_info['home_name'])); $rsync = $remote->masterServerUpdate($home_id, $home_info['home_path'], $ms_home_id, $ms_info['home_path'], $exec_folder_path, $exec_path, $precmd, $postcmd); $master = "&master=true"; } else { print_success(get_lang_f("starting_sync_with", $full_url)); $rsync = $remote->start_rsync_install($home_id, $home_info['home_path'], "{$full_url}", $exec_folder_path, $exec_path, $precmd, $postcmd); $master = ""; } if ($rsync === 0) { print_failure(get_lang('failed_to_start_rsync_update')); return; } else { if ($rsync === 1) { print_success(get_lang('update_started')); echo "<p><a href=\"?m=gamemanager&p=rsync_install&update=refresh&home_id={$home_id}&mod_id={$mod_id}{$master}\">"; echo get_lang('refresh_rsync_status') . "</a></p>"; $view->refresh("?m=gamemanager&p=rsync_install&update=refresh&home_id={$home_id}&mod_id={$mod_id}{$master}", 5); return; } elseif ($rsync === 0) { print_failure(get_lang('agent_offline')); return; } } } elseif ($update_active == 1) { echo "<p class='note'></p>\n"; if (isset($_POST['stop_update_x'])) { $stop_update = sprintf("screen -S OGP_UPDATE_%09d -X quit", $home_id); $remote->exec("{$stop_update}"); } $update_complete = false; echo "<form method=POST><input type='image' name='stop_update' onsubmit='submit-form();' src='modules/administration/images/remove.gif'>" . get_lang('stop_update') . "</input></form>"; if (empty($log_txt)) { $log_txt = get_lang('not_available'); } if (!isset($_GET['master'])) { $kbytes = $remote->rsync_progress($home_info['home_path']); list($totalsize, $mbytes, $pct) = explode(";", do_progress($kbytes, $lgslname . "/" . $os)); $totalmbytes = round($totalsize / 1024, 2); echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" > <h4>' . get_lang('update_in_progress') . " {$mbytes}MB/{$totalmbytes}MB</h4>\n\t\t\t\t <div style='background-color:#dce9f2;' >\n\t\t\t\t "; $bar = ''; for ($i = 1; $i <= $pct; $i++) { $bar .= '<img style="width:0.92%;vertical-align:middle;" src="images/progressBar.png">'; } echo "{$bar} <b style='vertical-align:top;display:inline;font-size:1.2em;color:red;' >{$pct}%</b>\n\t\t\t\t\t</div>\n\t\t\t\t </div><br>"; } else { echo '<h4>' . get_lang('update_in_progress') . '</h4>'; } echo "<pre>" . $log_txt . "</pre>\n"; echo "<p><a href=\"?m=gamemanager&p=rsync_install&update=refresh&home_id={$home_id}&mod_id={$mod_id}\">"; echo get_lang('refresh_rsync_status') . "</a></p>"; $view->refresh("?m=gamemanager&p=rsync_install&update=refresh&home_id={$home_id}&mod_id={$mod_id}", 5); return; } elseif ($update != "update") { echo "<meta http-equiv='refresh' content='60'>"; print_success(get_lang('update_completed')); echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; echo "<pre>" . $log_txt . "</pre>\n"; echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; $update_complete = true; } else { $rsync_remote_sites = file("modules/gamemanager/rsync_sites.list"); #load offical rsync sites $rsync_local_sites = file("modules/gamemanager/rsync_sites_local.list"); #load user custom sites $settings['rsync_available'] = isset($settings['rsync_available']) ? $settings['rsync_available'] : "1"; if (is_array($rsync_local_sites) and $settings['rsync_available'] == "1") { $rsync_sites = array_merge($rsync_remote_sites, $rsync_local_sites); #merge arrays } elseif ($settings['rsync_available'] == "2") { $rsync_sites = $rsync_remote_sites; } elseif ($settings['rsync_available'] == "3") { $rsync_sites = $rsync_local_sites; } #echo "LGSL or GameQ query name is $server_xml->lgsl_query_name$server_xml->gameq_query_name"; $sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES); if (!is_array($sync_list)) { if (!is_file("modules/gamemanager/rsync.list")) { print_failure("Trouble accessing http://www.opengamepanel.org/rsync.list"); print_failure("Make sure allow_fopen_url is set to \"On\" in your php.ini and opengamepanel.org is online"); print_failure("In the mean time, you can get a local copy of the file by running wget http://www.opengamepanel.org/sync_data/rsync.list -O /path/to/ogpweb/modules/gamemanager/rsync.list"); return; } # print_failure("Error loading rsync.list"); # return; $sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES); if (!is_array($sync_list)) { print_failure("Failed to open local copy of rsync.list in modules/gamemanager/rsync.list"); return; } } $master_server_home_id = $db->getMasterServer($home_info['remote_server_id'], $home_info['home_cfg_id']); if (in_array($lgslname, $sync_list)) { echo "Game type supported<br>\n\t\t\t\t <p class='center'>To add your own rsync site, create modules/gamemanager/rsync_sites_local.list and put a server name on each line.</p><br>\n\t\t\t\t <form action='?m=gamemanager&p=rsync_install' method='post'>\n\t\t\t\t <table class='center'>\n\t\t\t\t <input type='hidden' name='home_id' value='{$home_id}' />\n\t\t\t\t <input type='hidden' name='mod_id' value='{$mod_id}' />\n\t\t\t\t <input type='hidden' name='lgslname' value='{$lgslname}' />\n\t\t\t\t <input type='hidden' name='state' value='start' />\n\t\t\t\t <tr><td align='right'>Game name:</td><td align='left'>{$home_info['game_name']}</td></tr>\n\t\t\t\t <tr><td align='right'>Directory:</td><td align='left'>{$home_info['home_path']}</td></tr>\n\t\t\t\t <tr><td align='right'>Remoteserver:</td>\n\t\t\t\t <td align='left'>{$home_info['remote_server_name']} ({$home_info['agent_ip']}:{$home_info['agent_port']})</td></tr>\n\t\t\t\t <tr><td align='right'>Rsync Server:</td>\n\t\t\t\t <td align='left'>" . create_drop_box_from_array_rsync($rsync_sites, "url") . "<br>"; if ($master_server_home_id != FALSE and $master_server_home_id != $home_id) { echo "<input type='checkbox' name='master_server_home_id' value='{$master_server_home_id}' /><b>" . get_lang('update_from_local_master_server') . "</b>"; } echo "</td></tr></table><p><input type='submit' name='update' value='update' /></p>\n\t\t\t\t </form>"; } elseif ($master_server_home_id != FALSE and $master_server_home_id != $home_id) { $ms_home_info = $db->getGameHome($master_server_home_id); echo "<br>\n\t\t\t\t <p class='success'>Master server update available</p><br>\n\t\t\t\t <form action='?m=gamemanager&p=rsync_install' method='post'>\n\t\t\t\t <table class='center'>\n\t\t\t\t <input type='hidden' name='home_id' value='{$home_id}' />\n\t\t\t\t <input type='hidden' name='mod_id' value='{$mod_id}' />\n\t\t\t\t <input type='hidden' name='lgslname' value='{$lgslname}' />\n\t\t\t\t <input type='hidden' name='state' value='start' />\n\t\t\t\t <tr><td align='right'>Game name:</td><td align='left'>{$home_info['game_name']}</td></tr>\n\t\t\t\t <tr><td align='right'>Master Server Name:</td><td align='left'>{$ms_home_info['home_name']}</td></tr>\n\t\t\t\t <tr><td align='right'>Master Server Directory:</td><td align='left'>{$ms_home_info['home_path']}</td></tr>\n\t\t\t\t <tr><td align='right'>Local Directory:</td><td align='left'>{$home_info['home_path']}</td></tr>" . "<input type='hidden' name='master_server_home_id' value='{$master_server_home_id}' />" . "</td></tr></table><p><input type='submit' name='update' value='" . get_lang('update_from_local_master_server') . "' /></p>\n\t\t\t\t </form>"; } else { print_failure("This game type [ {$lgslname} ] is not yet supported with rsync install"); } } }