Stuart Johnson 6 months ago
parent
commit
bb43ac0e37

+ 13 - 24
.vs/TFA-Bot/xs/UserPrefs.xml

@@ -2,31 +2,23 @@
   <MonoDevelop.Ide.ItemProperties.TFA-Bot PreferredExecutionTarget="MonoDevelop.Default" />
   <MonoDevelop.Ide.Workbench ActiveDocument="TFA-Bot Status">
     <Files>
-      <File FileName="TFA-Bot/DataClasses/clsSSLCerts.cs" Line="14" Column="41" />
-      <File FileName="TFA-Bot/DataClasses/clsSetting.cs" Line="1" Column="1" />
-      <File FileName="TFA-Bot/DataClasses/clsNotificationPolicy.cs" Line="1" Column="1" />
-      <File FileName="TFA-Bot/Spreadsheet/clsSpreadsheet.cs" Line="31" Column="1" />
-      <File FileName="TFA-Bot/Spreadsheet/clsSpreadsheetReader.cs" Line="44" Column="1" />
-      <File FileName="TFA-Bot/DataClasses/clsNode.cs" Line="192" Column="1" />
-      <File FileName="TFA-Bot/DataClasses/clsUser.cs" Line="1" Column="1" />
-      <File FileName="TFA-Bot/Program.cs" Line="181" Column="52" />
-      <File FileName="TFA-Bot/clsAlarm.cs" Line="82" Column="65" />
-      <File FileName="TFA-Bot/clsSSLCertMonitor.cs" Line="95" Column="76" />
-      <File FileName="TFA-Bot/DiscordBot/Commands/clsSSL.cs" Line="50" Column="77" />
-      <File FileName="TFA-Bot/DiscordBot/clsBotClient.cs" Line="105" Column="1" />
-      <File FileName="TFA-Bot/clsEmail.cs" Line="42" Column="23" />
-      <File FileName="TFA-Bot/Spreadsheet/ASheetColumnHeader.cs" Line="23" Column="35" />
-      <File FileName="TFA-Bot/DiscordBot/Commands/clsHelp.cs" Line="24" Column="60" />
-      <File FileName="TFA-Bot/DiscordBot/clsCommands.cs" Line="115" Column="17" />
-      <File FileName="TFA-Bot/clsExtenstions.cs" Line="1" Column="1" />
-      <File FileName="TFA-Bot/Git/clsGitHead.cs" Line="1" Column="1" />
+      <File FileName="TFA-Bot/Program.cs" Line="11" Column="7" />
+      <File FileName="Dockerfile" Line="33" Column="42" />
+      <File FileName="TFA-Bot/DiscordBot/clsCommands.cs" Line="9" Column="28" />
+      <File FileName="TFA-Bot/DiscordBot/clsBotClient.cs" Line="67" Column="59" />
+      <File FileName="TFA-Bot/DataClasses/clsSSLCerts.cs" Line="24" Column="83" />
+      <File FileName="TFA-Bot/Git/clsGitBranchInfo.cs" Line="1" Column="1" />
+      <File FileName="TFA-Bot/clsSSLCertMonitor.cs" Line="104" Column="76" />
+      <File FileName="TFA-Bot/packages.config" Line="1" Column="1" />
       <File FileName="TFA-Bot Status" />
     </Files>
     <Pads>
       <Pad Id="ProjectPad">
         <State name="__root__">
-          <Node name="TFA-Bot" expanded="True" selected="True">
-            <Node name="Solution Items" expanded="True" />
+          <Node name="TFA-Bot" expanded="True">
+            <Node name="Solution Items" expanded="True">
+              <Node name="/HOME/Projects/TFA-Bot/.gitignore" selected="True" />
+            </Node>
             <Node name="TFA-Bot" expanded="True">
               <Node name="Packages" expanded="True" />
               <Node name="DataClasses" expanded="True" />
@@ -49,10 +41,7 @@
   <MonoDevelop.Ide.DebuggingService.PinnedWatches />
   <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
   <MonoDevelop.Ide.DebuggingService.Breakpoints>
-    <BreakpointStore>
-      <Breakpoint file="/HOME/Projects/TFA-Bot/TFA-Bot/DiscordBot/Commands/clsSSL.cs" relfile="TFA-Bot/DiscordBot/Commands/clsSSL.cs" line="71" column="33" />
-      <Breakpoint file="/HOME/Projects/TFA-Bot/TFA-Bot/clsSSLCertMonitor.cs" relfile="TFA-Bot/clsSSLCertMonitor.cs" line="89" column="70" />
-    </BreakpointStore>
+    <BreakpointStore />
   </MonoDevelop.Ide.DebuggingService.Breakpoints>
   <MultiItemStartupConfigurations />
 </Properties>

+ 3 - 1
TFA-Bot/DataClasses/clsSSLCerts.cs

@@ -13,10 +13,12 @@ namespace TFABot
         public String URL {get;set;}
         [ASheetColumnHeader("contacts")]
         public String Contacts {get;set;}
+        [ASheetColumnHeader("monitor")]
+        public bool Monitor { get; set; }
         
         public DateTime? CertExpiry {get;set;}
         
-        
+
         public void Update(clsSSLCerts user)
         {
             if (URL != user.URL) throw new Exception("index name does not match");

+ 23 - 35
TFA-Bot/TFA-Bot.csproj

@@ -7,7 +7,7 @@
     <OutputType>Exe</OutputType>
     <RootNamespace>TFABot</RootNamespace>
     <AssemblyName>TFA-Bot</AssemblyName>
-    <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     <DebugSymbols>true</DebugSymbols>
@@ -33,33 +33,6 @@
     <Reference Include="mscorlib" />
     <Reference Include="System.Web" />
     <Reference Include="System.Net.Http" />
-    <Reference Include="DSharpPlus">
-      <HintPath>..\packages\DSharpPlus.3.2.3\lib\net46\DSharpPlus.dll</HintPath>
-    </Reference>
-    <Reference Include="DSharpPlus.CommandsNext">
-      <HintPath>..\packages\DSharpPlus.CommandsNext.3.2.3\lib\net46\DSharpPlus.CommandsNext.dll</HintPath>
-    </Reference>
-    <Reference Include="DSharpPlus.Interactivity">
-      <HintPath>..\packages\DSharpPlus.Interactivity.3.2.3\lib\net46\DSharpPlus.Interactivity.dll</HintPath>
-    </Reference>
-    <Reference Include="DSharpPlus.WebSocket.WebSocketSharp">
-      <HintPath>..\packages\DSharpPlus.WebSocket.WebSocketSharp.3.2.3\lib\net46\DSharpPlus.WebSocket.WebSocketSharp.dll</HintPath>
-    </Reference>
-    <Reference Include="DSharpPlus.CommandsNext">
-      <HintPath>..\packages\DSharpPlus.CommandsNext.3.2.3\lib\net46\DSharpPlus.CommandsNext.dll</HintPath>
-    </Reference>
-    <Reference Include="DSharpPlus">
-      <HintPath>..\packages\DSharpPlus.3.2.3\lib\net46\DSharpPlus.dll</HintPath>
-    </Reference>
-    <Reference Include="DSharpPlus.Interactivity">
-      <HintPath>..\packages\DSharpPlus.Interactivity.3.2.3\lib\net46\DSharpPlus.Interactivity.dll</HintPath>
-    </Reference>
-    <Reference Include="DSharpPlus.WebSocket.WebSocketSharp">
-      <HintPath>..\packages\DSharpPlus.WebSocket.WebSocketSharp.3.2.3\lib\net46\DSharpPlus.WebSocket.WebSocketSharp.dll</HintPath>
-    </Reference>
-    <Reference Include="System.ValueTuple">
-      <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
-    </Reference>
     <Reference Include="websocket-sharp">
       <HintPath>..\packages\WebSocketSharp-NonPreRelease.1.0.0\lib\net35\websocket-sharp.dll</HintPath>
     </Reference>
@@ -79,13 +52,7 @@
       <HintPath>..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll</HintPath>
     </Reference>
     <Reference Include="Newtonsoft.Json">
-      <HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
-    </Reference>
-    <Reference Include="MimeKit">
-      <HintPath>..\packages\MimeKit.2.4.0.1\lib\net46\MimeKit.dll</HintPath>
-    </Reference>
-    <Reference Include="MailKit">
-      <HintPath>..\packages\MailKit.2.4.0.1\lib\net46\MailKit.dll</HintPath>
+      <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
     <Reference Include="RestSharp">
       <HintPath>..\packages\RestSharp.106.6.10\lib\net452\RestSharp.dll</HintPath>
@@ -93,6 +60,27 @@
     <Reference Include="LibGit2Sharp">
       <HintPath>..\packages\LibGit2Sharp.0.26.1\lib\net46\LibGit2Sharp.dll</HintPath>
     </Reference>
+    <Reference Include="DSharpPlus">
+      <HintPath>..\packages\DSharpPlus.3.2.3\lib\net47\DSharpPlus.dll</HintPath>
+    </Reference>
+    <Reference Include="DSharpPlus.CommandsNext">
+      <HintPath>..\packages\DSharpPlus.CommandsNext.3.2.3\lib\net47\DSharpPlus.CommandsNext.dll</HintPath>
+    </Reference>
+    <Reference Include="DSharpPlus.Interactivity">
+      <HintPath>..\packages\DSharpPlus.Interactivity.3.2.3\lib\net47\DSharpPlus.Interactivity.dll</HintPath>
+    </Reference>
+    <Reference Include="MailKit">
+      <HintPath>..\packages\MailKit.2.4.1\lib\net47\MailKit.dll</HintPath>
+    </Reference>
+    <Reference Include="MimeKit">
+      <HintPath>..\packages\MimeKit.2.4.1\lib\net47\MimeKit.dll</HintPath>
+    </Reference>
+    <Reference Include="System.ValueTuple">
+      <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
+    </Reference>
+    <Reference Include="DSharpPlus.WebSocket.WebSocketSharp">
+      <HintPath>..\packages\DSharpPlus.WebSocket.WebSocketSharp.3.2.3\lib\net47\DSharpPlus.WebSocket.WebSocketSharp.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Program.cs" />

+ 12 - 5
TFA-Bot/clsSSLCertMonitor.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Linq;
 using System.Net;
+using System.Net.Cache;
 using System.Net.Http;
 using System.Security.Cryptography.X509Certificates;
 using System.Threading.Tasks;
@@ -20,7 +21,10 @@ namespace TFABot
 
         internal static void HeartbeatCheck(bool force = false)
         {
-            if (force || !LastTest.HasValue || (DateTime.UtcNow - LastTest.Value).Hours >= 24)
+
+            var hoursSinceLastTest = LastTest.HasValue ? (DateTime.UtcNow - LastTest.Value).Hours : int.MaxValue;
+        
+            if (force || hoursSinceLastTest >= 24)
             {
                 Console.WriteLine("clsSSLCertMonitor: HeartbeatCheck");
                 LastTest = DateTime.UtcNow;
@@ -29,13 +33,13 @@ namespace TFABot
                 {
                     foreach (var ssl in Program.SSLCertsList.Values)
                     {
-                        CheckSSL(ssl, force || DateTime.UtcNow.Hour==0);
+                        if (ssl.Monitor) CheckSSL(ssl);
                     }
                 });
             }
         }
 
-        private static async void CheckSSL(clsSSLCerts ssl, bool report)
+        private static async void CheckSSL(clsSSLCerts ssl)
         {       
             try
             {
@@ -45,6 +49,9 @@ namespace TFABot
                 var uri = new Uri(url);
 
                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
+                RequestCachePolicy policy = new  RequestCachePolicy( RequestCacheLevel.BypassCache);
+                request.AllowAutoRedirect = true;
+                request.CachePolicy = policy;
 
                 HttpWebResponse response;
                 try
@@ -61,13 +68,13 @@ namespace TFABot
                 ssl.CertExpiry = DateTime.Parse(cert2.GetExpirationDateString());
                 var days = (ssl.CertExpiry - DateTime.UtcNow).Value.Days;
 
-                if (report && days <= 7) SendMessage(ssl, $"{ssl.URL} certificate expires in {days} days");
+                if (days <= 7) SendMessage(ssl, $"{ssl.URL} certificate expires in {days} days");
                 
             }
             catch (Exception ex)
             {
                 var errorMsg = $"{ssl.URL} certificate read error: {ex.Message}";
-                if (report) SendMessage(ssl, errorMsg);
+                SendMessage(ssl, errorMsg);
                 Console.WriteLine(errorMsg);
             }
         }

+ 8 - 8
TFA-Bot/packages.config

@@ -1,16 +1,16 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="BouncyCastle" version="1.8.5" targetFramework="net462" />
-  <package id="DSharpPlus" version="3.2.3" targetFramework="net462" />
-  <package id="DSharpPlus.CommandsNext" version="3.2.3" targetFramework="net462" />
-  <package id="DSharpPlus.Interactivity" version="3.2.3" targetFramework="net462" />
-  <package id="DSharpPlus.WebSocket.WebSocketSharp" version="3.2.3" targetFramework="net462" />
+  <package id="DSharpPlus" version="3.2.3" targetFramework="net471" />
+  <package id="DSharpPlus.CommandsNext" version="3.2.3" targetFramework="net471" />
+  <package id="DSharpPlus.Interactivity" version="3.2.3" targetFramework="net471" />
+  <package id="DSharpPlus.WebSocket.WebSocketSharp" version="3.2.3" targetFramework="net471" />
   <package id="LibGit2Sharp" version="0.26.1" targetFramework="net46" />
   <package id="LibGit2Sharp.NativeBinaries" version="2.0.289" targetFramework="net46" />
-  <package id="MailKit" version="2.4.0.1" targetFramework="net462" />
-  <package id="MimeKit" version="2.4.0.1" targetFramework="net462" />
-  <package id="Newtonsoft.Json" version="12.0.2" targetFramework="net462" />
+  <package id="MailKit" version="2.4.1" targetFramework="net471" />
+  <package id="MimeKit" version="2.4.1" targetFramework="net471" />
+  <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net46" />
   <package id="RestSharp" version="106.6.10" targetFramework="net462" />
-  <package id="System.ValueTuple" version="4.5.0" targetFramework="net462" requireReinstallation="true" />
+  <package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
   <package id="WebSocketSharp-NonPreRelease" version="1.0.0" targetFramework="net462" />
 </packages>