Ejemplo n.º 1
0
        private async Task <SshCommand> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default)
        {
            SshClient        sshClient;
            IObjectContainer scopeObjectContainer = context.DataContext.GetProperties()[SSHConnectScope.ParentContainerPropertyTag].GetValue(context.DataContext) as IObjectContainer;

            if (SSHClient.Expression == null)
            {
                if (scopeObjectContainer == null)
                {
                    throw new ArgumentException("SSHClient was not provided and cannot be retrieved from the container.");
                }

                sshClient = scopeObjectContainer.Get <SshClient>();
            }
            else
            {
                sshClient = SSHClient.Get(context);
            }

            var sshCommand = sshClient.CreateCommand(Command.Get(context));

            sshCommand.CommandTimeout = TimeSpan.FromMilliseconds(SSHTimeoutMS.Get(context));
            sshCommand.Execute();

            return(sshCommand);
        }
        private async Task ExecuteWithTimeout(NativeActivityContext context, CancellationToken cancellationToken = default)
        {
            var sshPassword   = new NetworkCredential("", Password.Get(context)).Password;
            var proxyPassword = new NetworkCredential("", ProxyPassword.Get(context)).Password;
            var sshTimeout    = TimeSpan.FromMilliseconds(SSHTimeoutMS.Get(context));

            ConnectionInfo connectionInfo;

            if (!string.IsNullOrEmpty(ProxyHost.Get(context)))         // Proxy defined
            {
                if (!string.IsNullOrEmpty(ProxyUsername.Get(context))) // Proxy authentication
                {
                    connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), Encoding.UTF8.GetBytes(sshPassword), ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context), ProxyUsername.Get(context), proxyPassword);
                }
                else // No proxy authentication
                {
                    connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), sshPassword, ProxyTypes.Http, ProxyHost.Get(context), ProxyPort.Get(context));
                }
            }
            else // No Proxy defined
            {
                connectionInfo = new PasswordConnectionInfo(Host.Get(context), Port.Get(context), Username.Get(context), sshPassword);
            }

            connectionInfo.Timeout = sshTimeout;

            sshClient = new SshClient(connectionInfo);
            sshClient.Connect();

            if (ShellExpectedPrompt.Expression != null)
            {
                var terminalMode = new Dictionary <TerminalModes, uint>
                {
                    { TerminalModes.ECHO, 53 }
                };

                expectedPromptRegex = new Regex(ShellExpectedPrompt.Get(context), RegexOptions.Compiled);
                currentShellStream  = sshClient.CreateShellStream("UiPathTeam.SSHConnector.Shell", 0, 0, 0, 0, 4096, terminalMode);
                var welcomeMessage = SSHHelpers.Expect(currentShellStream, expectedPromptRegex, string.Empty, sshTimeout);
                ShellWelcomeMessage.Set(context, welcomeMessage);
            }
        }
Ejemplo n.º 3
0
        private async Task <string> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default)
        {
            ShellStream      shellStream;
            Regex            expectedShellPromptRegex;
            IObjectContainer scopeObjectContainer = context.DataContext.GetProperties()[SSHConnectScope.ParentContainerPropertyTag]
                                                    .GetValue(context.DataContext) as IObjectContainer;

            if (ShellStream.Expression == null)
            {
                if (scopeObjectContainer == null)
                {
                    throw new ArgumentException("ShellStream was not provided and cannot be retrieved from the container.");
                }

                shellStream = scopeObjectContainer.Get <ShellStream>();
            }
            else
            {
                shellStream = ShellStream.Get(context);
            }

            if (ShellExpectedPrompt.Expression == null)
            {
                if (scopeObjectContainer == null)
                {
                    throw new ArgumentException("Shell Expected Prompt was not provided and cannot be retrieved from the container.");
                }

                expectedShellPromptRegex = scopeObjectContainer.Get <Regex>();
            }
            else
            {
                expectedShellPromptRegex = new Regex(ShellExpectedPrompt.Get(context), RegexOptions.Compiled);
            }

            return(SSHHelpers.Execute(shellStream,
                                      expectedShellPromptRegex,
                                      Command.Get(context),
                                      TimeSpan.FromMilliseconds(SSHTimeoutMS.Get(context)),
                                      CheckExitCode.Get(context)));
        }