feat: wire discord and paypal configs to panel settings

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/6163aa0e-000d-4376-ad24-9f63a04f4d95

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-21 13:28:06 +00:00 committed by GitHub
parent c1d7c27b35
commit 428bccb6ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 336 additions and 134 deletions

View file

@ -77,6 +77,73 @@ function discordmsg($msg, $webhook) {
} }
} }
function ogp_setting_is_enabled($value, $default = false)
{
if ($value === null || $value === '') return $default;
if (is_bool($value)) return $value;
$value = strtolower(trim((string)$value));
return in_array($value, array('1', 'true', 'yes', 'on'), true);
}
function ogp_get_discord_settings($settings = array())
{
$settings = is_array($settings) ? $settings : array();
$legacy_webhook = isset($settings['webhookurl']) ? trim((string)$settings['webhookurl']) : '';
$webhook = isset($settings['discord_webhook_url']) ? trim((string)$settings['discord_webhook_url']) : '';
if ($webhook === '' && $legacy_webhook !== '') {
$webhook = $legacy_webhook;
}
$has_explicit_flag = array_key_exists('discord_enabled', $settings);
$enabled_default = $legacy_webhook !== '';
return array(
'enabled' => ogp_setting_is_enabled($has_explicit_flag ? $settings['discord_enabled'] : null, $enabled_default),
'webhook_url' => $webhook,
'username' => isset($settings['discord_username']) ? trim((string)$settings['discord_username']) : '',
'avatar_url' => isset($settings['discord_avatar_url']) ? trim((string)$settings['discord_avatar_url']) : '',
'notify_orders' => ogp_setting_is_enabled(isset($settings['discord_notify_orders']) ? $settings['discord_notify_orders'] : null, true),
'notify_server_events' => ogp_setting_is_enabled(isset($settings['discord_notify_server_events']) ? $settings['discord_notify_server_events'] : null, true),
'notify_admin_events' => ogp_setting_is_enabled(isset($settings['discord_notify_admin_events']) ? $settings['discord_notify_admin_events'] : null, true),
);
}
function ogp_send_discord_notification($settings, $message, $toggle = '')
{
$discord = ogp_get_discord_settings($settings);
if (!$discord['enabled'] || $discord['webhook_url'] === '') {
return false;
}
if ($toggle !== '' && isset($discord[$toggle]) && !$discord[$toggle]) {
return false;
}
if (!function_exists('curl_init')) {
error_log('OGP Discord webhook skipped: PHP curl extension is not loaded.');
return false;
}
$payload = array('content' => (string)$message);
if ($discord['username'] !== '') {
$payload['username'] = $discord['username'];
}
if ($discord['avatar_url'] !== '') {
$payload['avatar_url'] = $discord['avatar_url'];
}
$ch = curl_init($discord['webhook_url']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
//read_expire() converts a time stamp to a human readable form //read_expire() converts a time stamp to a human readable form
//Used as a count down to when the user's account expires //Used as a count down to when the user's account expires
@ -1131,4 +1198,3 @@ function deleteMysqlAddonDatabasesForGameServerHome($home_id){
return false; return false;
} }
?> ?>

View file

@ -297,28 +297,8 @@ function ogpHome()
//NOTIFY DISCORD WHEN ADMIN LOGS IN //NOTIFY DISCORD WHEN ADMIN LOGS IN
$trust_admins = array("iaregamer","dimrod","CJB","Bebiano","Syru"); $trust_admins = array("iaregamer","dimrod","CJB","Bebiano","Syru");
if ($userInfo['users_role'] == "admin" && in_array($userInfo['users_login'], $trust_admins) == false) { if ($userInfo['users_role'] == "admin" && in_array($userInfo['users_login'], $trust_admins) == false) {
//WEBHOOK Discord=======================================================================================
// Create new webhook in your Discord channel settings and copy&paste URL
//=======================================================================================================
$webhookurl = "https://discord.com/api/webhooks/1087810639390576650/sspI3frko8FLD6ybvzG-_BXhG4wjH7yujFBxffgtTw34uAL_AdrDxY36C-khqs--cEMu";
//========================================================================================================
$msg = "Admin Login :warning: \nIP:".$client_ip." \nID:".$userInfo['user_id']." \nUser:".$userInfo['users_login']; $msg = "Admin Login :warning: \nIP:".$client_ip." \nID:".$userInfo['user_id']." \nUser:".$userInfo['users_login'];
$json_data = array ('content'=>"$msg"); ogp_send_discord_notification($settings, $msg, 'notify_admin_events');
$make_json = json_encode($json_data);
if(!function_exists('curl_init')){
error_log("OGP Discord webhook skipped: PHP curl extension is not loaded.");
}else{
$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
curl_close($ch);
}
//end WEBHOOK Discord
} }
$_SESSION['user_id'] = $userInfo['user_id']; $_SESSION['user_id'] = $userInfo['user_id'];
@ -487,4 +467,3 @@ function ogpHome()
?> ?>

View file

@ -143,6 +143,46 @@ define('OGP_LANG_trusted_host_or_proxy_addresses_or_cidr', "Trusted Hosts or Pro
define('OGP_LANG_trusted_forwarded_ip_addresses_or_cidr', "Trusted Forwarded IPs (IPv4/IPv6 Addresses or CIDR)"); define('OGP_LANG_trusted_forwarded_ip_addresses_or_cidr', "Trusted Forwarded IPs (IPv4/IPv6 Addresses or CIDR)");
define('OGP_LANG_reset_game_server_order', "Reset Game Server Ordering"); define('OGP_LANG_reset_game_server_order', "Reset Game Server Ordering");
define('OGP_LANG_reset_game_server_order_info', "Resets game server ordering back to the default of using the server ID"); define('OGP_LANG_reset_game_server_order_info', "Resets game server ordering back to the default of using the server ID");
define('OGP_LANG_discord_enabled', "Enable Discord Notifications");
define('OGP_LANG_discord_enabled_info', "Enable or disable Discord webhook notifications globally.");
define('OGP_LANG_discord_webhook_url', "Discord Webhook URL");
define('OGP_LANG_discord_webhook_url_info', "Discord channel webhook endpoint used for panel notifications.");
define('OGP_LANG_discord_username', "Discord Webhook Username");
define('OGP_LANG_discord_username_info', "Optional username override for webhook messages.");
define('OGP_LANG_discord_avatar_url', "Discord Webhook Avatar URL");
define('OGP_LANG_discord_avatar_url_info', "Optional avatar URL override for webhook messages.");
define('OGP_LANG_discord_notify_orders', "Discord Notify: Orders");
define('OGP_LANG_discord_notify_orders_info', "Send Discord notifications for order/payment events.");
define('OGP_LANG_discord_notify_server_events', "Discord Notify: Server Events");
define('OGP_LANG_discord_notify_server_events_info', "Send Discord notifications for server provisioning/renewal/ticket events.");
define('OGP_LANG_discord_notify_admin_events', "Discord Notify: Admin Events");
define('OGP_LANG_discord_notify_admin_events_info', "Send Discord notifications for admin security and role-change events.");
define('OGP_LANG_paypal_enabled', "Enable PayPal");
define('OGP_LANG_paypal_enabled_info', "Enable or disable PayPal checkout and webhook processing.");
define('OGP_LANG_paypal_mode', "PayPal Mode");
define('OGP_LANG_paypal_mode_info', "Select sandbox for testing or live for production.");
define('OGP_LANG_paypal_client_id', "PayPal Default Client ID");
define('OGP_LANG_paypal_client_id_info', "Fallback client ID used when mode-specific IDs are not set.");
define('OGP_LANG_paypal_client_secret', "PayPal Default Client Secret");
define('OGP_LANG_paypal_client_secret_info', "Fallback client secret used when mode-specific secrets are not set.");
define('OGP_LANG_paypal_sandbox_client_id', "PayPal Sandbox Client ID");
define('OGP_LANG_paypal_sandbox_client_id_info', "Sandbox REST app client ID from PayPal Developer.");
define('OGP_LANG_paypal_sandbox_client_secret', "PayPal Sandbox Client Secret");
define('OGP_LANG_paypal_sandbox_client_secret_info', "Sandbox REST app client secret from PayPal Developer.");
define('OGP_LANG_paypal_live_client_id', "PayPal Live Client ID");
define('OGP_LANG_paypal_live_client_id_info', "Live REST app client ID from PayPal Developer.");
define('OGP_LANG_paypal_live_client_secret', "PayPal Live Client Secret");
define('OGP_LANG_paypal_live_client_secret_info', "Live REST app client secret from PayPal Developer.");
define('OGP_LANG_paypal_email', "PayPal Merchant Email");
define('OGP_LANG_paypal_email_info', "Optional merchant email used for payment records and reconciliation.");
define('OGP_LANG_paypal_currency', "PayPal Currency");
define('OGP_LANG_paypal_currency_info', "Default currency code used by checkout (for example: USD).");
define('OGP_LANG_paypal_webhook_id', "PayPal Webhook ID");
define('OGP_LANG_paypal_webhook_id_info', "Webhook ID used for PayPal signature verification.");
define('OGP_LANG_paypal_return_url', "PayPal Return URL");
define('OGP_LANG_paypal_return_url_info', "Optional return URL used after successful approval.");
define('OGP_LANG_paypal_cancel_url', "PayPal Cancel URL");
define('OGP_LANG_paypal_cancel_url_info', "Optional cancel URL used when checkout is canceled.");
?> ?>

View file

@ -39,7 +39,7 @@ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
</ul> </ul>
<h3>Sandbox account (testing)</h3> <h3>Sandbox account (testing)</h3>
<p>Use PayPal sandbox credentials when testing payments. Set your sandbox <code>client_id</code> and <code>client_secret</code> in the runtime config that the payment handlers use (for this site those are in the respective files under <code>_website/api/</code> or in a central config if you moved credentials).</p> <p>Use PayPal sandbox credentials when testing payments. Configure all PayPal fields in the panel settings page (<code>home.php?m=settings</code>) so billing endpoints read values from <code>ogp_settings</code>.</p>
<ul> <ul>
<li>Create a sandbox business account at <a href="https://developer.paypal.com">PayPal Developer</a> and obtain a sandbox client ID/secret.</li> <li>Create a sandbox business account at <a href="https://developer.paypal.com">PayPal Developer</a> and obtain a sandbox client ID/secret.</li>
<li>Update the payment handler config and restart the webserver if required.</li> <li>Update the payment handler config and restart the webserver if required.</li>

View file

@ -6,6 +6,7 @@
*/ */
require_once(__DIR__ . '/../includes/config_loader.php'); require_once(__DIR__ . '/../includes/config_loader.php');
require_once(__DIR__ . '/../includes/runtime_settings.php');
// Prevent any output before JSON // Prevent any output before JSON
ob_start(); ob_start();
@ -50,10 +51,16 @@ if (!$paypal_order_id) {
log_payment('REQUEST_START', ['order_id' => $paypal_order_id]); log_payment('REQUEST_START', ['order_id' => $paypal_order_id]);
// PayPal API configuration // PayPal API configuration
$sandbox = true; $paypalSettings = billing_get_paypal_settings();
$client_id = 'AfvY_C2zA_hTHxHq7TIhtOeub4xBdySYrt_Hjj3d_WYQwjWI9NfOAVOTeResx2rgZ_nP5tOoxQSAHw8c'; $client_id = $paypalSettings['client_id'];
$client_secret = 'EJ216np9cAj9n7KSddez3fLVxGe-zi4oKKKl1YGqPp88XIikr4Qzbxh0XW2as-V6LgdX-upjtQAg9dC0'; $client_secret = $paypalSettings['client_secret'];
$api = $sandbox ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; $api = $paypalSettings['api_base'];
if (!billing_paypal_is_ready($paypalSettings)) {
log_payment('PAYPAL_NOT_CONFIGURED', ['enabled' => $paypalSettings['enabled'] ?? false]);
ob_clean();
echo json_encode(['error' => 'paypal_not_configured', 'request_id' => $requestId]);
exit;
}
// Get OAuth token // Get OAuth token
$ch = curl_init("$api/v1/oauth2/token"); $ch = curl_init("$api/v1/oauth2/token");
@ -366,4 +373,3 @@ echo json_encode([
'provisioned' => $autoProvisionResult['provisioned_count'] ?? 0 'provisioned' => $autoProvisionResult['provisioned_count'] ?? 0
]); ]);

View file

@ -9,10 +9,12 @@ ini_set('display_errors', '0');
error_reporting(E_ALL); error_reporting(E_ALL);
require_once(__DIR__ . '/../includes/config_loader.php'); require_once(__DIR__ . '/../includes/config_loader.php');
require_once(__DIR__ . '/../includes/runtime_settings.php');
// create_order for PayPal — adapted to run from _website/api // create_order for PayPal — adapted to run from _website/api
$sandbox = true; // flip to false for Live $paypalSettings = billing_get_paypal_settings();
$client_id = 'AfvY_C2zA_hTHxHq7TIhtOeub4xBdySYrt_Hjj3d_WYQwjWI9NfOAVOTeResx2rgZ_nP5tOoxQSAHw8c'; $sandbox = !empty($paypalSettings['sandbox']);
$client_secret = 'EJ216np9cAj9n7KSddez3fLVxGe-zi4oKKKl1YGqPp88XIikr4Qzbxh0XW2as-V6LgdX-upjtQAg9dC0'; $client_id = $paypalSettings['client_id'];
$client_secret = $paypalSettings['client_secret'];
// Setup comprehensive logging // Setup comprehensive logging
$logDir = __DIR__ . '/../logs'; $logDir = __DIR__ . '/../logs';
@ -62,7 +64,7 @@ if (!$in) {
} }
$amount_in = $in['amount'] ?? '0.00'; $amount_in = $in['amount'] ?? '0.00';
$currency = $in['currency'] ?? 'USD'; $currency = $in['currency'] ?? $paypalSettings['currency'];
$invoice_id = $in['invoice_id'] ?? null; $invoice_id = $in['invoice_id'] ?? null;
$custom_id = $in['custom_id'] ?? null; $custom_id = $in['custom_id'] ?? null;
$description = $in['description'] ?? 'Order'; $description = $in['description'] ?? 'Order';
@ -96,7 +98,7 @@ if ($items) {
]); ]);
} }
$api = $sandbox ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; $api = $paypalSettings['api_base'];
create_order_log('PAYPAL_API_CONFIG', [ create_order_log('PAYPAL_API_CONFIG', [
'sandbox_mode' => $sandbox, 'sandbox_mode' => $sandbox,
'api_base' => $api, 'api_base' => $api,
@ -104,6 +106,13 @@ create_order_log('PAYPAL_API_CONFIG', [
'has_client_secret' => !empty($client_secret) 'has_client_secret' => !empty($client_secret)
]); ]);
if (!billing_paypal_is_ready($paypalSettings)) {
create_order_log('PAYPAL_NOT_CONFIGURED', ['enabled' => $paypalSettings['enabled'] ?? false]);
http_response_code(503);
echo json_encode(['error' => 'paypal_not_configured', 'request_id' => $requestId]);
exit;
}
// Step 1: Get OAuth token // Step 1: Get OAuth token
create_order_log('OAUTH_REQUEST_START', ['endpoint' => "$api/v1/oauth2/token"]); create_order_log('OAUTH_REQUEST_START', ['endpoint' => "$api/v1/oauth2/token"]);
@ -154,7 +163,7 @@ if (!$access) {
create_order_log('OAUTH_SUCCESS', ['token_length' => strlen($access)]); create_order_log('OAUTH_SUCCESS', ['token_length' => strlen($access)]);
// Update site base URL to exclude 'modules/billing' // Update site base URL to exclude 'modules/billing'
$siteBaseUrl = 'http://gameservers.world'; $siteBaseUrl = $paypalSettings['site_base'];
create_order_log('URL_PROCESSING_BEFORE', [ create_order_log('URL_PROCESSING_BEFORE', [
'return_url' => $return_url, 'return_url' => $return_url,
@ -163,11 +172,15 @@ create_order_log('URL_PROCESSING_BEFORE', [
]); ]);
// Ensure return_url and cancel_url are absolute URLs (relative to site root) // Ensure return_url and cancel_url are absolute URLs (relative to site root)
if (strpos($return_url, 'http') !== 0) { if (empty($return_url)) {
$return_url = $siteBaseUrl . '/' . ltrim($return_url, '/'); $return_url = $paypalSettings['return_url'];
} elseif (strpos($return_url, 'http') !== 0) {
$return_url = billing_absolute_url($return_url, $siteBaseUrl);
} }
if (strpos($cancel_url, 'http') !== 0) { if (empty($cancel_url)) {
$cancel_url = $siteBaseUrl . '/' . ltrim($cancel_url, '/'); $cancel_url = $paypalSettings['cancel_url'];
} elseif (strpos($cancel_url, 'http') !== 0) {
$cancel_url = billing_absolute_url($cancel_url, $siteBaseUrl);
} }
create_order_log('URL_PROCESSING_AFTER', [ create_order_log('URL_PROCESSING_AFTER', [

View file

@ -13,6 +13,7 @@ if (session_status() === PHP_SESSION_NONE) {
// Load configuration // Load configuration
require_once(__DIR__ . '/bootstrap.php'); require_once(__DIR__ . '/bootstrap.php');
require_once(__DIR__ . '/includes/runtime_settings.php');
// Variables from config.inc.php (helps IDEs understand scope) // Variables from config.inc.php (helps IDEs understand scope)
/** @var string $db_host Database host */ /** @var string $db_host Database host */
@ -251,8 +252,11 @@ if ($applied_coupon && $coupon_discount_percent > 0) {
$final_amount = $total_amount - $discount_amount; $final_amount = $total_amount - $discount_amount;
// PayPal configuration // PayPal configuration
$sandbox = true; $paypal_settings = billing_get_paypal_settings();
$client_id = 'AfvY_C2zA_hTHxHq7TIhtOeub4xBdySYrt_Hjj3d_WYQwjWI9NfOAVOTeResx2rgZ_nP5tOoxQSAHw8c'; $client_id = $paypal_settings['client_id'];
$paypal_currency = $paypal_settings['currency'];
$paypal_enabled = !empty($paypal_settings['enabled']);
$paypal_ready = billing_paypal_is_ready($paypal_settings);
// Prepare PayPal items // Prepare PayPal items
$paypal_items = []; $paypal_items = [];
@ -264,7 +268,7 @@ foreach ($invoices as $inv) {
'description' => $inv['description'] ?? '', 'description' => $inv['description'] ?? '',
'quantity' => $qty, 'quantity' => $qty,
'unit_amount' => [ 'unit_amount' => [
'currency_code' => 'USD', 'currency_code' => $paypal_currency,
'value' => number_format(floatval($inv['amount']) / $qty, 2, '.', '') 'value' => number_format(floatval($inv['amount']) / $qty, 2, '.', '')
] ]
]; ];
@ -507,8 +511,8 @@ $siteBase = $protocol . $host;
<!-- Favicon --> <!-- Favicon -->
<link rel="icon" href="images/logo-sm.png" type="image/png"> <link rel="icon" href="images/logo-sm.png" type="image/png">
<link rel="apple-touch-icon" href="images/logo-sm.png"> <link rel="apple-touch-icon" href="images/logo-sm.png">
<?php if (!$cart_empty): ?> <?php if (!$cart_empty && $paypal_ready): ?>
<script src="https://www.paypal.com/sdk/js?client-id=<?php echo htmlspecialchars($client_id); ?>&currency=USD&intent=capture"></script> <script src="https://www.paypal.com/sdk/js?client-id=<?php echo htmlspecialchars($client_id); ?>&currency=<?php echo urlencode($paypal_currency); ?>&intent=capture"></script>
<?php endif; ?> <?php endif; ?>
</head> </head>
<body> <body>
@ -623,9 +627,14 @@ $siteBase = $protocol . $host;
<div class="checkout-section"> <div class="checkout-section">
<h3>Checkout with PayPal</h3> <h3>Checkout with PayPal</h3>
<p>Click the button below to complete your purchase securely through PayPal.</p> <p>Click the button below to complete your purchase securely through PayPal.</p>
<?php if (!$paypal_enabled): ?>
<div id="paypal-button-container"></div> <div class="alert alert-error">PayPal checkout is currently disabled by the administrator.</div>
<div id="status-message" class="status-message"></div> <?php elseif (!$paypal_ready): ?>
<div class="alert alert-error">PayPal checkout is not configured yet. Please contact support.</div>
<?php else: ?>
<div id="paypal-button-container"></div>
<div id="status-message" class="status-message"></div>
<?php endif; ?>
<div class="action-buttons"> <div class="action-buttons">
<a href="/order.php" class="btn btn-secondary">Continue Shopping</a> <a href="/order.php" class="btn btn-secondary">Continue Shopping</a>
@ -633,6 +642,7 @@ $siteBase = $protocol . $host;
</div> </div>
</div> </div>
<?php if ($paypal_ready): ?>
<script> <script>
function setStatus(msg) { function setStatus(msg) {
const statusDiv = document.getElementById('status-message'); const statusDiv = document.getElementById('status-message');
@ -646,17 +656,17 @@ $siteBase = $protocol . $host;
return actions.order.create({ return actions.order.create({
purchase_units: [{ purchase_units: [{
amount: { amount: {
currency_code: 'USD', currency_code: '<?php echo htmlspecialchars($paypal_currency); ?>',
value: '<?php echo number_format($final_amount, 2, '.', ''); ?>', value: '<?php echo number_format($final_amount, 2, '.', ''); ?>',
breakdown: { breakdown: {
item_total: { item_total: {
currency_code: 'USD', currency_code: '<?php echo htmlspecialchars($paypal_currency); ?>',
value: '<?php echo number_format($total_amount, 2, '.', ''); ?>' value: '<?php echo number_format($total_amount, 2, '.', ''); ?>'
} }
<?php if ($discount_amount > 0): ?> <?php if ($discount_amount > 0): ?>
, ,
discount: { discount: {
currency_code: 'USD', currency_code: '<?php echo htmlspecialchars($paypal_currency); ?>',
value: '<?php echo number_format($discount_amount, 2, '.', ''); ?>' value: '<?php echo number_format($discount_amount, 2, '.', ''); ?>'
} }
<?php endif; ?> <?php endif; ?>
@ -708,10 +718,11 @@ $siteBase = $protocol . $host;
onCancel: function(data) { onCancel: function(data) {
setStatus('Payment cancelled'); setStatus('Payment cancelled');
window.location.href = '/payment_cancel.php'; window.location.href = '<?php echo htmlspecialchars($paypal_settings['cancel_url']); ?>';
} }
}).render('#paypal-button-container'); }).render('#paypal-button-container');
</script> </script>
<?php endif; ?>
<script> <script>
// Remove invoice via AJAX and perform a partial reload of the cart container // Remove invoice via AJAX and perform a partial reload of the cart container
function removeInvoice(invoiceId) { function removeInvoice(invoiceId) {
@ -760,4 +771,3 @@ $siteBase = $protocol . $host;
<?php include(__DIR__ . '/includes/footer.php'); ?> <?php include(__DIR__ . '/includes/footer.php'); ?>
</body> </body>
</html> </html>

View file

@ -146,21 +146,8 @@ function exec_ogp_module()
//WEBHOOK Discord======================================================================================= //WEBHOOK Discord=======================================================================================
$webhookurl = $settings['webhookurl'];
$msg = "The ". $home_name ." server ID #". $home_id . " has just been renewed."; $msg = "The ". $home_name ." server ID #". $home_id . " has just been renewed.";
$json_data = array ('content'=>"$msg"); ogp_send_discord_notification($settings, $msg, 'notify_server_events');
$make_json = json_encode($json_data);
$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
//If you need to debug, or find out why you can't send message uncomment line below, and execute script.
//echo $response;
//end WEBHOOK Discord //end WEBHOOK Discord
} }
@ -310,24 +297,8 @@ function exec_ogp_module()
//WEBHOOK Discord======================================================================================= //WEBHOOK Discord=======================================================================================
$webhookurl = "https://discord.com/api/webhooks/710275918274363412/g5Tr-EUdEnLfFryOlscxJ6FuPiSJuE6EMKRYmh9UGMiqTUxU5-y9CQrBlDJW7znr0Tol";
//$settings['webhookurl'];
$msg = "A new server, ". $home_name ." ID #". $home_id . ", has just been created."; $msg = "A new server, ". $home_name ." ID #". $home_id . ", has just been created.";
$json_data = array ('content'=>"$msg"); ogp_send_discord_notification($settings, $msg, 'notify_server_events');
$make_json = json_encode($json_data);
$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
//If you need to debug, or find out why you can't send message uncomment line below, and execute script.
//echo $response;
//end WEBHOOK Discord //end WEBHOOK Discord
} }
// END EMAIL // END EMAIL
@ -449,4 +420,3 @@ function exec_ogp_module()

View file

@ -0,0 +1,99 @@
<?php
require_once(__DIR__ . '/panel_bridge.php');
if (!function_exists('billing_bool_setting')) {
function billing_bool_setting($value, $default = false)
{
if ($value === null || $value === '') {
return $default;
}
if (is_bool($value)) {
return $value;
}
$value = strtolower(trim((string)$value));
return in_array($value, array('1', 'true', 'yes', 'on'), true);
}
}
if (!function_exists('billing_detect_site_base')) {
function billing_detect_site_base()
{
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = isset($_SERVER['HTTP_HOST']) ? trim((string)$_SERVER['HTTP_HOST']) : 'localhost';
return $scheme . '://' . $host;
}
}
if (!function_exists('billing_absolute_url')) {
function billing_absolute_url($url, $siteBase)
{
$url = trim((string)$url);
if ($url === '') {
return '';
}
if (preg_match('#^https?://#i', $url)) {
return $url;
}
return rtrim($siteBase, '/') . '/' . ltrim($url, '/');
}
}
if (!function_exists('billing_get_paypal_settings')) {
function billing_get_paypal_settings()
{
$panelSettings = billing_get_panel_settings();
$mode = strtolower(trim((string)($panelSettings['paypal_mode'] ?? 'sandbox')));
if (!in_array($mode, array('sandbox', 'live'), true)) {
$mode = 'sandbox';
}
$sandboxClientId = trim((string)($panelSettings['paypal_sandbox_client_id'] ?? ''));
$sandboxClientSecret = trim((string)($panelSettings['paypal_sandbox_client_secret'] ?? ''));
$liveClientId = trim((string)($panelSettings['paypal_live_client_id'] ?? ''));
$liveClientSecret = trim((string)($panelSettings['paypal_live_client_secret'] ?? ''));
$fallbackClientId = trim((string)($panelSettings['paypal_client_id'] ?? ''));
$fallbackClientSecret = trim((string)($panelSettings['paypal_client_secret'] ?? ''));
$clientId = $mode === 'live' ? $liveClientId : $sandboxClientId;
$clientSecret = $mode === 'live' ? $liveClientSecret : $sandboxClientSecret;
if ($clientId === '') {
$clientId = $fallbackClientId;
}
if ($clientSecret === '') {
$clientSecret = $fallbackClientSecret;
}
$currency = strtoupper(trim((string)($panelSettings['paypal_currency'] ?? 'USD')));
if ($currency === '') {
$currency = 'USD';
}
$enabled = billing_bool_setting($panelSettings['paypal_enabled'] ?? null, ($clientId !== '' && $clientSecret !== ''));
$siteBase = billing_detect_site_base();
$returnUrl = billing_absolute_url($panelSettings['paypal_return_url'] ?? '/payment_success.php', $siteBase);
$cancelUrl = billing_absolute_url($panelSettings['paypal_cancel_url'] ?? '/payment_cancel.php', $siteBase);
return array(
'enabled' => $enabled,
'mode' => $mode,
'sandbox' => $mode !== 'live',
'client_id' => $clientId,
'client_secret' => $clientSecret,
'currency' => $currency,
'webhook_id' => trim((string)($panelSettings['paypal_webhook_id'] ?? '')),
'email' => trim((string)($panelSettings['paypal_email'] ?? '')),
'return_url' => $returnUrl,
'cancel_url' => $cancelUrl,
'site_base' => $siteBase,
'api_base' => $mode === 'live' ? 'https://api-m.paypal.com' : 'https://api-m.sandbox.paypal.com',
);
}
}
if (!function_exists('billing_paypal_is_ready')) {
function billing_paypal_is_ready($settings)
{
return !empty($settings['enabled']) && !empty($settings['client_id']) && !empty($settings['client_secret']);
}
}

View file

@ -1,16 +1,21 @@
<?php <?php
require_once(__DIR__ . '/includes/config_loader.php'); require_once(__DIR__ . '/includes/config_loader.php');
require_once(__DIR__ . '/includes/runtime_settings.php');
if (is_file(__DIR__ . '/includes/log.php')) require_once(__DIR__ . '/includes/log.php'); if (is_file(__DIR__ . '/includes/log.php')) require_once(__DIR__ . '/includes/log.php');
$paypalSettings = billing_get_paypal_settings();
$dataDir = rtrim(
(defined('SITE_DATA_DIR') ? SITE_DATA_DIR : '') ?: ($SITE_DATA_DIR ?? ''),
DIRECTORY_SEPARATOR
);
$config = [ $config = [
'sandbox' => true, 'sandbox' => !empty($paypalSettings['sandbox']),
'client_id' => 'AfvY_C2zA_hTHxHq7TIhtOeub4xBdySYrt_Hjj3d_WYQwjWI9NfOAVOTeResx2rgZ_nP5tOoxQSAHw8c', 'enabled' => !empty($paypalSettings['enabled']),
'client_secret' => 'EJ216np9cAj9n7KSddez3fLVxGe-zi4oKKKl1YGqPp88XIikr4Qzbxh0XW2as-V6LgdX-upjtQAg9dC0', 'client_id' => $paypalSettings['client_id'],
'webhook_id' => '6N620673281740730', 'client_secret' => $paypalSettings['client_secret'],
'data_dir' => rtrim( 'webhook_id' => $paypalSettings['webhook_id'],
(defined('SITE_DATA_DIR') ? SITE_DATA_DIR : '') ?: ($SITE_DATA_DIR ?? ''), 'data_dir' => $dataDir,
DIRECTORY_SEPARATOR
),
'log_file' => __DIR__ . '/data/webhook.log', 'log_file' => __DIR__ . '/data/webhook.log',
]; ];
@ -24,6 +29,12 @@ function api_base(){global $config; return $config['sandbox'] ? 'https://api-m.s
http_response_code(200); http_response_code(200);
@mkdir($config['data_dir'], 0775, true); @mkdir($config['data_dir'], 0775, true);
if (empty($config['enabled']) || empty($config['client_id']) || empty($config['client_secret']) || empty($config['webhook_id'])) {
if (function_exists('site_log_warn')) site_log_warn('paypal_webhook_not_configured', ['enabled' => $config['enabled']]);
else log_line("PAYPAL_WEBHOOK_NOT_CONFIGURED");
exit;
}
$raw = file_get_contents('php://input'); $raw = file_get_contents('php://input');
$headers = array_change_key_case(getallheaders() ?: [], CASE_UPPER); $headers = array_change_key_case(getallheaders() ?: [], CASE_UPPER);
if (function_exists('site_log_info')) site_log_info('webhook_hit', ['ip'=>($_SERVER['REMOTE_ADDR']??''),'bytes'=>strlen($raw)]); if (function_exists('site_log_info')) site_log_info('webhook_hit', ['ip'=>($_SERVER['REMOTE_ADDR']??''),'bytes'=>strlen($raw)]);

View file

@ -72,7 +72,27 @@ function exec_ogp_module()
"use_authorized_hosts" => $_REQUEST['use_authorized_hosts'], "use_authorized_hosts" => $_REQUEST['use_authorized_hosts'],
"allow_setting_cpu_affinity" => $_REQUEST['allow_setting_cpu_affinity'], "allow_setting_cpu_affinity" => $_REQUEST['allow_setting_cpu_affinity'],
"regex_invalid_file_name_chars" => addslashes($_REQUEST['regex_invalid_file_name_chars']), "regex_invalid_file_name_chars" => addslashes($_REQUEST['regex_invalid_file_name_chars']),
"login_ban_time" => $_REQUEST['login_ban_time'] "login_ban_time" => $_REQUEST['login_ban_time'],
"discord_enabled" => $_REQUEST['discord_enabled'],
"discord_webhook_url" => $_REQUEST['discord_webhook_url'],
"discord_username" => $_REQUEST['discord_username'],
"discord_avatar_url" => $_REQUEST['discord_avatar_url'],
"discord_notify_orders" => $_REQUEST['discord_notify_orders'],
"discord_notify_server_events" => $_REQUEST['discord_notify_server_events'],
"discord_notify_admin_events" => $_REQUEST['discord_notify_admin_events'],
"paypal_enabled" => $_REQUEST['paypal_enabled'],
"paypal_mode" => $_REQUEST['paypal_mode'],
"paypal_client_id" => $_REQUEST['paypal_client_id'],
"paypal_client_secret" => $_REQUEST['paypal_client_secret'],
"paypal_sandbox_client_id" => $_REQUEST['paypal_sandbox_client_id'],
"paypal_sandbox_client_secret" => $_REQUEST['paypal_sandbox_client_secret'],
"paypal_live_client_id" => $_REQUEST['paypal_live_client_id'],
"paypal_live_client_secret" => $_REQUEST['paypal_live_client_secret'],
"paypal_email" => $_REQUEST['paypal_email'],
"paypal_currency" => $_REQUEST['paypal_currency'],
"paypal_webhook_id" => $_REQUEST['paypal_webhook_id'],
"paypal_return_url" => $_REQUEST['paypal_return_url'],
"paypal_cancel_url" => $_REQUEST['paypal_cancel_url']
); );
$db->setSettings($settings); $db->setSettings($settings);
@ -191,6 +211,29 @@ function exec_ogp_module()
// Add regex setting for file manager // Add regex setting for file manager
$ft->add_field('string','regex_invalid_file_name_chars',(@empty($row['regex_invalid_file_name_chars']) ? htmlentities('/[\^\$\*\+\?\(\)\[\{\\\\\\|\]!@#%&=~`,\\\'<>"}\s]/i', ENT_COMPAT | ENT_HTML401 | ENT_QUOTES) : htmlentities(@$row['regex_invalid_file_name_chars'], ENT_COMPAT | ENT_HTML401 | ENT_QUOTES))); $ft->add_field('string','regex_invalid_file_name_chars',(@empty($row['regex_invalid_file_name_chars']) ? htmlentities('/[\^\$\*\+\?\(\)\[\{\\\\\\|\]!@#%&=~`,\\\'<>"}\s]/i', ENT_COMPAT | ENT_HTML401 | ENT_QUOTES) : htmlentities(@$row['regex_invalid_file_name_chars'], ENT_COMPAT | ENT_HTML401 | ENT_QUOTES)));
$ft->add_field('on_off','discord_enabled', isset($row['discord_enabled']) ? $row['discord_enabled'] : '0');
$ft->add_field('string','discord_webhook_url',@$row['discord_webhook_url']);
$ft->add_field('string','discord_username',@$row['discord_username']);
$ft->add_field('string','discord_avatar_url',@$row['discord_avatar_url']);
$ft->add_field('on_off','discord_notify_orders', isset($row['discord_notify_orders']) ? $row['discord_notify_orders'] : '1');
$ft->add_field('on_off','discord_notify_server_events', isset($row['discord_notify_server_events']) ? $row['discord_notify_server_events'] : '1');
$ft->add_field('on_off','discord_notify_admin_events', isset($row['discord_notify_admin_events']) ? $row['discord_notify_admin_events'] : '1');
$ft->add_field('on_off','paypal_enabled', isset($row['paypal_enabled']) ? $row['paypal_enabled'] : '0');
$ft->add_custom_field('paypal_mode',
create_drop_box_from_array(array('sandbox' => 'Sandbox', 'live' => 'Live'),"paypal_mode",isset($row['paypal_mode']) && !empty($row['paypal_mode']) ? $row['paypal_mode'] : 'sandbox',false));
$ft->add_field('string','paypal_client_id',@$row['paypal_client_id']);
$ft->add_field('password','paypal_client_secret',@$row['paypal_client_secret']);
$ft->add_field('string','paypal_sandbox_client_id',@$row['paypal_sandbox_client_id']);
$ft->add_field('password','paypal_sandbox_client_secret',@$row['paypal_sandbox_client_secret']);
$ft->add_field('string','paypal_live_client_id',@$row['paypal_live_client_id']);
$ft->add_field('password','paypal_live_client_secret',@$row['paypal_live_client_secret']);
$ft->add_field('string','paypal_email',@$row['paypal_email']);
$ft->add_field('string','paypal_currency',isset($row['paypal_currency']) && !empty($row['paypal_currency']) ? $row['paypal_currency'] : 'USD');
$ft->add_field('string','paypal_webhook_id',@$row['paypal_webhook_id']);
$ft->add_field('string','paypal_return_url',@$row['paypal_return_url']);
$ft->add_field('string','paypal_cancel_url',@$row['paypal_cancel_url']);
// Add option to reset game server order to default // Add option to reset game server order to default
$ft->add_field('checkbox','reset_game_server_order','0'); $ft->add_field('checkbox','reset_game_server_order','0');

View file

@ -48,16 +48,8 @@ function exec_ogp_module() {
// URL FROM DISCORD WEBHOOK SETUP // URL FROM DISCORD WEBHOOK SETUP
$webhook = "https://discordapp.com/api/webhooks/710275918274363412/g5Tr-EUdEnLfFryOlscxJ6FuPiSJuE6EMKRYmh9UGMiqTUxU5-y9CQrBlDJW7znr0Tol"; $msg = "SUPPORT TICKET CREATED: Login with the userid and password http://privateemail.com";
$msg = json_decode(' ogp_send_discord_notification($settings, $msg, 'notify_server_events');
{
"username":"I Are Gamer",
"content":"SUPPORT TICKET CREATED: Login with the userid and password http://privateemail.com"
}
', true);
discordmsg($msg, $webhook);
//end discord //end discord
$content = get_lang_f('support_email_content', $user['users_login'], $email, $gameserver, $message); $content = get_lang_f('support_email_content', $user['users_login'], $email, $gameserver, $message);

View file

@ -94,24 +94,10 @@ function exec_ogp_module()
//WEBHOOK Discord======================================================================================= //WEBHOOK Discord=======================================================================================
$discord_settings = $db->getSettings();
$webhook = "https://discord.com/api/webhooks/1087807080657854484/yYtW8q63xKj3rTFYrNfW2LJk_GeC_WtuI8eJOyELxWbqTQ-uMzOO2I9qofoJCoHXFhC1";
//$webhook = "https://discord.com/api/webhooks/710275918274363412/g5Tr-EUdEnLfFryOlscxJ6FuPiSJuE6EMKRYmh9UGMiqTUxU5-y9CQrBlDJW7znr0Tol";
$msg = "Server support ticket created:\n"."ServerID: " .$_POST['ticket_service'] ."\n". "Subject: " .$_POST['ticket_subject']; $msg = "Server support ticket created:\n"."ServerID: " .$_POST['ticket_service'] ."\n". "Subject: " .$_POST['ticket_subject'];
$json_data = array ('content'=>"$msg"); ogp_send_discord_notification($discord_settings, $msg, 'notify_server_events');
$make_json = json_encode($json_data);
$ch = curl_init( $webhook );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
//If you need to debug, or find out why you can't send message uncomment line below, and execute script.
//echo $response;
//end WEBHOOK Discord //end WEBHOOK Discord

View file

@ -154,21 +154,8 @@ function exec_ogp_module() {
if (isset($userInfo['users_role']) && isset($_POST['newrole']) && $userInfo['users_role'] != $_POST['newrole']) { if (isset($userInfo['users_role']) && isset($_POST['newrole']) && $userInfo['users_role'] != $_POST['newrole']) {
$client_ip = getClientIPAddress(); $client_ip = getClientIPAddress();
//WEBHOOK Discord======================================================================================= //WEBHOOK Discord=======================================================================================
// Create new webhook in your Discord channel settings and copy&paste URL
//=======================================================================================================
$webhookurl = "https://discord.com/api/webhooks/1087810639390576650/sspI3frko8FLD6ybvzG-_BXhG4wjH7yujFBxffgtTw34uAL_AdrDxY36C-khqs--cEMu";
//========================================================================================================
$msg = "User Role Changed :warning: \nIP: ".$client_ip." \nUser: ".$login." \nUser Role: ".$userInfo['users_role']." \nNew Role: ".$_POST['newrole']; $msg = "User Role Changed :warning: \nIP: ".$client_ip." \nUser: ".$login." \nUser Role: ".$userInfo['users_role']." \nNew Role: ".$_POST['newrole'];
$json_data = array ('content'=>"$msg"); ogp_send_discord_notification($settings, $msg, 'notify_admin_events');
$make_json = json_encode($json_data);
$ch = curl_init( $webhookurl );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $make_json);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
//end WEBHOOK Discord //end WEBHOOK Discord
} }