Removed Satori broadcasting.
This commit is contained in:
parent
dd7b63fc24
commit
b793af9157
2 changed files with 4 additions and 73 deletions
|
@ -10,11 +10,5 @@
|
||||||
public string MySqlExcludeDatabases { get; set; } = @"mysql information_schema performance_schema";
|
public string MySqlExcludeDatabases { get; set; } = @"mysql information_schema performance_schema";
|
||||||
|
|
||||||
public string MisuzuPath { get; set; }
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,13 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace BackupManager {
|
namespace BackupManager
|
||||||
|
{
|
||||||
public static class Program {
|
public static class Program {
|
||||||
public readonly static Stopwatch sw = new();
|
public readonly static Stopwatch sw = new();
|
||||||
|
|
||||||
|
@ -173,14 +171,14 @@ namespace BackupManager {
|
||||||
|
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
Log($@"Done! Took {sw.Elapsed}.", true);
|
Log($@"Done! Took {sw.Elapsed}.");
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Log(object line, bool forceSatori = false) {
|
public static void Log(object line) {
|
||||||
if(!Headless) {
|
if(!Headless) {
|
||||||
if(sw?.IsRunning == true) {
|
if(sw?.IsRunning == true) {
|
||||||
ConsoleColor fg = Console.ForegroundColor;
|
ConsoleColor fg = Console.ForegroundColor;
|
||||||
|
@ -191,9 +189,6 @@ namespace BackupManager {
|
||||||
|
|
||||||
Console.WriteLine(line);
|
Console.WriteLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(forceSatori || (!Headless && !(Config?.SatoriErrorsOnly ?? true)))
|
|
||||||
SatoriBroadcast(line.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Error(object line, int exit = 0x00DEAD00) {
|
public static void Error(object line, int exit = 0x00DEAD00) {
|
||||||
|
@ -203,8 +198,6 @@ namespace BackupManager {
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
SatoriBroadcast(line.ToString(), true);
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
#endif
|
#endif
|
||||||
|
@ -260,61 +253,5 @@ namespace BackupManager {
|
||||||
|
|
||||||
File.Delete(sqldump);
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue