", " "); $replace = array(""", "'", "\", """, "'", "<", ">", " "); $text = str_replace($search, $replace, $text); return $text; } session_start(); if (!isset($_SESSION['users_lang'])) $_SESSION['users_lang'] = "English"; if (isset($_GET['localeset'])) $_SESSION['users_lang'] = $_GET['localeset']; require_once("includes/helpers.php"); require_once("includes/view.php"); require_once("includes/lang.php"); require_once("includes/html_functions.php"); require_once("includes/functions.php"); ogpLang(); $view = new OGPView(); $view->setCharset(get_lang('lang_charset')); ?>
| ";
if ($locale_files[$i] == $_SESSION['users_lang'])
echo " | \n";
$counter++;
}
echo "
Welcome to the GSP (Game Server Panel) installer, maintained by WDS.
"; echo ""; echo "GSP is a heavily customized fork of OGP. This installer will:
"; echo "includes/config.inc.php with your database credentials.ogp_ tables to your chosen prefix.modules/ directory.| \n"; echo ""; echo ""; echo ""; echo " |
| \n"; if (!isset($_POST['db_host'])) { print_failure("No form data received. Please go back and fill in the database settings."); echo ""; echo " |
includes/config.inc.php could not be opened for writing. " .
"Please run: sudo chmod 664 includes/config.inc.php && sudo chown www-data:www-data includes/config.inc.php " .
"(or sudo chmod -R 775 includes/ && sudo chown -R www-data:www-data includes/ if the file does not yet exist). " .
"You can also use the Dependency Check page for a full diagnostics report.");
echo "";
echo "\n";
return;
}
if (fwrite($temp, $config) === false) {
print_failure(get_lang('unable_to_write_config'));
echo "";
fclose($temp);
echo "\n";
return;
}
fclose($temp);
print_success(get_lang('config_written'));
// --- Connect to database using port ---
$db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix, (int)$db_port);
$error_text = "";
if (get_db_error_text($db, $error_text)) {
print_failure($error_text);
echo "";
echo "\n";
return;
}
// --- Detect existing database and back it up before reinstall ---
gsp_backup_existing_db($db, $db_host, $db_user, $db_pass, $db_name, $db_port);
// --- Optional ogp_ → gsp_ migration ---
gsp_migrate_tables($db, $table_prefix);
// --- Create base module management tables ---
$db->query("DROP TABLE IF EXISTS `".$table_prefix."modules`");
$db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."modules` (
`id` smallint(5) unsigned NOT NULL auto_increment,
`title` varchar(100) NOT NULL default '',
`folder` varchar(100) NOT NULL default '',
`version` varchar(10) NOT NULL default '0',
`db_version` int(10) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `folder` (`folder`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;");
$db->query("DROP TABLE IF EXISTS `".$table_prefix."module_menus`");
$db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."module_menus` (
`module_id` int(11) NOT NULL COMMENT 'This references to modules.id',
`subpage` varchar(64) NOT NULL default '',
`group` varchar(32) NOT NULL,
`menu_name` varchar(128) NOT NULL,
`pos` INT UNSIGNED NOT NULL,
PRIMARY KEY (`module_id`, `subpage`, `group`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;");
// --- Install all modules ---
require_once("modules/modulemanager/module_handling.php");
@add_lang_module('modulemanager');
$modules = list_available_modules();
// Install modulemanager first
if (in_array('modulemanager', $modules)) {
gsp_install_module($db, 'modulemanager');
}
foreach ($modules as $module) {
if ($module == 'modulemanager') continue;
gsp_install_module($db, $module);
}
print_success(get_lang('database_created'));
// --- Default site settings ---
$site_settings = array(
"title" => "GSP - Game Server Panel",
"slogan" => get_lang('slogan'),
"ogp_version" => "0",
"version_type" => "GSP",
"theme" => "Revolution",
"welcome_title" => "1",
"welcome_title_message"=> "Admin user already exists – skipped creation.
"; } // --- Update game configs --- updateGameConfigsPostInstall(); echo "".get_lang('remove_install_and_secure_config')."
"; echo "SECURITY: The default admin password is admin. Change it immediately after your first login at Admin → User Management.
"; echo ""; echo "\n"; // --- Disable the installer by renaming install.php to install.php.bak --- gsp_disable_installer(); echo "\n"; } else { echo "Unknown step. Start over
"; } } /** * Install a single module, treating prerequisite failures as warnings * (not hard failures) per GSP policy: "Do not run prerequisite checks – * our environment is customized." * * Returns the same values as install_module(), but the caller does not * abort the overall install when -2 is returned. */ function gsp_install_module($db, $module) { $result = install_module($db, $module, FALSE); // -1 = module.php missing or malformed (genuine hard error) // -2 = prereq missing or DB query failed; treat as warning // 0 = already installed // 1 = installed successfully // 2 = optional, skipped if ($result === -1) { // Already printed by install_module(); just note it. } return $result; } /** * Optional ogp_ → configured-prefix migration. * * Rules: * - If a table named ogp_X exists AND the corresponding prefix_X does NOT * exist, rename ogp_X -> prefix_X. * - If prefix_X already exists, skip that table (never fail). * - If no ogp_ tables exist at all, do nothing. */ function gsp_migrate_tables($db, $table_prefix) { if ($table_prefix === 'ogp_') { // Already using ogp_ prefix – nothing to migrate. return; } // Fetch all tables starting with ogp_ $rows = $db->resultQuery("SHOW TABLES LIKE 'ogp\\_%'"); if (!$rows || !is_array($rows)) return; $renamed = 0; $skipped = 0; foreach ($rows as $row) { $ogp_table = array_values($row)[0]; // e.g. ogp_users $suffix = substr($ogp_table, 4); // strip leading "ogp_" $new_table = $table_prefix . $suffix; // Check if destination table already exists $exists = $db->resultQuery("SHOW TABLES LIKE '".str_replace("_", "\\_", $new_table)."'"); if ($exists && is_array($exists) && count($exists) > 0) { $skipped++; continue; } // Rename $ok = $db->query("RENAME TABLE `".mysqli_real_escape_string_compat($ogp_table)."` TO `".mysqli_real_escape_string_compat($new_table)."`"); if ($ok) { $renamed++; } } if ($renamed > 0) print_success("Migrated {$renamed} table(s) fromogp_ to {$table_prefix} prefix.");
if ($skipped > 0)
echo "{$skipped} table(s) already existed under the {$table_prefix} prefix – skipped.
⚠ Existing database detected (" . htmlspecialchars((string)$table_count, ENT_QUOTES, 'UTF-8') . " table(s)). Creating backup before reinstall…
"; // Determine backup DB name $backup_name = $db_name . '_BAK'; $check_bak = $db->resultQuery("SHOW DATABASES LIKE '" . mysqli_real_escape_string_compat($backup_name) . "'"); if ($check_bak && is_array($check_bak) && count($check_bak) > 0) { $backup_name = $db_name . '_BAK_' . date('Ymd_His'); } // Create backup database $safe_backup = '`' . mysqli_real_escape_string_compat($backup_name) . '`'; $safe_src = '`' . mysqli_real_escape_string_compat($db_name) . '`'; $created = $db->query("CREATE DATABASE IF NOT EXISTS {$safe_backup} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); if (!$created) { echo "Could not create backup database " . htmlspecialchars($backup_name) . ". Skipping backup (install will continue).
" . htmlspecialchars($backup_name) . " — {$copied} table(s) copied" . ($failed > 0 ? ", {$failed} failed (non-fatal)" : "") . ".");
// Drop all tables in the target database so the fresh install is clean
$db->query("SET FOREIGN_KEY_CHECKS = 0");
foreach ($tables_result as $row) {
$tbl = array_values($row)[0];
$safe_tbl = '`' . mysqli_real_escape_string_compat($tbl) . '`';
$db->query("DROP TABLE IF EXISTS {$safe_src}.{$safe_tbl}");
}
$db->query("SET FOREIGN_KEY_CHECKS = 1");
print_success("Target database cleared. Fresh install will proceed.");
}
/**
* After a successful install, rename install.php to install.php.bak and write
* a minimal bootstrap stub as the new install.php that prevents accidental
* re-runs while giving an admin an easy path to restore the real installer.
*/
function gsp_disable_installer() {
$self = __FILE__;
$bak_path = dirname($self) . '/install.php.bak';
// Read the current file before we rename it
$installer_content = @file_get_contents($self);
if ($installer_content === false) {
echo "Could not read install.php for backup — installer not renamed (non-fatal).
"; return; } // Write the backup copy if (@file_put_contents($bak_path, $installer_content) === false) { echo "Could not write install.php.bak — installer not renamed (non-fatal).
"; return; } // Write the stub that replaces install.php $stub = <<<'STUB' Invalid or expired restore token. Please reload the page and try again.'); } $bak = __DIR__ . '/install.php.bak'; if (!is_readable($bak)) { die('install.php.bak not found. Restore manually.
'); } $content = file_get_contents($bak); if ($content === false || file_put_contents(__FILE__, $content) === false) { die('Could not overwrite install.php. Check file permissions.
'); } // Invalidate the token after use unset($_SESSION['gsp_restore_token']); header('Location: install.php'); exit; } $token = htmlspecialchars($_SESSION['gsp_restore_token'], ENT_QUOTES, 'UTF-8'); ?>The GSP installer has been disabled after a successful installation to prevent accidental re-runs.
The original installer is preserved at install.php.bak.
To restore manually:
cp install.php.bak install.php
Could not overwrite install.php with stub — installer not disabled (non-fatal). Delete or rename install.php manually.
"; return; } print_success("Installer disabled:install.php renamed to stub. Full installer preserved as install.php.bak.");
echo "To re-enable the installer, click Restore & Re-run Installer on the new install.php page, or run: cp install.php.bak install.php