public static ISofOperation PrepareRebootResults()
        {
            ISofOperation operation = new SofOperation();
            var location = Path.Combine(Settings.AgentDirectory, "rebootoperation.data");
            if (!File.Exists(location)) return null;

            var operationId = File.ReadAllText(location);
            Logger.Log("Found reboot operation, preparing to send back results for operation id {0}", LogLevel.Info, operationId);

            var rebooted = (IsBootUp().ToLower() == "yes") ? true.ToString().ToLower() : false.ToString().ToLower();

            var json = new JObject();
            json["operation"]    = "reboot";
            json["operation_id"] = operationId;
            json["success"]      = (String.IsNullOrEmpty(rebooted)) ? "no" : rebooted;

            operation.Id        = operationId;
            operation.Api       = ApiCalls.CoreRebootResults();
            operation.Type      = "reboot";
            operation.RawResult = json.ToString();

            File.Delete(location);
            Logger.Log("Deleted reboot operation file, sending back results.");

            return operation;
        }
示例#2
0
        private static bool ConfirmOperation(string message, bool success)
        {
            if (success)
            {
                var operation = new SofOperation(message);

                switch (operation.Type)
                {
                case OperationValue.InstallWindowsUpdate:
                    Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallOsUpdate);
                    return(true);

                case OperationValue.InstallSupportedApp:
                    Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallSupportedApp);
                    return(true);

                case OperationValue.InstallCustomApp:
                    Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallCustomApp);
                    return(true);

                case OperationValue.InstallAgentUpdate:
                    Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallAgentUpdate);
                    return(true);

                case OperationValue.Uninstall:
                    Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.UninstallApplication);
                    return(true);

                default:
                    return(false);
                }
            }

            return(false);
        }
示例#3
0
        public void ResumeOperations()
        {
            var operation = new SofOperation {
                Type = OperationValue.ResumeOp
            };
            var data = operation.ToJson();
            var json = JObject.Parse(data);

            json["plugin"] = "rv";
            json["type"]   = OperationValue.ResumeOp;
            var stringJson = json.ToString();

            ProcessOperation(stringJson);
        }
        public void InitialDataSender()
        {
            var operation = new SofOperation();

            if (!(Settings.AgentId.Equals(String.Empty)))
            {
                operation.Api = ApiCalls.CoreStartUp();
                operation.Type = OperationValue.Startup;
            }
            else
            {
                operation.Type = OperationValue.NewAgent;
                operation.Api = ApiCalls.CoreNewAgent;
            }

            ProcessOperation(operation.ToJson());
        }
示例#5
0
        public void InitialDataSender()
        {
            var operation = new SofOperation();

            if (!(Settings.AgentId.Equals(String.Empty)))
            {
                operation.Api  = ApiCalls.CoreStartUp();
                operation.Type = OperationValue.Startup;
            }
            else
            {
                operation.Type = OperationValue.NewAgent;
                operation.Api  = ApiCalls.CoreNewAgent;
            }

            ProcessOperation(operation.ToJson());
        }
示例#6
0
        public void ResumeOperations()
        {
            try
            {
                var operation = new SofOperation {
                    Type = OperationValue.ResumeOp
                };
                var data = operation.ToJson();
                var json = JObject.Parse(data);
                json["plugin"] = "rv";
                json["type"]   = OperationValue.ResumeOp;
                var stringJson = json.ToString();

                ProcessOperation(stringJson);
            }
            catch
            {
                Logger.Log("Error while \"ResumingOperations\".", LogLevel.Error);
            }
        }
示例#7
0
        public void InitialDataSender()
        {
            var operation = new SofOperation();

            try
            {
                if (!(Settings.AgentId.Equals(String.Empty)))
                {
                    operation.Api  = ApiCalls.CoreStartUp();
                    operation.Type = OperationValue.Startup;
                }
                else
                {
                    operation.Type = OperationValue.NewAgent;
                    operation.Api  = ApiCalls.CoreNewAgent();
                }
            }
            catch
            {
                Logger.Log("Error while gathering Inititial Data for \"InititalDataSender\".", LogLevel.Error);
            }

            ProcessOperation(operation.ToJson());
        }
        public void InitialDataSender()
        {
            var operation = new SofOperation();

            try
            {
                if (!(Settings.AgentId.Equals(String.Empty)))
                {
                    operation.Api = ApiCalls.CoreStartUp();
                    operation.Type = OperationValue.Startup;
                }
                else
                {
                    operation.Type = OperationValue.NewAgent;
                    operation.Api = ApiCalls.CoreNewAgent;
                }
            }
            catch
            {
                Logger.Log("Error while gathering Inititial Data for \"InititalDataSender\".", LogLevel.Error);
            }

            ProcessOperation(operation.ToJson());
        }
        private void SendNewUpdatesHandler(object sender, ElapsedEventArgs e)
        {
            var operation = new SofOperation
                {
                    Plugin = "rv",
                    Type   = RvOperationValue.UpdatesAndApplications,
                    Api    = ApiCalls.RvUpdatesApplications()
                };

            RegisterOperation(operation);
            RunOperation(operation);
        }
        public void ResumeOperations()
        {
            var operation = new SofOperation {Type = OperationValue.ResumeOp};
            var data = operation.ToJson();
            var json = JObject.Parse(data);
                json["plugin"] = "rv";
                json["type"] = OperationValue.ResumeOp;
            var stringJson = json.ToString();

            ProcessOperation(stringJson);
        }
        /// <summary>
        /// Based on the message sent from the server, the agent determines which plugin
        /// performs which operations. 
        /// See the ServerOperationFormart (SOF) spec for more information.
        /// </summary>
        /// <param name="serverMessage">The JSON-base SOF message sent from the server</param>
        private void ProcessOperation(string serverMessage)
        {
            Logger.Log("Process operation: {0}", LogLevel.Debug, serverMessage);
            ISofOperation operation = new SofOperation(serverMessage);

            try
            {
                switch (operation.Type)
                {
                    case OperationValue.Startup:
                        operation.Type = OperationValue.Startup;
                        operation.Api = ApiCalls.CoreStartUp();
                        operation = PluginsInitialDataOperation(operation);
                        operation.RawResult = InitialDataFormatter(operation);
                        SaveAndSendResults(operation);
                        break;

                    case OperationValue.NewAgent:
                        Logger.Info("IN NEW AGENT");
                        operation.Type = OperationValue.NewAgent;
                        operation.Api = ApiCalls.CoreNewAgent;
                        operation = PluginsInitialDataOperation(operation);
                        operation.RawResult = InitialDataFormatter(operation);
                        Logger.Info("BEFORE save and send");
                        SaveAndSendResults(operation);
                        Logger.Info("BEFORE BREAK");
                        break;

                    case OperationValue.NewAgentId:
                        Settings.AgentId = operation.JsonMessage[OperationKey.AgentId].ToString();
                        break;

                    case OperationValue.InvalidAgentId:
                        _queue.Pause();
                        Logger.Log("Invalid agent ID. Generating new one.");
                        Settings.AgentId = String.Empty;
                        InitialDataSender();
                        _queue.Done();
                        break;

                    case OperationValue.SystemInfo:
                        operation.RawResult = GetSystemInfo();
                        break;

                    case OperationValue.Reboot:
                        Tools.SaveRebootOperationId(operation);
                        Tools.SystemReboot();
                        break;

                    case OperationValue.Shutdown:
                        Tools.SystemShutdown();
                        break;

                    case OperationValue.ReverseTunnel:
                        //TODO: WILL COME SOON
                        break;

                    default:
                        if (_plugins.ContainsKey(operation.Plugin))
                        {
                            //The operation belongs to a plugin.
                            _plugins[operation.Plugin].RunOperation(operation);
                        }
                        else
                        {
                            PluginNotFound(operation);
                        }
                        break;
                }
            }
            catch (Exception e)
            {
                Logger.Log("Couldn't complete operation.", LogLevel.Error);
                Logger.LogException(e);

            Logger.Info("END OF FUNCTION");

                switch (operation.Type)
                {
                    case OperationValue.InstallWindowsUpdate:
                        operation.Api = ApiCalls.RvInstallWinUpdateResults();
                        break;

                    case OperationValue.InstallSupportedApp:
                        operation.Api = ApiCalls.RvInstallSupportedAppsResults();
                        break;

                    case OperationValue.InstallCustomApp:
                        operation.Api = ApiCalls.RvInstallCustomAppsResults();
                        break;

                    case OperationValue.InstallAgentUpdate:
                        operation.Api = ApiCalls.RvInstallAgentUpdateResults();
                        break;

                    case OperationValue.Uninstall:
                        operation.Api = ApiCalls.RvUninstallOperation();
                        break;
                }

                _queue.Pause();
                MajorFailure(operation, e);
                _queue.Done();

            }
        }
        private static bool ConfirmOperation(string message, bool success)
        {
            if (success)
            {
                var operation = new SofOperation(message);

                switch (operation.Type)
                {
                    case OperationValue.InstallWindowsUpdate:
                        Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallOsUpdate);
                        return true;

                    case OperationValue.InstallSupportedApp:
                        Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallSupportedApp);
                        return true;

                    case OperationValue.InstallCustomApp:
                        Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallCustomApp);
                        return true;

                    case OperationValue.InstallAgentUpdate:
                        Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.InstallAgentUpdate);
                        return true;

                    case OperationValue.Uninstall:
                        Operations.SaveOperationsToDisk(operation.RawOperation, Operations.OperationType.UninstallApplication);
                        return true;

                    default:
                        return false;
                }
            }

             return false;
        }
示例#13
0
        /// <summary>
        /// Based on the message sent from the server, the agent determines which plugin
        /// performs which operations.
        /// See the ServerOperationFormart (SOF) spec for more information.
        /// </summary>
        /// <param name="serverMessage">The JSON-base SOF message sent from the server</param>
        private void ProcessOperation(string serverMessage)
        {
            Logger.Log("Process operation: {0}", LogLevel.Info, serverMessage);
            ISofOperation operation = new SofOperation(serverMessage);

            try
            {
                switch (operation.Type)
                {
                case OperationValue.Startup:
                    operation.Type      = OperationValue.Startup;
                    operation.Api       = ApiCalls.CoreStartUp();
                    operation           = PluginsInitialDataOperation(operation);
                    operation.RawResult = InitialDataFormatter(operation);
                    SaveAndSendResults(operation);
                    break;

                case OperationValue.NewAgent:
                    Logger.Info("IN NEW AGENT");
                    operation.Type      = OperationValue.NewAgent;
                    operation.Api       = ApiCalls.CoreNewAgent();
                    operation           = PluginsInitialDataOperation(operation);
                    operation.RawResult = InitialDataFormatter(operation);
                    Logger.Info("BEFORE save and send");
                    SaveAndSendResults(operation);
                    Logger.Info("BEFORE BREAK");
                    break;

                case OperationValue.NewAgentId:
                    Settings.AgentId = operation.JsonMessage[OperationKey.AgentId].ToString();
                    break;

                case OperationValue.InvalidAgentId:
                    _queue.Pause();
                    Logger.Log("Invalid agent ID. Generating new one.");
                    Settings.AgentId = String.Empty;
                    InitialDataSender();
                    _queue.Done();
                    break;

                case OperationValue.SystemInfo:
                    operation.RawResult = GetSystemInfo();
                    break;

                case OperationValue.Reboot:
                    Tools.SaveRebootOperationId(operation);
                    Tools.SystemReboot();
                    break;

                case OperationValue.Shutdown:
                    Tools.SystemShutdown();
                    break;

                case OperationValue.RefreshUris:
                    ApiCalls.RefreshUris(operation);
                    break;

                case OperationValue.ReverseTunnel:
                    //TODO: WILL COME SOON
                    break;

                default:
                    if (_plugins.ContainsKey(operation.Plugin))
                    {
                        //The operation belongs to a plugin.
                        _plugins[operation.Plugin].RunOperation(operation);
                    }
                    else
                    {
                        PluginNotFound(operation);
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Log("Couldn't complete operation.", LogLevel.Error);
                Logger.LogException(e);

                Logger.Info("END OF FUNCTION");

                switch (operation.Type)
                {
                case OperationValue.InstallWindowsUpdate:
                    operation.Api = ApiCalls.RvInstallWinUpdateResults();
                    break;

                case OperationValue.InstallSupportedApp:
                    operation.Api = ApiCalls.RvInstallSupportedAppsResults();
                    break;

                case OperationValue.InstallCustomApp:
                    operation.Api = ApiCalls.RvInstallCustomAppsResults();
                    break;

                case OperationValue.InstallAgentUpdate:
                    operation.Api = ApiCalls.RvInstallAgentUpdateResults();
                    break;

                case OperationValue.Uninstall:
                    operation.Api = ApiCalls.RvUninstallOperation();
                    break;
                }

                _queue.Pause();
                MajorFailure(operation, e);
                _queue.Done();
            }
        }
        public void ResumeOperations()
        {
            try
            {
                var operation = new SofOperation {Type = OperationValue.ResumeOp};
                var data = operation.ToJson();
                var json = JObject.Parse(data);
                json["plugin"] = "rv";
                json["type"] = OperationValue.ResumeOp;
                var stringJson = json.ToString();

                ProcessOperation(stringJson);
            }
            catch
            {
                Logger.Log("Error while \"ResumingOperations\".", LogLevel.Error);
            }
        }