This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
updateGateway.cs
78 lines (72 loc) · 2.89 KB
/
updateGateway.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Net.Http;
using System.Net.Mail;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace GatewayPing
{
public class UpdateGateway
{
public static async Task Update(string currentGateway, string newGateway)
{
string from = "status@satowa-network.eu";
string to = "it@satowa-network.eu";
var gateways = new[]
{
new { Name = "Gateway Vienna 21", Host = "gateway-vie-21.satowa-network.dev"},
new { Name = "Gateway Innsbruck 02", Host = "gateway-il-02.satowa-network.eu"},
new { Name = "Gateway Frankfurt", Host = "gateway-f-100.satowa-network.eu" }
};
string zoneID = "b0ac2333c3d3b486e917ef3f54bea126";
string dnsID = "908058f3832db6d80c2388c927fff232";
string apiKey = "";
if (from == gateways[0].Host)
{
// Erstellen Sie den PUT-Antrag
var apiUrl = $"https://api.cloudflare.com/client/v4/zones/{zoneID}/dns_records/{dnsID}";
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var requestData = new
{
content = newGateway,
data = new { },
name = "gateway.satowa-network.eu",
proxiable = true,
proxied = true,
ttl = 1,
type = "CNAME",
zone_id = zoneID,
zone_name = "satowa-network.eu",
tags = new string[] { }
};
var jsonContent = JsonSerializer.Serialize(requestData);
var httpContent = new StringContent(jsonContent, Encoding.UTF8, "application/json");
var response = await client.PutAsync(apiUrl, httpContent);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Gateway erfolgreich aktualisiert.");
}
else
{
Console.WriteLine("Fehler beim Aktualisieren des Gateways: " + response.ReasonPhrase);
}
}
else
{
MailMessage message = new MailMessage(from, to);
message.Subject = "Down";
SmtpClient client = new SmtpClient("mail.satowa-network.eu");
client.Credentials = new System.Net.NetworkCredential("status@satowa-network.eu", "ieneSsANtaNC,16,;");
try
{
client.Send(message);
}
catch (Exception e)
{
Console.WriteLine($"Beim Senden der E-Mail ist ein Fehler aufgetreten: {e.ToString()}");
}
}
}
}
}