Website is completed working, moved into billing module
This commit is contained in:
parent
3ea6436f27
commit
437fbad5e6
401 changed files with 1822 additions and 7831 deletions
28
modules/billing/includes/README.md
Normal file
28
modules/billing/includes/README.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Website Includes Directory
|
||||
|
||||
This directory contains configuration and shared files for the standalone _website folder.
|
||||
|
||||
## config.inc.php
|
||||
|
||||
Central database configuration file for the website. This file contains the database connection settings that are used by all website PHP files through the `db.php` file.
|
||||
|
||||
**Important:** The values in this file should match the panel's database configuration in `/includes/config.inc.php` to ensure the website can access the same database as the panel.
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
- `$db_host` - Database server hostname
|
||||
- `$db_user` - Database username
|
||||
- `$db_pass` - Database password
|
||||
- `$db_name` - Database name
|
||||
- `$table_prefix` - Table prefix (default: "ogp_")
|
||||
- `$db_type` - Database type (default: "mysql")
|
||||
|
||||
### Usage
|
||||
|
||||
The website files include `db.php`, which in turn loads this configuration file:
|
||||
|
||||
```php
|
||||
require_once('db.php'); // db.php loads includes/config.inc.php
|
||||
```
|
||||
|
||||
This centralizes database credentials in one place, making the website easier to configure and maintain as a standalone site.
|
||||
60
modules/billing/includes/admin_auth.php
Normal file
60
modules/billing/includes/admin_auth.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
// Admin authorization include — include early (before output) on admin pages
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_name("gameservers_website");
|
||||
session_start();
|
||||
}
|
||||
|
||||
// If not logged in, redirect to login
|
||||
if (empty($_SESSION['website_user_id'])) {
|
||||
// Build absolute login URL to avoid browser-relative resolution issues
|
||||
$script = $_SERVER['SCRIPT_NAME'] ?? '';
|
||||
$siteRoot = '/';
|
||||
$pos = strpos($script, '/_website');
|
||||
if ($pos !== false) {
|
||||
$siteRoot = substr($script, 0, $pos + strlen('/_website'));
|
||||
} else {
|
||||
$siteRoot = rtrim(dirname($script), '/\\');
|
||||
}
|
||||
$loginUrl = $siteRoot . '/login.php';
|
||||
$returnTo = $siteRoot . '/' . basename($_SERVER['PHP_SELF']);
|
||||
header('Location: ' . $loginUrl . '?return_to=' . urlencode($returnTo));
|
||||
exit();
|
||||
}
|
||||
|
||||
// Require DB config and check role live from panel DB
|
||||
|
||||
require_once(__DIR__ . '/config.inc.php');
|
||||
// Use a local connection variable so we don't clash with pages that also use $db
|
||||
$auth_db = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||
if (!$auth_db) {
|
||||
// If DB unavailable, deny access gracefully
|
||||
// Redirect to absolute login URL
|
||||
$script = $_SERVER['SCRIPT_NAME'] ?? '';
|
||||
$pos = strpos($script, '/_website');
|
||||
$siteRoot = $pos !== false ? substr($script, 0, $pos + strlen('/_website')) : rtrim(dirname($script), '/\\');
|
||||
header('Location: ' . $siteRoot . '/login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$uid = intval($_SESSION['website_user_id']);
|
||||
$role = '';
|
||||
$res = mysqli_query($auth_db, "SELECT users_role FROM ogp_users WHERE user_id = $uid LIMIT 1");
|
||||
if ($res && mysqli_num_rows($res) === 1) {
|
||||
$row = mysqli_fetch_assoc($res);
|
||||
$role = (string)($row['users_role'] ?? '');
|
||||
}
|
||||
mysqli_close($auth_db);
|
||||
|
||||
if (strtolower($role) !== 'admin') {
|
||||
// Not an admin — redirect to login or home
|
||||
// Redirect to absolute login URL
|
||||
$script = $_SERVER['SCRIPT_NAME'] ?? '';
|
||||
$pos = strpos($script, '/_website');
|
||||
$siteRoot = $pos !== false ? substr($script, 0, $pos + strlen('/_website')) : rtrim(dirname($script), '/\\');
|
||||
header('Location: ' . $siteRoot . '/login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// If we reach here, user is an admin
|
||||
?>
|
||||
22
modules/billing/includes/cart_helper.php
Normal file
22
modules/billing/includes/cart_helper.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
// Helper to read cart items stored in session and return count
|
||||
// Non-invasive: reads $_SESSION['cart'] if present and returns total quantity or items count
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
@session_start();
|
||||
}
|
||||
|
||||
function get_cart_count() {
|
||||
if (!isset($_SESSION['cart']) || !is_array($_SESSION['cart'])) {
|
||||
return 0;
|
||||
}
|
||||
$count = 0;
|
||||
foreach ($_SESSION['cart'] as $item) {
|
||||
if (is_array($item) && isset($item['quantity'])) {
|
||||
$count += (int) $item['quantity'];
|
||||
} else {
|
||||
$count += 1;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
32
modules/billing/includes/config.inc.php
Normal file
32
modules/billing/includes/config.inc.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
###############################################
|
||||
# Website Database Configuration
|
||||
# This file contains the database connection
|
||||
# settings for the _website standalone site.
|
||||
#
|
||||
# These settings should match the panel's
|
||||
# database configuration in includes/config.inc.php
|
||||
###############################################
|
||||
$db_host="localhost";
|
||||
$db_user="localuser";
|
||||
$db_pass="Pkloyn7yvpht!";
|
||||
$db_name="panel";
|
||||
$table_prefix="ogp_";
|
||||
$db_type="mysql";
|
||||
// Optional: base URL used by admin pages to build absolute image previews.
|
||||
// Leave empty to prefer relative paths (local folder).
|
||||
// To enable production base URL, uncomment and set it to your site, e.g.:
|
||||
// $SITE_BASE_URL = 'https://gameservers.world/';
|
||||
$SITE_BASE_URL = '';
|
||||
|
||||
// Normalize: ensure either empty or ends without trailing slash (we use join_base to handle joining)
|
||||
$SITE_BASE_URL = trim((string)$SITE_BASE_URL);
|
||||
|
||||
// Site-wide background image (relative to site root). Change to your preferred background.
|
||||
$SITE_BACKGROUND = 'images/dark.jpg';
|
||||
// Normalize
|
||||
$SITE_BACKGROUND = trim((string)$SITE_BACKGROUND);
|
||||
|
||||
// Data directory for persisted payment webhook JSON files (relative to repo root)
|
||||
$SITE_DATA_DIR = realpath(__DIR__ . '/..') . DIRECTORY_SEPARATOR . 'data';
|
||||
?>
|
||||
8
modules/billing/includes/footer.php
Normal file
8
modules/billing/includes/footer.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
// Simple footer include
|
||||
?>
|
||||
<footer class="gsw-footer">
|
||||
<div class="container-wide">
|
||||
<a href="privacy.php">Privacy</a> | <a href="tos.php">TOS</a> | <a href="server_status.php">Server Status</a> | <a href="https://worlddomination.dev" target="_blank" rel="noopener">Worlddomination.dev</a>
|
||||
</div>
|
||||
</footer>
|
||||
33
modules/billing/includes/log.php
Normal file
33
modules/billing/includes/log.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
// Simple site logging helper for _website
|
||||
// Writes to _website/logs/YYYY-MM-DD.log
|
||||
|
||||
function site_log_dir(){
|
||||
$d = __DIR__ . '/../logs';
|
||||
if (!is_dir($d)) @mkdir($d, 0775, true);
|
||||
return $d;
|
||||
}
|
||||
|
||||
function site_log_filename(){
|
||||
$d = site_log_dir();
|
||||
return rtrim($d, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . date('Y-m-d') . '.log';
|
||||
}
|
||||
|
||||
function site_log($level, $message, $meta = null){
|
||||
$ts = date('c');
|
||||
$lvl = strtoupper(substr((string)$level,0,10));
|
||||
$line = "[{$ts}] [{$lvl}] {$message}";
|
||||
if ($meta !== null) {
|
||||
if (!is_string($meta)) $meta = json_encode($meta, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
|
||||
$line .= ' | ' . $meta;
|
||||
}
|
||||
$file = site_log_filename();
|
||||
@file_put_contents($file, $line . PHP_EOL, FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
|
||||
// Convenience wrappers
|
||||
function site_log_info($msg, $meta=null){ site_log('INFO', $msg, $meta); }
|
||||
function site_log_warn($msg, $meta=null){ site_log('WARN', $msg, $meta); }
|
||||
function site_log_error($msg, $meta=null){ site_log('ERROR', $msg, $meta); }
|
||||
|
||||
?>
|
||||
11
modules/billing/includes/login_required.php
Normal file
11
modules/billing/includes/login_required.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_name("gameservers_website");
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Debugging mode: do not enforce login redirects. Pages can load without authentication.
|
||||
// If you later want to re-enable, restore the original redirect behavior.
|
||||
// (This file intentionally left as a no-op during debugging.)
|
||||
return;
|
||||
?>
|
||||
115
modules/billing/includes/menu.php
Normal file
115
modules/billing/includes/menu.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* Navigation Menu for GameServers.World Website
|
||||
* This file provides a consistent navigation menu across all website pages
|
||||
*/
|
||||
|
||||
// Start the website session to check if user is logged in (if not already started)
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_name("gameservers_website");
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Check login status
|
||||
// Primary check uses website_user_id, but some remote deployments may only set website_username.
|
||||
// Treat presence of website_username as a fallback to consider the user logged in for UI purposes.
|
||||
$is_logged_in = (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) || (isset($_SESSION['website_username']) && !empty($_SESSION['website_username']));
|
||||
$username = '';
|
||||
if (isset($_SESSION['website_username']) && !empty($_SESSION['website_username'])) {
|
||||
$username = htmlspecialchars($_SESSION['website_username']);
|
||||
} elseif (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) {
|
||||
// fetch username lazily if only user_id is present
|
||||
$username = htmlspecialchars((string)($_SESSION['website_user_id']));
|
||||
}
|
||||
|
||||
// Determine if the logged-in user is an admin by checking the panel DB
|
||||
$is_admin = false;
|
||||
if ($is_logged_in) {
|
||||
// load DB credentials
|
||||
require_once(__DIR__ . '/config.inc.php');
|
||||
// Prefer reusing an existing $db if present, otherwise open a local connection
|
||||
$menu_db = null;
|
||||
$menu_db_opened = false;
|
||||
if (isset($db) && $db instanceof mysqli) {
|
||||
$menu_db = $db;
|
||||
} else {
|
||||
$menu_db = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
|
||||
$menu_db_opened = true;
|
||||
}
|
||||
|
||||
if ($menu_db) {
|
||||
$uid = null;
|
||||
if (isset($_SESSION['website_user_id']) && !empty($_SESSION['website_user_id'])) {
|
||||
$uid = intval($_SESSION['website_user_id']);
|
||||
}
|
||||
if (!empty($uid)) {
|
||||
$res = mysqli_query($menu_db, "SELECT users_role FROM ogp_users WHERE user_id = $uid LIMIT 1");
|
||||
if ($res && mysqli_num_rows($res) === 1) {
|
||||
$row = mysqli_fetch_assoc($res);
|
||||
if (strtolower((string)($row['users_role'] ?? '')) === 'admin') $is_admin = true;
|
||||
}
|
||||
}
|
||||
if ($menu_db_opened) {
|
||||
mysqli_close($menu_db);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<link rel="stylesheet" href="css/header.css">
|
||||
|
||||
<div class="gsw-header">
|
||||
<div class="gsw-header-left">
|
||||
<a href="index.php" class="gsw-logo-link">
|
||||
<img src="images/logo-sm.png" alt="GameServers.World" class="gsw-logo">
|
||||
<span class="gsw-site-name">GameServers.World</span>
|
||||
</a>
|
||||
</div>
|
||||
<nav class="gsw-header-nav">
|
||||
<a href="index.php" class="gsw-nav-link">Home</a>
|
||||
<a href="serverlist.php" class="gsw-nav-link">Game Servers</a>
|
||||
<?php if ($is_logged_in): ?>
|
||||
<a href="my_servers.php" class="gsw-nav-link">My Servers</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($is_logged_in): ?>
|
||||
<a href="cart.php" class="gsw-nav-link">Cart
|
||||
<?php
|
||||
// show cart badge if helper available
|
||||
$cart_count = 0;
|
||||
if (file_exists(__DIR__ . '/cart_helper.php')) {
|
||||
include_once __DIR__ . '/cart_helper.php';
|
||||
if (function_exists('get_cart_count')) {
|
||||
$cart_count = (int) get_cart_count();
|
||||
}
|
||||
}
|
||||
if ($cart_count > 0) {
|
||||
echo ' <span class="cart-badge">' . intval($cart_count) . '</span>';
|
||||
}
|
||||
?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (basename($_SERVER['PHP_SELF']) === 'login.php'): ?>
|
||||
<a href="register.php" class="gsw-nav-link">Register</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($is_logged_in && $is_admin): ?>
|
||||
<a href="admin.php" class="gsw-nav-link">Admin</a>
|
||||
<?php endif; ?>
|
||||
<a href="http://panel.iaregamer.com" class="gsw-nav-link" target="_blank">Panel Login</a>
|
||||
</nav>
|
||||
<div class="gsw-header-right">
|
||||
<?php if ($is_logged_in): ?>
|
||||
<span class="gsw-user-info">Welcome, <?php echo $username; ?>!</span>
|
||||
<?php
|
||||
// Build a safe absolute return_to under this site so logout redirects stay in _website
|
||||
$script = $_SERVER['SCRIPT_NAME'] ?? '';
|
||||
$pos = strpos($script, '/_website');
|
||||
$siteRoot = $pos !== false ? substr($script, 0, $pos + strlen('/_website')) : rtrim(dirname($script), '/\\');
|
||||
$current = $_SERVER['REQUEST_URI'] ?? $siteRoot . '/index.php';
|
||||
// Ensure current is absolute and under site root; urlencode only when embedding in URL
|
||||
$return_to_param = $current;
|
||||
?>
|
||||
<a href="logout.php?return_to=<?php echo urlencode($return_to_param); ?>" class="gsw-header-btn">Logout</a>
|
||||
<?php else: ?>
|
||||
<a href="login.php" class="gsw-header-btn">Login</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
6
modules/billing/includes/top.php
Normal file
6
modules/billing/includes/top.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
// top.php — reserved placeholder
|
||||
// The site header (logo + title) has been moved into includes/menu.php
|
||||
// Keep this file present so pages that include it continue to work.
|
||||
// If you need to re-enable a separate top strip later, add markup here.
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue