Adjusted BoatCom protocol use, I have not tested this :D
This commit is contained in:
parent
8bf5a00a40
commit
cbe982ba77
3 changed files with 19 additions and 23 deletions
|
@ -16,6 +16,7 @@
|
||||||
public string SatoriHost { get; set; }
|
public string SatoriHost { get; set; }
|
||||||
public ushort SatoriPort { get; set; }
|
public ushort SatoriPort { get; set; }
|
||||||
public string SatoriSecret { get; set; }
|
public string SatoriSecret { get; set; }
|
||||||
|
public string SatoriFormat { get; set; } = @"/msg flash {0}";
|
||||||
public bool SatoriErrorsOnly { get; set; } = true;
|
public bool SatoriErrorsOnly { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,39 +287,34 @@ namespace BackupManager {
|
||||||
|
|
||||||
EndPoint endPoint = new IPEndPoint(ip, Config.SatoriPort);
|
EndPoint endPoint = new IPEndPoint(ip, Config.SatoriPort);
|
||||||
|
|
||||||
StringBuilder textBuilder = new StringBuilder();
|
StringBuilder textBuilder = new();
|
||||||
textBuilder.AppendFormat(@"[b]Backup System[/b] [{0}]: ", Environment.MachineName);
|
textBuilder.AppendFormat(@"[b]Backup System[/b] [{0}]: ", Environment.MachineName);
|
||||||
|
|
||||||
if (error)
|
if(error)
|
||||||
textBuilder.Append(@"[color=red]");
|
textBuilder.Append(@"[color=red]");
|
||||||
|
|
||||||
textBuilder.Append(text);
|
textBuilder.Append(text);
|
||||||
|
|
||||||
if (error)
|
if(error)
|
||||||
textBuilder.Append(@"[/color]");
|
textBuilder.Append(@"[/color]");
|
||||||
|
|
||||||
text = textBuilder.ToString();
|
text = string.Format(Config.SatoriFormat, textBuilder);
|
||||||
|
|
||||||
StringBuilder messageBuilder = new StringBuilder();
|
byte[] opcode = new byte[1] { 1 };
|
||||||
|
byte[] hash;
|
||||||
using (HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(Config.SatoriSecret))) {
|
using(HMACSHA256 hmac = new(Encoding.UTF8.GetBytes(Config.SatoriSecret))) {
|
||||||
byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(text));
|
hmac.TransformBlock(opcode, 0, opcode.Length, null, 0);
|
||||||
|
hash = Encoding.UTF8.GetBytes(text);
|
||||||
foreach (byte b in hash)
|
hmac.TransformFinalBlock(hash, 0, hash.Length);
|
||||||
messageBuilder.AppendFormat(@"{0:x2}", b);
|
hash = hmac.Hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
messageBuilder.Append(text);
|
using Socket sock = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
string message = messageBuilder.ToString();
|
sock.NoDelay = sock.Blocking = true;
|
||||||
byte[] messageBytes = new byte[Encoding.UTF8.GetByteCount(message) + 2];
|
sock.Connect(endPoint);
|
||||||
messageBytes[0] = messageBytes[messageBytes.Length - 1] = 0x0F;
|
sock.Send(hash);
|
||||||
Encoding.UTF8.GetBytes(message).CopyTo(messageBytes, 1);
|
sock.Send(opcode);
|
||||||
|
sock.Send(Encoding.UTF8.GetBytes(text));
|
||||||
using (Socket sock = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) {
|
|
||||||
sock.NoDelay = sock.Blocking = true;
|
|
||||||
sock.Connect(endPoint);
|
|
||||||
sock.Send(messageBytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
cwd="$(pwd)"
|
cwd="$(pwd)"
|
||||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||||
cd "$(dirname "$0")"
|
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"
|
cd "$cwd"
|
||||||
|
|
Reference in a new issue