fix: remove hardcoded Discord webhook URLs, centralize via discordmsg() helper

- Improve discordmsg() in includes/functions.php: add curl_init existence
  check, CURLOPT_TIMEOUT/CONNECTTIMEOUT, safe no-op when webhook is empty,
  correct false-return on curl_init failure
- index.php: replace hardcoded webhook URL + 15-line inline cURL block with
  discordmsg() using $settings['discord_webhook_admin']
- modules/user_admin/edit_user.php: same — role-change notification now
  uses discordmsg() + discord_webhook_admin setting
- modules/tickets/submitTicket.php: add global $settings; replace hardcoded
  webhook URL + inline cURL with discordmsg() using discord_webhook_main
- modules/billing/create_servers.php: replace $settings['webhookurl'] +
  inline cURL blocks (x2) with discordmsg() using discord_webhook_main

All modules now use the centralized discord_webhook_main / discord_webhook_admin
settings already managed in Admin > Settings. No DB migration needed.

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/e4d38343-77ed-4c7a-afac-a2a815a059fd

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-05 20:21:59 +00:00 committed by GitHub
parent 8abe2653f7
commit 4babef08eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 112 deletions

View file

@ -62,19 +62,26 @@ $msg = json_decode('
', true);
*/
function discordmsg($msg, $webhook) {
if($webhook != "") {
$ch = curl_init($webhook);
$msg = "payload_json=" . urlencode(json_encode($msg))."";
if(isset($ch)) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
if (empty($webhook)) {
return false;
}
}
if (!function_exists('curl_init')) {
error_log("GSP Discord webhook skipped: PHP curl extension is not loaded.");
return false;
}
$ch = curl_init($webhook);
if ($ch === false) {
return false;
}
$payload = "payload_json=" . urlencode(json_encode($msg));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}