Merge pull request #127 from GameServerPanel/copilot/remove-hardcoded-discord-webhooks
This commit is contained in:
commit
11b205682f
5 changed files with 41 additions and 149 deletions
|
|
@ -24,57 +24,34 @@
|
|||
|
||||
#functions go here
|
||||
|
||||
//discordmsg() posts a message to webhook
|
||||
//can post form data. Minium is username and content
|
||||
/*
|
||||
$msg = json_decode('
|
||||
{
|
||||
"username":"BOTNAME",
|
||||
"content":"The message the BOTNAME posts.",
|
||||
"embeds": [{
|
||||
"title":"The Link Title",
|
||||
"description":"The Link Description",
|
||||
"url":"https://www.thelinkurl.com/",
|
||||
"color":DECIMALCOLORCODE,
|
||||
"author":{
|
||||
"name":"Site Name",
|
||||
"url":"https://www.sitelink.com/",
|
||||
"icon_url":"URLTOIMG"
|
||||
},
|
||||
"fields":[
|
||||
{
|
||||
"name":"LISTITEM1",
|
||||
"value":"LISTVALUE1",
|
||||
"inline":true
|
||||
},
|
||||
{
|
||||
"name":"LISTITEM2",
|
||||
"value":"LISTVALUE2",
|
||||
"inline":true
|
||||
},
|
||||
{
|
||||
"name":"LISTITEM3",
|
||||
"value":"LISTVALUE3",
|
||||
"inline":true
|
||||
}]
|
||||
}]
|
||||
}
|
||||
', true);
|
||||
*/
|
||||
//discordmsg() posts a message to a Discord webhook.
|
||||
// $msg - associative array (e.g. ['content' => '...']) to send as payload_json.
|
||||
// $webhook - Discord webhook URL; no-op (returns false) when empty.
|
||||
// Returns the response string on success, or false on failure / skipped.
|
||||
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);
|
||||
if ($result === false) {
|
||||
error_log("GSP Discord webhook error: " . curl_error($ch));
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
28
index.php
28
index.php
|
|
@ -304,30 +304,10 @@ 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
|
||||
}
|
||||
if ($userInfo['users_role'] == "admin" && !in_array($userInfo['users_login'], $trust_admins)) {
|
||||
$msg = "Admin Login :warning: \nIP:".$client_ip." \nID:".$userInfo['user_id']." \nUser:".$userInfo['users_login'];
|
||||
discordmsg(array('content' => $msg), $settings['discord_webhook_admin'] ?? '');
|
||||
}
|
||||
|
||||
$_SESSION['user_id'] = $userInfo['user_id'];
|
||||
$_SESSION['users_login'] = $userInfo['users_login'];
|
||||
|
|
|
|||
|
|
@ -147,24 +147,8 @@ function exec_ogp_module()
|
|||
$db->logger( "Email FAILED - Server Renewed " . $home_id);
|
||||
// END EMAIL
|
||||
|
||||
//WEBHOOK Discord=======================================================================================
|
||||
|
||||
|
||||
$webhookurl = $settings['webhookurl'];
|
||||
|
||||
$msg = "The ". $home_name ." server ID #". $home_id . " has just been renewed.";
|
||||
$json_data = array ('content'=>"$msg");
|
||||
$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;
|
||||
//WEBHOOK Discord
|
||||
discordmsg(array('content' => "The ". $home_name ." server ID #". $home_id . " has just been renewed."), $settings['discord_webhook_main'] ?? '');
|
||||
//end WEBHOOK Discord
|
||||
|
||||
}
|
||||
|
|
@ -294,28 +278,9 @@ function exec_ogp_module()
|
|||
$db->logger( "Email FAILED - Server Created " . $home_id);
|
||||
|
||||
|
||||
//WEBHOOK Discord=======================================================================================
|
||||
|
||||
$webhookurl = !empty($settings['webhookurl']) ? $settings['webhookurl'] : '';
|
||||
|
||||
if (!empty($webhookurl)) {
|
||||
|
||||
|
||||
$msg = "A new server, ". $home_name ." ID #". $home_id . ", has just been created.";
|
||||
$json_data = array ('content'=>"$msg");
|
||||
$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;
|
||||
//WEBHOOK Discord
|
||||
discordmsg(array('content' => "A new server, ". $home_name ." ID #". $home_id . ", has just been created."), $settings['discord_webhook_main'] ?? '');
|
||||
//end WEBHOOK Discord
|
||||
}
|
||||
}
|
||||
// END EMAIL
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ require 'include/functions.php';
|
|||
|
||||
function exec_ogp_module()
|
||||
{
|
||||
global $db, $view;
|
||||
global $db, $view, $settings;
|
||||
|
||||
$ticket = new Ticket($db);
|
||||
$TicketSettings = new TicketSettings($db);
|
||||
|
|
@ -94,25 +94,10 @@ function exec_ogp_module()
|
|||
|
||||
|
||||
|
||||
//WEBHOOK Discord=======================================================================================
|
||||
|
||||
$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'];
|
||||
$json_data = array ('content'=>"$msg");
|
||||
$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
|
||||
//TICKET SUBMITTED, POST ON DISCORD
|
||||
$msg = "Server support ticket created:\n"."ServerID: " .$_POST['ticket_service'] ."\n". "Subject: " .$_POST['ticket_subject'];
|
||||
discordmsg(array('content' => $msg), $settings['discord_webhook_main'] ?? '');
|
||||
//end discord
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -153,23 +153,8 @@ function exec_ogp_module() {
|
|||
//when someone changes the profile to admin
|
||||
if (isset($userInfo['users_role']) && isset($_POST['newrole']) && $userInfo['users_role'] != $_POST['newrole']) {
|
||||
$client_ip = getClientIPAddress();
|
||||
//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'];
|
||||
$json_data = array ('content'=>"$msg");
|
||||
$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
|
||||
$msg = "User Role Changed :warning: \nIP: ".$client_ip." \nUser: ".$login." \nUser Role: ".$userInfo['users_role']." \nNew Role: ".$_POST['newrole'];
|
||||
discordmsg(array('content' => $msg), $settings['discord_webhook_admin'] ?? '');
|
||||
}
|
||||
|
||||
if ( empty($theme) )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue