Пример #1
0
 function getStat()
 {
     $_statPath = '/proc/stat';
     if (isset($_GET['remote_server_id']) and $_GET['remote_server_id'] != "" and $_GET['remote_server_id'] != "webhost") {
         require_once 'includes/lib_remote.php';
         global $db;
         $rhost_id = $_GET['remote_server_id'];
         $remote_server = $db->getRemoteServer($rhost_id);
         $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
         $stat = $remote->exec('cat ' . $_statPath);
     } else {
         ob_start();
         passthru('cat ' . $_statPath);
         $stat = ob_get_contents();
         ob_end_clean();
     }
     $lb = explode("\n", $stat);
     $first = 1;
     $cores = array();
     foreach ($lb as $line) {
         if ($first == 0) {
             if (preg_match('/^cpu[0-9]/', $line)) {
                 $info = explode(' ', $line);
                 $cores[] = array('user' => $info[1], 'nice' => $info[2], 'sys' => $info[3], 'idle' => $info[4], 'total' => $info[1] + $info[2] + $info[3] + $info[4]);
             }
         } else {
             $first = 0;
         }
     }
     return $cores;
 }
Пример #2
0
function exec_ogp_module()
{
    global $db;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    require_once 'includes/lib_remote.php';
    if (isset($_GET['home_id']) and $_GET['home_id'] != "total") {
        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;
        }
        $remote = new OGPRemoteLibrary($game_home['agent_ip'], $game_home['agent_port'], $game_home['encryption_key']);
        $r = $remote->rfile_exists($game_home['home_path']);
        if ($r == 1) {
            $du = $remote->exec("du -sb " . $game_home['home_path']);
            list($size, $path) = explode("\t", $du);
            if (isset($_GET['bytes'])) {
                echo $size;
            } else {
                echo numbersFormatting($size);
            }
        } else {
            echo get_lang("does_not_exist_yet");
        }
    } elseif ($isAdmin) {
        $game_homes = $db->getGameHomes();
        $total_size = 0;
        foreach ($game_homes as $game_home) {
            $remote = new OGPRemoteLibrary($game_home['agent_ip'], $game_home['agent_port'], $game_home['encryption_key']);
            $r = $remote->rfile_exists($game_home['home_path']);
            if ($r == 1) {
                $du = $remote->exec("du -sb " . $game_home['home_path']);
                list($kilobytes, $path) = explode("\t", $du);
                $kilobytes = intval(preg_replace('/\\D/', '', $kilobytes));
                $total_size += $kilobytes;
            }
        }
        echo numbersFormatting($total_size);
    }
}
Пример #3
0
function exec_ogp_module()
{
    $modDb = new MySQLModuleDatabase();
    require "includes/config.inc.php";
    $modDb->connect($db_host, $db_user, $db_pass, $db_name, $table_prefix);
    global $db;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if ($isAdmin) {
        $game_home = $db->getGameHome($_REQUEST['home_id']);
    } else {
        $game_home = $db->getUserGameHome($_SESSION['user_id'], $_GET['home_id']);
    }
    if (!$game_home and !$isAdmin) {
        return;
    }
    $home_dbs = $modDb->getMysqlDBsbyHomeId($game_home['home_id']);
    if (empty($home_dbs)) {
        return;
    }
    $db_id = $_REQUEST['db_id'];
    $mysql_db = $modDb->getMysqlHomeDBbyId($game_home['home_id'], $db_id);
    if (!$mysql_db) {
        return;
    }
    $command = 'mysqldump --host=' . $mysql_db['mysql_ip'] . ' --port=' . $mysql_db['mysql_port'] . ' --user='******'db_user'] . ' --password='******'db_passwd'] . ' ' . $mysql_db['db_name'];
    if ($mysql_db['remote_server_id'] != "0") {
        $remote_server = $db->getRemoteServer($mysql_db['remote_server_id']);
        $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
        $host_stat = $remote->status_chk();
        if ($host_stat === 1) {
            $dump = $remote->exec($command, $output);
        }
    } else {
        $dump = system($command);
    }
    header("Content-Type: text/plain");
    header('Content-Disposition: attachment; filename="backup-' . $mysql_db['db_name'] . '-' . date("d-m-Y") . '.sql"');
    echo $dump;
}
function exec_ogp_module()
{
    global $db;
    global $view;
    $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : "";
    $mod_id = isset($_REQUEST['mod_id']) ? $_REQUEST['mod_id'] : "";
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if ($isAdmin) {
        $home_info = $db->getGameHome($home_id);
    } else {
        $home_info = $db->getUserGameHome($_SESSION['user_id'], $home_id);
    }
    if ($home_info === FALSE || preg_match("/u/", $home_info['access_rights']) != 1) {
        print_failure(get_lang('no_rights'));
        echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
        return;
    }
    $game_type = $home_info['game_key'];
    echo "<h2>Updating game server <em>" . $home_info['home_name'] . "</em></h2>";
    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
    if ($server_xml->installer != "steamcmd") {
        print_failure(get_lang('xml_steam_error'));
        return;
    }
    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
    $host_stat = $remote->status_chk();
    if ($remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_id) == 1) {
        print_failure(get_lang('server_running_cant_update'));
        return;
    }
    $log_txt = '';
    $update_active = $remote->get_log(OGP_SCREEN_TYPE_UPDATE, $home_id, clean_path($home_info['home_path']), $log_txt);
    $modkey = $home_info['mods'][$mod_id]['mod_key'];
    $mod_xml = xml_get_mod($server_xml, $modkey);
    if (!$mod_xml) {
        print_failure(get_lang_f('mod_key_not_found_from_xml', $modkey));
        return;
    }
    if ($update_active === 0) {
        print_failure(get_lang('agent_offline'));
        echo "<meta http-equiv='refresh' content='5'>";
        return;
    } else {
        if ($_REQUEST['update'] == 'update' && $update_active != 1) {
            $installer_name = $modkey;
            if (isset($mod_xml->installer_name)) {
                $installer_name = $mod_xml->installer_name;
            }
            $mod_cfg_id = $home_info['mod_cfg_id'];
            $game_mod_precmd = $db->resultQuery("SELECT DISTINCT precmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'");
            if ($game_mod_precmd[0]['precmd'] === NULL or empty($game_mod_precmd[0]['precmd'])) {
                $config_mod_precmd = $db->resultQuery("SELECT DISTINCT def_precmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'");
                if ($config_mod_precmd[0]['def_precmd'] === NULL or empty($config_mod_precmd[0]['def_precmd'])) {
                    $precmd = "";
                } else {
                    $precmd = $config_mod_precmd[0]['def_precmd'];
                }
            } else {
                $precmd = $game_mod_precmd[0]['precmd'];
            }
            $game_mod_postcmd = $db->resultQuery("SELECT DISTINCT postcmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'");
            if ($game_mod_postcmd[0]['postcmd'] === NULL or empty($game_mod_postcmd[0]['postcmd'])) {
                $config_mod_postcmd = $db->resultQuery("SELECT DISTINCT def_postcmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'");
                if ($config_mod_postcmd[0]['def_postcmd'] === NULL or empty($config_mod_postcmd[0]['def_postcmd'])) {
                    $postcmd = "";
                } else {
                    $postcmd = $config_mod_postcmd[0]['def_postcmd'];
                }
            } else {
                $postcmd = $game_mod_postcmd[0]['postcmd'];
            }
            $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location);
            $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name);
            if (isset($_REQUEST['master_server_home_id'])) {
                $ms_home_id = $_REQUEST['master_server_home_id'];
                $ms_info = $db->getGameHome($ms_home_id);
                $steam_out = $remote->masterServerUpdate($home_id, $home_info['home_path'], $ms_home_id, $ms_info['home_path'], $exec_folder_path, $exec_path, $precmd, $postcmd);
            } else {
                if (preg_match("/win32/", $server_xml->game_key) or preg_match("/win64/", $server_xml->game_key)) {
                    $cfg_os = "windows";
                } elseif (preg_match("/linux/", $server_xml->game_key)) {
                    $cfg_os = "linux";
                }
                $settings = $db->getSettings();
                // Some games like L4D2 require anonymous login
                if ($mod_xml->installer_login) {
                    $login = $mod_xml->installer_login;
                    $pass = '';
                } else {
                    $login = $settings['steam_user'];
                    $pass = $settings['steam_pass'];
                }
                $modname = ($installer_name == '90' and !preg_match("/(cstrike|valve)/", $modkey)) ? $modkey : '';
                $betaname = isset($mod_xml->betaname) ? $mod_xml->betaname : '';
                $betapwd = isset($mod_xml->betapwd) ? $mod_xml->betapwd : '';
                $steam_out = $remote->steam_cmd($home_id, $home_info['home_path'], $installer_name, $modname, $betaname, $betapwd, $login, $pass, $settings['steam_guard'], $exec_folder_path, $exec_path, $precmd, $postcmd, $cfg_os);
            }
            if ($steam_out === 0) {
                print_failure(get_lang('failed_to_start_steam_update'));
                return;
            } else {
                if ($steam_out === 1) {
                    print_success(get_lang('update_started'));
                } else {
                    if ($host_stat === 0) {
                        print_failure(get_lang('agent_offline'));
                        $view->refresh("?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}", 5);
                        return;
                    }
                    echo "Installing Steam... wait.";
                    $steamcmdtrue = isset($_REQUEST['steamcmd']) ? "&amp;steamcmd=true" : "";
                    $view->refresh("?m=gamemanager&amp;p=update&amp;update=update&amp;home_id={$home_id}&amp;mod_id={$mod_id}{$steamcmdtrue}", 5);
                    return;
                }
            }
        } else {
            if (isset($_POST['stop_update_x'])) {
                $stop_update = sprintf("screen -S OGP_UPDATE_%09d -X quit", $home_id);
                $remote->exec("{$stop_update}");
            }
            $update_complete = false;
            if ($update_active == 1) {
                echo "<p class='note'>" . get_lang('update_in_progress') . "</p>\n";
                echo "<form method=POST><input type='image' name='stop_update' onsubmit='submit-form();' src='modules/administration/images/remove.gif'>" . get_lang('stop_update') . "</input></form>";
            } else {
                echo "<meta http-equiv='refresh' content='60'>";
                print_success(get_lang('update_completed'));
                echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
                $update_complete = true;
            }
            if (empty($log_txt)) {
                $log_txt = get_lang('not_available');
            }
            echo "<pre>" . $log_txt . "</pre>\n";
            if ($update_complete) {
                return;
            }
        }
    }
    echo "<p><a href=\"?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}\">";
    echo get_lang('refresh_steam_status') . "</a></p>";
    $view->refresh("?m=gamemanager&amp;p=update&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}", 5);
    return;
}
    }
    $replace_id++;
}
foreach ($replacements as $key => $replacement) {
    $filepath = $replacement['filepath'];
    $file_replacements[$filepath][$key] = $replacement;
}
/* echo "<xmp>";
print_r($file_replacements);
echo "</xmp>"; */
require_once 'includes/lib_remote.php';
$remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key']);
foreach ($file_replacements as $filepath => $replacements) {
    $file_info = $remote->remote_readfile($server_home['home_path'] . "/{$filepath}", $file_content);
    if ($file_info === 0) {
        $remote->exec("touch " . $server_home['home_path'] . "/{$filepath}");
        $file_info = "";
    }
    foreach ($replacements as $replacement) {
        $info_param = $replacement['info_param'];
        $default = $replacement['default'];
        $var = $replacement['var'];
        $options = $replacement['options'];
        $param_enc = mb_detect_encoding($info_param);
        $file_enc = mb_detect_encoding($file_content);
        if ($param_enc != $file_enc) {
            $file_content = mb_convert_encoding($file_content, $param_enc, $file_enc);
        }
        if (!in_array($options, array("tags", "tagValueByName", "sc", "sqc"))) {
            $match_found = preg_match("/{$default}/m", $file_content);
            if ($var == "") {
Пример #6
0
    foreach ($ossq as $osq) {
        $total = $osq->TotalVisibleMemorySize * 1024;
        $free = $osq->FreePhysicalMemory * 1024;
    }
    $belegtq = $total - $free;
    $percentage_used = 100 * $belegtq / $total;
    $ramusage = numbersFormatting($belegtq) . " of " . numbersFormatting($total);
    $rampercent = round($percentage_used, "2");
} elseif ($os == "linux" or $os == "cygwin") {
    if (isset($_GET['remote_server_id'])) {
        require_once 'includes/lib_remote.php';
        global $db;
        $rhost_id = $_GET['remote_server_id'];
        $remote_server = $db->getRemoteServer($rhost_id);
        $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
        $mem = $remote->exec('cat /proc/meminfo');
    } else {
        $mem = file_get_contents("/proc/meminfo");
    }
    if (preg_match('/MemTotal\\:\\s+(\\d+) kB/', $mem, $matches)) {
        $total = $matches[1];
    }
    if (preg_match('/Buffers\\:\\s+(\\d+) kB/', $mem, $matches)) {
        $buffers = $matches[1];
    }
    if (preg_match('/Cached\\:\\s+(\\d+) kB/', $mem, $matches)) {
        $cached = $matches[1];
    }
    unset($matches);
    if (preg_match('/MemFree\\:\\s+(\\d+) kB/', $mem, $matches)) {
        $free = $matches[1];
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);
                        }
                    }
                }
            }
        }
    }
}
Пример #8
0
function exec_ogp_module()
{
    $modDb = new MySQLModuleDatabase();
    require "includes/config.inc.php";
    $modDb->connect($db_host, $db_user, $db_pass, $db_name, $table_prefix);
    global $view, $db;
    echo "<h2>" . get_lang('add_new_mysql_host') . "</h2>";
    if (isset($_GET['add_mysql_server'])) {
        foreach ($_GET as $name => $value) {
            $get[$name] = trim($value);
        }
        if (empty($get['mysql_ip'])) {
            print_failure(get_lang('enter_mysql_ip'));
        }
        if (!isPortValid($get['mysql_port'])) {
            print_failure(get_lang('enter_valid_port'));
        }
        if (empty($get['mysql_root_passwd'])) {
            print_failure(get_lang('enter_mysql_root_password'));
        }
        if (empty($get['mysql_name'])) {
            print_failure(get_lang('enter_mysql_name'));
        }
        if ($get['privilegies'] == "custom") {
            $priv = $get;
            $privilegies_str = "";
            unset($priv['m'], $priv['p'], $priv['remote_server_id'], $priv['mysql_ip'], $priv['mysql_port'], $priv['mysql_root_passwd'], $priv['mysql_name'], $priv['privilegies'], $priv['add_mysql_server']);
            foreach ($priv as $name => $value) {
                $privilegies_str .= str_replace("_", " ", $name) . ", ";
            }
        } else {
            $privilegies_str = "ALL";
        }
        $privilegies_str = rtrim($privilegies_str, ', ');
        $mysql_server_id = $modDb->addMysqlServer($get['remote_server_id'], $get['mysql_name'], $get['mysql_ip'], $get['mysql_port'], $get['mysql_root_passwd'], $privilegies_str);
        if (!$mysql_server_id) {
            print_failure(get_lang('could_not_add_mysql_server'));
            $view->refresh("?m=mysql&p=mysql_admin");
            return;
        }
        print_success(get_lang('server_added'));
        $view->refresh("?m=mysql&p=mysql_admin");
        return;
    }
    echo "<p>" . get_lang('note_mysql_host') . "</p>";
    $servers = $db->getRemoteServers();
    $conn_method[0] = get_lang('direct_connection');
    foreach ($servers as $server_row) {
        $id = $server_row['remote_server_id'];
        $name = get_lang_f('connection_through_remote_server_named', $server_row['remote_server_name']);
        $conn_method[$id] = $name;
    }
    require_once "includes/form_table_class.php";
    $ft = new FormTable();
    $ft->start_form("", "GET");
    $ft->start_table();
    $ft->add_field_hidden('m', 'mysql');
    $ft->add_field_hidden('p', 'mysql_admin');
    $ft->add_custom_field('connection_method', create_drop_box_from_array($conn_method, "remote_server_id", "0", false));
    $ft->add_field('string', 'mysql_name', isset($_GET['mysql_name']) ? $_GET['mysql_name'] : "");
    $ft->add_field('string', 'mysql_ip', isset($_GET['mysql_ip']) ? $_GET['mysql_ip'] : "localhost");
    $ft->add_field('string', 'mysql_port', isset($_GET['mysql_port']) ? $_GET['mysql_port'] : "3306");
    $ft->add_field('string', 'mysql_root_passwd', isset($_GET['mysql_root_passwd']) ? $_GET['mysql_root_passwd'] : "");
    $ft->add_custom_field('privilegies', create_drop_box_from_array(array('all' => get_lang('all'), 'custom' => get_lang('custom')), "privilegies", isset($_GET['privilegies']) ? $_GET['privilegies'] : "all", false));
    if (isset($_GET['privilegies']) and $_GET['privilegies'] == "custom") {
        $ft->add_custom_field('alter', '<input type="checkbox" name="ALTER" checked="checked" >');
        $ft->add_custom_field('create', '<input type="checkbox" name="CREATE" checked="checked" >');
        $ft->add_custom_field('create_temporary_tables', '<input type="checkbox" name="CREATE TEMPORARY TABLES" checked="checked" >');
        $ft->add_custom_field('delete', '<input type="checkbox" name="DELETE" checked="checked" >');
        $ft->add_custom_field('drop', '<input type="checkbox" name="DROP" checked="checked" >');
        $ft->add_custom_field('index', '<input type="checkbox" name="INDEX" checked="checked" >');
        $ft->add_custom_field('insert', '<input type="checkbox" name="INSERT" checked="checked" >');
        $ft->add_custom_field('lock_tables', '<input type="checkbox" name="LOCK TABLES" checked="checked" >');
        $ft->add_custom_field('select', '<input type="checkbox" name="SELECT" checked="checked" >');
        $ft->add_custom_field('update', '<input type="checkbox" name="UPDATE" checked="checked" >');
        $ft->add_custom_field('grant_option', '<input type="checkbox" name="GRANT OPTION" checked="checked" >');
    }
    $ft->end_table();
    $ft->add_button("submit", "add_mysql_server", get_lang('add_mysql_server'));
    $ft->end_form();
    $mysql_servers = $modDb->getMysqlServers();
    if ($mysql_servers === FALSE) {
        return;
    }
    $tr = 0;
    ?>
<table id="servermonitor" class="tablesorter remote">
		<thead> 
		<tr> 
			<th colspan="4" ><?php 
    print_lang('configured_mysql_hosts');
    ?>
</th> 
		</tr> 
		</thead> 
		<tbody> <?php 
    foreach ($mysql_servers as $mysql_server) {
        if ($mysql_server['remote_server_id'] != 0) {
            $remote_server = $db->getRemoteServer($mysql_server['remote_server_id']);
            $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
            $host_stat = $remote->status_chk();
            if ($host_stat === 0) {
                $server_status = "<span class='failure'>" . get_lang('offline') . "</span> ";
            } elseif ($host_stat === 1) {
                $server_status = "<span class='success'>" . get_lang('online') . "</span>";
                $command = "mysql -h " . $mysql_server['mysql_ip'] . " -P " . $mysql_server['mysql_port'] . " -u root -p" . $mysql_server['mysql_root_passwd'] . ' -e exit; echo $?';
                $test_mysql_conn = $remote->exec($command);
                if ($test_mysql_conn == 0) {
                    $server_status .= " / <span class='success'>" . get_lang('mysql_online') . "</span>";
                } else {
                    $server_status .= "/<span class='failure'>" . get_lang('mysql_offline') . "</span>";
                }
            } elseif ($host_stat === -1) {
                $server_status = "<span class='failure'>" . get_lang('encryption_key_mismatch') . "</span>\n";
            } else {
                $server_status = "<span class='failure'>" . get_lang('unknown_error') . ": {$host_stat}</span>\n";
            }
        } else {
            @($link = mysql_connect($mysql_server['mysql_ip'] . ':' . $mysql_server['mysql_port'], 'root', $mysql_server['mysql_root_passwd']));
            if ($link === FALSE) {
                $server_status = "<span class='failure'>" . get_lang('mysql_offline') . "</span>";
            } else {
                $server_status = "<span class='success'>" . get_lang('mysql_online') . "</span>";
                mysql_close($link);
            }
        }
        $databases = "";
        $mysql_server_dbs = $modDb->getMysqlServerDBs($mysql_server['mysql_server_id']);
        if (!empty($mysql_server_dbs)) {
            foreach ($mysql_server_dbs as $mysql_db) {
                $databases .= $mysql_db['db_name'] . "<a href='?m=mysql&p=edit&mysql_server_id=" . $mysql_server['mysql_server_id'] . "&assign=true&db_id=" . $mysql_db['db_id'] . "&edit_db_settings'>[" . get_lang('edit') . "]</a>\n" . "<a href='?m=mysql&p=edit&mysql_server_id=" . $mysql_server['mysql_server_id'] . "&assign=true&db_id=" . $mysql_db['db_id'] . "&remove_db'>[" . get_lang('remove') . "]</a>\n" . "<br>";
            }
        }
        $conection_type = $mysql_server['remote_server_id'] == 0 ? get_lang('direct_connection') : get_lang_f('connection_through_remote_server_named', $remote_server['remote_server_name']);
        $buttons = "<a href='?m=mysql&amp;p=edit&amp;mysql_server_id=" . $mysql_server['mysql_server_id'] . "&amp;delete'>[" . get_lang('remove') . "]</a>\n" . "<a href='?m=mysql&amp;p=edit&amp;mysql_server_id=" . $mysql_server['mysql_server_id'] . "&amp;edit'>[" . get_lang('edit') . "]</a>\n" . "<a href='?m=mysql&amp;p=edit&amp;mysql_server_id=" . $mysql_server['mysql_server_id'] . "&amp;assign'>[" . get_lang('assign_db') . "]</a>\n";
        $tittle = "<b>ID#:</b>  <b style='color:red;'>" . $mysql_server['mysql_server_id'] . "</b></td>\n\t\t\t\t\t<td class='collapsible' ><b>" . get_lang('mysql_server_name') . ":</b> " . $mysql_server['mysql_name'] . "</td>\n\t\t\t\t\t<td class='collapsible' ><b>" . get_lang('server_status') . ":</b>{$server_status}</td>";
        $data = "<tr class='expand-child' >\n\t\t\t\t   <td>\n\t\t\t\t\t<b>" . get_lang('mysql_ip_port') . ":</b> " . $mysql_server['mysql_ip'] . ":" . $mysql_server['mysql_port'] . "<br />\n\t\t\t\t\t<b>" . get_lang('mysql_root_passwd') . ":</b> " . $mysql_server['mysql_root_passwd'] . "<br />\n\t\t\t\t\t<b>" . get_lang('connection_method') . ":</b> " . $conection_type . "<br />\n\t\t\t\t\t<b>" . get_lang('user_privilegies') . ":</b> " . $mysql_server['privilegies_str'] . "<br />\n\t\t\t\t   </td>\n\t\t\t\t   <td>\n\t\t\t\t    <b>" . get_lang('current_dbs') . ":</b><br />" . $databases . "</td>\n\t\t\t\t   <td>\n\t\t\t\t    {$buttons}\n\t\t\t\t   </td>\n\t\t\t\t </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">
$(document).ready(function(){ 
	$("#servermonitor")
		.collapsible("td.collapsible", {collapse: true})
		.tablesorter({sortList: [[0,0], [1,0]] , widgets: ['zebra','repeatHeaders']});
});
</script>
<?php 
    unset($modDb);
}
Пример #9
0
function exec_ogp_module()
{
    $modDb = new MySQLModuleDatabase();
    require "includes/config.inc.php";
    $modDb->connect($db_host, $db_user, $db_pass, $db_name, $table_prefix);
    global $view, $db;
    $mysql_server_id = @$_REQUEST['mysql_server_id'];
    $mysql_server = $modDb->getMysqlServer($mysql_server_id);
    if ($mysql_server['remote_server_id'] == "0") {
        $server_homes = $db->getGameHomes();
    } else {
        $server_homes = $modDb->getGameHomesByRemoteServerId($mysql_server['remote_server_id']);
    }
    $homes_array[0] = get_lang('select_game_server');
    foreach ($server_homes as $server_home) {
        $homes_array["{$server_home['home_id']}"] = "(ID " . $server_home['home_id'] . ") " . $server_home['home_name'];
    }
    if ($mysql_server === FALSE) {
        print_failure(get_lang_f('invalid_mysql_server_id', $mysql_server_id));
        $view->refresh("?m=mysql&p=mysql_admin");
        return;
    }
    if (isset($_REQUEST['add_db'])) {
        $home_id = $_POST['home_id'];
        $db_user = trim($_POST['db_user']);
        $db_passwd = trim($_POST['db_passwd']);
        $db_name = trim($_POST['db_name']);
        $enabled = $_POST['enabled'];
        if (empty($db_user)) {
            print_failure(get_lang('enter_db_user'));
        } elseif (empty($db_passwd)) {
            print_failure(get_lang('enter_db_password'));
        } elseif (empty($db_name)) {
            print_failure(get_lang('enter_db_name'));
        } elseif ($home_id == 0) {
            print_failure(get_lang('select_game_server'));
        } else {
            $db_id = $modDb->addMysqlServerDB($mysql_server_id, $home_id, $db_user, $db_passwd, $db_name, $enabled);
            if (!$db_id) {
                print_failure(get_lang_f('there_is_another_db_named_or_user_named', $db_name, $db_user));
            } else {
                $mysql_db = $modDb->getMysqlDBbyId($db_id);
                if (!$mysql_db) {
                    return;
                }
                if ($mysql_db['remote_server_id'] != "0") {
                    $remote_server = $db->getRemoteServer($mysql_db['remote_server_id']);
                    $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
                    $host_stat = $remote->status_chk();
                    if ($host_stat === 1) {
                        $command = "mysql -h localhost -P " . $mysql_db['mysql_port'] . " -u root -p" . $mysql_db['mysql_root_passwd'] . ' -e exit; echo $?';
                        $test_mysql_conn = $remote->exec($command);
                        if ($test_mysql_conn == 0) {
                            $SQL = "CREATE DATABASE IF NOT EXISTS \\`" . $mysql_db['db_name'] . "\\`;" . "GRANT " . $mysql_db['privilegies_str'] . " ON \\`" . $mysql_db['db_name'] . "\\`.* TO '" . $mysql_db['db_user'] . "'@'localhost' IDENTIFIED BY '" . $mysql_db['db_passwd'] . "';" . "FLUSH PRIVILEGES;";
                            $command = "mysql --host=localhost --port=" . $mysql_db['mysql_port'] . " -uroot -p" . $mysql_db['mysql_root_passwd'] . " -e \"" . $SQL . "\"";
                            $result = $remote->exec($command);
                        }
                    }
                } else {
                    @($link = mysql_connect($mysql_db['mysql_ip'] . ':' . $mysql_db['mysql_port'], $mysql_db['db_user'], $mysql_db['db_passwd']));
                    if ($link === FALSE) {
                        @($link = mysql_connect($mysql_db['mysql_ip'] . ':' . $mysql_db['mysql_port'], 'root', $mysql_db['mysql_root_passwd']));
                        if ($link !== FALSE) {
                            $queries = array("CREATE DATABASE IF NOT EXISTS `" . $mysql_db['db_name'] . "`;", "GRANT " . $mysql_db['privilegies_str'] . " ON `" . $mysql_db['db_name'] . "`.* TO '" . $mysql_db['db_user'] . "'@'" . $mysql_db['mysql_ip'] . "' IDENTIFIED BY '" . $mysql_db['db_passwd'] . "';", "FLUSH PRIVILEGES;");
                            foreach ($queries as $query) {
                                @($return = mysql_query($query));
                                if (!$return) {
                                    break;
                                }
                            }
                            mysql_close($link);
                        }
                    }
                }
                print_success(get_lang_f('db_added_for_home_id', $_POST['home_id']));
            }
        }
        $view->refresh("?m=mysql&p=mysql_admin&amp;p=edit&amp;mysql_server_id=" . $mysql_server_id . "&amp;assign", 5);
    } else {
        if (isset($_REQUEST['remove_db'])) {
            $db_id = $_REQUEST['db_id'];
            $mysql_db = $modDb->getMysqlDBbyId($db_id);
            if ($mysql_db['remote_server_id'] != "0") {
                $remote_server = $db->getRemoteServer($mysql_db['remote_server_id']);
                $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
                $host_stat = $remote->status_chk();
                if ($host_stat === 1) {
                    $remote->exec('mysql --host=localhost --port=' . $mysql_db['mysql_port'] . ' -uroot -p' . $mysql_db['mysql_root_passwd'] . ' -e "DROP DATABASE ' . $mysql_db['db_name'] . ";DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_db['mysql_ip'] . "';\"");
                }
            } else {
                @($link = mysql_connect($mysql_db['mysql_ip'] . ':' . $mysql_db['mysql_port'], 'root', $mysql_db['mysql_root_passwd']));
                if ($link !== FALSE) {
                    $queries = array("DROP DATABASE " . $mysql_db['db_name'] . ";", "DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_db['mysql_ip'] . "';");
                    foreach ($queries as $query) {
                        @($return = mysql_query($query));
                        if (!$return) {
                            break;
                        }
                    }
                    mysql_close($link);
                    $modDb->connect($db_host, $db_user, $db_pass, $db_name, $table_prefix);
                }
            }
            if ($modDb->removeMysqlServerDB($db_id) === FALSE) {
                print_failure(get_lang('could_not_remove_db'));
            } else {
                print_success(get_lang_f('db_removed_successfully_from_mysql_server_named', $mysql_db['mysql_name']));
            }
            $view->refresh("?m=mysql&p=mysql_admin&amp;p=edit&amp;mysql_server_id=" . $mysql_server_id . "&amp;assign");
        } else {
            if (isset($_POST['save_db_changes'])) {
                $db_id = $_POST['db_id'];
                $home_id = $_POST['home_id'];
                $post_db_user = trim($_POST['db_user']);
                $post_db_passwd = trim($_POST['db_passwd']);
                $post_db_name = trim($_POST['db_name']);
                $enabled = $_POST['enabled'];
                if (empty($post_db_passwd)) {
                    print_failure(get_lang('enter_db_password'));
                } elseif ($home_id == 0) {
                    print_failure(get_lang('select_game_server'));
                } else {
                    $mysql_db = $modDb->getMysqlDBbyId($db_id);
                    if ($post_db_passwd != $mysql_db['db_passwd']) {
                        if ($mysql_db['remote_server_id'] != "0") {
                            $remote_server = $db->getRemoteServer($mysql_db['remote_server_id']);
                            $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
                            $host_stat = $remote->status_chk();
                            if ($host_stat === 1) {
                                $SQL = "DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_server['mysql_ip'] . "';" . "GRANT " . $mysql_db['privilegies_str'] . " ON \\`" . $mysql_db['db_name'] . "\\`.* TO '" . $mysql_db['db_user'] . "'@'localhost' IDENTIFIED BY '" . $post_db_passwd . "';" . "FLUSH PRIVILEGES;";
                                $command = "mysql --host=localhost --port=" . $mysql_db['mysql_port'] . " -uroot -p" . $mysql_db['mysql_root_passwd'] . " -e \"" . $SQL . "\"";
                                $remote->exec($command);
                            }
                        } else {
                            @($link = mysql_connect($mysql_db['mysql_ip'] . ':' . $mysql_db['mysql_port'], 'root', $mysql_db['mysql_root_passwd']));
                            if ($link !== FALSE) {
                                $queries = array("DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_server['mysql_ip'] . "';", "GRANT " . $mysql_db['privilegies_str'] . " ON `" . $mysql_db['db_name'] . "`.* TO '" . $mysql_db['db_user'] . "'@'" . $mysql_db['mysql_ip'] . "' IDENTIFIED BY '" . $post_db_passwd . "';", "FLUSH PRIVILEGES;");
                                foreach ($queries as $query) {
                                    @($return = mysql_query($query));
                                    if (!$return) {
                                        break;
                                    }
                                }
                                mysql_close($link);
                                $modDb->connect($db_host, $db_user, $db_pass, $db_name, $table_prefix);
                            }
                        }
                    }
                    if ($enabled != $mysql_db['enabled']) {
                        if ($mysql_db['remote_server_id'] != "0") {
                            $remote_server = $db->getRemoteServer($mysql_db['remote_server_id']);
                            $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
                            $host_stat = $remote->status_chk();
                            if ($host_stat === 1) {
                                if ($enabled == "0") {
                                    $SQL = "DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_server['mysql_ip'] . "';" . "FLUSH PRIVILEGES;";
                                } else {
                                    $SQL = "GRANT " . $mysql_db['privilegies_str'] . " ON \\`" . $mysql_db['db_name'] . "\\`.* TO '" . $mysql_db['db_user'] . "'@'localhost' IDENTIFIED BY '" . $post_db_passwd . "';" . "FLUSH PRIVILEGES;";
                                }
                                $command = "mysql --host=localhost --port=" . $mysql_db['mysql_port'] . " -uroot -p" . $mysql_db['mysql_root_passwd'] . " -e \"" . $SQL . "\"";
                                $remote->exec($command);
                            }
                        } else {
                            @($link = mysql_connect($mysql_db['mysql_ip'] . ':' . $mysql_db['mysql_port'], 'root', $mysql_db['mysql_root_passwd']));
                            if ($link !== FALSE) {
                                if ($enabled == "0") {
                                    $queries = array("DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_server['mysql_ip'] . "';", "FLUSH PRIVILEGES;");
                                } else {
                                    $queries = array("GRANT " . $mysql_db['privilegies_str'] . " ON `" . $mysql_db['db_name'] . "`.* TO '" . $mysql_db['db_user'] . "'@'" . $mysql_db['mysql_ip'] . "' IDENTIFIED BY '" . $post_db_passwd . "';", "FLUSH PRIVILEGES;");
                                }
                                foreach ($queries as $query) {
                                    @($return = mysql_query($query));
                                    if (!$return) {
                                        break;
                                    }
                                }
                                mysql_close($link);
                                $modDb->connect($db_host, $db_user, $db_pass, $db_name, $table_prefix);
                            }
                        }
                    }
                    if ($modDb->editMysqlServerDB($db_id, $home_id, $post_db_user, $post_db_passwd, $post_db_name, $enabled) === FALSE) {
                        print_failure(get_lang('could_not_be_changed'));
                    } else {
                        print_success(get_lang_f('db_changed_successfully', $post_db_name));
                    }
                }
                $view->refresh("?m=mysql&p=mysql_admin&amp;p=edit&amp;mysql_server_id=" . $mysql_server_id . "&amp;assign");
            } else {
                if (isset($_REQUEST['delete'])) {
                    if (!isset($_REQUEST['y'])) {
                        echo "<p>" . get_lang_f('areyousure_remove_mysql_server', $mysql_server['mysql_name']) . "</p>\n                <p><a href='?m=mysql&p=mysql_admin&amp;p=edit&amp;mysql_server_id=" . $mysql_server_id . "&amp;delete&amp;y=y'>" . get_lang('yes') . "</a> <a href='?m=mysql&p=mysql_admin'>" . get_lang('no') . "</a></p>";
                        return;
                    } else {
                        $mysql_dbs = $modDb->getMysqlServerDBs($mysql_server_id);
                        if (!empty($mysql_dbs)) {
                            foreach ($mysql_dbs as $mysql_db) {
                                if ($mysql_server['remote_server_id'] != "0") {
                                    $remote_server = $db->getRemoteServer($mysql_server['remote_server_id']);
                                    $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
                                    $host_stat = $remote->status_chk();
                                    if ($host_stat === 1) {
                                        $remote->exec('mysql --host=localhost --port=' . $mysql_server['mysql_port'] . ' -uroot -p' . $mysql_server['mysql_root_passwd'] . ' -e "DROP DATABASE ' . $mysql_db['db_name'] . ";DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_server['mysql_ip'] . "';\"");
                                    }
                                } else {
                                    @($link = mysql_connect($mysql_server['mysql_ip'] . ':' . $mysql_server['mysql_port'], 'root', $mysql_server['mysql_root_passwd']));
                                    if ($link !== FALSE) {
                                        $queries = array("DROP DATABASE " . $mysql_db['db_name'] . ";", "DROP USER '" . $mysql_db['db_user'] . "'@'" . $mysql_server['mysql_ip'] . "';");
                                        foreach ($queries as $query) {
                                            @($return = mysql_query($query));
                                            if (!$return) {
                                                break;
                                            }
                                        }
                                        mysql_close($link);
                                    }
                                }
                            }
                        }
                        if ($modDb->removeMysqlServer($mysql_server_id) === FALSE) {
                            print_failure(get_lang('error_while_remove'));
                        } else {
                            print_success(get_lang_f('mysql_server_removed', $mysql_server['mysql_name']));
                        }
                    }
                    $view->refresh("?m=mysql&p=mysql_admin");
                    return;
                } else {
                    if (isset($_POST['save_settings'])) {
                        foreach ($_POST as $name => $value) {
                            $get[$name] = trim($value);
                        }
                        if (empty($get['mysql_ip'])) {
                            print_failure(get_lang('enter_mysql_ip'));
                        } elseif (!isPortValid($get['mysql_port'])) {
                            print_failure(get_lang('enter_valid_port'));
                        } elseif (empty($get['mysql_root_passwd'])) {
                            print_failure(get_lang('enter_mysql_root_password'));
                        } elseif (empty($get['mysql_name'])) {
                            print_failure(get_lang('enter_mysql_name'));
                        } elseif (!$modDb->editMysqlServer($mysql_server_id, $get['remote_server_id'], $get['mysql_name'], $get['mysql_ip'], $get['mysql_port'], $get['mysql_root_passwd'], $mysql_server['privilegies_str'])) {
                            print_failure(get_lang_f('unable_to_set_changes_to', $mysql_server['mysql_name']));
                        } else {
                            print_success(get_lang_f('mysql_server_settings_changed', $mysql_server['mysql_name']));
                        }
                        $view->refresh("?m=mysql&p=mysql_admin&amp;p=edit&amp;mysql_server_id=" . $mysql_server_id . "&amp;edit", 5);
                    } elseif (isset($_GET['edit'])) {
                        echo "<h2>" . get_lang_f('editing_mysql_server', $mysql_server['mysql_name']) . "</h2>";
                        $mysql_server = $modDb->getMysqlServer($mysql_server_id);
                        $servers = $db->getRemoteServers();
                        $conn_method[0] = get_lang('direct_connection');
                        foreach ($servers as $server_row) {
                            $id = $server_row['remote_server_id'];
                            $name = get_lang_f('connection_through_remote_server_named', $server_row['remote_server_name']);
                            $conn_method[$id] = $name;
                        }
                        $ft = new FormTable();
                        $ft->start_form('?m=mysql&amp;p=edit&amp;mysql_server_id=' . $mysql_server_id . '&amp;edit');
                        $ft->start_table();
                        $ft->add_custom_field('connection_method', create_drop_box_from_array($conn_method, "remote_server_id", $mysql_server['remote_server_id'], false));
                        $ft->add_field('string', 'mysql_name', $mysql_server['mysql_name']);
                        $ft->add_field('string', 'mysql_ip', $mysql_server['mysql_ip']);
                        $ft->add_field('string', 'mysql_port', $mysql_server['mysql_port']);
                        $ft->add_field('string', 'mysql_root_passwd', $mysql_server['mysql_root_passwd']);
                        $ft->end_table();
                        $ft->add_button("submit", "save_settings", get_lang('save_settings'));
                        $ft->end_form();
                        echo create_back_button('mysql', 'mysql_admin');
                    } elseif (isset($_GET['assign'])) {
                        echo "<h2>" . get_lang_f('mysql_dbs_for', $mysql_server['mysql_name']) . "</h2>";
                        $mysql_server_dbs = $modDb->getMysqlServerDBs($mysql_server['mysql_server_id']);
                        if (!empty($mysql_server_dbs)) {
                            echo "<h4>" . get_lang('edit_dbs') . "</h4>";
                            foreach ($mysql_server_dbs as $mysql_db) {
                                $home_info = $db->getGameHomeWithoutMods($mysql_db['home_id']);
                                $db_array["{$mysql_db['db_id']}"] = $mysql_db['db_name'] . " (" . $home_info['home_name'] . ")";
                            }
                            $ft = new FormTable();
                            $ft->start_form('', 'GET');
                            $ft->add_field_hidden('m', 'mysql');
                            $ft->add_field_hidden('p', 'edit');
                            $ft->add_field_hidden('mysql_server_id', $mysql_server_id);
                            $ft->add_field_hidden('assign', 'true');
                            $ft->start_table();
                            $ft->add_custom_field('select_db', create_drop_box_from_array($db_array, "db_id", isset($_GET['db_id']) ? $_GET['db_id'] : "", false));
                            $ft->end_table();
                            $ft->add_button('submit', 'edit_db_settings', get_lang('edit_db_settings'));
                            $ft->add_button('submit', 'remove_db', get_lang('remove_db'));
                            $ft->end_form();
                            if (isset($_GET['edit_db_settings'])) {
                                $mysql_db = $modDb->getMysqlDBbyId($_GET['db_id']);
                                $ft = new FormTable();
                                $ft->start_form('');
                                $ft->add_field_hidden('db_id', $mysql_db['db_id']);
                                $ft->start_table();
                                $ft->add_custom_field('game_server', create_drop_box_from_array($homes_array, "home_id", $mysql_db['home_id'], false));
                                $ft->add_field('string', 'db_user', $mysql_db['db_user'], "50", "readonly");
                                $ft->add_field('string', 'db_passwd', $mysql_db['db_passwd']);
                                $ft->add_field('string', 'db_name', $mysql_db['db_name'], "50", "readonly");
                                $ft->add_field('on_off', 'enabled', $mysql_db['enabled']);
                                $ft->end_table();
                                $ft->add_button('submit', 'save_db_changes', get_lang('save_db_changes'));
                                $ft->end_form();
                            }
                        }
                        echo "<h4>" . get_lang('add_db') . "</h4>";
                        $ft = new FormTable();
                        $ft->start_form('');
                        $ft->start_table();
                        $ft->add_custom_field('game_server', create_drop_box_from_array($homes_array, "home_id", "0", false));
                        $ft->add_field('string', 'db_user', '');
                        $ft->add_field('string', 'db_passwd', genRandomString('10'));
                        $ft->add_field('string', 'db_name', '');
                        $ft->add_field('on_off', 'enabled', '1');
                        $ft->end_table();
                        $ft->add_button('submit', 'add_db', get_lang('add_db'));
                        $ft->end_form();
                        echo create_back_button('mysql', 'mysql_admin');
                    } else {
                        print_failure("Invalid url.");
                        $view->refresh("?m=mysql&p=mysql_admin");
                    }
                }
            }
        }
    }
}
Пример #10
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
if (isset($_GET['remote_server_id']) and $os != "nocpu") {
    require_once 'includes/lib_remote.php';
    global $db;
    $rhost_id = $_GET['remote_server_id'];
    $remote_server = $db->getRemoteServer($rhost_id);
    $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
    if ($cygwin) {
        $disk_info = $remote->exec('df -lP|grep "^.:\\s"|awk \'{size+=$2}{used+=$3}{avail+=$4} END {print size, used, avail}\'');
    } else {
        $disk_info = $remote->exec('df -lP|grep "^/dev/.*"|awk \'{size+=$2}{used+=$3}{avail+=$4} END {print size, used, avail}\'');
    }
    list($insgesamtKB, $belegtKB, $freiKB) = explode(" ", $disk_info);
    $frei = 1024 * $freiKB;
    $belegt = 1024 * $belegtKB;
    $insgesamt = 1024 * $insgesamtKB;
} else {
    if ($os == "windows") {
        $insgesamt = disk_total_space("./");
        $frei = disk_free_space("./");
        $belegt = $insgesamt - $frei;
    } else {
        if ($cygwin) {
            $disk_info = shell_exec('df -lP|grep "^.:\\s"|awk \'{size+=$2}{used+=$3}{avail+=$4} END {print size, used, avail}\'');
function exec_ogp_module()
{
    //update_local_copies(); #Disabled until the rsync_sites.list file from master servers is corrected.
    global $db, $view, $settings;
    if (isset($_REQUEST['url'])) {
        $url = $_REQUEST['url'];
    } else {
        $url = "";
    }
    $home_id = isset($_REQUEST['home_id']) ? $_REQUEST['home_id'] : "";
    $mod_id = isset($_REQUEST['mod_id']) ? $_REQUEST['mod_id'] : "";
    $state = isset($_POST['state']) ? $_POST['state'] : "";
    $update = isset($_GET['update']) ? $_GET['update'] : "";
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    if ($isAdmin) {
        $home_info = $db->getGameHome($home_id);
    } else {
        $home_info = $db->getUserGameHome($_SESSION['user_id'], $home_id);
    }
    if ($home_info === FALSE || preg_match("/u/", $home_info['access_rights']) != 1) {
        print_failure(get_lang('no_rights'));
        echo create_back_button("gamemanager", "game_monitor");
        return;
    }
    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
    if (isset($server_xml->lgsl_query_name)) {
        $lgslname = $server_xml->lgsl_query_name;
        if ($lgslname == "quake3") {
            if ($server_xml->game_name == "Quake 3") {
                $lgslname = "q3";
            }
        }
    } elseif (isset($server_xml->gameq_query_name)) {
        $lgslname = $server_xml->gameq_query_name;
        if ($lgslname == "minecraft") {
            if ($server_xml->game_name == "Minecraft Tekkit") {
                $lgslname = "tekkit";
            } elseif ($server_xml->game_name == "Minecraft Bukkit") {
                $lgslname = "bukkit";
            }
        }
    } elseif (isset($server_xml->protocol)) {
        $lgslname = $server_xml->protocol;
    } else {
        $lgslname = $server_xml->mods->mod['key'];
    }
    if (preg_match("/win32/", $server_xml->game_key) or preg_match("/win64/", $server_xml->game_key)) {
        $os = "windows";
    } elseif (preg_match("/linux/", $server_xml->game_key)) {
        $os = "linux";
    }
    $full_url = $url . "/ogp_game_installer/{$lgslname}/{$os}/";
    echo "<h2>Update {$home_info['home_name']}</h2>";
    if ($remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_id) == 1) {
        print_failure(get_lang('server_running_cant_update'));
        return;
    }
    $update_active = $remote->get_log(OGP_SCREEN_TYPE_UPDATE, $home_id, clean_path($home_info['home_path']), $log_txt, 30);
    if ($update_active === 0) {
        print_failure(get_lang('agent_offline'));
        echo "<meta http-equiv='refresh' content='5'>";
        return;
    } elseif ($state == 'start' && $update_active != 1) {
        $mod_cfg_id = $home_info['mod_cfg_id'];
        $game_mod_precmd = $db->resultQuery("SELECT DISTINCT precmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'");
        if ($game_mod_precmd[0]['precmd'] === NULL or empty($game_mod_precmd[0]['precmd'])) {
            $config_mod_precmd = $db->resultQuery("SELECT DISTINCT def_precmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'");
            if ($config_mod_precmd[0]['def_precmd'] === NULL or empty($config_mod_precmd[0]['def_precmd'])) {
                $precmd = "";
            } else {
                $precmd = $config_mod_precmd[0]['def_precmd'];
            }
        } else {
            $precmd = $game_mod_precmd[0]['precmd'];
        }
        $game_mod_postcmd = $db->resultQuery("SELECT DISTINCT postcmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='{$mod_id}'");
        if ($game_mod_postcmd[0]['postcmd'] === NULL or empty($game_mod_postcmd[0]['postcmd'])) {
            $config_mod_postcmd = $db->resultQuery("SELECT DISTINCT def_postcmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='{$mod_cfg_id}'");
            if ($config_mod_postcmd[0]['def_postcmd'] === NULL or empty($config_mod_postcmd[0]['def_postcmd'])) {
                $postcmd = "";
            } else {
                $postcmd = $config_mod_postcmd[0]['def_postcmd'];
            }
        } else {
            $postcmd = $game_mod_postcmd[0]['postcmd'];
        }
        $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location);
        $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name);
        if (isset($_REQUEST['master_server_home_id'])) {
            $ms_home_id = $_REQUEST['master_server_home_id'];
            $ms_info = $db->getGameHome($ms_home_id);
            print_success(get_lang_f("starting_copy_with_master_server_named", $ms_info['home_name']));
            $rsync = $remote->masterServerUpdate($home_id, $home_info['home_path'], $ms_home_id, $ms_info['home_path'], $exec_folder_path, $exec_path, $precmd, $postcmd);
            $master = "&amp;master=true";
        } else {
            print_success(get_lang_f("starting_sync_with", $full_url));
            $rsync = $remote->start_rsync_install($home_id, $home_info['home_path'], "{$full_url}", $exec_folder_path, $exec_path, $precmd, $postcmd);
            $master = "";
        }
        if ($rsync === 0) {
            print_failure(get_lang('failed_to_start_rsync_update'));
            return;
        } else {
            if ($rsync === 1) {
                print_success(get_lang('update_started'));
                echo "<p><a href=\"?m=gamemanager&amp;p=rsync_install&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}{$master}\">";
                echo get_lang('refresh_rsync_status') . "</a></p>";
                $view->refresh("?m=gamemanager&amp;p=rsync_install&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}{$master}", 5);
                return;
            } elseif ($rsync === 0) {
                print_failure(get_lang('agent_offline'));
                return;
            }
        }
    } elseif ($update_active == 1) {
        echo "<p class='note'></p>\n";
        if (isset($_POST['stop_update_x'])) {
            $stop_update = sprintf("screen -S OGP_UPDATE_%09d -X quit", $home_id);
            $remote->exec("{$stop_update}");
        }
        $update_complete = false;
        echo "<form method=POST><input type='image' name='stop_update' onsubmit='submit-form();' src='modules/administration/images/remove.gif'>" . get_lang('stop_update') . "</input></form>";
        if (empty($log_txt)) {
            $log_txt = get_lang('not_available');
        }
        if (!isset($_GET['master'])) {
            $kbytes = $remote->rsync_progress($home_info['home_path']);
            list($totalsize, $mbytes, $pct) = explode(";", do_progress($kbytes, $lgslname . "/" . $os));
            $totalmbytes = round($totalsize / 1024, 2);
            echo '<div class="dragbox bloc rounded" style="background-color:#dce9f2;" >
					<h4>' . get_lang('update_in_progress') . " {$mbytes}MB/{$totalmbytes}MB</h4>\n\t\t\t\t  <div style='background-color:#dce9f2;' >\n\t\t\t\t  ";
            $bar = '';
            for ($i = 1; $i <= $pct; $i++) {
                $bar .= '<img style="width:0.92%;vertical-align:middle;" src="images/progressBar.png">';
            }
            echo "{$bar} <b style='vertical-align:top;display:inline;font-size:1.2em;color:red;' >{$pct}%</b>\n\t\t\t\t\t</div>\n\t\t\t\t  </div><br>";
        } else {
            echo '<h4>' . get_lang('update_in_progress') . '</h4>';
        }
        echo "<pre>" . $log_txt . "</pre>\n";
        echo "<p><a href=\"?m=gamemanager&amp;p=rsync_install&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}\">";
        echo get_lang('refresh_rsync_status') . "</a></p>";
        $view->refresh("?m=gamemanager&amp;p=rsync_install&amp;update=refresh&amp;home_id={$home_id}&amp;mod_id={$mod_id}", 5);
        return;
    } elseif ($update != "update") {
        echo "<meta http-equiv='refresh' content='60'>";
        print_success(get_lang('update_completed'));
        echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
        echo "<pre>" . $log_txt . "</pre>\n";
        echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=" . $home_info['home_id'] . "'><< " . get_lang('back') . "</a></td></tr></table>";
        $update_complete = true;
    } else {
        $rsync_remote_sites = file("modules/gamemanager/rsync_sites.list");
        #load offical rsync sites
        $rsync_local_sites = file("modules/gamemanager/rsync_sites_local.list");
        #load user custom sites
        $settings['rsync_available'] = isset($settings['rsync_available']) ? $settings['rsync_available'] : "1";
        if (is_array($rsync_local_sites) and $settings['rsync_available'] == "1") {
            $rsync_sites = array_merge($rsync_remote_sites, $rsync_local_sites);
            #merge arrays
        } elseif ($settings['rsync_available'] == "2") {
            $rsync_sites = $rsync_remote_sites;
        } elseif ($settings['rsync_available'] == "3") {
            $rsync_sites = $rsync_local_sites;
        }
        #echo "LGSL or GameQ query name is $server_xml->lgsl_query_name$server_xml->gameq_query_name";
        $sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES);
        if (!is_array($sync_list)) {
            if (!is_file("modules/gamemanager/rsync.list")) {
                print_failure("Trouble accessing http://www.opengamepanel.org/rsync.list");
                print_failure("Make sure allow_fopen_url is set to \"On\" in your php.ini and opengamepanel.org is online");
                print_failure("In the mean time, you can get a local copy of the file by running wget http://www.opengamepanel.org/sync_data/rsync.list -O /path/to/ogpweb/modules/gamemanager/rsync.list");
                return;
            }
            # print_failure("Error loading rsync.list");
            # return;
            $sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES);
            if (!is_array($sync_list)) {
                print_failure("Failed to open local copy of rsync.list in modules/gamemanager/rsync.list");
                return;
            }
        }
        $master_server_home_id = $db->getMasterServer($home_info['remote_server_id'], $home_info['home_cfg_id']);
        if (in_array($lgslname, $sync_list)) {
            echo "Game type supported<br>\n\t\t\t\t <p class='center'>To add your own rsync site, create modules/gamemanager/rsync_sites_local.list and put a server name on each line.</p><br>\n\t\t\t\t <form action='?m=gamemanager&amp;p=rsync_install' method='post'>\n\t\t\t\t <table class='center'>\n\t\t\t\t <input type='hidden' name='home_id' value='{$home_id}' />\n\t\t\t\t <input type='hidden' name='mod_id' value='{$mod_id}' />\n\t\t\t\t <input type='hidden' name='lgslname' value='{$lgslname}' />\n\t\t\t\t <input type='hidden' name='state' value='start' />\n\t\t\t\t <tr><td align='right'>Game name:</td><td align='left'>{$home_info['game_name']}</td></tr>\n\t\t\t\t <tr><td align='right'>Directory:</td><td align='left'>{$home_info['home_path']}</td></tr>\n\t\t\t\t <tr><td align='right'>Remoteserver:</td>\n\t\t\t\t <td align='left'>{$home_info['remote_server_name']} ({$home_info['agent_ip']}:{$home_info['agent_port']})</td></tr>\n\t\t\t\t <tr><td align='right'>Rsync Server:</td>\n\t\t\t\t <td align='left'>" . create_drop_box_from_array_rsync($rsync_sites, "url") . "<br>";
            if ($master_server_home_id != FALSE and $master_server_home_id != $home_id) {
                echo "<input type='checkbox' name='master_server_home_id' value='{$master_server_home_id}' /><b>" . get_lang('update_from_local_master_server') . "</b>";
            }
            echo "</td></tr></table><p><input type='submit' name='update' value='update' /></p>\n\t\t\t\t </form>";
        } elseif ($master_server_home_id != FALSE and $master_server_home_id != $home_id) {
            $ms_home_info = $db->getGameHome($master_server_home_id);
            echo "<br>\n\t\t\t\t <p class='success'>Master server update available</p><br>\n\t\t\t\t <form action='?m=gamemanager&amp;p=rsync_install' method='post'>\n\t\t\t\t <table class='center'>\n\t\t\t\t <input type='hidden' name='home_id' value='{$home_id}' />\n\t\t\t\t <input type='hidden' name='mod_id' value='{$mod_id}' />\n\t\t\t\t <input type='hidden' name='lgslname' value='{$lgslname}' />\n\t\t\t\t <input type='hidden' name='state' value='start' />\n\t\t\t\t <tr><td align='right'>Game name:</td><td align='left'>{$home_info['game_name']}</td></tr>\n\t\t\t\t <tr><td align='right'>Master Server Name:</td><td align='left'>{$ms_home_info['home_name']}</td></tr>\n\t\t\t\t <tr><td align='right'>Master Server Directory:</td><td align='left'>{$ms_home_info['home_path']}</td></tr>\n\t\t\t\t <tr><td align='right'>Local Directory:</td><td align='left'>{$home_info['home_path']}</td></tr>" . "<input type='hidden' name='master_server_home_id' value='{$master_server_home_id}' />" . "</td></tr></table><p><input type='submit' name='update' value='" . get_lang('update_from_local_master_server') . "' /></p>\n\t\t\t\t </form>";
        } else {
            print_failure("This game type [ {$lgslname} ] is not yet supported with rsync install");
        }
    }
}
Пример #12
0
 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;
     $cli_param_data['USER_PATH'] = $home_path_win;
 }
 // We do this check because sometimes server does not answer to lgsl check
 // done below and is still running.
 if ($remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_id) === 1) {
     echo "<p>" . get_lang_f('server_already_running') . "<a href=?m=gamemanager&amp;p=stop&amp;home_id=" . $home_id . "&amp;ip=" . $ip . "&amp;port=" . $port . ">" . get_lang_f('already_running_stop_server') . "</a></p>";
     return;
 }
 if (isset($server_home['ufw_status']) and $server_home['ufw_status'] == "enable") {
Пример #13
0
        if ($mins > 0) {
            @($uptimeString .= ($days > 0 || $hours > 0 ? " " : "") . $mins);
            $uptimeString .= $mins == 1 ? " Minute" : " Minutes";
        }
        if ($secs > 0) {
            $uptimeString .= ($days > 0 || $hours > 0 || $mins > 0 ? " " : "") . $secs;
            $uptimeString .= $secs == 1 ? " Second" : " Seconds";
        }
        return $uptimeString;
    }
    if (isset($_GET['remote_server_id'])) {
        require_once 'includes/lib_remote.php';
        global $db;
        $rhost_id = $_GET['remote_server_id'];
        $remote_server = $db->getRemoteServer($rhost_id);
        $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
        $uptime = $remote->exec('cat /proc/uptime');
        $uptime = explode(" ", $uptime);
        $uptimeSecs = $uptime[0];
        $staticUptime = format_uptime($uptimeSecs);
        $indexuptime = $staticUptime;
        $indexuptimesince = $remote->exec('date -d "`cut -f1 -d. /proc/uptime` seconds ago"');
    } else {
        $uptime = exec("cat /proc/uptime");
        $uptime = explode(" ", $uptime);
        $uptimeSecs = $uptime[0];
        $staticUptime = format_uptime($uptimeSecs);
        $indexuptime = $staticUptime;
        $indexuptimesince = exec('date -d "`cut -f1 -d. /proc/uptime` seconds ago"');
    }
}
Пример #14
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>";
}
Пример #15
0
function exec_ogp_module()
{
    $modDb = new MySQLModuleDatabase();
    require "includes/config.inc.php";
    $modDb->connect($db_host, $db_user, $db_pass, $db_name, $table_prefix);
    global $view, $db;
    $isAdmin = $db->isAdmin($_SESSION['user_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;
    }
    echo "<h2>" . get_lang_f('mysql_dbs_for', $game_home['home_name']) . "</h2>";
    $home_dbs = $modDb->getMysqlDBsbyHomeId($game_home['home_id']);
    if (empty($home_dbs)) {
        print_failure(get_lang_f('there_are_no_databases_assigned_for', $game_home['home_name']));
        return;
    }
    $db_array["0"] = get_lang('select_db');
    foreach ($home_dbs as $home_db) {
        $db_array["{$home_db['db_id']}"] = $home_db['db_name'];
    }
    $ft = new FormTable();
    $ft->start_form('');
    $ft->start_table();
    $ft->add_custom_field('select_db', create_drop_box_from_array($db_array, "db_id", isset($_REQUEST['db_id']) ? $_REQUEST['db_id'] : "0", false));
    $ft->end_table();
    $ft->end_form();
    $database_exists = FALSE;
    $server_online = FALSE;
    if (isset($_REQUEST['db_id']) and $_REQUEST['db_id'] != "0") {
        $db_id = $_REQUEST['db_id'];
        $mysql_db = $modDb->getMysqlHomeDBbyId($game_home['home_id'], $db_id);
        if (!$mysql_db) {
            return;
        }
        if ($mysql_db['remote_server_id'] != "0") {
            $remote_server = $db->getRemoteServer($mysql_db['remote_server_id']);
            $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key']);
            $host_stat = $remote->status_chk();
            if ($host_stat === 1) {
                $command = "mysql -h localhost -P " . $mysql_db['mysql_port'] . " -u root -p" . $mysql_db['mysql_root_passwd'] . ' -e exit; echo $?';
                $test_mysql_conn = $remote->exec($command);
                if ($test_mysql_conn == 0) {
                    $user_db = $remote->exec('mysqlshow --user='******'db_user'] . ' --password='******'db_passwd'] . ' ' . $mysql_db['db_name']);
                    if ($user_db != "") {
                        $database_exists = TRUE;
                    }
                    $server_online = TRUE;
                }
            }
        } else {
            @($link = mysql_connect($mysql_db['mysql_ip'] . ':' . $mysql_db['mysql_port'], $mysql_db['db_user'], $mysql_db['db_passwd']));
            if ($link !== FALSE) {
                $server_online = TRUE;
                if (mysql_select_db($mysql_db['db_name'], $link) !== FALSE) {
                    $databases = mysql_query("SHOW TABLES;");
                    $user_db = "Database: " . $mysql_db['db_name'] . "\nTables:\n";
                    while ($table = mysql_fetch_array($databases)) {
                        $user_db .= $table[0] . "\n";
                    }
                    $database_exists = TRUE;
                }
            }
        }
        if (isset($_POST['restore'])) {
            $command = 'mysql --host=' . $mysql_db['mysql_ip'] . ' --port=' . $mysql_db['mysql_port'] . ' --user='******'db_user'] . ' --password='******'db_passwd'] . ' ' . $mysql_db['db_name'] . ' < ' . $_FILES["file"]["tmp_name"];
            if ($mysql_db['remote_server_id'] != "0") {
                $remote->exec($command, $output);
            } else {
                system($command);
            }
            $view->refresh('?m=mysql&p=user_db&home_id=' . $game_home['home_id'] . '&db_id=' . $db_id, 0);
        }
        if ($server_online and $database_exists) {
            echo "<table class='database' ><tr><td>\n<div class='dragbox bloc rounded' ><h4>" . get_lang('db_info') . "</h4>\n" . "<table class='database_info' ><tr>" . "<td><b>" . get_lang('mysql_ip') . " :</b></td><td>" . $mysql_db['mysql_ip'] . "</td></tr>\n" . "<td><b>" . get_lang('mysql_port') . " :</b></td><td>" . $mysql_db['mysql_port'] . "</td></tr>\n" . "<td><b>" . get_lang('db_name') . " :</b></td><td>" . $mysql_db['db_name'] . "</td></tr>\n" . "<td><b>" . get_lang('db_user') . " :</b></td><td>" . $mysql_db['db_user'] . "</td></tr>\n" . "<td><b>" . get_lang('db_passwd') . " :</b></td><td>" . $mysql_db['db_passwd'] . "</td></tr>\n" . "<td><b>" . get_lang('privilegies') . " :</b></td><td>" . $mysql_db['privilegies_str'] . "</td></tr></table></div>\n" . "<td><div class='dragbox bloc rounded' style='background:black;' ><h4>" . get_lang('db_tables') . "</h4>" . "<pre><xmp>" . $user_db . "</xmp></pre></div></td></tr></table>";
            echo "<h2>" . get_lang('db_backup') . "</h2>";
            ?>
			<table class='administration-table'>
			 <tr>
			  <td>
			  <form method="POST" action="?m=mysql&p=get_dump&home_id=<?php 
            echo $game_home['home_id'];
            ?>
&db_id=<?php 
            echo $db_id;
            ?>
&type=cleared" >
			   <button name="download"><?php 
            print_lang('download_db_backup');
            ?>
</button>
			  </form>
			  <br>
			  <form method="POST" action="?m=mysql&p=user_db&home_id=<?php 
            echo $game_home['home_id'];
            ?>
&db_id=<?php 
            echo $db_id;
            ?>
" enctype="multipart/form-data">
			   <label for="file"><?php 
            print_lang('sql_file');
            ?>
:</label>
			   <input type="file" name="file" id="file" />
			   <button name="restore"><?php 
            print_lang('restore_db_backup');
            ?>
</button>
			  </form>
			  </td>
			 </tr>
			</table>
			<?php 
        }
    }
}