Exemple #1
0
        public async Task RunScript(Guid savedScriptId,
                                    int scriptRunId,
                                    string initiator,
                                    ScriptInputType scriptInputType,
                                    string authToken)
        {
            try
            {
                Logger.Write($"Script run started.  Script ID: {savedScriptId}. Script Run: {scriptRunId}. Initiator: {initiator}.");

                var connectionInfo = ConfigService.GetConnectionInfo();
                var url            = $"{connectionInfo.Host}/API/SavedScripts/{savedScriptId}";
                using var hc = new HttpClient();
                hc.DefaultRequestHeaders.Add("Authorization", authToken);
                var savedScript = await hc.GetFromJsonAsync <SavedScript>(url);

                var result = ExecuteScriptContent(savedScript.Shell,
                                                  Guid.NewGuid().ToString(),
                                                  savedScript.Content,
                                                  TimeSpan.FromMinutes(AppConstants.ScriptRunExpirationMinutes));

                result.SenderUserName = initiator;
                result.ScriptRunId    = scriptRunId;
                result.InputType      = scriptInputType;
                result.SavedScriptId  = savedScriptId;

                var responseResult = await SendResultsToApi(result, authToken);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
        }
Exemple #2
0
        public async Task RunCommandFromTerminal(ScriptingShell shell,
                                                 string command,
                                                 string authToken,
                                                 string senderUsername,
                                                 string senderConnectionID,
                                                 ScriptInputType scriptInputType,
                                                 TimeSpan timeout,
                                                 HubConnection hubConnection)
        {
            try
            {
                var result = ExecuteScriptContent(shell, senderConnectionID, command, timeout);

                result.InputType      = scriptInputType;
                result.SenderUserName = senderUsername;

                var responseResult = await SendResultsToApi(result, authToken);

                if (responseResult is null)
                {
                    return;
                }
                await hubConnection.SendAsync("ScriptResult", responseResult.ID);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                await hubConnection.SendAsync("DisplayMessage",
                                              "There was an error executing the command. It has been logged on the client device.",
                                              "Error executing command.",
                                              "bg-danger",
                                              senderConnectionID);
            }
        }