private void DownloadRemotelyFile(string remotelyUrl, string fileName) { var destinationDir = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads", "99999999-9999-9999-9999-999999999999"); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { var directory = new DirectoryInfo(destinationDir); try { if (!directory.Exists) { directory.Create(); } using (var webClient = new WebClient()) { webClient.DownloadFile(new Uri(remotelyUrl + "/Downloads/" + fileName), Path.Combine(destinationDir, fileName)); } } catch (Exception ex) { return; } } else { return; } } }
public void SendLockOutEmail(int userId) { //Mail not enabled if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } var lockedUser = GetUser(userId); foreach (var user in SearchUsers(new DtoSearchFilter()).Where(x => !string.IsNullOrEmpty(x.Email))) { if (user.Membership != "Administrator" && user.Id != userId) { continue; } var mail = new MailServices { MailTo = user.Email, Body = lockedUser.Name + " Has Been Locked For 15 Minutes Because Of Too Many Failed Login Attempts", Subject = "User Locked" }; mail.Send(); } }
public byte[] GenerateComCert(int comServerId) { var comServer = GetServer(comServerId); if (comServer == null) { return(null); } var iCert = new ServiceCertificate().GetIntermediate(); var site = new Uri(comServer.Url); var intermediateEntity = new ServiceCertificate().GetIntermediateEntity(); var pass = new EncryptionServices().DecryptText(intermediateEntity.Password); var intermediateCert = new X509Certificate2(intermediateEntity.PfxBlob, pass, X509KeyStorageFlags.Exportable); var certRequest = new CertificateRequest(); var organization = ServiceSetting.GetSettingValue(SettingStrings.CertificateOrganization); certRequest.SubjectName = string.Format($"CN={site.Host}"); certRequest.NotBefore = DateTime.UtcNow; certRequest.NotAfter = certRequest.NotBefore.AddYears(10); var certificate = new ServiceGenerateCertificate(certRequest).IssueCertificate(intermediateCert, false, true); var bytes = certificate.Export(X509ContentType.Pfx); return(bytes); }
public void SendTaskErrorEmail(EntityActiveImagingTask task, string error) { //Mail not enabled if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } var computer = new ServiceComputer().GetComputer(task.ComputerId); foreach ( var user in _userServices.GetAll().Where(x => !string.IsNullOrEmpty(x.Email))) { var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList(); if (rights.Any(right => right == AuthorizationStrings.EmailImagingTaskFailed)) { if (task.UserId == user.Id) { if (computer == null) { computer = new EntityComputer(); computer.Name = "Unknown Computer"; } var mail = new MailServices { MailTo = user.Email, Body = computer.Name + " Image Task Has Failed. " + error, Subject = "Task Failed" }; mail.Send(); } } } }
public void SendMulticastCompletedEmail(EntityActiveMulticastSession session) { //Mail not enabled if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) == "0") { return; } foreach ( var user in _userServices.GetAll().Where(x => !string.IsNullOrEmpty(x.Email))) { var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList(); if (rights.Any(right => right == AuthorizationStrings.EmailImagingTaskCompleted)) { if (session.UserId == user.Id) { var mail = new MailServices { MailTo = user.Email, Body = session.Name + " Multicast Task Has Completed.", Subject = "Multicast Completed" }; mail.Send(); } } } }
public bool CollectInventory(int id) { var computer = _uow.ComputerRepository.GetById(id); if (computer == null) { return(false); } if (computer.CertificateId == -1) { return(false); } var socket = _uow.ActiveSocketRepository.GetFirstOrDefault(x => x.ComputerId == computer.Id); if (socket != null) { var deviceCertEntity = _uow.CertificateRepository.GetById(computer.CertificateId); var deviceCert = new X509Certificate2(deviceCertEntity.PfxBlob, new EncryptionServices().DecryptText(deviceCertEntity.Password), X509KeyStorageFlags.Exportable); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var socketRequest = new DtoSocketRequest(); socketRequest.connectionIds.Add(socket.ConnectionId); socketRequest.action = "Collect_Inventory"; new APICall().ClientComServerApi.SendAction(socket.ComServer, "", decryptedKey, socketRequest); } return(true); }
public bool EditBootFileText(DtoCoreScript script) { var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var comServer = new ServiceClientComServer().GetServer(script.ComServerId); return(new APICall().ClientComServerApi.EditBootFileText(comServer.Url, "", decryptedKey, script)); }
public string GetBootFileText(string path, int comServerId) { var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var comServer = new ServiceClientComServer().GetServer(comServerId); return(new APICall().ClientComServerApi.ReadBootFileText(comServer.Url, "", decryptedKey, path)); }
public bool KillProcess(int comServerId, int pid) { var comServer = _uow.ClientComServerRepository.GetById(comServerId); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.KillProcess(comServer.Url, "", decryptedKey, pid)); }
public List <DtoReplicationProcess> GetReplicationProcesses(int comServerId) { var comServer = _uow.ClientComServerRepository.GetById(comServerId); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.GetReplicationProcesses(comServer.Url, "", decryptedKey)); }
public bool VerifyRemoteAccessInstalled(int comServerId) { var comServer = _uow.ClientComServerRepository.GetById(comServerId); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.VerifyRemoteAccessInstalled(comServer.Url, "", decryptedKey)); }
public DtoActionResult Delete(int multicastId) { var multicast = _uow.ActiveMulticastSessionRepository.GetById(multicastId); if (multicast == null) { return new DtoActionResult { ErrorMessage = "Multicast Not Found", Id = 0 } } ; var computers = _uow.ActiveImagingTaskRepository.MulticastComputers(multicastId); var actionResult = new DtoActionResult(); _uow.ActiveMulticastSessionRepository.Delete(multicastId); _uow.Save(); actionResult.Id = multicast.Id; actionResult.Success = true; new ServiceActiveImagingTask().DeleteForMulticast(multicastId); if (computers != null) { foreach (var computer in computers) { if (computer != null) { new CleanTaskBootFiles().Execute(computer); } } } var comServer = new ServiceClientComServer().GetServer(multicast.ComServerId); if (comServer == null) { actionResult.Success = false; Logger.Error("Could Not find com Server With ID " + multicast.ComServerId); return(actionResult); } var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); if (!new APICall().ClientComServerApi.TerminateMulticast(comServer.Url, "", decryptedKey, multicast)) { actionResult.Success = false; } return(actionResult); }
public DtoActionResult Delete(int id) { var u = Get(id); if (u == null) { return new DtoActionResult { ErrorMessage = "Attachment Not Found", Id = 0 } } ; _uow.AttachmentRepository.Delete(id); _uow.Save(); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { try { if (string.IsNullOrEmpty(u.DirectoryGuid) || string.IsNullOrEmpty(u.Name) || u.DirectoryGuid == Path.DirectorySeparatorChar.ToString() || u.Name == Path.DirectorySeparatorChar.ToString()) { //ignored } else { var storagePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); File.Delete(Path.Combine(storagePath, "attachments", u.DirectoryGuid, u.Name)); var dirFiles = Directory.GetFiles(Path.Combine(storagePath, "attachments", u.DirectoryGuid)); if (dirFiles.Length == 0) { Directory.Delete(Path.Combine(storagePath, "attachments", u.DirectoryGuid)); } } } catch { //ignored } } } var actionResult = new DtoActionResult(); actionResult.Success = true; actionResult.Id = u.Id; return(actionResult); } }
public DtoActionResult DeleteUnregisteredOndTask(int activeImagingTaskId) { var activeImagingTask = _uow.ActiveImagingTaskRepository.GetById(activeImagingTaskId); if (activeImagingTask == null) { return new DtoActionResult { ErrorMessage = "Task Not Found", Id = 0 } } ; if (activeImagingTask.ComputerId > -1) { return new DtoActionResult { ErrorMessage = "This Task Is Not An On Demand Task And Cannot Be Cancelled", Id = 0 } } ; _uow.ActiveImagingTaskRepository.Delete(activeImagingTask.Id); _uow.Save(); var actionResult = new DtoActionResult(); actionResult.Success = true; actionResult.Id = activeImagingTaskId; if (activeImagingTask.Type.Contains("upload")) { var comServer = _uow.ClientComServerRepository.GetById(activeImagingTask.ComServerId); if (comServer == null) { return(actionResult); } var receiverPids = _uow.ActiveMulticastSessionRepository.Get(x => x.UploadTaskId == activeImagingTask.Id).Select(x => x.Pid).ToList(); _uow.ActiveMulticastSessionRepository.DeleteRange(x => x.UploadTaskId == activeImagingTask.Id); _uow.Save(); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); new APICall().ClientComServerApi.KillUdpReceiver(comServer.Url, "", decryptedKey, receiverPids); } return(actionResult); }
public bool CopyMsiToClientUpdate() { foreach (var type in new List <bool> { true, false }) { var msi = new ServiceMsiUpdater().UpdateMsis(is64bit: type); var fileName = new ServiceMsiUpdater().GetNameForExport(is64bit: type); var destinationDir = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "client_versions"); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { var directory = new DirectoryInfo(destinationDir); try { if (!directory.Exists) { directory.Create(); } File.WriteAllBytes(Path.Combine(destinationDir, fileName), msi); } catch (Exception ex) { Logger.Error(ex.Message); return(false); } } else { return(false); } } } return(true); }
public void CancelTimedOutTasks() { var timeout = ServiceSetting.GetSettingValue(SettingStrings.ImageTaskTimeoutMinutes); if (string.IsNullOrEmpty(timeout)) { return; } if (timeout == "0") { return; } var tasks = GetAll(); foreach (var task in tasks) { if (DateTime.UtcNow > task.LastUpdateTimeUTC.AddMinutes(Convert.ToInt32(timeout))) { DeleteActiveImagingTask(task.Id); log.Debug("Task Timeout Hit. Task " + task.Id + "Cancelled. Computer Id " + task.ComputerId); } } }
public bool SendLowDiskSpaceReport() { if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) != "1") { return(true); } var uow = new UnitOfWork(); var sb = new StringBuilder(); var errorsFound = false; var comServers = new Workflows.ComServerFreeSpace().RunAllServers(); sb.Append("The Following Com Servers Have Low Disk Space:\r\n\r\n"); foreach (var comServer in comServers) { if (comServer.freePercent < 20) { errorsFound = true; sb.Append(comServer.name + "\t" + comServer.freePercent + "% Free"); } } if (!errorsFound) { return(true); } var emailList = new List <string>(); var users = uow.UserRepository.Get(); foreach (var user in users) { if (user.Membership.Equals("Administrator")) { if (!string.IsNullOrEmpty(user.Email)) { emailList.Add(user.Email); } } else { var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList(); if (rights.Any(right => right == AuthorizationStrings.EmailLowDiskSpace)) { if (!string.IsNullOrEmpty(user.Email)) { emailList.Add(user.Email); } } } } foreach (var email in emailList) { var mail = new MailServices { Subject = "Com Server Low Disk Space", Body = sb.ToString(), MailTo = email }; mail.Send(); } return(true); }
public bool SendSmartReport() { if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) != "1") { return(true); } var uow = new UnitOfWork(); var computers = uow.ComputerRepository.Get(x => x.ProvisionStatus == EnumProvisionStatus.Status.Provisioned); if (computers.Count == 0) { return(true); } var sb = new StringBuilder(); var errorsFound = false; sb.Append("The Following Hard Drives Have A Failed S.M.A.R.T. Status:\r\n\r\n"); foreach (var computer in computers) { var localComputer = computer; var hdds = uow.HardDriveInventoryRepository.Get(x => x.ComputerId == localComputer.Id); foreach (var hdd in hdds) { if (!hdd.Status.ToLower().Equals("ok")) { errorsFound = true; sb.Append(computer.Name + "\t" + hdd.Model + "\t" + hdd.SerialNumber + "\t" + hdd.Status + Environment.NewLine); } } } if (!errorsFound) { return(true); } var emailList = new List <string>(); var users = uow.UserRepository.Get(); foreach (var user in users) { if (user.Membership.Equals("Administrator")) { if (!string.IsNullOrEmpty(user.Email)) { emailList.Add(user.Email); } } else { var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList(); if (rights.Any(right => right == AuthorizationStrings.EmailSmart)) { if (!string.IsNullOrEmpty(user.Email)) { emailList.Add(user.Email); } } } } foreach (var email in emailList) { var mail = new MailServices { Subject = "S.M.A.R.T Failure Report", Body = sb.ToString(), MailTo = email }; mail.Send(); } return(true); }
public bool GenerateCAandInt() { var isAllowed = ConfigurationManager.AppSettings["AllowCAGen"]; if (!isAllowed.ToLower().Equals("true")) { Logger.Debug("Certificates cannot be generated without updating the web.config key AllowCAGen"); return(false); } var certRequest = new CertificateRequest(); var organization = new ServiceSetting().GetSetting(SettingStrings.CertificateOrganization); if (organization == null) { return(false); } if (string.IsNullOrEmpty(organization.Value)) { return(false); } certRequest.SubjectName = string.Format("O={0},CN=Toems CA", organization.Value); certRequest.NotBefore = DateTime.UtcNow; certRequest.NotAfter = certRequest.NotBefore.AddYears(20); var authCertificate = new ServiceGenerateCertificate(certRequest).CreateCertificateAuthorityCertificate(); var c = new EntityCertificate(); c.NotAfter = authCertificate.NotAfter; c.NotBefore = authCertificate.NotBefore; c.Serial = authCertificate.SerialNumber; var pfxPass = Membership.GeneratePassword(10, 0); c.Password = new EncryptionServices().EncryptText(pfxPass); c.PfxBlob = authCertificate.Export(X509ContentType.Pfx, pfxPass); c.SubjectName = authCertificate.Subject; c.Type = EnumCertificate.CertificateType.Authority; var existingCA = _uow.CertificateRepository.GetFirstOrDefault(x => x.Type == EnumCertificate.CertificateType.Authority); if (existingCA != null) { _uow.CertificateRepository.Delete(existingCA.Id); } _uow.CertificateRepository.Insert(c); //intermediate var intRequest = new CertificateRequest(); intRequest.SubjectName = string.Format("O={0},CN=Toems Intermediate", organization.Value); intRequest.NotBefore = DateTime.UtcNow; intRequest.NotAfter = intRequest.NotBefore.AddYears(20); var intCertificate = new ServiceGenerateCertificate(intRequest).IssueCertificate(authCertificate, true, false); var ce = new EntityCertificate(); ce.NotAfter = intCertificate.NotAfter; ce.NotBefore = intCertificate.NotBefore; ce.Serial = intCertificate.SerialNumber; var pfxPassInt = Membership.GeneratePassword(10, 0); ce.Password = new EncryptionServices().EncryptText(pfxPassInt); ce.PfxBlob = intCertificate.Export(X509ContentType.Pfx, pfxPassInt); ce.SubjectName = intCertificate.Subject; ce.Type = EnumCertificate.CertificateType.Intermediate; var existingInt = _uow.CertificateRepository.GetFirstOrDefault(x => x.Type == EnumCertificate.CertificateType.Intermediate); if (existingInt != null) { _uow.CertificateRepository.Delete(existingInt.Id); } _uow.CertificateRepository.Insert(ce); _uow.Save(); return(true); }
public bool SendApprovalRequestReport() { if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) != "1") { return(true); } var approvalRequests = _uow.ApprovalRequestRepository.Get(); if (approvalRequests.Count == 0) { return(true); } var sb = new StringBuilder(); sb.Append("The Following Computers Are Pending Approval:\r\n\r\n"); foreach (var approvalRequest in approvalRequests) { sb.Append(approvalRequest.ComputerName + "\t" + approvalRequest.RequestTime + "\t" + approvalRequest.IpAddress + Environment.NewLine); } var emailList = new List <string>(); var users = _uow.UserRepository.Get(); foreach (var user in users) { if (user.Membership.Equals("Administrator")) { if (!string.IsNullOrEmpty(user.Email)) { emailList.Add(user.Email); } } else { var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList(); if (rights.Any(right => right == AuthorizationStrings.EmailReset)) { if (!string.IsNullOrEmpty(user.Email)) { emailList.Add(user.Email); } } } } foreach (var email in emailList) { var mail = new MailServices { Subject = "Approval Request Report", Body = sb.ToString(), MailTo = email }; mail.Send(); } return(true); }
public static string GetSettingValue(string settingName) { var setting = new ServiceSetting().GetSetting(settingName); return(setting != null ? setting.Value : string.Empty); }
public DtoActionResult RunHealthCheck() { var comServer = _uow.ClientComServerRepository.Get(x => x.IsRemoteAccessServer).FirstOrDefault(); if (comServer == null) { return(new DtoActionResult() { ErrorMessage = "No Active Remote Access Servers Were Found" }); } //check connection to remotely api var status = new APICall().RemoteAccessApi.RemotelyStatus(comServer.RemoteAccessUrl); if (status == null) { return new DtoActionResult() { ErrorMessage = "Could Not Contact Remote Access API" } } ; status = status.Replace("\"", ""); status = status.Replace("\\", ""); if (status != "true") { return(new DtoActionResult() { ErrorMessage = "Could Not Contact Remote Access API" }); } //check api connection with auth header, should return false with fake device id var auth = new EncryptionServices().DecryptText(comServer.RaAuthHeaderEncrypted); var online = new APICall().RemoteAccessApi.RemotelyIsDeviceOnline(comServer.RemoteAccessUrl, "abc", auth); if (online == null) { return new DtoActionResult() { ErrorMessage = "Remote Access API Unauthorized" } } ; online = online.Replace("\"", ""); online = online.Replace("\\", ""); if (online != "false") { return new DtoActionResult() { ErrorMessage = "Remote Access API Unauthorized" } } ; //verify files exist var basePath = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads", "99999999-9999-9999-9999-999999999999"); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { try { var installer = Path.Combine(basePath, "Remotely_Installer.exe"); var x64 = Path.Combine(basePath, "Remotely-Win10-x64.zip"); var x86 = Path.Combine(basePath, "Remotely-Win10-x86.zip"); //no need to check if exists, exception will catch when looking for size var hasSize = new FileInfo(installer).Length > 0; if (!hasSize) { return new DtoActionResult() { ErrorMessage = "Remotely_Installer.exe Is Missing From Storage Path" } } ; hasSize = new FileInfo(x64).Length > 0; if (!hasSize) { return new DtoActionResult() { ErrorMessage = "Remotely x64 File Is Missing From Storage Path" } } ; hasSize = new FileInfo(x86).Length > 0; if (!hasSize) { return new DtoActionResult() { ErrorMessage = "Remotely x86 File Is Missing From Storage Path" } } ; } catch { return(new DtoActionResult() { ErrorMessage = "Remote Access Files Have Not Been Copied To The Storage Path" }); } } else { return(new DtoActionResult() { ErrorMessage = "Could Not Determine If Remote Access Installer Files Are Available" }); } } return(new DtoActionResult() { Success = true }); } } }
public List <DtoServerImageRepStatus> GetReplicationStatus(int imageId) { var list = new List <DtoServerImageRepStatus>(); var image = GetImage(imageId); var comServers = _uow.ClientComServerRepository.Get(x => x.IsImagingServer); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); foreach (var com in comServers) { var status = new DtoServerImageRepStatus(); status.Servername = com.DisplayName; var hasImage = new APICall().ClientComServerApi.CheckImageExists(com.Url, "", decryptedKey, imageId); if (hasImage) { status.Status = "Replicated"; } else { status.Status = "Not Replicated"; } list.Add(status); } //check if images already exist on smb share var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { var imagePath = Path.Combine(basePath, "images", image.Name); var guidPath = Path.Combine(imagePath, "guid"); if (File.Exists(guidPath)) { using (StreamReader reader = new StreamReader(guidPath)) { var fileGuid = reader.ReadLine() ?? ""; if (fileGuid.Equals(image.LastUploadGuid)) { var status = new DtoServerImageRepStatus(); status.Servername = basePath.Replace(@"\", "\\"); status.Status = "Replicated"; list.Add(status); } else { var status = new DtoServerImageRepStatus(); status.Servername = basePath.Replace(@"\", "\\"); status.Status = "Not Replicated"; list.Add(status); } } } else { var status = new DtoServerImageRepStatus(); status.Servername = basePath.Replace(@"\", "\\"); status.Status = "Not Replicated"; list.Add(status); } } } return(list); }