Removed Satori broadcasting.

This commit is contained in:
flash 2023-09-04 14:55:27 +02:00
parent dd7b63fc24
commit b793af9157
2 changed files with 4 additions and 73 deletions

View file

@ -10,11 +10,5 @@
public string MySqlExcludeDatabases { get; set; } = @"mysql information_schema performance_schema";
public string MisuzuPath { get; set; }
public string SatoriHost { get; set; }
public ushort SatoriPort { get; set; }
public string SatoriSecret { get; set; }
public string SatoriFormat { get; set; } = @"/msg flash {0}";
public bool SatoriErrorsOnly { get; set; } = true;
}
}

View file

@ -5,15 +5,13 @@ using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace BackupManager {
namespace BackupManager
{
public static class Program {
public readonly static Stopwatch sw = new();
@ -173,14 +171,14 @@ namespace BackupManager {
SaveConfig();
sw.Stop();
Log($@"Done! Took {sw.Elapsed}.", true);
Log($@"Done! Took {sw.Elapsed}.");
#if DEBUG
Console.ReadLine();
#endif
}
public static void Log(object line, bool forceSatori = false) {
public static void Log(object line) {
if(!Headless) {
if(sw?.IsRunning == true) {
ConsoleColor fg = Console.ForegroundColor;
@ -191,9 +189,6 @@ namespace BackupManager {
Console.WriteLine(line);
}
if(forceSatori || (!Headless && !(Config?.SatoriErrorsOnly ?? true)))
SatoriBroadcast(line.ToString());
}
public static void Error(object line, int exit = 0x00DEAD00) {
@ -203,8 +198,6 @@ namespace BackupManager {
Console.ResetColor();
}
SatoriBroadcast(line.ToString(), true);
#if DEBUG
Console.ReadLine();
#endif
@ -260,61 +253,5 @@ namespace BackupManager {
File.Delete(sqldump);
}
public static void SatoriBroadcast(string text, bool error = false) {
if(string.IsNullOrEmpty(text)
|| Config == null
|| string.IsNullOrWhiteSpace(Config.SatoriHost)
|| string.IsNullOrWhiteSpace(Config.SatoriSecret)
|| Config.SatoriPort < 1)
return;
IPAddress ip = null;
try {
ip = IPAddress.Parse(Config.SatoriHost);
} catch {
try {
// forcing IPv4 here, it seems to explode with IPv6 and i don't really want to figure out why
ip = Dns.GetHostAddresses(Config.SatoriHost).FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);
} catch {
ip = null;
}
}
if(ip == null)
return;
EndPoint endPoint = new IPEndPoint(ip, Config.SatoriPort);
StringBuilder textBuilder = new();
textBuilder.AppendFormat(@"[b]Backup System[/b] [{0}]: ", Environment.MachineName);
if(error)
textBuilder.Append(@"[color=red]");
textBuilder.Append(text);
if(error)
textBuilder.Append(@"[/color]");
text = string.Format(Config.SatoriFormat, textBuilder);
byte[] opcode = new byte[1] { 1 };
byte[] hash;
using(HMACSHA256 hmac = new(Encoding.UTF8.GetBytes(Config.SatoriSecret))) {
hmac.TransformBlock(opcode, 0, opcode.Length, null, 0);
hash = Encoding.UTF8.GetBytes(text);
hmac.TransformFinalBlock(hash, 0, hash.Length);
hash = hmac.Hash;
}
using Socket sock = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
sock.NoDelay = sock.Blocking = true;
sock.Connect(endPoint);
sock.Send(hash);
sock.Send(opcode);
sock.Send(Encoding.UTF8.GetBytes(text));
}
}
}