public static void Load() { Model.Setting setting; if (!File.Exists(configPath)) { setting = new Model.Setting(); } else { setting = JSON.Read <Model.Setting>(configPath); } LogLevel = setting.LogLevel; AutoStart = setting.AutoStart; Mode = setting.Mode; SocksPort = setting.SockPort; PacPort = setting.PacPort; HttpPort = setting.HttpPort; AcceptLAN = setting.AcceptLAN; Servers = setting.Servers as List <VMess>; ActiveServerIndex = setting.Active; EnableUDP = setting.EnableUDP; GFWListURL = setting.GFWListURL; UpdateViaProxy = setting.UpdateViaProxy; EnableAccessLog = setting.EnableAccessLog; EnableErrorLog = setting.EnableErrorLog; if (ActiveServerIndex >= Servers.Count || ActiveServerIndex < 0) { ActiveServerIndex = 0; } }
void ModeChanged(object sender, RoutedEventArgs e) { Debug.WriteLine($"mode changed by {sender} {e}"); MenuItem senderItem = sender as MenuItem; int senderTag = Int32.Parse(senderItem.Tag as string); if (proxyState == true && proxyMode == ProxyMode.manual && senderTag != (int)ProxyMode.manual) { this.BackupSystemProxy(); } if (proxyState == true && proxyMode != ProxyMode.manual && senderTag == (int)ProxyMode.manual) { if (enableRestore) { RestoreSystemProxy(); } else { CancelSystemProxy(); } } proxyMode = (ProxyMode)senderTag; this.UpdateStatusAndModeMenus(); if (senderTag == (int)ProxyMode.pac) { this.UpdatePacMenuList(); } if (proxyState == true) { this.UpdateSystemProxy(); } }
/// <summary> /// Creates a new proxy loaded with the specified form. /// </summary> /// <param name="form"></param> /// <param name="mode"></param> /// <returns></returns> public FormProxy CreateFormProxy(Form form, ProxyMode mode) { var proxy = CreateFormProxy(form.FormKind, mode); proxy.WithForm(form); return(proxy); }
public FieldProxy <T> CreateFieldProxy <T>(T field, ProxyMode mode) where T : Field { var proxy = CreateFieldProxy <T>(mode); proxy.Field = field; return(proxy); }
public Configuration() { index = 0; localPort = 1080; reconnectTimes = 2; keepVisitTime = 180; connectTimeout = 5; dnsServer = string.Empty; localDnsServer = string.Empty; balanceAlgorithm = LoadBalance.LowException.ToString(); random = false; sysProxyMode = ProxyMode.NoModify; proxyRuleMode = ProxyRuleMode.Disable; checkSwitchAutoCloseAll = true; logEnable = true; AutoCheckUpdate = true; isPreRelease = true; LangName = string.Empty; serverSubscribes = new List <ServerSubscribe>(); configs = new List <Server>(); }
public void SwitchProxyMode(ProxyMode mode) { switch (mode) { case ProxyMode.Global: keepSystemProxyModeItem.Checked = false; directModeItem.Checked = false; globalModeItem.Checked = true; pacModeItem.Checked = false; break; case ProxyMode.PAC: keepSystemProxyModeItem.Checked = false; directModeItem.Checked = false; globalModeItem.Checked = false; pacModeItem.Checked = true; break; case ProxyMode.Disable: keepSystemProxyModeItem.Checked = false; directModeItem.Checked = true; globalModeItem.Checked = false; pacModeItem.Checked = false; break; case ProxyMode.KeepSystemProxy: default: keepSystemProxyModeItem.Checked = true; directModeItem.Checked = false; globalModeItem.Checked = false; pacModeItem.Checked = false; break; } UpdateText(); }
/// <summary> /// 切换系统代理模式 /// </summary> public void ToggleMode(ProxyMode mode) { Global.GuiConfig.SysProxyMode = mode; ReloadPacServer(); UpdateSystemProxy(); SaveAndNotifyChanged(); }
public void CopyFrom(Configuration config) { configs = config.configs; index = config.index; random = config.random; sysProxyMode = config.sysProxyMode; shareOverLan = config.shareOverLan; localPort = config.localPort; reconnectTimes = config.reconnectTimes; balanceAlgorithm = config.balanceAlgorithm; randomInGroup = config.randomInGroup; TTL = config.TTL; connectTimeout = config.connectTimeout; dnsServer = config.dnsServer; localDnsServer = config.localDnsServer; proxyEnable = config.proxyEnable; pacDirectGoProxy = config.pacDirectGoProxy; proxyType = config.proxyType; proxyHost = config.proxyHost; proxyPort = config.proxyPort; proxyAuthUser = config.proxyAuthUser; proxyAuthPass = config.proxyAuthPass; proxyUserAgent = config.proxyUserAgent; authUser = config.authUser; authPass = config.authPass; autoBan = config.autoBan; checkSwitchAutoCloseAll = config.checkSwitchAutoCloseAll; logEnable = config.logEnable; sameHostForSameTarget = config.sameHostForSameTarget; keepVisitTime = config.keepVisitTime; AutoCheckUpdate = config.AutoCheckUpdate; isPreRelease = config.isPreRelease; serverSubscribes = config.serverSubscribes; }
public override void LoadFromJson(JsonObject o) { base.LoadFromJson(o); if (o[SettingsKey.REGKEY_PROXYENABLED] != null) { ProxyMode = (ProxyMode)Toolbox.ToInt(o[SettingsKey.REGKEY_PROXYENABLED]); } }
private object CreateProxy(ProxyInfo info, ProxyMode mode) { var proxy = (Proxy)Activator.CreateInstance(info.ImplementationType); proxy.Provider = this; proxy.Mode = mode; return(proxy); }
public FormCollectionProxy <T> CreateFormCollectionProxy <T>(ProxyMode mode, IEnumerable <uint> items) where T : IForm { return(new FormCollectionProxy <T>() { Provider = this, Mode = mode, Items = items }); }
public void ToggleGlobalStatus(ProxyMode mode) { this._config.ProxyMode = mode; if (GlobalStatusChanged != null) { GlobalStatusChanged(this, new EventArgs()); } }
//public void ToggleEnable(bool enabled) //{ // _config.enabled = enabled; // SaveConfig(_config); // if (EnableStatusChanged != null) // { // EnableStatusChanged(this, new EventArgs()); // } //} public void ToggleMode(ProxyMode mode) { _config.sysProxyMode = (int)mode; SaveConfig(_config); if (ToggleModeChanged != null) { ToggleModeChanged(this, new EventArgs()); } }
public T CreateProxy <T>(ProxyMode mode) where T : Proxy { string typeFullName = typeof(T).FullName; if (!proxies.ContainsKey(typeFullName)) { throw new NotImplementedException("Proxy implementation not found: " + typeFullName); } return((T)CreateProxy(proxies[typeFullName], mode)); }
/// <summary> /// Creates a new proxy loaded with the specified form. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="form"></param> /// <param name="mode"></param> /// <returns></returns> public T CreateFormProxy <T>(Form form, ProxyMode mode) where T : IForm { var proxy = CreateFormProxy <T>(form.FormKind, mode); // Force cast to FormProxy via a common IForm interface to set Form property // This will work because any class that implements IForm does it through the FormProxy class ((FormProxy)(IForm)proxy).WithForm(form); return(proxy); }
private T CreateProxy <T>(ProxyInfo info, ProxyMode mode) { // Ensure T is compatible info.ImplementationType // Otherwise cast to T will fail anyway if (!typeof(T).IsAssignableFrom(info.ImplementationType)) { throw new InvalidProgramException("Created proxy " + info.ImplementationType.FullName + " is not compatible with requested type " + typeof(T).FullName); } return((T)CreateProxy(info, mode)); }
/// <summary> /// Invoke this event when toggle system proxy mode /// </summary> protected override void View_SaveData(object sender, EventArgs e) { MenuItem menuItem = (MenuItem)sender; ProxyMode index = (ProxyMode)menuItem.Index; if (Setting.Instance.Mode == index) { return; } Setting.Instance.Mode = index; Setting.Instance.Save(); }
/// <summary> /// Creates a new proxy loaded with form that has the specified Form ID. /// If provided Form ID is zero, returned proxy will be a null form proxy. /// If provided Form ID is not resolved, returned proxy will be an unresolved form proxy. /// </summary> /// <param name="formId"></param> /// <param name="mode">Proxy mode of created proxy</param> /// <returns></returns> public FormProxy CreateFormProxy(uint formId, ProxyMode mode) { if (formId == 0 || !engine.Context.Forms.Contains(formId)) { // Create dummy proxy, setting formID return(CreateFormProxy(FormKind.Any, mode).WithForm(formId)); } else { return(CreateFormProxy(engine.Context.Forms[formId], mode)); } }
/// <summary> /// Adds a proxy to the stub with predicate generators containing booleans /// </summary> /// <param name="to">endpoint address to proxy to</param> /// <param name="proxyMode">proxyalways, proxyonce or proxytransparent</param> /// <param name="predicateGenerators">list of predicates that a proxy repsonse will be recorded for</param> /// <returns></returns> public HttpStub ReturnsProxy(Uri to, ProxyMode proxyMode, IList <MatchesPredicate <HttpBooleanPredicateFields> > predicateGenerators) { var fields = new ProxyResponseFields <HttpBooleanPredicateFields> { To = to, Mode = proxyMode, PredicateGenerators = predicateGenerators }; var response = new ProxyResponse <ProxyResponseFields <HttpBooleanPredicateFields> >(fields); return(Returns(response)); }
public FieldProxy <T> CreateFieldProxy <T>(ProxyMode mode) where T : Field { string typeFullName = typeof(T).FullName; if (!backingFieldMap.ContainsKey(typeFullName)) { throw new InvalidProgramException("Could not find proxy implmentation for field " + typeFullName + "."); } var info = proxies[backingFieldMap[typeFullName]]; return(CreateProxy <FieldProxy <T> >(info, mode)); }
private async Task <HttpResponseMessage> ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ProcessUrl(request); ProcessHostHeader(request); request.Headers.ConnectionClose = true; // TODO: Connection re-use is not supported. ProxyMode proxyMode = DetermineProxyModeAndAddressLine(request); Socket socket; Stream transport; try { if (_socketOpener != null) { socket = await _socketOpener(request.GetConnectionHostProperty(), request.GetConnectionPortProperty().Value, cancellationToken).ConfigureAwait(false); transport = new NetworkStream(socket); } else { socket = null; transport = await _streamOpener(request.GetConnectionHostProperty(), request.GetConnectionPortProperty().Value, cancellationToken).ConfigureAwait(false); } } catch (SocketException sox) { throw new HttpRequestException("Connection failed", sox); } if (proxyMode == ProxyMode.Tunnel) { await TunnelThroughProxyAsync(request, transport, cancellationToken); } System.Diagnostics.Debug.Assert(!(proxyMode == ProxyMode.Http && request.IsHttps())); if (request.IsHttps()) { SslStream sslStream = new SslStream(transport, false, ServerCertificateValidationCallback); await sslStream.AuthenticateAsClientAsync(request.GetHostProperty(), ClientCertificates, SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, false); transport = sslStream; } var bufferedReadStream = new BufferedReadStream(transport, socket); var connection = new HttpConnection(bufferedReadStream); return(await connection.SendAsync(request, cancellationToken)); }
public T CreateFormProxy <T>(uint formId, ProxyMode mode) where T : IForm { if (formId == 0 || !engine.Context.Forms.Contains(formId)) { // Create dummy proxy, setting formID var proxy = CreateFormProxy <T>(FormKind.Any, mode); ((FormProxy)(IForm)proxy).WithForm(formId); return(proxy); } else { return(CreateFormProxy <T>(engine.Context.Forms[formId], mode)); } }
public bool SetProxy(ProxyMode proxyMode, string proxyHost, int proxyPort, bool proxyAuthentication, string proxyUser, string proxyPassword, bool ntlmAuthentication, string ntlmDomain) { this.proxyMode = proxyMode; this.proxyHost = proxyHost; this.proxyPort = proxyPort; this.proxyAuthentication = proxyAuthentication; this.proxyUser = proxyUser; this.ProxyDecryptedPassword = proxyPassword; this.proxyNtlmAuthentication = ntlmAuthentication; this.proxyNtlmDomain = ntlmDomain; return(Apply()); }
protected static UnitTestMode Translate(ProxyMode mode) { switch (mode) { case ProxyMode.DataCapture: return(UnitTestMode.Capture); case ProxyMode.DataReplay: return(UnitTestMode.Replay); case ProxyMode.DataPassthrough: return(UnitTestMode.NoProxy); } throw new InvalidOperationException($"'{mode}' is an undefined value of` {nameof(ProxyMode)}`"); }
public void SetDownloadProxy(ProxyMode _mode, ProxyModel _proxy) { switch (_mode) { case ProxyMode.NotUseProxy: DownloadProxy = null; break; case ProxyMode.SystemProxy: DownloadProxy = WebRequest.GetSystemWebProxy(); break; case ProxyMode.CustomProxy: DownloadProxy = new WebProxy(_proxy.ProxyIP, _proxy.ProxyPort); DownloadProxy.Credentials = new NetworkCredential(_proxy.ProxyUser, _proxy.ProxyPwd); break; } }
public bool Apply() { if (proxyMode == ProxyMode.System) { networkSetting.Proxy = WebRequest.DefaultWebProxy; networkSetting.Proxy.Credentials = CredentialCache.DefaultCredentials; } else if (proxyMode == ProxyMode.None) { networkSetting.Proxy = null; } else { try { WebProxy proxyObject = new WebProxy("http://" + proxyHost + ":" + proxyPort.ToString(CultureInfo.InvariantCulture) + "/", true); proxyObject.Credentials = CredentialCache.DefaultCredentials; if (proxyAuthentication) { if (!proxyNtlmAuthentication) { proxyObject.Credentials = new NetworkCredential(proxyUser, ProxyDecryptedPassword); } else { proxyObject.Credentials = new NetworkCredential(proxyUser, ProxyDecryptedPassword, proxyNtlmDomain); } } networkSetting.Proxy = proxyObject; } catch (System.UriFormatException) { proxyMode = ProxyMode.System; string errmessage = LangPack.TranslateString("Format of HTTP-Proxy ({0}) is wrong. Proxy settings will be reset to default."); errmessage = string.Format(errmessage, proxyHost); MessageBox.Show(errmessage, Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } return(true); }
public ProxyOptions(ProxyMode mode, string solutionDirectory, string projectDirectory) { if (mode != ProxyMode.DataCapture && mode != ProxyMode.DataPassthrough && mode != ProxyMode.DataReplay) { throw new ArgumentOutOfRangeException(nameof(mode)); } if (string.IsNullOrEmpty(solutionDirectory)) { throw new ArgumentNullException(nameof(solutionDirectory)); } if (string.IsNullOrEmpty(projectDirectory)) { throw new ArgumentNullException(nameof(projectDirectory)); } if (mode != ProxyMode.DataReplay && !Directory.Exists(solutionDirectory)) { var inner = new DirectoryNotFoundException(solutionDirectory); throw new ArgumentException(inner.Message, nameof(solutionDirectory), inner); } if (mode != ProxyMode.DataReplay && !Directory.Exists(projectDirectory)) { while (projectDirectory.Length > 0 && (projectDirectory[0] == '\\' || projectDirectory[0] == '/')) { projectDirectory = projectDirectory.Remove(0, 1); } projectDirectory = Path.Combine(solutionDirectory, projectDirectory); if (!Directory.Exists(projectDirectory)) { var inner = new DirectoryNotFoundException(projectDirectory); throw new ArgumentException(inner.Message, nameof(projectDirectory), inner); } } Mode = mode; ProjectDirectory = projectDirectory; SolutionDirectory = solutionDirectory; }
private void selectButton_Click(object sender, RoutedEventArgs e) { ProxyMode mode = ProxyMode.Default; if ((bool)proxiesDefaultRadio.IsChecked) { mode = ProxyMode.Default; } else if ((bool)proxiesOnRadio.IsChecked) { mode = ProxyMode.On; } else if ((bool)proxiesOffRadio.IsChecked) { mode = ProxyMode.Off; } if (Caller.GetType() == typeof(Runner)) { (Caller as Runner).vm.ProxyMode = mode; } ((MainDialog)Parent).Close(); }
public Configuration() { index = 0; localPort = 1080; reconnectTimes = 2; keepVisitTime = 180; connectTimeout = 5; dnsServer = string.Empty; localDnsServer = string.Empty; balanceAlgorithm = @"LowException"; random = false; sysProxyMode = ProxyMode.NoModify; proxyRuleMode = ProxyRuleMode.Disable; AutoCheckUpdate = true; isPreRelease = false; nodeFeedAutoUpdate = true; serverSubscribes = new List <ServerSubscribe>(); configs = new ObservableCollection <Server>(); }
private async Task <HttpResponseMessage> ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ProcessUrl(request); ProcessHostHeader(request); request.Headers.ConnectionClose = true; // TODO: Connection re-use is not supported. if (request.Method != HttpMethod.Get) { throw new NotImplementedException(request.Method.Method); // TODO: POST } ProxyMode proxyMode = DetermineProxyModeAndAddressLine(request); ApmStream transport = await ConnectAsync(request, cancellationToken); if (proxyMode == ProxyMode.Tunnel) { await TunnelThroughProxyAsync(request, transport, cancellationToken); } System.Diagnostics.Debug.Assert(!(proxyMode == ProxyMode.Http && request.IsHttps())); if (request.IsHttps()) { SslStream sslStream = new SslStream(transport); await sslStream.AuthenticateAsClientAsync(request.GetHostProperty()); transport = new ApmStreamWrapper(sslStream); } var bufferedReadStream = new BufferedReadStream(transport); var connection = new HttpConnection(bufferedReadStream); return(await connection.SendAsync(request, cancellationToken)); }
public override void LoadFromJson(JsonObject o) { base.LoadFromJson(o); if (o[SettingsKey.REGKEY_PROXYENABLED] != null) { ProxyMode = (ProxyMode)Toolbox.ToInt(o[SettingsKey.REGKEY_PROXYENABLED]); } }
public bool SetProxy(ProxyMode proxyMode, string proxyHost, int proxyPort, bool proxyAuthentication, string proxyUser, string proxyPassword, bool ntlmAuthentication, string ntlmDomain) { this.proxyMode = proxyMode; this.proxyHost = proxyHost; this.proxyPort = proxyPort; this.proxyAuthentication = proxyAuthentication; this.proxyUser = proxyUser; this.ProxyDecryptedPassword = proxyPassword; this.proxyNtlmAuthentication = ntlmAuthentication; this.proxyNtlmDomain = ntlmDomain; return Apply(); }
public bool Apply() { if(proxyMode == ProxyMode.System) { networkSetting.Proxy = WebRequest.DefaultWebProxy; networkSetting.Proxy.Credentials = CredentialCache.DefaultCredentials; } else if(proxyMode == ProxyMode.None) { networkSetting.Proxy = null; } else { try { WebProxy proxyObject = new WebProxy("http://" + proxyHost + ":" + proxyPort.ToString(CultureInfo.InvariantCulture) + "/", true); proxyObject.Credentials = CredentialCache.DefaultCredentials; if(proxyAuthentication) { if(!proxyNtlmAuthentication) proxyObject.Credentials = new NetworkCredential(proxyUser, ProxyDecryptedPassword); else proxyObject.Credentials = new NetworkCredential(proxyUser, ProxyDecryptedPassword, proxyNtlmDomain); } networkSetting.Proxy = proxyObject; } catch (System.UriFormatException) { proxyMode = ProxyMode.System; string errmessage = LangPack.TranslateString("Format of HTTP-Proxy ({0}) is wrong. Proxy settings will be reset to default."); errmessage = string.Format(errmessage, proxyHost); MessageBox.Show(errmessage, Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } } return true; }