function exec_ogp_module() { global $db; global $view; $home_cfg_id = isset($_REQUEST['home_cfg_id']) ? $_REQUEST['home_cfg_id'] : ""; $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : ""; $addon_id = isset($_REQUEST['addon_id']) ? $_REQUEST['addon_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) { print_failure(get_lang('no_rights')); echo create_back_button("addonsmanager", "user_addons"); return; } $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']); $state = isset($_REQUEST['state']) ? $_REQUEST['state'] : ""; $pid = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : -1; if (!empty($state)) { $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']); $addons_rows = $db->resultQuery("SELECT url, path, post_script FROM OGP_DB_PREFIXaddons WHERE addon_id=" . $addon_id); $addon_info = $addons_rows[0]; $url = $addon_info['url']; $filename = basename($url); #### This makes replacements to the bash script: if (isset($addon_info['post_script']) and !empty($addon_info['post_script']) and $addon_info['post_script'] != "") { $check_passed = FALSE; $address_at_post = $_POST['ip'] . ":" . $_POST['port']; $ip_ports = $db->getHomeIpPorts($home_info["home_id"]); foreach ($ip_ports as $ip_port) { } $address_owned = $ip_port['ip'] . ":" . $ip_port['port']; if ($address_owned == $address_at_post) { $check_passed = TRUE; break; } $ip = $ip_port['ip']; $port = $ip_port['port']; $home_info["ip"] = $check_passed ? $_POST['ip'] : $ip; $home_info["port"] = $check_passed ? $_POST['port'] : $port; if (isset($server_xml->gameq_query_name)) { $home_info["query_port"] = get_query_port($server_xml, $home_info['port']); } elseif (isset($server_xml->lgsl_query_name)) { $get_q_and_s = lgsl_port_conversion((string) $server_xml->lgsl_query_name, $home_info['port'], "", ""); $home_info["query_port"] = $get_q_and_s['1']; } $home_info["incremental"] = $db->incrementalNumByHomeId($home_info["home_id"], $home_info["mod_cfg_id"], $home_info["remote_server_id"]); $post_script = preg_replace("/\\%home_path\\%/i", $home_info["home_path"], $addon_info['post_script']); $post_script = preg_replace("/\\%home_name\\%/i", $home_info["home_name"], $post_script); $post_script = preg_replace("/\\%control_password\\%/i", $home_info["control_password"], $post_script); $post_script = preg_replace("/\\%max_players\\%/i", $home_info["max_players"], $post_script); $post_script = preg_replace("/\\%ip\\%/i", $home_info["ip"], $post_script); $post_script = preg_replace("/\\%port\\%/i", $home_info["port"], $post_script); $post_script = preg_replace("/\\%query_port\\%/i", $home_info["query_port"], $post_script); $post_script = preg_replace("/\\%incremental\\%/i", $home_info["incremental"], $post_script); } else { $post_script = ""; } #### end of replacememnts if ($state == "start" and $addon_id != "") { $pid = $remote->start_file_download($addon_info['url'], $home_info['home_path'] . "/" . $addon_info['path'], $filename, "uncompress", $post_script); } $headers = get_headers($url, 1); $download_available = !$headers ? FALSE : TRUE; // Check if any error occured if ($download_available) { $bytes = is_array($headers['Content-Length']) ? $headers['Content-Length'][1] : $headers['Content-Length']; // Display the File Size $totalsize = $bytes / 1024; clearstatcache(); } $kbytes = $remote->rsync_progress($home_info['home_path'] . "/" . $addon_info['path'] . "/" . $filename); list($totalsize, $mbytes, $pct) = explode(";", do_progress($kbytes, $totalsize)); $totalmbytes = round($totalsize / 1024, 2); $pct = $pct > 100 ? 100 : $pct; echo "<h2>" . $home_info['home_name'] . "</h2>"; echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" > <h4>' . get_lang('install') . " " . $filename . " {$mbytes}MB/{$totalmbytes}MB</h4>\n\t\t\t <div style='background-color:#dce9f2;' >\n\t\t\t "; $bar = ''; for ($i = 1; $i <= $pct; $i++) { $bar .= '<img style="width:0.92%;vertical-align:middle;" src="images/progressBar.png">'; } echo "<center>{$bar} <b style='vertical-align:top;display:inline;font-size:1.2em;color:red;' >{$pct}%</b></center>\n\t\t\t\t</div>\n\t\t\t </div>"; if (($pct == "100" or !$download_available) and $post_script != "") { $log_retval = $remote->get_log("post_script", $pid, clean_path($home_info['home_path'] . "/" . $server_xml->exe_location), $script_log); if ($log_retval == 0) { print_failure(get_lang('agent_offline')); } elseif ($log_retval == 1 || $log_retval == 2) { echo "<pre class='log'>" . $script_log . "</pre>"; } elseif ($remote->is_screen_running("post_script", $pid) == 1) { print_failure(get_lang_f('unable_to_get_log', $log_retval)); } } if ($pct == "100" or !$download_available or $download_available and $pct == "-" and $pid > 0) { if (!$download_available) { print_failure(get_lang('failed_to_start_file_download')); } elseif ($remote->is_file_download_in_progress($pid) === 1) { print_success(get_lang_f('wait_while_decompressing', $filename)); echo "<p><a href=\"?m=addonsmanager&p=addons&state=refresh&home_id=" . $home_id . "&addon_id={$addon_id}&pid={$pid}\">" . get_lang('refresh') . "</a></p>"; $view->refresh("?m=addonsmanager&p=addons&state=refresh&home_id=" . $home_id . "&addon_id={$addon_id}&pid={$pid}", 5); } elseif ($remote->is_file_download_in_progress($pid) === 0 and $remote->is_screen_running("post_script", $pid) === 0) { print_success(get_lang('addon_installed_successfully')); $view->refresh("?m=addonsmanager&p=user_addons&home_id=" . $home_id, 10); return; } } else { echo "<p><a href=\"?m=addonsmanager&p=addons&state=refresh&home_id=" . $home_id . "&addon_id={$addon_id}&pid={$pid}\">" . get_lang('refresh') . "</a></p>"; $view->refresh("?m=addonsmanager&p=addons&state=refresh&home_id=" . $home_id . "&addon_id={$addon_id}&pid={$pid}", 5); } } elseif (!empty($_GET['addon_type'])) { ?> <h2><?php echo $home_info['home_name'] . " " . get_lang($_GET['addon_type']); ?> </h2> <table class='center'> <form action='?m=addonsmanager&p=addons<?php echo "&ip=" . $_GET['ip'] . "&port=" . $_GET['port']; ?> ' method='post'> <input type='hidden' name='home_id' value='<?php echo "{$home_id}"; ?> ' /> <input type='hidden' name='state' value='start' /> <tr><td align='right'><?php print_lang('game_name'); ?> : </td><td align='left'><?php echo "{$home_info['game_name']}"; ?> </td></tr> <tr><td align='right'><?php print_lang('directory'); ?> : </td><td align='left'><?php echo "{$home_info['home_path']}"; ?> </td></tr> <tr><td align='right'><?php print_lang('remote_server'); ?> : </td> <td align='left'><?php echo "{$home_info['remote_server_name']} ({$home_info['agent_ip']}:{$home_info['agent_port']})"; ?> </td></tr> <tr><td align='right'><?php print_lang('select_addon'); ?> : </td> <td align='left'> <select name="addon_id"> <?php $addons = $db->resultQuery("SELECT addon_id, name FROM OGP_DB_PREFIXaddons WHERE addon_type='" . $_GET['addon_type'] . "' AND home_cfg_id=" . $home_cfg_id); foreach ($addons as $addon) { ?> <option value="<?php echo $addon['addon_id']; ?> "><?php echo $addon['name']; ?> </option> <?php } ?> </select> </td></tr> <tr><td colspan='2' class='info'> </td></tr> <td align='left'> </td></tr><tr><td align="right"> <input type="submit" name="update" value="<?php print_lang('install'); ?> " /> </form></td><td> <form action="" method="get"> <input type="hidden" name="m" value="addonsmanager" /> <input type="hidden" name="p" value="user_addons" /> <input type="hidden" name="home_id" value="<?php echo "{$home_id}"; ?> " /> <input type="submit" value="<?php print_lang('back'); ?> " /> </form> </td></tr> </table> <?php } return; }
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 create_back_button("gamemanager", "gamemanager"); return; } $state = isset($_REQUEST['state']) ? $_REQUEST['state'] : ""; $pid = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : -1; $filename = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : ""; echo "<h2>" . get_lang('install_update_manual') . " {$home_info['home_name']}</h2>"; if (!empty($state)) { $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']); if ($state == "start") { if (isset($_POST['one_dir_down'])) { $home_info['home_path'] .= "/../"; } $pid = $remote->start_file_download($_REQUEST['url'], $home_info['home_path'], $filename, "uncompress"); if ($pid < 0) { print_failure(get_lang("failed_to_start_file_download")); return; } } $url = $_REQUEST['url']; $headers = get_headers($url, 1); $download_available = !$headers ? FALSE : TRUE; // Check if any error occured if ($download_available) { $bytes = is_array($headers['Content-Length']) ? $headers['Content-Length'][1] : $headers['Content-Length']; // Display the File Size $totalsize = $bytes / 1024; clearstatcache(); } $kbytes = $remote->rsync_progress($home_info['home_path'] . "/" . $filename); list($totalsize, $mbytes, $pct) = explode(";", do_progress($kbytes, $totalsize)); $totalmbytes = round($totalsize / 1024, 2); $pct = $pct > 100 ? 100 : $pct; 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 <div style='background-color:#dce9f2;' >\n\t\t\t "; $bar = ''; for ($i = 1; $i <= $pct; $i++) { $bar .= '<img style="width:0.92%;vertical-align:middle;" src="images/progressBar.png">'; } echo "<center>{$bar} <b style='vertical-align:top;display:inline;font-size:1.2em;color:red;' >{$pct}%</b></center>\n\t\t\t\t</div>\n\t\t\t </div>"; if ($remote->is_file_download_in_progress($pid) == 0) { print_success(get_lang('finished_manual_update')); } else { echo "<p><a href=\"?m=gamemanager&p=update_manual&state=refresh&home_id=" . $home_id . "&mod_id={$mod_id}&pid={$pid}&url={$url}&filename={$filename}\">Refresh</a></p>"; $view->refresh("?m=gamemanager&p=update_manual&state=refresh&home_id=" . $home_id . "&mod_id={$mod_id}&pid={$pid}&url={$url}&filename={$filename}", 5); } echo create_back_button($_GET['m'], "game_monitor&home_id=" . $_GET['home_id']); } else { echo "<form action='?m=gamemanager&p=update_manual' method='post'>\n <table class='center'>\n <input type='hidden' name='home_id' value='{$home_id}' />\n <input type='hidden' name='mod_id' value='{$mod_id}' />\n <input type='hidden' name='state' value='start' />\n <tr><td align='right'>" . get_lang('game_name') . ":</td><td align='left'>{$home_info['game_name']}</td></tr>\n <tr><td align='right'>" . get_lang('dest_dir') . ":</td><td align='left'>{$home_info['home_path']}</td></tr>\n <tr><td align='right'>" . get_lang('remote_server') . ":</td>\n <td align='left'>{$home_info['remote_server_name']} ({$home_info['agent_ip']}:{$home_info['agent_port']})</td></tr>\n <tr><td align='right'>" . get_lang('file_url') . ":</td>\n <td align='left'><input type='text' name='url' value='' size='50' /></td></tr>\n <tr><td colspan='2' class='info'>" . get_lang('file_url_info') . "</td></tr>\n <tr><td align='right'>" . get_lang('one_dir_down') . ":</td><td align='left'><input type='checkbox' name='one_dir_down' /></td></tr>\n <tr><td align='right'>" . get_lang('dest_filename') . ":</td>\n <td align='left'><input type='text' name='filename' value='' size='50'/></td></tr>\n <tr><td colspan='2' class='info'>" . get_lang('dest_filename_info') . "</td></tr>\n </table>\n <p><input type='submit' name='update' value='" . get_lang('update_server') . "' /></p>\n </form>"; } 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"); } } }
function exec_ogp_module() { $home_id = $_REQUEST['home_id']; if (empty($home_id)) { print_failure(get_lang('home_id_missing')); return; } global $db, $view; $isAdmin = $db->isAdmin($_SESSION['user_id']); if ($isAdmin) { $home_cfg = $db->getGameHome($home_id); } else { $home_cfg = $db->getUserGameHome($_SESSION['user_id'], $home_id); } if ($home_cfg === FALSE) { print_failure(get_lang('no_access_to_home')); return; } litefm_check($home_id); $remote = new OGPRemoteLibrary($home_cfg['agent_ip'], $home_cfg['agent_port'], $home_cfg['encryption_key']); $os_string = $remote->what_os(); $os = preg_match("/Linux/i", $os_string) ? "linux" : "windows"; echo "<h2>"; echo empty($home_cfg['home_name']) ? get_lang('not_available') : $home_cfg['home_name']; echo "</h2>"; // We must always add the home directory to the fm_cwd so that user // can not go out of the homedir. $path = clean_path($home_cfg['home_path'] . "/" . @$_SESSION['fm_cwd_' . $home_id]); $upload_folder_path = "modules/litefm/uploads/home_id_{$home_id}"; if (isset($_GET['pid']) and $_GET['pid'] != "") { $bytes = $_GET['bytes']; $totalsize = $bytes / 1024; $uploaded_filename = $_GET['uploaded_filename']; $dest_file_path = clean_path($upload_folder_path . "/" . $uploaded_filename . ".txt"); $kbytes = $remote->rsync_progress(clean_path($path . "/" . $uploaded_filename)); list($totalsize, $mbytes, $pct) = explode(";", do_progress($kbytes, $totalsize)); $totalmbytes = round($totalsize / 1024, 2); $pct = $pct > 100 ? 100 : $pct; if ($pct > 0) { echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" > <h4>' . get_lang('upload') . " " . $uploaded_filename . " {$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 "<center>{$bar} <b style='vertical-align:top;display:inline;font-size:1.2em;color:red;' >{$pct}%</b></center>\n\t\t\t\t\t</div>\n\t\t\t\t </div>"; } $pid = $_GET['pid']; if ($remote->is_file_download_in_progress($pid) == 0) { unlink($dest_file_path); $directory = dir($upload_folder_path); $directory_not_empty = FALSE; while (FALSE !== ($item = $directory->read()) && !isset($directory_not_empty)) { if ($item != '.' && $item != '..') { $directory_not_empty = TRUE; } } $directory->close(); if (!$directory_not_empty) { rmdir($upload_folder_path); } print_success(print_lang('upload_complete')); $db->logger(get_lang('upload_complete') . " ( " . clean_path($path . "/" . $uploaded_filename) . " )"); $view->refresh('?m=litefm&home_id=' . $home_id, 2); return; } else { print_success(print_lang('upload_in_progress')); $view->refresh('?m=litefm&home_id=' . $home_id . "&uploaded_filename={$uploaded_filename}&bytes={$bytes}&pid={$pid}&upload=true", 2); return; } } else { echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id=" . $home_cfg['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; $POST_MAX_SIZE = ini_get('post_max_size'); $mul = substr($POST_MAX_SIZE, -1); $mul = $mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)); if (isset($_GET['upload']) && $_GET['upload'] == "true" && $_SERVER['CONTENT_LENGTH'] > $mul * (int) $POST_MAX_SIZE && $POST_MAX_SIZE) { print_failure(get_lang_f('upload_failed', '( php.ini: upload_max_filesize = ' . ini_get('upload_max_filesize') . ", post_max_size = " . ini_get('post_max_size') . ", memory_limit = " . ini_get('memory_limit') . ' )')); } if (isset($_POST['upload'])) { if (isset($_FILES['uploaded_file'])) { $bytes = $_FILES['uploaded_file']['size']; $bad_chars = preg_replace("/([[:alnum:]_\\.-]*)/", "", $_FILES['uploaded_file']['name']); $bad_arr = str_split($bad_chars); $uploaded_filename = str_replace($bad_arr, "", $_FILES['uploaded_file']['name']); $dest_file_path = clean_path($upload_folder_path . "/" . $uploaded_filename . ".txt"); $s = isset($_SERVER['HTTPS']) ? "s" : ""; $p = isset($_SERVER['SERVER_PORT']) & $_SERVER['SERVER_PORT'] != "80" ? ":" . $_SERVER['SERVER_PORT'] : NULL; $url = 'http' . $s . '://' . $_SERVER['SERVER_NAME'] . $p . $_SERVER['SCRIPT_NAME']; $file_url = str_replace("home.php", $dest_file_path, $url); if ($_FILES['uploaded_file']['error'] > 0) { print_failure(get_lang_f('upload_failed'), $_FILES['uploaded_file']['error']); } else { if (!file_exists($upload_folder_path)) { if (!mkdir($upload_folder_path, 0777, true)) { print_failure(get_lang_f('can_not_create_upload_folder_path'), $upload_folder_path); } } if (file_exists($dest_file_path)) { unlink($dest_file_path); } move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], $dest_file_path); if (file_exists($dest_file_path)) { $remote_file_path = clean_path($path . "/" . $uploaded_filename); if ($remote->rfile_exists($remote_file_path)) { $remote->exec('rm -f ' . $remote_file_path); } $uncompress = isset($_POST['uncompress']) ? "uncompress" : ""; $pid = $remote->start_file_download($file_url, $path, $uploaded_filename, $uncompress); if ($remote->is_file_download_in_progress($pid) < 0) { print_failure(get_lang_f('upload_failed', get_lang_f('url_is_not_accesible_from_agent', $file_url))); } else { $view->refresh('?m=litefm&home_id=' . $home_id . "&uploaded_filename={$uploaded_filename}&bytes={$bytes}&pid={$pid}&upload=true", 1); } } } } } if (isset($_POST['create_folder'])) { $bad_chars = preg_replace("/([[:alnum:]_\\.-]*)/", "", $_POST['folder_name']); $bad_arr = str_split($bad_chars); $folder_name = str_replace($bad_arr, "", $_POST['folder_name']); $remote->exec('mkdir ' . clean_path($path . "/" . $folder_name)); $db->logger(get_lang('create_folder') . " " . clean_path($path . "/" . $folder_name)); } if (isset($_POST['delete'])) { if (!isset($_POST['delete_check'])) { echo "<table class='center' style='width:100%;' ><tr>\n" . "<td>" . get_lang_f('delete_item', clean_path($path . "/" . $_POST['delete'])) . "</td>" . "</tr><tr><td>" . '<form action="?m=litefm&home_id=' . $home_id . '" method="post" enctype="multipart/form-data">' . "\n" . '<input type="hidden" name="delete" value="' . $_POST['delete'] . '">' . "\n" . '<button name="delete_check" value="yes" >' . get_lang('yes') . "</button>\n" . '<button name="delete_check" value="no" >' . get_lang('no') . "</button>\n" . "</form>\n" . "</td>\n" . "</tr>\n" . "</table>\n"; } elseif ($_POST['delete_check'] == "yes") { $remote->exec('rm -Rf "' . clean_path($path . "/" . $_POST['delete']) . '"'); $db->logger('rm -Rf "' . clean_path($path . "/" . $_POST['delete']) . '"'); } } // Chattr Check if (isset($_POST['secureButton'])) { if (!isset($_POST['secure_check'])) { echo "<table class='center' style='width:100%;' ><tr>\n" . "<td>" . get_lang_f('secure_item', clean_path($path . "/" . $_POST['secureFile'])) . "</td>" . "</tr><tr><td>" . '<form action="?m=litefm&home_id=' . $home_id . '" method="post" >' . "\n" . '<input type="hidden" name="secureFile" value="' . $_POST['secureFile'] . '">' . "\n" . '<input type="hidden" name="secureButton" value="' . $_POST['secureButton'] . '">' . "\n" . '<button name="secure_check" value="yes" >' . get_lang('yes') . "</button>\n" . '<button name="secure_check" value="no" >' . get_lang('no') . "</button>\n" . "</form>\n" . "</td>\n" . "</tr>\n" . "</table>\n"; } elseif ($_POST['secure_check'] == "yes") { $chatAction = $_POST['secureButton']; if ($chatAction == get_lang('chattr_yes')) { $action = 'chattr+i'; } else { $action = 'chattr-i'; } $pathToFile = clean_path($path . "/" . $_POST['secureFile']); $remote->secure_path($action, $pathToFile); if ($action == 'chattr+i') { $db->logger(get_lang('chattr_locked') . ": {$pathToFile}"); } else { $db->logger(get_lang('chattr_unlocked') . ": {$pathToFile}"); } } } echo "<table class='center' style='width:100%;' ><tr>\n" . "<td colspan='3' ><h3>" . get_lang_f('currently_viewing', $path) . "</h3></td>" . "</tr><tr><td style='border:1px solid gray;'>" . get_lang('upload_file') . ':<form action="?m=litefm&home_id=' . $home_id . '&upload=true" method="post" enctype="multipart/form-data">' . "\n" . '<input type="file" name="uploaded_file" id="file">' . "\n" . '<input type="checkbox" name="uncompress" value="true"> ' . get_lang('uncompress') . "\n" . '<input type="submit" name="upload" value="' . get_lang('upload') . '">' . "\n" . "</form>\n" . "</td>\n" . "<td>\n" . " " . "</td>\n" . "<td style='border:1px solid gray;' >\n" . get_lang('create_folder') . ':<form action="?m=litefm&home_id=' . $home_id . '&create_folder=true" method="post" >' . "\n" . '<input type="text" name="folder_name" />' . "\n" . '<input type="submit" name="create_folder" value="' . get_lang('create') . '"/>' . "\n" . "</form>\n" . "</td></tr>\n" . "</table>\n"; if (!$remote->rfile_exists($path)) { $path = clean_path($home_cfg['home_path']); if (!$remote->rfile_exists($path)) { print_failure(get_lang_f("dir_not_found", $path)); } else { $_SESSION['fm_cwd_' . $home_id] = str_replace("\\", "", dirname($_SESSION['fm_cwd_' . $home_id])); echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=?m=litefm&home_id=' . $home_id . '">'; } } else { $dirlist = $remote->remote_dirlistfm($path); if ($os == "linux") { $lsattr = $remote->exec('lsattr ' . $path); } if (!is_array($dirlist)) { if ($dirlist === -1) { if ($path != $home_cfg['home_path'] . "/") { echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=?m=litefm&home_id=' . $home_id . '">'; } else { print_failure('Your game server\'s home path is too long or there is a file with a very long name inside of your game server\'s home folder.'); } } else { if ($remote->rfile_exists($path)) { if (strpos($path, '/') !== FALSE) { $ePath = explode('/', $path); $filename = end($ePath); } else { if (strpos($path, '\\') !== FALSE) { $ePath = explode('\\', $path); $filename = end($ePath); } } $_SESSION['fm_cwd_' . $home_id] = str_replace("\\", "", dirname($_SESSION['fm_cwd_' . $home_id])); echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=?m=litefm&home_id=' . $home_id . '&path=' . $filename . '&p=read_file">'; } else { print_failure(get_lang("failed_list")); } } return; } if (empty($dirlist)) { print_lang('empty_directory'); echo "<table class='center' style='width:100%;' >\n" . show_back($home_id) . "</table>"; } else { echo "<table class='center' style='width:100%;' >\n" . show_back($home_id) . "<tr><td style='width:10px;' ></td><td align=left>\n" . get_lang('filename') . "</td>"; if ($os == "linux") { echo "<td>" . get_lang('filesecure') . "</td>"; } echo "<td>" . get_lang('filesize') . " [" . get_lang('bytes') . "]</td><td>" . get_lang('owner') . " " . get_lang('group') . "</td></tr>\n"; $directorys = array(); $files = array(); $binarys = array(); foreach ($dirlist as $item) { # dirlist FM returns an array. Each element has 5 fields separated by the | character list($filename, $size, $user, $group, $type) = explode("|", $item); $filepath = str_replace("/", "\\/", clean_path($path . "/" . $filename)); if ($os == "linux") { preg_match('/(\\S+)\\s' . $filepath . '/', $lsattr, $file_attributes); } // Directory if ($type == 'D') { $directorys[$filename]['filename'] = $filename; $directorys[$filename]['user'] = $user; $directorys[$filename]['group'] = $group; } elseif ($type == 'F') { $files[$filename]['filename'] = $filename; $files[$filename]['size'] = $size; $files[$filename]['user'] = $user; $files[$filename]['group'] = $group; if ($os == "linux") { $files[$filename]['attr'] = $file_attributes[1]; } } elseif ($type == 'B') { $binarys[$filename]['filename'] = $filename; $binarys[$filename]['size'] = $size; $binarys[$filename]['user'] = $user; $binarys[$filename]['group'] = $group; if ($os == "linux") { $binarys[$filename]['attr'] = $file_attributes[1]; } } } foreach ($directorys as $directory) { echo "<tr>\n" . "<td>" . '<form method=POST>' . "<input type=hidden name='delete' value='" . $directory['filename'] . "' class='item' />\n" . '<input type="image" style="width:12px;padding-left:5px;" src="modules/administration/images/remove.gif" />' . "</form>\n" . "</td>" . "<td align=left>" . "<img class=\"viewitem\" src=\"images/folder.png\" alt=\"Directory\" /> " . "<a href=\"?m=litefm&home_id={$home_id}&path=" . $directory['filename'] . "\">" . $directory['filename'] . "</a></td>"; if ($os == "linux") { echo "<td>-</td>"; } echo "<td>-</td> <td>" . $directory['user'] . " " . $directory['group'] . "</td>\n" . "</tr>\n"; } foreach ($files as $file) { if ($os == "linux") { if ($isAdmin) { $secureFile = '<td><form method=POST>'; $secureFile .= "<input type=hidden name='secureFile' value='" . $file['filename'] . "' class='item' />\n"; if (preg_match("/i/", $file['attr'])) { $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_no') . "' class='item' />\n"; } else { $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_yes') . "' class='item' />\n"; } $secureFile .= '</form></td>'; } else { $secureFile = "<td><span class="; if (preg_match("/i/", $file['attr'])) { $secureFile .= "'chattrLock'>" . get_lang('chattr_locked'); } else { $secureFile .= "'chattrUnlock'>" . get_lang('chattr_unlocked'); } $secureFile .= "</span></td>\n"; } } else { $secureFile = ""; } echo "<tr>\n" . "<td>" . '<form method=POST>' . "<input type=hidden name='delete' value='" . $file['filename'] . "' class='item' />\n" . '<input type="image" style="width:12px;padding-left:5px;" src="modules/administration/images/remove.gif" />' . "</form>\n" . "</td>" . "<td align=left>"; echo "<img class=\"viewitem\" src=\"images/txt.png\" alt=\"Text file\" /> " . "<a href=\"?m=litefm&home_id={$home_id}&path=" . $file['filename'] . "&p=read_file\">" . get_lang("button_edit") . "</a>" . $file['filename'] . "</td>\n\t\t\t\t\t\t {$secureFile}<td>" . $file['size'] . "</td> <td>" . $file['user'] . " " . $file['group'] . "</td>\n"; echo "</tr>\n"; } foreach ($binarys as $binary) { if ($os == "linux") { if ($isAdmin) { $secureFile = '<td><form method=POST>'; $secureFile .= "<input type=hidden name='secureFile' value='" . $binary['filename'] . "' class='item' />\n"; if (preg_match("/i/", $binary['attr'])) { $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_no') . "' class='item' />\n"; } else { $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_yes') . "' class='item' />\n"; } $secureFile .= '</form></td>'; } else { $secureFile = "<td><span class="; if (preg_match("/i/", $binary['attr'])) { $secureFile .= "'chattrLock'>" . get_lang('chattr_locked'); } else { $secureFile .= "'chattrUnlock'>" . get_lang('chattr_unlocked'); } $secureFile .= "</span></td>\n"; } } else { $secureFile = ""; } echo "<tr>\n" . "<td>" . '<form method=POST>' . "<input type=hidden name='delete' value='" . $binary['filename'] . "' class='item' />\n" . '<input type="image" style="width:12px;padding-left:5px;" src="modules/administration/images/remove.gif" />' . "</form>\n" . "</td>" . "<td align=left>"; echo "<img class=\"viewitem\" src=\"images/exec.png\" alt=\"Binary file\" /> " . $binary['filename'] . "</td>\n\t\t\t\t\t\t {$secureFile}<td>" . $binary['size'] . "</td><td>" . $binary['user'] . " " . $binary['group'] . "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; } } } echo "<table class='center'><tr><td><a href='?m=gamemanager&p=game_monitor&home_id=" . $home_cfg['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>"; }