diff --git a/README.md b/README.md
index b44c673..0858552 100644
--- a/README.md
+++ b/README.md
@@ -237,7 +237,8 @@ The webhook notification can be used to make web requests (e.g. API calls) eithe
"Method": "POST",
"Authentication": "Bearer",
"Token": "XYZ.123456",
- "SendImage": "false"
+ "SendImage": false,
+ "AllowInsecureUrl": false
}
```
* Url [required]: The URL to send the image to
@@ -254,7 +255,8 @@ The webhook notification can be used to make web requests (e.g. API calls) eithe
* Bearer
* Token [optional]: The token to use when using Basic Authorization
* ImageField [optional] (Default: ```image```): The field name of the image in the POST data
-* SendImage [optional] (Default: ```true```): The image will be sent to the webhook when the method is POST, PATCH or PUT.
+* SendImage [optional] (Default: ```true```): The image will be sent to the webhook when the method is POST, PATCH or PUT
+* AllowInsecureUrl [optional] (Default: ```false```): Whether to allow an insecure HTTPS connection to the Webhook.
#### Example POST data
The following is example data for when ```SendImage``` is ```false``` and ```SynoAIUrl``` is ```"http://192.168.1.2"```.
diff --git a/SynoAI/Notifiers/Webhook/Webhook.cs b/SynoAI/Notifiers/Webhook/Webhook.cs
index 5a5983e..403fb1f 100644
--- a/SynoAI/Notifiers/Webhook/Webhook.cs
+++ b/SynoAI/Notifiers/Webhook/Webhook.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
@@ -52,6 +53,10 @@ public class Webhook : NotifierBase
/// content-type of multipart/form-data.
///
public bool SendImage { get; set; }
+ ///
+ /// Allow insecure URL Access to the API.
+ ///
+ public bool AllowInsecureUrl { get; set; }
///
/// Sends a notification to the Webhook.
@@ -62,7 +67,7 @@ public class Webhook : NotifierBase
public override async Task SendAsync(Camera camera, Notification notification, ILogger logger)
{
logger.LogInformation($"{camera.Name}: Webhook: Processing");
- using (HttpClient client = new())
+ using (HttpClient client = GetHttpClient())
{
FileStream fileStream = null;
client.DefaultRequestHeaders.Authorization = GetAuthenticationHeader();
@@ -152,6 +157,24 @@ public override async Task SendAsync(Camera camera, Notification notification, I
}
}
+ ///
+ /// Gets a object for the Webhook request.
+ ///
+ /// A .
+ private HttpClient GetHttpClient()
+ {
+ if (!Config.AllowInsecureUrl)
+ {
+ return new();
+ }
+
+ HttpClientHandler httpClientHandler = new()
+ {
+ ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => true
+ };
+ return new(httpClientHandler);
+ }
+
///
/// Generates an authentication header for the client.
///
diff --git a/SynoAI/Notifiers/Webhook/WebhookFactory.cs b/SynoAI/Notifiers/Webhook/WebhookFactory.cs
index c28ac71..22c7048 100644
--- a/SynoAI/Notifiers/Webhook/WebhookFactory.cs
+++ b/SynoAI/Notifiers/Webhook/WebhookFactory.cs
@@ -20,15 +20,17 @@ public override INotifier Create(ILogger logger, IConfigurationSection section)
string method = section.GetValue("Method", "POST");
bool sendImage = section.GetValue("SendImage", true);
bool sendTypes = section.GetValue("SendTypes", false);
+ bool allowInsecureUrl = section.GetValue("AllowInsecureUrl", false);
- Webhook webhook = new Webhook()
+ Webhook webhook = new()
{
Url = url,
Authentication = authentication,
Username = username,
Password = password,
Token = token,
- SendImage = sendImage
+ SendImage = sendImage,
+ AllowInsecureUrl = allowInsecureUrl
};
if (!string.IsNullOrWhiteSpace(imageField))