diff --git a/Seppuku.Client.Windows.CLI/Program.cs b/Seppuku.Client.Windows.CLI/Program.cs index 4adccd4..62cd7da 100644 --- a/Seppuku.Client.Windows.CLI/Program.cs +++ b/Seppuku.Client.Windows.CLI/Program.cs @@ -10,6 +10,7 @@ using Quartz.Impl; using Seppuku.Module; using Seppuku.Module.Config; +using Seppuku.Module.Standard; namespace Seppuku.Client.Windows.CLI { @@ -113,15 +114,15 @@ public static void UpdateLastReset(JObject data) { L.Info("response received from seppuku server"); L.Info("{0}", data.ToString()); - switch ((int)data["status"]) + switch ((StatusCode)(int)data["status"]) { - case 0: + case StatusCode.Success: NotificationIcon.ShowBalloonTip(5000, "Seppuku Reset", "Deadman's switch has been reset!", ToolTipIcon.Info); break; - case -1: - NotificationIcon.ShowBalloonTip(5000, "Seppuku Failure", "Deadman's switch has activated!", ToolTipIcon.Error); + case StatusCode.Expired: + NotificationIcon.ShowBalloonTip(5000, "Seppuku Failure", "Deadman's switch is already expired!", ToolTipIcon.Error); break; - case -999: + case StatusCode.Unauthorized: NotificationIcon.ShowBalloonTip(5000, "Seppuku Failure", "The authorization token is invalid!", ToolTipIcon.Error); break; } diff --git a/Seppuku.Module/SeppukuModule.cs b/Seppuku.Module/SeppukuModule.cs index ce12a24..28eac73 100644 --- a/Seppuku.Module/SeppukuModule.cs +++ b/Seppuku.Module/SeppukuModule.cs @@ -17,6 +17,7 @@ public abstract class SeppukuModule private static readonly NLog.Logger L = NLog.LogManager.GetCurrentClassLogger(); public const string ModuleConfigDirectory = "Configuration"; + public const int TokenDivision = 60 * 60; public string Name { get; set; } public string Description { get; set; } @@ -47,7 +48,7 @@ public virtual void OnStop() { } public static string GetCurrentToken(string secret) { - byte[] byteArray = Encoding.ASCII.GetBytes(DateTime.UtcNow.Date.ToLongDateString()); + byte[] byteArray = BitConverter.GetBytes((long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds / TokenDivision)); using (HMACSHA1 hmacsha1 = new HMACSHA1(Encoding.ASCII.GetBytes(secret))) { return hmacsha1.ComputeHash(byteArray).Aggregate("", (s, e) => s + $"{e:x2}", s => s); diff --git a/Seppuku/Program.cs b/Seppuku/Program.cs index f79baee..d9add0d 100644 --- a/Seppuku/Program.cs +++ b/Seppuku/Program.cs @@ -20,7 +20,7 @@ private static void Main(string[] args) Configuration.ConfigurationFileName); L.Info("Secret key is {0}", Configuration.Get("Secret")); - L.Info("Today's auth token is {0}", SeppukuModule.GetCurrentToken(Configuration.Get("Secret"))); + L.Info("Auth token is {0} for the next {1} second(s)", SeppukuModule.GetCurrentToken(Configuration.Get("Secret")), SeppukuModule.TokenDivision); // load scheduling information from global configuration Sched.Initialize();