public static ServiceSettings GetSettings()
        {
            Settings settings = new Settings();
            ServiceSettings serviceSettings = new ServiceSettings();

            serviceSettings.DynamicSocksHost = settings.DynamicSocksHost;
            serviceSettings.DynamicSocksPort = settings.DynamicSocksPort;
            serviceSettings.EnableCompression = settings.EnableCompression;
            serviceSettings.EnableDynamicSocks = settings.EnableDynamicSocks;
            serviceSettings.EnableTunnelValidation = settings.EnableTunnelValidation;
            serviceSettings.EnableVerbose = settings.EnableVerbose;
            serviceSettings.PlinkExecutable = settings.PlinkExecutable;
            serviceSettings.SshHostname = settings.SshHostname;
            serviceSettings.SshPassword = CryptoHelper.ToInsecureString(CryptoHelper.DecryptString(settings.SshPassword));
            serviceSettings.SshPort = settings.SshPort;
            serviceSettings.SshUsername = settings.SshUsername;
            serviceSettings.TunnelValidationLocalPort = settings.TunnelValidationLocalPort;
            serviceSettings.TunnelValidationPingInterval = settings.TunnelValidationPingInterval;
            serviceSettings.TunnelValidationPingTimeout = settings.TunnelValidationPingTimeout;
            serviceSettings.TunnelValidationRemotePort = settings.TunnelValidationRemotePort;
            serviceSettings.EnableIcmpValidation = settings.EnableIcmpValidation;
            serviceSettings.IcmpValidationHostnames = settings.IcmpValidationHostnames;
            serviceSettings.IcmpValidationPingSshServer = settings.IcmpValidationPingSshServer;
            serviceSettings.UiMinimizedToSysTray = settings.UiMinimizedToSysTray;
            serviceSettings.UiShowSysTrayNotifications = settings.UiShowSysTrayNotifications;
            serviceSettings.UiStartMinimized = settings.UiStartMinimized;
            serviceSettings.UiStartWithWindows = settings.UiStartWithWindows;
            serviceSettings.LocalTunnels = settings.LocalTunnels;
            serviceSettings.RemoteTunnels = settings.RemoteTunnels;

            return serviceSettings;
        }
        public static void ChangeTunnelStatus(TunnelStatuses tunnelStatus, bool saveTunnelStatus = true)
        {
            TunnelHelper.CurrentTunnelStatus = tunnelStatus;
            ServiceSettings serviceSettings = SettingsHelper.GetSettings();

            if (saveTunnelStatus)
            {
                Settings settings = new Settings();
                settings.CurrentTunnelStatus = (int)tunnelStatus;
                settings.Save();
            }

            if (tunnelStatus == TunnelStatuses.Started)
            {
                WcfServerHelper.BroadcastRemoteCallback(x => x.EventToLog("Plink Starting", DateTime.Now), true);
                if (ProcessHelper.StartPlink())
                {
                    TunnelPingHelper.OpenTunnelPingListener();
                    WcfServerHelper.BroadcastRemoteCallback(x => x.EventToLog("Plink Started: " + ProcessHelper.GetPlinkArguments(serviceSettings), DateTime.Now), true);
                }
                else
                {
                    ChangeTunnelStatus(TunnelStatuses.Paused);
                }
            }
            else
            {
                WcfServerHelper.BroadcastRemoteCallback(x => x.EventToLog("Plink Stopping", DateTime.Now), true);
                TunnelPingHelper.CloseTunnelPingListener();
                ProcessHelper.StopPlink();
            }

            WcfServerHelper.BroadcastRemoteCallback(x => x.TunnelStatusChanged(tunnelStatus), true);
        }
Пример #3
0
        protected override void OnStart(string[] args)
        {
            if (Settings.Default.UpgradeRequired)
            {
                Settings.Default.Upgrade();
                Settings.Default.UpgradeRequired = false;
                Settings.Default.Save();
            }

            WcfServerHelper.Start(typeof(ServiceRemoting));

            _pingClientTimer = new System.Timers.Timer(Constants.ServerPingInterval * 1000);
            _pingClientTimer.AutoReset = true;
            _pingClientTimer.Elapsed += pingTimer_Elapsed;
            _pingClientTimer.Start();

            Settings settings = new Settings();
            if (settings.CurrentTunnelStatus == (int)TunnelStatuses.Started)
            {
                TunnelHelper.ChangeTunnelStatus(TunnelStatuses.Started, false);
            }
        }
        public static void SaveSettings(ServiceSettings serviceSettings)
        {
            try
            {
                Settings settings = new Settings();

                settings.DynamicSocksHost = serviceSettings.DynamicSocksHost;
                settings.DynamicSocksPort = serviceSettings.DynamicSocksPort;
                settings.EnableCompression = serviceSettings.EnableCompression;
                settings.EnableDynamicSocks = serviceSettings.EnableDynamicSocks;
                settings.EnableTunnelValidation = serviceSettings.EnableTunnelValidation;
                settings.EnableVerbose = serviceSettings.EnableVerbose;
                settings.PlinkExecutable = serviceSettings.PlinkExecutable;
                settings.SshHostname = serviceSettings.SshHostname;
                settings.SshPassword = CryptoHelper.EncryptString(CryptoHelper.ToSecureString(serviceSettings.SshPassword));
                settings.SshPort = serviceSettings.SshPort;
                settings.SshUsername = serviceSettings.SshUsername;
                settings.TunnelValidationLocalPort = serviceSettings.TunnelValidationLocalPort;
                settings.TunnelValidationPingInterval = serviceSettings.TunnelValidationPingInterval;
                settings.TunnelValidationPingTimeout = serviceSettings.TunnelValidationPingTimeout;
                settings.TunnelValidationRemotePort = serviceSettings.TunnelValidationRemotePort;
                settings.EnableIcmpValidation = serviceSettings.EnableIcmpValidation;
                settings.IcmpValidationHostnames = serviceSettings.IcmpValidationHostnames;
                settings.IcmpValidationPingSshServer = serviceSettings.IcmpValidationPingSshServer;
                settings.UiMinimizedToSysTray = serviceSettings.UiMinimizedToSysTray;
                settings.UiShowSysTrayNotifications = serviceSettings.UiShowSysTrayNotifications;
                settings.UiStartMinimized = serviceSettings.UiStartMinimized;
                settings.UiStartWithWindows = serviceSettings.UiStartWithWindows;
                settings.LocalTunnels = serviceSettings.LocalTunnels;
                settings.RemoteTunnels = serviceSettings.RemoteTunnels;

                settings.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }