Esempio n. 1
0
        public SynoReportViaSSH(DSMHost host, IProxySettings proxy = null)
        {
            RmExecutionMode = ConsoleCommandMode.InteractiveSudo;

            _host = host;

            int i = 0;

            AuthenticationMethod[] methods = new AuthenticationMethod[host.AuthenticationSection.Count];
            foreach (var m in host.AuthenticationMethods)
            {
                methods[i++] = m.getAuthenticationMethod();
            }

            if (proxy != null)
            {
                ProxyTypes proxypath;
                if (!Enum.TryParse(proxy.ProxyType, true, out proxypath))
                {
                    proxypath = ProxyTypes.None;
                }
                _ci = new ConnectionInfo(host.Host, host.Port, host.UserName, proxypath, proxy.Host, proxy.Port, proxy.UserName, proxy.Password, methods);
            }
            else
            {
                _ci = new ConnectionInfo(host.Host, host.Port, host.UserName, methods);
            }
        }
Esempio n. 2
0
        public SynoReportViaSSH(DSMHost host, Func <string, string> getPassPhraseMethod, Func <DSMKeyboardInteractiveEventArgs, string> getInteractiveMethod, IProxySettings proxy = null)
        {
            bool canceled = false;

            RmExecutionMode = ConsoleCommandMode.InteractiveSudo;

            _host = host ?? throw new ArgumentNullException(nameof(host));
            if (getPassPhraseMethod == null)
            {
                throw new ArgumentNullException(nameof(getPassPhraseMethod));
            }
            if (getInteractiveMethod == null)
            {
                throw new ArgumentNullException(nameof(getInteractiveMethod));
            }
            _interactiveMethod = getInteractiveMethod;

            int i = 0;

            AuthenticationMethod[] methods = new AuthenticationMethod[host.AuthenticationSection.Count];
            foreach (var m in host.AuthenticationMethods)
            {
                methods[i++] = m.getAuthenticationMethod(host.UserName, host.StorePassPhrases, getPassPhraseMethod, getInteractiveMethod, out canceled);
            }
            if (!canceled)
            {
                if (proxy != null)
                {
                    ProxyTypes proxypath;
                    if (!Enum.TryParse(proxy.ProxyType, true, out proxypath))
                    {
                        proxypath = ProxyTypes.None;
                    }
                    _ci = new ConnectionInfo(host.Host, host.Port, host.UserName, proxypath, proxy.Host, proxy.Port, proxy.UserName, proxy.Password, methods);
                }
                else
                {
                    _ci = new ConnectionInfo(host.Host, host.Port, host.UserName, methods);
                }

                _ci.AuthenticationBanner += AuthorizationBannerAction;

                foreach (var am in _ci.AuthenticationMethods)
                {
                    KeyboardInteractiveAuthenticationMethod kb = am as KeyboardInteractiveAuthenticationMethod;
                    if (kb != null)
                    {
                        kb.AuthenticationPrompt += AuthenticationPromptAction;
                    }
                }
            }
        }