Beispiel #1
0
        public static void RealMain(string[] _args)
        {
            List <string> args = new List <string>(_args);
            Dictionary <string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);

            if (Duplicati.Library.Utility.Utility.IsClientWindows && !Duplicati.Library.Utility.Utility.ParseBoolOption(options, DETACHED_PROCESS))
            {
                Duplicati.Library.Utility.Win32.AttachConsole(Duplicati.Library.Utility.Win32.ATTACH_PARENT_PROCESS);
            }

            foreach (string s in args)
            {
                if (
                    s.Equals("help", StringComparison.OrdinalIgnoreCase) ||
                    s.Equals("/help", StringComparison.OrdinalIgnoreCase) ||
                    s.Equals("usage", StringComparison.OrdinalIgnoreCase) ||
                    s.Equals("/usage", StringComparison.OrdinalIgnoreCase))
                {
                    options["help"] = "";
                }
            }

            if (options.ContainsKey("help"))
            {
                Console.WriteLine("Supported commandline arguments:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in SupportedCommands)
                {
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);
                    if (arg.Name == TOOLKIT_OPTION)
                    {
                        Console.WriteLine("    Supported toolkits: {0}{1}", string.Join(", ", arg.ValidValues), Environment.NewLine);
                    }
                }

                Console.WriteLine("Additionally, these server options are also supported:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in Duplicati.Server.Program.SupportedCommands)
                {
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);
                }

                return;
            }

            options.TryGetValue(BROWSER_COMMAND_OPTION, out _browser_command);

            string toolkit;

            if (!options.TryGetValue(TOOLKIT_OPTION, out toolkit))
            {
#if !(__MonoCS__ || __WindowsGTK__ || ENABLE_GTK)
                if (Library.Utility.Utility.IsClientLinux && !Library.Utility.Utility.IsClientOSX)
                {
                    Console.WriteLine("Warning: this build does not support GTK, rebuild with ENABLE_GTK defined");
                }
#endif
                toolkit = GetDefaultToolKit(true);
            }
            else
            {
                if (TOOLKIT_WINDOWS_FORMS.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_WINDOWS_FORMS;
                }
#if __MonoCS__ || __WindowsGTK__ || ENABLE_GTK
                else if (TOOLKIT_GTK.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_GTK;
                }
                else if (TOOLKIT_GTK_APP_INDICATOR.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_GTK_APP_INDICATOR;
                }
#endif
                else if (TOOLKIT_COCOA.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_COCOA;
                }
                else if (TOOLKIT_RUMPS.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_RUMPS;
                }
                else
                {
                    toolkit = GetDefaultToolKit(true);
                }
            }

            HostedInstanceKeeper hosted = null;
            var    openui         = false;
            string password       = null;
            var    saltedpassword = false;
            var    serverURL      = new Uri(DEFAULT_HOSTURL);

            if (!Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION))
            {
                try
                {
                    hosted = new HostedInstanceKeeper(_args);
                }
                catch (Server.SingleInstance.MultipleInstanceException)
                {
                    return;
                }

                // We have a hosted server, if this is the first run,
                // we should open the main page
                openui         = Duplicati.Server.Program.IsFirstRun || Duplicati.Server.Program.ServerPortChanged;
                password       = Duplicati.Server.Program.DataConnection.ApplicationSettings.WebserverPassword;
                saltedpassword = true;
                serverURL      = (new UriBuilder(serverURL)
                {
                    Port = Duplicati.Server.Program.ServerPort
                }).Uri;
            }

            if (Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION) && Library.Utility.Utility.ParseBoolOption(options, READCONFIGFROMDB_OPTION))
            {
                databaseConnection = Server.Program.GetDatabaseConnection(options);
            }

            string pwd;

            if (options.TryGetValue("webserver-password", out pwd))
            {
                password       = pwd;
                saltedpassword = false;
            }

            if (databaseConnection != null)
            {
                password       = databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon;
                saltedpassword = false;
            }

            if (databaseConnection != null)
            {
                var cert   = databaseConnection.ApplicationSettings.ServerSSLCertificate;
                var scheme = "http";

                if (cert != null && cert.HasPrivateKey)
                {
                    scheme = "https";
                }

                serverURL = (new UriBuilder(serverURL)
                {
                    Port = databaseConnection.ApplicationSettings.LastWebserverPort == -1 ? serverURL.Port : databaseConnection.ApplicationSettings.LastWebserverPort,
                    Scheme = scheme
                }).Uri;
            }

            string url;

            if (options.TryGetValue(HOSTURL_OPTION, out url))
            {
                serverURL = new Uri(url);
            }

            using (hosted)
            {
                var reSpawn = 0;

                do
                {
                    try
                    {
                        System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                        using (Connection = new HttpServerConnection(serverURL, password, saltedpassword, databaseConnection != null, options))
                        {
                            using (var tk = RunTrayIcon(toolkit))
                            {
                                if (hosted != null && Server.Program.Instance != null)
                                {
                                    Server.Program.Instance.SecondInstanceDetected +=
                                        new Server.SingleInstance.SecondInstanceDelegate(
                                            x => { tk.ShowUrlInWindow(serverURL.ToString()); });
                                }

                                // TODO: If we change to hosted browser this should be a callback
                                if (openui)
                                {
                                    try
                                    {
                                        tk.ShowUrlInWindow(Connection.StatusWindowURL);

                                        Duplicati.Server.Program.IsFirstRun        = false;
                                        Duplicati.Server.Program.ServerPortChanged = false;
                                    }
                                    catch
                                    {
                                    }
                                }

                                // If the server shuts down, shut down the tray-icon as well
                                Action shutdownEvent = () =>
                                {
                                    // Make sure we do not start again after
                                    // a controlled exit
                                    reSpawn = 100;
                                    tk.InvokeExit();
                                };

                                if (hosted != null)
                                {
                                    hosted.InstanceShutdown += shutdownEvent;
                                }

                                tk.Init(_args);

                                // If the tray-icon quits, stop the server
                                reSpawn = 100;

                                // Make sure that the server shutdown does not access the tray-icon,
                                // as it would be disposed by now
                                if (hosted != null)
                                {
                                    hosted.InstanceShutdown -= shutdownEvent;
                                }
                            }
                        }
                    }
                    catch (WebException ex)
                    {
                        System.Diagnostics.Trace.WriteLine("Request error: " + ex.ToString());
                        Console.WriteLine("Request error: " + ex.ToString());

                        reSpawn++;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine("Unexpected error: " + ex.ToString());
                        Console.WriteLine("Unexpected error: " + ex.ToString());
                        return;
                    }
                } while (reSpawn < 3);
            }
        }
Beispiel #2
0
        public static void RealMain(string[] _args)
        {
            List <string> args = new List <string>(_args);
            Dictionary <string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);

            if (Platform.IsClientWindows && (Duplicati.Library.AutoUpdater.UpdaterManager.IsRunningInUpdateEnvironment || !Duplicati.Library.Utility.Utility.ParseBoolOption(options, DETACHED_PROCESS)))
            {
                Duplicati.Library.Utility.Win32.AttachConsole(Duplicati.Library.Utility.Win32.ATTACH_PARENT_PROCESS);
            }

            foreach (string s in args)
            {
                if (
                    s.Equals("help", StringComparison.OrdinalIgnoreCase) ||
                    s.Equals("/help", StringComparison.OrdinalIgnoreCase) ||
                    s.Equals("usage", StringComparison.OrdinalIgnoreCase) ||
                    s.Equals("/usage", StringComparison.OrdinalIgnoreCase))
                {
                    options["help"] = "";
                }
            }

            if (options.ContainsKey("help"))
            {
                Console.WriteLine("Supported commandline arguments:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in SupportedCommands)
                {
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);
                    if (arg.Name == TOOLKIT_OPTION)
                    {
                        Console.WriteLine("    Supported toolkits: {0}{1}", string.Join(", ", arg.ValidValues), Environment.NewLine);
                    }
                }

                Console.WriteLine("Additionally, these server options are also supported:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in Duplicati.Server.Program.SupportedCommands)
                {
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);
                }

                return;
            }

            options.TryGetValue(BROWSER_COMMAND_OPTION, out _browser_command);

            string toolkit;

            if (!options.TryGetValue(TOOLKIT_OPTION, out toolkit))
            {
#if !(__MonoCS__ || __WindowsGTK__ || ENABLE_GTK)
                if (Platform.IsClientPosix && !Platform.IsClientOSX)
                {
                    Console.WriteLine("Warning: this build does not support GTK, rebuild with ENABLE_GTK defined");
                }
#endif
                toolkit = GetDefaultToolKit();
            }
            else
            {
                if (TOOLKIT_WINDOWS_FORMS.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_WINDOWS_FORMS;
                }
#if __MonoCS__ || __WindowsGTK__ || ENABLE_GTK
                else if (TOOLKIT_GTK.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_GTK;
                }
                else if (TOOLKIT_GTK_APP_INDICATOR.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_GTK_APP_INDICATOR;
                }
#endif
                else if (TOOLKIT_COCOA.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_COCOA;
                }
                else if (TOOLKIT_RUMPS.Equals(toolkit, StringComparison.OrdinalIgnoreCase))
                {
                    toolkit = TOOLKIT_RUMPS;
                }
                else
                {
                    toolkit = GetDefaultToolKit();
                }
            }

            HostedInstanceKeeper hosted = null;

            string password       = null;
            var    saltedpassword = false;

            if (!Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION))
            {
                try
                {
                    hosted = new HostedInstanceKeeper(_args);
                }
                catch (Server.SingleInstance.MultipleInstanceException)
                {
                    return;
                }

                // We have a hosted server, if this is the first run,
                // we should open the main page
                openui         = Duplicati.Server.Program.IsFirstRun || Duplicati.Server.Program.ServerPortChanged;
                password       = Duplicati.Server.Program.DataConnection.ApplicationSettings.WebserverPassword;
                saltedpassword = true;
                // Tell the hosted server it was started by the TrayIcon
                Duplicati.Server.Program.Origin = "Tray icon";

                var cert   = Duplicati.Server.Program.DataConnection.ApplicationSettings.ServerSSLCertificate;
                var scheme = "http";

                if (cert != null && cert.HasPrivateKey)
                {
                    scheme = "https";
                }

                serverURL = (new UriBuilder(serverURL)
                {
                    Port = Duplicati.Server.Program.ServerPort,
                    Scheme = scheme
                }).Uri;
            }
            else if (Library.Utility.Utility.ParseBoolOption(options, READCONFIGFROMDB_OPTION))
            {
                databaseConnection = Server.Program.GetDatabaseConnection(options);

                if (databaseConnection != null)
                {
                    disableTrayIconLogin = databaseConnection.ApplicationSettings.DisableTrayIconLogin;
                    password             = databaseConnection.ApplicationSettings.WebserverPasswordTrayIcon;
                    saltedpassword       = false;

                    var cert   = databaseConnection.ApplicationSettings.ServerSSLCertificate;
                    var scheme = "http";

                    if (cert != null && cert.HasPrivateKey)
                    {
                        scheme = "https";
                    }

                    serverURL = (new UriBuilder(serverURL)
                    {
                        Port = databaseConnection.ApplicationSettings.LastWebserverPort == -1 ? serverURL.Port : databaseConnection.ApplicationSettings.LastWebserverPort,
                        Scheme = scheme
                    }).Uri;
                }
            }

            string pwd;

            if (options.TryGetValue("webserver-password", out pwd))
            {
                password       = pwd;
                saltedpassword = false;
            }

            string url;

            if (options.TryGetValue(HOSTURL_OPTION, out url))
            {
                serverURL = new Uri(url);
            }

            StartTray(_args, options, toolkit, hosted, password, saltedpassword);
        }
Beispiel #3
0
        public static void RealMain(string[] _args)
        {
            Library.UsageReporter.Reporter.Initialize();

            List<string> args = new List<string>(_args);
            Dictionary<string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);

            foreach (string s in args)
                if (
                    s.Equals("help", StringComparison.InvariantCultureIgnoreCase) ||
                    s.Equals("/help", StringComparison.InvariantCultureIgnoreCase) ||
                    s.Equals("usage", StringComparison.InvariantCultureIgnoreCase) ||
                    s.Equals("/usage", StringComparison.InvariantCultureIgnoreCase))
                    options["help"] = "";

            if (options.ContainsKey("help"))
            {
                Console.WriteLine("Supported commandline arguments:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in SupportedCommands)
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);

                Console.WriteLine("Additionally, these server options are also supported:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in Duplicati.Server.Program.SupportedCommands)
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);

                return;
            }            
            
            options.TryGetValue(BROWSER_COMMAND_OPTION, out _browser_command);
            
            string toolkit;
            if (!options.TryGetValue(TOOLKIT_OPTION, out toolkit))
                toolkit = GetDefaultToolKit();
            else 
            {
                if (TOOLKIT_WINDOWS_FORMS.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                    toolkit = TOOLKIT_WINDOWS_FORMS;
#if __MonoCS__ || __WindowsGTK__                
                else if (TOOLKIT_GTK.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                    toolkit = TOOLKIT_GTK;
                else if (TOOLKIT_GTK_APP_INDICATOR.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                    toolkit = TOOLKIT_GTK_APP_INDICATOR;
#endif
                else if (TOOLKIT_COCOA.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                    toolkit = TOOLKIT_COCOA;
                else
                    toolkit = GetDefaultToolKit();
            }

            HostedInstanceKeeper hosted = null;
            bool openui = false;
            string password = null;
            bool saltedpassword = false;
            if (!Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION))
            {
                try
                {
                    hosted = new HostedInstanceKeeper(_args);
                }
                catch (Server.SingleInstance.MultipleInstanceException)
                {
                    return;
                }

                // We have a hosted server, if this is the first run, 
                // we should open the main page
                openui = Duplicati.Server.Program.IsFirstRun || Duplicati.Server.Program.ServerPortChanged;
                password = Duplicati.Server.Program.DataConnection.ApplicationSettings.WebserverPassword;
                saltedpassword = true;
            }

            using (hosted)
            {
                string url;
                if (!options.TryGetValue(HOSTURL_OPTION, out url))
                {
                    if (hosted == null)
                    {
                        url = DEFAULT_HOSTURL;
                    }
                    else
                    {
                        int port = Duplicati.Server.Program.ServerPort;
                        url = "http://127.0.0.1:" + port;
                    }
                }

                string pwd;
                if (options.TryGetValue("webserver-password", out pwd))
                {
                    password = pwd;
                    saltedpassword = false;
                }

                using (Connection = new HttpServerConnection(new Uri(url), password, saltedpassword))
                {
                    using(var tk = RunTrayIcon(toolkit))
                    {
                        if (hosted != null && Server.Program.Instance != null)
                            Server.Program.Instance.SecondInstanceDetected += new Server.SingleInstance.SecondInstanceDelegate(x => { tk.ShowUrlInWindow(url); });
                        
                        // TODO: If we change to hosted browser this should be a callback
                        if (openui)
                        {
                            try 
                            {
                                tk.ShowUrlInWindow(Connection.StatusWindowURL);

                                Duplicati.Server.Program.IsFirstRun = false;
                                Duplicati.Server.Program.ServerPortChanged = false;
                            } 
                            catch
                            {
                            }
                        }

                        // If the server shuts down, shut down the tray-icon as well
                        Action shutdownEvent = () =>
                        {
                            tk.InvokeExit();
                        };

                        if (hosted != null)
                            hosted.InstanceShutdown += shutdownEvent;

                        tk.Init(_args);

                        // Make sure that the server shutdown does not access the tray-icon,
                        // as it would be disposed by now
                        if (hosted != null)
                            hosted.InstanceShutdown -= shutdownEvent;
                    }
                }
            }
        }
Beispiel #4
0
        private static void StartTray(string[] _args, Dictionary <string, string> options, string toolkit, HostedInstanceKeeper hosted, string password, bool saltedpassword)
        {
            using (hosted)
            {
                var reSpawn = 0;

                do
                {
                    try
                    {
                        System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                        using (Connection = new HttpServerConnection(serverURL, password, saltedpassword, databaseConnection != null ? PasswordSource.Database : PasswordSource.HostedServer, disableTrayIconLogin, options))
                        {
                            using (var tk = RunTrayIcon(toolkit))
                            {
                                if (hosted != null && Server.Program.ApplicationInstance != null)
                                {
                                    Server.Program.ApplicationInstance.SecondInstanceDetected +=
                                        new Server.SingleInstance.SecondInstanceDelegate(
                                            x => { tk.ShowUrlInWindow(serverURL.ToString()); });
                                }

                                // TODO: If we change to hosted browser this should be a callback
                                if (openui)
                                {
                                    try
                                    {
                                        tk.ShowUrlInWindow(Connection.StatusWindowURL);

                                        Duplicati.Server.Program.IsFirstRun        = false;
                                        Duplicati.Server.Program.ServerPortChanged = false;
                                    }
                                    catch
                                    {
                                    }
                                }

                                // If the server shuts down, shut down the tray-icon as well
                                Action shutdownEvent = () =>
                                {
                                    // Make sure we do not start again after
                                    // a controlled exit
                                    reSpawn = 100;
                                    tk.InvokeExit();
                                };

                                if (hosted != null)
                                {
                                    hosted.InstanceShutdown += shutdownEvent;
                                }

                                tk.Init(_args);

                                // If the tray-icon quits, stop the server
                                reSpawn = 100;

                                // Make sure that the server shutdown does not access the tray-icon,
                                // as it would be disposed by now
                                if (hosted != null)
                                {
                                    hosted.InstanceShutdown -= shutdownEvent;
                                }
                            }
                        }
                    }
                    catch (WebException ex)
                    {
                        System.Diagnostics.Trace.WriteLine("Request error: " + ex);
                        Console.WriteLine("Request error: " + ex);

                        reSpawn++;
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine("Unexpected error: " + ex);
                        Console.WriteLine("Unexpected error: " + ex);
                        return;
                    }
                } while (reSpawn < 3);
            }
        }
Beispiel #5
0
        public static void RealMain(string[] _args)
        {
            Library.UsageReporter.Reporter.Initialize();

            List <string> args = new List <string>(_args);
            Dictionary <string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);

            foreach (string s in args)
            {
                if (
                    s.Equals("help", StringComparison.InvariantCultureIgnoreCase) ||
                    s.Equals("/help", StringComparison.InvariantCultureIgnoreCase) ||
                    s.Equals("usage", StringComparison.InvariantCultureIgnoreCase) ||
                    s.Equals("/usage", StringComparison.InvariantCultureIgnoreCase))
                {
                    options["help"] = "";
                }
            }

            if (options.ContainsKey("help"))
            {
                Console.WriteLine("Supported commandline arguments:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in SupportedCommands)
                {
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);
                }

                Console.WriteLine("Additionally, these server options are also supported:");
                Console.WriteLine();

                foreach (Library.Interface.ICommandLineArgument arg in Duplicati.Server.Program.SupportedCommands)
                {
                    Console.WriteLine("--{0}: {1}", arg.Name, arg.LongDescription);
                }

                return;
            }

            options.TryGetValue(BROWSER_COMMAND_OPTION, out _browser_command);

            string toolkit;

            if (!options.TryGetValue(TOOLKIT_OPTION, out toolkit))
            {
                toolkit = GetDefaultToolKit();
            }
            else
            {
                if (TOOLKIT_WINDOWS_FORMS.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                {
                    toolkit = TOOLKIT_WINDOWS_FORMS;
                }
#if __MonoCS__ || __WindowsGTK__
                else if (TOOLKIT_GTK.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                {
                    toolkit = TOOLKIT_GTK;
                }
                else if (TOOLKIT_GTK_APP_INDICATOR.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                {
                    toolkit = TOOLKIT_GTK_APP_INDICATOR;
                }
#endif
                else if (TOOLKIT_COCOA.Equals(toolkit, StringComparison.InvariantCultureIgnoreCase))
                {
                    toolkit = TOOLKIT_COCOA;
                }
                else
                {
                    toolkit = GetDefaultToolKit();
                }
            }

            HostedInstanceKeeper hosted = null;
            bool   openui         = false;
            string password       = null;
            bool   saltedpassword = false;
            if (!Library.Utility.Utility.ParseBoolOption(options, NOHOSTEDSERVER_OPTION))
            {
                try
                {
                    hosted = new HostedInstanceKeeper(_args);
                }
                catch (Server.SingleInstance.MultipleInstanceException)
                {
                    return;
                }

                // We have a hosted server, if this is the first run,
                // we should open the main page
                openui         = Duplicati.Server.Program.IsFirstRun || Duplicati.Server.Program.ServerPortChanged;
                password       = Duplicati.Server.Program.DataConnection.ApplicationSettings.WebserverPassword;
                saltedpassword = true;
            }

            using (hosted)
            {
                string url;
                if (!options.TryGetValue(HOSTURL_OPTION, out url))
                {
                    if (hosted == null)
                    {
                        url = DEFAULT_HOSTURL;
                    }
                    else
                    {
                        int port = Duplicati.Server.Program.ServerPort;
                        url = "http://127.0.0.1:" + port;
                    }
                }

                string pwd;
                if (options.TryGetValue("webserver-password", out pwd))
                {
                    password       = pwd;
                    saltedpassword = false;
                }

                using (Connection = new HttpServerConnection(new Uri(url), password, saltedpassword))
                {
                    using (var tk = RunTrayIcon(toolkit))
                    {
                        if (hosted != null && Server.Program.Instance != null)
                        {
                            Server.Program.Instance.SecondInstanceDetected += new Server.SingleInstance.SecondInstanceDelegate(x => { tk.ShowUrlInWindow(url); });
                        }

                        // TODO: If we change to hosted browser this should be a callback
                        if (openui)
                        {
                            try
                            {
                                tk.ShowUrlInWindow(Connection.StatusWindowURL);

                                Duplicati.Server.Program.IsFirstRun        = false;
                                Duplicati.Server.Program.ServerPortChanged = false;
                            }
                            catch
                            {
                            }
                        }

                        // If the server shuts down, shut down the tray-icon as well
                        Action shutdownEvent = () =>
                        {
                            tk.InvokeExit();
                        };

                        if (hosted != null)
                        {
                            hosted.InstanceShutdown += shutdownEvent;
                        }

                        tk.Init(_args);

                        // Make sure that the server shutdown does not access the tray-icon,
                        // as it would be disposed by now
                        if (hosted != null)
                        {
                            hosted.InstanceShutdown -= shutdownEvent;
                        }
                    }
                }
            }
        }