mirror of
https://github.com/standardebooks/web.git
synced 2025-07-07 23:30:35 -04:00
Tweak a session variable name and update comments
This commit is contained in:
parent
3050ab7219
commit
11d9d0f44a
12 changed files with 25 additions and 37 deletions
|
@ -6,8 +6,7 @@ use function Safe\glob;
|
|||
use function Safe\shell_exec;
|
||||
|
||||
// This script makes various calls to external scripts using exec() (and when called via Apache, as the www-data user).
|
||||
// These scripts are allowed using the /etc/sudoers.d/www-data file. Only the specific scripts
|
||||
// in that file may be executed by this script.
|
||||
// These scripts are allowed using the /etc/sudoers.d/www-data file. Only the specific scripts in that file may be executed by this script.
|
||||
try{
|
||||
$log = new Log(GITHUB_WEBHOOK_LOG_FILE_PATH);
|
||||
$lastPushHashFlag = '';
|
||||
|
@ -87,13 +86,13 @@ try{
|
|||
}
|
||||
else{
|
||||
if($data['after'] == $lastCommitSha1){
|
||||
// This commit is already in our local repo, so silent success
|
||||
// This commit is already in our local repo, so silent success.
|
||||
$log->Write('Local repo already in sync, no action taken.');
|
||||
throw new Exceptions\NoopException();
|
||||
}
|
||||
}
|
||||
|
||||
// Get the current HEAD hash and save for later
|
||||
// Get the current HEAD hash and save for later.
|
||||
$output = [];
|
||||
exec('sudo --set-home --user se-vcs-bot git -C ' . escapeshellarg($dir) . ' rev-parse HEAD', $output, $returnCode);
|
||||
if($returnCode != 0){
|
||||
|
@ -130,11 +129,9 @@ try{
|
|||
throw new Exceptions\WebhookException('Unrecognized GitHub webhook event.', $post);
|
||||
}
|
||||
|
||||
// "Success, no content"
|
||||
http_response_code(Enums\HttpCode::NoContent->value);
|
||||
}
|
||||
catch(Exceptions\InvalidCredentialsException){
|
||||
// "Forbidden"
|
||||
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||
}
|
||||
catch(Exceptions\WebhookException $ex){
|
||||
|
@ -146,14 +143,12 @@ catch(Exceptions\WebhookException $ex){
|
|||
// Print less details to the client.
|
||||
print($ex->getMessage());
|
||||
|
||||
// "Client error"
|
||||
http_response_code(Enums\HttpCode::BadRequest->value);
|
||||
}
|
||||
catch(Exceptions\NoopException){
|
||||
// We arrive here because a special case required us to take no action for the request, but execution also had to be interrupted.
|
||||
// For example, we received a request for a known repo for which we must ignore requests.
|
||||
|
||||
// "Success, no content"
|
||||
http_response_code(Enums\HttpCode::NoContent->value);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -16,7 +16,7 @@ try{
|
|||
|
||||
$apiKey = get_cfg_var('se.secrets.postmark.api_key');
|
||||
|
||||
// Ensure this webhook actually came from Postmark
|
||||
// Ensure this webhook actually came from Postmark.
|
||||
if($apiKey != ($_SERVER['HTTP_X_SE_KEY'] ?? '')){
|
||||
throw new Exceptions\InvalidCredentialsException();
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ try{
|
|||
}
|
||||
|
||||
if($data->RecordType == 'SpamComplaint'){
|
||||
// Received when a user marks an email as spam
|
||||
// Received when a user marks an email as spam.
|
||||
$log->Write('Event type: spam complaint.');
|
||||
|
||||
Db::Query('
|
||||
|
@ -42,12 +42,12 @@ try{
|
|||
', [$data->Email]);
|
||||
}
|
||||
elseif($data->RecordType == 'SubscriptionChange' && $data->SuppressSending){
|
||||
// Received when a user clicks Postmark's "Unsubscribe" link in a newsletter email
|
||||
// Received when a user clicks Postmark's "Unsubscribe" link in a newsletter email.
|
||||
$log->Write('Event type: unsubscribe.');
|
||||
|
||||
$email = $data->Recipient;
|
||||
|
||||
// Remove the email from our newsletter list
|
||||
// Remove the email from our newsletter list.
|
||||
Db::Query('
|
||||
DELETE ns.*
|
||||
from NewsletterSubscriptions ns
|
||||
|
@ -55,7 +55,7 @@ try{
|
|||
where u.Email = ?
|
||||
', [$email]);
|
||||
|
||||
// Remove the suppression from Postmark, since we deleted it from our own list we will never email them again anyway
|
||||
// Remove the suppression from Postmark, since we deleted it from our own list we will never email them again anyway.
|
||||
$handle = curl_init();
|
||||
curl_setopt($handle, CURLOPT_URL, 'https://api.postmarkapp.com/message-streams/' . $data->MessageStream . '/suppressions/delete');
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
@ -73,11 +73,9 @@ try{
|
|||
|
||||
$log->Write('Event processed.');
|
||||
|
||||
// "Success, no content"
|
||||
http_response_code(Enums\HttpCode::NoContent->value);
|
||||
}
|
||||
catch(Exceptions\InvalidCredentialsException){
|
||||
// "Forbidden"
|
||||
$log->Write('Invalid key: ' . ($_SERVER['HTTP_X_SE_KEY'] ?? ''));
|
||||
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||
}
|
||||
|
@ -90,6 +88,5 @@ catch(Exceptions\WebhookException $ex){
|
|||
// Print less details to the client.
|
||||
print($ex->getMessage());
|
||||
|
||||
// "Client error"
|
||||
http_response_code(Enums\HttpCode::BadRequest->value);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@ use function Safe\file_get_contents;
|
|||
use function Safe\preg_match;
|
||||
use function Safe\json_decode;
|
||||
|
||||
// This webhook receives POSTs when email from a Fractured Atlas donation is received
|
||||
// at the SE Zoho email account. This script processes the email, and inserts the donation ID
|
||||
// into the database for later processing by ~se/web/scripts/process-pending-payments
|
||||
// This webhook receives POSTs when email from a Fractured Atlas donation is received at the SE Zoho email account. This script processes the email, and inserts the donation ID into the database for later processing by `~se/web/scripts/process-pending-payments`.
|
||||
try{
|
||||
$log = new Log(ZOHO_WEBHOOK_LOG_FILE_PATH);
|
||||
|
||||
|
@ -29,7 +27,7 @@ try{
|
|||
if($data->fromAddress == 'support@fracturedatlas.org' && strpos($data->subject, 'NOTICE:') !== false){
|
||||
$log->Write('Processing new donation.');
|
||||
|
||||
// Get the donation ID
|
||||
// Get the donation ID.
|
||||
preg_match('/Donation ID: ([0-9a-f\-]+)/us', $data->html, $matches);
|
||||
if(sizeof($matches) == 2){
|
||||
$transactionId = $matches[1];
|
||||
|
@ -50,11 +48,9 @@ try{
|
|||
|
||||
$log->Write('Event processed.');
|
||||
|
||||
// "Success, no content"
|
||||
http_response_code(Enums\HttpCode::NoContent->value);
|
||||
}
|
||||
catch(Exceptions\InvalidCredentialsException){
|
||||
// "Forbidden"
|
||||
$log->Write('Couldn\'t validate POST data.');
|
||||
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||
}
|
||||
|
@ -67,6 +63,5 @@ catch(Exceptions\WebhookException $ex){
|
|||
// Print less details to the client.
|
||||
print($ex->getMessage());
|
||||
|
||||
// "Client error"
|
||||
http_response_code(Enums\HttpCode::BadRequest->value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue