예제 #1
0
        private static RvSofOperation InstallOperation(RvSofOperation windowsOperation)
        {
            InstallSupportedData data = windowsOperation.InstallSupportedDataList[0];
            //string uri = data.Uris; //TODO: This must be corrected for agent updater to work..
            string filepath = Path.Combine(AgentUpdateDirectory, _fileName);

            try
            {
                InstallResult installResult = ExeInstall(filepath, data.CliOptions);

                if (!installResult.Success)
                {
                    var results = new RVsofResult();
                    results.Success = false.ToString();
                    results.AppId   = data.Id;
                    results.Error   = String.Format("Failed while installing RV Agent update: {0}. {1}. Exit code: {2}.",
                                                    filepath, installResult.ExitCodeMessage, installResult.ExitCode);
                    windowsOperation.AddResult(results);
                    return(windowsOperation);
                }

                return(null);
            }
            catch (Exception e)
            {
                Logger.Log("Could not install RV Agent Update: ", LogLevel.Error);
                Logger.LogException(e);

                var result = new RVsofResult();
                result.AppId = data.Id;
                result.Error = String.Format("Failed to update RV Agent:  {0}.", e.Message);
                windowsOperation.AddResult(result);
                return(windowsOperation);
            }
        }
예제 #2
0
        private void InstallSendResults(Operations.SavedOpData updateData, RvSofOperation operation, List <RVsofResult.AppsToAdd2> appsToAdd = null, List <RVsofResult.AppsToDelete2> appsToDelete = null)
        {
            try
            {
                var results = new RVsofResult();

                results.AppsToAdd    = results.AppsToAdd != null ? appsToAdd : new List <RVsofResult.AppsToAdd2>();
                results.AppsToDelete = results.AppsToDelete != null ? appsToDelete : new List <RVsofResult.AppsToDelete2>();

                results.AppId          = updateData.filedata_app_id;
                results.Operation      = updateData.operation;
                results.OperationId    = updateData.operation_id;
                results.Error          = updateData.error;
                results.RebootRequired = updateData.reboot_required;
                results.Success        = updateData.success;

                switch (updateData.operation)
                {
                case OperationValue.InstallWindowsUpdate:
                    results             = WindowsUpdates.AddAppDetailsToResults(results);
                    operation.RawResult = RvFormatter.Install(results);
                    break;

                case OperationValue.InstallCustomApp:
                    results             = CustomAppsManager.AddAppDetailsToResults(results);
                    operation.RawResult = RvFormatter.Install(results);
                    break;

                case OperationValue.InstallSupportedApp:
                    results             = SupportedAppsManager.AddAppDetailsToResults(results);
                    operation.RawResult = RvFormatter.Install(results);
                    break;

                case OperationValue.InstallAgentUpdate:
                    results             = AgentUpdateManager.AddAppDetailsToResults(results);
                    operation.RawResult = RvFormatter.AgentUpdate(results);
                    break;

                case OperationValue.Uninstall:
                    operation.RawResult = RvFormatter.Install(results);
                    break;
                }

                operation.Id     = updateData.operation_id;
                operation.Plugin = "rv";

                Operations.UpdateStatus(updateData, Operations.OperationStatus.ResultsPending);

                Logger.Log("Sending back results for {0}.", LogLevel.Info, updateData.filedata_app_name);
                if (SendResults(operation))
                {
                    Operations.CleanAllOperationData(updateData);
                }
            }
            catch (Exception e)
            {
                Logger.Log("Failed when attempting to send back results, Exception inside InstallSendResults().");
                Logger.LogException(e);
            }
        }
        public static RVsofResult AddAppDetailsToResults(RVsofResult originalResults)
        {
            try
            {
                var searchInstalled = AllInstalledUpdatesParsed.Where(p => p.Name == originalResults.Data.Name).Select(item => item).FirstOrDefault();

                if (searchInstalled != null)
                {
                    originalResults.Data.Description    = (String.IsNullOrEmpty(searchInstalled.Description)) ? String.Empty : searchInstalled.Description;
                    originalResults.Data.Kb             = (String.IsNullOrEmpty(searchInstalled.KB)) ? String.Empty : searchInstalled.KB;
                    originalResults.Data.ReleaseDate    = searchInstalled.ReleaseDate; //Double value type
                    originalResults.Data.VendorSeverity = (String.IsNullOrEmpty(searchInstalled.VendorSeverity)) ? String.Empty : searchInstalled.VendorSeverity;
                    originalResults.Data.VendorName     = (String.IsNullOrEmpty(searchInstalled.VendorName)) ? String.Empty : searchInstalled.VendorName;
                    originalResults.Data.VendorId       = (String.IsNullOrEmpty(searchInstalled.VendorId)) ? String.Empty : searchInstalled.VendorId;
                    originalResults.Data.Version        = (String.IsNullOrEmpty(searchInstalled.Version)) ? String.Empty : searchInstalled.Version;
                    originalResults.Data.SupportUrl     = (String.IsNullOrEmpty(searchInstalled.SupportUrl)) ? String.Empty : searchInstalled.SupportUrl;
                    return originalResults;
                }

                    var searchAvailable = AllAvailableUpdatesParsed.Where(p => p.Name == originalResults.Data.Name).Select(item => item).FirstOrDefault();

                    if (searchAvailable != null)
                    {
                        originalResults.Data.Description        = (String.IsNullOrEmpty(searchAvailable.Description)) ? String.Empty : searchAvailable.Description;
                        originalResults.Data.Kb                 = (String.IsNullOrEmpty(searchAvailable.KB)) ? String.Empty : searchAvailable.KB;
                        originalResults.Data.ReleaseDate        = searchAvailable.ReleaseDate; //Double value type
                        originalResults.Data.VendorSeverity     = (String.IsNullOrEmpty(searchAvailable.VendorSeverity)) ? String.Empty : searchAvailable.VendorSeverity;
                        originalResults.Data.VendorName         = (String.IsNullOrEmpty(searchAvailable.VendorName)) ? String.Empty : searchAvailable.VendorName;
                        originalResults.Data.VendorId           = (String.IsNullOrEmpty(searchAvailable.VendorId)) ? String.Empty : searchAvailable.VendorId;
                        originalResults.Data.Version            = (String.IsNullOrEmpty(searchAvailable.Version)) ? String.Empty : searchAvailable.Version;
                        originalResults.Data.SupportUrl         = (String.IsNullOrEmpty(searchAvailable.SupportUrl)) ? String.Empty : searchAvailable.SupportUrl;
                        return originalResults;
                    }

                        originalResults.Data.Description    = String.Empty;
                        originalResults.Data.Kb             = String.Empty;
                        originalResults.Data.ReleaseDate    = 0.0;
                        originalResults.Data.VendorSeverity = String.Empty;
                        originalResults.Data.VendorName     = String.Empty;
                        originalResults.Data.VendorId       = String.Empty;
                        originalResults.Data.Version        = String.Empty;
                        originalResults.Data.SupportUrl     = String.Empty;

            }
            catch (Exception)
            {
                originalResults.Data.Description     = String.Empty;
                originalResults.Data.Kb              = String.Empty;
                originalResults.Data.ReleaseDate     = 0.0;
                originalResults.Data.VendorSeverity  = String.Empty;
                originalResults.Data.VendorName      = String.Empty;
                originalResults.Data.VendorId        = String.Empty;
                originalResults.Data.Version         = String.Empty;
                originalResults.Data.SupportUrl      = String.Empty;
                return originalResults;
            }

            return originalResults;
        }
예제 #4
0
        public static RVsofResult AddAppDetailsToResults(RVsofResult originalResults)
        {
            try
            {
                var searchInstalled = AllInstalledUpdatesParsed.Where(p => p.Name == originalResults.Data.Name).Select(item => item).FirstOrDefault();

                if (searchInstalled != null)
                {
                    originalResults.Data.Description    = (String.IsNullOrEmpty(searchInstalled.Description)) ? String.Empty : searchInstalled.Description;
                    originalResults.Data.Kb             = (String.IsNullOrEmpty(searchInstalled.KB)) ? String.Empty : searchInstalled.KB;
                    originalResults.Data.ReleaseDate    = searchInstalled.ReleaseDate; //Double value type
                    originalResults.Data.VendorSeverity = (String.IsNullOrEmpty(searchInstalled.VendorSeverity)) ? String.Empty : searchInstalled.VendorSeverity;
                    originalResults.Data.VendorName     = (String.IsNullOrEmpty(searchInstalled.VendorName)) ? String.Empty : searchInstalled.VendorName;
                    originalResults.Data.VendorId       = (String.IsNullOrEmpty(searchInstalled.VendorId)) ? String.Empty : searchInstalled.VendorId;
                    originalResults.Data.Version        = (String.IsNullOrEmpty(searchInstalled.Version)) ? String.Empty : searchInstalled.Version;
                    originalResults.Data.SupportUrl     = (String.IsNullOrEmpty(searchInstalled.SupportUrl)) ? String.Empty : searchInstalled.SupportUrl;
                    return(originalResults);
                }

                var searchAvailable = AllAvailableUpdatesParsed.Where(p => p.Name == originalResults.Data.Name).Select(item => item).FirstOrDefault();

                if (searchAvailable != null)
                {
                    originalResults.Data.Description    = (String.IsNullOrEmpty(searchAvailable.Description)) ? String.Empty : searchAvailable.Description;
                    originalResults.Data.Kb             = (String.IsNullOrEmpty(searchAvailable.KB)) ? String.Empty : searchAvailable.KB;
                    originalResults.Data.ReleaseDate    = searchAvailable.ReleaseDate;         //Double value type
                    originalResults.Data.VendorSeverity = (String.IsNullOrEmpty(searchAvailable.VendorSeverity)) ? String.Empty : searchAvailable.VendorSeverity;
                    originalResults.Data.VendorName     = (String.IsNullOrEmpty(searchAvailable.VendorName)) ? String.Empty : searchAvailable.VendorName;
                    originalResults.Data.VendorId       = (String.IsNullOrEmpty(searchAvailable.VendorId)) ? String.Empty : searchAvailable.VendorId;
                    originalResults.Data.Version        = (String.IsNullOrEmpty(searchAvailable.Version)) ? String.Empty : searchAvailable.Version;
                    originalResults.Data.SupportUrl     = (String.IsNullOrEmpty(searchAvailable.SupportUrl)) ? String.Empty : searchAvailable.SupportUrl;
                    return(originalResults);
                }

                originalResults.Data.Description    = String.Empty;
                originalResults.Data.Kb             = String.Empty;
                originalResults.Data.ReleaseDate    = 0.0;
                originalResults.Data.VendorSeverity = String.Empty;
                originalResults.Data.VendorName     = String.Empty;
                originalResults.Data.VendorId       = String.Empty;
                originalResults.Data.Version        = String.Empty;
                originalResults.Data.SupportUrl     = String.Empty;
            }
            catch (Exception)
            {
                originalResults.Data.Description    = String.Empty;
                originalResults.Data.Kb             = String.Empty;
                originalResults.Data.ReleaseDate    = 0.0;
                originalResults.Data.VendorSeverity = String.Empty;
                originalResults.Data.VendorName     = String.Empty;
                originalResults.Data.VendorId       = String.Empty;
                originalResults.Data.Version        = String.Empty;
                originalResults.Data.SupportUrl     = String.Empty;
                return(originalResults);
            }

            return(originalResults);
        }
예제 #5
0
 public static RVsofResult AddAppDetailsToResults(RVsofResult results)
 {
     results.Data.Name           = String.Empty;
     results.Data.Description    = String.Empty;
     results.Data.Kb             = String.Empty;
     results.Data.ReleaseDate    = 0.0;
     results.Data.VendorSeverity = String.Empty;
     results.Data.VendorName     = String.Empty;
     results.Data.VendorId       = String.Empty;
     results.Data.Version        = String.Empty;
     results.Data.SupportUrl     = String.Empty;
     return(results);
 }
 public static RVsofResult AddAppDetailsToResults(RVsofResult results)
 {
     results.Data.Name           = String.Empty;
     results.Data.Description    = String.Empty;
     results.Data.Kb             = String.Empty;
     results.Data.ReleaseDate    = 0.0;
     results.Data.VendorSeverity = String.Empty;
     results.Data.VendorName     = String.Empty;
     results.Data.VendorId       = String.Empty;
     results.Data.Version        = String.Empty;
     results.Data.SupportUrl     = String.Empty;
     return results;
 }
예제 #7
0
        private void InstallSendResults(Operations.SavedOpData updateData, RvSofOperation operation, List<RVsofResult.AppsToAdd2> appsToAdd = null, List<RVsofResult.AppsToDelete2> appsToDelete = null)
        {
            try
            {
                var results = new RVsofResult();

                results.AppsToAdd      = results.AppsToAdd != null ? appsToAdd : new List<RVsofResult.AppsToAdd2>();
                results.AppsToDelete   = results.AppsToDelete != null ? appsToDelete : new List<RVsofResult.AppsToDelete2>();

                results.AppId          = updateData.filedata_app_id;
                results.Operation      = updateData.operation;
                results.OperationId    = updateData.operation_id;
                results.Error          = updateData.error;
                results.RebootRequired = updateData.reboot_required;
                results.Success        = updateData.success;

                switch (updateData.operation)
                {
                    case OperationValue.InstallWindowsUpdate:
                         results = WindowsUpdates.AddAppDetailsToResults(results);
                         operation.RawResult = RvFormatter.Install(results);
                         break;

                    case OperationValue.InstallCustomApp:
                         results = CustomAppsManager.AddAppDetailsToResults(results);
                         operation.RawResult = RvFormatter.Install(results);
                         break;

                    case OperationValue.InstallSupportedApp:
                         results = SupportedAppsManager.AddAppDetailsToResults(results);
                         operation.RawResult = RvFormatter.Install(results);
                         break;

                    case OperationValue.InstallAgentUpdate:
                         results = AgentUpdateManager.AddAppDetailsToResults(results);
                         operation.RawResult = RvFormatter.AgentUpdate(results);
                         break;

                    case OperationValue.Uninstall:
                         operation.RawResult = RvFormatter.Install(results);
                         break;
                }

               operation.Id        = updateData.operation_id;
               operation.Plugin    = "rv";

               Operations.UpdateStatus(updateData, Operations.OperationStatus.ResultsPending);

                Logger.Log("Sending back results for {0}.", LogLevel.Info, updateData.filedata_app_name);
                if (SendResults(operation))
                    Operations.CleanAllOperationData(updateData);

            }
            catch (Exception e)
            {
                Logger.Log("Failed when attempting to send back results, Exception inside InstallSendResults().");
                Logger.LogException(e);
            }
        }
        /// <summary>
        /// Determines whether to perform a system restore or send data back to the server. It use WMI.
        /// </summary>
        /// <param name="operation">Variable of type RvSofOperation</param>
        /// <returns>Returns updated RvSofOperation after processing.</returns>
        public static RvSofOperation Restore(RvSofOperation operation)
        {
            var results = new RVsofResult();
            var restoreClass = new ManagementClass("\\\\.\\root\\default", "systemrestore", new ObjectGetOptions());
            ManagementObjectCollection restoreCollection = restoreClass.GetInstances();

            foreach (ManagementObject restoreItem in restoreCollection)
            {
                // Possible properties. See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378925(v=vs.85).aspx
                //(string)restoreItem["Description"]
                //(uint)restoreItem["RestorePointType"]).ToString()
                //(uint)restoreItem["EventType"]).ToString()
                //(uint)restoreItem["SequenceNumber"]).ToString()
                //(string)restoreItem["CreationTime"]

                // Crazy way to call a method for a WMI class through System.Management.
                // See: http://msdn.microsoft.com/en-us/library/ms257364(v=vs.80).aspx
                if (((uint)restoreItem["SequenceNumber"]) != operation.WindowsRestoreSequence) continue;

                ManagementBaseObject inputParameters = restoreClass.GetMethodParameters("Restore");
                inputParameters["SequenceNumber"] = operation.WindowsRestoreSequence;

                try
                {
                    ManagementBaseObject outputParameters = restoreClass.InvokeMethod("Restore", inputParameters, null);
                    if (outputParameters != null && Convert.ToInt32(outputParameters["returnValue"]) == 0)
                    {
                        // Success! Restart system for restore point can take affect.
                        RvUtils.RestartSystem();
                        return null;
                    }

                    // Failed...
                    results.AppId = String.Empty;
                    results.Success = false.ToString();
                    results.RebootRequired = false.ToString();
                    results.Data.Name = String.Empty;

                    // Ummmm from the docs: "If the method succeeds, the return value is S_OK (0).
                    // Otherwise, the method returns one of the COM error codes defined in WinError.h."
                    if (outputParameters != null)
                    {
                        var exitCode = Convert.ToInt32(outputParameters["returnValue"]);
                        results.Error = "Win32 Error: " + new Win32Exception(exitCode).Message;
                    }

                    operation.AddResult(results);
                }
                catch (ManagementException e)
                {
                    Logger.Log("Exception: {0}", LogLevel.Error, e.Message);
                    if (e.InnerException != null)
                        Logger.Log("Inner exception: {0}", LogLevel.Error, e.InnerException.Message);

                    Logger.Log("Failed to perform a system restore.", LogLevel.Error);
                    results.AppId = String.Empty;
                    results.Success = false.ToString();
                    results.RebootRequired = false.ToString();
                    results.Data.Name = String.Empty;
                    results.Error = String.Format("ManagementException Error: {0}", e);
                }

                operation.AddResult(results);
                return operation;
            }

            results.AppId = String.Empty;
            results.Success = false.ToString();
            results.RebootRequired = false.ToString();
            results.Error= String.Format("No restore point with sequence number {0} was found.", operation.WindowsRestoreSequence);
            results.Data.Name = String.Empty;

            operation.AddResult(results);
            return operation;
        }
예제 #9
0
        public static RvSofOperation DownloadUpdate(RvSofOperation operation)
        {
            var url = operation.InstallAgentUpdateDataList[0].ToString();
            var split = url.Split(new[] { '/' });
            var filename = split[split.Length - 1];
            var filepath = Path.Combine(AgentUpdateDirectory, filename);
            int fileSize;

            _fileName = filename;

            if (!Directory.Exists(Settings.BackupDirectory))
                Directory.CreateDirectory(Settings.BackupDirectory);

            if (!Directory.Exists(AgentUpdateDirectory))
                Directory.CreateDirectory(AgentUpdateDirectory);

            if (File.Exists(filepath))
                File.Delete(filepath);

                  try
                  {
                     using (WebClient)
                     {
                        if (Settings.Proxy != null)
                            WebClient.Proxy = Settings.Proxy;

                        WebClient.OpenRead(url);
                        fileSize = Convert.ToInt32(WebClient.ResponseHeaders["Content-Length"]);
                        WebClient.DownloadFile(new Uri(url), filepath);
                     }

                  }
                  catch (Exception e)
                  {
                      Logger.Log("Could not download file {0}. Please check network settings and File URI.", LogLevel.Error, filename);
                      Logger.LogException(e);
                      var data = operation.InstallSupportedDataList[0];
                      var result = new RVsofResult();
                      result.AppId = data.Id;
                      result.Error = "RV Agent Update did not Download, check network and/or Download URI.";
                      operation.AddResult(result);
                      return operation;
                  }

                  if (File.Exists(filepath))
                  {
                      var downloadedAgent = new FileInfo(filepath);
                      var downloadedAgentSize = Convert.ToInt32(downloadedAgent.Length);

                      if (fileSize == downloadedAgentSize)
                      {
                          //Install Operation for the Update
                          var updateResults = InstallOperation(operation);
                          if (updateResults != null)
                              return updateResults;

                          //Installation of RV Agent Update Failed while Installing.
                          InstallSupportedData data = operation.InstallSupportedDataList[0];
                          var result = new RVsofResult();
                          result.AppId = data.Id;
                          result.Error = "RV Agent Update Failed while installing.";
                          result.Success = false.ToString();
                          operation.AddResult(result);
                          return operation;
                      }
                      else
                      {
                          //Downloaded failed, send back results
                          Logger.Log("RV Agent Update File download corrupted, unable to install the update.");
                          InstallSupportedData data = operation.InstallSupportedDataList[0];
                          var result = new RVsofResult();
                          result.AppId = data.Id;
                          result.Error = "File download corrupted, unable to install update.";
                          operation.AddResult(result);
                          return operation;
                      }

                  }
                  else
                  {
                      //Downloaded failed, send back results
                      Logger.Log("RV Agent Update did not Download, check network and/or Download URI.", LogLevel.Info);
                      InstallSupportedData data = operation.InstallSupportedDataList[0];
                      var result = new RVsofResult();
                      result.AppId = data.Id;
                      result.Error = "RV Agent Update did not Download, check network and/or Download URI.";
                      operation.AddResult(result);
                      return operation;

                  }
        }
예제 #10
0
        private static RvSofOperation InstallOperation(RvSofOperation windowsOperation)
        {
            InstallSupportedData data = windowsOperation.InstallSupportedDataList[0];
            //string uri = data.Uris; //TODO: This must be corrected for agent updater to work..
            string filepath = Path.Combine(AgentUpdateDirectory, _fileName);

            try
            {
                 InstallResult installResult = ExeInstall(filepath, data.CliOptions);

                 if (!installResult.Success)
                 {
                     var results = new RVsofResult();
                     results.Success = false.ToString();
                     results.AppId = data.Id;
                     results.Error = String.Format("Failed while installing RV Agent update: {0}. {1}. Exit code: {2}.",
                                                                filepath, installResult.ExitCodeMessage, installResult.ExitCode);
                     windowsOperation.AddResult(results);
                     return windowsOperation;
                 }

                 return null;
            }
            catch (Exception e)
            {
                    Logger.Log("Could not install RV Agent Update: ", LogLevel.Error);
                    Logger.LogException(e);

                    var result = new RVsofResult();
                    result.AppId = data.Id;
                    result.Error = String.Format("Failed to update RV Agent:  {0}.", e.Message);
                    windowsOperation.AddResult(result);
                    return windowsOperation;
            }
        }
        public static RvSofOperation InstallCustomAppsOperation(RvSofOperation operation)
        {
            var foundApplications = new List <InstallCustomData>();
            var registryOpen      = new RegistryReader();

            //Load all
            foreach (InstallCustomData installData in operation.InstallCustomDataList)
            {
                string appDir = Path.Combine(Settings.UpdateDirectory, installData.Id);
                bool   found  = false;

                foreach (string item in installData.Uris)
                {
                    string[] split    = item.Split(new[] { '/' });
                    string   filename = split[split.Length - 1];
                    string   filepath = Path.Combine(appDir, filename);

                    if (File.Exists(filepath))
                    {
                        found = true;
                    }
                    else
                    {
                        found = false;
                        break;
                    }
                }

                if (!found)
                {
                    var result = new RVsofResult();
                    result.AppId = installData.Id;
                    result.Error = "Update files did not Download: " + installData.Name;
                    Logger.Log("Update files did not Download for: " + installData.Name);
                    operation.AddResult(result);
                }
                else
                {
                    Logger.Log("Update Files for {0} : Downloaded OK", LogLevel.Info, installData.Name);
                    foundApplications.Add(installData);
                }
            }

            foreach (InstallCustomData id in foundApplications)
            {
                try
                {
                    string   appDirectory = Path.Combine(Settings.UpdateDirectory, id.Id);
                    string[] appFiles     = Directory.GetFiles(appDirectory);

                    foreach (string file in appFiles)
                    {
                        var    extension = Path.GetExtension(file);
                        Result result;

                        switch (extension)
                        {
                        case Extension.Exe:

                            Logger.Log("Installing: {0}", LogLevel.Info, id.Name);
                            result = ExeInstall(file, id.CliOptions);
                            break;

                        case Extension.Msi:

                            Logger.Log("Installing: {0}", LogLevel.Info, id.Name);
                            result = MsiInstall(file, id.CliOptions);
                            break;

                        case Extension.Msp:

                            Logger.Log("Installing: {0}", LogLevel.Info, id.Name);
                            result = MspInstall(file, id.CliOptions);
                            break;

                        default:
                            throw new Exception(String.Format("{0} is not a supported file format.", extension));
                        }

                        if (!result.Success)
                        {
                            var results = new RVsofResult();
                            results.Success = false.ToString();
                            results.AppId   = id.Id;
                            results.Error   = String.Format("Failed to install {0}. {1}. Exit code: {2}.", file, result.ExitCodeMessage, result.ExitCode);
                            Logger.Log("Failed to install: {0}", LogLevel.Info, file);
                            operation.AddResult(results);
                            break;
                        }

                        // If the last file was reached without issues, all should be good.
                        if (appFiles[appFiles.Length - 1].Equals(file))
                        {
                            var results = new RVsofResult();

                            //Get new list of installed applications after finishing installing applications.
                            operation.ListOfAppsAfterInstall = registryOpen.GetRegistryInstalledApplicationNames();

                            results.Success        = true.ToString();
                            results.AppId          = id.Id;
                            results.RebootRequired = result.Restart.ToString();
                            results.Data.Name      = registryOpen.GetSetFromTwoLists(operation.ListOfInstalledApps, operation.ListOfAppsAfterInstall); //TODO: keep an eye on this, no need for it??
                            Logger.Log("Update Success: {0}", LogLevel.Debug, file);
                            operation.AddResult(results);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Log("Could not install {0}.", LogLevel.Error, id.Name);
                    Logger.LogException(e);

                    var result = new RVsofResult();
                    result.AppId = id.Id;
                    result.Error = String.Format("Failed to install. {0}.", e.Message);
                    operation.AddResult(result);
                }
            }

            return(operation);
        }
예제 #12
0
        /// <summary>
        ///     Determines whether to perform a system restore or send data back to the server. It use WMI.
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        public static RvSofOperation Restore(RvSofOperation operation)
        {
            var results      = new RVsofResult();
            var restoreClass = new ManagementClass("\\\\.\\root\\default", "systemrestore", new ObjectGetOptions());
            ManagementObjectCollection restoreCollection = restoreClass.GetInstances();

            foreach (ManagementObject restoreItem in restoreCollection)
            {
                // Possible properties. See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378925(v=vs.85).aspx
                //(string)restoreItem["Description"]
                //(uint)restoreItem["RestorePointType"]).ToString()
                //(uint)restoreItem["EventType"]).ToString()
                //(uint)restoreItem["SequenceNumber"]).ToString()
                //(string)restoreItem["CreationTime"]

                // Crazy way to call a method for a WMI class through System.Management.
                // See: http://msdn.microsoft.com/en-us/library/ms257364(v=vs.80).aspx
                if (((uint)restoreItem["SequenceNumber"]) != operation.WindowsRestoreSequence)
                {
                    continue;
                }

                ManagementBaseObject inputParameters = restoreClass.GetMethodParameters("Restore");
                inputParameters["SequenceNumber"] = operation.WindowsRestoreSequence;

                try
                {
                    ManagementBaseObject outputParameters = restoreClass.InvokeMethod("Restore", inputParameters, null);
                    if (outputParameters != null && Convert.ToInt32(outputParameters["returnValue"]) == 0)
                    {
                        // Success! Restart system for restore point can take affect.
                        RvUtils.RestartSystem();
                        return(null);
                    }

                    // Failed...
                    results.AppId          = String.Empty;
                    results.Success        = false.ToString();
                    results.RebootRequired = false.ToString();
                    results.Data.Name      = String.Empty;

                    // Ummmm from the docs: "If the method succeeds, the return value is S_OK (0).
                    // Otherwise, the method returns one of the COM error codes defined in WinError.h."
                    if (outputParameters != null)
                    {
                        var exitCode = Convert.ToInt32(outputParameters["returnValue"]);
                        results.Error = "Win32 Error: " + new Win32Exception(exitCode).Message;
                    }

                    operation.AddResult(results);
                }
                catch (ManagementException e)
                {
                    Logger.Log("Exception: {0}", LogLevel.Error, e.Message);
                    if (e.InnerException != null)
                    {
                        Logger.Log("Inner exception: {0}", LogLevel.Error, e.InnerException.Message);
                    }

                    Logger.Log("Failed to perform a system restore.", LogLevel.Error);
                    results.AppId          = String.Empty;
                    results.Success        = false.ToString();
                    results.RebootRequired = false.ToString();
                    results.Data.Name      = String.Empty;
                    results.Error          = String.Format("ManagementException Error: {0}", e);
                }

                operation.AddResult(results);
                return(operation);
            }

            results.AppId          = String.Empty;
            results.Success        = false.ToString();
            results.RebootRequired = false.ToString();
            results.Error          = String.Format("No restore point with sequence number {0} was found.", operation.WindowsRestoreSequence);
            results.Data.Name      = String.Empty;

            operation.AddResult(results);
            return(operation);
        }
예제 #13
0
        public static string Install(RVsofResult operation)
        {
            var json = new JObject();

            json.Add(OperationKey.OperationId, operation.OperationId);
            json.Add("success", operation.Success.ToLower());
            json.Add("reboot_required", operation.RebootRequired.ToLower());
            json.Add("error", (string.IsNullOrEmpty(operation.Error) ? string.Empty : operation.Error));
            json.Add("app_id", operation.AppId);

            var appsToDeleteArray = new JArray();

            if (operation.AppsToDelete != null && (operation.AppsToDelete != null || operation.AppsToDelete.Count > 0))
            {
                foreach (var node in operation.AppsToDelete)
                {
                    var appsToDelete = new JObject();
                    appsToDelete["name"]    = (string.IsNullOrEmpty(node.Name) ? string.Empty : node.Name);
                    appsToDelete["version"] = (string.IsNullOrEmpty(node.Version) ? string.Empty : node.Version);
                    appsToDeleteArray.Add(appsToDelete);
                }
            }

            var appsToAddArray = new JArray();
            var filedata2      = new JArray();
            var tempEmptyArray = new JArray();

            if (operation.AppsToAdd != null && (operation.AppsToAdd != null || operation.AppsToAdd.Count > 0))
            {
                foreach (var node in operation.AppsToAdd)
                {
                    var appsToAdd = new JObject();
                    appsToAdd["name"]            = (string.IsNullOrEmpty(node.AppsToAdd.Name) ? string.Empty : node.AppsToAdd.Name);
                    appsToAdd["version"]         = (string.IsNullOrEmpty(node.AppsToAdd.Version) ? string.Empty : node.AppsToAdd.Version);
                    appsToAdd["description"]     = (string.IsNullOrEmpty(node.AppsToAdd.Description) ? string.Empty : node.AppsToAdd.Description);
                    appsToAdd["install_date"]    = node.AppsToAdd.InstallDate;
                    appsToAdd["kb"]              = (string.IsNullOrEmpty(node.AppsToAdd.KB) ? string.Empty : node.AppsToAdd.KB);
                    appsToAdd["reboot_required"] = (string.IsNullOrEmpty(node.AppsToAdd.RebootRequired) ? string.Empty : node.AppsToAdd.RebootRequired);
                    appsToAdd["release_date"]    = node.AppsToAdd.ReleaseDate;
                    appsToAdd["file_data"]       = filedata2;
                    appsToAdd["status"]          = (string.IsNullOrEmpty(node.AppsToAdd.Status) ? string.Empty : node.AppsToAdd.Status);
                    appsToAdd["support_url"]     = (string.IsNullOrEmpty(node.AppsToAdd.SupportUrl) ? string.Empty : node.AppsToAdd.SupportUrl);
                    appsToAdd["vendor_id"]       = (string.IsNullOrEmpty(node.AppsToAdd.VendorId) ? string.Empty : node.AppsToAdd.VendorId);
                    appsToAdd["vendor_name"]     = (string.IsNullOrEmpty(node.AppsToAdd.VendorName) ? string.Empty : node.AppsToAdd.VendorName);
                    appsToAdd["vendor_severity"] = (string.IsNullOrEmpty(node.AppsToAdd.VendorSeverity) ? string.Empty : node.AppsToAdd.VendorSeverity);
                    appsToAdd["repo"]            = string.Empty;
                    appsToAdd["dependencies"]    = tempEmptyArray;
                    appsToAddArray.Add(appsToAdd);
                }
            }

            var data = new JObject();

            data.Add("name", (string.IsNullOrEmpty(operation.Data.Name) ? string.Empty : operation.Data.Name));
            data.Add("description", (string.IsNullOrEmpty(operation.Data.Description) ? string.Empty : operation.Data.Description));
            data.Add("kb", (string.IsNullOrEmpty(operation.Data.Kb) ? string.Empty : operation.Data.Kb));
            data.Add("vendor_severity", (string.IsNullOrEmpty(operation.Data.VendorSeverity) ? string.Empty : operation.Data.VendorSeverity));
            data.Add("rv_severity", (string.IsNullOrEmpty(operation.Data.RvSeverity) ? string.Empty : operation.Data.RvSeverity));
            data.Add("support_url", (string.IsNullOrEmpty(operation.Data.SupportUrl) ? string.Empty : operation.Data.SupportUrl));
            data.Add("release_date", operation.Data.ReleaseDate);
            data.Add("vendor_id", (string.IsNullOrEmpty(operation.Data.VendorId) ? string.Empty : operation.Data.VendorId));
            data.Add("vendor_name", (string.IsNullOrEmpty(operation.Data.VendorName) ? string.Empty : operation.Data.VendorName));
            data.Add("repo", (string.IsNullOrEmpty(operation.Data.Repo) ? string.Empty : operation.Data.Repo));
            data.Add("version", (string.IsNullOrEmpty(operation.Data.Version) ? string.Empty : operation.Data.Version));

            var filedata = new JArray();

            foreach (var uri in operation.Data.FileData)
            {
                var jUri = new JObject();
                jUri["file_name"] = (string.IsNullOrEmpty(uri.FileName) ? string.Empty : uri.FileName);
                jUri["file_uri"]  = (string.IsNullOrEmpty(uri.Uri) ? string.Empty : uri.Uri);
                jUri["file_size"] = uri.FileSize;
                jUri["file_hash"] = (string.IsNullOrEmpty(uri.Hash) ? string.Empty : uri.Hash);
                filedata.Add(jUri);
            }

            data.Add("file_data", filedata);

            json.Add("apps_to_delete", appsToDeleteArray);
            json.Add("apps_to_add", appsToAddArray);
            json.Add("data", data.ToString());

            return(json.ToString());
        }
예제 #14
0
        /// <summary>
        /// Formats the json data for an angent update operatoin. 
        /// </summary>
        /// <param name="operation">Operatoin type RVsofResults, containing all the data gathers during the install process.</param>
        /// <returns>Returns string of the json.</returns>
        public static string AgentUpdate(RVsofResult operation)
        {
            var json = new JObject();
            json.Add(OperationKey.OperationId, operation.OperationId);
            json.Add("success", operation.Success.ToLower());
            json.Add("reboot_required", operation.RebootRequired.ToLower());
            json.Add("error", (string.IsNullOrEmpty(operation.Error) ? string.Empty : operation.Error));
            json.Add("app_id", operation.AppId);

            var appsToDeleteArray = new JArray();
            if (operation.AppsToDelete != null && (operation.AppsToDelete != null || operation.AppsToDelete.Count > 0))
            {
                foreach (var node in operation.AppsToDelete)
                {
                    var appsToDelete = new JObject();
                    appsToDelete["name"] = (string.IsNullOrEmpty(node.Name) ? string.Empty : node.Name);
                    appsToDelete["version"] = (string.IsNullOrEmpty(node.Version) ? string.Empty : node.Version);
                    appsToDeleteArray.Add(appsToDelete);
                }
            }

            var appsToAddArray = new JArray();
            var filedata2 = new JArray();
            var tempEmptyArray = new JArray();

            if (operation.AppsToAdd != null && (operation.AppsToAdd != null || operation.AppsToAdd.Count > 0))
            {
                foreach (var node in operation.AppsToAdd)
                {
                    var appsToAdd = new JObject();
                    appsToAdd["name"] = (string.IsNullOrEmpty(node.AppsToAdd.Name) ? string.Empty : node.AppsToAdd.Name);
                    appsToAdd["version"] = (string.IsNullOrEmpty(node.AppsToAdd.Version) ? string.Empty : node.AppsToAdd.Version);
                    appsToAdd["description"] = (string.IsNullOrEmpty(node.AppsToAdd.Description) ? string.Empty : node.AppsToAdd.Description);
                    appsToAdd["install_date"] = node.AppsToAdd.InstallDate;
                    appsToAdd["kb"] = (string.IsNullOrEmpty(node.AppsToAdd.KB) ? string.Empty : node.AppsToAdd.KB);
                    appsToAdd["reboot_required"] = (string.IsNullOrEmpty(node.AppsToAdd.RebootRequired) ? string.Empty : node.AppsToAdd.RebootRequired);
                    appsToAdd["release_date"] = node.AppsToAdd.ReleaseDate;
                    appsToAdd["file_data"] = filedata2;
                    appsToAdd["status"] = (string.IsNullOrEmpty(node.AppsToAdd.Status) ? string.Empty : node.AppsToAdd.Status);
                    appsToAdd["support_url"] = (string.IsNullOrEmpty(node.AppsToAdd.SupportUrl) ? string.Empty : node.AppsToAdd.SupportUrl);
                    appsToAdd["vendor_id"] = (string.IsNullOrEmpty(node.AppsToAdd.VendorId) ? string.Empty : node.AppsToAdd.VendorId);
                    appsToAdd["vendor_name"] = (string.IsNullOrEmpty(node.AppsToAdd.VendorName) ? string.Empty : node.AppsToAdd.VendorName);
                    appsToAdd["vendor_severity"] = (string.IsNullOrEmpty(node.AppsToAdd.VendorSeverity) ? string.Empty : node.AppsToAdd.VendorSeverity);
                    appsToAdd["repo"] = string.Empty;
                    appsToAdd["dependencies"] = tempEmptyArray;
                    appsToAddArray.Add(appsToAdd);
                }
            }

            var data = new JObject();
            data.Add("name", operation.Data.Name);
            data.Add("description", operation.Data.Description);
            data.Add("kb", operation.Data.Kb);
            data.Add("vendor_severity", operation.Data.VendorSeverity);
            data.Add("rv_severity", (string.IsNullOrEmpty(operation.Data.RvSeverity) ? string.Empty : operation.Data.RvSeverity));
            data.Add("support_url", operation.Data.SupportUrl);
            data.Add("release_date", operation.Data.ReleaseDate);
            data.Add("vendor_id", operation.Data.VendorId);
            data.Add("vendor_name", operation.Data.VendorName);
            data.Add("repo", (string.IsNullOrEmpty(operation.Data.Repo) ? string.Empty : operation.Data.Repo));
            data.Add("version", operation.Data.Version);

            var filedata = new JArray();
            foreach (var uri in operation.Data.FileData)
            {
                var jUri = new JObject();
                jUri["file_name"] = (string.IsNullOrEmpty(uri.FileName) ? string.Empty : uri.FileName);
                jUri["file_uri"] = (string.IsNullOrEmpty(uri.Uri) ? string.Empty : uri.Uri);
                jUri["file_size"] = uri.FileSize;
                jUri["file_hash"] = (string.IsNullOrEmpty(uri.Hash) ? string.Empty : uri.Hash);
                filedata.Add(jUri);
            }

            data.Add("file_data", filedata);

            json.Add("apps_to_delete", appsToDeleteArray);
            json.Add("apps_to_add", appsToAddArray);
            json.Add("data", data);

            return json.ToString();
        }
        public static RvSofOperation InstallSupportedAppsOperation(RvSofOperation operation)
        {
            var foundApplications = new List<InstallSupportedData>();
            var registryOpen = new RegistryReader();

            //Load all
            foreach (var installData in operation.InstallSupportedDataList)
            {
                var appDir = Path.Combine(Settings.UpdateDirectory, installData.Id);
                var found = false;

                foreach (var item in installData.Uris)
                {
                    var split = item.Split(new[] { '/' });
                    var filename = split[split.Length - 1];
                    var filepath = Path.Combine(appDir, filename);

                    if (File.Exists(filepath))
                        found = true;
                    else
                    {
                        found = false;
                        break;
                    }
                }

                if (!found)
                {
                    var result = new RVsofResult();
                    result.AppId = installData.Id;
                    result.Error = "Update did not Download: " + Environment.NewLine
                                                + installData.Name + Environment.NewLine;
                    operation.AddResult(result);
                }
                else
                {
                    Logger.Log("Update Files: Downloaded OK");
                    foundApplications.Add(installData);
                }
            }

            foreach (InstallSupportedData id in foundApplications)
            {
                try
                {
                    var appDirectory = Path.Combine(Settings.UpdateDirectory, id.Id);
                    var appFiles = Directory.GetFiles(appDirectory);

                    foreach (string file in appFiles)
                    {
                        var extension = Path.GetExtension(file);
                        Result result;

                        switch (extension)
                        {
                            case Extension.Exe:

                                Logger.Log("Installing: {0}", LogLevel.Info, id.Name);
                                result = ExeInstall(file, id.CliOptions);

                                break;

                            case Extension.Msi:

                                Logger.Log("Installing: {0}", LogLevel.Info, id.Name);
                                result = MsiInstall(file, id.CliOptions);

                                break;

                            case Extension.Msp:

                                Logger.Log("Installing: {0}", LogLevel.Info, id.Name);
                                result = MspInstall(file, id.CliOptions);

                                break;

                            default:

                                throw new Exception(String.Format("{0} is not a supported file format.", extension));
                        }

                        if (!result.Success)
                        {
                            var results = new RVsofResult();
                            results.Success = false.ToString();
                            results.AppId = id.Id;
                            results.Error = String.Format("Failed to install {0}. {1}. Exit code: {2}.", file, result.ExitCodeMessage, result.ExitCode);
                            Logger.Log("Failed to install: {0}", LogLevel.Info, file);
                            operation.AddResult(results);
                            break;
                        }

                        // If the last file was reached without issues, all should be good.
                        if (appFiles[appFiles.Length - 1].Equals(file))
                        {
                            var results = new RVsofResult();

                            //Get new list of installed applications after finishing installing applications.
                            operation.ListOfAppsAfterInstall = registryOpen.GetRegistryInstalledApplicationNames();

                            results.Success = true.ToString();
                            results.AppId = id.Id;
                            results.RebootRequired = result.Restart.ToString();
                            results.Data.Name = registryOpen.GetSetFromTwoLists(operation.ListOfInstalledApps, operation.ListOfAppsAfterInstall); //TODO: Keep eye on this, possibly not needed anymore.
                            Logger.Log("Update Success: {0}", LogLevel.Debug, file);
                            operation.AddResult(results);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Log("Could not install {0}.", LogLevel.Error, id.Name);
                    Logger.LogException(e);

                    var result = new RVsofResult();
                    result.AppId = id.Id;
                    result.Error = String.Format("Failed to install. {0}.", e.Message);
                    operation.AddResult(result);
                }
            }

            return operation;
        }
예제 #16
0
        public static RvSofOperation DownloadUpdate(RvSofOperation operation)
        {
            var url      = operation.InstallAgentUpdateDataList[0].ToString();
            var split    = url.Split(new[] { '/' });
            var filename = split[split.Length - 1];
            var filepath = Path.Combine(AgentUpdateDirectory, filename);
            int fileSize;

            _fileName = filename;


            if (!Directory.Exists(Settings.BackupDirectory))
            {
                Directory.CreateDirectory(Settings.BackupDirectory);
            }

            if (!Directory.Exists(AgentUpdateDirectory))
            {
                Directory.CreateDirectory(AgentUpdateDirectory);
            }

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }

            try
            {
                using (WebClient)
                {
                    if (Settings.Proxy != null)
                    {
                        WebClient.Proxy = Settings.Proxy;
                    }

                    WebClient.OpenRead(url);
                    fileSize = Convert.ToInt32(WebClient.ResponseHeaders["Content-Length"]);
                    WebClient.DownloadFile(new Uri(url), filepath);
                }
            }
            catch (Exception e)
            {
                Logger.Log("Could not download file {0}. Please check network settings and File URI.", LogLevel.Error, filename);
                Logger.LogException(e);
                var data   = operation.InstallSupportedDataList[0];
                var result = new RVsofResult();
                result.AppId = data.Id;
                result.Error = "RV Agent Update did not Download, check network and/or Download URI.";
                operation.AddResult(result);
                return(operation);
            }


            if (File.Exists(filepath))
            {
                var downloadedAgent     = new FileInfo(filepath);
                var downloadedAgentSize = Convert.ToInt32(downloadedAgent.Length);

                if (fileSize == downloadedAgentSize)
                {
                    //Install Operation for the Update
                    var updateResults = InstallOperation(operation);
                    if (updateResults != null)
                    {
                        return(updateResults);
                    }

                    //Installation of RV Agent Update Failed while Installing.
                    InstallSupportedData data = operation.InstallSupportedDataList[0];
                    var result = new RVsofResult();
                    result.AppId   = data.Id;
                    result.Error   = "RV Agent Update Failed while installing.";
                    result.Success = false.ToString();
                    operation.AddResult(result);
                    return(operation);
                }
                else
                {
                    //Downloaded failed, send back results
                    Logger.Log("RV Agent Update File download corrupted, unable to install the update.");
                    InstallSupportedData data = operation.InstallSupportedDataList[0];
                    var result = new RVsofResult();
                    result.AppId = data.Id;
                    result.Error = "File download corrupted, unable to install update.";
                    operation.AddResult(result);
                    return(operation);
                }
            }
            else
            {
                //Downloaded failed, send back results
                Logger.Log("RV Agent Update did not Download, check network and/or Download URI.", LogLevel.Info);
                InstallSupportedData data = operation.InstallSupportedDataList[0];
                var result = new RVsofResult();
                result.AppId = data.Id;
                result.Error = "RV Agent Update did not Download, check network and/or Download URI.";
                operation.AddResult(result);
                return(operation);
            }
        }