Esempio n. 1
0
        public WebServer()
        {
            context  = AzusaContext.GetInstance();
            handlers = new List <IAzusaWebHandler>();
            int port = AzusaContext.FindFreePort();

            Prefix       = String.Format("http://localhost:{0}/", port);
            httpListener = new HttpListener();
            httpListener.Prefixes.Add(Prefix);
            httpListener.Start();
            thread          = new Thread(ListenerThread);
            thread.Priority = ThreadPriority.Lowest;
            thread.Name     = "Internal Webserver";
            thread.Start();
        }
Esempio n. 2
0
        private bool AttemptSshPortForward()
        {
            context.Splash.SetLabel("Überprüfe Verfügbarkeit des SSH-Proxy...");

            string hostname = context.Ini["sshProxy"]["host"];
            ushort port     = Convert.ToUInt16(context.Ini["sshProxy"]["port"]);
            bool   tcpProbe = TcpProbe(hostname, port);

            if (!tcpProbe)
            {
                return(false);
            }

            context.Splash.SetLabel("Versuche über SSH-Proxy mit Datenbank zu verbinden...");
            string sshHost     = context.Ini["sshProxy"]["host"];
            int    sshPort     = Convert.ToInt32(context.Ini["sshProxy"]["port"]);
            string sshUser     = context.Ini["sshProxy"]["username"];
            string sshPassword = null;

            if (context.Ini["sshProxy"].ContainsKey("password"))
            {
                sshPassword = context.Ini["sshProxy"]["password"];
            }

            List <AuthenticationMethod> authenticationMethods = new List <AuthenticationMethod>();

            authenticationMethods.Add(new NoneAuthenticationMethod(sshUser));

            if (File.Exists("ssh.key"))
            {
                authenticationMethods.Add(
                    new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile[] { new PrivateKeyFile("ssh.key") }));
            }

            if (string.IsNullOrEmpty(sshPassword) && authenticationMethods.Count == 1)
            {
                context.Splash.Invoke((MethodInvoker) delegate
                {
                    sshPassword =
                        TextInputForm.PromptPassword(String.Format("Passwort für {0} auf {1}?", sshUser, sshHost),
                                                     context.Splash);
                });
            }

            if (!string.IsNullOrEmpty(sshPassword) && authenticationMethods.Count == 1)
            {
                authenticationMethods.Add(new PasswordAuthenticationMethod(sshUser, sshPassword));
            }

            if (authenticationMethods.Count > 1)
            {
                context.Splash.SetLabel("Verbinde mit SSH Server...");
                ConnectionInfo sshConnectionInfo =
                    new ConnectionInfo(sshHost, sshPort, sshUser, authenticationMethods.ToArray());
                context.SSH = new SshClient(sshConnectionInfo);
                if (!context.SSH.IsConnected)
                {
                    context.SSH.Connect();
                }

                context.Splash.SetLabel("Starte Port-Forwarding...");
                uint          localPort = (uint)AzusaContext.FindFreePort();
                ForwardedPort sqlPort   = new ForwardedPortLocal("127.0.0.1", localPort, context.Ini["postgresql"]["server"], Convert.ToUInt16(context.Ini["postgresql"]["port"]));
                context.SSH.AddForwardedPort(sqlPort);
                sqlPort.Start();
                bool worksWithForward = TcpProbe("127.0.0.1", (int)localPort);
                if (worksWithForward)
                {
                    context.Ini["postgresql"]["server"] = "127.0.0.1";
                    context.Ini["postgresql"]["port"]   = localPort.ToString();
                    return(true);
                }
                else
                {
                    context.SSH.Disconnect();
                    context.SSH = null;
                }
            }

            return(false);
        }