Skip to content

Commit a88a55f

Browse files
authored
Merge pull request #144 from androidseb25/dev
iGotify Notification Assistent v1.5.0.0
2 parents 12e3b04 + 3781dd7 commit a88a55f

19 files changed

Lines changed: 512 additions & 149 deletions
File renamed without changes.

Controller/DeviceController.cs

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using iGotify_Notification_Assist.Models;
22
using iGotify_Notification_Assist.Services;
33
using Microsoft.AspNetCore.Mvc;
4+
using Newtonsoft.Json;
45
using SecNtfyNuGet;
56
using Environments = iGotify_Notification_Assist.Services.Environments;
67

@@ -20,29 +21,32 @@ public async Task<IActionResult> PostDeviceModel(DeviceModel deviceModel)
2021
{
2122
string result;
2223
bool resultBool;
23-
24+
2425
Console.WriteLine($"ClientToken: {deviceModel.ClientToken}");
2526
Console.WriteLine($"DeviceToken: {deviceModel.DeviceToken}");
2627
Console.WriteLine($"GotifyUrl: {deviceModel.GotifyUrl}");
2728

2829
if (
2930
deviceModel.ClientToken.Length == 0 || deviceModel.ClientToken == "string" ||
30-
deviceModel.DeviceToken.Length == 0 || deviceModel.DeviceToken.Length < 60 || deviceModel.DeviceToken == "string" ||
31+
deviceModel.DeviceToken.Length == 0 || deviceModel.DeviceToken.Length < 60 ||
32+
deviceModel.DeviceToken == "string" ||
3133
deviceModel.GotifyUrl.Length == 0 || deviceModel.GotifyUrl == "string"
32-
)
34+
)
3335
{
3436
result = "Fehler beim hinzugefügen des Gerätes!";
3537
resultBool = false;
3638
return Ok(new { Message = result, Successful = resultBool });
3739
}
38-
40+
3941
if (await deviceModel.Insert())
4042
{
4143
GotifySocketService.getInstance();
4244
GotifySocketService.StartWsThread(deviceModel.GotifyUrl, deviceModel.ClientToken);
4345
result = "Gerät erfolgreich hinzugefügt";
4446
resultBool = true;
45-
} else {
47+
}
48+
else
49+
{
4650
result = "Fehler beim hinzugefügen des Gerätes!";
4751
resultBool = false;
4852
}
@@ -53,18 +57,18 @@ public async Task<IActionResult> PostDeviceModel(DeviceModel deviceModel)
5357
/// <summary>
5458
/// Delete device from TXT when loggin out from iGotify
5559
/// </summary>
56-
/// <param name="token"></param>
60+
/// <param name="token">Clienttoken for verify the correct entry</param>
5761
/// <returns></returns>
5862
[HttpDelete]
5963
public async Task<IActionResult> DeleteDevcice(string token)
6064
{
6165
string result;
6266
bool resultBool;
63-
67+
6468
Console.WriteLine($"Delete Token: {token}");
6569
if (token.Length == 0 || token == "string")
6670
{
67-
result = "Fehler beim löschen des Gerätes!";
71+
result = "Error deleting device!";
6872
resultBool = false;
6973
return Ok(new { Message = result, Successful = resultBool });
7074
}
@@ -79,22 +83,70 @@ public async Task<IActionResult> DeleteDevcice(string token)
7983
GotifySocketService.KillWsThread(usr.ClientToken);
8084
}
8185

82-
result = "Gerät erfolgreich gelöscht";
86+
result = "Device deleted successfully!";
8387
resultBool = true;
84-
} else {
85-
result = "Fehler beim löschen des Gerätes!";
88+
}
89+
else
90+
{
91+
result = "Error deleting device!";
8692
resultBool = false;
8793
}
88-
94+
8995
return Ok(new { Message = result, Successful = resultBool });
9096
}
91-
97+
98+
/// <summary>
99+
/// Add Custom Headers e.g. Cloudflare, Pangolin authentication
100+
/// </summary>
101+
/// <param name="customHeaders">Custome Header items</param>
102+
/// <param name="token">Clienttoken for verify the correct entry and instance</param>
103+
/// <returns></returns>
104+
[HttpPost("CustomHeaders/{token}")]
105+
public async Task<IActionResult> CustomHeaders([FromBody] List<CustomHeaders> customHeaders, string token)
106+
{
107+
string result = "";
108+
bool resultBool = false;
109+
110+
if (token == null || token.Length == 0)
111+
{
112+
resultBool = false;
113+
result = "Token not set!";
114+
return BadRequest(new { Message = result, Successful = resultBool });
115+
}
116+
117+
if (customHeaders.Count == 0)
118+
{
119+
resultBool = false;
120+
result = "CustomHeaders were not set!";
121+
return BadRequest(new { Message = result, Successful = resultBool });
122+
}
123+
124+
var usr = await DatabaseService.GetUser(token);
125+
usr.Headers = JsonConvert.SerializeObject(customHeaders);
126+
resultBool = await usr.Update();
127+
128+
if (resultBool)
129+
{
130+
var gss = GotifySocketService.getInstance();
131+
GotifySocketService.KillAllWsThread();
132+
gss.Start();
133+
result = "CustomHeaders successfully added!";
134+
}
135+
136+
return Ok(new { Message = result, Successful = resultBool });
137+
}
138+
139+
/// <summary>
140+
/// Send a Test message if remote notification work
141+
/// </summary>
142+
/// <param name="deviceToken">SecNtfy Token</param>
143+
/// <returns></returns>
92144
[HttpGet("Test/{deviceToken}")]
93145
public async Task<IActionResult> Test(string deviceToken)
94146
{
95147
var ntfy = new SecNtfy(Environments.secNtfyUrl);
96148
if (deviceToken.Length > 0)
97-
_ = await ntfy.SendNotification(deviceToken, "Test", "Test Nachricht");
149+
_ = await ntfy.SendNotification(deviceToken, "Test", "Test Notification");
98150
if (Environments.isLogEnabled)
99151
Console.WriteLine(ntfy.encTitle);
100152

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ WORKDIR /app
44
EXPOSE 5047
55
EXPOSE 7221
66

7+
# Install curl in the final runtime image
8+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
9+
710
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build
811
ARG TARGETARCH
912
WORKDIR /src
@@ -23,6 +26,9 @@ RUN dotnet publish "./iGotify Notification Assist.csproj" -c Release -a $TARGETA
2326
# final stage/image
2427
FROM base AS final
2528
WORKDIR /app
29+
30+
# Copy build output
2631
COPY --from=publish /app/publish .
32+
2733
# USER $APP_UID
2834
ENTRYPOINT ["dotnet", "iGotify Notification Assist.dll"]

Models/CustomHeaders.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace iGotify_Notification_Assist.Models;
2+
3+
public class CustomHeaders
4+
{
5+
public string Key { get; set; }
6+
public string Value { get; set; }
7+
}

Models/DeviceModel.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,23 @@ public async Task SendNotifications(GotifyMessage iGotifyMessage, WebsocketClien
4141
{
4242
var title = iGotifyMessage.title;
4343
var msg = iGotifyMessage.message;
44-
44+
4545
var protocol = webSock.Url.ToString().Contains("ws://") ? "http://" : "https://";
46-
var gotifyServerUrl = webSock.Url.ToString().Replace("ws://", "").Replace("wss://", "").Replace("\"", "").Split("/stream");
47-
var imageUrl = gotifyServerUrl.Length > 0 ? $"{protocol}{gotifyServerUrl[0]}$$${iGotifyMessage.appid}$$${webSock.Name}" : "";
48-
46+
var gotifyServerUrl = webSock.Url.ToString().Replace("ws://", "").Replace("wss://", "").Replace("\"", "")
47+
.Split("/stream");
48+
var imageUrl = gotifyServerUrl.Length > 0
49+
? $"{protocol}{gotifyServerUrl[0]}$$${iGotifyMessage.appid}$$${webSock.Name}"
50+
: "";
51+
4952
var usr = await DatabaseService.GetUser(webSock.Name!);
5053

5154
if (usr.Uid == 0)
5255
{
5356
Console.WriteLine("THERE'S SOMETHING WRONG HERE? NO USER FOUND");
5457
}
55-
58+
5659
var ntfy = new SecNtfy(Environments.secNtfyUrl);
57-
_ = ntfy.SendNotification(usr.DeviceToken, title, msg, iGotifyMessage.priority == 10, imageUrl, iGotifyMessage.priority);
60+
_ = ntfy.SendNotification(usr.DeviceToken, title, msg, iGotifyMessage.priority == 10, imageUrl,
61+
iGotifyMessage.priority);
5862
}
5963
}

Models/PragmaTableInfo.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace iGotify_Notification_Assist.Models;
2+
3+
public class PragmaTableInfo
4+
{
5+
public int Cid { get; set; }
6+
public string Name { get; set; } = "";
7+
public string Type { get; set; } = "";
8+
public int NotNull { get; set; }
9+
public string? Dflt_Value { get; set; }
10+
public int Pk { get; set; }
11+
}

Models/ThreadSocket.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using iGotify_Notification_Assist.Services;
2+
3+
namespace iGotify_Notification_Assist.Models;
4+
5+
public sealed class ThreadSocket
6+
{
7+
public ThreadSocket()
8+
{
9+
cts = new CancellationTokenSource();
10+
}
11+
12+
public Thread? thread = null;
13+
public WebSockClient? ws = null;
14+
public string? clientToken = null;
15+
public CancellationTokenSource? cts;
16+
}

Models/Users.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using iGotify_Notification_Assist.Services;
2+
13
namespace iGotify_Notification_Assist.Models;
24

35
public class Users
@@ -6,4 +8,10 @@ public class Users
68
public string ClientToken { get; init; } = "";
79
public string DeviceToken { get; init; } = "";
810
public string GotifyUrl { get; init; } = "";
11+
public string Headers { get; set; } = "";
12+
13+
public async Task<bool> Update()
14+
{
15+
return await DatabaseService.UpdateUser(this);
16+
}
917
}

Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
// Add services to the container.
1111
builder.Services.AddCors();
1212

13-
builder.Services.AddControllers(opt =>
14-
{
15-
opt.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true;
16-
})
13+
builder.Services.AddControllers(opt => { opt.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true; })
1714
.AddJsonOptions(opt =>
1815
{
1916
opt.JsonSerializerOptions.PropertyNamingPolicy = null;

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Download Link to iGotify down below
4040
* `GOTIFY_URLS` = the local gotify sever URL e.g.: `http://gotify`
4141
* `GOTIFY_CLIENT_TOKENS` = the client token from the Gotify Client e.g.: `cXXXXXXXX`
4242
* `SECNTFY_TOKENS` = the SecNtfy Token that you get from the app after configure it e.g.: `NTFY-DEVICE-XXXXXX`
43+
44+
*These three environment variables above aren't required when the Gotify & iGotify Instances available over a domain!*
45+
4346
* `ENABLE_CONSOLE_LOG` = you can disable unnecessary console logs (default: true)
4447
* `ENABLE_SCALAR_UI` = you can now disable the Endpoint page (default: true)
4548

@@ -55,8 +58,6 @@ Download Link to iGotify down below
5558
&nbsp;
5659

5760
```bash
58-
version: '3.8'
59-
6061
services:
6162
gotify:
6263
container_name: gotify
@@ -82,6 +83,11 @@ services:
8283
security_opt:
8384
- no-new-privileges:true
8485
pull_policy: always
86+
healthcheck:
87+
test: [ "CMD", "curl", "-f", "http://localhost:8080/Version" ]
88+
interval: "3s"
89+
timeout: "3s"
90+
retries: 5
8591
networks:
8692
- net
8793
ports:
@@ -122,8 +128,6 @@ Also **don't** check the boxes which say "HTTP/2 Support" and "HSTS enabled".
122128
### Traefik Config
123129

124130
```bash
125-
version: "3.8"
126-
127131
services:
128132
gotify:
129133
container_name: gotify
@@ -152,8 +156,6 @@ services:
152156
networks:
153157
default: null
154158
proxy: null
155-
volumes:
156-
- data:/app/data
157159

158160
igotify-notification: # (iGotify-Notification-Assistent)
159161
container_name: igotify
@@ -163,6 +165,11 @@ services:
163165
security_opt:
164166
- no-new-privileges:true
165167
pull_policy: always
168+
healthcheck:
169+
test: [ "CMD", "curl", "-f", "http://localhost:8080/Version" ]
170+
interval: "3s"
171+
timeout: "3s"
172+
retries: 5
166173
volumes:
167174
- api-data:/app/data
168175

0 commit comments

Comments
 (0)