Esempio n. 1
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());
        }
Esempio n. 2
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());
        }
Esempio n. 3
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();
            }
        }