Skip to content

Commit

Permalink
feat: settings to allow to ignore certificates for some notification …
Browse files Browse the repository at this point in the history
…methods
  • Loading branch information
ellite authored Oct 27, 2024
1 parent c40401c commit 2a0e665
Show file tree
Hide file tree
Showing 31 changed files with 1,498 additions and 1,357 deletions.
12 changes: 12 additions & 0 deletions endpoints/cronjobs/sendcancellationnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
$gotifyNotificationsEnabled = $row['enabled'];
$gotify['serverUrl'] = $row["url"];
$gotify['appToken'] = $row["token"];
$gotify['ignore_ssl'] = $row["ignore_ssl"];
}

// Check if Telegram notifications are enabled and get the settings
Expand Down Expand Up @@ -107,6 +108,7 @@
$ntfy['host'] = $row["host"];
$ntfy['topic'] = $row["topic"];
$ntfy['headers'] = $row["headers"];
$ntfy['ignore_ssl'] = $row["ignore_ssl"];
}

$notificationsEnabled = $emailNotificationsEnabled || $gotifyNotificationsEnabled || $telegramNotificationsEnabled ||
Expand Down Expand Up @@ -335,6 +337,11 @@
)
);

if ($gotify['ignore_ssl']) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

$result = curl_exec($ch);
if ($result === false) {
echo "Error sending notifications: " . curl_error($ch) . "<br />";
Expand Down Expand Up @@ -468,6 +475,11 @@
curl_setopt($ch, CURLOPT_HTTPHEADER, $customheaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($ntfy['ignore_ssl']) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

$response = curl_exec($ch);
curl_close($ch);

Expand Down
18 changes: 18 additions & 0 deletions endpoints/cronjobs/sendnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
$gotifyNotificationsEnabled = $row['enabled'];
$gotify['serverUrl'] = $row["url"];
$gotify['appToken'] = $row["token"];
$gotify['ignore_ssl'] = $row["ignore_ssl"];
}

// Check if Telegram notifications are enabled and get the settings
Expand Down Expand Up @@ -125,6 +126,7 @@
$ntfy['host'] = $row["host"];
$ntfy['topic'] = $row["topic"];
$ntfy['headers'] = $row["headers"];
$ntfy['ignore_ssl'] = $row["ignore_ssl"];
}

// Check if Webhook notifications are enabled and get the settings
Expand All @@ -147,6 +149,7 @@
$webhook['iterator'] = "{{" . $webhook['iterator'] . "}}";
}
}
$webhook['ignore_ssl'] = $row["ignore_ssl"];
}

$notificationsEnabled = $emailNotificationsEnabled || $gotifyNotificationsEnabled || $telegramNotificationsEnabled ||
Expand Down Expand Up @@ -387,6 +390,11 @@
)
);

if ($gotify['ignore_ssl']) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

$result = curl_exec($ch);
if ($result === false) {
echo "Error sending notifications: " . curl_error($ch) . "<br />";
Expand Down Expand Up @@ -523,6 +531,11 @@
curl_setopt($ch, CURLOPT_HTTPHEADER, $customheaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($ntfy['ignore_ssl']) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

$response = curl_exec($ch);
curl_close($ch);

Expand Down Expand Up @@ -598,6 +611,11 @@
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($webhook['ignore_ssl']) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

$response = curl_exec($ch);
curl_close($ch);

Expand Down
8 changes: 5 additions & 3 deletions endpoints/notifications/savegotifynotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
$enabled = $data["enabled"];
$url = $data["gotify_url"];
$token = $data["token"];
$ignore_ssl = $data["ignore_ssl"];

$query = "SELECT COUNT(*) FROM gotify_notifications WHERE user_id = :userId";
$stmt = $db->prepare($query);
Expand All @@ -41,17 +42,18 @@
$row = $result->fetchArray();
$count = $row[0];
if ($count == 0) {
$query = "INSERT INTO gotify_notifications (enabled, url, token, user_id)
VALUES (:enabled, :url, :token, :userId)";
$query = "INSERT INTO gotify_notifications (enabled, url, token, user_id, ignore_ssl)
VALUES (:enabled, :url, :token, :userId, :ignore_ssl)";
} else {
$query = "UPDATE gotify_notifications
SET enabled = :enabled, url = :url, token = :token WHERE user_id = :userId";
SET enabled = :enabled, url = :url, token = :token, ignore_ssl = :ignore_ssl WHERE user_id = :userId";
}

$stmt = $db->prepare($query);
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER);
$stmt->bindValue(':url', $url, SQLITE3_TEXT);
$stmt->bindValue(':token', $token, SQLITE3_TEXT);
$stmt->bindValue(':ignore_ssl', $ignore_ssl, SQLITE3_INTEGER);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);

if ($stmt->execute()) {
Expand Down
8 changes: 5 additions & 3 deletions endpoints/notifications/saventfynotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$host = $data["host"];
$topic = $data["topic"];
$headers = $data["headers"];
$ignore_ssl = $data["ignore_ssl"];

$query = "SELECT COUNT(*) FROM ntfy_notifications WHERE user_id = :userId";
$stmt = $db->prepare($query);
Expand All @@ -43,18 +44,19 @@
$row = $result->fetchArray();
$count = $row[0];
if ($count == 0) {
$query = "INSERT INTO ntfy_notifications (enabled, host, topic, headers, user_id)
VALUES (:enabled, :host, :topic, :headers, :userId)";
$query = "INSERT INTO ntfy_notifications (enabled, host, topic, headers, user_id, ignore_ssl)
VALUES (:enabled, :host, :topic, :headers, :userId, :ignore_ssl)";
} else {
$query = "UPDATE ntfy_notifications
SET enabled = :enabled, host = :host, topic = :topic, headers = :headers WHERE user_id = :userId";
SET enabled = :enabled, host = :host, topic = :topic, headers = :headers, ignore_ssl = :ignore_ssl WHERE user_id = :userId";
}

$stmt = $db->prepare($query);
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER);
$stmt->bindValue(':host', $host, SQLITE3_TEXT);
$stmt->bindValue(':topic', $topic, SQLITE3_TEXT);
$stmt->bindValue(':headers', $headers, SQLITE3_TEXT);
$stmt->bindValue(':ignore_ssl', $ignore_ssl, SQLITE3_INTEGER);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);

if ($stmt->execute()) {
Expand Down
8 changes: 5 additions & 3 deletions endpoints/notifications/savewebhooknotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$headers = $data["headers"];
$payload = $data["payload"];
$iterator = $data["iterator"];
$ignore_ssl = $data["ignore_ssl"];

$query = "SELECT COUNT(*) FROM webhook_notifications WHERE user_id = :userId";
$stmt = $db->prepare($query);
Expand All @@ -43,11 +44,11 @@
$row = $result->fetchArray();
$count = $row[0];
if ($count == 0) {
$query = "INSERT INTO webhook_notifications (enabled, url, headers, payload, iterator, user_id)
VALUES (:enabled, :url, :headers, :payload, :iterator, :userId)";
$query = "INSERT INTO webhook_notifications (enabled, url, headers, payload, iterator, user_id, ignore_ssl)
VALUES (:enabled, :url, :headers, :payload, :iterator, :userId, :ignore_ssl)";
} else {
$query = "UPDATE webhook_notifications
SET enabled = :enabled, url = :url, headers = :headers, payload = :payload, iterator = :iterator WHERE user_id = :userId";
SET enabled = :enabled, url = :url, headers = :headers, payload = :payload, iterator = :iterator, ignore_ssl = :ignore_ssl WHERE user_id = :userId";
}

$stmt = $db->prepare($query);
Expand All @@ -56,6 +57,7 @@
$stmt->bindValue(':headers', $headers, SQLITE3_TEXT);
$stmt->bindValue(':payload', $payload, SQLITE3_TEXT);
$stmt->bindValue(':iterator', $iterator, SQLITE3_TEXT);
$stmt->bindValue(':ignore_ssl', $ignore_ssl, SQLITE3_INTEGER);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);

if ($stmt->execute()) {
Expand Down
6 changes: 6 additions & 0 deletions endpoints/notifications/testgotifynotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

$url = $data["gotify_url"];
$token = $data["token"];
$ignore_ssl = $data["ignore_ssl"];

$ch = curl_init();

Expand All @@ -42,6 +43,11 @@
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($ignore_ssl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

// Execute the request
$response = curl_exec($ch);

Expand Down
6 changes: 6 additions & 0 deletions endpoints/notifications/testntfynotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
}, array_keys($headers), $headers);

$url = "$host/$topic";
$ignore_ssl = $data["ignore_ssl"];

// Set the message parameters
$message = translate('test_notification', $i18n);
Expand All @@ -47,6 +48,11 @@
curl_setopt($ch, CURLOPT_HTTPHEADER, $customheaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($ignore_ssl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

// Execute the request
$response = curl_exec($ch);

Expand Down
6 changes: 6 additions & 0 deletions endpoints/notifications/testwebhooknotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$url = $data["url"];
$payload = $data["payload"];
$customheaders = json_decode($data["customheaders"], true);
$ignore_ssl = $data["ignore_ssl"];

$ch = curl_init();

Expand All @@ -40,6 +41,11 @@
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($ignore_ssl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

// Execute the request
$response = curl_exec($ch);

Expand Down
Loading

0 comments on commit 2a0e665

Please sign in to comment.