private void CopySoftwareModule(EntityPolicyModules policyModule) { var softwareModuleExport = new DtoSoftwareModuleExport(); var softwareModule = new ServiceSoftwareModule().GetModule(policyModule.ModuleId); softwareModuleExport.DisplayName = softwareModule.Name; softwareModuleExport.Command = softwareModule.Command; softwareModuleExport.Description = softwareModule.Description; softwareModuleExport.Arguments = softwareModule.Arguments; softwareModuleExport.AdditionalArguments = softwareModule.AdditionalArguments; softwareModuleExport.Order = policyModule.Order; softwareModuleExport.Timeout = softwareModule.Timeout; softwareModuleExport.InstallType = softwareModule.InstallType; softwareModuleExport.RedirectOutput = softwareModule.RedirectStdOut; softwareModuleExport.RedirectError = softwareModule.RedirectStdError; softwareModuleExport.SuccessCodes = softwareModule.SuccessCodes; softwareModuleExport.Guid = softwareModule.Guid; softwareModuleExport.ConditionFailedAction = policyModule.ConditionFailedAction; softwareModuleExport.ConditionNextOrder = policyModule.ConditionNextModule; var uploadedFiles = new ServiceUploadedFile().GetFilesForModule(softwareModule.Guid); foreach (var file in uploadedFiles.OrderBy(x => x.Name)) { var uploadedFile = new DtoUploadedFileExport(); uploadedFile.FileName = file.Name; uploadedFile.Md5Hash = file.Hash; uploadedFile.ModuleGuid = file.Guid; softwareModuleExport.UploadedFiles.Add(uploadedFile); } var externalFiles = new ServiceExternalDownload().GetForModule(softwareModule.Guid); foreach (var file in externalFiles.OrderBy(x => x.FileName)) { var externalFile = new DtoExternalFileExport(); externalFile.FileName = file.FileName; externalFile.Sha256Hash = file.Sha256Hash; externalFile.Url = file.Url; externalFile.ModuleGuid = file.ModuleGuid; softwareModuleExport.ExternalFiles.Add(externalFile); } if (policyModule.ConditionId != -1) { softwareModuleExport.Condition = GetCondition(policyModule.ConditionId); } _policyExport.SoftwareModules.Add(softwareModuleExport); }
private void CopyCommandModule(EntityPolicyModules policyModule) { var commandModuleExport = new DtoCommandModuleExport(); var commandModule = new ServiceCommandModule().GetModule(policyModule.ModuleId); commandModuleExport.Description = commandModule.Description; commandModuleExport.Order = policyModule.Order; commandModuleExport.Command = commandModule.Command; commandModuleExport.Arguments = commandModule.Arguments; commandModuleExport.DisplayName = commandModule.Name; commandModuleExport.Timeout = commandModule.Timeout; commandModuleExport.RedirectOutput = commandModule.RedirectStdOut; commandModuleExport.RedirectError = commandModule.RedirectStdError; commandModuleExport.WorkingDirectory = commandModule.WorkingDirectory; commandModuleExport.SuccessCodes = commandModule.SuccessCodes; commandModuleExport.Guid = commandModule.Guid; commandModuleExport.ConditionFailedAction = policyModule.ConditionFailedAction; commandModuleExport.ConditionNextOrder = policyModule.ConditionNextModule; var uploadedFiles = new ServiceUploadedFile().GetFilesForModule(commandModule.Guid); foreach (var file in uploadedFiles.OrderBy(x => x.Name)) { var uploadedFile = new DtoUploadedFileExport(); uploadedFile.FileName = file.Name; uploadedFile.Md5Hash = file.Hash; uploadedFile.ModuleGuid = file.Guid; commandModuleExport.UploadedFiles.Add(uploadedFile); } var externalFiles = new ServiceExternalDownload().GetForModule(commandModule.Guid); foreach (var file in externalFiles.OrderBy(x => x.FileName)) { var externalFile = new DtoExternalFileExport(); externalFile.FileName = file.FileName; externalFile.Sha256Hash = file.Sha256Hash; externalFile.Url = file.Url; externalFile.ModuleGuid = file.ModuleGuid; commandModuleExport.ExternalFiles.Add(externalFile); } if (policyModule.ConditionId != -1) { commandModuleExport.Condition = GetCondition(policyModule.ConditionId); } _policyExport.CommandModules.Add(commandModuleExport); }
private void CopyFileCopyModule(EntityPolicyModules policyModule) { var fileCopyModuleExport = new DtoFileCopyModuleExport(); var fileCopyModule = new ServiceFileCopyModule().GetModule(policyModule.ModuleId); fileCopyModuleExport.DisplayName = fileCopyModule.Name; fileCopyModuleExport.Description = fileCopyModule.Description; fileCopyModuleExport.Destination = fileCopyModule.Destination; fileCopyModuleExport.Order = policyModule.Order; fileCopyModuleExport.Unzip = fileCopyModule.DecompressAfterCopy; fileCopyModuleExport.Guid = fileCopyModule.Guid; fileCopyModuleExport.ConditionFailedAction = policyModule.ConditionFailedAction; fileCopyModuleExport.ConditionNextOrder = policyModule.ConditionNextModule; var uploadedFiles = new ServiceUploadedFile().GetFilesForModule(fileCopyModule.Guid); foreach (var file in uploadedFiles.OrderBy(x => x.Name)) { var uploadedFile = new DtoUploadedFileExport(); uploadedFile.FileName = file.Name; uploadedFile.Md5Hash = file.Hash; uploadedFile.ModuleGuid = file.Guid; fileCopyModuleExport.UploadedFiles.Add(uploadedFile); } var externalFiles = new ServiceExternalDownload().GetForModule(fileCopyModule.Guid); foreach (var file in externalFiles.OrderBy(x => x.FileName)) { var externalFile = new DtoExternalFileExport(); externalFile.FileName = file.FileName; externalFile.Sha256Hash = file.Sha256Hash; externalFile.Url = file.Url; externalFile.ModuleGuid = file.ModuleGuid; fileCopyModuleExport.ExternalFiles.Add(externalFile); } if (policyModule.ConditionId != -1) { fileCopyModuleExport.Condition = GetCondition(policyModule.ConditionId); } _policyExport.FileCopyModules.Add(fileCopyModuleExport); }
private string VerifySoftware(EntityPolicyModules policyModule) { var softwareModule = new ServiceSoftwareModule().GetModule(policyModule.ModuleId); if (string.IsNullOrEmpty(softwareModule.Name)) { return("A Software Module Has An Invalid Name"); } if (softwareModule.Archived) { return("Software Module: " + softwareModule.Name + " Is Archived"); } if (string.IsNullOrEmpty(softwareModule.Guid)) { return("Software Module: " + softwareModule.Name + " Has An Invalid GUID"); } int value; if (!int.TryParse(softwareModule.Timeout.ToString(), out value)) { return("Software Module: " + softwareModule.Name + " Has An Invalid Timeout"); } if (string.IsNullOrEmpty(softwareModule.Command)) { return("Software Module: " + softwareModule.Name + " Has An Invalid Command"); } if (!int.TryParse(policyModule.Order.ToString(), out value)) { return("Software Module: " + softwareModule.Name + " Has An Invalid Order"); } List <string> successCodes = new List <string>(); foreach (var successCode in softwareModule.SuccessCodes.Split(',')) { successCodes.Add(successCode); } if (successCodes.Count == 0) { return("Software Module: " + softwareModule.Name + " Has An Invalid Success Code"); } if (successCodes.Any(code => !int.TryParse(code, out value))) { return("Software Module: " + softwareModule.Name + " Has An Invalid Success Code"); } var uploadedFiles = new ServiceUploadedFile().GetFilesForModule(softwareModule.Guid); var externalFiles = new ServiceExternalDownload().GetForModule(softwareModule.Guid); if (uploadedFiles == null && externalFiles == null) { return("Software Module: " + softwareModule.Name + " Does Not Have Any Associated Files"); } try { if (uploadedFiles.Count == 0 && externalFiles.Count == 0) { return("Software Module: " + softwareModule.Name + " Does Not Have Any Associated Files"); } } catch { return("Software Module: " + softwareModule.Name + " Error While Determining Associated Files"); } var basePath = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads"); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { try { foreach (var file in uploadedFiles.OrderBy(x => x.Name)) { if (string.IsNullOrEmpty(file.Hash)) { return("Software Module: " + softwareModule.Name + " " + file.Name + " Does Not Have An MD5 Hash"); } var fullPath = Path.Combine(basePath, file.Guid, file.Name); if (!File.Exists(fullPath)) { return("Software Module: " + softwareModule.Name + " " + fullPath + " Does Not Exist"); } } foreach (var file in externalFiles.OrderBy(x => x.FileName)) { if (file.Status != EnumFileDownloader.DownloadStatus.Complete) { return("Software Module: " + softwareModule.Name + " " + file.FileName + " Has Not Finished Downloading Or Is In An Error State"); } if (string.IsNullOrEmpty(file.Md5Hash)) { return("Software Module: " + softwareModule.Name + " " + file.FileName + " Does Not Have An MD5 Hash"); } var fullPath = Path.Combine(basePath, file.ModuleGuid, file.FileName); if (!File.Exists(fullPath)) { return("Software Module: " + softwareModule.Name + " " + fullPath + " Does Not Exist"); } } } catch (Exception ex) { Logger.Debug(ex.Message); return("Software Module: " + softwareModule.Name + " Unknown Error Trying To Verify Files"); } } else { return("Could Not Reach Storage Path"); } } if (softwareModule.ImpersonationId != -1) { var impAccount = new ServiceImpersonationAccount().GetAccount(softwareModule.ImpersonationId); if (impAccount == null) { return("Software Module: " + softwareModule.Name + " Has An Invalid Impersonation Account"); } } return(null); }
private string VerifyWindowsUpdate(EntityPolicyModules policyModule) { var wuModule = new ServiceWuModule().GetModule(policyModule.ModuleId); if (string.IsNullOrEmpty(wuModule.Name)) { return("A Windows Update Module Has An Invalid Name"); } if (wuModule.Archived) { return("Windows Update Module: " + wuModule.Name + " Is Archived"); } if (string.IsNullOrEmpty(wuModule.Guid)) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid GUID"); } int value; if (!int.TryParse(wuModule.Timeout.ToString(), out value)) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid Timeout"); } if (!int.TryParse(policyModule.Order.ToString(), out value)) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid Order"); } List <string> successCodes = new List <string>(); foreach (var successCode in wuModule.SuccessCodes.Split(',')) { successCodes.Add(successCode); } if (successCodes.Count == 0) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid Success Code"); } if (successCodes.Any(code => !int.TryParse(code, out value))) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid Success Code"); } var uploadedFiles = new ServiceUploadedFile().GetFilesForModule(wuModule.Guid); var externalFiles = new ServiceExternalDownload().GetForModule(wuModule.Guid); if (uploadedFiles == null && externalFiles == null) { return("Windows Update Module: " + wuModule.Name + " Does Not Have Any Associated Files"); } try { if (uploadedFiles.Count == 0 && externalFiles.Count == 0) { return("Windows Update Module: " + wuModule.Name + " Does Not Have Any Associated Files"); } } catch { return("Windows Update Module: " + wuModule.Name + " Error While Determining Associated Files"); } var firstExtension = ""; int uploadFileCounter = 0; foreach (var file in uploadedFiles) { var ext = Path.GetExtension(file.Name); if (ext == null) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid File Extension In The Uploaded Files List"); } if (!ext.ToLower().Equals(".cab") && !ext.ToLower().Equals(".msu")) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid File Extension In The Uploaded Files List"); } if (uploadFileCounter == 0) { firstExtension = ext; } else { if (!firstExtension.Equals(ext)) { return("Windows Update Module: " + wuModule.Name + " All Files Per Windows Update Module Must Be The Same Type. IE. All .msu Or All .cab"); } } uploadFileCounter++; } int externalFileCounter = 0; foreach (var file in externalFiles) { var ext = Path.GetExtension(file.FileName); if (ext == null) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid File Extension In The External Files List"); } if (!ext.ToLower().Equals(".cab") && !ext.ToLower().Equals(".msu")) { return("Windows Update Module: " + wuModule.Name + " Has An Invalid File Extension In The External Files List"); } if (uploadFileCounter == 0 && string.IsNullOrEmpty(firstExtension)) //don't overwrite extension that may have been set in uploaded files { firstExtension = ext; } else { if (!firstExtension.Equals(ext)) { return("Windows Update Module: " + wuModule.Name + " All Files Per Windows Update Module Must Be The Same Type. IE. All .msu Or All .cab"); } } externalFileCounter++; } var basePath = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads"); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { try { foreach (var file in uploadedFiles.OrderBy(x => x.Name)) { if (string.IsNullOrEmpty(file.Hash)) { return("Windows Update Module: " + wuModule.Name + " " + file.Name + " Does Not Have An MD5 Hash"); } var fullPath = Path.Combine(basePath, file.Guid, file.Name); if (!File.Exists(fullPath)) { return("Windows Update Module: " + wuModule.Name + " " + fullPath + " Does Not Exist"); } } foreach (var file in externalFiles.OrderBy(x => x.FileName)) { if (file.Status != EnumFileDownloader.DownloadStatus.Complete) { return("Windows Update Module: " + wuModule.Name + " " + file.FileName + " Has Not Finished Downloading Or Is In An Error State"); } if (string.IsNullOrEmpty(file.Md5Hash)) { return("Windows Update Module: " + wuModule.Name + " " + file.FileName + " Does Not Have An MD5 Hash"); } var fullPath = Path.Combine(basePath, file.ModuleGuid, file.FileName); if (!File.Exists(fullPath)) { return("Windows Update Module: " + wuModule.Name + " " + fullPath + " Does Not Exist"); } } } catch (Exception ex) { Logger.Debug(ex.Message); return("Windows Update Module: " + wuModule.Name + " Unknown Error Trying To Verify Files"); } } else { return("Could Not Reach Storage Path"); } } return(null); }