From d8972fee165c17f16924f89b2f7bb5ff4d4ff3a0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 2 May 2026 19:41:22 +0000 Subject: [PATCH] fix: consolidate module schemas to db_version=1, fix billing admin undefined vars and prefix Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/35af6b7c-2518-4105-b4d2-ba1f3fe754cd Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com> --- modules/TS3Admin/module.php | 30 ++-- modules/addonsmanager/module.php | 29 ++- modules/billing/admin.php | 11 ++ modules/billing/adminserverlist.php | 34 +++- modules/billing/module.php | 224 +++++++++++------------- modules/billing/tools/check_db_user.php | 7 +- modules/fast_download/module.php | 31 ++-- modules/gamemanager/module.php | 136 ++++++-------- modules/modulemanager/module.php | 29 ++- modules/server/module.php | 97 ++++------ 10 files changed, 284 insertions(+), 344 deletions(-) diff --git a/modules/TS3Admin/module.php b/modules/TS3Admin/module.php index 71a54893..fa8facfd 100644 --- a/modules/TS3Admin/module.php +++ b/modules/TS3Admin/module.php @@ -25,25 +25,21 @@ // Module general information $module_title = "TS3Admin"; $module_version = "0.2"; -$db_version = 2; +$db_version = 1; $module_required = TRUE; $module_menus = array( array( 'subpage' => '', 'name'=>'ts3admin', 'group'=>'user' ) ); $install_queries = array(); $install_queries[0] = array( -"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."ts3_homes`;", -"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."ts3_homes` - (`ts3_id` int(50) NOT NULL auto_increment, - `rserver_id` int(50) NOT NULL, - `ip` varchar(20) NOT NULL, - `pwd` varchar(40) NOT NULL, - `vserver_id` int(50) NOT NULL, - `user_id` int(50) NOT NULL, - PRIMARY KEY (`ts3_id`), -UNIQUE KEY user_id (user_id,vserver_id)) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); -$install_queries[1] = array( -"ALTER TABLE `".OGP_DB_PREFIX."ts3_homes` DROP INDEX `user_id` , - ADD UNIQUE `rserver_id` ( `rserver_id` , `vserver_id` , `user_id` );"); -$install_queries[2] = array( -"ALTER TABLE `".OGP_DB_PREFIX."ts3_homes` ADD `port` int(11) DEFAULT '10011'" + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."ts3_homes` ( + `ts3_id` int(50) NOT NULL auto_increment, + `rserver_id` int(50) NOT NULL, + `ip` varchar(20) NOT NULL, + `pwd` varchar(40) NOT NULL, + `vserver_id` int(50) NOT NULL, + `user_id` int(50) NOT NULL, + `port` int(11) DEFAULT '10011', + PRIMARY KEY (`ts3_id`), + UNIQUE KEY `rserver_id` (`rserver_id`,`vserver_id`,`user_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;" ); -?> +?> \ No newline at end of file diff --git a/modules/addonsmanager/module.php b/modules/addonsmanager/module.php index c74c512a..dc482d70 100644 --- a/modules/addonsmanager/module.php +++ b/modules/addonsmanager/module.php @@ -25,24 +25,21 @@ // Module general information $module_title = "Addons Manager"; $module_version = "1.2"; -$db_version = 2; +$db_version = 1; $module_required = TRUE; $module_menus = array( array( 'subpage' => 'addons_manager', 'name'=>'Addons Manager', 'group'=>'admin' ) ); $install_queries = array(); $install_queries[0] = array( -"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."addons`;", -"CREATE TABLE IF NOT EXISTS ".OGP_DB_PREFIX."addons - (addon_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(80) NOT NULL, - url VARCHAR(200) NOT NULL, - path VARCHAR(80) NOT NULL, - addon_type VARCHAR(7) NOT NULL, - home_cfg_id VARCHAR(7) NOT NULL) ENGINE=MyISAM;"); - -$install_queries[1] = array( - "ALTER TABLE `".OGP_DB_PREFIX."addons` ADD `post_script` longtext NOT NULL;"); - -$install_queries[2] = array( - "ALTER TABLE `".OGP_DB_PREFIX."addons` ADD `group_id` int(11) NULL;"); -?> + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."addons` ( + `addon_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(80) NOT NULL, + `url` VARCHAR(200) NOT NULL, + `path` VARCHAR(80) NOT NULL, + `addon_type` VARCHAR(7) NOT NULL, + `home_cfg_id` VARCHAR(7) NOT NULL, + `post_script` longtext NOT NULL, + `group_id` int(11) NULL + ) ENGINE=MyISAM;" +); +?> \ No newline at end of file diff --git a/modules/billing/admin.php b/modules/billing/admin.php index e1022335..b4ffee29 100644 --- a/modules/billing/admin.php +++ b/modules/billing/admin.php @@ -2,6 +2,17 @@ // Admin landing page require_once(__DIR__ . '/includes/admin_auth.php'); require_once(__DIR__ . '/includes/config_loader.php'); + +// Ensure site variables are defined regardless of which config was loaded. +// The panel config (loaded first by config_loader) does not define these, so +// we fall back to safe defaults when they are absent. +if (!isset($SITE_BASE_URL)) { + $SITE_BASE_URL = ''; +} +if (!isset($SITE_DATA_DIR)) { + $SITE_DATA_DIR = realpath(__DIR__ . '/data') ?: (__DIR__ . '/data'); +} + include(__DIR__ . '/includes/top.php'); include(__DIR__ . '/includes/menu.php'); diff --git a/modules/billing/adminserverlist.php b/modules/billing/adminserverlist.php index 299442b4..2d0d4e64 100644 --- a/modules/billing/adminserverlist.php +++ b/modules/billing/adminserverlist.php @@ -57,21 +57,39 @@ function sync_billing_services(mysqli $db, string $prefix): array { $messages = []; - // Schema guard: verify billing_services has the expected columns before touching it. + // Schema auto-repair: add any missing columns to billing_services before syncing. // col_exists() is provided by bootstrap.php. - $requiredCols = ['home_cfg_id', 'mod_cfg_id', 'service_name', 'description', - 'remote_server_id', 'enabled', 'out_of_stock', - 'price_daily', 'price_monthly', 'price_year', - 'slot_min_qty', 'slot_max_qty', 'install_method']; $tableName = $prefix . 'billing_services'; - foreach ($requiredCols as $col) { + + // Map of column => ALTER TABLE fragment to add it if missing. + $autoRepairCols = [ + 'description' => "ADD COLUMN `description` VARCHAR(1000) NOT NULL DEFAULT ''", + 'img_url' => "ADD COLUMN `img_url` VARCHAR(255) NOT NULL DEFAULT ''", + 'out_of_stock' => "ADD COLUMN `out_of_stock` VARCHAR(255) NOT NULL DEFAULT ''", + 'slot_min_qty' => "ADD COLUMN `slot_min_qty` INT(11) NOT NULL DEFAULT 0", + 'slot_max_qty' => "ADD COLUMN `slot_max_qty` INT(11) NOT NULL DEFAULT 0", + 'price_daily' => "ADD COLUMN `price_daily` FLOAT(15,4) NOT NULL DEFAULT 0", + 'price_monthly' => "ADD COLUMN `price_monthly` FLOAT(15,4) NOT NULL DEFAULT 0", + 'price_year' => "ADD COLUMN `price_year` FLOAT(15,4) NOT NULL DEFAULT 0", + 'remote_server_id' => "ADD COLUMN `remote_server_id` VARCHAR(255) NOT NULL DEFAULT ''", + 'install_method' => "ADD COLUMN `install_method` VARCHAR(255) NOT NULL DEFAULT 'steamcmd'", + ]; + + foreach ($autoRepairCols as $col => $alterFragment) { if (!col_exists($db, $tableName, $col)) { - $messages[] = "⚠ Schema issue: column '{$col}' missing from {$tableName}. Run the billing module migration."; + $t = $db->real_escape_string($tableName); + if ($db->query("ALTER TABLE `{$t}` {$alterFragment}")) { + $messages[] = "✔ Auto-repaired: added column '{$col}' to {$tableName}."; + } else { + $messages[] = "✖ Could not add column '{$col}' to {$tableName}: " . $db->error; + } } } - // If critical columns are missing, skip the sync to avoid SQL errors. + + // If critical columns are still missing after repair, skip the sync to avoid SQL errors. foreach (['service_name', 'mod_cfg_id', 'enabled'] as $critical) { if (!col_exists($db, $tableName, $critical)) { + $messages[] = "⚠ Critical column '{$critical}' missing from {$tableName}; skipping sync."; return $messages; } } diff --git a/modules/billing/module.php b/modules/billing/module.php index 7b84143d..2a5fade1 100644 --- a/modules/billing/module.php +++ b/modules/billing/module.php @@ -25,7 +25,7 @@ // Module general information $module_title = "billing"; $module_version = "3.2"; -$db_version = 4; +$db_version = 1; $module_required = FALSE; // Module description $module_description = "Billing storefront / provisioning integration. Public ordering runs as a standalone site; panel pages provide provisioning and admin order management."; @@ -39,151 +39,127 @@ $module_menus = array( $install_queries = array(); -// Version 1: Current schema - clean install with all tables and required columns +// Baseline schema — all billing tables with their final column set. +// This is the single source of truth for fresh installs. +// All CREATE TABLE statements use IF NOT EXISTS so they are safe to re-run. +// Existing installs at any previous db_version already have these tables and columns, +// so no incremental ALTER chains are needed here. $install_queries[0] = array( - // Billing Services - Available game server packages + // Billing Services — available game server packages "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_services` ( - `service_id` INT(11) NOT NULL AUTO_INCREMENT, - `home_cfg_id` INT(11) NOT NULL DEFAULT 0, - `mod_cfg_id` INT(11) NOT NULL DEFAULT 0, - `service_name` VARCHAR(255) NOT NULL, - `remote_server_id` VARCHAR(255) NOT NULL DEFAULT '', - `out_of_stock` VARCHAR(255) NOT NULL DEFAULT '', - `slot_max_qty` INT(11) NOT NULL DEFAULT 0, - `slot_min_qty` INT(11) NOT NULL DEFAULT 0, - `price_daily` FLOAT(15,4) NOT NULL DEFAULT 0, - `price_monthly` FLOAT(15,4) NOT NULL DEFAULT 0, - `price_year` FLOAT(15,4) NOT NULL DEFAULT 0, - `description` VARCHAR(1000) NOT NULL DEFAULT '', - `img_url` VARCHAR(255) NOT NULL DEFAULT '', - `ftp` VARCHAR(255) NOT NULL DEFAULT '', - `install_method` VARCHAR(255) NOT NULL DEFAULT 'steamcmd', - `manual_url` VARCHAR(255) NOT NULL DEFAULT '', - `access_rights` VARCHAR(255) NOT NULL DEFAULT '', - `enabled` INT(11) NOT NULL DEFAULT 0, + `service_id` INT(11) NOT NULL AUTO_INCREMENT, + `home_cfg_id` INT(11) NOT NULL DEFAULT 0, + `mod_cfg_id` INT(11) NOT NULL DEFAULT 0, + `service_name` VARCHAR(255) NOT NULL, + `description` VARCHAR(1000) NOT NULL DEFAULT '', + `img_url` VARCHAR(255) NOT NULL DEFAULT '', + `remote_server_id` VARCHAR(255) NOT NULL DEFAULT '', + `out_of_stock` VARCHAR(255) NOT NULL DEFAULT '', + `slot_max_qty` INT(11) NOT NULL DEFAULT 0, + `slot_min_qty` INT(11) NOT NULL DEFAULT 0, + `price_daily` FLOAT(15,4) NOT NULL DEFAULT 0, + `price_monthly` FLOAT(15,4) NOT NULL DEFAULT 0, + `price_year` FLOAT(15,4) NOT NULL DEFAULT 0, + `ftp` VARCHAR(255) NOT NULL DEFAULT '', + `install_method` VARCHAR(255) NOT NULL DEFAULT 'steamcmd', + `manual_url` VARCHAR(255) NOT NULL DEFAULT '', + `access_rights` VARCHAR(255) NOT NULL DEFAULT '', + `enabled` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`service_id`), - KEY `enabled` (`enabled`), - KEY `mod_cfg_id` (`mod_cfg_id`) + KEY `enabled` (`enabled`), + KEY `mod_cfg_id` (`mod_cfg_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;", - - // Billing Orders - Actual game server instances (ongoing services) + + // Billing Orders — active game server instances "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_orders` ( - `order_id` INT(11) NOT NULL AUTO_INCREMENT, - `user_id` INT(11) NOT NULL, - `service_id` INT(11) NOT NULL, - `home_name` VARCHAR(255) NOT NULL, - `ip` VARCHAR(255) NOT NULL DEFAULT '', - `qty` INT(11) NOT NULL DEFAULT 1, - `invoice_duration` VARCHAR(16) NOT NULL DEFAULT 'month', - `max_players` INT(11) NOT NULL DEFAULT 0, - `price` FLOAT(15,2) NOT NULL DEFAULT 0, + `order_id` INT(11) NOT NULL AUTO_INCREMENT, + `user_id` INT(11) NOT NULL, + `service_id` INT(11) NOT NULL, + `home_name` VARCHAR(255) NOT NULL, + `ip` VARCHAR(255) NOT NULL DEFAULT '', + `qty` INT(11) NOT NULL DEFAULT 1, + `invoice_duration` VARCHAR(16) NOT NULL DEFAULT 'month', + `max_players` INT(11) NOT NULL DEFAULT 0, + `price` FLOAT(15,2) NOT NULL DEFAULT 0, `remote_control_password` VARCHAR(255) NULL, - `ftp_password` VARCHAR(255) NULL, - `home_id` VARCHAR(255) NOT NULL DEFAULT '0', - `status` VARCHAR(16) NOT NULL DEFAULT 'in-cart', - `order_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `end_date` DATETIME NULL, - `payment_txid` VARCHAR(255) NULL, - `paid_ts` DATETIME NULL, - `coupon_id` INT(11) NOT NULL DEFAULT 0, + `ftp_password` VARCHAR(255) NULL, + `home_id` VARCHAR(255) NOT NULL DEFAULT '0', + `status` VARCHAR(16) NOT NULL DEFAULT 'in-cart', + `order_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `end_date` DATETIME NULL, + `payment_txid` VARCHAR(255) NULL, + `paid_ts` DATETIME NULL, + `coupon_id` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`order_id`), KEY `user_id` (`user_id`), - KEY `status` (`status`), + KEY `status` (`status`), KEY `home_id` (`home_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;", - - // Billing Invoices - Created when user adds to cart, becomes order after payment + + // Billing Invoices — created on cart add, paid after payment capture "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_invoices` ( - `invoice_id` INT(11) NOT NULL AUTO_INCREMENT, - `order_id` INT(11) NOT NULL DEFAULT 0, - `user_id` INT(11) NOT NULL, - `service_id` INT(11) NOT NULL, - `home_name` VARCHAR(255) NOT NULL DEFAULT '', - `ip` INT(11) NOT NULL DEFAULT 0, - `max_players` INT(11) NOT NULL DEFAULT 0, - `remote_control_password` VARCHAR(255) NULL, - `ftp_password` VARCHAR(255) NULL, - `customer_name` VARCHAR(255) NOT NULL DEFAULT '', - `customer_email` VARCHAR(255) NOT NULL DEFAULT '', - `amount` FLOAT(15,2) NOT NULL DEFAULT 0, - `currency` VARCHAR(3) NOT NULL DEFAULT 'USD', - `status` VARCHAR(16) NOT NULL DEFAULT 'due', - `invoice_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `due_date` DATETIME NULL, - `paid_date` DATETIME NULL, - `payment_txid` VARCHAR(255) NULL, - `payment_method` VARCHAR(50) NULL, - `description` VARCHAR(500) NOT NULL DEFAULT '', - `invoice_duration` VARCHAR(16) NOT NULL DEFAULT 'month', - `qty` INT(11) NOT NULL DEFAULT 1, + `invoice_id` INT(11) NOT NULL AUTO_INCREMENT, + `order_id` INT(11) NOT NULL DEFAULT 0, + `user_id` INT(11) NOT NULL, + `service_id` INT(11) NOT NULL, + `home_id` INT(11) NOT NULL DEFAULT 0, + `home_name` VARCHAR(255) NOT NULL DEFAULT '', + `ip` INT(11) NOT NULL DEFAULT 0, + `max_players` INT(11) NOT NULL DEFAULT 0, + `remote_control_password` VARCHAR(255) NULL, + `ftp_password` VARCHAR(255) NULL, + `customer_name` VARCHAR(255) NOT NULL DEFAULT '', + `customer_email` VARCHAR(255) NOT NULL DEFAULT '', + `amount` FLOAT(15,2) NOT NULL DEFAULT 0, + `currency` VARCHAR(3) NOT NULL DEFAULT 'USD', + `status` VARCHAR(16) NOT NULL DEFAULT 'due', + `invoice_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `due_date` DATETIME NULL, + `paid_date` DATETIME NULL, + `payment_txid` VARCHAR(255) NULL, + `payment_method` VARCHAR(50) NULL, + `description` VARCHAR(500) NOT NULL DEFAULT '', + `invoice_duration` VARCHAR(16) NOT NULL DEFAULT 'month', + `rate_type` ENUM('daily','monthly','yearly') NOT NULL DEFAULT 'monthly', + `rate_per_player` DECIMAL(15,4) NOT NULL DEFAULT 0, + `players` INT(11) NOT NULL DEFAULT 0, + `period_start` DATETIME NULL, + `period_end` DATETIME NULL, + `subtotal` DECIMAL(15,2) NOT NULL DEFAULT 0, + `total_due` DECIMAL(15,2) NOT NULL DEFAULT 0, + `payment_status` ENUM('unpaid','paid','cancelled','refunded') NOT NULL DEFAULT 'unpaid', + `qty` INT(11) NOT NULL DEFAULT 1, PRIMARY KEY (`invoice_id`), - KEY `order_id` (`order_id`), - KEY `user_id` (`user_id`), - KEY `status` (`status`), - KEY `due_date` (`due_date`), + KEY `order_id` (`order_id`), + KEY `user_id` (`user_id`), + KEY `status` (`status`), + KEY `due_date` (`due_date`), KEY `service_id` (`service_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;" -); + ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;", -// Version 2: New columns on billing_invoices, transaction log table, service-to-node mapping -// Each ALTER TABLE is a separate statement because ADD COLUMN IF NOT EXISTS requires MySQL 8.0+. -// The module manager only runs these once (on db_version bump 1->2), so they do not need IF NOT EXISTS. -$install_queries[1] = array( - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `home_id` INT(11) NOT NULL DEFAULT 0 AFTER `service_id`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `rate_type` ENUM('daily','monthly','yearly') NOT NULL DEFAULT 'monthly' AFTER `invoice_duration`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `rate_per_player` DECIMAL(15,4) NOT NULL DEFAULT 0 AFTER `rate_type`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `players` INT(11) NOT NULL DEFAULT 0 AFTER `rate_per_player`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `period_start` DATETIME NULL AFTER `players`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `period_end` DATETIME NULL AFTER `period_start`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `subtotal` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `period_end`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `total_due` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `subtotal`", - "ALTER TABLE `".OGP_DB_PREFIX."billing_invoices` ADD COLUMN `payment_status` ENUM('unpaid','paid','cancelled','refunded') NOT NULL DEFAULT 'unpaid' AFTER `total_due`", - - // Payment transaction log — immutable audit trail + // Billing Transactions — immutable payment audit trail "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_transactions` ( - `transaction_id` INT(11) NOT NULL AUTO_INCREMENT, - `invoice_id` INT(11) NOT NULL DEFAULT 0, - `user_id` INT(11) NOT NULL DEFAULT 0, - `home_id` INT(11) NOT NULL DEFAULT 0, - `payment_method` VARCHAR(50) NOT NULL DEFAULT 'paypal', + `transaction_id` INT(11) NOT NULL AUTO_INCREMENT, + `invoice_id` INT(11) NOT NULL DEFAULT 0, + `user_id` INT(11) NOT NULL DEFAULT 0, + `home_id` INT(11) NOT NULL DEFAULT 0, + `payment_method` VARCHAR(50) NOT NULL DEFAULT 'paypal', `transaction_external_id` VARCHAR(255) NOT NULL DEFAULT '', `amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00, - `currency` VARCHAR(3) NOT NULL DEFAULT 'USD', + `currency` VARCHAR(3) NOT NULL DEFAULT 'USD', `status` ENUM('pending','completed','failed','refunded') NOT NULL DEFAULT 'pending', - `raw_response` MEDIUMTEXT NULL, - `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `raw_response` MEDIUMTEXT NULL, + `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`transaction_id`), - KEY `invoice_id` (`invoice_id`), - KEY `user_id` (`user_id`), - KEY `home_id` (`home_id`), - KEY `status` (`status`), + KEY `invoice_id` (`invoice_id`), + KEY `user_id` (`user_id`), + KEY `home_id` (`home_id`), + KEY `status` (`status`), KEY `payment_method` (`payment_method`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", - // Service-to-remote-server mapping (admin can enable/disable per service) - "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_service_remote_servers` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `service_id` INT(11) NOT NULL, - `remote_server_id` INT(11) NOT NULL, - `enabled` TINYINT(1) NOT NULL DEFAULT 1, - PRIMARY KEY (`id`), - UNIQUE KEY `svc_rs` (`service_id`, `remote_server_id`), - KEY `service_id` (`service_id`), - KEY `remote_server_id` (`remote_server_id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;" -); - -// Version 3 (array index 2, because install_queries is zero-indexed starting from version 1): -// Add override_price to service-to-server mapping table -$install_queries[2] = array( - "ALTER TABLE `".OGP_DB_PREFIX."billing_service_remote_servers` ADD COLUMN `override_price` DECIMAL(10,2) NULL AFTER `enabled`" -); - -// Version 4 (array index 3): Remove the separate service-to-server mapping table. -// remote_server_id on billing_services now stores a comma-separated list of server IDs. -// The mapping table is no longer used; drop it if it still exists from older installs. -$install_queries[3] = array( + // Drop legacy mapping table if it still exists from older installs "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."billing_service_remote_servers`" ); diff --git a/modules/billing/tools/check_db_user.php b/modules/billing/tools/check_db_user.php index d6fc3ea7..58b9f524 100644 --- a/modules/billing/tools/check_db_user.php +++ b/modules/billing/tools/check_db_user.php @@ -5,14 +5,15 @@ if (!$db) { echo "DB connect failed: " . mysqli_connect_error() . PHP_EOL; exit(1); } -$user = $argv[1] ?? 'iaregamer'; +$prefix = isset($table_prefix) ? $table_prefix : ''; +$user = $argv[1] ?? 'iaregamer'; $user_safe = mysqli_real_escape_string($db, $user); $has_shadow = false; -$res_cols = mysqli_query($db, "SHOW COLUMNS FROM ogp_users LIKE 'users_pass_hash'"); +$res_cols = mysqli_query($db, "SHOW COLUMNS FROM `{$prefix}users` LIKE 'users_pass_hash'"); if ($res_cols && mysqli_num_rows($res_cols) > 0) $has_shadow = true; $select_fields = 'user_id, users_login, users_passwd'; if ($has_shadow) $select_fields .= ", users_pass_hash"; -$q = "SELECT $select_fields FROM ogp_users WHERE users_login = '$user_safe' LIMIT 1"; +$q = "SELECT $select_fields FROM `{$prefix}users` WHERE users_login = '$user_safe' LIMIT 1"; $res = mysqli_query($db, $q); if (!$res) { echo "Query error: " . mysqli_error($db) . PHP_EOL; diff --git a/modules/fast_download/module.php b/modules/fast_download/module.php index a71da780..153088ff 100644 --- a/modules/fast_download/module.php +++ b/modules/fast_download/module.php @@ -25,28 +25,25 @@ // Module general information $module_title = "Fast Download"; $module_version = "2.1"; -$db_version = 4; +$db_version = 1; $module_required = TRUE; $module_menus = array( array( 'subpage' => '', 'name'=>'Fast Download', 'group'=>'admin' ) ); $module_access_rights = array('d' => 'allow_fast_download'); -$install_queries[0] = array("SELECT NOW();"); -$install_queries[1] = array("DROP TABLE IF EXISTS `".OGP_DB_PREFIX."fastdl`;"); -$install_queries[2] = array("SELECT NOW();"); -$install_queries[3] = array( - "CREATE TABLE ".OGP_DB_PREFIX."fastdl_access_rules ( - `home_cfg_id` varchar(32) NOT NULL, - `match_file_extension` TEXT, - `match_client_ip` TEXT, - UNIQUE KEY (`home_cfg_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); -$install_queries[4] = array( - "CREATE TABLE ".OGP_DB_PREFIX."fastdl_settings ( - `remote_server_id` int(11) NOT NULL, - `setting` varchar(63) NOT NULL, +$install_queries[0] = array( + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."fastdl_access_rules` ( + `home_cfg_id` varchar(32) NOT NULL, + `match_file_extension` TEXT, + `match_client_ip` TEXT, + UNIQUE KEY (`home_cfg_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."fastdl_settings` ( + `remote_server_id` int(11) NOT NULL, + `setting` varchar(63) NOT NULL, `value` varchar(255) NOT NULL, - UNIQUE KEY remote_server_id (remote_server_id,setting) - ) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); + UNIQUE KEY remote_server_id (remote_server_id,setting) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;" +); $uninstall_queries = array("DROP TABLE IF EXISTS `".OGP_DB_PREFIX."fastdl_access_rules`;", "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."fastdl_settings`;"); ?> diff --git a/modules/gamemanager/module.php b/modules/gamemanager/module.php index 376a43b0..25a7bad7 100644 --- a/modules/gamemanager/module.php +++ b/modules/gamemanager/module.php @@ -25,96 +25,66 @@ // Module general information $module_title = "Game manager"; $module_version = "1.33"; -$db_version = 9; +$db_version = 1; $module_required = TRUE; $module_menus = array( array( 'subpage' => 'game_monitor', 'name'=>'Game Monitor', 'group'=>'user' ) ); $module_access_rights = array('u' => 'allow_updates', 'p' => 'allow_parameter_usage', 'e' => 'allow_extra_params', 'c' => 'allow_custom_fields'); $install_queries[0] = array( - "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."home_ip_ports`;", "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."home_ip_ports` ( - `ip_id` int(11) NOT NULL, - `port` int(11) NOT NULL, - `home_id` int(11) NOT NULL, - PRIMARY KEY (`ip_id`,`port`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1;", + `ip_id` int(11) NOT NULL, + `port` int(11) NOT NULL, + `home_id` int(11) NOT NULL, + `force_mod_id` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`ip_id`,`port`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;", -"DROP TABLE IF EXISTS ".OGP_DB_PREFIX."server_homes", -"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."server_homes` ( - `home_id` int(50) NOT NULL auto_increment, - `remote_server_id` int(11) NOT NULL, - `user_id_main` int(11) NOT NULL, - `home_path` varchar(500) NOT NULL, - `home_cfg_id` int(50) NOT NULL, - `home_name` varchar(500) NOT NULL, - `control_password` VARCHAR( 128 ) NULL, - `ftp_password` VARCHAR( 128 ) NULL, - `last_param` LONGTEXT NULL, - PRIMARY KEY (`home_id`), -UNIQUE KEY remote_server_id (remote_server_id,home_path) -) ENGINE=MyISAM DEFAULT CHARSET=latin1;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."server_homes` ( + `home_id` int(50) NOT NULL auto_increment, + `remote_server_id` int(11) NOT NULL, + `user_id_main` int(11) NOT NULL, + `home_path` varchar(500) NOT NULL, + `home_cfg_id` int(50) NOT NULL, + `home_name` varchar(500) NOT NULL, + `control_password` VARCHAR(128) NULL, + `ftp_password` VARCHAR(128) NULL, + `ftp_login` varchar(32) NULL, + `ftp_status` int(11) NOT NULL DEFAULT '0', + `last_param` LONGTEXT NULL, + `custom_fields` LONGTEXT NULL, + `server_expiration_date` VARCHAR(21) NOT NULL DEFAULT 'X', + `home_user_order` INT NOT NULL DEFAULT 99999, + PRIMARY KEY (`home_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;", -"DROP TABLE IF EXISTS ".OGP_DB_PREFIX."rcon_presets;", -"CREATE TABLE ".OGP_DB_PREFIX."rcon_presets ( - `preset_id` int(50) NOT NULL auto_increment, - `name` varchar(20) NOT NULL, - `command` varchar(100) NOT NULL, - `home_cfg_id` int(50) NOT NULL, - `mod_cfg_id` int(50) NOT NULL, - PRIMARY KEY (`preset_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."rcon_presets` ( + `preset_id` int(50) NOT NULL auto_increment, + `name` varchar(20) NOT NULL, + `command` varchar(100) NOT NULL, + `home_cfg_id` int(50) NOT NULL, + `mod_cfg_id` int(50) NOT NULL, + PRIMARY KEY (`preset_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;", -"DROP TABLE IF EXISTS ".OGP_DB_PREFIX."game_mods", -"CREATE TABLE IF NOT EXISTS ".OGP_DB_PREFIX."game_mods ( - `mod_id` int(50) NOT NULL auto_increment, - `home_id` int(255) NOT NULL, - `mod_cfg_id` int(11) NOT NULL, - `max_players` smallint(3) default NULL, - `extra_params` varchar(255) default NULL, - `cpu_affinity` varchar(2) default NULL, - `nice` smallint(3) default '0', - `precmd` TEXT, - `postcmd` TEXT, - PRIMARY KEY (mod_id), -UNIQUE KEY home_id (home_id,mod_cfg_id) - ) ENGINE=MyISAM;"); - -$install_queries[1] = array( - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` ADD `ftp_login` varchar(32) NULL;", - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` ADD `ftp_status` int(11) NOT NULL DEFAULT '0';"); - -$install_queries[2] = array( -"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."status_cache`", -"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."status_cache` ( - `date_timestamp` char(16) NOT NULL, - `ip_id` char(3) NOT NULL, - `port` char(6) NOT NULL, - `server_status_cache` longtext NOT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1;"); + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."game_mods` ( + `mod_id` int(50) NOT NULL auto_increment, + `home_id` int(255) NOT NULL, + `mod_cfg_id` int(11) NOT NULL, + `max_players` smallint(3) DEFAULT NULL, + `extra_params` varchar(255) DEFAULT NULL, + `cpu_affinity` varchar(2) DEFAULT NULL, + `nice` smallint(3) DEFAULT '0', + `precmd` TEXT, + `postcmd` TEXT, + PRIMARY KEY (mod_id), + UNIQUE KEY home_id (home_id,mod_cfg_id) + ) ENGINE=MyISAM;", -$install_queries[3] = array( - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` ADD `custom_fields` LONGTEXT NULL;"); - -$install_queries[4] = array( - "ALTER TABLE `".OGP_DB_PREFIX."home_ip_ports` ADD `force_mod_id` int(11) NOT NULL DEFAULT '0';"); - -$install_queries[5] = array( - "TRUNCATE `".OGP_DB_PREFIX."status_cache`;"); - -$install_queries[6] = array( - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` ADD `server_expiration_date` VARCHAR(21) NOT NULL default 'X';"); - -$install_queries[7] = array( - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` drop index `remote_server_id`;" - ); - -$install_queries[8] = array( - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` ADD `home_user_order` INT NOT NULL default 99999;"); - -// Increase default column sizes -$install_queries[9] = array( - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` MODIFY COLUMN `home_path` VARCHAR(500);", - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` MODIFY COLUMN `home_name` VARCHAR(500);", - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` MODIFY COLUMN `control_password` VARCHAR(128);", - "ALTER TABLE `".OGP_DB_PREFIX."server_homes` MODIFY COLUMN `ftp_password` VARCHAR(128);"); -?> + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."status_cache` ( + `date_timestamp` char(16) NOT NULL, + `ip_id` char(3) NOT NULL, + `port` char(6) NOT NULL, + `server_status_cache` longtext NOT NULL + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;" +); +?> \ No newline at end of file diff --git a/modules/modulemanager/module.php b/modules/modulemanager/module.php index e738ae00..e2ab9ac7 100644 --- a/modules/modulemanager/module.php +++ b/modules/modulemanager/module.php @@ -25,21 +25,18 @@ // Module general information $module_title = "Module manager"; $module_version = "1.1"; -$db_version = 2; +$db_version = 1; $module_required = TRUE; $module_menus = array( - array( 'subpage' => '', 'name'=>'Modules', 'group'=>'admin' ) - ); - -## You will need uncomment the next three lines (remove /* from the beginning and */ from the end) -## of the next array if you are updating from a version previous or equal to 2429: -$install_queries[0] = array(); -$install_queries[1] = array(); -$install_queries[2] = array("DROP TABLE IF EXISTS ".OGP_DB_PREFIX."module_access_rights", - "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."module_access_rights` (". - "`module_id` int(11) NOT NULL COMMENT 'This references to modules.id',". - "`flag` char(1) NOT NULL,". - "`description` varchar(64) NOT NULL,". - "UNIQUE (`flag`)". - ") ENGINE=MyISAM DEFAULT CHARSET=latin1;"); -?> +array( 'subpage' => '', 'name'=>'Modules', 'group'=>'admin' ) +); + +$install_queries[0] = array( + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."module_access_rights` (". + "`module_id` int(11) NOT NULL COMMENT 'This references to modules.id',". + "`flag` char(1) NOT NULL,". + "`description` varchar(64) NOT NULL,". + "UNIQUE (`flag`)". + ") ENGINE=MyISAM DEFAULT CHARSET=latin1;" +); +?> \ No newline at end of file diff --git a/modules/server/module.php b/modules/server/module.php index feb785b5..8b56e570 100644 --- a/modules/server/module.php +++ b/modules/server/module.php @@ -25,70 +25,47 @@ // Module general information $module_title = "Server manager"; $module_version = "1.6.1"; -$db_version = 7; +$db_version = 1; $module_required = TRUE; $module_menus = array( - array( 'subpage' => '', 'name'=>'Servers', 'group'=>'admin' ) - ); +array( 'subpage' => '', 'name'=>'Servers', 'group'=>'admin' ) +); $install_queries = array(); $install_queries[0] = array( -"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."remote_server_ips`;", -"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."remote_server_ips` ( - `ip_id` int(11) NOT NULL AUTO_INCREMENT, - `remote_server_id` int(11) NOT NULL, - `ip` varchar(255) NOT NULL, - PRIMARY KEY (`ip_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1;", -"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."remote_servers`;", -"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."remote_servers` ( - `remote_server_id` int(11) NOT NULL auto_increment, - `remote_server_name` varchar(100) NOT NULL, - `ogp_user` varchar(100) NOT NULL, - `agent_ip` varchar(255) NOT NULL, - `agent_port` int(11) NOT NULL, - `ftp_port` int(11) NOT NULL, - `encryption_key` varchar(50) NOT NULL, - `timeout` int(11) NOT NULL, - PRIMARY KEY (`remote_server_id`), - UNIQUE KEY `agent_ip` (`agent_ip`,`agent_port`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Remote servers and IPs';"); + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."remote_server_ips` ( + `ip_id` int(11) NOT NULL AUTO_INCREMENT, + `remote_server_id` int(11) NOT NULL, + `ip` varchar(255) NOT NULL, + PRIMARY KEY (`ip_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1;", -$install_queries[1] = array( - "ALTER TABLE `".OGP_DB_PREFIX."remote_servers` - ADD `use_nat` int(11) NOT NULL;"); -$install_queries[2] = array( - "ALTER TABLE `OGP_DB_PREFIXremote_servers` - ADD `ufw_status` CHAR(8);"); -$install_queries[3] = array( - "ALTER TABLE `OGP_DB_PREFIXremote_servers` - ADD `ftp_ip` varchar(255) NOT NULL;"); - -$install_queries[4] = array( -"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."arrange_ports`;", -"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."arrange_ports` ( - `range_id` int(11) NOT NULL auto_increment, - `ip_id` int(11) NOT NULL, - `home_cfg_id` int(11) NOT NULL, - `start_port` smallint(11) unsigned NOT NULL, - `end_port` smallint(11) unsigned NOT NULL, - `port_increment` smallint(11) unsigned NOT NULL, - PRIMARY KEY (`range_id`), - UNIQUE KEY `ip_id` (`ip_id`,`home_cfg_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Remote servers and IPs';"); + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."remote_servers` ( + `remote_server_id` int(11) NOT NULL auto_increment, + `remote_server_name` varchar(100) NOT NULL, + `ogp_user` varchar(100) NOT NULL, + `agent_ip` varchar(255) NOT NULL, + `agent_port` int(11) NOT NULL, + `ftp_port` int(11) NOT NULL, + `encryption_key` varchar(50) NOT NULL, + `timeout` int(11) NOT NULL, + `use_nat` int(11) NOT NULL DEFAULT 0, + `ftp_ip` varchar(255) NOT NULL DEFAULT '', + `firewall_settings` LONGTEXT NULL, + `display_public_ip` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY (`remote_server_id`), + UNIQUE KEY `agent_ip` (`agent_ip`,`agent_port`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Remote servers and IPs';", -$install_queries[5] = array( - "ALTER TABLE `OGP_DB_PREFIXremote_servers` - DROP COLUMN `ufw_status`;", - "ALTER TABLE `OGP_DB_PREFIXremote_servers` - ADD `firewall_settings` LONGTEXT NULL;"); - -$install_queries[6] = array( - "ALTER TABLE `OGP_DB_PREFIXremote_servers` - ADD `display_public_ip` varchar(15) NOT NULL;"); - -$install_queries[7] = array( - "ALTER TABLE `OGP_DB_PREFIXremote_servers` - MODIFY `display_public_ip` varchar(255) NOT NULL;"); - -?> + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."arrange_ports` ( + `range_id` int(11) NOT NULL auto_increment, + `ip_id` int(11) NOT NULL, + `home_cfg_id` int(11) NOT NULL, + `start_port` smallint(11) unsigned NOT NULL, + `end_port` smallint(11) unsigned NOT NULL, + `port_increment` smallint(11) unsigned NOT NULL, + PRIMARY KEY (`range_id`), + UNIQUE KEY `ip_id` (`ip_id`,`home_cfg_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Remote servers and IPs';" +); +?> \ No newline at end of file