Ejemplo n.º 1
0
function exec_ogp_module()
{
    require_once 'includes/form_table_class.php';
    global $db, $view;
    if (isset($_REQUEST['update_settings'])) {
        $settings = array("panel_name" => $_REQUEST['panel_name'], "header_code" => $_REQUEST['header_code'], "maintenance_mode" => $_REQUEST['maintenance_mode'], "maintenance_title" => $_REQUEST['maintenance_title'], "maintenance_message" => $_REQUEST['maintenance_message'], "panel_language" => $_REQUEST['panel_language'], "time_zone" => $_REQUEST['time_zone'], "charset" => $_REQUEST['charset'], "page_auto_refresh" => $_REQUEST['page_auto_refresh'], "smtp_server" => $_REQUEST['smtp_server'], "smtp_port" => $_REQUEST['smtp_port'], "smtp_login" => $_REQUEST['smtp_login'], "smtp_passw" => $_REQUEST['smtp_passw'], "smtp_ssl" => $_REQUEST['smtp_ssl'], "panel_email_address" => $_REQUEST['panel_email_address'], "feed_enable" => $_REQUEST['feed_enable'], "feed_url" => $_REQUEST['feed_url'], "query_cache_life" => $_REQUEST['query_cache_life'], "query_num_servers_stop" => $_REQUEST['query_num_servers_stop'], "steam_user" => $_REQUEST['steam_user'], "steam_pass" => $_REQUEST['steam_pass'], "steam_guard" => $_REQUEST['steam_guard'], "editable_email" => $_REQUEST['editable_email'], "old_dashboard_behavior" => $_REQUEST['old_dashboard_behavior'], "rsync_available" => $_REQUEST['rsync_available']);
        $db->setSettings($settings);
        echo "<h2>" . get_lang('settings') . "</h2>";
        print_success(get_lang('settings_updated'));
        $view->refresh("?m=settings");
        return;
    }
    function formatOffset($offset)
    {
        $hours = $offset / 3600;
        $remainder = $offset % 3600;
        $sign = $hours > 0 ? '+' : '-';
        $hour = (int) abs($hours);
        $minutes = (int) abs($remainder / 60);
        if ($hour == 0 and $minutes == 0) {
            $sign = ' ';
        }
        return $sign . str_pad($hour, 2, '0', STR_PAD_LEFT) . ':' . str_pad($minutes, 2, '0');
    }
    $utc = new DateTimeZone('UTC');
    $dt = new DateTime('now', $utc);
    if (!method_exists($dt, 'getTimestamp')) {
        $dt = new DateTime_52('now', $utc);
    }
    foreach (DateTimeZone::listIdentifiers() as $tz) {
        $current_tz = new DateTimeZone($tz);
        $offset = $current_tz->getOffset($dt);
        $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
        $abbr = $transition[0]['abbr'];
        $zones["{$tz}"] = $tz . '[' . $abbr . ' ' . formatOffset($offset) . ']';
    }
    $rsync_options = array("1" => get_lang('all_available_servers'), "2" => get_lang('only_remote_servers'), "3" => get_lang('only_local_servers'));
    echo "<h2>" . get_lang('settings') . "</h2>";
    $row = $db->getSettings();
    $ft = new FormTable();
    $ft->start_form("?m=settings", "post", "autocomplete=\"off\"");
    $ft->start_table();
    $ft->add_field('string', 'panel_name', @$row['panel_name']);
    $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
    $locale_files = array('' => "-") + $locale_files;
    $ft->add_custom_field('panel_language', create_drop_box_from_array($locale_files, "panel_language", @$row['panel_language']));
    $zones = array('' => "-") + $zones;
    $ft->add_custom_field('time_zone', create_drop_box_from_array($zones, "time_zone", @$row['time_zone'], false));
    $ft->add_field('string', 'charset', @$row['charset']);
    $ft->add_field('text', 'header_code', @$row['header_code']);
    $ft->add_field('on_off', 'maintenance_mode', @$row['maintenance_mode']);
    $ft->add_field('string', 'maintenance_title', @$row['maintenance_title']);
    $ft->add_field('text', 'maintenance_message', @$row['maintenance_message']);
    $ft->add_field('on_off', 'page_auto_refresh', @$row['page_auto_refresh']);
    $ft->add_field('string', 'panel_email_address', @$row['panel_email_address']);
    $ft->add_field('string', 'smtp_server', @$row['smtp_server']);
    $ft->add_field('string', 'smtp_port', @$row['smtp_port']);
    $ft->add_field('on_off', 'smtp_ssl', @$row['smtp_ssl']);
    $ft->add_field('string', 'smtp_login', @$row['smtp_login']);
    $ft->add_field('string', 'smtp_passw', @$row['smtp_passw']);
    $ft->add_field('on_off', 'feed_enable', @$row['feed_enable']);
    $ft->add_field('string', 'feed_url', @$row['feed_url']);
    $query_cache_life = (isset($row['query_cache_life']) and $row['query_cache_life'] != "") ? $row['query_cache_life'] : "30";
    $ft->add_field('string', 'query_cache_life', $query_cache_life);
    $query_num_servers_stop = (isset($row['query_num_servers_stop']) and $row['query_num_servers_stop'] != "") ? $row['query_num_servers_stop'] : "15";
    $ft->add_field('string', 'query_num_servers_stop', $query_num_servers_stop);
    $ft->add_field('string', 'steam_user', @$row['steam_user']);
    $ft->add_field('password', 'steam_pass', @$row['steam_pass']);
    $ft->add_field('password', 'steam_guard', @$row['steam_guard']);
    $mail_setting = isset($row['editable_email']) ? $row['editable_email'] : "1";
    $ft->add_field('on_off', 'editable_email', $mail_setting);
    $ft->add_field('on_off', 'old_dashboard_behavior', @$row['old_dashboard_behavior']);
    $ft->add_custom_field('rsync_available', create_drop_box_from_array($rsync_options, "rsync_available", @$row['rsync_available'], false));
    $ft->end_table();
    $ft->add_button("submit", "update_settings", get_lang('update_settings'));
    $ft->end_form();
}
Ejemplo n.º 2
0
function exec_ogp_module()
{
    global $db;
    $isAdmin = $db->isAdmin($_SESSION['user_id']);
    $submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : "";
    $home_id = $_GET['home_id'];
    $enabled_mods = $db->getHomeMods($home_id);
    if ($isAdmin and isset($_POST['change_home_cfg_id'])) {
        if (!empty($enabled_mods)) {
            foreach ($enabled_mods as $enabled_rows) {
                $db->delGameMod($enabled_rows['mod_id']);
            }
        }
        $home_cfg_id = $game_home['home_cfg_id'];
        $new_home_cfg_id = $_POST['home_cfg_id'];
        if ($db->updateHomeCfgId($home_id, $new_home_cfg_id)) {
            print_success(get_lang('successfully_changed_game_server'));
            $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_game_type') . ":old home_cfg_id:{$home_cfg_id}, new home_cfg_id:{$new_home_cfg_id}");
        }
        $enabled_mods = $db->getHomeMods($home_id);
    }
    if ($isAdmin) {
        $game_home = $db->getGameHome($_GET['home_id']);
    } else {
        $game_home = $db->getUserGameHome($_SESSION['user_id'], $_GET['home_id']);
    }
    if (!$game_home and !$isAdmin) {
        return;
    }
    $home_info = $db->getGameHomeWithoutMods($home_id);
    $server_xml = read_server_config(SERVER_CONFIG_LOCATION . $home_info['home_cfg_file']);
    include 'includes/lib_remote.php';
    $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key']);
    $ftp_installed = $db->isModuleInstalled('ftp');
    $screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME, $home_info['home_id']) === 1;
    if ($isAdmin) {
        $game_home['access_rights'] = "ufpet";
    }
    echo "<h2>" . get_lang('editing_home_called') . " \"" . $home_info['home_name'] . "\"</h2>";
    if (isset($_REQUEST['change_name'])) {
        $server_name = $_POST['server_name'];
        if ($db->changeHomeName($home_id, $server_name) === TRUE) {
            print_success(get_lang('successfully_changed_game_server'));
            $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('game_server_name') . ":{$server_name}");
        } else {
            print_failure("Name update failed.");
        }
    } elseif (isset($_REQUEST['change_control_password'])) {
        $control_password = $_POST['control_password'];
        if ($db->changeHomeControlPassword($home_id, $control_password) === TRUE) {
            print_success(get_lang('control_password_updated_successfully'));
            $db->logger(get_lang('control_password_updated_successfully') . " HOME ID:{$home_id} - " . get_lang('game_control_password') . ":{$control_password}");
        } else {
            print_failure(get_lang('control_password_update_failed'));
        }
    } elseif (isset($_REQUEST['change_ftp_login']) && preg_match("/t/", $game_home['access_rights']) > 0) {
        // Is FTP Module Installed?
        if ($ftp_installed) {
            if ($db->IsFtpEnabled($home_id) or $isAdmin) {
                $post_ftp_login = trim($_POST['ftp_login']);
                $host_stat = $remote->status_chk();
                $user_exists = FALSE;
                $host_online = FALSE;
                if ($host_stat === 1) {
                    $host_online = TRUE;
                    $ftp_accounts_list = $remote->ftp_mgr("list");
                    $ftp_accounts = explode("\n", $ftp_accounts_list);
                    foreach ($ftp_accounts as $ftp_account) {
                        if ($ftp_account != "") {
                            list($ftp_login, $ftp_path) = explode("\t", $ftp_account);
                            $ftp_login = trim($ftp_login);
                            if ($ftp_login == $post_ftp_login) {
                                $user_exists = TRUE;
                                break;
                            }
                        }
                    }
                }
                if ($host_online and !$user_exists) {
                    $old_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                    $change_login_delete_old = $remote->ftp_mgr("userdel", $old_login);
                    if ($change_login_delete_old !== 0) {
                        $change_login_add_new = $remote->ftp_mgr("useradd", $post_ftp_login, $home_info['ftp_password'], $home_info['home_path']);
                    }
                    if (isset($change_login_add_new) and $change_login_add_new !== 0) {
                        if ($db->changeFtpLogin($home_id, $post_ftp_login) === TRUE) {
                            print_success(get_lang('successfully_changed_game_server'));
                            $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('server_ftp_login') . ":{$post_ftp_login}");
                        }
                    } else {
                        print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_login_can_not_be_changed'));
                    }
                } else {
                    print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_login_can_not_be_changed'));
                }
            }
        }
    } elseif (isset($_REQUEST['change_ftp_password']) && preg_match("/t/", $game_home['access_rights']) > 0) {
        // Is FTP Module Installed?
        if ($ftp_installed) {
            if ($db->IsFtpEnabled($home_id) or $isAdmin) {
                $ftp_password = $_POST['ftp_password'];
                $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                $change_passwd_on_remote = $remote->ftp_mgr("passwd", $ftp_login, $ftp_password);
                if ($change_passwd_on_remote !== 0) {
                    if ($db->changeFtpPassword($home_id, clean_path($ftp_password)) === TRUE) {
                        print_success(get_lang('successfully_changed_game_server'));
                        $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('server_ftp_password') . ":{$ftp_password}");
                    }
                } else {
                    print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_password_can_not_be_changed'));
                }
            }
        }
    } elseif (isset($_POST["force_mod_id"])) {
        $force_mod_id = $_POST['force_mod_id'];
        $ip_id = $_POST['ip_id'];
        $port = $_POST['port'];
        if ($db->forceModAtAddress($ip_id, $port, $force_mod_id)) {
            print_success(get_lang('successfully_assigned_mod_to_address'));
            $db->logger(get_lang('successfully_assigned_mod_to_address'));
        } else {
            print_failure("Failed to assign mod to address.");
        }
    } elseif ($isAdmin) {
        if (isset($_REQUEST['create_ftp'])) {
            $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
            $create_ftp = $remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_info['home_path']);
            if ($create_ftp === 0) {
                print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_can_not_be_switched_on'));
            } else {
                $db->changeFtpStatus('enabled', $home_id);
                print_success(get_lang('successfully_changed_game_server'));
                $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_ftp_account_status') . ":enabled");
            }
        } else {
            if (isset($_REQUEST['delete_ftp'])) {
                $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                $delete_ftp = $remote->ftp_mgr("userdel", $login);
                if ($delete_ftp === 0) {
                    print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_can_not_be_switched_off'));
                } else {
                    $db->changeFtpStatus('disabled', $home_id);
                    print_success(get_lang('successfully_changed_game_server'));
                    $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_ftp_account_status') . ":disabled");
                }
            } else {
                if (isset($_REQUEST['change_user_id_main'])) {
                    $user_id_main = $_POST['user_id_main'];
                    if (isset($_POST['deleteoldassigns'])) {
                        $db->unassignHomeFrom("user", $home_info['user_id_main'], $home_id);
                        $home_groups = $db->getGroupsForHome($home_info['home_id']);
                        if (isset($home_groups)) {
                            foreach ($home_groups as $home_group) {
                                $db->unassignHomeFrom("group", $home_group['group_id'], $home_id);
                            }
                        }
                    }
                    $old_home = $db->getUserGameHome($home_info['user_id_main'], $home_id);
                    if ($db->changeUserIdMain($home_id, clean_path($user_id_main)) === TRUE && $db->assignHomeTo("user", $user_id_main, $home_id, $old_home['access_rights']) === TRUE) {
                        print_success(get_lang('successfully_changed_game_server'));
                        $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('change_user_id_main') . ":{$user_id_main}");
                    }
                } else {
                    if (isset($_REQUEST['change_home'])) {
                        $home_path = $_POST['home_path'];
                        if ($db->changeHomePath($home_id, clean_path($home_path)) === TRUE) {
                            if ($ftp_installed) {
                                if ($db->IsFtpEnabled($home_id)) {
                                    $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
                                    $delte_old_ftp_account = $remote->ftp_mgr("userdel", $login);
                                    if ($delte_old_ftp_account !== 0) {
                                        $create_new_ftp_account = $remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_path);
                                    }
                                    if (isset($create_new_ftp_account) and $create_new_ftp_account !== 0) {
                                        print_success(get_lang('successfully_changed_game_server'));
                                        $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('home_path') . ":{$home_path}");
                                    } else {
                                        print_failure(get_lang('error_ocurred_on_remote_server') . " " . get_lang('ftp_login_can_not_be_changed'));
                                    }
                                } else {
                                    print_success(get_lang('successfully_changed_game_server'));
                                    $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('home_path') . ":{$home_path}");
                                }
                            } else {
                                print_success(get_lang('successfully_changed_game_server'));
                                $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('home_path') . ":{$home_path}");
                            }
                        }
                    } else {
                        if (isset($_REQUEST['master_server'])) {
                            if (isset($_POST['add'])) {
                                $action = "add";
                            } else {
                                $action = "remove";
                            }
                            if ($db->setMasterServer($action, $home_id, $home_info['home_cfg_id'], $home_info['remote_server_id']) === TRUE) {
                                print_success(get_lang('successfully_changed_game_server'));
                                $db->logger(get_lang('successfully_changed_game_server') . " HOME ID:{$home_id} - " . get_lang('set_as_master_server') . ":{$action}");
                            }
                        }
                    }
                }
            }
        }
        if (isset($_REQUEST['add_mod'])) {
            $mod_cfg_id = $_POST['mod_cfg_id'];
            if ($db->addModToGameHome($home_id, $mod_cfg_id) === FALSE) {
                print_failure(get_lang_f('failed_to_assing_mod_to_home', $mod_cfg_id));
            } else {
                print_success(get_lang_f('successfully_assigned_mod_to_home', $mod_cfg_id));
                $db->logger(get_lang_f('successfully_assigned_mod_to_home', $mod_cfg_id) . " [HOME ID:{$home_id}]");
            }
        } else {
            if ($submit == "delete_mod") {
                $mod_id = $_GET['mod_id'];
                if ($db->delGameMod($mod_id) === TRUE) {
                    print_success(get_lang('successfully_removed_mod'));
                }
                $db->logger(get_lang('successfully_removed_mod') . " [MOD ID:{$mod_id} HOME ID:{$home_id}]");
            } else {
                if (isset($_REQUEST['set_options'])) {
                    $maxplayers = 0 + @$_POST['maxplayers'];
                    $cliopts = $_POST['cliopts'];
                    $cpus = $_POST['cpus'];
                    $nice = $_POST['nice'];
                    $mod_cfg_id = $_POST['mod_cfg_id'];
                    $db->updateGameModParams($maxplayers, $cliopts, $cpus, $nice, $home_id, $mod_cfg_id);
                    print_success(get_lang("successfully_modified_mod"));
                    $db->logger(get_lang('successfully_modified_mod') . " [MOD CFG ID:{$mod_cfg_id} HOME ID:{$home_id}]");
                    echo "<meta http-equiv='refresh' content='2'>";
                }
            }
        }
    }
    $home_info = $db->getGameHomeWithoutMods($home_id);
    $custom_fileds_access_enabled = preg_match("/c/", $game_home['access_rights']) > 0 ? TRUE : FALSE;
    echo "<p>";
    echo "<a href='?m=gamemanager&p=game_monitor&home_id={$home_id}'>&lt;&lt; " . get_lang('back_to_game_monitor') . "</a>";
    if ($isAdmin) {
        echo " &nbsp; ";
        echo "<a href='?m=user_games'>&lt;&lt; " . get_lang('back_to_game_servers') . "</a>";
        $custom_fileds_access_enabled = TRUE;
    }
    if (isset($server_xml->custom_fields) and $custom_fileds_access_enabled) {
        echo " &nbsp; <a href='?m=user_games&p=custom_fields&home_id=" . $home_id . "'>" . get_lang('go_to_custom_fields') . " &gt;&gt;</a>";
    }
    echo "</p>";
    echo "<table class='center'>";
    if ($isAdmin) {
        // Form to change game type
        echo "<tr><td rowspan='2' class='right'>" . get_lang('game_type') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        $game_cfgs = $db->getGameCfgs();
        $host_stat = $remote->status_chk();
        if ($host_stat === 1) {
            $os = $remote->what_os();
        } else {
            $os = "Unknown OS";
        }
        echo "<select name='home_cfg_id' >";
        // Linux 64 bits + wine
        if (preg_match("/Linux/", $os) and preg_match("/64/", $os) and preg_match("/wine/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
            echo "<option style='background:black;color:white;' value=''>" . get_lang('wine_games') . ":</option>\n";
            foreach ($game_cfgs as $row) {
                if (preg_match("/win/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
        } elseif (preg_match("/Linux/", $os) and preg_match("/64/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
        } elseif (preg_match("/Linux/", $os) and preg_match("/wine/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
            echo "<option style='background:black;color:white;' value=''>" . get_lang('wine_games') . "</option>\n";
            foreach ($game_cfgs as $row) {
                if (preg_match("/win32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif (preg_match("/Linux/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/linux32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif (preg_match("/CYGWIN/", $os) and preg_match("/64/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/win/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                    if (preg_match("/64/", $row['game_key'])) {
                        echo " (64 bit)";
                    }
                    echo "</option>\n";
                }
            }
        } elseif (preg_match("/CYGWIN/", $os)) {
            foreach ($game_cfgs as $row) {
                if (preg_match("/win32/", $row['game_key'])) {
                    $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                    echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'] . "</option>\n";
                }
            }
        } elseif ($os == "Unknown OS") {
            foreach ($game_cfgs as $row) {
                $selected = $home_info['home_cfg_id'] == $row['home_cfg_id'] ? 'selected="selected"' : "";
                echo "<option value='" . $row['home_cfg_id'] . "' {$selected}>" . $row['game_name'];
                if (preg_match("/64/", $row['game_key'])) {
                    echo " (64 bit)";
                }
                echo "</option>\n";
            }
        }
        echo "</select>\n</td></tr>";
        echo "<tr><td class='left'><input type='submit' name='change_home_cfg_id' value='" . get_lang('change_game_type') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('change_game_type_info') . "</td></tr>";
        // Form to edit main user.
        echo "<tr><td rowspan='3' class='right'>" . get_lang('user_id_main') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
        echo "<select name='user_id_main'>";
        $user = $db->getUserById($home_info['user_id_main']);
        echo "<option value='" . $home_info['user_id_main'] . "'>" . $user['users_login'] . "</option>\n";
        $users = $db->getUserList();
        foreach ($users as $user) {
            // Only users and admins can be assigned homes... not subusers
            if (is_null($user['users_parent'])) {
                if ($home_info['user_id_main'] != $user['user_id']) {
                    echo "<option value='" . $user['user_id'] . "'>" . $user['users_login'] . "</option>\n";
                }
            }
        }
        echo "</select></td></tr>";
        echo "<tr><td><input type='checkbox' name='deleteoldassigns' id='deleteoldassigns' /><label for='deleteoldassigns' >" . get_lang('Delete_old_user_assigned_homes') . "</label></td></tr>";
        echo "<tr><td class='left'><input type='submit' name='change_user_id_main' value='" . get_lang('change_user_id_main') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('change_user_id_main_info') . "</td></tr>";
        // Form to edit game path.
        echo "<tr><td class='right'>" . get_lang('home_path') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
        echo "<input type='text' size='30' name='home_path' value=" . $home_info['home_path'] . " />";
        echo "<input type='submit' name='change_home' value='" . get_lang('change_home') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('change_home_info') . "</td></tr>";
    }
    // Form to edit game name
    echo "<tr><td class='right'>" . get_lang('game_server_name') . ":</td><td class='left'>";
    echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
    echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
    echo "<input type='text' size='30' name='server_name' value='" . $home_info['home_name'] . "' />";
    echo "<input type=submit name='change_name' value='" . get_lang('change_name') . "' />";
    echo "</form></td></tr>";
    echo "<tr><td colspan='2' class='info'>" . get_lang('change_name_info') . "</td></tr>";
    // Form to edit control password
    echo "<tr><td class='right'>" . get_lang('game_control_password') . ":</td><td class='left'>";
    echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
    echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
    echo "<input type='text' size='30' name='control_password' value='" . $home_info['control_password'] . "' />";
    echo "<input type='submit' name='change_control_password' value='" . get_lang('change_control_password') . "' />";
    echo "</form></td></tr>";
    echo "<tr><td colspan='2' class='info'>" . get_lang('change_control_password_info') . "</td></tr>";
    if (preg_match("/t/", $game_home['access_rights']) > 0 && $ftp_installed && $db->IsFtpEnabled($home_id)) {
        // Form to edit control ftp login
        $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
        echo "<tr><td class='right'>" . get_lang('server_ftp_login') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='text' size='30' name='ftp_login' value='" . $ftp_login . "' />";
        echo "<input type='submit' name='change_ftp_login' value='" . get_lang('change_ftp_login') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td  colspan='2' class='info'>" . get_lang('change_ftp_login_info') . "</td></tr>";
        // Form to edit control ftp password
        echo "<tr><td class='right'>" . get_lang('server_ftp_password') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='text' size='30' name='ftp_password' value='" . $home_info['ftp_password'] . "' />";
        echo "<input type='submit' name='change_ftp_password' value='" . get_lang('change_ftp_password') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td  colspan='2' class='info'>" . get_lang('change_ftp_password_info') . "</td></tr>";
    }
    if ($isAdmin && $ftp_installed) {
        // Forms to enable/disable ftp account
        echo "<tr>";
        echo "<td class='right'>" . get_lang('change_ftp_account_status') . ":</td>";
        echo "<td class='left'>";
        if (!$db->IsFtpEnabled($home_id)) {
            echo "<div style='display:block;float:left;' ><form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
            echo "<input type='submit' name='create_ftp' value='" . get_lang('ftp_on') . "' />";
            echo "</form></div>";
        } else {
            echo "<div style='display:block;float:left;' ><form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
            echo "<input type='submit' name='delete_ftp' value='" . get_lang('ftp_off') . "' />";
            echo "</form></div>";
        }
        echo "</td></tr>";
        echo "<tr><td  colspan='2' class='info'>" . get_lang('change_ftp_account_status_info') . "</td>";
        echo "</tr>";
    }
    if ($isAdmin) {
        $master_server_home_id = $db->getMasterServer($home_info['remote_server_id'], $home_info['home_cfg_id']);
        if ($master_server_home_id != FALSE and $master_server_home_id == $home_id) {
            $checked = 'checked ="checked"';
        } else {
            $checked = "";
        }
        // Form to enable/disable as master server for local update
        echo "</tr><tr><td class='right'>" . get_lang('master_server_for_clon_update') . ":</td><td class='left'>";
        echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>";
        echo "<input type='checkbox' name='add' {$checked} />";
        echo "<input type='submit' name='master_server' value='" . get_lang('set_as_master_server') . "' />";
        echo "</form></td></tr>";
        echo "<tr><td colspan='2' class='info'>" . get_lang('set_as_master_server_for_local_clon_update') . " (" . get_lang_f('only_available_for', $server_xml->game_name, $home_info['remote_server_name']) . ")</td></tr>";
    }
    echo "</table>";
    if ($isAdmin) {
        $avail_ips = $db->getRemoteServerIPs($home_info['remote_server_id']);
        $ip_array = array();
        if (is_array($avail_ips) && !empty($avail_ips)) {
            echo "<h3>" . get_lang('ips_and_ports') . "</h3>";
            if (!$screen_running) {
                if (isset($_REQUEST['set_ip'])) {
                    $ip_id = $_POST['ip'];
                    $ip_row = $db->resultQuery("SELECT ip FROM OGP_DB_PREFIXremote_server_ips WHERE ip_id=" . $ip_id);
                    $ip = $ip_row['0']['ip'];
                    $port = $_POST['port'];
                    $port = (int) trim($port);
                    $home_id = $_POST['home_id'];
                    if (!isPortValid($port)) {
                        print_failure(get_lang('port_range_error'));
                    } else {
                        if ($db->addGameIpPort($home_id, $ip_id, $port) === FALSE) {
                            print_failure(get_lang_f('ip_port_already_in_use', $ip, $port));
                        } else {
                            print_success(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
                            $db->logger(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
                        }
                    }
                }
                if (isset($_REQUEST["delete_ip"])) {
                    $del_ip = $_GET['ip'];
                    $del_port = $_GET['port'];
                    if ($db->delGameIpPort($home_id, $del_ip, $del_port)) {
                        print_success(get_lang('successfully_assigned_ip_port'));
                        $db->logger(get_lang('successfully_assigned_ip_port') . " [unassigned]");
                    } else {
                        print_failure("Failed to unassign ip:port.");
                    }
                }
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n";
                echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
                echo get_lang('ip') . ":<select name='ip' onchange='this.form.submit();'>";
                foreach ($avail_ips as $value) {
                    $selected = (isset($_POST['ip']) and $_POST['ip'] == $value['ip_id']) ? "selected='selected'" : "";
                    echo "<option value='" . $value['ip_id'] . "' {$selected} >" . $value['ip'] . "</option>\n";
                }
                echo "</select>";
                $ip_id = isset($_POST['ip']) ? $_POST['ip'] : $avail_ips[0]['ip_id'];
                $port = $db->getNextAvailablePort($ip_id, $home_info['home_cfg_id']);
                echo " " . get_lang('port') . ":<input type='text' name='port' value='" . $port . "' size='6' />";
                echo "<input type='submit' name='set_ip' value='" . get_lang('set_ip') . "' />";
                echo "</form>";
                $assigned = $db->getHomeIpPorts($home_id);
                if (empty($assigned)) {
                    print_failure(get_lang('no_ip_ports_assigned'));
                } else {
                    foreach ($assigned as $assigned_rows) {
                        $force_mod = "";
                        $align = "center";
                        if (!empty($enabled_mods) and count($enabled_mods) > 1) {
                            $force_mod .= "<td align='left'>\n" . "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n" . "<input type='hidden' name='ip_id' value=" . $assigned_rows['ip_id'] . " />" . "<input type='hidden' name='port' value=" . $assigned_rows['port'] . " />" . "<select name='force_mod_id' onchange='this.form.submit();'>" . "<option value='0' >" . get_lang('force_mod_on_this_address') . "</option>";
                            foreach ($enabled_mods as $mod) {
                                $selected = $mod['mod_id'] == $assigned_rows['force_mod_id'] ? "selected='selected'" : "";
                                $force_mod .= "<option value='" . $mod['mod_id'] . "' {$selected}>" . $mod['mod_name'] . "</option>";
                            }
                            $force_mod .= "</select>\n</form>\n</td>\n";
                            $align = "right";
                        }
                        echo "<table class='center'><tr><td align='{$align}'>" . $assigned_rows['ip'] . ":" . $assigned_rows['port'] . " <a href='?m=user_games&amp;p=edit&amp;home_id={$home_id}&amp;delete_ip&amp;ip=" . $assigned_rows['ip_id'] . "&amp;port=" . $assigned_rows['port'] . "'>[ " . get_lang('delete') . " ]</a></td>\n" . $force_mod . "</tr>\n</table>\n";
                    }
                }
            } else {
                print_failure(get_lang('server_is_running_change_addresses_not_available'));
            }
        } else {
            print_failure(get_lang('no_ip_addresses_configured') . "<a href='?m=server'>" . get_lang('server_page') . "</a>.");
        }
        echo "<h3>" . get_lang('mods') . "</h3>";
        echo "<p class='info'>" . get_lang('extra_cmd_line_info') . "</p>\n";
        if (empty($enabled_mods)) {
            print_failure(get_lang('note') . ":" . get_lang('note_no_mods'));
            $cpu_count = $remote->cpu_count();
            if ($cpu_count === -1) {
                print_failure(get_lang('warning_agent_offline_defaulting_CPU_count_to_1'));
                $cpu_count = 'NA';
            } else {
                // cpu numbering starts from 0 so lets remove the last cpu.
                $cpu_count -= 1;
            }
            $game_mods = $db->getAvailableModsForGameHome($home_id);
            foreach ($game_mods as $game_mod) {
                if ($game_mod['mod_name'] == "none") {
                    $mod_cfg_id = $game_mod['mod_cfg_id'];
                }
                if ($game_mod['mod_name'] == "None") {
                    $mod_cfg_id = $game_mod['mod_cfg_id'];
                }
            }
            if (isset($mod_cfg_id)) {
                $db->addModToGameHome($home_id, $mod_cfg_id);
                $maxplayers = $server_xml->max_user_amount ? $server_xml->max_user_amount : 0;
                $db->updateGameModParams($maxplayers, '', 'NA', '0', $home_id, $mod_cfg_id);
                echo "<meta http-equiv='refresh' content='0'>";
                return;
            } else {
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n";
                echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
                echo "<p>" . get_lang('available_mods') . ": <select name='mod_cfg_id'>\n";
                foreach ($game_mods as $game_mod) {
                    echo "<option value='" . $game_mod['mod_cfg_id'] . "'>" . $game_mod['mod_name'] . "</option>\n";
                }
                echo "</select>\n";
                echo "<input type='submit' name='add_mod' value='" . get_lang('add_mod') . "' /></p>";
                echo "</form>";
            }
        } else {
            $cpu_count = $remote->cpu_count();
            if ($cpu_count === -1) {
                print_failure(get_lang('warning_agent_offline_defaulting_CPU_count_to_1'));
                $cpu_count = 'NA';
            } else {
                // cpu numbering starts from 0 so lets remove the last cpu.
                $cpu_count -= 1;
            }
            echo "<table class='center'>\n";
            echo "<tr><td></td><td><b>" . get_lang('mod_name') . "</b></td>";
            if ($server_xml->max_user_amount) {
                echo "<td><b>" . get_lang('max_players') . "</b></td>";
            }
            echo "<td><b>" . get_lang('extra_cmd_line_args') . "</b></td><td><b>" . get_lang('cpu_affinity') . "</b></td>";
            echo "<td><b>" . get_lang('nice_level') . "</b></td><td></td></tr>\n";
            foreach ($enabled_mods as $enabled_rows) {
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'><tr><td>\n" . "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n" . "<input type='hidden' name='mod_cfg_id' value=\"" . $enabled_rows['mod_cfg_id'] . "\" />\n" . "<a href='?m=user_games&amp;p=edit&amp;mod_id=" . $enabled_rows['mod_id'] . "&amp;home_id={$home_id}&amp;submit=delete_mod'>[ " . get_lang('remove_mod') . " ]</a><br>" . "<a href='?m=user_games&p=install_cmds&home_id={$home_id}&mod_id=" . $enabled_rows['mod_id'] . "'>" . get_lang('mod_install_cmds') . "</a></td>" . "<td>" . $enabled_rows['mod_name'] . "</td>";
                if ($server_xml->max_user_amount) {
                    echo "<td>" . create_drop_box_from_array(range(0, $server_xml->max_user_amount), 'maxplayers', $enabled_rows['max_players'], true) . "</td>";
                }
                echo "<td><input type='text' name='cliopts' size='20' value=\"" . $enabled_rows['extra_params'] . "\" /></td>";
                echo "<td>" . create_drop_box_from_array(array_merge(array('NA'), range(0, $cpu_count)), 'cpus', $enabled_rows['cpu_affinity']) . "</td>";
                echo "<td>" . create_drop_box_from_array(array_merge(range(-19, 19)), 'nice', $enabled_rows['nice']) . "</td>";
                echo "<td><input type='submit' name='set_options' value='" . get_lang('set_options') . "' /></td></tr></form>\n";
            }
            echo "</table>\n";
            $game_mods = $db->getAvailableModsForGameHome($home_id);
            foreach ($game_mods as $game_mod) {
                if ($game_mod['mod_name'] == "none") {
                    $mods_available = 0;
                } elseif ($game_mod['mod_name'] == "None") {
                    $mods_available = 0;
                } else {
                    $mods_available = 1;
                }
            }
            if ($mods_available == 1) {
                echo "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n";
                echo "<input type='hidden' name='home_id' value=\"{$home_id}\" />\n";
                echo "<p>" . get_lang('available_mods') . ": <select name='mod_cfg_id'>\n";
                foreach ($game_mods as $game_mod) {
                    echo "<option value='" . $game_mod['mod_cfg_id'] . "'>" . $game_mod['mod_name'] . "</option>\n";
                }
                echo "</select>\n";
                echo "<input type='submit' name='add_mod' value='" . get_lang('add_mod') . "' /></p>";
                echo "</form>";
            }
        }
    } else {
        $assigned = $db->getHomeIpPorts($home_id);
        if (!empty($assigned) and !empty($enabled_mods) and count($enabled_mods) > 1) {
            echo "<table class='center'>\n" . "<tr>\n" . "<td colspan='2' align='center'>" . "<h3>" . get_lang('switch_mods') . "</h3>" . "</td>\n" . "</tr>\n";
            foreach ($assigned as $assigned_rows) {
                $force_mod = "<tr>\n<td align='right' style='width:50%' >" . get_lang_f('switch_mod_for_address', $assigned_rows['ip'] . ":" . $assigned_rows['port']) . "</td>\n" . ($force_mod .= "<td align='left' style='width:50%' >\n" . "<form action='?m=user_games&p=edit&home_id=" . $home_id . "' method='post'>\n" . "<input type='hidden' name='ip_id' value=" . $assigned_rows['ip_id'] . " />" . "<input type='hidden' name='port' value=" . $assigned_rows['port'] . " />" . "<select name='force_mod_id' onchange='this.form.submit();'>");
                foreach ($enabled_mods as $mod) {
                    $selected = $mod['mod_id'] == $assigned_rows['force_mod_id'] ? "selected='selected'" : "";
                    $force_mod .= "<option value='" . $mod['mod_id'] . "' {$selected}>" . $mod['mod_name'] . "</option>";
                }
                $force_mod .= "</select>\n</form>\n</td>\n</tr>\n";
            }
            echo $force_mod . "</table>\n";
        }
    }
}
Ejemplo n.º 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 $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);
}
Ejemplo n.º 4
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");
                    }
                }
            }
        }
    }
}
Ejemplo n.º 5
0
function exec_ogp_module()
{
    global $db, $settings;
    $my_user_id = $_SESSION['user_id'];
    #who we're logged in as
    $user_id = $_REQUEST['user_id'];
    $isAdmin = $db->isAdmin($my_user_id);
    $mySubUsersAssoc = $db->listSubUsersByParent($my_user_id);
    if ($mySubUsersAssoc) {
        foreach ($mySubUsersAssoc as $subuser) {
            $mySubUsers[] = $subuser['user_id'];
        }
    }
    // Check that we are admin or the user itself.
    if (!isset($user_id)) {
        print_failure("Error in parameters.");
        return;
    } else {
        if (!$isAdmin && $my_user_id !== $user_id && @(!in_array($user_id, $mySubUsers))) {
            print_failure(get_lang('no_rights'));
            return;
        }
    }
    if ($isAdmin) {
        $users = $db->getUserList();
        foreach ($users as $user) {
            if ($db->isAdmin($user['user_id'])) {
                $first_admin_id = $user['user_id'];
                break;
            }
        }
        if ($db->isAdmin($user_id) and $first_admin_id != $my_user_id and $user_id != $my_user_id) {
            print_failure(get_lang('no_rights'));
            return;
        }
    }
    echo "<h2>" . get_lang('your_profile') . "</h2>";
    echo "<div align='center'>";
    require_once "includes/form_table_class.php";
    if ((isset($_POST['new_password']) || isset($_POST['retype_new_password'])) && $_POST['new_password'] !== $_POST['retype_new_password']) {
        print_failure(get_lang('password_mismatch'));
    } elseif (isset($_POST['edit_user']) && $my_user_id === $user_id && !$db->is_valid_login($my_user_id, $_REQUEST['current_password'])) {
        print_failure(get_lang('current_password_mismatch'));
    } else {
        if (isset($_POST['edit_user'])) {
            $user_id = $_POST['user_id'];
            $newlang = $_POST['newlang'];
            $login = $_POST['login'];
            $login = str_replace('"', '', $login);
            $login = str_replace("'", "", $login);
            $firstname = $_POST['first_name'];
            $firstname = str_replace('"', '', $firstname);
            $firstname = str_replace("'", "", $firstname);
            $lastname = $_POST['last_name'];
            $lastname = str_replace('"', '', $lastname);
            $lastname = str_replace("'", "", $lastname);
            $email = $_POST['email_address'];
            $city = $_POST['city'];
            $province = $_POST['province'];
            $country = $_POST['country'];
            $phone = $_POST['phone_number'];
            $phone = preg_replace("/[^0-9]/", "", $phone);
            $theme = $_POST['theme'];
            // OGP needs to set the new theme and language in the current session, only if I'm modifying my own user profile.
            if ($my_user_id == $user_id) {
                $_SESSION['users_theme'] = $theme;
                $_SESSION['users_lang'] = $newlang;
            }
            $fields['users_lang'] = $_POST['newlang'];
            $fields['users_fname'] = $firstname;
            $fields['users_lname'] = $lastname;
            $fields['users_phone'] = $phone;
            $fields['users_city'] = $city;
            $fields['users_province'] = $province;
            $fields['users_country'] = $country;
            if (isset($settings['editable_email'])) {
                if ($settings['editable_email'] == "1" or $settings['editable_email'] == "0" and $isAdmin) {
                    $fields['users_email'] = $email;
                }
            } elseif (!isset($settings['editable_email'])) {
                $fields['users_email'] = $email;
            }
            if ($isAdmin) {
                $comment = $_POST['comment'];
                $mins = $_POST['minutes'];
                $hours = $_POST['hours'];
                $months = $_POST['month'];
                $days = $_POST['days'];
                $years = $_POST['years'];
                if ($months == 'X' || $days == 'X' || $years == 'X' || $hours == 'X' || $mins == 'X') {
                    $expire_timestamp = "X";
                } else {
                    $expire_timestamp = mktime($hours, $mins, 0, $months, $days, $years, -1);
                }
                $fields['users_comment'] = $comment;
                $fields['user_expires'] = $expire_timestamp;
                $fields['users_login'] = $login;
            }
            if (empty($theme)) {
                $fields['users_theme'] = NULL;
            } else {
                $fields['users_theme'] = $theme;
            }
            if (isset($_POST['new_password']) && !empty($_POST['new_password'])) {
                $fields['users_passwd'] = md5($_POST['new_password']);
            }
            if (!$db->editUser($fields, $user_id)) {
                print_failure(get_lang_f('failed_to_update_user_profile_error', $db->getError()));
            } else {
                print_success(get_lang_f('profile_of_user_modified_successfully', $login));
                $db->logger(get_lang_f('profile_of_user_modified_successfully', $login));
            }
            global $view;
            if ($isAdmin) {
                $view->refresh("?m=user_admin");
            } else {
                if (isset($_SESSION['REFER'])) {
                    $view->refresh($_SESSION['REFER']);
                } else {
                    $view->refresh("?m=user_admin&amp;p=edit_user&user_id=" . $_SESSION['user_id']);
                }
            }
            return;
        }
    }
    $userInfo = $db->getUserById($user_id);
    $ft = new FormTable();
    $ft->start_form('?m=user_admin&amp;p=edit_user');
    $ft->add_field_hidden('user_id', $user_id);
    $ft->start_table();
    $login_option = !$isAdmin ? 'readonly="readonly"' : "";
    $ft->add_field('string', 'login', $userInfo['users_login'], 50, $login_option);
    if ($my_user_id === $user_id) {
        $ft->add_field('password', 'current_password', '');
    }
    $ft->add_field('password', 'new_password', '');
    $ft->add_field('password', 'retype_new_password', '');
    $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
    array_push($locale_files, "-");
    sort($locale_files);
    $ft->add_custom_field('language', create_drop_box_from_array($locale_files, "newlang", @$userInfo['users_lang']));
    require_once 'modules/settings/functions.php';
    $theme = "";
    $add_empty = FALSE;
    if (isset($userInfo['users_theme'])) {
        $theme = $userInfo['users_theme'];
        $add_empty = TRUE;
    }
    $ft->add_custom_field('theme', get_theme_html_str($theme, $add_empty));
    $ft->add_field('string', 'first_name', $userInfo['users_fname']);
    $ft->add_field('string', 'last_name', $userInfo['users_lname']);
    $ft->add_field('string', 'phone_number', $userInfo['users_phone']);
    $email_option = (!$isAdmin and isset($settings['editable_email']) and $settings['editable_email'] == "0") ? 'readonly="readonly"' : "";
    $ft->add_field('string', 'email_address', $userInfo['users_email'], 50, $email_option);
    $ft->add_field('string', 'city', $userInfo['users_city']);
    $ft->add_field('string', 'province', $userInfo['users_province']);
    $ft->add_field('string', 'country', $userInfo['users_country']);
    if ($isAdmin) {
        $ft->add_field('text', 'comment', $userInfo['users_comment']);
        ?>
		<tr>
		<td align='right'><?php 
        print_lang('expires');
        ?>
:</td>
	<?php 
        $timediff = $userInfo["user_expires"];
        //echo "Timediff is $timediff<br>";
        if (read_expire($timediff) !== 'X') {
            $exday = date("j", $timediff);
            $exyear = date("Y", $timediff);
            $exmonth = date("m", $timediff);
            $exhour = date("H", $timediff);
            $exmin = date("i", $timediff);
        } else {
            $exday = "X";
            $exyear = "X";
            $exmonth = "X";
            $exhour = "X";
            $exmin = "X";
        }
        $minutes = range(0, 59);
        $pad_length = 2;
        foreach ($minutes as &$minute) {
            $minute = str_pad($minute, $pad_length, "0", STR_PAD_LEFT);
        }
        $months = array('X' => 'X', '1' => 'Jan', '2' => 'Feb', '3' => 'Mar', '4' => 'Apr', '5' => 'May', '6' => 'Jun', '7' => 'July', '8' => 'Aug', '9' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
        #The ugliness below is to populate the expiration fields with what is in the db
        #Looks bad, but it works well
        echo "<td align='left'>";
        $x_array = array('X');
        echo create_drop_box_from_array(array_merge($x_array, range(1, 31)), "days", $exday, true);
        echo create_drop_box_from_array($months, "month", $exmonth, false);
        echo create_drop_box_from_array(array_merge($x_array, range(date('Y') - 1, date('Y') + 10)), "years", $exyear, true);
        echo " - ";
        echo create_drop_box_from_array(array_merge($x_array, range(0, 23)), "hours", $exhour, true);
        echo ":";
        echo create_drop_box_from_array(array_merge($x_array, $minutes), "minutes", $exmin, true);
        echo "<tr><td colspan='2' class='info'>" . get_lang('expires_info') . "</td></tr>";
    }
    $ft->end_table();
    $ft->add_button("submit", "edit_user", get_lang('save_profile'));
    $ft->end_form();
    echo "</div>";
}
Ejemplo n.º 6
0
     if (is_array($map_array)) {
         $map_array = cleanFilenames($map_array);
         $maps_found = "DIR";
     }
 }
 $check_ok = TRUE;
 // If there is map list or location defined we should have maps available.
 if ($server_xml->map_list || $server_xml->maps_location) {
     if (is_array($map_array)) {
         echo "<tr><td class='right'>" . get_lang('available_maps') . ":</td><td class='left'>\n";
         // We remove all lines that start with // because we
         // expect those lines to be comments.
         $comments = preg_grep("/^\\s*\\/\\//", $map_array);
         $map_array = array_diff($map_array, $comments);
         sort($map_array);
         echo create_drop_box_from_array($map_array, 'map', $last_param['map']);
         echo "</td></tr>";
         echo "<tr><td colspan='2' class='info'>" . get_lang('maps_read_from') . " ";
         if ($maps_found == "DIR") {
             echo get_lang('directory') . " " . clean_path($map_path) . ".";
         } else {
             echo get_lang('file') . " " . clean_path($mapfile) . ".";
         }
         echo "</td></tr>\n";
     } else {
         echo "<tr><td>";
         print_failure(get_lang('failed_to_read_maps_error_code') . ": {$map_array}");
         echo "</td></tr>";
         $check_ok = FALSE;
     }
 }
Ejemplo n.º 7
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 
        }
    }
}