From the panel site

This commit is contained in:
Frank Harris 2025-09-17 21:14:45 -04:00
parent d684ca74fb
commit 2fc04bcfac
1194 changed files with 154606 additions and 13040 deletions

View file

@ -2,129 +2,6 @@
require_once("includes/lib_remote.php");
require_once("modules/config_games/server_config_parser.php");
function createMysqlDatabase($home_id, $settings, $db) {
// Generate database name and user based on server ID
$dbID = "server_" . $home_id;
$dbPass = substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0, 12);
// Check if MySQL auto-creation is enabled
if (!isset($settings['mysql_auto_create']) || $settings['mysql_auto_create'] != '1') {
return false;
}
// Check if we have the required MySQL settings
if (empty($settings['mysql_root_user']) || empty($settings['mysql_root_password']) || empty($settings['mysql_host'])) {
return false;
}
$mysql_host = $settings['mysql_host'];
$mysql_user = $settings['mysql_root_user'];
$mysql_pass = $settings['mysql_root_password'];
$mysql_port = isset($settings['mysql_port']) ? $settings['mysql_port'] : '3306';
try {
// Create MySQL connection
if (function_exists('mysqli_connect')) {
$link = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, "", $mysql_port);
if (!$link) {
$db->logger("MYSQL DB CREATION FAILED - Could not connect to MySQL server for server " . $home_id);
return false;
}
// Create database
$query = "CREATE DATABASE IF NOT EXISTS `" . mysqli_real_escape_string($link, $dbID) . "`";
mysqli_query($link, $query);
// Grant privileges to database user locally
$query = "GRANT ALL ON `" . mysqli_real_escape_string($link, $dbID) . "`.* TO '" . mysqli_real_escape_string($link, $dbID) . "'@'localhost' IDENTIFIED BY '" . mysqli_real_escape_string($link, $dbPass) . "'";
mysqli_query($link, $query);
// Grant privileges to database user remotely
$query = "GRANT ALL ON `" . mysqli_real_escape_string($link, $dbID) . "`.* TO '" . mysqli_real_escape_string($link, $dbID) . "'@'%' IDENTIFIED BY '" . mysqli_real_escape_string($link, $dbPass) . "'";
mysqli_query($link, $query);
// If there's a special user defined, grant it access too (like dayzhivemind in the original script)
if (!empty($settings['mysql_special_user']) && !empty($settings['mysql_special_password'])) {
$query = "GRANT ALL ON `" . mysqli_real_escape_string($link, $dbID) . "`.* TO '" . mysqli_real_escape_string($link, $settings['mysql_special_user']) . "'@'%' IDENTIFIED BY '" . mysqli_real_escape_string($link, $settings['mysql_special_password']) . "'";
mysqli_query($link, $query);
}
// Flush privileges
mysqli_query($link, "FLUSH PRIVILEGES");
// Import SQL file if specified
if (!empty($settings['mysql_init_sql_file'])) {
$sql_file = $settings['mysql_init_sql_file'];
if (file_exists($sql_file)) {
$sql_content = file_get_contents($sql_file);
mysqli_select_db($link, $dbID);
mysqli_multi_query($link, $sql_content);
}
}
mysqli_close($link);
} else {
// Fallback to old mysql functions
$link = mysql_connect($mysql_host . ':' . $mysql_port, $mysql_user, $mysql_pass);
if (!$link) {
$db->logger("MYSQL DB CREATION FAILED - Could not connect to MySQL server for server " . $home_id);
return false;
}
// Create database
$query = "CREATE DATABASE IF NOT EXISTS `" . mysql_real_escape_string($dbID, $link) . "`";
mysql_query($query, $link);
// Grant privileges
$query = "GRANT ALL ON `" . mysql_real_escape_string($dbID, $link) . "`.* TO '" . mysql_real_escape_string($dbID, $link) . "'@'localhost' IDENTIFIED BY '" . mysql_real_escape_string($dbPass, $link) . "'";
mysql_query($query, $link);
$query = "GRANT ALL ON `" . mysql_real_escape_string($dbID, $link) . "`.* TO '" . mysql_real_escape_string($dbID, $link) . "'@'%' IDENTIFIED BY '" . mysql_real_escape_string($dbPass, $link) . "'";
mysql_query($query, $link);
if (!empty($settings['mysql_special_user']) && !empty($settings['mysql_special_password'])) {
$query = "GRANT ALL ON `" . mysql_real_escape_string($dbID, $link) . "`.* TO '" . mysql_real_escape_string($settings['mysql_special_user'], $link) . "'@'%' IDENTIFIED BY '" . mysql_real_escape_string($settings['mysql_special_password'], $link) . "'";
mysql_query($query, $link);
}
mysql_query("FLUSH PRIVILEGES", $link);
if (!empty($settings['mysql_init_sql_file'])) {
$sql_file = $settings['mysql_init_sql_file'];
if (file_exists($sql_file)) {
$sql_content = file_get_contents($sql_file);
mysql_select_db($dbID, $link);
mysql_query($sql_content, $link);
}
}
mysql_close($link);
}
// Add database to OGP tracking if mysql_server_id is configured
if (!empty($settings['mysql_default_server_id'])) {
// Try to add to the mysql_databases table directly using the main db connection
$db->query("DELETE FROM OGP_DB_PREFIXmysql_databases WHERE db_user = '" . $db->realEscapeSingle($dbID) . "'");
// Insert new database record directly
$query = "INSERT INTO OGP_DB_PREFIXmysql_databases (mysql_server_id, home_id, db_user, db_passwd, db_name, enabled) VALUES (" .
$db->realEscapeSingle($settings['mysql_default_server_id']) . ", " .
$db->realEscapeSingle($home_id) . ", '" .
$db->realEscapeSingle($dbID) . "', '" .
$db->realEscapeSingle($dbPass) . "', '" .
$db->realEscapeSingle($dbID) . "', 1)";
$db->query($query);
}
$db->logger("MYSQL DB CREATED - Database " . $dbID . " created for server " . $home_id);
return true;
} catch (Exception $e) {
$db->logger("MYSQL DB CREATION FAILED - Error creating database for server " . $home_id . ": " . $e->getMessage());
return false;
}
}
function exec_ogp_module()
{
global $db,$view,$settings;
@ -364,13 +241,6 @@ function exec_ogp_module()
echo "<h4><br><p>".get_lang('starting_installations')."</p></h4><br>";
//PANEL LOG
$db->logger( "CREATED NEW SERVER " . $home_id);
// CREATE MYSQL DATABASE FOR NEW SERVERS
if($order['finish_date'] == 0){
$settings = $db->getSettings();
createMysqlDatabase($home_id, $settings, $db);
}
// SEND EMAIL to new server only
if($order['finish_date'] == 0){
$settings = $db->getSettings();

View file

@ -0,0 +1,217 @@
<?php
/*
*
* OGP - Open Game Panel
* Copyright (C) 2008 - 2017 The OGP Development Team
*
* http://www.opengamepanel.org/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
chdir(realpath(dirname(__FILE__))); /* Change to the current file path */
chdir("../.."); /* Base path to ogp web files */
// Report all PHP errors
error_reporting(E_ALL);
// Path definitions
define("CONFIG_FILE","includes/config.inc.php");
//Requiere
require_once("includes/functions.php");
require_once("includes/helpers.php");
require_once("includes/html_functions.php");
require_once("modules/config_games/server_config_parser.php");
require_once("includes/lib_remote.php");
require_once CONFIG_FILE;
// Connect to the database server and select database.
$db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
$panel_settings = $db->getSettings();
if( isset($panel_settings['time_zone']) && $panel_settings['time_zone'] != "" )
date_default_timezone_set($panel_settings['time_zone']);
//these dates are configured in the Shop Settings page
$today=time();
$invoice_date = strtotime('+ 7 days'); //this many days until the finish_date
$suspend_date = $today; //suspend when overdue
//final date is 10th, we need to remove on 17th, so final date is > removal_date
$removal_date = strtotime('- 7 days'); //finish_date is passed 7 days ago
$rundate = date('d/M/y G:i',$today);
//THESE SERVERS HAVE REACHED THE DATE FOR INVOICE, FINISH_DATE - 7 (OR WHAT IS IN SETTINGS)
//SET STATUS -1 MEANING INVOICED
//LOOP THROUGH ALL SERVERS WITH STATUS = 1 (ACTIVE) -----------------------------------------------------------
$user_homes = $db->resultQuery( "SELECT *
FROM " . $table_prefix . "billing_orders
WHERE status > 0 AND finish_date <" . $invoice_date);
if (!is_array($user_homes))
{
}
else
{
foreach($user_homes as $user_home)
{
$user_id = $user_home['user_id'];
$home_id = $user_home['home_id'];
// Reset the STATUS -1 so cart.php will create an invoice
$db->query( "UPDATE " . $table_prefix . "billing_orders
SET status=-1
WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
// SEND EMAIL
$settings = $db->getSettings();
$subject = "You have an INVOICE at ". $panel_settings['panel_name'];
$email = $db->resultQuery(" SELECT DISTINCT users_email
FROM " . $table_prefix . "users, " . $table_prefix . "billing_orders
WHERE " . $table_prefix . "users.user_id = $user_id")[0]["users_email"];
$message = "Your server with ID ". $home_id . " will expire soon. Please log in and VIEW INVOICES on the Dashboard to renew your server.<br><br><br>~<br>Thanks!<br>";
$mail = mymail($email, $subject, $message, $settings);
//logger
$db->logger( "INVOICE created for server " . $home_id);
if (!$mail)
$db->logger( "Email FAILED - Server Invoiced " . $home_id);
// END EMAIL
}
}
//THESE ARE THE SERVERS THAT HAVE NOT BEEN PAID AND THE FINISH_DATE IS TODAY
//THESE SERVERS GET SUSPENDED
//LOOP THROUGH ALL ORDERS WITH STATUS 0 OR -1 (INACTIVE OR INVOICED)
$user_homes = $db->resultQuery( "SELECT *
FROM " . $table_prefix . "billing_orders
WHERE (status = -1 OR status = 0) AND finish_date < ".$today);
if (!is_array($user_homes))
{
}
else
{
foreach($user_homes as $user_home)
{
$user_id = $user_home['user_id'];
$home_id = $user_home['home_id'];
$home_info = $db->getGameHomeWithoutMods($home_id);
$server_info = $db->getRemoteServerById($home_info['remote_server_id']);
$remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'],$server_info['timeout']);
$ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
$remote->ftp_mgr("userdel", $ftp_login);
$db->changeFtpStatus('disabled',$home_id);
$server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = "";
$addresses = $db->getHomeIpPorts($home_id);
foreach($addresses as $address)
{
$remote->remote_stop_server($home_id,$address['ip'],$address['port'],$server_xml->control_protocol,$home_info['control_password'],$control_type,$home_info['home_path']);
}
$db->unassignHomeFrom("user", $user_id, $home_id);
// Reset the invoice end date to -2
// User can still RENEW server
$db->query( "UPDATE " . $table_prefix . "billing_orders
SET status=-2
WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
//logger
$db->logger( "SUSPENDED server " . $home_id);
// SEND EMAIL
$settings = $db->getSettings();
$subject = "GameServer Suspended at ". $panel_settings['panel_name'];
$email = $db->resultQuery(" SELECT DISTINCT users_email
FROM " . $table_prefix . "users, " . $table_prefix . "billing_orders
WHERE " . $table_prefix . "users.user_id = $user_id")[0]["users_email"];
$message = "Your server with ID ". $home_id . " has expired and has been suspended. Please log in and VIEW INVOICES on the Dashboard to renew your server.<br>~<br>Thanks!<br>";
$mail = mymail($email, $subject, $message, $settings);
if (!$mail)
$db->logger( "Email FAILED - Server Suspended " . $home_id);
// END EMAIL
}
}
// end date = -2 (suspended) and its been suspended for $removal_date days
//set removed servers as -99
$user_homes = $db->resultQuery( "SELECT *
FROM " . $table_prefix . "billing_orders
WHERE status = -2 AND finish_date < ".$removal_date );
if (!is_array($user_homes))
{
}
else
{
foreach($user_homes as $user_home)
{
$user_id = $user_home['user_id'];
$home_id = $user_home['home_id'];
$home_info = $db->getGameHomeWithoutMods($home_id);
$server_info = $db->getRemoteServerById($home_info['remote_server_id']);
$remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'],$server_info['timeout']);
// Remove the game home from db
$db->deleteGameHome($home_id);
// Remove the game home files from remote server
$remote->remove_home($home_info['home_path']);
// Reset the invoice end date
$db->query( "UPDATE " . $table_prefix . "billing_orders
SET status=-3
WHERE order_id=".$db->realEscapeSingle($user_home['order_id']));
// Set order as not installed
$db->query( "UPDATE " . $table_prefix . "billing_orders
SET home_id=0
WHERE cart_id=".$db->realEscapeSingle($user_home['cart_id']));
//logger
$db->logger( "DELETED server " . $home_id);
// SEND EMAIL
$settings = $db->getSettings();
$settings = $db->getSettings();
$subject = "GameServer DELETED at ". $panel_settings['panel_name'];
$email = $db->resultQuery(" SELECT DISTINCT users_email
FROM " . $table_prefix . "users, " . $table_prefix . "billing_orders
WHERE " . $table_prefix . "users.user_id = $user_id")[0]["users_email"];
$message = "Your server with ID ". $home_id . " has been deleted<br><br>You did not renew the service and it was PERMANENTLY REMOVED today. If this was an error, if you contact us immediately we may be able to restore your server.<br>Thanks for being a customer and we hope we can provide a server for you again.<br><br>";
$mail = mymail($email, $subject, $message, $settings);
if (!$mail)
$db->logger( "Email FAILED - Server Deleted " . $home_id);
// END EMAIL
}
}
?>

View file

@ -24,8 +24,8 @@
// Module general information
$module_title = "billing";
$module_version = "1.0";
$db_version = 0;
$module_version = "1";
$db_version = 4;
$module_required = FALSE;
$module_menus = array(
array( 'subpage' => 'orders', 'name'=>'Orders', 'group'=>'user,admin' ),
@ -34,4 +34,103 @@ $module_menus = array(
array( 'subpage' => 'coupons', 'name'=>'Coupons', 'group'=>'admin' )
);
$install_queries = array();
$install_queries[0] = array(
"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."billing_services`;",
"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,
`mod_cfg_id` int(11) NOT NULL,
`service_name` varchar(255) NOT NULL,
`remote_server_id` varchar(255) NOT NULL,
`slot_max_qty` int(11) NOT NULL,
`slot_min_qty` int(11) NOT NULL,
`price_daily` float(15,4) NOT NULL,
`price_monthly` float(15,4) NOT NULL,
`price_year` float(15,4) NOT NULL,
`description` varchar(1000) NOT NULL,
`img_url` varchar(255) NOT NULL,
`ftp` varchar(255) NOT NULL,
`install_method` varchar(255) NOT NULL,
`manual_url` varchar(255) NOT NULL,
`access_rights` varchar(255) NOT NULL,
PRIMARY KEY (`service_id`)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8;",
"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."billing_orders`;",
"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_path` varchar(255) NOT NULL,
`home_name` varchar(255) NOT NULL,
`ip` varchar(255) NOT NULL,
`port` varchar(5) NOT NULL,
`qty` int(11) NOT NULL,
`invoice_duration` varchar(16) NOT NULL,
`max_players` int(11) NOT NULL,
`remote_control_password` varchar(10) NULL,
`ftp_password` varchar(10) NULL,
`subtotal` float(15,2) NOT NULL,
`rate` int(11) NOT NULL,
`total` float(15,2) NOT NULL,
`date` varchar(10) NULL,
PRIMARY KEY (`order_id`)
) ENGINE=MyISAM;"
);
$install_queries[1] = array(
"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."billing_carts`;",
"CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."billing_carts` (
`cart_id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`paid` int(11) NULL,
PRIMARY KEY (`cart_id`)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8;",
"DROP TABLE IF EXISTS `".OGP_DB_PREFIX."billing_orders`;",
"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_path` varchar(255) NOT NULL,
`home_name` varchar(255) NOT NULL,
`ip` varchar(255) NOT NULL,
`qty` int(11) NOT NULL,
`invoice_duration` varchar(16) NOT NULL,
`max_players` int(11) NOT NULL,
`price` float(15,2) NOT NULL,
`remote_control_password` varchar(10) NULL,
`ftp_password` varchar(10) NULL,
`paid` varchar(1) NULL,
`date` varchar(10) NULL,
`cart_id` int(11) NOT NULL,
PRIMARY KEY (`order_id`)
) ENGINE=MyISAM;"
);
$install_queries[2] = array(
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` DROP `date`;",
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` DROP `home_path`;",
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` DROP `paid`;",
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` ADD `home_id` varchar(255) NOT NULL DEFAULT '0';",
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` ADD `status` varchar(16) NOT NULL DEFAULT '0';",
"ALTER TABLE `".OGP_DB_PREFIX."billing_carts` ADD `date` varchar(16) NOT NULL DEFAULT '0';",
"ALTER TABLE `".OGP_DB_PREFIX."billing_carts` ADD `tax_amount` varchar(16) NOT NULL DEFAULT '0';",
"ALTER TABLE `".OGP_DB_PREFIX."billing_carts` ADD `currency` varchar(3) NOT NULL DEFAULT '0';"
);
$install_queries[3] = array(
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` ADD `finish_date` varchar(16) NOT NULL DEFAULT '0';"
);
$install_queries[4] = array(
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` ADD `extended` tinyint(1) NOT NULL;",
"ALTER TABLE `".OGP_DB_PREFIX."billing_services` ADD `enabled` int(11) NOT NULL;"
"ALTER TABLE `".OGP_DB_PREFIX."billing_carts` ADD `coupon_id` varchar(3) NOT NULL DEFAULT '0';"
"ALTER TABLE `".OGP_DB_PREFIX."billing_orders` ADD `coupon_id` varchar(3) NOT NULL DEFAULT '0';"
);
?>