public static bool Start() { listener = new TcpListener(IPAddress.Any, 0); listener.Start(); listenerThread = new Thread(new ParameterizedThreadStart(Listen)); listenerThread.IsBackground = true; ShouldListen = true; listenerThread.Start(listener); if (SetAsSystemProxy) { SystemProxyHelper.EnableProxyHTTP("localhost", ListeningPort); FireFoxHelper.AddFirefox(); if (EnableSSL) { RootCertificateName = RootCertificateName == null ? "Titanium_Proxy_Test_Root" : RootCertificateName; bool certTrusted = CertManager.CreateTrustedRootCertificate(); //If certificate was trusted by the machine if (certTrusted) { SystemProxyHelper.EnableProxyHTTPS("localhost", ListeningPort); } } } return(true); }
public static void Stop() { if (!proxyRunning) { throw new Exception("Proxy is not running."); } var setAsSystemProxy = ProxyEndPoints.OfType <ExplicitProxyEndPoint>().Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy); if (setAsSystemProxy) { SystemProxyHelper.DisableAllProxy(); #if !DEBUG FireFoxHelper.RemoveFirefox(); #endif } foreach (var endPoint in ProxyEndPoints) { endPoint.listener.Stop(); } CertManager.Dispose(); Quit(); proxyRunning = false; }
public static bool Start() { listener = new TcpListener(IPAddress.Any, 0); listener.Start(); listenerThread = new Thread(new ParameterizedThreadStart(Listen)); listenerThread.IsBackground = true; ShouldListen = true; listenerThread.Start(listener); if (SetAsSystemProxy) { SystemProxyHelper.EnableProxyHTTP("localhost", ListeningPort); FireFoxHelper.AddFirefox(); if (EnableSSL) { RootCertificateName = RootCertificateName == null ? "DO_NOT_TRUST_FiddlerRoot" : RootCertificateName; bool certTrusted = CertManager.CreateTrustedRootCertificate(); if (!certTrusted) { // The user didn't want to install the self-signed certificate to the root store. } SystemProxyHelper.EnableProxyHTTPS("localhost", ListeningPort); } } return(true); }
public static void EnableProxy() { #if !DEBUG //if(System.Environment.OSVersion.Version <= //if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) //{ // log.Info("Enabel Proxy Win7!"); // try { ProxyRoutines.SetProxy("http=127.0.0.1:8090"); } // catch (Exception exp) { log.Error(exp.ToString()); } //} //else { log.Info("Enabel Proxy!"); try { if (!GetProxy()) { if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) { TrollProxyHelper.SetHttpProxy("127.0.0.1", 8090); } else { SystemProxyHelper.SetHttpProxy("127.0.0.1", 8090); } FireFoxHelper.AddFirefox(); } } catch (Exception e) { log.Error(e.ToString()); } } #endif }
public static void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint) { VerifyProxy(endPoint); if (!endPoint.EnableSsl) { throw new Exception("Endpoint do not support Https connections"); } //clear any settings previously added ProxyEndPoints.OfType <ExplicitProxyEndPoint>().ToList().ForEach(x => x.IsSystemHttpsProxy = false); //If certificate was trusted by the machine if (certTrusted) { SystemProxyHelper.SetHttpsProxy( Equals(endPoint.IpAddress, IPAddress.Any) | Equals(endPoint.IpAddress, IPAddress.Loopback) ? "127.0.0.1" : endPoint.IpAddress.ToString(), endPoint.Port); } endPoint.IsSystemHttpsProxy = true; #if !DEBUG FireFoxHelper.AddFirefox(); #endif Console.WriteLine("Set endpoint at Ip {1} and port: {2} as System HTTPS Proxy", endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port); }
private void FormMain_FormClosed(object sender, FormClosedEventArgs e) { #if !DEBUG // if (Properties.Settings.Default.isProtected) //ProxyRoutines.SetProxy(false); SystemProxyHelper.DisableAllProxy(); FireFoxHelper.RemoveFirefox(); #endif log.Info("FormMain_FormClosed Unset Proxy!"); }
public static void Stop() { if (SetAsSystemProxy) { SystemProxyHelper.DisableAllProxy(); FireFoxHelper.RemoveFirefox(); } _listener.Stop(); CertManager.Dispose(); }
public static void Stop() { if (SetAsSystemProxy) { SystemProxyHelper.DisableAllProxy(); FireFoxHelper.RemoveFirefox(); } ShouldListen = false; listener.Stop(); listenerThread.Interrupt(); }
private void TurnOnProxy() { #if !DEBUG //ProxyRoutines.SetProxy("http=127.0.0.1:8090", null); SystemProxyHelper.EnableProxyHTTP("127.0.0.1", 8090); FireFoxHelper.AddFirefox(); #endif //notify_icon_main.Icon = Properties.Resources.on; tool_strip_menu_item_toggle_onff.Checked = true; //toggleOnOffButton.Image = Properties.Resources.powerblue_small; Properties.Settings.Default.isProtected = true; Properties.Settings.Default.Save(); //同时设置 TurnOnAutoStart(); }
public static void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint) { VerifyProxy(endPoint); //clear any settings previously added ProxyEndPoints.OfType <ExplicitProxyEndPoint>().ToList().ForEach(x => x.IsSystemHttpProxy = false); SystemProxyHelper.SetHttpProxy( Equals(endPoint.IpAddress, IPAddress.Any) | Equals(endPoint.IpAddress, IPAddress.Loopback) ? "127.0.0.1" : endPoint.IpAddress.ToString(), endPoint.Port); endPoint.IsSystemHttpProxy = true; #if !DEBUG FireFoxHelper.AddFirefox(); #endif Console.WriteLine("Set endpoint at Ip {1} and port: {2} as System HTTPS Proxy", endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port); }
private void TurnOffProxy() { if (WechatForm.Auth()) { #if !DEBUG //ProxyRoutines.SetProxy(false); SystemProxyHelper.DisableAllProxy(); FireFoxHelper.RemoveFirefox(); #endif //notify_icon_main.Icon = Properties.Resources.off; tool_strip_menu_item_toggle_onff.Checked = false; //toggleOnOffButton.Image = Properties.Resources.powerblack_small; Properties.Settings.Default.isProtected = false; Properties.Settings.Default.Save(); //同时设置 TurnOffAutoStart(); } }
public static bool Start() { _listener = new TcpListener(ListeningIpAddress, ListeningPort); _listener.Start(); ListeningPort = ((IPEndPoint)_listener.LocalEndpoint).Port; // accept clients asynchronously _listener.BeginAcceptTcpClient(OnAcceptConnection, _listener); var certTrusted = false; if (EnableSsl) { certTrusted = CertManager.CreateTrustedRootCertificate(); } if (SetAsSystemProxy) { SystemProxyHelper.EnableProxyHttp( Equals(ListeningIpAddress, IPAddress.Any) ? "127.0.0.1" : ListeningIpAddress.ToString(), ListeningPort); #if !DEBUG FireFoxHelper.AddFirefox(); #endif if (EnableSsl) { RootCertificateName = RootCertificateName ?? "Titanium_Proxy_Test_Root"; //If certificate was trusted by the machine if (certTrusted) { SystemProxyHelper.EnableProxyHttps( Equals(ListeningIpAddress, IPAddress.Any) ? "127.0.0.1" : ListeningIpAddress.ToString(), ListeningPort); } } } return(true); }
public static void DisableAllSystemProxies() { SystemProxyHelper.DisableAllProxy(); }
public static void DisableSystemHttpsProxy() { SystemProxyHelper.RemoveHttpsProxy(); }
public static void DisableProxy() { //unset proxy again to make sure #if !DEBUG //if (System.Environment.OSVersion.Version.Major<=6 && System.Environment.OSVersion.Version.Minor<=1) //{ // log.Info("Disable Proxy Win7!"); // try // { // ProxyRoutines.SetProxy(false); // } // catch (Exception exp) // { log.Error(exp.ToString()); } //} //else { try { if (GetProxy()) { log.Info("Disable Proxy!"); //在关机时,不能refresh,否则会导致无法修改成功,其他时候则要刷新,否则会导致无法刷新 if (kCloseReason == CloseReason.WindowsShutDown) { if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) { log.Info("Win7 Disable proxy on Exit!"); TrollProxyHelper.RemoveHttpProxyWithRefresh(); } else { log.Info("Disable proxy without Refresh!"); SystemProxyHelper.DisableAllProxyWithourRestoreAndRefresh(); } //int tryTimes = 10; //while (tryTimes-- > 0) //{ //SystemProxyHelper.DisableAllProxyWithourRestore(); //reg.SetValue("ProxyEnable", 0); //reg.Flush(); ////read again //if ((int)reg.GetValue("ProxyEnable") != 0) // Thread.Sleep(50); ////else // //break; RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); log.Info("ProxyEnable Value: " + reg.GetValue("ProxyEnable")); //} } else { if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) { log.Info("Win7 Disable proxy!"); TrollProxyHelper.RemoveHttpProxy(); } else { log.Info("Disable proxy with Refresh!"); SystemProxyHelper.DisableAllProxyWithourRestore(); } } FireFoxHelper.RemoveFirefox(); } } catch (Exception exp) { log.Error(exp.ToString()); } } #endif }