Ejemplo n.º 1
0
        public DtoActionResult UpdateModule(EntityScriptModule module)
        {
            var u = GetModule(module.Id);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Module Not Found", Id = 0
                }
            }
            ;
            var isActiveModule = new ServiceModule().IsModuleActive(module.Id, EnumModule.ModuleType.Script);

            if (!string.IsNullOrEmpty(isActiveModule))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = isActiveModule, Id = 0
                       }
            }
            ;
            if (!module.IsCondition && u.IsCondition)
            {
                //condition has been removed, check for policies with this condition
                var modulesWithCondition = _uow.PolicyModulesRepository.Get(x => x.ConditionId == u.Id);

                foreach (var m in modulesWithCondition)
                {
                    m.ConditionId = -1;
                    _uow.PolicyModulesRepository.Update(m, m.Id);
                }


                var policiesWithCondition = _uow.PolicyRepository.Get(x => x.ConditionId == u.Id);
                foreach (var policy in policiesWithCondition)
                {
                    policy.ConditionId = -1;
                    _uow.PolicyRepository.Update(policy, policy.Id);
                }
            }
            var validationResult = ValidateModule(module, false);
            var actionResult     = new DtoActionResult();

            if (validationResult.Success)
            {
                _uow.ScriptModuleRepository.Update(module, module.Id);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = module.Id;
            }
            else
            {
                actionResult.ErrorMessage = validationResult.ErrorMessage;
            }

            return(actionResult);
        }
Ejemplo n.º 2
0
        public DtoActionResult DeleteModule(int moduleId)
        {
            var u = GetModule(moduleId);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Module Not Found", Id = 0
                }
            }
            ;
            var isActiveModule = new ServiceModule().IsModuleActive(moduleId, EnumModule.ModuleType.Script);

            if (!string.IsNullOrEmpty(isActiveModule))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = isActiveModule, Id = 0
                       }
            }
            ;
            if (string.IsNullOrEmpty(u.Guid))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = "Unknown Guid", Id = 0
                       }
            }
            ;
            _uow.ModuleRepository.DeleteRange(x => x.Guid == u.Guid);
            //_uow.ScriptModuleRepository.Delete(moduleId);

            var modulesWithCondition = _uow.PolicyModulesRepository.Get(x => x.ConditionId == u.Id);

            foreach (var module in modulesWithCondition)
            {
                module.ConditionId = -1;

                _uow.PolicyModulesRepository.Update(module, module.Id);
            }

            var policiesWithCondition = _uow.PolicyRepository.Get(x => x.ConditionId == u.Id);

            foreach (var policy in policiesWithCondition)
            {
                policy.ConditionId = -1;
                _uow.PolicyRepository.Update(policy, policy.Id);
            }

            _uow.Save();
            var actionResult = new DtoActionResult();

            actionResult.Success = true;
            actionResult.Id      = u.Id;
            return(actionResult);
        }
Ejemplo n.º 3
0
        public DtoActionResult DeleteModule(int moduleId)
        {
            var u = GetModule(moduleId);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Module Not Found", Id = 0
                }
            }
            ;
            var isActiveModule = new ServiceModule().IsModuleActive(moduleId, EnumModule.ModuleType.Software);

            if (!string.IsNullOrEmpty(isActiveModule))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = isActiveModule, Id = 0
                       }
            }
            ;
            if (string.IsNullOrEmpty(u.Guid))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = "Unknown Guid", Id = 0
                       }
            }
            ;
            _uow.ModuleRepository.DeleteRange(x => x.Guid == u.Guid);
            //_uow.SoftwareModuleRepository.Delete(moduleId);
            _uow.Save();
            var actionResult          = new DtoActionResult();
            var deleteDirectoryResult = new FilesystemServices().DeleteModuleDirectory(u.Guid);

            if (deleteDirectoryResult)
            {
                actionResult.Success = true;

                actionResult.Id = u.Id;
            }
            else
            {
                actionResult.Success      = false;
                actionResult.ErrorMessage =
                    "Module Has Been Deleted But File System Cleanup Has Failed.  You Must Manually Delete Folder " + u.Guid;
            }


            return(actionResult);
        }
Ejemplo n.º 4
0
        public DtoActionResult Delete(int downloadId)
        {
            var u = GetDownload(downloadId);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "External Download Not Found", Id = 0
                }
            }
            ;

            var f = new ServiceModule().GetModuleIdFromGuid(u.ModuleGuid);

            if (f != null)
            {
                var isActive = new ServiceModule().IsModuleActive(f.moduleId, f.moduleType);

                if (!string.IsNullOrEmpty(isActive))
                {
                    return new DtoActionResult()
                           {
                               ErrorMessage = isActive, Id = 0
                           }
                }
                ;
            }

            _uow.ExternalDownloadRepository.Delete(downloadId);
            _uow.Save();
            new FilesystemServices().DeleteExternalFile(u);

            var module = _uow.SoftwareModuleRepository.Get(x => x.Guid == u.ModuleGuid).FirstOrDefault();

            //arguments may need changed now that file is deleted, update arguments.
            if (module != null)
            {
                new ServiceSoftwareModule().GenerateArguments(module.Id);
            }

            var actionResult = new DtoActionResult();

            actionResult.Success = true;
            actionResult.Id      = u.Id;
            return(actionResult);
        }
Ejemplo n.º 5
0
        public DtoActionResult UpdateModule(EntitySoftwareModule module)
        {
            var u = GetModule(module.Id);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Module Not Found", Id = 0
                }
            }
            ;
            var isActiveModule = new ServiceModule().IsModuleActive(module.Id, EnumModule.ModuleType.Software);

            if (!string.IsNullOrEmpty(isActiveModule))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = isActiveModule, Id = 0
                       }
            }
            ;
            var validationResult = ValidateModule(module, false);
            var actionResult     = new DtoActionResult();

            if (validationResult.Success)
            {
                _uow.SoftwareModuleRepository.Update(module, module.Id);

                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = module.Id;
            }
            else
            {
                actionResult.ErrorMessage = validationResult.ErrorMessage;
            }

            return(actionResult);
        }
Ejemplo n.º 6
0
        public DtoActionResult DeleteModule(int moduleId)
        {
            var u = GetModule(moduleId);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Module Not Found", Id = 0
                }
            }
            ;
            var isActiveModule = new ServiceModule().IsModuleActive(moduleId, EnumModule.ModuleType.Message);

            if (!string.IsNullOrEmpty(isActiveModule))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = isActiveModule, Id = 0
                       }
            }
            ;
            if (string.IsNullOrEmpty(u.Guid))
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = "Unknown Guid", Id = 0
                       }
            }
            ;
            _uow.ModuleRepository.DeleteRange(x => x.Guid == u.Guid);
            _uow.Save();
            var actionResult = new DtoActionResult();

            actionResult.Success = true;
            actionResult.Id      = u.Id;

            return(actionResult);
        }
Ejemplo n.º 7
0
        public DtoActionResult GenerateArguments(int moduleId)
        {
            var result  = new DtoActionResult();
            var module  = GetModule(moduleId);
            var files   = new ServiceModule().GetModuleFiles(module.Guid);
            var msiList = new List <string>();
            var mspList = new List <string>();
            var mstList = new List <string>();

            foreach (var file in files.OrderBy(x => x.FileName))
            {
                var ext = Path.GetExtension(file.FileName);
                if (ext == null)
                {
                    result.Success      = false;
                    result.ErrorMessage = "File Extension Is Missing.";
                    return(result);
                }
                switch (ext.ToLower())
                {
                case ".msi":
                    msiList.Add(file.FileName);
                    break;

                case ".msp":
                    mspList.Add(file.FileName);
                    break;

                case ".mst":
                    mstList.Add(file.FileName);
                    break;

                default:
                    break;
                }
            }

            var arguments = new StringBuilder();
            var command   = "";

            if (module.InstallType == EnumSoftwareModule.MsiInstallType.Install)
            {
                if (msiList.Count == 0)
                {
                    result.Success      = false;
                    result.ErrorMessage = "No MSI Files Were Found For This Install Type";
                    return(result);
                }
                command = msiList.First();

                if (mspList.Count > 0)
                {
                    arguments.Append("PATCHES=");
                    foreach (var patch in mspList)
                    {
                        arguments.Append("[cache-path]");
                        arguments.Append(patch);
                        arguments.Append(";");
                    }
                }
                arguments.Append(" ");
                if (mstList.Count > 0)
                {
                    arguments.Append("TRANSFORMS=");
                    foreach (var transform in mstList)
                    {
                        arguments.Append(transform);
                        arguments.Append(";");
                    }
                }
            }
            else if (module.InstallType == EnumSoftwareModule.MsiInstallType.Uninstall)
            {
                if (msiList.Count == 0)
                {
                    result.Success      = false;
                    result.ErrorMessage = "No MSI Files Were Found For This Install Type";
                    return(result);
                }
                command = msiList.First();
            }
            else if (module.InstallType == EnumSoftwareModule.MsiInstallType.Patch)
            {
                if (mspList.Count == 0)
                {
                    result.Success      = false;
                    result.ErrorMessage = "No MSP Files Were Found For This Install Type";
                    return(result);
                }
                command = mspList.First();

                arguments.Append("REINSTALL=ALL REINSTALLMODE=omus");
            }
            else
            {
                result.Success      = false;
                result.ErrorMessage = "Invalid Software Install Type";
            }

            module.Command   = command;
            module.Arguments = arguments.ToString();
            var updateResult = UpdateModule(module);

            if (updateResult.Success)
            {
                result.Success = true;
                result.Id      = moduleId;
            }
            else
            {
                result.Success      = false;
                result.ErrorMessage = updateResult.ErrorMessage;
            }


            return(result);
        }
Ejemplo n.º 8
0
        public List <EntitySoftwareModule> SearchModules(DtoSearchFilterCategories filter)
        {
            var list = _uow.SoftwareModuleRepository.Get(s => (s.Name.Contains(filter.SearchText) || s.Guid.Contains(filter.SearchText)) && !s.Archived).OrderBy(x => x.Name).ToList();
            var categoryFilterIds = new List <int>();

            foreach (var catName in filter.Categories)
            {
                var category = _uow.CategoryRepository.GetFirstOrDefault(x => x.Name.Equals(catName));
                if (category != null)
                {
                    categoryFilterIds.Add(category.Id);
                }
            }

            var toRemove = new List <EntitySoftwareModule>();

            if (filter.CategoryType.Equals("Any Category"))
            {
                return(list.Take(filter.Limit).ToList());
            }
            else if (filter.CategoryType.Equals("And Category"))
            {
                foreach (var module in list)
                {
                    var moduleCategories = new ServiceModule().GetModuleCategories(module.Guid);
                    if (moduleCategories == null)
                    {
                        continue;
                    }

                    if (filter.Categories.Count == 0)
                    {
                        if (moduleCategories.Count > 0)
                        {
                            toRemove.Add(module);
                            continue;
                        }
                    }

                    foreach (var id in categoryFilterIds)
                    {
                        if (moduleCategories.Any(x => x.CategoryId == id))
                        {
                            continue;
                        }
                        toRemove.Add(module);
                        break;
                    }
                }
            }
            else if (filter.CategoryType.Equals("Or Category"))
            {
                foreach (var module in list)
                {
                    var mCategories = new ServiceModule().GetModuleCategories(module.Guid);
                    if (mCategories == null)
                    {
                        continue;
                    }
                    if (filter.Categories.Count == 0)
                    {
                        if (mCategories.Count > 0)
                        {
                            toRemove.Add(module);
                            continue;
                        }
                    }

                    var catFound = false;
                    foreach (var id in categoryFilterIds)
                    {
                        if (mCategories.Any(x => x.CategoryId == id))
                        {
                            catFound = true;
                            break;
                        }
                    }
                    if (!catFound)
                    {
                        toRemove.Add(module);
                    }
                }
            }

            foreach (var p in toRemove)
            {
                list.Remove(p);
            }

            return(list.Take(filter.Limit).ToList());
        }
Ejemplo n.º 9
0
        public DtoActionResult ArchivePolicy(int policyId)
        {
            var u = GetPolicy(policyId);

            if (u == null)
            {
                return new DtoActionResult {
                           ErrorMessage = "Policy Not Found", Id = 0
                }
            }
            ;
            var activePolicy = GetActivePolicy(policyId);

            if (activePolicy != null)
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = "Active Policies Cannot Be Archived.  You Must Deactivate It First.", Id = 0, Success = false
                       }
            }
            ;
            if (u.Archived)
            {
                return new DtoActionResult()
                       {
                           Id = u.Id, Success = true
                       }
            }
            ;
            u.Archived        = true;
            u.Name            = u.Name + "#" + DateTime.Now.ToString("MM-dd-yyyy_HH:mm");
            u.ArchiveDateTime = DateTime.Now;

            var policyWithModules  = _uow.PolicyRepository.GetDetailed(policyId);
            var moduleService      = new ServiceModule();
            var moduleArchiveError = false;

            foreach (var m in policyWithModules.CommandModules)
            {
                if (!moduleService.ArchiveModule(m.Id, EnumModule.ModuleType.Command).Success)
                {
                    moduleArchiveError = true;
                }
            }
            foreach (var m in policyWithModules.FileCopyModules)
            {
                if (!moduleService.ArchiveModule(m.Id, EnumModule.ModuleType.FileCopy).Success)
                {
                    moduleArchiveError = true;
                }
            }
            foreach (var m in policyWithModules.PrinterModules)
            {
                if (!moduleService.ArchiveModule(m.Id, EnumModule.ModuleType.Printer).Success)
                {
                    moduleArchiveError = true;
                }
            }
            foreach (var m in policyWithModules.ScriptModules)
            {
                if (!moduleService.ArchiveModule(m.Id, EnumModule.ModuleType.Script).Success)
                {
                    moduleArchiveError = true;
                }
            }
            foreach (var m in policyWithModules.SoftwareModules)
            {
                if (!moduleService.ArchiveModule(m.Id, EnumModule.ModuleType.Software).Success)
                {
                    moduleArchiveError = true;
                }
            }
            foreach (var m in policyWithModules.WuModules)
            {
                if (!moduleService.ArchiveModule(m.Id, EnumModule.ModuleType.Wupdate).Success)
                {
                    moduleArchiveError = true;
                }
            }
            foreach (var m in policyWithModules.MessageModules)
            {
                if (!moduleService.ArchiveModule(m.Id, EnumModule.ModuleType.Message).Success)
                {
                    moduleArchiveError = true;
                }
            }
            _uow.GroupPolicyRepository.DeleteRange(x => x.PolicyId == policyId);
            _uow.Save();
            if (moduleArchiveError)
            {
                return new DtoActionResult()
                       {
                           ErrorMessage = "Some Modules Could Not Be Archived Because They Are Active With Other Policies.",
                           Success      = false,
                           Id           = 0
                       }
            }
            ;
            else
            {
                _uow.PinnedPolicyRepository.DeleteRange(x => x.PolicyId == policyId);

                _uow.Save();
                return(new DtoActionResult()
                {
                    Id = u.Id, Success = true
                });
            }
        }