diff --git a/includes/functions.php b/includes/functions.php index d535f8b3..58c37f40 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -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 //Used as a count down to when the user's account expires @@ -1131,4 +1198,3 @@ function deleteMysqlAddonDatabasesForGameServerHome($home_id){ return false; } ?> - diff --git a/index.php b/index.php index 0072a9cc..bea8599b 100644 --- a/index.php +++ b/index.php @@ -297,28 +297,8 @@ function ogpHome() //NOTIFY DISCORD WHEN ADMIN LOGS IN $trust_admins = array("iaregamer","dimrod","CJB","Bebiano","Syru"); 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']; - $json_data = array ('content'=>"$msg"); - $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 + ogp_send_discord_notification($settings, $msg, 'notify_admin_events'); } $_SESSION['user_id'] = $userInfo['user_id']; @@ -487,4 +467,3 @@ function ogpHome() ?> - diff --git a/lang/English/modules/settings.php b/lang/English/modules/settings.php index 8a4b2480..142e9090 100644 --- a/lang/English/modules/settings.php +++ b/lang/English/modules/settings.php @@ -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_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_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."); ?> diff --git a/modules/billing/admin.php b/modules/billing/admin.php index 95f77b76..2ca716dd 100644 --- a/modules/billing/admin.php +++ b/modules/billing/admin.php @@ -39,7 +39,7 @@ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }

Sandbox account (testing)

-

Use PayPal sandbox credentials when testing payments. Set your sandbox client_id and client_secret in the runtime config that the payment handlers use (for this site those are in the respective files under _website/api/ or in a central config if you moved credentials).

+

Use PayPal sandbox credentials when testing payments. Configure all PayPal fields in the panel settings page (home.php?m=settings) so billing endpoints read values from ogp_settings.