Script Update & Correction

Corrected the code so it now runs smoothly. 
Clearly labeled sections of the code which need to be configured.
Optimised code into one function.
This commit is contained in:
William Phillips
2017-09-23 16:37:33 +01:00
committed by GitHub
parent 53f99eeb93
commit 710c27816e

View File

@@ -1,134 +1,73 @@
<?php <?php
//////// Configuration Area //////// //////// Configuration Information ////////
// Unfortunately due to WHMCS hooks not allowing external inputs, values are required to defined within each hook. If this changes it will be updated!
$discordWebHookURL = ""; // Your Discord WebHook URL. // I recommend using NotePad++ to mass replace all values at once.
// Please be aware that the channel which you select to create the web hook is the channel which will be used for sending messages.
$whmcsAdminURL = ""; // Your WHMCS Admin URL.
// Please include the end / on your URL. An example of an accepted link would be: https://account.whmcs.com/admin/
$companyName = ""; // Your Company Name
// This will be the name of the user which sends the messages.
$discordGroupID = ""; // Discord Group ID Config Option // $discordWebHookURL = "";
// If you wished for each message which is sent to ping a specific group, please place the ID here. An example of a group ID is: @&343029528563548162 // Found on line(s): 300
// Your Discord WebHook URL. Please be aware that the channel which you select to create the web hook is the channel which will be used for sending messages.
//////// End Of Configuration Area ////////
// $whmcsAdminURL = "";
add_hook('TicketOpen', 1, function($vars) { // Found on line(s): 24, 45, 66, 87, 125, 146, 199, 220, 259
$dataPacket = array( // Your WHMCS Admin URL. Please include the end / on your URL. An example of an accepted link would be: https://account.whmcs.com/admin/
if (isset($discordGroupID)) {
'content' => $discordGroupID, // $companyName = "";
} // Found on line(s): 25, 46, 67, 88, 126, 147, 200, 221, 260
// Your Company Name. This will be the name of the user which sends the messages.
// $discordGroupID = "";
// Found on line(s): 26, 47, 68, 89, 127, 148, 201, 222, 261
// Discord Group ID Config Option. If you wished for each message which is sent to ping a specific group, please place the ID here. An example of a group ID is: @&343029528563548162
add_hook('InvoicePaid', 1, function($vars) {
$whmcsAdminURL = ""; // Your WHMCS Admin URL.
$companyName = ""; // Your Company Name.
$discordGroupID = ""; // Discord Group ID Config Option.
$dataPacket = array(
'content' => $discordGroupID,
'username' => $companyName, 'username' => $companyName,
'embeds' => array( 'embeds' => array(
array( array(
'title' => $vars['subject'], 'url' => $whmcsAdminURL . 'orders.php?action=view&id=' . $vars['invoiceid'],
'url' => $whmcsAdminURL . 'supporttickets.php?action=view&id=' . $vars['ticketid'],
'timestamp' => date(DateTime::ISO8601), 'timestamp' => date(DateTime::ISO8601),
'description' => '', 'description' => '',
'color' => '5653183', 'color' => '5653183',
'author' => array( 'author' => array(
'name' => 'New Support Ticket', 'name' => 'Invoice Payment Received'
), )
'fields' => array(
array(
'name' => 'Priority',
'value' => $vars['priority'],
'inline' => true,
),
array(
'name' => 'Department',
'value' => $vars['deptname'],
'inline' => true,
),
array(
'name' => 'Ticket ID',
'value' => $vars['ticketid'],
'inline' => true,
)
),
) )
), )
); );
$dataString = json_encode($dataPacket); processNotification($dataPacket);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $discordWebHookURL);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
$output = curl_exec($curl);
$output = json_decode($output, true);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 204) {
echo "Failed " . curl_getinfo($curl, CURLINFO_HTTP_CODE) . "<br><br>";
print_r($output);
}
curl_close($curl);
}); });
add_hook('InvoiceRefunded', 1, function($vars) {
add_hook('TicketUserReply', 1, function($vars) { $whmcsAdminURL = ""; // Your WHMCS Admin URL.
$dataPacket = array( $companyName = ""; // Your Company Name.
if (isset($discordGroupID)) { $discordGroupID = ""; // Discord Group ID Config Option.
'content' => $discordGroupID, $dataPacket = array(
} 'content' => $discordGroupID,
'username' => $companyName, 'username' => $companyName,
'embeds' => array( 'embeds' => array(
array( array(
'title' => $vars['subject'], 'url' => $whmcsAdminURL . 'orders.php?action=view&id=' . $vars['invoiceid'],
'url' => $whmcsAdminURL . 'supporttickets.php?action=view&id=' . $vars['ticketid'],
'timestamp' => date(DateTime::ISO8601), 'timestamp' => date(DateTime::ISO8601),
'description' => '', 'description' => '',
'color' => '5653183', 'color' => '5653183',
'author' => array( 'author' => array(
'name' => 'New Ticket Reply', 'name' => 'Invoice Refunded'
), )
'fields' => array(
array(
'name' => 'Priority',
'value' => $vars['priority'],
'inline' => true,
),
array(
'name' => 'Department',
'value' => $vars['deptname'],
'inline' => true,
),
array(
'name' => 'Ticket ID',
'value' => $vars['ticketid'],
'inline' => true,
)
),
) )
), )
); );
$dataString = json_encode($dataPacket); processNotification($dataPacket);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $discordWebHookURL);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
$output = curl_exec($curl);
$output = json_decode($output, true);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 204) {
echo "Failed " . curl_getinfo($curl, CURLINFO_HTTP_CODE) . "<br><br>";
print_r($output);
}
curl_close($curl);
}); });
add_hook('AcceptOrder', 1, function($vars) {
add_hook('PendingOrder', 1, function($vars) { $whmcsAdminURL = ""; // Your WHMCS Admin URL.
$dataPacket = array( $companyName = ""; // Your Company Name.
if (isset($discordGroupID)) { $discordGroupID = ""; // Discord Group ID Config Option.
'content' => $discordGroupID, $dataPacket = array(
} 'content' => $discordGroupID,
'username' => $companyName, 'username' => $companyName,
'embeds' => array( 'embeds' => array(
array( array(
@@ -137,106 +76,19 @@
'description' => '', 'description' => '',
'color' => '5653183', 'color' => '5653183',
'author' => array( 'author' => array(
'name' => 'New Pending Order', 'name' => 'New Accepted Order'
), )
) )
), )
); );
$dataString = json_encode($dataPacket); processNotification($dataPacket);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $discordWebHookURL);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
$output = curl_exec($curl);
$output = json_decode($output, true);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 204) {
echo "Failed " . curl_getinfo($curl, CURLINFO_HTTP_CODE) . "<br><br>";
print_r($output);
}
curl_close($curl);
}); });
add_hook('CancellationRequest', 1, function($vars) {
add_hook('AcceptOrder', 1, function($vars) { $whmcsAdminURL = ""; // Your WHMCS Admin URL.
$dataPacket = array( $companyName = ""; // Your Company Name.
if (isset($discordGroupID)) { $discordGroupID = ""; // Discord Group ID Config Option.
'content' => $discordGroupID, $dataPacket = array(
} 'content' => $discordGroupID,
'username' => $companyName,
'embeds' => array(
array(
'url' => $whmcsAdminURL . 'orders.php?action=view&id=' . $vars['orderid'],
'timestamp' => date(DateTime::ISO8601),
'description' => '',
'color' => '5653183',
'author' => array(
'name' => 'New Accepted Order',
),
)
),
);
$dataString = json_encode($dataPacket);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $discordWebHookURL);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
$output = curl_exec($curl);
$output = json_decode($output, true);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 204) {
echo "Failed " . curl_getinfo($curl, CURLINFO_HTTP_CODE) . "<br><br>";
print_r($output);
}
curl_close($curl);
});
add_hook('FraudOrder', 1, function($vars) {
$dataPacket = array(
if (isset($discordGroupID)) {
'content' => $discordGroupID,
}
'username' => $companyName,
'embeds' => array(
array(
'url' => $whmcsAdminURL . 'orders.php?action=view&id=' . $vars['orderid'],
'timestamp' => date(DateTime::ISO8601),
'description' => '',
'color' => '5653183',
'author' => array(
'name' => 'Order Marked As Fraud',
),
)
),
);
$dataString = json_encode($dataPacket);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $discordWebHookURL);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataString);
$output = curl_exec($curl);
$output = json_decode($output, true);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 204) {
echo "Failed " . curl_getinfo($curl, CURLINFO_HTTP_CODE) . "<br><br>";
print_r($output);
}
curl_close($curl);
});
add_hook('CancellationRequest', 1, function($vars) {
$dataPacket = array(
if (isset($discordGroupID)) {
'content' => $discordGroupID,
}
'username' => $companyName, 'username' => $companyName,
'embeds' => array( 'embeds' => array(
array( array(
@@ -245,33 +97,212 @@
'description' => $vars['reason'], 'description' => $vars['reason'],
'color' => '5653183', 'color' => '5653183',
'author' => array( 'author' => array(
'name' => 'New Cancellation Request', 'name' => 'New Cancellation Request'
), ),
'fields' => array( 'fields' => array(
array( array(
'name' => 'Product ID', 'name' => 'Product ID',
'value' => $vars['relid'], 'value' => $vars['relid'],
'inline' => true, 'inline' => true
), ),
array( array(
'name' => 'Cancellation Type', 'name' => 'Cancellation Type',
'value' => $vars['type'], 'value' => $vars['type'],
'inline' => true, 'inline' => true
), ),
array( array(
'name' => 'User ID', 'name' => 'User ID',
'value' => $vars['userid'], 'value' => $vars['userid'],
'inline' => true, 'inline' => true
) )
), )
) )
), )
); );
$dataString = json_encode($dataPacket); processNotification($dataPacket);
$curl = curl_init(); });
add_hook('FraudOrder', 1, function($vars) {
$whmcsAdminURL = ""; // Your WHMCS Admin URL.
$companyName = ""; // Your Company Name.
$discordGroupID = ""; // Discord Group ID Config Option.
$dataPacket = array(
'content' => $discordGroupID,
'username' => $companyName,
'embeds' => array(
array(
'url' => $whmcsAdminURL . 'orders.php?action=view&id=' . $vars['orderid'],
'timestamp' => date(DateTime::ISO8601),
'description' => '',
'color' => '5653183',
'author' => array(
'name' => 'Order Marked As Fraud'
)
)
)
);
processNotification($dataPacket);
});
add_hook('NetworkIssueAdd', 1, function($vars) {
$whmcsAdminURL = ""; // Your WHMCS Admin URL.
$companyName = ""; // Your Company Name.
$discordGroupID = ""; // Discord Group ID Config Option.
$dataPacket = array(
'content' => $discordGroupID,
'username' => $companyName,
'embeds' => array(
array(
'url' => $whmcsAdminURL . 'networkissues.php?action=manage&id=' . $vars['announcementid'],
'timestamp' => date(DateTime::ISO8601),
'description' => $vars['reason'],
'color' => '5653183',
'author' => array(
'name' => 'New Network Issue'
),
'fields' => array(
array(
'name' => 'Start Date',
'value' => $vars['startdate'],
'inline' => true
),
array(
'name' => 'End Date',
'value' => $vars['enddate'],
'inline' => true
),
array(
'name' => 'Title',
'value' => $vars['title'],
'inline' => true
),
array(
'name' => 'Description',
'value' => $vars['description'],
'inline' => true
),
array(
'name' => 'Affecting',
'value' => $vars['affecting'],
'inline' => true
),
array(
'name' => 'Priority',
'value' => $vars['priority'],
'inline' => true
)
)
)
)
);
processNotification($dataPacket);
});
add_hook('PendingOrder', 1, function($vars) {
$whmcsAdminURL = ""; // Your WHMCS Admin URL.
$companyName = ""; // Your Company Name.
$discordGroupID = ""; // Discord Group ID Config Option.
$dataPacket = array(
'content' => $discordGroupID,
'username' => $companyName,
'embeds' => array(
array(
'url' => $whmcsAdminURL . 'orders.php?action=view&id=' . $vars['orderid'],
'timestamp' => date(DateTime::ISO8601),
'description' => '',
'color' => '5653183',
'author' => array(
'name' => 'New Pending Order'
)
)
)
);
processNotification($dataPacket);
});
add_hook('TicketOpen', 1, function($vars) {
$whmcsAdminURL = ""; // Your WHMCS Admin URL.
$companyName = ""; // Your Company Name.
$discordGroupID = ""; // Discord Group ID Config Option.
$dataPacket = array(
'content' => $discordGroupID,
'username' => $companyName,
'embeds' => array(
array(
'title' => $vars['subject'],
'url' => $whmcsAdminURL . 'supporttickets.php?action=view&id=' . $vars['ticketid'],
'timestamp' => date(DateTime::ISO8601),
'description' => '',
'color' => '5653183',
'author' => array(
'name' => 'New Support Ticket'
),
'fields' => array(
array(
'name' => 'Priority',
'value' => $vars['priority'],
'inline' => true
),
array(
'name' => 'Department',
'value' => $vars['deptname'],
'inline' => true
),
array(
'name' => 'Ticket ID',
'value' => $vars['ticketid'],
'inline' => true
)
)
)
)
);
processNotification($dataPacket);
});
add_hook('TicketUserReply', 1, function($vars) {
$whmcsAdminURL = ""; // Your WHMCS Admin URL.
$companyName = ""; // Your Company Name.
$discordGroupID = ""; // Discord Group ID Config Option.
$dataPacket = array(
'content' => $discordGroupID,
'username' => $companyName,
'embeds' => array(
array(
'title' => $vars['subject'],
'url' => $whmcsAdminURL . 'supporttickets.php?action=view&id=' . $vars['ticketid'],
'timestamp' => date(DateTime::ISO8601),
'description' => '',
'color' => '5653183',
'author' => array(
'name' => 'New Ticket Reply'
),
'fields' => array(
array(
'name' => 'Priority',
'value' => $vars['priority'],
'inline' => true
),
array(
'name' => 'Department',
'value' => $vars['deptname'],
'inline' => true
),
array(
'name' => 'Ticket ID',
'value' => $vars['ticketid'],
'inline' => true
)
)
)
)
);
processNotification($dataPacket);
});
function processNotification($dataPacket, $discordWebHookURL) {
$dataString = json_encode($dataPacket);
$curl = curl_init();
$discordWebHookURL = ""; // Your Discord WebHook URL
curl_setopt($curl, CURLOPT_URL, $discordWebHookURL); curl_setopt($curl, CURLOPT_URL, $discordWebHookURL);
curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
@@ -283,5 +314,5 @@
print_r($output); print_r($output);
} }
curl_close($curl); curl_close($curl);
}); }
?> ?>