Adjusted BoatCom protocol use, I have not tested this :D

This commit is contained in:
flash 2023-04-12 04:19:12 +02:00
parent 8bf5a00a40
commit cbe982ba77
3 changed files with 19 additions and 23 deletions

View file

@ -16,6 +16,7 @@
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

@ -287,39 +287,34 @@ namespace BackupManager {
EndPoint endPoint = new IPEndPoint(ip, Config.SatoriPort);
StringBuilder textBuilder = new StringBuilder();
StringBuilder textBuilder = new();
textBuilder.AppendFormat(@"[b]Backup System[/b] [{0}]: ", Environment.MachineName);
if (error)
if(error)
textBuilder.Append(@"[color=red]");
textBuilder.Append(text);
if (error)
if(error)
textBuilder.Append(@"[/color]");
text = textBuilder.ToString();
text = string.Format(Config.SatoriFormat, textBuilder);
StringBuilder messageBuilder = new StringBuilder();
using (HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(Config.SatoriSecret))) {
byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(text));
foreach (byte b in hash)
messageBuilder.AppendFormat(@"{0:x2}", b);
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;
}
messageBuilder.Append(text);
string message = messageBuilder.ToString();
byte[] messageBytes = new byte[Encoding.UTF8.GetByteCount(message) + 2];
messageBytes[0] = messageBytes[messageBytes.Length - 1] = 0x0F;
Encoding.UTF8.GetBytes(message).CopyTo(messageBytes, 1);
using (Socket sock = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) {
sock.NoDelay = sock.Blocking = true;
sock.Connect(endPoint);
sock.Send(messageBytes);
}
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));
}
}
}

View file

@ -1,5 +1,5 @@
cwd="$(pwd)"
export DOTNET_CLI_TELEMETRY_OPTOUT=1
cd "$(dirname "$0")"
dotnet run --project BackupManager -c Release -f net5.0 -- -cron
dotnet run --project BackupManager -c Release -f net6.0 -- -cron
cd "$cwd"