Files
Wallos/endpoints/notifications/testwebhooknotifications.php
Miguel Ribeiro aff3ed06b1 feat: add OIDC_REQUIRE_EMAIL_VERIFIED environment variable and SSRF_ALLOWLIST environment variable
feat: add Arabic localization
feat: add manual logo search box and png prioritization
fix: pin discord notification action to a commit sha
fix: service worker caching stale logo search results and broken images as logos
fix: ai recommendations not handling varied provider responses
fix: deleting orphaned logos not taking into account themed variants
fix: stats page not using themed logo variants
fix: email notification test rejecting non-admin users
fix: notification test/send requests hanging on unreachable hosts
fix: progress bar showing 100% when next payment is more than one cycle away
2026-07-18 23:33:40 +02:00

105 lines
3.7 KiB
PHP

<?php
require_once '../../includes/connect_endpoint.php';
require_once '../../includes/validate_endpoint.php';
require_once '../../includes/ssrf_helper.php';
// Variables available: {{days_until}}, {{subscription_name}}, {{subscription_price}}, {{subscription_currency}}, {{subscription_category}}, {{subscription_date}}, {{subscription_payer}}, {{subscription_days_until_payment}}, {{subscription_notes}}, {{subscription_url}}
$fakeSubscription = [
"days_until" => 5,
"subscription_name" => "Test Subscription",
"subscription_price" => 10.00,
"subscription_currency" => "USD",
"subscription_category" => "Test Category",
"subscription_date" => date("Y-m-d H:i:s"),
"subscription_payer" => "Test Payer",
"subscription_days_until_payment" => 30,
"subscription_notes" => "Test Notes",
"subscription_url" => "https://example.com/test-subscription"
];
$postData = file_get_contents("php://input");
$data = json_decode($postData, true);
if (
!isset($data["requestmethod"]) || $data["requestmethod"] == "" ||
!isset($data["url"]) || $data["url"] == "" ||
!isset($data["payload"]) || $data["payload"] == ""
) {
$response = [
"success" => false,
"message" => translate('fill_mandatory_fields', $i18n)
];
die(json_encode($response));
} else {
$requestmethod = $data["requestmethod"];
$url = $data["url"];
$payload = $data["payload"];
// Validate URL scheme
$parsedUrl = parse_url($url);
if (
!isset($parsedUrl['scheme']) ||
!in_array(strtolower($parsedUrl['scheme']), ['http', 'https']) ||
!filter_var($url, FILTER_VALIDATE_URL)
) {
die(json_encode([
"success" => false,
"message" => translate("error", $i18n)
]));
}
$ssrf = validate_webhook_url_for_ssrf($url, $db, $i18n, $userId);
// Replace placeholders in the payload with fake subscription data
foreach ($fakeSubscription as $key => $value) {
$placeholder = "{{" . $key . "}}";
$payload = str_replace($placeholder, $value, $payload);
}
$customheaders = json_decode($data["customheaders"], true);
$ignore_ssl = $data["ignore_ssl"];
$ch = curl_init();
// Set the URL and other options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RESOLVE, ["{$ssrf['host']}:{$ssrf['port']}:{$ssrf['ip']}"]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestmethod);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
if (!empty($customheaders)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $customheaders);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
if ($ignore_ssl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
// Execute the request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
// Close the cURL session
unset($ch);
// Check if the message was sent successfully
if ($response === false || $httpCode >= 400) {
die(json_encode([
"success" => false,
"message" => translate('notification_failed', $i18n),
"response" => $curlError ? $curlError : $response
]));
} else {
die(json_encode([
"success" => true,
"message" => translate('notification_sent_successfuly', $i18n),
"response" => $response
]));
}
}