1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Separated ScanUploads from main of maintainence program.

This commit is contained in:
Uncled1023 2016-05-09 16:49:01 -07:00
parent d5c85add89
commit 73c621667b

View File

@ -15,15 +15,16 @@ namespace ServerMaint
{
public class Program
{
private static string currentPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
private static string parentPath = Directory.GetParent(currentPath).FullName;
private static string virusFile = Path.Combine(currentPath, "virusLogs.txt");
private static string errorFile = Path.Combine(currentPath, "errorLogs.txt");
private static string configPath = Path.Combine(parentPath, "App_Data");
public static event Action<string> OutputEvent;
public static void Main(string[] args)
{
string currentPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string parentPath = Directory.GetParent(currentPath).FullName;
string logFile = Path.Combine(currentPath, "virusLogs.txt");
string errorFile = Path.Combine(currentPath, "errorLogs.txt");
string configPath = Path.Combine(parentPath, "App_Data");
// Let's clean some stuff!!
try
@ -33,6 +34,19 @@ namespace ServerMaint
// Scan all the uploads for viruses, and remove the bad ones
if (config.UploadConfig.VirusScanEnable)
{
ScanUploads(config, db);
}
}
catch (Exception ex)
{
string msg = string.Format("[{0}] Exception: {1}", DateTime.Now, ex.Message);
File.AppendAllLines(errorFile, new List<string> { msg });
Output(msg);
}
}
public static void ScanUploads(Config config, TeknikEntities db)
{
List<Upload> uploads = db.Uploads.ToList();
@ -71,7 +85,7 @@ namespace ServerMaint
case ClamScanResults.VirusDetected:
totalViruses++;
string msg = string.Format("[{0}] Virus Detected: {1} - {2} - {3}", DateTime.Now, upload.Url, upload.FileName, scanResult.InfectedFiles.First().VirusName);
File.AppendAllLines(logFile, new List<string> { msg });
File.AppendAllLines(virusFile, new List<string> { msg });
Output(msg);
//// Delete from the DB
//db.Uploads.Remove(upload);
@ -95,18 +109,10 @@ namespace ServerMaint
break;
}
}
}
Output(string.Format("Scanning Complete. {0} Scanned | {1} Viruses Found | {2} Total Files", totalScans, totalViruses, totalCount));
}
}
catch (Exception ex)
{
string msg = string.Format("[{0}] Exception: {1}", DateTime.Now, ex.Message);
File.AppendAllLines(errorFile, new List<string> { msg });
Output(msg);
}
}
public static void Output(string message)
{