Пример #1
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 $view, $db;
    $ip = $_REQUEST['ip'];
    $port = $_REQUEST['port'];
    $home_id = $_REQUEST['home_id'];
    $user_id = $_SESSION['user_id'];
    $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);
    }
    require_once 'includes/lib_remote.php';
    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
    $mod_id = $_REQUEST['mod_id'];
    if ($home_info === FALSE) {
        print_failure(get_lang('no_rights_to_stop_server'));
        return;
    }
    echo "<h2>";
    echo empty($home_info['home_name']) ? get_lang('not_available') : $home_info['home_name'];
    echo "</h2>";
    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
    if (!$server_xml) {
        echo create_back_button("gamemanager", "game_monitor");
        return;
    }
    $rserver = $db->getRemoteServerById($home_info['remote_server_id']);
    if (empty($rserver)) {
        print_failure("" . get_lang('not_found_server') . " " . $home_info['remote_server_id'] . ".");
    } else {
        if (isset($_REQUEST['refresh'])) {
            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 = TRUE;
            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\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_f('server_restarted', $home_info['home_name']));
            $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_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $_REQUEST['ip'] . "-" . $_REQUEST['port']);
            echo "<p>" . get_lang('follow_server_status') . " <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('game_monitor') . "</a> " . get_lang('page') . ".</p>";
            return;
        } else {
            if ($server_xml->replace_texts) {
                $server_home = $home_info;
                if (isset($server_xml->lgsl_query_name)) {
                    require_once 'protocol/lgsl/lgsl_protocol.php';
                }
                require_once "modules/gamemanager/cfg_text_replace.php";
            }
            $control_type = isset($server_xml->control_protocol_type) ? $server_xml->control_protocol_type : "";
            $run_dir = isset($server_xml->exe_location) ? $server_xml->exe_location : "";
            $last_param = json_decode($home_info['last_param'], True);
            $cli_param_data['GAME_TYPE'] = $home_info['mods'][$mod_id]['mod_key'];
            $cli_param_data['IP'] = $ip;
            $cli_param_data['PORT'] = $port;
            $cli_param_data['HOSTNAME'] = $home_info['home_name'];
            $cli_param_data['PID_FILE'] = "ogp_game_startup.pid";
            $os = $remote->what_os();
            // Linux
            if (preg_match("/Linux/", $os)) {
                $cli_param_data['BASE_PATH'] = $home_info['home_path'];
                $cli_param_data['HOME_PATH'] = $home_info['home_path'];
                $cli_param_data['SAVE_PATH'] = $home_info['home_path'];
                $cli_param_data['OUTPUT_PATH'] = $home_info['home_path'];
                $cli_param_data['USER_PATH'] = $home_info['home_path'];
            } elseif (preg_match("/CYGWIN/", $os)) {
                $home_path_win = $remote->exec("cygpath -w " . $home_info['home_path']);
                $home_path_win = str_replace("\\", "\\\\", $home_path_win);
                $home_path_win = trim($home_path_win);
                $cli_param_data['BASE_PATH'] = $home_path_win;
                $cli_param_data['HOME_PATH'] = $home_path_win;
                $cli_param_data['SAVE_PATH'] = $home_path_win;
                $cli_param_data['OUTPUT_PATH'] = $home_path_win;
                $cli_param_data['USER_PATH'] = $home_path_win;
            }
            if ($server_xml->protocol == "gameq") {
                $cli_param_data['QUERY_PORT'] = get_query_port($server_xml, $port);
            } elseif ($server_xml->protocol == "lgsl") {
                require 'protocol/lgsl/lgsl_protocol.php';
                $get_ports = lgsl_port_conversion((string) $server_xml->lgsl_query_name, $port, "", "");
                $cli_param_data['QUERY_PORT'] = $get_ports['1'];
            } elseif ($server_xml->protocol == "teamspeak3") {
                $cli_param_data['QUERY_PORT'] = "10011";
            }
            $cli_param_data['MAP'] = empty($last_param['map']) ? "" : $last_param['map'];
            $cli_param_data['PLAYERS'] = empty($last_param['players']) ? $home_info['mods'][$mod_id]['max_players'] : $last_param['players'];
            $start_cmd = "";
            // If the template is empty then these are not needed.
            if ($server_xml->cli_template) {
                $start_cmd = $server_xml->cli_template;
                if ($server_xml->cli_params) {
                    foreach ($server_xml->cli_params->cli_param as $cli) {
                        // If s is found the param is seperated with space
                        $add_space = preg_match("/s/", $cli['options']) > 0 ? " " : "";
                        $cli_value = $cli_param_data[(string) $cli['id']];
                        // If q is found we add quotes around the value.
                        if (preg_match("/q/", $cli['options']) > 0) {
                            $cli_value = "\"" . $cli_value . "\"";
                        }
                        $start_cmd = preg_replace("/%" . $cli['id'] . "%/", $cli['cli_string'] . $add_space . $cli_value, $start_cmd);
                    }
                }
            }
            if ($isAdmin) {
                $home_info['access_rights'] = "ufpet";
            }
            $param_access_enabled = preg_match("/p/", $home_info['access_rights']) > 0 ? TRUE : FALSE;
            if ($param_access_enabled && isset($last_param)) {
                foreach ($server_xml->server_params->param as $param) {
                    foreach ($last_param as $paramKey => $paramValue) {
                        if (!isset($paramValue)) {
                            $paramValue = (string) $param->default;
                        }
                        if ($param['key'] == $paramKey) {
                            if (0 == strlen($paramValue)) {
                                continue;
                            }
                            if ($param['key'] == $paramValue) {
                                // it's a checkbox
                                $new_param = $paramKey;
                            } elseif ($param->option == "ns" or $param->options == "ns") {
                                $new_param = $paramKey . $paramValue;
                            } else {
                                $new_param = $paramKey . ' "' . $paramValue . '"';
                            }
                            if ($param['id'] == NULL || $param['id'] == "") {
                                $start_cmd .= ' ' . $new_param;
                            } else {
                                $start_cmd = preg_replace("/%" . $param['id'] . "%/", $new_param, $start_cmd);
                            }
                        }
                    }
                    $start_cmd = preg_replace("/%" . $param['id'] . "%/", '', $start_cmd);
                }
            }
            $extra_param_access_enabled = preg_match("/e/", $home_info['access_rights']) > 0 ? TRUE : FALSE;
            if (array_key_exists('extra', $last_param) && $extra_param_access_enabled) {
                $extra_default = $last_param['extra'];
            } else {
                $extra_default = $home_info['mods'][$mod_id]['extra_params'];
            }
            $start_cmd .= " " . $extra_default;
            $remote_retval = $remote->remote_restart_server($home_info['home_id'], $ip, $port, $server_xml->control_protocol, $home_info['control_password'], $control_type, $home_info['home_path'], $server_xml->server_exec_name, $run_dir, $start_cmd, $home_info['cpu_affinity'], $home_info['nice']);
            $db->logger(get_lang_f('server_restarted', $home_info['home_name']) . "({$ip}:{$port})");
            if ($remote_retval === 1) {
                print "<p class='note'>" . get_lang('restarting_server') . "</p>";
                $view->refresh("?m=gamemanager&amp;p=restart&amp;refresh&amp;ip={$ip}&amp;port={$port}&amp;home_id={$home_id}&amp;mod_id={$mod_id}", 3);
                return;
            } else {
                if ($remote_retval === -1) {
                    print_failure(get_lang('server_cant_start'));
                    $view->refresh("?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $ip . "-" . $port, 3);
                } else {
                    if ($remote_retval === -2) {
                        print_failure(get_lang('server_cant_stop'));
                        $view->refresh("?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $ip . "-" . $port, 3);
                    } else {
                        $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']);
                        if ($screen_running == 1) {
                            print "<p class='note'>" . get_lang('restarting_server') . "</p>";
                            $view->refresh("?m=gamemanager&amp;p=restart&amp;refresh&amp;ip={$ip}&amp;port={$port}&amp;home_id={$home_id}&amp;mod_id={$mod_id}", 3);
                            return;
                        } else {
                            print_failure("" . get_lang('error_occured_remote_host') . ".{$remote_retval}");
                            $view->refresh("?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=" . $home_info['home_id'] . "-" . $home_info['mod_id'] . "-" . $ip . "-" . $port, 3);
                        }
                    }
                }
            }
        }
    }
}
Пример #3
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";
        }
    }
}
Пример #4
0
function exec_ogp_module()
{
    global $view;
    global $db;
    echo "<h2>" . get_lang('add_new_remote_host') . "</h2>";
    echo "<p>" . get_lang('note_remote_host') . "</p>";
    require_once "includes/form_table_class.php";
    $ft = new FormTable();
    $ft->start_form("?m=server&amp;p=add");
    $ft->start_table();
    $ft->add_field('string', 'remote_host', "");
    $ft->add_field('string', 'remote_host_port', "12679");
    $ft->add_field('string', 'remote_host_name', "");
    $ft->add_field('string', 'remote_host_user_name', "");
    $ft->add_field('string', 'remote_host_ftp_ip', "");
    $ft->add_field('string', 'remote_host_ftp_port', "21");
    $ft->add_field('string', 'remote_encryption_key', "");
    $ft->add_field('string', 'timeout', "2");
    $ft->add_field('on_off', 'use_nat', "0");
    $ft->end_table();
    $ft->add_button('submit', 'add_remote_host', get_lang('add_remote_host'));
    $ft->end_form();
    $servers = $db->getRemoteServers();
    if ($servers === FALSE) {
        return;
    }
    $tr = 0;
    ?>
<table id="servermonitor" class="tablesorter remote">
		<thead> 
		<tr> 
			<th colspan="4" ><?php 
    print_lang('configured_remote_hosts');
    ?>
</th> 
		</tr> 
		</thead> 
		<tbody> <?php 
    foreach ($servers as $server_row) {
        #generate jQuery code
        $jqboobles["{$server_row['remote_server_id']}"] = '$("#tonus-' . $server_row['remote_server_id'] . '").tooltip({
						delay: 0,
						showURL: false,
						bodyHandler: function() {
							return $("<img/>").attr("src", this.src);
						}
					});';
        #check to see if the remote daeomns are up status_chk is found in lib_remote.php
        $remote = new OGPRemoteLibrary($server_row['agent_ip'], $server_row['agent_port'], $server_row['encryption_key']);
        $host_stat = $remote->status_chk();
        $buttons = "<a href='?m=server&amp;p=edit&amp;rhost_id=" . $server_row['remote_server_id'] . "&amp;delete'>[" . get_lang('delete') . "]</a>\n" . "<a href='?m=server&amp;p=edit&amp;rhost_id=" . $server_row['remote_server_id'] . "&amp;edit'>[" . get_lang('edit') . "]</a>\n";
        $tittle = "<b>ID#:</b>  <b style='color:red;'>" . $server_row['remote_server_id'] . "</b></td>\n\t\t\t\t\t<td class='collapsible' ><b>" . get_lang('server_name') . ":</b> " . $server_row['remote_server_name'] . "</td>\n\t\t\t\t\t<td class='collapsible' ><b>" . get_lang('agent_status') . ":</b> ";
        $booble = "";
        if ($host_stat === 0) {
            $tittle .= "<span class='failure'>" . get_lang('offline') . "</span> ";
        } elseif ($host_stat === 1) {
            $os = $remote->what_os();
            $buttons .= "<a href='?m=server&amp;p=log&amp;rhost_id=" . $server_row['remote_server_id'] . "'>[" . get_lang('view_log') . "]</a>\n";
            $tittle .= "<span class='success'>" . get_lang('online') . "</span>";
            $booble .= "<img id='tonus-{$server_row['remote_server_id']}' src='includes/api.php?remote_server={$server_row['remote_server_id']}&mon_stats' height='20' />";
        } elseif ($host_stat === -1) {
            $tittle .= "<span class='failure'>" . get_lang('encryption_key_mismatch') . "</span>\n";
        } else {
            $tittle .= "<span class='failure'>" . get_lang('unknown_error') . ": {$host_stat}</span>\n";
        }
        $tittle .= "</td><td>{$buttons}</td>";
        $ftp_ip = empty($server_row['ftp_ip']) ? $server_row['agent_ip'] : $server_row['ftp_ip'];
        $data = "<tr class='expand-child' >\n\t\t\t\t   <td>{$booble}</td><td>\n\t\t\t\t\t<b>" . get_lang('ogp_user') . ":</b> " . $server_row['ogp_user'] . "<br />\n\t\t\t\t\t<b>" . get_lang('agent_ip_port') . ":</b> " . $server_row['agent_ip'] . ":" . $server_row['agent_port'] . "<br />\n\t\t\t\t\t<b>" . get_lang('remote_host_ftp_ip') . ":</b> " . $ftp_ip . "<br />\n\t\t\t\t\t<b>" . get_lang('remote_host_ftp_port') . ":</b> " . $server_row['ftp_port'] . "<br />\n\t\t\t\t\t<b>" . get_lang('timeout') . ":</b> " . $server_row['timeout'] . "&nbsp;" . get_lang('seconds') . "<br />\n\t\t\t\t\t<b>" . get_lang('encryption_key') . ":</b> " . $server_row['encryption_key'] . "<br />\n\t\t\t\t   </td>\n\t\t\t\t   <td><b>" . get_lang('ips') . ": </b><br>";
        // Next we print the IP addresses and one empty field.
        $remote_server_ips = $db->getRemoteServerIPs($server_row['remote_server_id']);
        if (empty($remote_server_ips)) {
            $data .= "<span class='failure'>" . get_lang('no_ip_for_remote_host') . "</span>";
        } else {
            foreach ($remote_server_ips as $ip_row) {
                $data .= $ip_row['ip'] . "<br>";
            }
        }
        $data .= "</td><td>";
        if ($host_stat === 1) {
            $data .= "<b>OS:</b> " . @$os . "<br>";
            if (preg_match("/Linux/", $os)) {
                $data .= "<b>" . get_lang('ufw') . ":</b>";
                if (isset($_GET['ch_ufw_status']) and $server_row['remote_server_id'] == $_GET['rhost_id']) {
                    $rhost_id = $_GET['rhost_id'];
                    $ch_ufw_status = $_GET['ch_ufw_status'];
                    $db->query("UPDATE `OGP_DB_PREFIXremote_servers`\n\t\t\t\t\t\t\t\tSET ufw_status = '{$ch_ufw_status}'\n\t\t\t\t\t\t\t\tWHERE remote_server_id  = '{$rhost_id}'");
                    if ($ch_ufw_status == "enable") {
                        $remote->sudo_exec("ufw allow " . $server_row['agent_port']);
                        //OGP agent port
                        $remote->sudo_exec("ufw allow " . $server_row['ftp_port']);
                        //FTP port
                        $remote->sudo_exec("ufw allow 80");
                        //Apache (web server) port
                        $remote->sudo_exec("ufw allow 22");
                        //SSH (putty) port
                        $remote->sudo_exec("ufw allow 25");
                        //SMTP (mail) port
                        $remote->sudo_exec("ufw allow proto tcp to any port 40000:65000");
                        //unknow range of ports needed by the OGP agent
                        $remote->sudo_exec("echo y | ufw {$ch_ufw_status}");
                    } else {
                        $remote->sudo_exec("ufw {$ch_ufw_status}");
                    }
                }
                if (!$db->query("SELECT ufw_status FROM `OGP_DB_PREFIXremote_servers`")) {
                    $status = "disable";
                } else {
                    $status = $db->resultQuery("SELECT ufw_status \n\t\t\t\t\t\t\t\t\t\t  FROM `OGP_DB_PREFIXremote_servers` \n\t\t\t\t\t\t\t\t\t\t  WHERE remote_server_id  = '" . $server_row['remote_server_id'] . "'");
                    $status = $status[0]['ufw_status'];
                    if (empty($status)) {
                        $status = "disable";
                    }
                }
                $data .= "<br />";
                if ($status == "enable") {
                    $data .= "<b>" . get_lang('status') . "</b> " . get_lang('on') . "<br />\n\t\t\t\t\t\t\t  <a href='?m=server&amp;rhost_id=" . $server_row['remote_server_id'] . "&amp;ch_ufw_status=disable'>[" . get_lang('stop_firewall') . "]</a>\n";
                } elseif ($status == "disable") {
                    $data .= "<b>" . get_lang('status') . "</b> " . get_lang('off') . "<br />\n\t\t\t\t\t\t\t  <a href='?m=server&amp;rhost_id=" . $server_row['remote_server_id'] . "&amp;ch_ufw_status=enable'>[" . get_lang('start_firewall') . "]</a>\n";
                }
                $data .= "<br />";
            }
        }
        $data .= "</td></tr>";
        // Template
        $first = "<tr class='maintr'><td class='collapsible' >{$tittle}</td></tr>";
        $second = $data;
        //Echo them all
        echo "{$first}{$second}";
    }
    echo "</tbody>";
    echo "</table>\n";
    ?>
<script type="text/javascript">
$(function() {
<?php 
    foreach ($jqboobles as $jqbooble) {
        echo "{$jqbooble}\n";
    }
    ?>
});
</script>
<script type="text/javascript">
$(document).ready(function(){ 
	$("#servermonitor")
		.collapsible("td.collapsible", {collapse: true})
		.tablesorter({sortList: [[0,0], [1,0]] , widgets: ['zebra','repeatHeaders']});
});
</script>
<?php 
}
function exec_ogp_module()
{
    global $db, $view;
    if (isset($_GET['rserver_id']) and $_GET['rserver_id'] != "") {
        $remote_server_ips = $db->getRemoteServerIPs($_GET['rserver_id']);
        if (!empty($remote_server_ips)) {
            if (isset($_GET['ip_id']) and $_GET['ip_id'] != "") {
                $ip = $db->getIpById($_GET['ip_id']);
                echo "<h2>" . get_lang_f('assign_new_ports_range_for_ip', $ip) . "</h2>";
                if (isset($_POST['assign_range'])) {
                    if ($_POST['home_cfg_id'] != "0") {
                        $cfg_info = $db->getGameCfg($_POST['home_cfg_id']);
                    } else {
                        $cfg_info['game_name'] = get_lang('unspecified_game_types');
                    }
                    $retval = $db->addPortsRange($_POST['ip_id'], $_POST['home_cfg_id'], $_POST['start_port'], $_POST['end_port'], $_POST['port_increment']);
                    if ($retval === 1) {
                        print_failure(get_lang('invalid_values'));
                    } elseif ($retval === 2) {
                        print_failure(get_lang('ports_in_range_already_arranged'));
                    } elseif ($retval) {
                        print_success(get_lang_f('ports_range_added_successfull_for', $cfg_info['game_name']));
                    } else {
                        print_failure(get_lang_f('ports_range_already_configured_for', $cfg_info['game_name']));
                    }
                    $view->refresh('?m=server&p=arrange_ports&rserver_id=' . $_GET['rserver_id'] . '&ip_id=' . $_GET['ip_id'], 3);
                }
                $game_homes = $db->getIpPorts($_GET['ip_id']);
                $game_cfgs = $db->getGameCfgs();
                //
                require_once 'includes/lib_remote.php';
                $rhost_id = $_GET['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 method='POST' action=''>\n\n\t\t\t\t\t  <input type='hidden' name='ip_id' value='" . $_GET['ip_id'] . "' />\n\n\t\t\t\t\t  <table>\n\n\t\t\t\t\t  <tr>\n\n\t\t\t\t\t  <td>\n\n\t\t\t\t\t  <select name='home_cfg_id'>\n\n\t\t\t\t\t  <option style='background:black;color:white;' value='0'>" . get_lang('unspecified_game_types') . "</option>\n";
                echo "<b>" . get_lang('assign_range_to_game_type') . ":</b>";
                // 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\n\t\t\t\t\t  </td>\n\n\t\t\t\t\t  <td>\n" . get_lang('start_port') . "<input type='text' id='start_port' name='start_port' class='add' size='8' />\n\n\t\t\t\t\t   </td>\n\n\t\t\t\t\t   <td>\n" . get_lang('end_port') . "<input type='text' id='end_port' name='end_port' class='add' size='8' />\n\n\t\t\t\t\t   </td>\n\n\t\t\t\t\t   <td>\n\n\t\t\t\t\t   " . get_lang('port_increment') . "<input type='text' id='port_increment' name='port_increment' class='add' value='1' size='2' />\n\n\t\t\t\t\t   </td>\n\n\t\t\t\t\t   <td>\n\n\t\t\t\t\t   " . get_lang('total_assignable_ports') . "\t<span id='total_assignable_ports' class='add'></span>\n\n\t\t\t\t\t   </td>\n\n\t\t\t\t\t   <td>\n" . "<input type='submit' name='assign_range' value='" . get_lang('assign_range') . "' />\n\n\t\t\t\t\t   </td>\n \n\t\t\t\t\t   </tr>\n \n\t\t\t\t\t   </table>\n\n\t\t\t\t\t   </form>\n";
                echo "<h2>" . get_lang_f('assigned_port_ranges_for_ip', $ip) . "</h2>";
                //
                if (isset($_POST['delete_range'])) {
                    if ($db->delPortsRange($_POST['range_id'])) {
                        print_success(get_lang('ports_range_deleted_successfull'));
                    } else {
                        print_failure(get_lang('failed_to_delete_ports_range'));
                    }
                    $view->refresh('?m=server&p=arrange_ports&rserver_id=' . $_GET['rserver_id'] . '&ip_id=' . $_GET['ip_id'], 3);
                }
                if (isset($_POST['edit_range'])) {
                    if ($_POST['home_cfg_id'] != "0") {
                        $cfg_info = $db->getGameCfg($_POST['home_cfg_id']);
                    } else {
                        $cfg_info['game_name'] = get_lang('unspecified_game_types');
                    }
                    $retval = $db->editPortsRange($_POST['range_id'], $_POST['ip_id'], $_POST['start_port'], $_POST['end_port'], $_POST['port_increment']);
                    if ($retval === 1) {
                        print_failure(get_lang('invalid_values'));
                    } elseif ($retval === 2) {
                        print_failure(get_lang('ports_in_range_already_arranged'));
                    } elseif ($retval) {
                        print_success(get_lang_f('ports_range_edited_successfull_for', $cfg_info['game_name']));
                    } else {
                        print_failure(get_lang_f('ports_range_already_configured_for', $cfg_info['game_name']));
                    }
                    $view->refresh('?m=server&p=arrange_ports&rserver_id=' . $_GET['rserver_id'] . '&ip_id=' . $_GET['ip_id'], 3);
                }
                $ranges = $db->getPortsRange($_GET['ip_id']);
                if (!empty($ranges)) {
                    echo "<table>\n";
                    foreach ($ranges as $range) {
                        if ($range['home_cfg_id'] != "0") {
                            $cfg_info = $db->getGameCfg($range['home_cfg_id']);
                        } else {
                            $cfg_info['game_name'] = get_lang('unspecified_game_types');
                        }
                        $available_ports_amount = intval(($range['end_port'] - $range['start_port']) / $range['port_increment'] + 1);
                        $usable_range_ports = array();
                        for ($port = $range['start_port']; $port >= $range['start_port'] and $port <= $range['end_port']; $port += $range['port_increment']) {
                            $usable_range_ports[] = $port;
                        }
                        $used_ports = array();
                        if (!empty($game_homes)) {
                            foreach ($game_homes as $game_home) {
                                $used_ports[] = $game_home['port'];
                            }
                        }
                        if (!empty($used_ports)) {
                            foreach ($used_ports as $used_port) {
                                if (in_array($used_port, $usable_range_ports)) {
                                    $available_ports_amount--;
                                }
                            }
                        }
                        echo "<form method='POST' action=''>\n\n\t\t\t\t\t\t\t  <input type='hidden' name='range_id' value='" . $range['range_id'] . "' />\n\n\t\t\t\t\t\t\t  <input type='hidden' name='ip_id' value='" . $range['ip_id'] . "' />\n\n\t\t\t\t\t\t\t  <input type='hidden' name='home_cfg_id' value='" . $range['home_cfg_id'] . "' />\n\n\t\t\t\t\t\t\t  <tr>\n\n\t\t\t\t\t\t\t   <td>\n" . $cfg_info['game_name'] . "</td>\n\n\t\t\t\t\t\t\t   <td>\n" . get_lang('start_port') . "<input type='text' id='start_port' name='start_port' value='" . $range['start_port'] . "' size='8' />\n\n\t\t\t\t\t\t\t   </td>\n\n\t\t\t\t\t\t\t   <td>\n" . get_lang('end_port') . "<input type='text' id='end_port' name='end_port' value='" . $range['end_port'] . "' size='8' />\n\n\t\t\t\t\t\t\t   </td>\n\n\t\t\t\t\t\t\t   <td>\n" . get_lang('port_increment') . "<input type='text' id='port_increment' name='port_increment' value='" . $range['port_increment'] . "' value='1' size='2' />\n\n\t\t\t\t\t\t\t   </td>\n\n\t\t\t\t\t\t\t   <td>\n" . get_lang('available_range_ports') . "\t<span id='available_range_ports'>" . $available_ports_amount . "</span>\n\n\t\t\t\t\t\t\t   </td>\n\n\t\t\t\t\t\t\t   <td>\n\n\t\t\t\t\t\t\t\t<input type='submit' name='edit_range' value='" . get_lang('edit_range') . "' />\n\n\t\t\t\t\t\t\t\t<input type='submit' name='delete_range' value='" . get_lang('delete_range') . "' />\n\n\t\t\t\t\t\t\t   </td>\n \n\t\t\t\t\t\t\t  </tr>\n \n\t\t\t\t\t\t   </form>\n";
                    }
                    echo "</table>\n";
                }
                echo "<h2>" . get_lang_f('assigned_ports_for_ip', $ip) . "</h2>";
                if (!empty($game_homes)) {
                    echo "<table class='center'>";
                    echo "<tr><th>" . get_lang('home_id') . "</th><th>" . get_lang('home_path') . "</th><th>" . get_lang('game_type') . "</th><th>" . get_lang('server_name') . "</th><th>" . get_lang('port') . "</th></tr>";
                    foreach ($game_homes as $game_home) {
                        echo "<tr><td>" . $game_home['home_id'] . "</td><td>" . $game_home['home_path'] . "</td><td>" . $game_home['game_name'] . "</td><td>" . $game_home['home_name'] . "</td><td>" . $game_home['port'] . "</td></tr>";
                    }
                    echo "</table>";
                }
            }
        } else {
            echo "There are no IPs assigned to the selected remote server.";
            return;
        }
        echo create_back_button('server', 'edit&rhost_id=' . $_GET['rserver_id'] . '&edit');
    }
    ?>
	<script type="text/javascript">
		$(document).ready(function(){
			$("input[type=text]").each(function(){
				$(this).numeric();
			});
			$('input#start_port.add').on('input', function() {
				$('input#end_port.add').val( Number($(this).val()) );
				$('span#total_assignable_ports.add').html(  parseInt( ( Number( $('input#end_port.add').val() ) - Number( $(this).val() ) ) / Number( $('input#port_increment.add').val() ) ) + 1 );
			});
			$('input#end_port.add').on('input', function() {
				$('span#total_assignable_ports.add').html(  parseInt( ( Number( $(this).val() ) - Number( $('input#start_port.add').val() ) ) / Number( $('input#port_increment.add').val() ) ) + 1 );
			});
			$('input#port_increment.add').on('input', function() {
				$('span#total_assignable_ports.add').html(  parseInt( ( Number( $('input#end_port.add').val() ) - Number( $('input#start_port.add').val() ) ) / Number( $(this).val() ) ) + 1 );
			});
		});
	</script>
<?php 
}
Пример #6
0
 // It compares ip and port on POST with the pair on DB for security reasons (FORM 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'] == $ip && $ip_ports_row['port'] == $port) {
         $cli_param_data['IP'] = $ip_ports_row['ip'];
         $cli_param_data['PORT'] = $ip_ports_row['port'];
     }
 }
 if (!isset($cli_param_data['IP']) or !isset($cli_param_data['PORT'])) {
     echo "<h2>" . get_lang_f('ip_port_pair_not_owned') . "</h2>";
     return;
 }
 $cli_param_data['HOSTNAME'] = $home_info['home_name'];
 $cli_param_data['PID_FILE'] = "ogp_game_startup.pid";
 $os = $remote->what_os();
 // Linux
 if (preg_match("/Linux/", $os)) {
     $cli_param_data['BASE_PATH'] = $home_info['home_path'];
     $cli_param_data['HOME_PATH'] = $home_info['home_path'];
     $cli_param_data['SAVE_PATH'] = $home_info['home_path'];
     $cli_param_data['OUTPUT_PATH'] = $home_info['home_path'];
     $cli_param_data['USER_PATH'] = $home_info['home_path'];
 } elseif (preg_match("/CYGWIN/", $os)) {
     $home_path_win = $remote->exec("cygpath -w " . $home_info['home_path']);
     $home_path_win = str_replace("\\", "\\\\", $home_path_win);
     $home_path_win = trim($home_path_win);
     $cli_param_data['BASE_PATH'] = $home_path_win;
     $cli_param_data['HOME_PATH'] = $home_path_win;
     $cli_param_data['SAVE_PATH'] = $home_path_win;
     $cli_param_data['OUTPUT_PATH'] = $home_path_win;
Пример #7
0
function exec_ogp_module()
{
    $home_id = $_REQUEST['home_id'];
    if (empty($home_id)) {
        print_failure(get_lang('home_id_missing'));
        return;
    }
    global $db, $view;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if ($isAdmin) {
        $home_cfg = $db->getGameHome($home_id);
    } else {
        $home_cfg = $db->getUserGameHome($_SESSION['user_id'], $home_id);
    }
    if ($home_cfg === FALSE) {
        print_failure(get_lang('no_access_to_home'));
        return;
    }
    litefm_check($home_id);
    $remote = new OGPRemoteLibrary($home_cfg['agent_ip'], $home_cfg['agent_port'], $home_cfg['encryption_key']);
    $os_string = $remote->what_os();
    $os = preg_match("/Linux/i", $os_string) ? "linux" : "windows";
    echo "<h2>";
    echo empty($home_cfg['home_name']) ? get_lang('not_available') : $home_cfg['home_name'];
    echo "</h2>";
    // We must always add the home directory to the fm_cwd so that user
    // can not go out of the homedir.
    $path = clean_path($home_cfg['home_path'] . "/" . @$_SESSION['fm_cwd_' . $home_id]);
    $upload_folder_path = "modules/litefm/uploads/home_id_{$home_id}";
    if (isset($_GET['pid']) and $_GET['pid'] != "") {
        $bytes = $_GET['bytes'];
        $totalsize = $bytes / 1024;
        $uploaded_filename = $_GET['uploaded_filename'];
        $dest_file_path = clean_path($upload_folder_path . "/" . $uploaded_filename . ".txt");
        $kbytes = $remote->rsync_progress(clean_path($path . "/" . $uploaded_filename));
        list($totalsize, $mbytes, $pct) = explode(";", do_progress($kbytes, $totalsize));
        $totalmbytes = round($totalsize / 1024, 2);
        $pct = $pct > 100 ? 100 : $pct;
        if ($pct > 0) {
            echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" >
					<h4>' . get_lang('upload') . " " . $uploaded_filename . " {$mbytes}MB/{$totalmbytes}MB</h4>\n\t\t\t\t  <div style='background-color:#dce9f2;' >\n\t\t\t\t  ";
            $bar = '';
            for ($i = 1; $i <= $pct; $i++) {
                $bar .= '<img style="width:0.92%;vertical-align:middle;" src="images/progressBar.png">';
            }
            echo "<center>{$bar} <b style='vertical-align:top;display:inline;font-size:1.2em;color:red;' >{$pct}%</b></center>\n\t\t\t\t\t</div>\n\t\t\t\t  </div>";
        }
        $pid = $_GET['pid'];
        if ($remote->is_file_download_in_progress($pid) == 0) {
            unlink($dest_file_path);
            $directory = dir($upload_folder_path);
            $directory_not_empty = FALSE;
            while (FALSE !== ($item = $directory->read()) && !isset($directory_not_empty)) {
                if ($item != '.' && $item != '..') {
                    $directory_not_empty = TRUE;
                }
            }
            $directory->close();
            if (!$directory_not_empty) {
                rmdir($upload_folder_path);
            }
            print_success(print_lang('upload_complete'));
            $db->logger(get_lang('upload_complete') . " ( " . clean_path($path . "/" . $uploaded_filename) . " )");
            $view->refresh('?m=litefm&amp;home_id=' . $home_id, 2);
            return;
        } else {
            print_success(print_lang('upload_in_progress'));
            $view->refresh('?m=litefm&amp;home_id=' . $home_id . "&uploaded_filename={$uploaded_filename}&bytes={$bytes}&pid={$pid}&upload=true", 2);
            return;
        }
    } else {
        echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=" . $home_cfg['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
        $POST_MAX_SIZE = ini_get('post_max_size');
        $mul = substr($POST_MAX_SIZE, -1);
        $mul = $mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1));
        if (isset($_GET['upload']) && $_GET['upload'] == "true" && $_SERVER['CONTENT_LENGTH'] > $mul * (int) $POST_MAX_SIZE && $POST_MAX_SIZE) {
            print_failure(get_lang_f('upload_failed', '( php.ini: upload_max_filesize = ' . ini_get('upload_max_filesize') . ", post_max_size = " . ini_get('post_max_size') . ", memory_limit = " . ini_get('memory_limit') . ' )'));
        }
        if (isset($_POST['upload'])) {
            if (isset($_FILES['uploaded_file'])) {
                $bytes = $_FILES['uploaded_file']['size'];
                $bad_chars = preg_replace("/([[:alnum:]_\\.-]*)/", "", $_FILES['uploaded_file']['name']);
                $bad_arr = str_split($bad_chars);
                $uploaded_filename = str_replace($bad_arr, "", $_FILES['uploaded_file']['name']);
                $dest_file_path = clean_path($upload_folder_path . "/" . $uploaded_filename . ".txt");
                $s = isset($_SERVER['HTTPS']) ? "s" : "";
                $p = isset($_SERVER['SERVER_PORT']) & $_SERVER['SERVER_PORT'] != "80" ? ":" . $_SERVER['SERVER_PORT'] : NULL;
                $url = 'http' . $s . '://' . $_SERVER['SERVER_NAME'] . $p . $_SERVER['SCRIPT_NAME'];
                $file_url = str_replace("home.php", $dest_file_path, $url);
                if ($_FILES['uploaded_file']['error'] > 0) {
                    print_failure(get_lang_f('upload_failed'), $_FILES['uploaded_file']['error']);
                } else {
                    if (!file_exists($upload_folder_path)) {
                        if (!mkdir($upload_folder_path, 0777, true)) {
                            print_failure(get_lang_f('can_not_create_upload_folder_path'), $upload_folder_path);
                        }
                    }
                    if (file_exists($dest_file_path)) {
                        unlink($dest_file_path);
                    }
                    move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], $dest_file_path);
                    if (file_exists($dest_file_path)) {
                        $remote_file_path = clean_path($path . "/" . $uploaded_filename);
                        if ($remote->rfile_exists($remote_file_path)) {
                            $remote->exec('rm -f ' . $remote_file_path);
                        }
                        $uncompress = isset($_POST['uncompress']) ? "uncompress" : "";
                        $pid = $remote->start_file_download($file_url, $path, $uploaded_filename, $uncompress);
                        if ($remote->is_file_download_in_progress($pid) < 0) {
                            print_failure(get_lang_f('upload_failed', get_lang_f('url_is_not_accesible_from_agent', $file_url)));
                        } else {
                            $view->refresh('?m=litefm&amp;home_id=' . $home_id . "&uploaded_filename={$uploaded_filename}&bytes={$bytes}&pid={$pid}&upload=true", 1);
                        }
                    }
                }
            }
        }
        if (isset($_POST['create_folder'])) {
            $bad_chars = preg_replace("/([[:alnum:]_\\.-]*)/", "", $_POST['folder_name']);
            $bad_arr = str_split($bad_chars);
            $folder_name = str_replace($bad_arr, "", $_POST['folder_name']);
            $remote->exec('mkdir ' . clean_path($path . "/" . $folder_name));
            $db->logger(get_lang('create_folder') . " " . clean_path($path . "/" . $folder_name));
        }
        if (isset($_POST['delete'])) {
            if (!isset($_POST['delete_check'])) {
                echo "<table class='center' style='width:100%;' ><tr>\n" . "<td>" . get_lang_f('delete_item', clean_path($path . "/" . $_POST['delete'])) . "</td>" . "</tr><tr><td>" . '<form action="?m=litefm&home_id=' . $home_id . '" method="post" enctype="multipart/form-data">' . "\n" . '<input type="hidden" name="delete" value="' . $_POST['delete'] . '">' . "\n" . '<button name="delete_check" value="yes" >' . get_lang('yes') . "</button>\n" . '<button name="delete_check" value="no" >' . get_lang('no') . "</button>\n" . "</form>\n" . "</td>\n" . "</tr>\n" . "</table>\n";
            } elseif ($_POST['delete_check'] == "yes") {
                $remote->exec('rm -Rf "' . clean_path($path . "/" . $_POST['delete']) . '"');
                $db->logger('rm -Rf "' . clean_path($path . "/" . $_POST['delete']) . '"');
            }
        }
        // Chattr Check
        if (isset($_POST['secureButton'])) {
            if (!isset($_POST['secure_check'])) {
                echo "<table class='center' style='width:100%;' ><tr>\n" . "<td>" . get_lang_f('secure_item', clean_path($path . "/" . $_POST['secureFile'])) . "</td>" . "</tr><tr><td>" . '<form action="?m=litefm&home_id=' . $home_id . '" method="post" >' . "\n" . '<input type="hidden" name="secureFile" value="' . $_POST['secureFile'] . '">' . "\n" . '<input type="hidden" name="secureButton" value="' . $_POST['secureButton'] . '">' . "\n" . '<button name="secure_check" value="yes" >' . get_lang('yes') . "</button>\n" . '<button name="secure_check" value="no" >' . get_lang('no') . "</button>\n" . "</form>\n" . "</td>\n" . "</tr>\n" . "</table>\n";
            } elseif ($_POST['secure_check'] == "yes") {
                $chatAction = $_POST['secureButton'];
                if ($chatAction == get_lang('chattr_yes')) {
                    $action = 'chattr+i';
                } else {
                    $action = 'chattr-i';
                }
                $pathToFile = clean_path($path . "/" . $_POST['secureFile']);
                $remote->secure_path($action, $pathToFile);
                if ($action == 'chattr+i') {
                    $db->logger(get_lang('chattr_locked') . ": {$pathToFile}");
                } else {
                    $db->logger(get_lang('chattr_unlocked') . ": {$pathToFile}");
                }
            }
        }
        echo "<table class='center' style='width:100%;' ><tr>\n" . "<td colspan='3' ><h3>" . get_lang_f('currently_viewing', $path) . "</h3></td>" . "</tr><tr><td style='border:1px solid gray;'>" . get_lang('upload_file') . ':<form action="?m=litefm&home_id=' . $home_id . '&upload=true" method="post" enctype="multipart/form-data">' . "\n" . '<input type="file" name="uploaded_file" id="file">' . "\n" . '<input type="checkbox" name="uncompress" value="true"> ' . get_lang('uncompress') . "\n" . '<input type="submit" name="upload" value="' . get_lang('upload') . '">' . "\n" . "</form>\n" . "</td>\n" . "<td>\n" . "&nbsp;&nbsp;&nbsp;&nbsp;" . "</td>\n" . "<td style='border:1px solid gray;' >\n" . get_lang('create_folder') . ':<form action="?m=litefm&home_id=' . $home_id . '&create_folder=true" method="post" >' . "\n" . '<input type="text" name="folder_name" />' . "\n" . '<input type="submit" name="create_folder" value="' . get_lang('create') . '"/>' . "\n" . "</form>\n" . "</td></tr>\n" . "</table>\n";
        if (!$remote->rfile_exists($path)) {
            $path = clean_path($home_cfg['home_path']);
            if (!$remote->rfile_exists($path)) {
                print_failure(get_lang_f("dir_not_found", $path));
            } else {
                $_SESSION['fm_cwd_' . $home_id] = str_replace("\\", "", dirname($_SESSION['fm_cwd_' . $home_id]));
                echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=?m=litefm&amp;home_id=' . $home_id . '">';
            }
        } else {
            $dirlist = $remote->remote_dirlistfm($path);
            if ($os == "linux") {
                $lsattr = $remote->exec('lsattr ' . $path);
            }
            if (!is_array($dirlist)) {
                if ($dirlist === -1) {
                    if ($path != $home_cfg['home_path'] . "/") {
                        echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=?m=litefm&amp;home_id=' . $home_id . '">';
                    } else {
                        print_failure('Your game server\'s home path is too long or there is a file with a very long name inside of your game server\'s home folder.');
                    }
                } else {
                    if ($remote->rfile_exists($path)) {
                        if (strpos($path, '/') !== FALSE) {
                            $ePath = explode('/', $path);
                            $filename = end($ePath);
                        } else {
                            if (strpos($path, '\\') !== FALSE) {
                                $ePath = explode('\\', $path);
                                $filename = end($ePath);
                            }
                        }
                        $_SESSION['fm_cwd_' . $home_id] = str_replace("\\", "", dirname($_SESSION['fm_cwd_' . $home_id]));
                        echo '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=?m=litefm&amp;home_id=' . $home_id . '&amp;path=' . $filename . '&amp;p=read_file">';
                    } else {
                        print_failure(get_lang("failed_list"));
                    }
                }
                return;
            }
            if (empty($dirlist)) {
                print_lang('empty_directory');
                echo "<table class='center' style='width:100%;' >\n" . show_back($home_id) . "</table>";
            } else {
                echo "<table class='center' style='width:100%;' >\n" . show_back($home_id) . "<tr><td style='width:10px;' ></td><td align=left>\n" . get_lang('filename') . "</td>";
                if ($os == "linux") {
                    echo "<td>" . get_lang('filesecure') . "</td>";
                }
                echo "<td>" . get_lang('filesize') . " [" . get_lang('bytes') . "]</td><td>" . get_lang('owner') . " " . get_lang('group') . "</td></tr>\n";
                $directorys = array();
                $files = array();
                $binarys = array();
                foreach ($dirlist as $item) {
                    # dirlist FM returns an array.  Each element has 5 fields separated by the | character
                    list($filename, $size, $user, $group, $type) = explode("|", $item);
                    $filepath = str_replace("/", "\\/", clean_path($path . "/" . $filename));
                    if ($os == "linux") {
                        preg_match('/(\\S+)\\s' . $filepath . '/', $lsattr, $file_attributes);
                    }
                    // Directory
                    if ($type == 'D') {
                        $directorys[$filename]['filename'] = $filename;
                        $directorys[$filename]['user'] = $user;
                        $directorys[$filename]['group'] = $group;
                    } elseif ($type == 'F') {
                        $files[$filename]['filename'] = $filename;
                        $files[$filename]['size'] = $size;
                        $files[$filename]['user'] = $user;
                        $files[$filename]['group'] = $group;
                        if ($os == "linux") {
                            $files[$filename]['attr'] = $file_attributes[1];
                        }
                    } elseif ($type == 'B') {
                        $binarys[$filename]['filename'] = $filename;
                        $binarys[$filename]['size'] = $size;
                        $binarys[$filename]['user'] = $user;
                        $binarys[$filename]['group'] = $group;
                        if ($os == "linux") {
                            $binarys[$filename]['attr'] = $file_attributes[1];
                        }
                    }
                }
                foreach ($directorys as $directory) {
                    echo "<tr>\n" . "<td>" . '<form method=POST>' . "<input type=hidden name='delete' value='" . $directory['filename'] . "' class='item' />\n" . '<input type="image" style="width:12px;padding-left:5px;" src="modules/administration/images/remove.gif" />' . "</form>\n" . "</td>" . "<td align=left>" . "<img class=\"viewitem\" src=\"images/folder.png\" alt=\"Directory\" /> " . "<a href=\"?m=litefm&amp;home_id={$home_id}&amp;path=" . $directory['filename'] . "\">" . $directory['filename'] . "</a></td>";
                    if ($os == "linux") {
                        echo "<td>-</td>";
                    }
                    echo "<td>-</td> <td>" . $directory['user'] . " " . $directory['group'] . "</td>\n" . "</tr>\n";
                }
                foreach ($files as $file) {
                    if ($os == "linux") {
                        if ($isAdmin) {
                            $secureFile = '<td><form method=POST>';
                            $secureFile .= "<input type=hidden name='secureFile' value='" . $file['filename'] . "' class='item' />\n";
                            if (preg_match("/i/", $file['attr'])) {
                                $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_no') . "' class='item' />\n";
                            } else {
                                $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_yes') . "' class='item' />\n";
                            }
                            $secureFile .= '</form></td>';
                        } else {
                            $secureFile = "<td><span class=";
                            if (preg_match("/i/", $file['attr'])) {
                                $secureFile .= "'chattrLock'>" . get_lang('chattr_locked');
                            } else {
                                $secureFile .= "'chattrUnlock'>" . get_lang('chattr_unlocked');
                            }
                            $secureFile .= "</span></td>\n";
                        }
                    } else {
                        $secureFile = "";
                    }
                    echo "<tr>\n" . "<td>" . '<form method=POST>' . "<input type=hidden name='delete' value='" . $file['filename'] . "' class='item' />\n" . '<input type="image" style="width:12px;padding-left:5px;" src="modules/administration/images/remove.gif" />' . "</form>\n" . "</td>" . "<td align=left>";
                    echo "<img class=\"viewitem\" src=\"images/txt.png\" alt=\"Text file\" /> " . "<a href=\"?m=litefm&amp;home_id={$home_id}&amp;path=" . $file['filename'] . "&amp;p=read_file\">" . get_lang("button_edit") . "</a>" . $file['filename'] . "</td>\n\t\t\t\t\t\t {$secureFile}<td>" . $file['size'] . "</td> <td>" . $file['user'] . " " . $file['group'] . "</td>\n";
                    echo "</tr>\n";
                }
                foreach ($binarys as $binary) {
                    if ($os == "linux") {
                        if ($isAdmin) {
                            $secureFile = '<td><form method=POST>';
                            $secureFile .= "<input type=hidden name='secureFile' value='" . $binary['filename'] . "' class='item' />\n";
                            if (preg_match("/i/", $binary['attr'])) {
                                $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_no') . "' class='item' />\n";
                            } else {
                                $secureFile .= "<input type='submit' class='chattrButton' name='secureButton' value='" . get_lang('chattr_yes') . "' class='item' />\n";
                            }
                            $secureFile .= '</form></td>';
                        } else {
                            $secureFile = "<td><span class=";
                            if (preg_match("/i/", $binary['attr'])) {
                                $secureFile .= "'chattrLock'>" . get_lang('chattr_locked');
                            } else {
                                $secureFile .= "'chattrUnlock'>" . get_lang('chattr_unlocked');
                            }
                            $secureFile .= "</span></td>\n";
                        }
                    } else {
                        $secureFile = "";
                    }
                    echo "<tr>\n" . "<td>" . '<form method=POST>' . "<input type=hidden name='delete' value='" . $binary['filename'] . "' class='item' />\n" . '<input type="image" style="width:12px;padding-left:5px;" src="modules/administration/images/remove.gif" />' . "</form>\n" . "</td>" . "<td align=left>";
                    echo "<img class=\"viewitem\" src=\"images/exec.png\" alt=\"Binary file\" /> " . $binary['filename'] . "</td>\n\t\t\t\t\t\t {$secureFile}<td>" . $binary['size'] . "</td><td>" . $binary['user'] . " " . $binary['group'] . "</td>\n";
                    echo "</tr>\n";
                }
                echo "</table>\n";
            }
        }
    }
    echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=" . $home_cfg['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
}
Пример #8
0
 * 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.
 *
 */
include_once "modules/status/config.php";
global $db;
$cygwin = FALSE;
if (isset($_GET['remote_server_id']) and $_GET['remote_server_id'] != "webhost") {
    $rhost_id = $_GET['remote_server_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']);
    $os_string = $remote->what_os();
    if (preg_match("/Linux/", $os_string)) {
        $os = "linux";
        $goodforuptime = "1";
        if (preg_match("/64/", $os_string)) {
            $osbuild = "64bit";
        } else {
            $osbuild = "32bit";
        }
    } elseif (preg_match("/CYGWIN/", $os_string)) {
        $os = "linux";
        $cygwin = TRUE;
        if (preg_match("/64/", $os_string)) {
            $osbuild = "64bit";
        } else {
            $osbuild = "32bit";