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); }
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); } }