Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit b6fdadc

Browse files
author
Dan Done
committed
#185 - Adding config to allow insecure HTTPS connections for webhooks.
1 parent 5a5f533 commit b6fdadc

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ The webhook notification can be used to make web requests (e.g. API calls) eithe
237237
"Method": "POST",
238238
"Authentication": "Bearer",
239239
"Token": "XYZ.123456",
240-
"SendImage": "false"
240+
"SendImage": false,
241+
"AllowInsecureUrl": false
241242
}
242243
```
243244
* 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
254255
* Bearer
255256
* Token [optional]: The token to use when using Basic Authorization
256257
* ImageField [optional] (Default: ```image```): The field name of the image in the POST data
257-
* SendImage [optional] (Default: ```true```): The image will be sent to the webhook when the method is POST, PATCH or PUT.
258+
* SendImage [optional] (Default: ```true```): The image will be sent to the webhook when the method is POST, PATCH or PUT
259+
* AllowInsecureUrl [optional] (Default: ```false```): Whether to allow an insecure HTTPS connection to the Webhook.
258260

259261
#### Example POST data
260262
The following is example data for when ```SendImage``` is ```false``` and ```SynoAIUrl``` is ```"http://192.168.1.2"```.

SynoAI/Notifiers/Webhook/Webhook.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.IO;
8+
using System.Net;
89
using System.Net.Http;
910
using System.Net.Http.Headers;
1011
using System.Text;
@@ -52,6 +53,10 @@ public class Webhook : NotifierBase
5253
/// content-type of multipart/form-data.
5354
/// </summary>
5455
public bool SendImage { get; set; }
56+
/// <summary>
57+
/// Allow insecure URL Access to the API.
58+
/// </summary>
59+
public bool AllowInsecureUrl { get; set; }
5560

5661
/// <summary>
5762
/// Sends a notification to the Webhook.
@@ -62,7 +67,7 @@ public class Webhook : NotifierBase
6267
public override async Task SendAsync(Camera camera, Notification notification, ILogger logger)
6368
{
6469
logger.LogInformation($"{camera.Name}: Webhook: Processing");
65-
using (HttpClient client = new())
70+
using (HttpClient client = GetHttpClient())
6671
{
6772
FileStream fileStream = null;
6873
client.DefaultRequestHeaders.Authorization = GetAuthenticationHeader();
@@ -152,6 +157,24 @@ public override async Task SendAsync(Camera camera, Notification notification, I
152157
}
153158
}
154159

160+
/// <summary>
161+
/// Gets a <see cref="HttpClient"/> object for the Webhook request.
162+
/// </summary>
163+
/// <returns>A <see cref="HttpClient"/>.</returns>
164+
private HttpClient GetHttpClient()
165+
{
166+
if (!Config.AllowInsecureUrl)
167+
{
168+
return new();
169+
}
170+
171+
HttpClientHandler httpClientHandler = new()
172+
{
173+
ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => true
174+
};
175+
return new(httpClientHandler);
176+
}
177+
155178
/// <summary>
156179
/// Generates an authentication header for the client.
157180
/// </summary>

SynoAI/Notifiers/Webhook/WebhookFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ public override INotifier Create(ILogger logger, IConfigurationSection section)
2020
string method = section.GetValue<string>("Method", "POST");
2121
bool sendImage = section.GetValue<bool>("SendImage", true);
2222
bool sendTypes = section.GetValue<bool>("SendTypes", false);
23+
bool allowInsecureUrl = section.GetValue("AllowInsecureUrl", false);
2324

24-
Webhook webhook = new Webhook()
25+
Webhook webhook = new()
2526
{
2627
Url = url,
2728
Authentication = authentication,
2829
Username = username,
2930
Password = password,
3031
Token = token,
31-
SendImage = sendImage
32+
SendImage = sendImage,
33+
AllowInsecureUrl = allowInsecureUrl
3234
};
3335

3436
if (!string.IsNullOrWhiteSpace(imageField))

0 commit comments

Comments
 (0)