From 5a5f5337f3618139d322b559d8e7790f1469528e Mon Sep 17 00:00:00 2001 From: djdd87 Date: Tue, 7 Feb 2023 10:47:11 +0000 Subject: [PATCH 1/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 69c7253..b44c673 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,8 @@ The Deepstack API is a free to use AI that can identify objects, faces and more. ### CodeProject.AI-Server +For a full list of supported types see the [CodeProject.AI documentation](https://www.codeproject.com/AI/docs/api/api_reference.html). + ```json "AI": { "Type": "CodeProjectAIServer", From b6fdadc54b54bebece3a7866283873a465781684 Mon Sep 17 00:00:00 2001 From: Dan Done Date: Wed, 22 Mar 2023 10:31:46 +0000 Subject: [PATCH 2/5] #185 - Adding config to allow insecure HTTPS connections for webhooks. --- README.md | 6 ++++-- SynoAI/Notifiers/Webhook/Webhook.cs | 25 +++++++++++++++++++++- SynoAI/Notifiers/Webhook/WebhookFactory.cs | 6 ++++-- 3 files changed, 32 insertions(+), 5 deletions(-) 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)) From 405eea3296c8f0dadb8e761659e7f6abebb6cc4b Mon Sep 17 00:00:00 2001 From: Dan Done Date: Wed, 22 Mar 2023 10:37:54 +0000 Subject: [PATCH 3/5] #182 Catching exception from Webhook requests to prevent the container falling over. --- SynoAI/Notifiers/Webhook/Webhook.cs | 46 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/SynoAI/Notifiers/Webhook/Webhook.cs b/SynoAI/Notifiers/Webhook/Webhook.cs index 403fb1f..f83a6a6 100644 --- a/SynoAI/Notifiers/Webhook/Webhook.cs +++ b/SynoAI/Notifiers/Webhook/Webhook.cs @@ -118,26 +118,34 @@ public override async Task SendAsync(Camera camera, Notification notification, I logger.LogInformation($"{camera.Name}: Webhook: Calling {Method}."); HttpResponseMessage response; - switch (Method) + try { - case "DELETE": - response = await client.DeleteAsync(Url); - break; - case "GET": - response = await client.GetAsync(Url); - break; - case "PATCH": - response = await client.PatchAsync(Url, content); - break; - case "POST": - response = await client.PostAsync(Url, content); - break; - case "PUT": - response = await client.PutAsync(Url, content); - break; - default: - logger.LogError($"{camera.Name}: Webhook: The method type '{Method}' is not supported."); - return; + switch (Method) + { + case "DELETE": + response = await client.DeleteAsync(Url); + break; + case "GET": + response = await client.GetAsync(Url); + break; + case "PATCH": + response = await client.PatchAsync(Url, content); + break; + case "POST": + response = await client.PostAsync(Url, content); + break; + case "PUT": + response = await client.PutAsync(Url, content); + break; + default: + logger.LogError($"{camera.Name}: Webhook: The method type '{Method}' is not supported."); + return; + } + } + catch (Exception ex) + { + logger.LogError($"{camera.Name}: Webhook: Unhandled Exception occurred '{ex.Message}'."); + return; } if (response.IsSuccessStatusCode) From 0a4d1e804e22a82a24080f7b6f5cf033f769aaa1 Mon Sep 17 00:00:00 2001 From: djdd87 Date: Tue, 29 Aug 2023 08:35:15 +0100 Subject: [PATCH 4/5] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0858552..69ceb8a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# UPDATE! +I've begun working on a new version of SynoAI from the group up which has an administrative interface instead of a config based approach. I will also be taking the opportunity to implement a number of requested features that have been requested for a long time. + # SynoAI A Synology Surveillance Station notification system utilising DeepStack AI, inspired by Christopher Adams' [sssAI](https://github.com/Christofo/sssAI) implementation. From 13bae31a90fe2ad8482a9bf9a7e970dba9fca006 Mon Sep 17 00:00:00 2001 From: djdd87 Date: Tue, 29 Aug 2023 14:10:54 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69ceb8a..df0e885 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# UPDATE! -I've begun working on a new version of SynoAI from the group up which has an administrative interface instead of a config based approach. I will also be taking the opportunity to implement a number of requested features that have been requested for a long time. +# UPDATE 2023-08-29 +I've begun working on a new version of SynoAI from the ground up which has an administrative interface instead of a config based approach. I will also be taking the opportunity to implement a number of requested features that have been requested for a long time. # SynoAI A Synology Surveillance Station notification system utilising DeepStack AI, inspired by Christopher Adams' [sssAI](https://github.com/Christofo/sssAI) implementation.