예제 #1
0
function exec_ogp_module()
{
    global $db;
    global $view;
    $user_id = $_GET['user_id'];
    $y = isset($_GET['y']) ? $_GET['y'] : "";
    $user = $db->getUserById($user_id);
    if (empty($user)) {
        print_failure(get_lang_f('user_with_id_does_not_exist', $user_id));
        return;
    }
    $username = $user['users_login'];
    if ($y !== 'y') {
        if (!$db->isModuleInstalled("subusers")) {
            echo "<p>" . get_lang_f('are_you_sure_you_want_to_delete_user', $username) . "</p>";
        } else {
            if (!$db->isSubUser($user_id)) {
                echo "<p>" . get_lang_f('are_you_sure_you_want_to_delete_user', $username) . get_lang('andSubUsers') . "</p>";
            } else {
                echo "<p>" . get_lang_f('are_you_sure_you_want_to_delete_user', $username) . "</p>";
            }
        }
        echo "<p><a href=\"?m=user_admin&amp;p=del&amp;user_id={$user_id}&amp;y=y\">" . get_lang('yes') . "</a> <a href=\"?m=user_admin\">" . get_lang('no') . "</a></p>";
        return;
    }
    if (!$db->delUser($user_id)) {
        print_failure(get_lang_f('unable_to_delete_user', $username));
        $view->refresh("?m=user_admin");
        return;
    }
    print_success(get_lang_f('successfully_deleted_user', $username));
    $db->logger(get_lang_f('successfully_deleted_user', $username));
    $view->refresh("?m=user_admin");
}
function exec_ogp_module()
{
    global $db;
    global $view;
    $group_id = $_GET['group_id'];
    if (!$db->isAdmin($_SESSION['user_id'])) {
        $result = $db->getUserGroupList($_SESSION['user_id']);
        foreach ($result as $row) {
            if ($row['group_id'] == $group_id) {
                $own_group = TRUE;
            }
        }
    }
    if (!$db->isAdmin($_SESSION['user_id']) && !isset($own_group)) {
        echo "<p class='note'>" . get_lang('not_available') . "</p>";
        return;
    }
    // Delete user from group.
    if (isset($_GET['group_id']) && isset($_GET['user_id'])) {
        $group_id = trim($_GET['group_id']);
        $user_id = trim($_GET['user_id']);
        if (!$db->delUserFromGroup($user_id, $group_id)) {
            print_failure(get_lang_f('could_not_delete_user_from_group', $user_id, $group_id));
            $view->refresh("?m=user_admin");
            return;
        }
        echo "<p class='success'>" . get_lang_f('successfully_removed_from_group', $user_id, $group_id) . "</p>";
        $db->logger(get_lang_f('successfully_removed_from_group', $user_id, $group_id));
        $view->refresh("?m=user_admin&amp;p=show_groups");
    }
}
function exec_ogp_module()
{
    global $db;
    global $view;
    $group_id = $_REQUEST['group_id'];
    if (!$db->isAdmin($_SESSION['user_id'])) {
        $result = $db->getUserGroupList($_SESSION['user_id']);
        foreach ($result as $row) {
            if ($row['group_id'] == $group_id) {
                $own_group = TRUE;
            }
        }
    }
    if (!$db->isAdmin($_SESSION['user_id']) && !isset($own_group)) {
        echo "<p class='note'>" . get_lang('not_available') . "</p>";
        return;
    }
    if (isset($_POST['add_user_to_group'])) {
        $group_id = trim($_POST['group_id']);
        $user_id = trim($_POST['user_to_add']);
        $username = $db->getUserById($user_id);
        $group_name = $db->getGroupById($group_id);
        if (!$db->addUsertoGroup($user_id, $group_id)) {
            print_failure(get_lang_f('could_not_add_user_to_group', $username['users_login'], $group_name['group_name']));
            $view->refresh("?m=user_admin&amp;p=show_groups");
            return;
        }
        echo "<p class='success'>" . get_lang_f('successfully_added_to_group', $username['users_login'], $group_name['group_name']) . "</p>";
        $db->logger(get_lang_f('successfully_added_to_group', $username['users_login'], $group_name['group_name']));
        $view->refresh("?m=user_admin&amp;p=show_groups");
    }
}
예제 #4
0
function exec_ogp_module()
{
    global $view;
    global $db;
    #This will add a remote host to the list
    if (isset($_REQUEST['add_remote_host'])) {
        $rhost_ip = trim($_POST['remote_host']);
        $rhost_name = trim($_POST['remote_host_name']);
        $rhost_user_name = trim($_POST['remote_host_user_name']);
        $rhost_port = trim($_POST['remote_host_port']);
        $rhost_ftp_ip = trim($_POST['remote_host_ftp_ip']);
        $rhost_ftp_port = trim($_POST['remote_host_ftp_port']);
        $encryption_key = trim($_POST['remote_encryption_key']);
        $timeout = trim($_POST['timeout']);
        $use_nat = trim($_POST['use_nat']);
        if (empty($rhost_ip)) {
            print_failure(get_lang('enter_ip_host'));
            $view->refresh("?m=server");
            return;
        }
        if (empty($rhost_user_name)) {
            print_failure(get_lang('enter_unix_user_name'));
            $view->refresh("?m=server");
            return;
        }
        if (!isPortValid($rhost_port)) {
            print_failure(get_lang('enter_valid_ip'));
            $view->refresh("?m=server");
            return;
        }
        $rhost_id = $db->addRemoteServer($rhost_ip, $rhost_name, $rhost_user_name, $rhost_port, $rhost_ftp_ip, $rhost_ftp_port, $encryption_key, $timeout, $use_nat);
        if (!$rhost_id) {
            print_failure("" . get_lang('could_not_add_server') . " " . $rhost_ip . " " . get_lang('to_db') . "");
            $view->refresh("?m=server");
            return;
        }
        print_success("" . get_lang('added_server') . " {$rhost_ip} " . get_lang('with_port') . " {$rhost_port} " . get_lang('to_db_succesfully') . "");
        require_once 'includes/lib_remote.php';
        $remote = new OGPRemoteLibrary($rhost_ip, $rhost_port, $encryption_key);
        $iplist = $remote->discover_ips();
        if (empty($iplist)) {
            print_failure("" . get_lang('unable_discover') . " " . $rhost_ip . ". " . get_lang('set_ip_manually') . "");
        } else {
            print_success("" . get_lang('found_ips') . " (" . implode(",", $iplist) . ") " . get_lang('for_remote_server') . "");
            foreach ($iplist as $remote_ip) {
                $remote_ip = trim($remote_ip);
                if (empty($remote_ip)) {
                    continue;
                }
                if (!$db->addRemoteServerIp($rhost_id, $remote_ip)) {
                    print_failure("" . get_lang('failed_add_ip') . " (" . $remote_ip . ") " . get_lang('for_remote_server') . "");
                }
            }
        }
        $view->refresh("?m=server");
        return;
    }
}
function exec_ogp_module()
{
    global $db;
    global $view;
    print "<h2>" . get_lang_f('uninstalling_module', $_REQUEST['module']) . "</h2>";
    require_once 'modules/modulemanager/module_handling.php';
    if (isset($_REQUEST['id']) && isset($_REQUEST['module']) && uninstall_module($db, $_REQUEST['id'], $_REQUEST['module']) === TRUE) {
        print_success(get_lang_f("successfully_uninstalled_module", $_REQUEST['module']));
    } else {
        print_failure(get_lang_f("failed_to_uninstall_module", $_REQUEST['module']));
    }
    $view->refresh("?m=modulemanager");
}
예제 #6
0
function heading()
{
    global $db, $view, $settings;
    if (!file_exists(CONFIG_FILE)) {
        print_failure(get_lang('failed_to_read_config'));
        $view->refresh("index.php");
        return;
    }
    // Start Output Buffering
    if (!isset($_SESSION['users_login'])) {
        print_failure(get_lang('invalid_login_information'));
        echo "<p class='note' style='color:red;'>" . get_lang('invalid_redirect') . "...</p>";
        echo "<meta http-equiv='refresh' content='2;url=index.php'";
        return;
    } else {
        $info = $db->getUser($_SESSION['users_login']);
        $chk_expire = $info['user_expires'];
        $exptime = read_expire($chk_expire);
        if ($exptime != "X") {
            list($days, $strd, $hours, $strh, $minutes, $strm) = explode(" ", $exptime);
            $minutes2expire = $minutes + intval($hours * 60) + intval($days * 24 * 60);
            if ($minutes2expire <= 0) {
                echo "<h1>" . get_lang('account_expired') . "</h1>";
                echo "<p class='note'>" . get_lang('contact_admin_to_enable_account') . "</p>";
                session_destroy();
                return;
            }
        }
        if (isset($settings['maintenance_mode']) && $settings['maintenance_mode'] == "1") {
            if ($_SESSION['users_group'] == "user") {
                echo "<h2>" . $settings['maintenance_title'] . "</h2>";
                echo "<p>" . $settings['maintenance_message'] . "</p>";
                $view->setTitle("OGP: Maintenance.");
                echo "<p class='failure'>" . get_lang('logging_out_10') . "...</p>";
                echo "<meta http-equiv='refresh' content='10;url=index.php'";
                session_destroy();
                return;
            }
        }
        if (isset($_REQUEST['logout'])) {
            session_destroy();
            print_success(get_lang('logout_message'));
            $view->refresh("index.php");
            return;
        }
        include "includes/navig.php";
    }
    if (isset($maintenance)) {
        echo $maintenance;
    }
}
function read_server_config($filename)
{
    $dom = new DOMDocument();
    if ($dom->load($filename) === FALSE) {
        print_failure(get_lang_f('unable_to_load_xml', $filename));
        return FALSE;
    }
    if ($dom->schemaValidate(XML_SCHEMA) != TRUE) {
        print_failure(get_lang_f('xml_file_not_valid', $filename, XML_SCHEMA));
        return FALSE;
    }
    $xml = simplexml_load_file($filename);
    $xml->addChild('home_cfg_file', basename($filename));
    return $xml;
}
예제 #8
0
function exec_ogp_module()
{
    require_once MODULES . "/litefm/litefm.php";
    $home_id = $_REQUEST['home_id'];
    if (empty($home_id)) {
        print_failure(get_lang('home_id_missing'));
        return;
    }
    if (litefm_check($home_id) === FALSE) {
        return;
    }
    global $db;
    $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;
    }
    echo "<table class='center' style='width:100%;'>" . show_back($home_id) . "</table>";
    //Logic to open the file we're editing
    $remote = new OGPRemoteLibrary($home_cfg['agent_ip'], $home_cfg['agent_port'], $home_cfg['encryption_key']);
    $data = "";
    $file_info = $remote->remote_readfile($home_cfg['home_path'] . "/" . $_SESSION['fm_cwd_' . $home_id], $data);
    if ($file_info === 0) {
        print_failure(get_lang("not_found"));
        return;
    } else {
        if ($file_info === -1) {
            print_failure(get_lang("agent_offline"));
            return;
        } else {
            if ($file_info === -2) {
                print_failure(get_lang("failed_read"));
                return;
            }
        }
    }
    echo "<form action='?m=litefm&amp;p=write_file' method='post'>";
    echo "<input type='hidden' name='home_id' value='{$home_id}' />";
    echo "<textarea name='file_content' style='width:98%;' rows='40'>{$data}</textarea>";
    echo "<p><input type='submit' name='save_file' value='" . get_lang('save') . "' /></p>";
    echo "</form>";
    show_back($home_id);
}
예제 #9
0
function exec_ogp_module()
{
    global $db, $view, $settings;
    if (is_readable("includes/config.inc.php")) {
        require "includes/config.inc.php";
    }
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if ($isAdmin) {
        $user_homes = $db->getIpPorts();
    } else {
        $user_homes = $db->getIpPortsForUser($_SESSION['user_id']);
    }
    echo "<h2>" . get_lang('ftp') . "</h2>";
    if ($user_homes === FALSE) {
        // If there are no games, then there can not be any mods either.
        print_failure('No game homes assigned');
        if ($isAdmin) {
            echo "<p><a href='?m=user_games&amp;p=assign&amp;user_id={$_SESSION['user_id']}'>Assign game homes</a></p>";
        }
        return;
    }
    if (empty($_GET['home_id'])) {
        unset($_GET['home_id']);
    }
    if (!isset($_GET['home_id'])) {
        create_home_selector($_GET['m'], FALSE, $user_homes);
        $show_all = TRUE;
    } else {
        create_home_selector($_GET['m'], FALSE, $user_homes);
        create_home_selector($_GET['m'], FALSE, "show_all");
        $show_all = FALSE;
    }
    if (isset($_GET['home_id'])) {
        $_SESSION['home_id'] = $_GET['home_id'];
    }
    $_SESSION['time_zone'] = $settings['time_zone'];
    ?>
	<IFRAME SRC="modules/ftp/index.php<?php 
    if (isset($_GET['home_id'])) {
        echo "?home_id=" . $_GET['home_id'];
    }
    ?>
" ALIGN=center WIDTH=100% HEIGHT=460 style="border:1px solid transparent;background-color:white" >
	</IFRAME>
	<?php 
    if ($show_all == FALSE) {
        echo "<form action='' method='get'>\n\t\t\t  <input type='hidden' name='m' value='gamemanager' />\n\t\t\t  <input type='hidden' name='p' value='game_monitor' />\n\t\t\t  <input type='hidden' name='home_id' value='" . $_GET['home_id'] . "' />\n\t\t\t  <input type='submit' value='" . get_lang('back') . "' />\n\t\t\t  </form>";
예제 #10
0
function exec_ogp_module()
{
    echo "<h2>" . get_lang('ban_list') . "</h2>";
    global $db;
    if (isset($_POST['unban'])) {
        unset($_POST['unban']);
        foreach ($_POST as $name => $ip) {
            $db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='0', banned_until='0' WHERE client_ip = '{$ip}';");
        }
    }
    $ban_list = $db->resultQuery("SELECT logging_attempts, banned_until, client_ip FROM `OGP_DB_PREFIXban_list`;");
    $ban_qty = 0;
    $ban_table = '';
    foreach ($ban_list as $ban) {
        if ($ban['logging_attempts'] >= 3) {
            $ban_table .= "<tr><td><input type=checkbox name='" . $ban_qty . "' value='" . $ban['client_ip'] . "' /></td><td>" . $ban['client_ip'] . "</td><td>" . date("r", $ban['banned_until']) . "</td></tr>\n";
            $ban_qty++;
        } else {
            continue;
        }
    }
    if ($ban_qty == 0) {
        print_failure(get_lang('no_banned_ips'));
    } else {
        echo "<form method=post >\n" . "<table><tr><th><span id=check >" . get_lang('unban') . "</span></th><th>" . get_lang('client_ip') . "</th><th>" . get_lang('banned_until') . "</th></tr>\n" . $ban_table . "</table>\n" . "<input type=submit name=unban value='" . get_lang('unban_selected_ips') . "' /></form>";
        ?>
		<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
		<script type="text/javascript">
		$('span#check').css({'cursor':'pointer','color':'blue'});
		$('span#check').click(function(){
			$('input[type=checkbox]').each(function( ){
				if( this.checked )
				{
					$(this).attr('checked', false);
				}
				else
				{
					$(this).attr('checked', true);
				}
			});
		});
		</script>
		<?php 
    }
    echo create_back_button($_GET['m'], "main");
}
예제 #11
0
function litefm_check($home_id)
{
    if (isset($_GET['path']) and !isset($_GET['upload']) and !isset($_POST['delete']) and !isset($_POST['create_folder']) and !isset($_POST['secureButton']) and !isset($_POST['delete_check']) and !isset($_POST['secure_check'])) {
        $path = $_GET['path'];
        // Make sure nobody tries to get outside thier game server by referencing the .. directory
        if (preg_match("/\\.\\.|\\||;/", $path)) {
            print_failure(get_lang("unallowed_char"));
            $_SESSION['fm_cwd_' . $home_id] = NULL;
            return FALSE;
        } else {
            $_SESSION['fm_cwd_' . $home_id] = @$_SESSION['fm_cwd_' . $home_id] . "/" . $path;
        }
    }
    // To go back a dir, we just use dirname to strip the last directory or file off the path
    if (isset($_GET['back']) and !isset($_GET['upload']) and !isset($_POST['delete']) and !isset($_POST['create_folder']) and !isset($_POST['secureButton']) and !isset($_POST['delete_check']) and !isset($_POST['secure_check'])) {
        $_SESSION['fm_cwd_' . $home_id] = str_replace("\\", "", dirname($_SESSION['fm_cwd_' . $home_id]));
    }
    return TRUE;
}
예제 #12
0
function exec_ogp_module()
{
    global $db;
    global $view;
    if (isset($_POST['add_group'])) {
        $group = trim($_POST['group_name']);
        if (empty($group)) {
            print_failure(get_lang('group_name_empty'));
            return;
        }
        if (!$db->addGroup($group, $_SESSION['user_id'])) {
            print_failure(get_lang_f("failed_to_add_group", $group));
            $view->refresh("?m=user_admin&amp;p=show_groups");
            return;
        }
        print_success(get_lang_f('successfully_added_group', $group));
        $db->logger(get_lang_f('successfully_added_group', $group));
        $view->refresh("?m=user_admin&amp;p=show_groups");
    }
}
예제 #13
0
function exec_ogp_module()
{
    global $view;
    global $db;
    echo "<h2>" . get_lang('view_log') . "</h2>";
    $rhost_id = @$_REQUEST['rhost_id'];
    $remote_server = $db->getRemoteServer($rhost_id);
    $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
    if (isset($_POST['save_file'])) {
        $file_info = $remote->remote_writefile('./ogp_agent.log', $_REQUEST['file_content']);
        if ($file_info === 1) {
            print_success(get_lang('wrote_changes'));
        } else {
            if ($file_info === 0) {
                print_failure(get_lang('failed_write'));
            } else {
                print_failure(get_lang("agent_offline"));
            }
        }
    }
    $data = "";
    $file_info = $remote->remote_readfile('./ogp_agent.log', $data);
    if ($file_info === 0) {
        print_failure(get_lang("not_found"));
        return;
    } else {
        if ($file_info === -1) {
            print_failure(get_lang("agent_offline"));
            return;
        } else {
            if ($file_info === -2) {
                print_failure(get_lang("failed_read"));
                return;
            }
        }
    }
    echo "<form action='?m=server&amp;p=log&amp;rhost_id=" . $rhost_id . "' method='post'>";
    echo "<textarea name='file_content' style='width:98%;' rows='40'>{$data}</textarea>";
    echo "<p><input type='submit' name='save_file' value='Save' /></p>";
    echo "</form>";
}
예제 #14
0
function exec_ogp_module()
{
    global $db;
    global $view;
    print "<h2>" . get_lang_f('installing_module', $_REQUEST['module']) . "</h2>";
    require_once 'modules/modulemanager/module_handling.php';
    $install_retval = -99;
    if (isset($_REQUEST['module'])) {
        $install_retval = install_module($db, $_REQUEST['module']);
    }
    if ($install_retval > 0) {
        print_success(get_lang_f("successfully_installed_module", $_REQUEST['module']));
    } else {
        if ($install_retval == 0) {
            print_success(get_lang_f("module_already_installed", $_REQUEST['module']));
        } else {
            print_failure(get_lang_f("failed_to_install_module", $_REQUEST['module']));
        }
    }
    $view->refresh("?m=modulemanager");
}
예제 #15
0
function exec_ogp_module()
{
    global $db;
    global $view;
    $group_id = $_GET['group_id'];
    if (!$db->isAdmin($_SESSION['user_id'])) {
        $result = $db->getUserGroupList($_SESSION['user_id']);
        foreach ($result as $row) {
            if ($row['group_id'] == $group_id) {
                $own_group = TRUE;
            }
        }
    }
    if (!$db->isAdmin($_SESSION['user_id']) && !isset($own_group)) {
        echo "<p class='note'>" . get_lang('not_available') . "</p>";
        return;
    }
    $y = isset($_GET['y']) ? $_GET['y'] : "";
    $group = $db->getGroupById($group_id);
    if (empty($group)) {
        print_failure(get_lang_f('group_with_id_does_not_exist', $group_id));
        return;
    }
    $groupname = $group['group_name'];
    if ($y !== 'y') {
        echo "<p>" . get_lang_f('are_you_sure_you_want_to_delete_group', $groupname) . "</p>";
        echo "<p><a href=\"?m=user_admin&amp;p=del_group&amp;group_id={$group_id}&amp;y=y\">" . get_lang('yes') . "</a> <a href=\"?m=user_admin&amp;p=show_groups\">" . get_lang('no') . "</a></p>";
        return;
    }
    if (!$db->delGroup($group_id)) {
        print_failure(get_lang_f('unable_to_delete_group', $groupname));
        $view->refresh("?m=user_admin&amp;p=show_groups");
        return;
    }
    print_success(get_lang_f('successfully_deleted_group', $groupname));
    $db->logger(get_lang_f('successfully_deleted_group', $groupname));
    $view->refresh("?m=user_admin&amp;p=show_groups");
}
예제 #16
0
function exec_ogp_module()
{
    global $db;
    global $view;
    $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : "";
    $user_id = $_SESSION['user_id'];
    // Check if user has some games.
    $isAdmin = $db->isAdmin($user_id);
    if ($isAdmin) {
        $home_info = $db->getGameHome($home_id);
    } else {
        $home_info = $db->getUserGameHome($user_id, $home_id);
    }
    $home_cfg_id = $home_info['home_cfg_id'];
    if ($home_info) {
        echo "<h2>" . get_lang('user_addons') . ": " . $home_info['home_name'] . "</h2>\n\t\t\t\t <table class='center' >\n\t\t\t\t  <tr><td>";
        $plugins = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name FROM OGP_DB_PREFIXaddons  NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE addon_type='plugin' AND home_cfg_id=" . $home_cfg_id);
        $plugins_qty = count($plugins);
        if ($plugins and $plugins_qty >= 1) {
            echo "<a href='?m=addonsmanager&amp;p=addons&amp;home_id=" . $home_id . "&amp;mod_id=" . $home_info['mod_id'] . "&amp;home_cfg_id=" . $home_cfg_id . "&amp;addon_type=plugin&amp;ip=" . $_GET['ip'] . "&amp;port=" . $_GET['port'] . "'>" . get_lang('install_plugin') . "(" . $plugins_qty . ")</a>";
        }
        $mappacks = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name FROM OGP_DB_PREFIXaddons  NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE addon_type='mappack' AND home_cfg_id=" . $home_cfg_id);
        $mappacks_qty = count($mappacks);
        if ($mappacks and $mappacks_qty >= 1) {
            echo "</td><td>";
            echo "<a href='?m=addonsmanager&amp;p=addons&amp;home_id=" . $home_id . "&amp;mod_id=" . $home_info['mod_id'] . "&amp;home_cfg_id=" . $home_cfg_id . "&amp;addon_type=mappack&amp;ip=" . $_GET['ip'] . "&amp;port=" . $_GET['port'] . "'>" . get_lang('install_mappack') . "(" . $mappacks_qty . ")</a>";
        }
        $configs = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name FROM OGP_DB_PREFIXaddons  NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE addon_type='config' AND home_cfg_id=" . $home_cfg_id);
        $configs_qty = count($configs);
        if ($configs and $configs_qty >= 1) {
            echo "</td><td>";
            echo "<a href='?m=addonsmanager&amp;p=addons&amp;home_id=" . $home_id . "&amp;mod_id=" . $home_info['mod_id'] . "&amp;home_cfg_id=" . $home_cfg_id . "&amp;addon_type=config&amp;ip=" . $_GET['ip'] . "&amp;port=" . $_GET['port'] . "'>" . get_lang('install_config') . "(" . $configs_qty . ")</a>";
        }
        echo "</td></tr>\n\t\t\t\t </table>\n\t\t\t\t <form action='?m=gamemanager&amp;p=game_monitor&amp;home_id=" . $home_id . "' method='POST'>\n\t\t\t\t  <input type='submit' value='" . get_lang('back') . "' />\n\t\t\t\t </form>\n\t\t\t\t <br>";
    } else {
        print_failure(get_lang('no_games_servers_available'));
    }
}
예제 #17
0
function exec_ogp_module()
{
    $home_id = $_REQUEST['home_id'];
    if (empty($home_id)) {
        print_failure(get_lang('home_id_missing'));
        return;
    }
    global $db;
    $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;
    }
    if (isset($_REQUEST['save_file'])) {
        // If magic quotes are on then we need to remove those slashes here.
        if (get_magic_quotes_gpc()) {
            $_REQUEST['file_content'] = stripslashes($_REQUEST['file_content']);
        }
        $remote = new OGPRemoteLibrary($home_cfg['agent_ip'], $home_cfg['agent_port'], $home_cfg['encryption_key']);
        $file_info = $remote->remote_writefile($home_cfg['home_path'] . "/" . $_SESSION['fm_cwd_' . $home_id], $_REQUEST['file_content']);
        if ($file_info === 1) {
            print_success(get_lang('wrote_changes'));
            $db->logger(get_lang('wrote_changes') . " ( " . $home_cfg['home_name'] . " - " . $home_cfg['home_path'] . $_SESSION['fm_cwd_' . $home_id] . " )");
        } else {
            if ($file_info === 0) {
                print_failure(get_lang('failed_write'));
            } else {
                print_failure(get_lang("agent_offline"));
            }
        }
    }
    echo "<table class='center' style='width:100%;'>" . show_back($home_id) . "</table>";
}
function exec_ogp_module()
{
    global $db;
    print "<h2>" . get_lang('modules') . "</h2>";
    print '<a href="?m=modulemanager&amp;p=update">' . get_lang('update_modules') . '</a>';
    $modules = $db->getInstalledModules();
    if ($modules === FALSE) {
        print_failure(get_lang('no_installed_modules'));
        return;
    }
    print "<p class='note'>" . get_lang("not_complete") . "</p>";
    print "<table class='center'><tr class='first_row'><td>" . get_lang('module_id') . "</td>\n        <td>" . get_lang('module_name') . "</td><td>" . get_lang('module_folder') . "</td>\n        <td>" . get_lang('module_version') . "</td><td>" . get_lang('db_version') . "</td>\n        <td></td></tr>";
    require_once 'modules/modulemanager/module_handling.php';
    $installed_modules = array();
    $i = 0;
    foreach ($modules as $row) {
        print "<tr class='tr" . $i++ % 2 . "'><td>" . $row['id'] . "</td>";
        print "<td>" . $row['title'] . "</td><td>" . $row['folder'] . "</td><td>" . $row['version'] . "</td><td>" . $row['db_version'] . "</td>";
        print "<td><a href='?m=modulemanager&amp;p=del&amp;id=" . $row['id'] . "&amp;module=" . $row['folder'] . "'>";
        print get_lang('delete') . "</a></td></tr>\n";
        array_push($installed_modules, $row['folder']);
    }
    print "</table>";
    $not_installed = array_diff(list_available_modules(), $installed_modules);
    if (empty($not_installed)) {
        return;
    }
    print "<h3>" . get_lang('modules_available_for_install') . "</h3>";
    echo "<table class='center'><tr class='first_row'><td>" . get_lang('module_folder') . "</td><td></td></tr>";
    foreach ($not_installed as $available_module) {
        echo "<tr><td>" . $available_module . "</td><td>";
        echo "<a href='?m=modulemanager&amp;p=add&amp;module=" . $available_module . "'>";
        echo get_lang('install') . "</a></td></tr>";
    }
    echo "</table>";
}
<script src="modules/addonsmanager/jquery-ui.js"></script>
<script>
$(function() {
$( 'input,textarea' ).tooltip();
});
</script>
<?php 
/*
 *
 * OGP - Open Game Panel
 * Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
 *
 * http://www.opengamepanel.org/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
function exec_ogp_module()
{
    global $db;
    if (isset($_POST['create_addon']) and isset($_POST['name']) and $_POST['url'] == "") {
        print_failure(get_lang("fill_the_url_address_to_a_compressed_file"));
    } elseif (isset($_POST['create_addon']) and isset($_POST['url']) and $_POST['name'] == "") {
        print_failure(get_lang("fill_the_addon_name"));
    } elseif (isset($_POST['create_addon']) and isset($_POST['name']) and isset($_POST['url']) and empty($_POST['addon_type'])) {
        print_failure(get_lang("select_an_addon_type"));
    } elseif (isset($_POST['create_addon']) and isset($_POST['name']) and isset($_POST['url']) and isset($_POST['addon_type']) and empty($_POST['home_cfg_id'])) {
        print_failure(get_lang("select_a_game_type"));
    } elseif (isset($_POST['create_addon']) and isset($_POST['name']) and isset($_POST['url']) and isset($_POST['addon_type']) and isset($_POST['home_cfg_id'])) {
        $fields['name'] = $_POST['name'];
        $fields['url'] = $_POST['url'];
        $fields['path'] = $_POST['path'];
        $fields['addon_type'] = $_POST['addon_type'];
        $fields['home_cfg_id'] = $_POST['home_cfg_id'];
        $fields['post_script'] = $_POST['post_script'];
        if (is_numeric($db->resultInsertId('addons', $fields))) {
            print_success(get_lang_f("addon_has_been_created", $_POST['name']));
            if (isset($_POST['addon_id']) && isset($_POST['edit'])) {
                $db->query("DELETE FROM OGP_DB_PREFIXaddons WHERE addon_id=" . $_POST['addon_id']);
            }
        }
    }
    echo "<h2>" . get_lang('addons_manager') . "</h2>";
    $name = isset($_POST['name']) ? $_POST['name'] : "";
    $url = isset($_POST['url']) ? $_POST['url'] : "";
    $path = isset($_POST['path']) ? $_POST['path'] : "";
    $post_script = isset($_POST['post_script']) ? $_POST['post_script'] : "";
    $home_cfg_id = isset($_POST['home_cfg_id']) ? $_POST['home_cfg_id'] : "";
    $addon_type = isset($_POST['addon_type']) ? $_POST['addon_type'] : "";
    if (isset($_POST['addon_id']) && isset($_POST['edit'])) {
        $addons_rows = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXaddons WHERE addon_id=" . $_POST['addon_id']);
        $addon_info = $addons_rows[0];
        $name = isset($addon_info['name']) ? $addon_info['name'] : "";
        $url = isset($addon_info['url']) ? $addon_info['url'] : "";
        $path = isset($addon_info['path']) ? $addon_info['path'] : "";
        $post_script = isset($addon_info['post_script']) ? $addon_info['post_script'] : "";
        $home_cfg_id = isset($addon_info['home_cfg_id']) ? $addon_info['home_cfg_id'] : "";
        $addon_type = isset($addon_info['addon_type']) ? $addon_info['addon_type'] : "";
    }
    ?>
	<form action="" method="post">
		<table class="center">
			<tr>				
				<td align="right">
					<b><?php 
    print_lang('addon_name');
    ?>
</b>
				</td>
				<td align="left">
					<input type="text" value="<?php 
    echo $name;
    ?>
" name="name" size="90" title="<?php 
    print_lang('addon_name_info');
    ?>
" />
				</td>
			</tr>
			<tr>					
				<td align="right">
					<b><?php 
    print_lang('url');
    ?>
</b>
				</td>
				<td align="left">
					<input type="text" value="<?php 
    echo $url;
    ?>
" name="url" size="90" title="<?php 
    print_lang('url_info');
    ?>
" />
				</td>
			</tr>
			<!-- If any, you can set the destination path, should be a relative path to the main game server folder. -->
			<tr>					
				<td align="right">
					<b><?php 
    print_lang('path');
    ?>
</b>
					</td>
					<td align="left">
					<input type="text" value="<?php 
    echo $path;
    ?>
" name="path" size="90" title="<?php 
    print_lang('path_info');
    ?>
" />
				</td>
			</tr>
			<tr>					
				<td align="right">
					<b><?php 
    print_lang('post-script');
    ?>
</b><br>
					<u><?php 
    print_lang('replacements');
    ?>
</u><br>
					%home_path%<br>
					%home_name%<br>
					%control_password%<br>
					%max_players%<br>
					%ip%<br>
					%port%<br>
					%query_port%<br>
					%incremental%<br>
				</td>
				<td align="left">
					<textarea name="post_script" style="width:99%;height:175px;" title="<?php 
    print_lang('post-script_info');
    ?>
" ><?php 
    echo $post_script;
    ?>
</textarea>
				</td>
			</tr>
			<tr>
				<td align="right">
					<b><?php 
    print_lang('select_game_type');
    ?>
</b>
				</td>
				<td align="left">
				<select name='home_cfg_id'>
		<?php 
    $game_cfgs = $db->getGameCfgs();
    echo "<option style='background:black;color:white;' value=''>" . get_lang('linux_games') . "</option>\n";
    foreach ($game_cfgs as $row) {
        if (preg_match("/linux/", $row['game_key'])) {
            $selected = (isset($home_cfg_id) and $row['home_cfg_id'] == $home_cfg_id) ? 'selected="selected"' : '';
            echo "<option {$selected} value='" . $row['home_cfg_id'] . "'>" . $row['game_name'];
            if (preg_match("/64/", $row['game_key'])) {
                echo " (64bit)";
            }
            echo "</option>\n";
        }
    }
    echo "<option style='background:black;color:white;' value=''>" . get_lang('windows_games') . "</option>\n";
    foreach ($game_cfgs as $row) {
        if (preg_match("/win/", $row['game_key'])) {
            $selected = (isset($home_cfg_id) and $row['home_cfg_id'] == $home_cfg_id) ? 'selected=selected' : '';
            echo "<option {$selected} value='" . $row['home_cfg_id'] . "'>" . $row['game_name'];
            if (preg_match("/64/", $row['game_key'])) {
                echo " (64bit)";
            }
            echo "</option>\n";
        }
    }
    ?>
				</select>
				</td>
			</tr>
			<tr>
				<td align="right">
				<b><?php 
    print_lang('type');
    ?>
</b>	
				</td>
				<td align="left">
		<?php 
    $types = array('plugin', 'mappack', 'config');
    foreach ($types as $type) {
        $checked = (isset($addon_type) and $type == $addon_type) ? 'checked' : '';
        echo '<input type="radio" name="addon_type" value="' . $type . '" ' . $checked . '>' . get_lang($type);
    }
    ?>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
				<?php 
    if (isset($_POST['addon_id']) && isset($_POST['edit'])) {
        echo '<input type="hidden" name="addon_id" value="' . $_POST['addon_id'] . '" >';
        echo '<input type="hidden" name="edit" value="' . $_POST['edit'] . '" >';
        ?>
					<button name="create_addon" type="submit">
					<?php 
        print_lang('edit_addon');
        ?>
					</button>
				<?php 
    } else {
        ?>
					<button name="create_addon" type="submit">
					<?php 
        print_lang('create_addon');
        ?>
					</button>
				<?php 
    }
    ?>
				</td>
			</tr>
		</table>
	</form>
	<br>
	<h2><?php 
    print_lang('addons_db');
    ?>
</h2>
	<table class="center">
		<tr>	
			<td align="center">
				<form name="remove" action="" method="get">
				<input name="m" type="hidden" value="addonsmanager"/>
				<input name="p" type="hidden" value="addons_manager"/>
				<b><?php 
    print_lang('game');
    ?>
</b> <select name='home_cfg_id'>
				<?php 
    echo "<option style='background:black;color:white;' value=''>" . get_lang('linux_games') . "</option>\n";
    foreach ($game_cfgs as $row) {
        if (preg_match("/linux/", $row['game_key'])) {
            if (isset($_GET['home_cfg_id']) and $row['home_cfg_id'] == $_GET['home_cfg_id']) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            echo "<option value='" . $row['home_cfg_id'] . "' {$selected} >" . $row['game_name'];
예제 #20
0
function exec_ogp_module()
{
    if (!function_exists("curl_init")) {
        print_failure(get_lang('curl_needed'));
        return;
    }
    if ($_SESSION['users_group'] != "admin") {
        print_failure(get_lang('no_access'));
        return;
    }
    global $db;
    global $view;
    $version = $_GET['version'];
    $vtype = "SVN";
    echo "<h4>" . get_lang('dwl_update') . "</h4>\n";
    //This is usefull when you are downloading big files, as it
    //will prevent time out of the script
    set_time_limit(0);
    error_reporting(E_ALL);
    ini_set('display_errors', true);
    $baseDir = str_replace("modules" . DIRECTORY_SEPARATOR . "update", "", dirname(__FILE__));
    if (!is_writable($baseDir)) {
        if (!@chmod($baseDir, 0755)) {
            print_failure(get_lang_f('base_dir_not_writable', $baseDir));
            return;
        }
    }
    if (is_writable(sys_get_temp_dir())) {
        // Download file to temporary folder
        if (isset($_POST['mirror']) && !empty($_POST['mirror'])) {
            $mirror = $_POST['mirror'];
        } else {
            $mirror = "master";
        }
        $temp_dwl = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'svn.tar.gz';
        $fp = fopen($temp_dwl, 'w+');
        //This is the download destination
        $url = "http://" . $mirror . ".dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/hldstart-code-{$version}.zip";
        //This is the download source
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 500);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);
        // Check if the file exists and the size is bigger than a 404 error page from sf.net
        if (file_exists($temp_dwl)) {
            $stat = stat($temp_dwl);
        } else {
            print_failure(get_lang_f('dwl_failed', $url));
            return;
        }
        if ($stat['size'] > 1500) {
            print_success(get_lang('dwl_complete'));
        } else {
            print_failure(get_lang_f('dwl_failed', $url));
            return;
        }
        echo "<h4>" . get_lang('install_update') . "</h4>\n";
        // Set default values for file checkings before installing
        $not_writable = get_lang('can_not_update_non_writable_files') . " :<br>";
        $filename = "";
        $overwritten = 0;
        $new = 0;
        $all_writable = TRUE;
        $filelist = "";
        $overwritten_files = "";
        $new_files = "";
        $unwanted_path = "hldstart-code-{$version}/trunk/upload";
        $extract_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "OGP_update";
        if (!file_exists($extract_path)) {
            mkdir($extract_path, 0775);
        }
        $blacklist = array('/install.php', '/modules/gamemanager/rsync_sites_local.list');
        $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
        if ($blacklisted_files !== FALSE) {
            $curren_blacklist = array();
            foreach ($blacklisted_files as $blacklisted_file) {
                $curren_blacklist[] = $blacklisted_file['file_path'];
            }
            $blacklist = array_merge($curren_blacklist, $blacklist);
        }
        include 'unzip.php';
        // array|false extractZip( string $zipFile, string $extract_path [, string $remove_path, array $blacklist, array $whitelist] )
        $files = extractZip($temp_dwl, $extract_path, $unwanted_path, $blacklist, '');
        if (is_array($files) and count($files) > 0) {
            // Check file by file if already exists, if it matches, compares both files
            // looking for changes determining if the file needs to be updated.
            // Also determines if the file is writable
            $filelist = array();
            $i = 0;
            foreach ($files as $file) {
                $filename = str_replace($unwanted_path . "/", "", $file['filename']);
                if (in_array($filename, $blacklist)) {
                    continue;
                }
                $temp_file = $extract_path . DIRECTORY_SEPARATOR . $filename;
                $web_file = $baseDir . $filename;
                if (file_exists($web_file)) {
                    $temp = file_get_contents($temp_file);
                    $web = file_get_contents($web_file);
                    if ($temp != $web) {
                        if (!is_writable($web_file)) {
                            if (!@chmod($web_file, 0775)) {
                                $all_writable = FALSE;
                                $not_writable .= $web_file . "<br>";
                            } else {
                                $filelist[$i] = $file['filename'];
                                $i++;
                                $overwritten_files .= $filename . "<br>";
                                $overwritten++;
                            }
                        } else {
                            $filelist[$i] = $file['filename'];
                            $i++;
                            $overwritten_files .= $filename . "<br>";
                            $overwritten++;
                        }
                    }
                } else {
                    $filelist[$i] = $file['filename'];
                    $i++;
                    $new_files .= $filename . "<br>";
                    $new++;
                }
            }
        }
        // Once checkings are done the temp folder is removed
        if (file_exists($extract_path)) {
            rmdir_recurse($extract_path);
        }
        if ($all_writable) {
            // Extract the files that are set in $filelist, to the folder at $baseDir and removes 'upload' from the beggining of the path.
            $files = extractZip($temp_dwl, preg_replace("/\\/\$/", "", $baseDir), $unwanted_path, $blacklist, $filelist);
            if (is_array($files)) {
                // Updated files
                if ($overwritten > 0) {
                    print_success(get_lang_f('files_overwritten', $overwritten));
                    echo get_lang_f("updated_files", $overwritten_files);
                }
                if ($new > 0) {
                    print_success(get_lang_f('new_files', $new));
                    echo get_lang_f("updated_files", $new_files);
                }
                // update version info in db
                $db->query("UPDATE OGP_DB_PREFIXsettings SET value = '{$version}'\tWHERE setting = 'ogp_version'");
                $db->query("UPDATE OGP_DB_PREFIXsettings SET value = '{$vtype}'\tWHERE setting = 'version_type'");
                // Remove the downloaded package
                if (file_exists($temp_dwl)) {
                    unlink($temp_dwl);
                }
                // Remove files that are not related to the panel
                if (file_exists($baseDir . DIRECTORY_SEPARATOR . "hldstart-code-{$version}")) {
                    rmdir_recurse($baseDir . DIRECTORY_SEPARATOR . "hldstart-code-{$version}");
                }
                echo "<br>\n<h4>" . get_lang('updating_modules') . "</h4>\n";
                require_once 'modules/modulemanager/module_handling.php';
                $modules = $db->getInstalledModules();
                foreach ($modules as $row) {
                    update_module($db, $row['id'], $row['folder']);
                }
                print_success(get_lang('update_complete'));
            } else {
                print_failure("Failed extracting files.<br>There is not enough space available in the system temporary folder (" . sys_get_temp_dir() . ").</b>");
            }
        } else {
            print_failure($not_writable);
        }
    } else {
        print_failure(get_lang_f('temp_folder_not_writable', sys_get_temp_dir()));
    }
}
function exec_ogp_module()
{
    global $db;
    global $view;
    $pieces = explode("-", $_GET['home_id-mod_id-ip-port']);
    $home_id = $pieces[0];
    $mod_id = $pieces[1];
    $ip = $pieces[2];
    $port = $pieces[3];
    $user_id = $_SESSION['user_id'];
    $isAdmin = $db->isAdmin($user_id);
    if ($isAdmin) {
        $home_info = $db->getGameHome($home_id);
    } else {
        $home_info = $db->getUserGameHome($user_id, $home_id);
    }
    if ($home_info === FALSE) {
        print_failure(get_lang('no_access_to_home'));
        return;
    }
    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
    if (!$server_xml) {
        echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
        return;
    }
    require_once 'includes/lib_remote.php';
    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
    $home_log = "";
    if (isset($server_xml->console_log)) {
        $log_retval = $remote->remote_readfile($home_info['home_path'] . '/' . $server_xml->console_log, $home_log);
    } else {
        $log_retval = $remote->get_log(OGP_SCREEN_TYPE_HOME, $home_info['home_id'], clean_path($home_info['home_path'] . "/" . $server_xml->exe_location), $home_log);
    }
    if ($log_retval == 0) {
        print_failure(get_lang('agent_offline'));
        echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
    } elseif ($log_retval == 1 || $log_retval == 2) {
        // Using the refreshed class
        if (isset($_GET['refreshed'])) {
            echo "<pre class='log'>" . $home_log . "</pre>";
        } else {
            echo "<h2>" . $home_info['home_name'] . "</h2>";
            require_once "includes/refreshed.php";
            $control = '<form method="POST" >
						<input type="submit" name="';
            if (isset($_POST['full'])) {
                $height = "100%";
                $control .= 'default" value="-';
            } else {
                $height = "500px";
                $control .= 'full" value="+';
            }
            $control .= '" /></form><br />';
            $intervals = array("4s" => "4000", "8s" => "8000", "30s" => "30000", "2m" => "120000", "5m" => "300000");
            $intSel = '<form action="" method="GET" >
					   <input type="hidden" name="m" value="gamemanager" />
					   <input type="hidden" name="p" value="log" />
					   <input type="hidden" name="home_id-mod_id-ip-port" value="' . $_GET['home_id-mod_id-ip-port'] . '" />' . get_lang('refresh_interval') . ':<select name="setInterval" onchange="this.form.submit();">';
            foreach ($intervals as $interval => $value) {
                $selected = "";
                if (isset($_GET['setInterval']) and $_GET['setInterval'] == $value) {
                    $selected = 'selected="selected"';
                }
                $intSel .= '<option value="' . $value . '" ' . $selected . ' >' . $interval . '</option>';
            }
            $intSel .= "</select></form>";
            $setInterval = $_GET['setInterval'] ? $_GET['setInterval'] : 4000;
            $refresh = new refreshed();
            $pos = $refresh->add("home.php?m=gamemanager&p=log&type=cleared&refreshed&home_id-mod_id-ip-port=" . $_GET['home_id-mod_id-ip-port']);
            echo $refresh->getdiv($pos, "height:" . $height . ";overflow:auto;max-width:1600px;");
            ?>
<script type="text/javascript">$(document).ready(function(){ <?php 
            echo $refresh->build("{$setInterval}");
            ?>
} ); </script><?php 
            echo "<table class='center' ><tr><td>{$intSel}</td><td>{$control}</td></tr></table>";
            if ($remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']) != 1) {
                print_failure(get_lang('server_not_running'));
            } else {
                if ($server_xml->control_protocol == 'rcon' or $server_xml->control_protocol == 'rcon2' or @$server_xml->gameq_query_name == "minecraft" or $server_xml->control_protocol == 'lcon' or isset($server_xml->lgsl_query_name) and $server_xml->lgsl_query_name == "7dtd") {
                    require 'modules/gamemanager/rcon.php';
                }
            }
            echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
        }
    } else {
        print_failure(get_lang_f('unable_to_get_log', $log_retval));
        echo create_back_button($_GET['m'], 'game_monitor&home_id-mod_id-ip-port=' . $_GET['home_id-mod_id-ip-port']);
    }
}
예제 #22
0
function exec_ogp_module()
{
    global $db;
    global $view;
    $home_id = $_REQUEST['home_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_to_start_server'));
        echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $_REQUEST['ip'] . "-" . $_REQUEST['port'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
        return;
    }
    $mod_id = $_REQUEST['mod_id'];
    if (!array_key_exists($mod_id, $home_info['mods'])) {
        print_failure("Unable to retrieve mod information from database.");
        return;
    }
    echo "<h2>";
    echo empty($home_info['home_name']) ? get_lang('not_available') : $home_info['home_name'];
    echo "</h2>";
    require_once 'includes/lib_remote.php';
    $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 (!$server_xml) {
        echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $_REQUEST['ip'] . "-" . $_REQUEST['port'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
        return;
    }
    // It compares ip and port on POST with the pair on DB for security reasons (URL HACKING)
    $home_id = $home_info['home_id'];
    $ip_info = $db->getHomeIpPorts($home_id);
    foreach ($ip_info as $ip_ports_row) {
        if ($ip_ports_row['ip'] == $_REQUEST['ip'] && $ip_ports_row['port'] == $_REQUEST['port']) {
            $ip = $ip_ports_row['ip'];
            $port = $ip_ports_row['port'];
        }
    }
    if (!isset($ip) or !isset($port)) {
        echo "<h2>" . get_lang_f('ip_port_pair_not_owned') . "</h2>";
        echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port={$home_id}-{$mod_id}-{$ip}-{$port}'><< " . get_lang('back') . "</a></td></tr></table>";
        return;
    }
    if (isset($server_xml->console_log)) {
        $log_retval = $remote->remote_readfile($home_info['home_path'] . '/' . $server_xml->console_log, $home_log);
    } else {
        $log_retval = $remote->get_log(OGP_SCREEN_TYPE_HOME, $home_info['home_id'], clean_path($home_info['home_path'] . "/" . $server_xml->exe_location), $home_log);
    }
    function getLastLines($string, $n = 1)
    {
        $lines = explode("\n", $string);
        $lines = array_slice($lines, -$n);
        return implode("\n", $lines);
    }
    $home_log = getLastLines($home_log, 40);
    if ($log_retval > 0) {
        if ($log_retval == 2) {
            print_failure(get_lang('server_not_running_log_found'));
        }
        echo "<pre style='background:black;color:white;'>" . $home_log . "</pre>";
        if ($log_retval == 2) {
            return;
        }
    } else {
        print_failure(get_lang_f('unable_to_get_log', $log_retval));
    }
    // If game is not supported by lgsl we skip the lgsl checks and
    // assume successfull start.
    if ($home_info['use_nat'] == 1) {
        $query_ip = $home_info['agent_ip'];
    } else {
        $query_ip = $ip;
    }
    $running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']);
    if ($server_xml->lgsl_query_name) {
        require 'protocol/lgsl/lgsl_protocol.php';
        $get_q_and_s = lgsl_port_conversion((string) $server_xml->lgsl_query_name, $port, "", "");
        //Connection port
        $c_port = $get_q_and_s['0'];
        //query port
        $q_port = $get_q_and_s['1'];
        //software port
        $s_port = $get_q_and_s['2'];
        $data = lgsl_query_live((string) $server_xml->lgsl_query_name, $query_ip, $c_port, $q_port, $s_port, "sa");
        if ($data['b']['status'] == "0") {
            $running = FALSE;
        }
    } elseif ($server_xml->gameq_query_name) {
        require 'protocol/GameQ/GameQ.php';
        $query_port = get_query_port($server_xml, $port);
        $servers = array(array('id' => 'server', 'type' => (string) $server_xml->gameq_query_name, 'host' => $query_ip . ":" . $query_port));
        $gq = new GameQ();
        $gq->addServers($servers);
        $gq->setOption('timeout', 4);
        $gq->setOption('debug', FALSE);
        $gq->setFilter('normalise');
        $game = $gq->requestData();
        if (!$game['server']['gq_online']) {
            $running = FALSE;
        }
    }
    if (!$running) {
        if (!isset($_GET['retry'])) {
            $retry = 0;
        } else {
            $retry = $_GET['retry'];
        }
        if ($retry >= 5) {
            echo "<p>" . get_lang('server_running_not_responding') . "\n\t\t\t<a href=?m=gamemanager&amp;p=stop&amp;home_id=" . $home_info['home_id'] . "&amp;ip=" . $ip . "&amp;port=" . $port . ">" . get_lang('already_running_stop_server') . ".</a></p>";
            echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port={$home_id}-{$mod_id}-{$ip}-{$port}'><< " . get_lang('back') . "</a></td></tr></table>";
        }
        echo "</b>Retry #" . $retry . ".</b>";
        $retry++;
        print "<p class='note'>" . get_lang('starting_server') . "</p>";
        $view->refresh("?m=gamemanager&amp;p=start&amp;refresh&amp;ip={$ip}&amp;port={$port}&amp;home_id={$home_id}&amp;mod_id={$mod_id}&amp;retry=" . $retry, 3);
        return;
    }
    print_success(get_lang('server_started'));
    $ip_id = $db->getIpIdByIp($ip);
    $db->delServerStatusCache($ip_id, $port);
    $view->refresh("?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port={$home_id}-{$mod_id}-{$ip}-{$port}");
    return;
}
function exec_ogp_module()
{
    global $db;
    echo "<h2>" . get_lang('game_monitor') . "</h2>";
    $refresh = new refreshed(100000);
    set_time_limit(0);
    $stats_servers_online = 0;
    $stats_servers = 0;
    $stats_players = 0;
    $stats_maxplayers = 0;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if ($isAdmin) {
        $server_homes = $db->getIpPorts();
    } else {
        $server_homes = $db->getIpPortsForUser($_SESSION['user_id']);
    }
    if ($server_homes === FALSE) {
        // If there are no games, then there can not be any mods either.
        print_failure(get_lang('no_game_homes_assigned'));
        if ($isAdmin) {
            echo "<p><a href='?m=user_games&amp;p=assign&amp;user_id={$_SESSION['user_id']}'>" . get_lang('assign_game_homes') . "</a></p>";
        }
        return;
    }
    if (empty($_GET['home_id-mod_id-ip-port'])) {
        unset($_GET['home_id-mod_id-ip-port']);
    }
    if (empty($_GET['home_id'])) {
        unset($_GET['home_id']);
    }
    if ($_GET['home_cfg_id'] == get_lang('game_type')) {
        unset($_GET['home_cfg_id']);
    }
    create_home_selector_game_type($_GET['m'], $_GET['p'], $server_homes);
    if (!isset($_GET['home_id-mod_id-ip-port']) and !isset($_GET['home_id']) and !isset($_GET['home_cfg_id'])) {
        create_home_selector_address($_GET['m'], $_GET['p'], $server_homes);
        $show_all = TRUE;
    } else {
        create_home_selector_address($_GET['m'], $_GET['p'], $server_homes);
        create_home_selector($_GET['m'], $_GET['p'], "show_all");
        $show_all = FALSE;
    }
    require "protocol/lgsl/lgsl_protocol.php";
    ?>
		<form>
			<b><?php 
    print_lang('search');
    ?>
:</b>
			<input type="text" id="search">
		</form>
	<?php 
    $info = $db->getUser($_SESSION['users_login']);
    $chk_expire = $info['user_expires'];
    $exptime = read_expire($chk_expire);
    $time_to_expire = str_replace('hr', 'hours', $exptime);
    if ($exptime != "X") {
        ?>
		<span style="color:black;font-weight:bold;">
		 <center>
			<?php 
        echo print_lang('account_expiration');
        ?>
: <span style="color:green;"><?php 
        echo date("l, F jS, Y, H:i:s", $chk_expire) . " ( " . $time_to_expire . ")";
        ?>
</span>
		 </center>
		</span>
	<?php 
    }
    ?>
		<table id="servermonitor" class="tablesorter">
		<thead> 
		<tr> 
			<th style="width:16px;background-position: center;"></th> 
			<th style="width:16px;background-position: center;"></th> 
			<th><?php 
    print_lang('server_name');
    ?>
</th> 
			<th><?php 
    print_lang('address');
    ?>
</th> 
			<th><?php 
    print_lang('owner');
    ?>
</th> 
			<th>
			  <?php 
    print_lang('operations');
    ?>
			  <img style="border:0;height:15px;" id="action-stop" src="images/stop.png"/>
			  <img style="border:0;height:15px;" id="action-restart" src="images/restart.png"/>
			  <img style="border:0;height:15px;" id="action-start" src="images/start.png"/>
			</th>
		</tr> 
		</thead> 
		<tbody> 
	<?php 
    foreach ($server_homes as $server_home) {
        $stats_servers++;
        //Unset variables.
        if (isset($_GET['home_id-mod_id-ip-port'])) {
            $pieces = explode("-", $_GET['home_id-mod_id-ip-port']);
            $post_home_id = $pieces[0];
            $post_mod_id = $pieces[1];
            $post_ip = $pieces[2];
            $post_port = $pieces[3];
        }
        if ($show_all or isset($_GET['home_id']) and $_GET['home_id'] == $server_home['home_id'] or isset($_GET['home_id-mod_id-ip-port']) and $server_home['home_id'] == $post_home_id and $server_home['mod_id'] == $post_mod_id and $post_ip == $server_home['ip'] and $post_port == $server_home['port'] or isset($_GET['home_cfg_id']) and $_GET['home_cfg_id'] == $server_home['home_cfg_id']) {
            unset($map, $trclass, $first, $second, $onlineT, $ts3opt, $offlineT, $halfT, $ministart, $player_list, $groupsus, $name, $mod_name, $SrvCtrl, $lite_fm, $manager, $user, $pos, $ftp, $addonsmanager, $ctrlChkBoxes);
            //End
            if ($isAdmin) {
                $server_home['access_rights'] = "ufpet";
            } else {
                $home_info = $db->getUserGameHome($_SESSION['user_id'], $server_home['home_id']);
                $server_home['access_rights'] = $home_info['access_rights'];
            }
            $litefm_installed = $db->isModuleInstalled('litefm');
            $ftp_installed = $db->isModuleInstalled('ftp');
            $addonsmanager_installed = $db->isModuleInstalled('addonsmanager');
            $mysql_installed = $db->isModuleInstalled('mysql');
            if ($server_home['mod_name'] == "none" or $server_home['mod_name'] == "None") {
                $mod_name = "";
            } elseif ($server_home['mod_name'] != $server_home['game_name']) {
                $mod_name = " ( " . $server_home['mod_name'] . " )";
            }
            $get_size = "<table align='left' class='monitorbutton' ><tr>" . "<td align='middle' class='size' id='" . $server_home["home_id"] . "'>" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/file_size.png' title='" . get_lang('get_size') . "'/>\n<br /><span style='font-weight:bold;'>" . get_lang('get_size') . "</span></td></tr></table>";
            $manager = "<a href='?m=user_games&amp;p=edit&amp;home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/edit.png' title='" . get_lang('edit') . "'/>\n<br />" . get_lang('edit') . "\n</td></tr></table></a>";
            // Only show the filemanager link when the litefm is installed.
            if (preg_match("/f/", $server_home['access_rights']) > 0 && $litefm_installed) {
                $lite_fm = "<a href='?m=litefm&amp;home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/txt.png' title='" . get_lang('file_manager') . "'/>\n<br />" . get_lang('file_manager') . "\n</td></tr></table></a>";
            }
            if (preg_match("/t/", $server_home['access_rights']) > 0 && $ftp_installed) {
                $ftp = "<a href='?m=ftp&amp;home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/ftp.png' title='" . get_lang('ftp') . "'/>\n<br>" . get_lang('ftp') . "\n</td></tr></table></a>";
            }
            if ($addonsmanager_installed) {
                $addons = $db->resultQuery("SELECT DISTINCT addon_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE home_cfg_id=" . $server_home['home_cfg_id']);
                $addons_qty = count($addons);
                if ($addons and $addons_qty >= 1) {
                    $addonsmanager = "<a href='?m=addonsmanager&amp;p=user_addons&amp;home_id=" . $server_home['home_id'] . "&amp;ip=" . $server_home['ip'] . "&amp;port=" . $server_home['port'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='modules/administration/images/addons_manager.png' title='" . get_lang('addons') . "'/>\n<br />" . get_lang('addons') . "\n<b style='font-size:0.9em' >(" . $addons_qty . ")</td></tr></table></a>";
                }
            }
            if ($mysql_installed) {
                $mysql_dbs = $db->resultQuery("SELECT db_id FROM OGP_DB_PREFIXmysql_databases WHERE enabled=1 AND home_id=" . $server_home['home_id']);
                if (!empty($mysql_dbs)) {
                    $mysql = "<a href='?m=mysql&p=user_db&home_id=" . $server_home['home_id'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='modules/administration/images/mysql_admin.png' title='" . get_lang('mysql_databases') . "'/>\n<br />" . get_lang('mysql_databases') . "\n</td></tr></table></a>\n";
                }
            }
            $mod_result = $db->getHomeMods($server_home['home_id']);
            if ($mod_result === FALSE) {
                print_failure(get_lang('fail_no_mods'));
                if ($isAdmin) {
                    $manager .= "<a href='?m=user_games&amp;p=edit&amp;home_id=" . $server_home['home_id'] . "'>" . get_lang('configure_mods') . "</a>";
                }
                continue;
            }
            $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $server_home['home_cfg_file']);
            $master_server_home_id = $db->getMasterServer($server_home['remote_server_id'], $server_home['home_cfg_id']);
            if ($master_server_home_id != FALSE) {
                if (!$db->getGameHomeWithoutMods($master_server_home_id)) {
                    $db->setMasterServer("remove", $master_server_home_id, $server_home['home_cfg_id'], $server_home['remote_server_id']);
                    $master_server_home_id = FALSE;
                }
            }
            if ($server_xml) {
                if (preg_match("/u/", $server_home['access_rights']) > 0) {
                    // In case game is compatible with steam we offer a way to use steam with the updates.
                    if ($server_xml->installer == "steamcmd") {
                        if ($master_server_home_id != FALSE and $master_server_home_id != $server_home['home_id']) {
                            $manager .= "<form name='steam_master_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . "' action='?m=gamemanager&amp;p=update&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update' method='POST' >\n" . "<table align='left' class='monitorbutton' >\n" . "<tr><td align='middle' onclick='document.steam_master_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . ".submit()' ><img style='border:0;height:40px;vertical-align:middle;' src='images/master.png' />" . "<br /><span style='font-weight:bold;'>" . get_lang('update_from_local_master_server') . "</span><input id='master" . $server_home['home_id'] . "' type='hidden' name='master_server_home_id' value='" . $master_server_home_id . "' /></td></tr>\n</table>\n</form>";
                        }
                        $manager .= "<form name='steam_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . "' action='?m=gamemanager&amp;p=update&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update' method='POST' >\n" . "<table align='left' class='monitorbutton' >\n" . "<tr><td align='middle' onclick='document.steam_" . $server_home['home_id'] . "_" . $server_home['mod_id'] . "_" . str_replace(".", "", $server_home['ip']) . "_" . $server_home['port'] . ".submit()' ><img style='border:0;height:40px;vertical-align:middle;' src='images/steam.png' />" . "<br /><span style='font-weight:bold;'>" . get_lang('install_update_steam') . "</span></td></tr>\n</table>\n</form>";
                    } else {
                        $manager .= "<a href='?m=gamemanager&amp;p=update_manual&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/install.png' title='" . get_lang('install_update_manual') . "'/>\n<br>" . get_lang('install_update_manual') . "\n</td></td></table></a>";
                        $sync_name = get_sync_name($server_xml);
                        $sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES);
                        $master_server_home_id = $db->getMasterServer($server_home['remote_server_id'], $server_home['home_cfg_id']);
                        if (in_array($sync_name, $sync_list) or $master_server_home_id != FALSE and $master_server_home_id != $server_home['home_id']) {
                            $manager .= "<a href='?m=gamemanager&amp;p=rsync_install&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "&amp;update=update'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/rsync.png' title='" . get_lang('rsync_install') . "'/>\n<br />" . get_lang('rsync_install') . "\n</td></td></table></a>";
                        }
                    }
                }
            }
            if ($isAdmin) {
                if ($server_xml->control_protocol == 'rcon' or $server_xml->control_protocol == 'lcon' or $server_xml->control_protocol == 'rcon2' or @$server_xml->gameq_query_name == 'minecraft') {
                    $manager .= "<form name='rcon_preset" . $server_home['home_id'] . "' action='home.php?m=gamemanager&amp;p=rcon_presets&amp;home_id=" . $server_home['home_id'] . "&amp;mod_id=" . $server_home['mod_id'] . "' method='POST'>\n" . "<table align='left' class='monitorbutton' >\n" . "<tr>\n" . "<td align='middle' onclick='document.rcon_preset" . $server_home['home_id'] . ".submit()' ><img style='border:0;height:40px;vertical-align:middle;' src='images/rcon_preset.png' /><br /><span style='font-weight:bold;'>" . get_lang('rcon_presets') . "</span></td>\n" . "</tr>\n" . "</table>\n" . "</form>";
                }
            }
            $xml_installer = $server_xml->installer;
            // If query name does not exist use mod key instead.
            if ($server_xml->protocol == "gameq") {
                $query_name = $server_xml->gameq_query_name;
            } elseif ($server_xml->protocol == "lgsl") {
                $query_name = $server_xml->lgsl_query_name;
            } elseif ($server_xml->mods->mod['key'] == "none" or $server_xml->mods->mod['key'] == "None") {
                $query_name = "none";
            } else {
                $query_name = $server_xml->mods->mod['key'];
            }
            if ($server_xml->mods->mod['key'] == "none" or $server_xml->mods->mod['key'] == "None") {
                $mod = "none";
            } else {
                $mod = $server_xml->mods->mod['key'];
            }
            //----------+ getting the lgsl image icon
            $icon_paths = array("images/icons/{$mod}.png", "images/icons/{$query_name}.png", "protocol/lgsl/other/icon_unknown.gif");
            $icon_path = get_first_existing_file($icon_paths);
            //Properties for all servers
            if (isset($post_home_id) && $post_home_id == $server_home['home_id'] or isset($_GET['home_id']) && $_GET['home_id'] == $server_home['home_id']) {
                $trclass = " expandme";
            }
            $groupusers = $db->getGroupUsersByHomeId($server_home['home_id']);
            if ($groupusers) {
                $groupsus = "<b>" . get_lang('group_users') . "</b><br>";
                foreach ($groupusers as $groupu) {
                    $groupsus .= $groupu['users_login'] . "<br>";
                }
            } else {
                $groupsus = "";
            }
            $view_log = "<a href='?m=gamemanager&amp;p=log&amp;home_id-mod_id-ip-port=" . $server_home['home_id'] . "-" . $server_home['mod_id'] . "-" . $server_home['ip'] . "-" . $server_home['port'] . "'>\n" . "<table align='left' class='monitorbutton' ><tr><td align='middle' >" . "<img style='border:0;height:40px;vertical-align:middle;' src='images/log.png' title='" . get_lang('view_log') . "'/>\n<br>" . get_lang('view_log') . "\n</td></tr></table></a>";
            $btns = $view_log . @$ftp . @$lite_fm . @$addonsmanager;
            //End
            $remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
            $host_stat = $remote->status_chk();
            if ($host_stat === 1) {
                if ($server_home['use_nat'] == 1) {
                    $query_ip = $server_home['agent_ip'];
                } else {
                    $query_ip = $server_home['ip'];
                }
                $address = $query_ip . ":" . $server_home['port'];
                $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $server_home['home_id']) === 1;
                $update_in_progress = $remote->is_screen_running(OGP_SCREEN_TYPE_UPDATE, $server_home['home_id']) === 1;
                if ($screen_running) {
                    // Check if the screen running the server is running.
                    $status = "online";
                    $order = 1;
                    if ($server_xml->protocol == "lgsl") {
                        $get_q_and_s = lgsl_port_conversion((string) $query_name, $server_home['port'], "", "");
                        //Connection port
                        $c_port = $get_q_and_s['0'];
                        //query port
                        $q_port = $get_q_and_s['1'];
                        //software port
                        $s_port = $get_q_and_s['2'];
                        $address = "<a href='" . lgsl_software_link($query_name, $query_ip, $c_port, $q_port, $s_port) . "'>" . $query_ip . ":" . $server_home['port'] . "</a>";
                    }
                    if ($server_xml->protocol == "teamspeak3") {
                        $address = "<a href='ts3server://" . $query_ip . ":" . $server_home['port'] . "'>" . $query_ip . ":" . $server_home['port'] . "</a>";
                    }
                    if ($server_xml->protocol == "gameq" and $server_xml->installer == 'steamcmd') {
                        $address = "<a href='steam://connect/" . $query_ip . ":" . $server_home['port'] . "'>" . $query_ip . ":" . $server_home['port'] . "</a>";
                    }
                    $pos = $refresh->add("home.php?m=gamemanager&p=ref_servermonitor&type=cleared&server_home=" . $server_home['home_id'] . "&ip=" . $server_home['ip'] . "&port=" . $server_home['port']);
                    if ($server_xml->protocol == "teamspeak3") {
                        require 'protocol/TeamSpeak3/functions.php';
                    }
                    $startup_file_exists = $remote->rfile_exists("startups/" . $server_home['ip'] . "-" . $server_home['port']) === 1;
                    $ctrlChkBoxes .= '<div id="server_icon" class="action-stop' . $server_home['home_id'] . '" >
									 <div>
									 <input id="action-stop" class="action-stop' . $server_home['home_id'] . '" name="action-' . $server_home['home_id'] . '" value="stop-' . $server_home['home_id'] . '-' . $server_home['mod_id'] . '-' . $server_home['ip'] . '-' . $server_home['port'] . '" type="radio"><img style="border:0;height:15px;" src="images/stop.png"/></div><div>&nbsp;' . get_lang('stop_server') . '</div></div>';
                    if ($startup_file_exists) {
                        $ctrlChkBoxes .= '<div id="server_icon" class="action-restart' . $server_home['home_id'] . '" >
										 <div>
										 <input id="action-restart" class="action-restart' . $server_home['home_id'] . '" name="action-' . $server_home['home_id'] . '" value="restart-' . $server_home['home_id'] . '-' . $server_home['mod_id'] . '-' . $server_home['ip'] . '-' . $server_home['port'] . '" type="radio"><img style="border:0;height:15px;" src="images/restart.png"/></div><div>&nbsp;' . get_lang('restart_server') . '</div></div>';
                    }
                    $stats_servers_online++;
                } else {
                    $status = "offline";
                    if ($db->getLastParam($server_home['home_id']) != FALSE) {
                        if ($update_in_progress) {
                            $ctrlChkBoxes .= '<div id="server_icon" class="action-start' . $server_home['home_id'] . '" >&nbsp;' . get_lang('update_in_progress') . '</div>';
                        } else {
                            $ctrlChkBoxes .= '<div id="server_icon" class="action-start' . $server_home['home_id'] . '" >
											 <div>
											 <input id="action-start" class="action-start' . $server_home['home_id'] . '" name="action-' . $server_home['home_id'] . '" value="start-' . $server_home['home_id'] . '-' . $server_home['mod_id'] . '-' . $server_home['ip'] . '-' . $server_home['port'] . '" type="radio"><img style="border:0;height:15px;" src="images/start.png"/></div><div>&nbsp;' . get_lang('start_server') . '</div></div>';
                        }
                    }
                    $order = 3;
                    ob_start();
                    require 'modules/gamemanager/mini_start.php';
                    $ministart = ob_get_contents();
                    ob_end_clean();
                    if ($update_in_progress) {
                        $offlineT = '<div id="server_icon" class="action-start' . $server_home['home_id'] . '" >&nbsp;' . get_lang('update_in_progress') . '</div>';
                    } else {
                        $offlineT = $ministart;
                    }
                }
            } else {
                $status = "offline";
                $order = 3;
                $address = "<span style='color:darkred;font-weight:bold;'>Agent Offline</span>";
            }
            $user = $db->getUserById($server_home['user_id_main']);
            // Template
            @($first = "<tr class='maintr{$trclass}'>");
            $first .= "<td class='collapsible'><span class='hidden'>{$order}</span><a></a>" . "<img src='images/{$status}.png' />" . "</td>";
            $first .= "<td>" . "<span class='hidden'>{$mod}</span><img src='{$icon_path}' />" . "</td>";
            $first .= "<td class='collapsible'><a></a><b>" . $server_home['home_name'] . "</b>{$mod_name}</td>";
            $first .= "<td>" . $address . "</td>";
            $first .= "<td>" . $user['users_login'] . "</td>";
            $first .= "<td style='width:328px;padding:0px;'>{$ctrlChkBoxes}</td>";
            $first .= "</tr>";
            $second = "<tr class='expand-child'>";
            @($second .= "<td colspan='4'>" . $refresh->getdiv($pos, "width:100%;") . "{$offlineT}</td>");
            $second .= "<td width='80'>{$groupsus}</td>";
            @($second .= "<td>{$btns}{$manager}<br>{$mysql}<br>{$get_size}<br>{$ts3opt}</td>");
            $second .= "</tr>";
            //Echo them all
            echo "{$first}{$second}";
        }
    }
    echo "</tbody>";
    echo "<tfoot style='border:1px solid grey;'>\n\t\t\t<tr>\n\t\t\t  <td colspan='6' >\n\t\t\t\t<div class='bloc' >\n\t\t\t\t<img src='images/magnifglass.png' /> " . get_lang('statistics') . ": {$stats_servers_online}/{$stats_servers} " . get_lang('servers') . "\n</div>\n\t\t\t\t<div class='right bloc' >\n\t\t\t\t  <label>" . get_lang('execute_selected_server_operations') . "</label>\n\t\t\t\t  <input id='execute_operations' type='submit' value='" . get_lang('execute_operations') . "' >\n\n\t\t\t\t</div>\n\t\t\t  </td>\n\t\t\t</tr>\n\t\t  </tfoot>";
    echo "</table>";
    ?>
	<script type="text/javascript">
			$(document).ready(function() 
				{ 
					<?php 
    echo $refresh->build("8000");
    ?>
					$('input#search').quicksearch('table#servermonitor tbody tr.maintr');
					$("#servermonitor")
						.collapsible("td.collapsible", {collapse: true})
						.tablesorter({sortList: [[0,0], [1,0]] , widgets: ['zebra','repeatHeaders']})
						; 
				} 
			);
			
			$("div#server_icon").click(function(){
				var id = $(this).attr('class');
				if($("input[type=radio]."+id).attr('checked') == 'checked')
				{
					$("input[type=radio]."+id).prop('checked', false);
				}
				else
				{
					$("input[type=radio]."+id).prop('checked', true);
				}
			});
						
			$('.size').click(function(){
				var $id = $(this).attr('id');
				$.get( "home.php?m=user_games&type=cleared&p=get_size&home_id="+$id, function( data ) {
					$('#'+$id+".size").text( data );
					$('#'+$id+".size").css("font-size", "16pt");
				});
			});
			
			$('#execute_operations').click(function(){
				var addpost = {};
				$('input[type=radio]:checked').each(function( ){
					var name = $(this).attr('name');
					var value = $(this).val();
					addpost[ name ] = value;
				});
				
				$('.right.bloc').html('<img src="images/loading.gif" />');
				
				$.ajax({
				type: "POST",
				url: "home.php?m=gamemanager&p=game_monitor",
				data: addpost,
				complete: function(){ 
					document.location.reload(); 
				}
				});
			});
			
			$('img#action-stop').click(function(){
				$('input[type=radio]#action-stop').each(function( ){
					if( this.checked )
					{
						$(this).attr('checked', false);
					}
					else
					{
						$(this).attr('checked', true);
					}
				});
			});
			
			$('img#action-restart').click(function(){
				$('input[type=radio]#action-restart').each(function( ){
					if( this.checked )
					{
						$(this).attr('checked', false);
					}
					else
					{
						$(this).attr('checked', true);
					}
				});
			});
			
			$('img#action-start').click(function(){
				$('input[type=radio]#action-start').each(function( ){
					if( this.checked )
					{
						$(this).attr('checked', false);
					}
					else
					{
						$(this).attr('checked', true);
					}
				});
			});
		</script>
	<?php 
}
예제 #24
0
function exec_ogp_module()
{
    global $db;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if (isset($_REQUEST['user_id']) && !$isAdmin) {
        echo "<p class='note'>" . get_lang('not_available') . "</p>";
        return;
    }
    if (isset($_REQUEST['group_id']) && !$isAdmin) {
        $result = $db->getUserGroupList($_SESSION['user_id']);
        foreach ($result as $row) {
            if ($row['group_id'] == $_REQUEST['group_id']) {
                $own_group = TRUE;
            }
        }
    }
    if (!$isAdmin && !isset($own_group)) {
        echo "<p class='note'>" . get_lang('not_available') . "</p>";
        return;
    }
    if (!isset($_REQUEST['user_id']) && !isset($_REQUEST['group_id'])) {
        print_failure(get_lang("invalid_url"));
        return;
    }
    /// \todo We might want to save this information to XML file?
    $selections = array("allow_updates" => "u", "allow_file_management" => "f", "allow_parameter_usage" => "p", "allow_extra_params" => "e", "allow_ftp" => "t", "allow_custom_fields" => "c");
    if (isset($_REQUEST['user_id'])) {
        $assign_id = $_REQUEST['user_id'];
        $id_type = "user";
        $user = $db->getUserById($assign_id);
        $assign_name = $user['users_login'];
    } else {
        if (isset($_REQUEST['group_id'])) {
            $assign_id = $_REQUEST['group_id'];
            $id_type = "group";
            $group = $db->getGroupById($assign_id);
            $assign_name = $group['group_name'];
        }
    }
    $submit = isset($_POST['submit']) ? $_POST['submit'] : "";
    if (isset($_REQUEST['assign'])) {
        $access_rights = "";
        foreach ($selections as $selection => $flag) {
            if (isset($_REQUEST[$selection])) {
                $access_rights .= $flag;
            }
        }
        $hacker = FALSE;
        if (!$isAdmin) {
            $home_info = $db->getUserGameHome($_SESSION['user_id'], $_REQUEST['home_id']);
            if (!$home_info) {
                print_failure(get_lang_f("failed_to_assign_game_for", $id_type, "(Hacking attempt)"));
                $hacker = TRUE;
            } else {
                foreach ($selections as $selection => $flag) {
                    if (isset($_REQUEST[$selection])) {
                        if (!preg_match("/{$flag}/", $home_info['access_rights'])) {
                            print_failure(get_lang_f("failed_to_assign_game_for", $id_type, "(Hacking attempt)"));
                            $hacker = TRUE;
                        }
                    }
                }
            }
        }
        if (!$hacker) {
            if ($db->assignHomeTo($id_type, $assign_id, $_REQUEST['home_id'], $access_rights) === TRUE) {
                print_success(get_lang_f("assigned_home_to_" . $id_type, $_REQUEST['home_id'], $assign_name));
                $db->logger(get_lang_f("assigned_home_to_" . $id_type, $_REQUEST['home_id'], $assign_name));
            } else {
                print_failure(get_lang_f("failed_to_assign_game_for_", $id_type, $db->getError()));
            }
        }
        unset($_POST['home_id']);
    } else {
        if (isset($_REQUEST['unassign'])) {
            if ($db->unassignHomeFrom($id_type, $assign_id, $_REQUEST['home_id']) === TRUE) {
                print_success(get_lang_f("unassigned_home_from_" . $id_type, $_REQUEST['home_id'], $assign_name));
                $db->logger(get_lang_f("unassigned_home_from_" . $id_type, $_REQUEST['home_id'], $assign_name));
            } else {
                print_failure(get_lang_f("failed_to_assign_game_from_", $id_type));
            }
        }
    }
    $remote_servers = $db->getRemoteServers();
    if (empty($remote_servers)) {
        print_failure(get_lang("no_remote_servers_available_please_add_at_least_one"));
        echo "<p><a href='?m=server'>" . get_lang('add_remote_server') . "</a></p>";
        return;
    }
    if ($isAdmin) {
        $available_homes = $db->getAvailableHomesFor($id_type, $assign_id);
    } else {
        $available_homes = $db->getAvailableUserHomesFor($id_type, $assign_id, $_SESSION['user_id']);
    }
    if (!empty($available_homes)) {
        echo "<h2>" . get_lang_f('assign_new_home_to_' . $id_type, $assign_name) . "</h2>";
        echo "<form action='?m=user_games&amp;p=assign' method='post'>";
        echo "<input name='" . $id_type . "_id' value='" . $assign_id . "' type='hidden' />\n";
        echo "<table class='center'><tr><td align='right'><label for='home_id'>" . get_lang('select_home') . ":</label></td>";
        echo '<td align="left"><select id="home_id" name="home_id" onchange="this.form.submit();">';
        echo "<option></option>\n";
        foreach ($available_homes as $home) {
            if (isset($_POST['home_id']) && $_POST['home_id'] == $home['home_id']) {
                $selected = "selected='selected'";
            } else {
                $selected = "";
            }
            echo "<option value='" . $home['home_id'] . "' {$selected} >" . $home['home_name'] . "</option>\n";
        }
        echo "</select></td>\n";
        if (isset($_POST['home_id']) and !empty($_POST['home_id'])) {
            if ($isAdmin) {
                $access_rights = "ufpetc";
            } else {
                $home_info = $db->getUserGameHome($_SESSION['user_id'], $_POST['home_id']);
                $access_rights = $home_info['access_rights'];
            }
            foreach ($selections as $selection => $flag) {
                echo create_selection($selection, $flag, $access_rights);
            }
            echo "<tr><td colspan='2'><input type='submit' name='assign' value='" . get_lang('assign') . "' /></td></tr>";
        }
        echo "</table></form>";
    } else {
        echo "<h2>" . get_lang("no_more_homes_available_that_can_be_assigned_for_this_{$id_type}") . "</h2>";
        //print_lang('you_can_add_a_new_game_server_from');
        //echo "<a href='?m=user_games'>".get_lang('game_servers')."</a>.</p>";
        if ($isAdmin) {
            echo get_lang_f("you_can_add_a_new_game_server_from", "<a href='?m=user_games'>" . get_lang('game_servers') . "</a>") . "</p>";
        }
    }
    // View servers for use if there are any.
    $game_homes = $db->getHomesFor($id_type, $assign_id);
    if (empty($game_homes)) {
        echo "<h3>" . get_lang_f("no_homes_assigned_to_" . $id_type, $assign_name) . "</h3>";
    } else {
        echo "<h2>" . get_lang('assigned_homes') . "</h2>";
        echo '<table class="center">';
        echo "<tr><th>" . get_lang('home_id') . "</th><th>" . get_lang('game_server') . "</th>\n            <th>" . get_lang('game_type') . "</th>\n            <th align='center'>" . get_lang('game_home') . "</th>\n            <th>" . get_lang('game_home_name') . "</th><th>" . get_lang('access_rights') . "</th>\n            <th>" . get_lang('actions') . "</th></tr>";
        foreach ($game_homes as $row) {
            echo "<tr><td>{$row['home_id']}</td>\n                <td>" . $row['agent_ip'] . " (Agent)</td>\n                <td>{$row['game_name']}</td>\n                <td>{$row['home_path']}</td>\n                <td>{$row['home_name']}</td>\n                <td>";
            echo empty($row['access_rights']) ? "-" : $row['access_rights'];
            echo "</td>\n                <td>\n                <form action='?m=user_games&amp;p=assign' method='post'>\n                <input name='" . $id_type . "_id' value='{$assign_id}' type='hidden' />\n                <input name='home_id' value='" . $row['home_id'] . "' type='hidden' />\n                <input type='submit' name='unassign' value='" . get_lang('unassign') . "' /></form></td>\n                </tr>";
        }
        echo "</table>";
    }
    if ($id_type === "group") {
        echo create_back_button('user_admin', 'show_groups');
    } else {
        echo create_back_button('user_admin');
    }
}
예제 #25
0
function navigation()
{
    global $db;
    if (isset($_REQUEST['m'])) {
        if (preg_match('[/|\\|;|\\.]', $_REQUEST['m']) !== 0) {
            // Unallowed characters found.
            print_failure("Unallowed characters found from m.");
            return;
        }
        // If module is not installed we must not allow access.
        if ($db->isModuleInstalled($_REQUEST['m']) === FALSE) {
            print_failure(get_lang('module_not_installed'));
            return;
        }
        // If module dir does not exist there has been some error...
        if (!is_dir(MODULES . '/' . $_REQUEST['m'])) {
            print_failure("Invalid module " . $_REQUEST['m'] . ".");
            return;
        }
        // There is navigation.xml file lets parse the information.
        if (is_file(MODULES . '/' . $_REQUEST['m'] . '/navigation.xml')) {
            $xml_navig = simplexml_load_file(MODULES . '/' . $_REQUEST['m'] . '/navigation.xml');
            if ($xml_navig === FALSE) {
                print_failure("Invalid XML navigation file.");
                return;
            }
            // If the subpage is not defined we use the default page.
            $wanted_page = isset($_REQUEST['p']) ? $_REQUEST['p'] : "default";
            foreach ($xml_navig->page as $page) {
                if ($page["key"] != $wanted_page) {
                    continue;
                }
                $access_groups = explode(",", $page['access']);
                if (basename($_SERVER['PHP_SELF']) != "index.php") {
                    if (array_search($_SESSION['users_group'], $access_groups) === FALSE) {
                        print_failure(get_lang('no_rights'));
                        return;
                    }
                } else {
                    if (array_search("guest", $access_groups) === FALSE) {
                        print_failure(get_lang('no_rights'));
                        return;
                    }
                }
                $include_file = MODULES . '/' . $_REQUEST['m'] . '/' . $page['file'];
                if (!is_file($include_file)) {
                    print_failure("File (" . $include_file . ") missing from module.");
                    return;
                }
                include_once $include_file;
                if (!function_exists('exec_ogp_module')) {
                    print_failure("Missing module execute function.");
                    return;
                }
                exec_ogp_module();
                return;
            }
            print_failure("Invalid subpage given.");
            return;
        } else {
            if (is_file(MODULES . '/' . $_REQUEST['m'] . '/' . $_REQUEST['m'] . '.php')) {
                include MODULES . '/' . $_REQUEST['m'] . '/' . $_REQUEST['m'] . '.php';
                if (!function_exists('exec_ogp_module')) {
                    print_failure("Missing module execute function.");
                    return;
                }
                exec_ogp_module();
            } else {
                print_failure("Invalid module " . $_REQUEST['m'] . ".");
                return;
            }
        }
    }
}
예제 #26
0
function exec_ogp_module()
{
    global $db;
    global $view;
    echo "<h2>" . get_lang('add_new_game_home') . "</h2>";
    echo "<p><a href='?m=user_games'>&lt;&lt; " . get_lang('back_to_game_servers') . "</a></p>";
    $remote_servers = $db->getRemoteServers();
    if ($remote_servers === FALSE) {
        echo "<p class='note'>" . get_lang('no_remote_servers_configured') . "</p>\n\t\t\t  <p><a href='?m=server'>" . get_lang('add_remote_server') . "</a></p>";
        return;
    }
    $game_cfgs = $db->getGameCfgs();
    $users = $db->getUserList();
    if ($game_cfgs === FALSE) {
        echo "<p class='note'>" . get_lang('no_game_configurations_found') . " <a href='?m=config_games'>" . get_lang('game_configurations') . "</a></p>";
        return;
    }
    echo "<p> <span class='note'>" . get_lang('note') . ":</span> " . get_lang('add_mods_note') . "</p>";
    $selections = array("allow_updates" => "u", "allow_file_management" => "f", "allow_parameter_usage" => "p", "allow_extra_params" => "e", "allow_ftp" => "t", "allow_custom_fields" => "c");
    if (isset($_REQUEST['add_game_home'])) {
        $rserver_id = $_POST['rserver_id'];
        $home_cfg_id = $_POST['home_cfg_id'];
        $web_user_id = trim($_POST['web_user_id']);
        $control_password = genRandomString(8);
        $access_rights = "";
        $ftp = FALSE;
        foreach ($selections as $selection => $flag) {
            if (isset($_REQUEST[$selection])) {
                $access_rights .= $flag;
                if ($flag == "t") {
                    $ftp = TRUE;
                }
            }
        }
        if (empty($web_user_id)) {
            print_failure(get_lang('game_path_empty'));
        } else {
            foreach ($game_cfgs as $row) {
                if ($row['home_cfg_id'] == $home_cfg_id) {
                    $server_name = $row['game_name'];
                }
            }
            foreach ($remote_servers as $server) {
                if ($server['remote_server_id'] == $rserver_id) {
                    $ogp_user = $server['ogp_user'];
                }
            }
            foreach ($users as $user) {
                if ($user['user_id'] == $web_user_id) {
                    $web_user = $user['users_login'];
                }
            }
            $ftppassword = genRandomString(8);
            $game_path = "/home/" . $ogp_user . "/OGP_User_Files/";
            if (($new_home_id = $db->addGameHome($rserver_id, $web_user_id, $home_cfg_id, clean_path($game_path), $server_name, $control_password, $ftppassword)) !== FALSE) {
                $db->assignHomeTo("user", $web_user_id, $new_home_id, $access_rights);
                if ($ftp) {
                    $home_info = $db->getGameHomeWithoutMods($new_home_id);
                    require_once 'includes/lib_remote.php';
                    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
                    $host_stat = $remote->status_chk();
                    if ($host_stat === 1) {
                        $remote->ftp_mgr("useradd", $home_info['home_id'], $home_info['ftp_password'], $home_info['home_path']);
                    }
                    $db->changeFtpStatus('enabled', $new_home_id);
                }
                print_success(get_lang('game_home_added'));
                $db->logger(get_lang('game_home_added') . " ({$server_name})");
                $view->refresh("?m=user_games&amp;p=edit&amp;home_id={$new_home_id}");
            } else {
                print_failure(get_lang_f("failed_to_add_home_to_db", $db->getError()));
            }
        }
    }
    // View form to add more servers.
    if (!isset($_POST['rserver_id'])) {
        echo "<form action='?m=user_games&amp;p=add' method='post'>";
        echo "<table class='center'>";
        echo "<tr><td  class='right'>" . get_lang('game_server') . "</td><td class='left'><select onchange=" . '"this.form.submit()"' . " name='rserver_id'>\n";
        echo "<option>" . get_lang('select_remote_server') . "</option>\n";
        foreach ($remote_servers as $server) {
            echo "<option value='" . $server['remote_server_id'] . "'>" . $server['remote_server_name'] . " (" . $server['agent_ip'] . ")</option>\n";
        }
        echo "</select>\n";
        echo "</form>";
        echo "</td></tr></table>";
    } else {
        if (isset($_POST['rserver_id'])) {
            $rhost_id = $_POST['rserver_id'];
        }
        $remote_server = $db->getRemoteServer($rhost_id);
        require_once 'includes/lib_remote.php';
        $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
        $host_stat = $remote->status_chk();
        if ($host_stat === 1) {
            $os = $remote->what_os();
        } else {
            print_failure(get_lang_f("caution_agent_offline_can_not_get_os_and_arch_showing_servers_for_all_platforms"));
            $os = "Unknown OS";
        }
        echo "<form action='?m=user_games&amp;p=add' method='post'>";
        echo "<table class='center'>";
        echo "<tr><td class='right'>" . get_lang('game_type') . "</td><td class='left'> <select name='home_cfg_id'>\n";
        // Linux 64 bits + wine
        if (preg_match("/Linux/", $os) and preg_match("/64/", $os) and preg_match("/wine/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'];
                }
                if (preg_match("/64/", $row['game_key'])) {
                    echo " (64 bit)";
                }
                echo "</option>\n";
            }
            echo "<option style='background:black;color:white;' value=''>" . get_lang('wine_games') . ":</option>\n";
            foreach ($game_cfgs as $row) {
                if (preg_match("/win/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'];
                }
                if (preg_match("/64/", $row['game_key'])) {
                    echo " (64 bit)";
                }
                echo "</option>\n";
            }
        } elseif (preg_match("/Linux/", $os) and preg_match("/64/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'];
                }
                if (preg_match("/64/", $row['game_key'])) {
                    echo " (64 bit)";
                }
                echo "</option>\n";
            }
        } elseif (preg_match("/Linux/", $os) and preg_match("/wine/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux32/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'] . "</option>\n";
                }
            }
            echo "<option style='background:black;color:white;' value=''>" . get_lang('wine_games') . "</option>\n";
            foreach ($game_cfgs as $row) {
                if (preg_match("/win32/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif (preg_match("/Linux/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux32/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif (preg_match("/CYGWIN/", $os) and preg_match("/64/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/win/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'];
                }
                if (preg_match("/64/", $row['game_key'])) {
                    echo " (64 bit)";
                }
                echo "</option>\n";
            }
        } elseif (preg_match("/CYGWIN/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/win32/", $row['game_key'])) {
                    echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif ($os == "Unknown OS") {
            foreach ($game_cfgs as $row) {
                echo "<option value='" . $row['home_cfg_id'] . "'>" . $row['game_name'];
                if (preg_match("/64/", $row['game_key'])) {
                    echo " (64 bit)";
                }
                echo "</option>\n";
            }
        }
        echo "</select>\n</td></tr>";
        // Select user
        echo "<tr><td class='right'>" . get_lang('login') . ":</td>\n\t\t\t<td class='left'><select name='web_user_id'>";
        $users = $db->getUserList();
        foreach ($users as $user) {
            // Only users and admins can be assigned homes... not subusers
            if (is_null($user['users_parent'])) {
                echo "<option value='" . $user['user_id'] . "'>" . $user['users_login'] . "</option>\n";
            }
        }
        echo "</select>\n</td></tr>";
        // Select permisions
        echo "<tr><td class='right'>" . get_lang('access_rights') . ":</td>\n\t\t\t<td class='left'>";
        foreach ($selections as $selection => $flag) {
            echo create_selection($selection, $flag);
        }
        echo "</td></tr>";
        // Assign home
        echo "<tr><td align='center' colspan='2'>\n\t\t\t  <input type='hidden' name='rserver_id' value='" . $rhost_id . "' />" . "<input type='submit' name='add_game_home' value='" . get_lang('add_game_home') . "' /></td></tr></table>";
        echo "</form>";
    }
}
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&amp;p=game_monitor&amp;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&amp;p=update&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}", 5);
                        return;
                    }
                    echo "Installing Steam... wait.";
                    $steamcmdtrue = isset($_REQUEST['steamcmd']) ? "&amp;steamcmd=true" : "";
                    $view->refresh("?m=gamemanager&amp;p=update&amp;update=update&amp;home_id={$home_id}&amp;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&amp;p=game_monitor&amp;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&amp;p=update&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}\">";
    echo get_lang('refresh_steam_status') . "</a></p>";
    $view->refresh("?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}", 5);
    return;
}
예제 #28
0
function exec_ogp_module()
{
    if ($_SESSION['users_group'] != "admin") {
        print_failure(get_lang('no_access'));
        return;
    }
    global $db;
    global $view;
    echo "<h2>" . get_lang('update') . "</h2>";
    $panel_settings = $db->getSettings();
    $pversion = "" . $panel_settings['ogp_version'] . "";
    echo '<a href="?m=update&p=blacklist" >' . get_lang('blacklist_files') . "</a>&nbsp;" . get_lang('blacklist_files_info') . "</br></br>";
    echo get_lang('panel_version') . ": " . $pversion . "</br></br>";
    //Get SVN rev.
    $serverlist_url = "http://svn.code.sf.net/p/hldstart/code/trunk/upload/";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $serverlist_url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //Save Page
    $result = curl_exec($ch);
    curl_close($ch);
    //Parse the result to get the last version.
    preg_match_all("(<title>p/hldstart/code - Revision (.*): /trunk/upload</title>)siU", $result, $matches);
    $last_svn_version = $matches[1][0];
    if (isset($last_svn_version) and $last_svn_version != "") {
        echo get_lang('latest_version') . ": {$last_svn_version}</br></br>";
        //Check snapshot file exists.
        $ch = curl_init("http://master.dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/hldstart-code-{$last_svn_version}.zip");
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_exec($ch);
        $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        // Run the snapshot creation if it does not exists yet.
        if ($retcode == '404') {
            print_failure("The snapshot of the current version has not been created yet.");
            print_failure("Try again in 5 minutes.");
        } else {
            if ($last_svn_version != $pversion) {
                if (isset($_GET['view_changes'])) {
                    echo "<div style=\"\ttext-align:left;\n\t\t\t\t\t\t\t\t\t\twidth:80%;\n\t\t\t\t\t\t\t\t\t\tmargin:0 auto;\n\t\t\t\t\t\t\t\t\t\tpadding: 10px 5px;\n\t\t\t\t\t\t\t\t\t\tborder: 1px solid rgb(170, 170, 170);\n\t\t\t\t\t\t\t\t\t\tborder-radius: 4px;\n\t\t\t\t\t\t\t\t\t\tbackground-color: rgb(189, 229, 248);\" >";
                    for ($revision = $pversion + 1; $revision <= $last_svn_version; $revision++) {
                        $serverlist_url = "http://sourceforge.net/p/hldstart/code/{$revision}/";
                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_URL, $serverlist_url);
                        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
                        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: es-es,en"));
                        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        //Save Page
                        $result = curl_exec($ch);
                        curl_close($ch);
                        //Parse the result to get the last version.
                        preg_match_all("(<div class=\"commit-message\">(.*)</div>\n    <div class=\"commit-details\">)siU", $result, $matches);
                        $commit_message = str_replace("<div class=\"markdown_content\">", "\\sl\\", $matches[1][0]);
                        $commit_message = strip_tags($commit_message);
                        $commit_message = str_replace("\\sl\\", "<br>", $commit_message);
                        echo "<b>Revision {$revision} changes</b>: {$commit_message}<br><br>";
                    }
                    echo "</div>";
                } else {
                    echo "<form action='' method='get'>";
                    echo "<input type='hidden' name='m' value='update' />";
                    echo "<input type='hidden' name='view_changes' value='true' />";
                    echo "<input type='submit' value='" . get_lang('view_changes') . "' /></form>";
                    $messages_qty = $last_svn_version - $pversion;
                    if ($messages_qty >= 3) {
                        print_failure(get_lang_f('get_x_revison_messages_may_take_some_time', $messages_qty));
                    }
                }
                echo "<br>";
                $sf_mirrors = file("modules/update/mirrors.list");
                echo "<form action='?m=update&amp;p=updating&amp;version=" . $last_svn_version . "' method='post'>";
                echo get_lang('select_mirror') . ": " . create_drop_box_from_array_rsync($sf_mirrors, "mirror");
                echo "<br><br><input type='submit' value='" . get_lang('update_now') . "' /></form><br><br>";
            } else {
                print_failure(get_lang('the_panel_is_up_to_date'));
            }
        }
    } else {
        print_failure('sourceforge.net is down or not responding.');
    }
    echo "</div>";
}
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&amp;p=addons&amp;state=refresh&amp;home_id=" . $home_id . "&addon_id={$addon_id}&amp;pid={$pid}\">" . get_lang('refresh') . "</a></p>";
                $view->refresh("?m=addonsmanager&amp;p=addons&amp;state=refresh&amp;home_id=" . $home_id . "&addon_id={$addon_id}&amp;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&amp;p=user_addons&amp;home_id=" . $home_id, 10);
                return;
            }
        } else {
            echo "<p><a href=\"?m=addonsmanager&amp;p=addons&amp;state=refresh&amp;home_id=" . $home_id . "&addon_id={$addon_id}&amp;pid={$pid}\">" . get_lang('refresh') . "</a></p>";
            $view->refresh("?m=addonsmanager&amp;p=addons&amp;state=refresh&amp;home_id=" . $home_id . "&addon_id={$addon_id}&amp;pid={$pid}", 5);
        }
    } elseif (!empty($_GET['addon_type'])) {
        ?>
			<h2><?php 
        echo $home_info['home_name'] . "&nbsp;" . get_lang($_GET['addon_type']);
        ?>
</h2>
            <table class='center'>
			<form action='?m=addonsmanager&amp;p=addons<?php 
        echo "&amp;ip=" . $_GET['ip'] . "&amp;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'>&nbsp;</td></tr>
            <td align='left'>
			&nbsp;
			</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;
}
예제 #30
0
function exec_ogp_module()
{
    global $db;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    $submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : "";
    $home_id = $_GET['home_id'];
    $enabled_mods = $db->getHomeMods($home_id);
    if ($isAdmin and isset($_POST['change_home_cfg_id'])) {
        if (!empty($enabled_mods)) {
            foreach ($enabled_mods as $enabled_rows) {
                $db->delGameMod($enabled_rows['mod_id']);
            }
        }
        $home_cfg_id = $game_home['home_cfg_id'];
        $new_home_cfg_id = $_POST['home_cfg_id'];
        if ($db->updateHomeCfgId($home_id, $new_home_cfg_id)) {
            print_success(get_lang('successfully_changed_game_server'));
            $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_game_type') . ":old home_cfg_id:{$home_cfg_id}, new home_cfg_id:{$new_home_cfg_id}");
        }
        $enabled_mods = $db->getHomeMods($home_id);
    }
    if ($isAdmin) {
        $game_home = $db->getGameHome($_GET['home_id']);
    } else {
        $game_home = $db->getUserGameHome($_SESSION['user_id'], $_GET['home_id']);
    }
    if (!$game_home and !$isAdmin) {
        return;
    }
    $home_info = $db->getGameHomeWithoutMods($home_id);
    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . $home_info['home_cfg_file']);
    include 'includes/lib_remote.php';
    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
    $ftp_installed = $db->isModuleInstalled('ftp');
    $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']) === 1;
    if ($isAdmin) {
        $game_home['access_rights'] = "ufpet";
    }
    echo "<h2>" . get_lang('editing_home_called') . " \"" . $home_info['home_name'] . "\"</h2>";
    if (isset($_REQUEST['change_name'])) {
        $server_name = $_POST['server_name'];
        if ($db->changeHomeName($home_id, $server_name) === TRUE) {
            print_success(get_lang('successfully_changed_game_server'));
            $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('game_server_name') . ":{$server_name}");
        } else {
            print_failure("Name update failed.");
        }
    } elseif (isset($_REQUEST['change_control_password'])) {
        $control_password = $_POST['control_password'];
        if ($db->changeHomeControlPassword($home_id, $control_password) === TRUE) {
            print_success(get_lang('control_password_updated_successfully'));
            $db->logger(get_lang('control_password_updated_successfully') . " HOME ID:{$home_id} - " . get_lang('game_control_password') . ":{$control_password}");
        } else {
            print_failure(get_lang('control_password_update_failed'));
        }
    } elseif (isset($_REQUEST['change_ftp_login']) && preg_match("/t/", $game_home['access_rights']) > 0) {
        // Is FTP Module Installed?
        if ($ftp_installed) {
            if ($db->IsFtpEnabled($home_id) or $isAdmin) {
                $post_ftp_login = trim($_POST['ftp_login']);
                $host_stat = $remote->status_chk();
                $user_exists = FALSE;
                $host_online = FALSE;
                if ($host_stat === 1) {
                    $host_online = TRUE;
                    $ftp_accounts_list = $remote->ftp_mgr("list");
                    $ftp_accounts = explode("\n", $ftp_accounts_list);
                    foreach ($ftp_accounts as $ftp_account) {
                        if ($ftp_account != "") {
                            list($ftp_login, $ftp_path) = explode("\t", $ftp_account);
                            $ftp_login = trim($ftp_login);
                            if ($ftp_login == $post_ftp_login) {
                                $user_exists = TRUE;
                                break;
                            }
                        }
                    }
                }
                if ($host_online and !$user_exists) {
                    $old_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                    $change_login_delete_old = $remote->ftp_mgr("userdel", $old_login);
                    if ($change_login_delete_old !== 0) {
                        $change_login_add_new = $remote->ftp_mgr("useradd", $post_ftp_login, $home_info['ftp_password'], $home_info['home_path']);
                    }
                    if (isset($change_login_add_new) and $change_login_add_new !== 0) {
                        if ($db->changeFtpLogin($home_id, $post_ftp_login) === TRUE) {
                            print_success(get_lang('successfully_changed_game_server'));
                            $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('server_ftp_login') . ":{$post_ftp_login}");
                        }
                    } else {
                        print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_login_can_not_be_changed'));
                    }
                } else {
                    print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_login_can_not_be_changed'));
                }
            }
        }
    } elseif (isset($_REQUEST['change_ftp_password']) && preg_match("/t/", $game_home['access_rights']) > 0) {
        // Is FTP Module Installed?
        if ($ftp_installed) {
            if ($db->IsFtpEnabled($home_id) or $isAdmin) {
                $ftp_password = $_POST['ftp_password'];
                $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                $change_passwd_on_remote = $remote->ftp_mgr("passwd", $ftp_login, $ftp_password);
                if ($change_passwd_on_remote !== 0) {
                    if ($db->changeFtpPassword($home_id, clean_path($ftp_password)) === TRUE) {
                        print_success(get_lang('successfully_changed_game_server'));
                        $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('server_ftp_password') . ":{$ftp_password}");
                    }
                } else {
                    print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_password_can_not_be_changed'));
                }
            }
        }
    } elseif (isset($_POST["force_mod_id"])) {
        $force_mod_id = $_POST['force_mod_id'];
        $ip_id = $_POST['ip_id'];
        $port = $_POST['port'];
        if ($db->forceModAtAddress($ip_id, $port, $force_mod_id)) {
            print_success(get_lang('successfully_assigned_mod_to_address'));
            $db->logger(get_lang('successfully_assigned_mod_to_address'));
        } else {
            print_failure("Failed to assign mod to address.");
        }
    } elseif ($isAdmin) {
        if (isset($_REQUEST['create_ftp'])) {
            $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
            $create_ftp = $remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_info['home_path']);
            if ($create_ftp === 0) {
                print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_can_not_be_switched_on'));
            } else {
                $db->changeFtpStatus('enabled', $home_id);
                print_success(get_lang('successfully_changed_game_server'));
                $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_ftp_account_status') . ":enabled");
            }
        } else {
            if (isset($_REQUEST['delete_ftp'])) {
                $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                $delete_ftp = $remote->ftp_mgr("userdel", $login);
                if ($delete_ftp === 0) {
                    print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_can_not_be_switched_off'));
                } else {
                    $db->changeFtpStatus('disabled', $home_id);
                    print_success(get_lang('successfully_changed_game_server'));
                    $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_ftp_account_status') . ":disabled");
                }
            } else {
                if (isset($_REQUEST['change_user_id_main'])) {
                    $user_id_main = $_POST['user_id_main'];
                    if (isset($_POST['deleteoldassigns'])) {
                        $db->unassignHomeFrom("user", $home_info['user_id_main'], $home_id);
                        $home_groups = $db->getGroupsForHome($home_info['home_id']);
                        if (isset($home_groups)) {
                            foreach ($home_groups as $home_group) {
                                $db->unassignHomeFrom("group", $home_group['group_id'], $home_id);
                            }
                        }
                    }
                    $old_home = $db->getUserGameHome($home_info['user_id_main'], $home_id);
                    if ($db->changeUserIdMain($home_id, clean_path($user_id_main)) === TRUE && $db->assignHomeTo("user", $user_id_main, $home_id, $old_home['access_rights']) === TRUE) {
                        print_success(get_lang('successfully_changed_game_server'));
                        $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_user_id_main') . ":{$user_id_main}");
                    }
                } else {
                    if (isset($_REQUEST['change_home'])) {
                        $home_path = $_POST['home_path'];
                        if ($db->changeHomePath($home_id, clean_path($home_path)) === TRUE) {
                            if ($ftp_installed) {
                                if ($db->IsFtpEnabled($home_id)) {
                                    $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                                    $delte_old_ftp_account = $remote->ftp_mgr("userdel", $login);
                                    if ($delte_old_ftp_account !== 0) {
                                        $create_new_ftp_account = $remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_path);
                                    }
                                    if (isset($create_new_ftp_account) and $create_new_ftp_account !== 0) {
                                        print_success(get_lang('successfully_changed_game_server'));
                                        $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('home_path') . ":{$home_path}");
                                    } else {
                                        print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_login_can_not_be_changed'));
                                    }
                                } else {
                                    print_success(get_lang('successfully_changed_game_server'));
                                    $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('home_path') . ":{$home_path}");
                                }
                            } else {
                                print_success(get_lang('successfully_changed_game_server'));
                                $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('home_path') . ":{$home_path}");
                            }
                        }
                    } else {
                        if (isset($_REQUEST['master_server'])) {
                            if (isset($_POST['add'])) {
                                $action = "add";
                            } else {
                                $action = "remove";
                            }
                            if ($db->setMasterServer($action, $home_id, $home_info['home_cfg_id'], $home_info['remote_server_id']) === TRUE) {
                                print_success(get_lang('successfully_changed_game_server'));
                                $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('set_as_master_server') . ":{$action}");
                            }
                        }
                    }
                }
            }
        }
        if (isset($_REQUEST['add_mod'])) {
            $mod_cfg_id = $_POST['mod_cfg_id'];
            if ($db->addModToGameHome($home_id, $mod_cfg_id) === FALSE) {
                print_failure(get_lang_f('failed_to_assing_mod_to_home', $mod_cfg_id));
            } else {
                print_success(get_lang_f('successfully_assigned_mod_to_home', $mod_cfg_id));
                $db->logger(get_lang_f('successfully_assigned_mod_to_home', $mod_cfg_id) . " [HOME ID:{$home_id}]");
            }
        } else {
            if ($submit == "delete_mod") {
                $mod_id = $_GET['mod_id'];
                if ($db->delGameMod($mod_id) === TRUE) {
                    print_success(get_lang('successfully_removed_mod'));
                }
                $db->logger(get_lang('successfully_removed_mod') . " [MOD ID:{$mod_id} HOME ID:{$home_id}]");
            } else {
                if (isset($_REQUEST['set_options'])) {
                    $maxplayers = 0 + @$_POST['maxplayers'];
                    $cliopts = $_POST['cliopts'];
                    $cpus = $_POST['cpus'];
                    $nice = $_POST['nice'];
                    $mod_cfg_id = $_POST['mod_cfg_id'];
                    $db->updateGameModParams($maxplayers, $cliopts, $cpus, $nice, $home_id, $mod_cfg_id);
                    print_success(get_lang("successfully_modified_mod"));
                    $db->logger(get_lang('successfully_modified_mod') . " [MOD CFG ID:{$mod_cfg_id} HOME ID:{$home_id}]");
                    echo "<meta http-equiv='refresh' content='2'>";
                }
            }
        }
    }
    $home_info = $db->getGameHomeWithoutMods($home_id);
    $custom_fileds_access_enabled = preg_match("/c/", $game_home['access_rights']) > 0 ? TRUE : FALSE;
    echo "<p>";
    echo "<a href='?m=gamemanager&p=game_monitor&home_id={$home_id}'>&lt;&lt; " . get_lang('back_to_game_monitor') . "</a>";
    if ($isAdmin) {
        echo " &nbsp; ";
        echo "<a href='?m=user_games'>&lt;&lt; " . get_lang('back_to_game_servers') . "</a>";
        $custom_fileds_access_enabled = TRUE;
    }
    if (isset($server_xml->custom_fields) and $custom_fileds_access_enabled) {
        echo " &nbsp; <a href='?m=user_games&p=custom_fields&home_id=" . $home_id . "'>" . get_lang('go_to_custom_fields') . " &gt;&gt;</a>";
    }
    echo "</p>";
    echo "<table class='center'>";
    if ($isAdmin) {
        // Form to change game type
        echo "<tr><td rowspan='2' class='right'>" . get_lang('game_type') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        $game_cfgs = $db->getGameCfgs();
        $host_stat = $remote->status_chk();
        if ($host_stat === 1) {
            $os = $remote->what_os();
        } else {
            $os = "Unknown OS";
        }
        echo "<select name='home_cfg_id' >";
        // Linux 64 bits + wine
        if (preg_match("/Linux/", $os) and preg_match("/64/", $os) and preg_match("/wine/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
            echo "<option style='background:black;color:white;' value=''>" . get_lang('wine_games') . ":</option>\n";
            foreach ($game_cfgs as $row) {
                if (preg_match("/win/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
        } elseif (preg_match("/Linux/", $os) and preg_match("/64/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
        } elseif (preg_match("/Linux/", $os) and preg_match("/wine/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
            echo "<option style='background:black;color:white;' value=''>" . get_lang('wine_games') . "</option>\n";
            foreach ($game_cfgs as $row) {
                if (preg_match("/win32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif (preg_match("/Linux/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif (preg_match("/CYGWIN/", $os) and preg_match("/64/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/win/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
        } elseif (preg_match("/CYGWIN/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/win32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif ($os == "Unknown OS") {
            foreach ($game_cfgs as $row) {
                $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                if (preg_match("/64/", $row['game_key'])) {
                    echo " (64 bit)";
                }
                echo "</option>\n";
            }
        }
        echo "</select>\n</td></tr>";
        echo "<tr><td class='left'><input type='submit' name='change_home_cfg_id' value='" . get_lang('change_game_type') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('change_game_type_info') . "</td></tr>";
        // Form to edit main user.
        echo "<tr><td rowspan='3' class='right'>" . get_lang('user_id_main') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
        echo "<select name='user_id_main'>";
        $user = $db->getUserById($home_info['user_id_main']);
        echo "<option value='" . $home_info['user_id_main'] . "'>" . $user['users_login'] . "</option>\n";
        $users = $db->getUserList();
        foreach ($users as $user) {
            // Only users and admins can be assigned homes... not subusers
            if (is_null($user['users_parent'])) {
                if ($home_info['user_id_main'] != $user['user_id']) {
                    echo "<option value='" . $user['user_id'] . "'>" . $user['users_login'] . "</option>\n";
                }
            }
        }
        echo "</select></td></tr>";
        echo "<tr><td><input type='checkbox' name='deleteoldassigns' id='deleteoldassigns' /><label for='deleteoldassigns' >" . get_lang('Delete_old_user_assigned_homes') . "</label></td></tr>";
        echo "<tr><td class='left'><input type='submit' name='change_user_id_main' value='" . get_lang('change_user_id_main') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('change_user_id_main_info') . "</td></tr>";
        // Form to edit game path.
        echo "<tr><td class='right'>" . get_lang('home_path') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
        echo "<input type='text' size='30' name='home_path' value=" . $home_info['home_path'] . " />";
        echo "<input type='submit' name='change_home' value='" . get_lang('change_home') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('change_home_info') . "</td></tr>";
    }
    // Form to edit game name
    echo "<tr><td class='right'>" . get_lang('game_server_name') . ":</td><td class='left'>";
    echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
    echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
    echo "<input type='text' size='30' name='server_name' value='" . $home_info['home_name'] . "' />";
    echo "<input type=submit name='change_name' value='" . get_lang('change_name') . "' />";
    echo "</form></td></tr>";
    echo "<tr><td colspan='2' class='info'>" . get_lang('change_name_info') . "</td></tr>";
    // Form to edit control password
    echo "<tr><td class='right'>" . get_lang('game_control_password') . ":</td><td class='left'>";
    echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
    echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
    echo "<input type='text' size='30' name='control_password' value='" . $home_info['control_password'] . "' />";
    echo "<input type='submit' name='change_control_password' value='" . get_lang('change_control_password') . "' />";
    echo "</form></td></tr>";
    echo "<tr><td colspan='2' class='info'>" . get_lang('change_control_password_info') . "</td></tr>";
    if (preg_match("/t/", $game_home['access_rights']) > 0 && $ftp_installed && $db->IsFtpEnabled($home_id)) {
        // Form to edit control ftp login
        $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
        echo "<tr><td class='right'>" . get_lang('server_ftp_login') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='text' size='30' name='ftp_login' value='" . $ftp_login . "' />";
        echo "<input type='submit' name='change_ftp_login' value='" . get_lang('change_ftp_login') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td  colspan='2' class='info'>" . get_lang('change_ftp_login_info') . "</td></tr>";
        // Form to edit control ftp password
        echo "<tr><td class='right'>" . get_lang('server_ftp_password') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='text' size='30' name='ftp_password' value='" . $home_info['ftp_password'] . "' />";
        echo "<input type='submit' name='change_ftp_password' value='" . get_lang('change_ftp_password') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td  colspan='2' class='info'>" . get_lang('change_ftp_password_info') . "</td></tr>";
    }
    if ($isAdmin && $ftp_installed) {
        // Forms to enable/disable ftp account
        echo "<tr>";
        echo "<td class='right'>" . get_lang('change_ftp_account_status') . ":</td>";
        echo "<td class='left'>";
        if (!$db->IsFtpEnabled($home_id)) {
            echo "<div style='display:block;float:left;' ><form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
            echo "<input type='submit' name='create_ftp' value='" . get_lang('ftp_on') . "' />";
            echo "</form></div>";
        } else {
            echo "<div style='display:block;float:left;' ><form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
            echo "<input type='submit' name='delete_ftp' value='" . get_lang('ftp_off') . "' />";
            echo "</form></div>";
        }
        echo "</td></tr>";
        echo "<tr><td  colspan='2' class='info'>" . get_lang('change_ftp_account_status_info') . "</td>";
        echo "</tr>";
    }
    if ($isAdmin) {
        $master_server_home_id = $db->getMasterServer($home_info['remote_server_id'], $home_info['home_cfg_id']);
        if ($master_server_home_id != FALSE and $master_server_home_id == $home_id) {
            $checked = 'checked ="checked"';
        } else {
            $checked = "";
        }
        // Form to enable/disable as master server for local update
        echo "</tr><tr><td class='right'>" . get_lang('master_server_for_clon_update') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='checkbox' name='add' {$checked} />";
        echo "<input type='submit' name='master_server' value='" . get_lang('set_as_master_server') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('set_as_master_server_for_local_clon_update') . " (" . get_lang_f('only_available_for', $server_xml->game_name, $home_info['remote_server_name']) . ")</td></tr>";
    }
    echo "</table>";
    if ($isAdmin) {
        $avail_ips = $db->getRemoteServerIPs($home_info['remote_server_id']);
        $ip_array = array();
        if (is_array($avail_ips) && !empty($avail_ips)) {
            echo "<h3>" . get_lang('ips_and_ports') . "</h3>";
            if (!$screen_running) {
                if (isset($_REQUEST['set_ip'])) {
                    $ip_id = $_POST['ip'];
                    $ip_row = $db->resultQuery("SELECT ip FROM OGP_DB_PREFIXremote_server_ips WHERE ip_id=" . $ip_id);
                    $ip = $ip_row['0']['ip'];
                    $port = $_POST['port'];
                    $port = (int) trim($port);
                    $home_id = $_POST['home_id'];
                    if (!isPortValid($port)) {
                        print_failure(get_lang('port_range_error'));
                    } else {
                        if ($db->addGameIpPort($home_id, $ip_id, $port) === FALSE) {
                            print_failure(get_lang_f('ip_port_already_in_use', $ip, $port));
                        } else {
                            print_success(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
                            $db->logger(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
                        }
                    }
                }
                if (isset($_REQUEST["delete_ip"])) {
                    $del_ip = $_GET['ip'];
                    $del_port = $_GET['port'];
                    if ($db->delGameIpPort($home_id, $del_ip, $del_port)) {
                        print_success(get_lang('successfully_assigned_ip_port'));
                        $db->logger(get_lang('successfully_assigned_ip_port') . " [unassigned]");
                    } else {
                        print_failure("Failed to unassign ip:port.");
                    }
                }
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n";
                echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
                echo get_lang('ip') . ":<select name='ip' onchange='this.form.submit();'>";
                foreach ($avail_ips as $value) {
                    $selected = (isset($_POST['ip']) and $_POST['ip'] == $value['ip_id']) ? "selected='selected'" : "";
                    echo "<option value='" . $value['ip_id'] . "' {$selected} >" . $value['ip'] . "</option>\n";
                }
                echo "</select>";
                $ip_id = isset($_POST['ip']) ? $_POST['ip'] : $avail_ips[0]['ip_id'];
                $port = $db->getNextAvailablePort($ip_id, $home_info['home_cfg_id']);
                echo " " . get_lang('port') . ":<input type='text' name='port' value='" . $port . "' size='6' />";
                echo "<input type='submit' name='set_ip' value='" . get_lang('set_ip') . "' />";
                echo "</form>";
                $assigned = $db->getHomeIpPorts($home_id);
                if (empty($assigned)) {
                    print_failure(get_lang('no_ip_ports_assigned'));
                } else {
                    foreach ($assigned as $assigned_rows) {
                        $force_mod = "";
                        $align = "center";
                        if (!empty($enabled_mods) and count($enabled_mods) > 1) {
                            $force_mod .= "<td align='left'>\n" . "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n" . "<input type='hidden' name='ip_id' value=" . $assigned_rows['ip_id'] . " />" . "<input type='hidden' name='port' value=" . $assigned_rows['port'] . " />" . "<select name='force_mod_id' onchange='this.form.submit();'>" . "<option value='0' >" . get_lang('force_mod_on_this_address') . "</option>";
                            foreach ($enabled_mods as $mod) {
                                $selected = $mod['mod_id'] == $assigned_rows['force_mod_id'] ? "selected='selected'" : "";
                                $force_mod .= "<option value='" . $mod['mod_id'] . "' {$selected}>" . $mod['mod_name'] . "</option>";
                            }
                            $force_mod .= "</select>\n</form>\n</td>\n";
                            $align = "right";
                        }
                        echo "<table class='center'><tr><td align='{$align}'>" . $assigned_rows['ip'] . ":" . $assigned_rows['port'] . " <a href='?m=user_games&amp;p=edit&amp;home_id={$home_id}&amp;delete_ip&amp;ip=" . $assigned_rows['ip_id'] . "&amp;port=" . $assigned_rows['port'] . "'>[ " . get_lang('delete') . " ]</a></td>\n" . $force_mod . "</tr>\n</table>\n";
                    }
                }
            } else {
                print_failure(get_lang('server_is_running_change_addresses_not_available'));
            }
        } else {
            print_failure(get_lang('no_ip_addresses_configured') . "<a href='?m=server'>" . get_lang('server_page') . "</a>.");
        }
        echo "<h3>" . get_lang('mods') . "</h3>";
        echo "<p class='info'>" . get_lang('extra_cmd_line_info') . "</p>\n";
        if (empty($enabled_mods)) {
            print_failure(get_lang('note') . ":" . get_lang('note_no_mods'));
            $cpu_count = $remote->cpu_count();
            if ($cpu_count === -1) {
                print_failure(get_lang('warning_agent_offline_defaulting_CPU_count_to_1'));
                $cpu_count = 'NA';
            } else {
                // cpu numbering starts from 0 so lets remove the last cpu.
                $cpu_count -= 1;
            }
            $game_mods = $db->getAvailableModsForGameHome($home_id);
            foreach ($game_mods as $game_mod) {
                if ($game_mod['mod_name'] == "none") {
                    $mod_cfg_id = $game_mod['mod_cfg_id'];
                }
                if ($game_mod['mod_name'] == "None") {
                    $mod_cfg_id = $game_mod['mod_cfg_id'];
                }
            }
            if (isset($mod_cfg_id)) {
                $db->addModToGameHome($home_id, $mod_cfg_id);
                $maxplayers = $server_xml->max_user_amount ? $server_xml->max_user_amount : 0;
                $db->updateGameModParams($maxplayers, '', 'NA', '0', $home_id, $mod_cfg_id);
                echo "<meta http-equiv='refresh' content='0'>";
                return;
            } else {
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n";
                echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
                echo "<p>" . get_lang('available_mods') . ": <select name='mod_cfg_id'>\n";
                foreach ($game_mods as $game_mod) {
                    echo "<option value='" . $game_mod['mod_cfg_id'] . "'>" . $game_mod['mod_name'] . "</option>\n";
                }
                echo "</select>\n";
                echo "<input type='submit' name='add_mod' value='" . get_lang('add_mod') . "' /></p>";
                echo "</form>";
            }
        } else {
            $cpu_count = $remote->cpu_count();
            if ($cpu_count === -1) {
                print_failure(get_lang('warning_agent_offline_defaulting_CPU_count_to_1'));
                $cpu_count = 'NA';
            } else {
                // cpu numbering starts from 0 so lets remove the last cpu.
                $cpu_count -= 1;
            }
            echo "<table class='center'>\n";
            echo "<tr><td></td><td><b>" . get_lang('mod_name') . "</b></td>";
            if ($server_xml->max_user_amount) {
                echo "<td><b>" . get_lang('max_players') . "</b></td>";
            }
            echo "<td><b>" . get_lang('extra_cmd_line_args') . "</b></td><td><b>" . get_lang('cpu_affinity') . "</b></td>";
            echo "<td><b>" . get_lang('nice_level') . "</b></td><td></td></tr>\n";
            foreach ($enabled_mods as $enabled_rows) {
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'><tr><td>\n" . "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n" . "<input type='hidden' name='mod_cfg_id' value=\"" . $enabled_rows['mod_cfg_id'] . "\" />\n" . "<a href='?m=user_games&amp;p=edit&amp;mod_id=" . $enabled_rows['mod_id'] . "&amp;home_id={$home_id}&amp;submit=delete_mod'>[ " . get_lang('remove_mod') . " ]</a><br>" . "<a href='?m=user_games&p=install_cmds&home_id={$home_id}&mod_id=" . $enabled_rows['mod_id'] . "'>" . get_lang('mod_install_cmds') . "</a></td>" . "<td>" . $enabled_rows['mod_name'] . "</td>";
                if ($server_xml->max_user_amount) {
                    echo "<td>" . create_drop_box_from_array(range(0, $server_xml->max_user_amount), 'maxplayers', $enabled_rows['max_players'], true) . "</td>";
                }
                echo "<td><input type='text' name='cliopts' size='20' value=\"" . $enabled_rows['extra_params'] . "\" /></td>";
                echo "<td>" . create_drop_box_from_array(array_merge(array('NA'), range(0, $cpu_count)), 'cpus', $enabled_rows['cpu_affinity']) . "</td>";
                echo "<td>" . create_drop_box_from_array(array_merge(range(-19, 19)), 'nice', $enabled_rows['nice']) . "</td>";
                echo "<td><input type='submit' name='set_options' value='" . get_lang('set_options') . "' /></td></tr></form>\n";
            }
            echo "</table>\n";
            $game_mods = $db->getAvailableModsForGameHome($home_id);
            foreach ($game_mods as $game_mod) {
                if ($game_mod['mod_name'] == "none") {
                    $mods_available = 0;
                } elseif ($game_mod['mod_name'] == "None") {
                    $mods_available = 0;
                } else {
                    $mods_available = 1;
                }
            }
            if ($mods_available == 1) {
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n";
                echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
                echo "<p>" . get_lang('available_mods') . ": <select name='mod_cfg_id'>\n";
                foreach ($game_mods as $game_mod) {
                    echo "<option value='" . $game_mod['mod_cfg_id'] . "'>" . $game_mod['mod_name'] . "</option>\n";
                }
                echo "</select>\n";
                echo "<input type='submit' name='add_mod' value='" . get_lang('add_mod') . "' /></p>";
                echo "</form>";
            }
        }
    } else {
        $assigned = $db->getHomeIpPorts($home_id);
        if (!empty($assigned) and !empty($enabled_mods) and count($enabled_mods) > 1) {
            echo "<table class='center'>\n" . "<tr>\n" . "<td colspan='2' align='center'>" . "<h3>" . get_lang('switch_mods') . "</h3>" . "</td>\n" . "</tr>\n";
            foreach ($assigned as $assigned_rows) {
                $force_mod = "<tr>\n<td align='right' style='width:50%' >" . get_lang_f('switch_mod_for_address', $assigned_rows['ip'] . ":" . $assigned_rows['port']) . "</td>\n" . ($force_mod .= "<td align='left' style='width:50%' >\n" . "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n" . "<input type='hidden' name='ip_id' value=" . $assigned_rows['ip_id'] . " />" . "<input type='hidden' name='port' value=" . $assigned_rows['port'] . " />" . "<select name='force_mod_id' onchange='this.form.submit();'>");
                foreach ($enabled_mods as $mod) {
                    $selected = $mod['mod_id'] == $assigned_rows['force_mod_id'] ? "selected='selected'" : "";
                    $force_mod .= "<option value='" . $mod['mod_id'] . "' {$selected}>" . $mod['mod_name'] . "</option>";
                }
                $force_mod .= "</select>\n</form>\n</td>\n</tr>\n";
            }
            echo $force_mod . "</table>\n";
        }
    }
}