示例#1
0
        public static void Update(Configuration config, bool forceDisable)
        {
            int sysProxyMode = config.sysProxyMode;

            if (sysProxyMode == (int)ProxyMode.NoModify)
            {
                return;
            }
            if (forceDisable)
            {
                sysProxyMode = (int)ProxyMode.Direct;
            }
            bool global  = sysProxyMode == (int)ProxyMode.Global;
            bool enabled = sysProxyMode != (int)ProxyMode.Direct;

            using (RegistryKey registry = OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true))
            {
                try
                {
                    if (enabled)
                    {
                        if (global)
                        {
                            RegistrySetValue(registry, "ProxyEnable", 1);
                            RegistrySetValue(registry, "ProxyServer", "127.0.0.1:" + config.localPort.ToString());
                            RegistrySetValue(registry, "AutoConfigURL", "");
                        }
                        else
                        {
                            string pacUrl;
                            pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?" + "auth=" + config.localAuthPassword + "&t=" + Util.Utils.GetTimestamp(DateTime.Now);
                            RegistrySetValue(registry, "ProxyEnable", 0);
                            RegistrySetValue(registry, "ProxyServer", "");
                            RegistrySetValue(registry, "AutoConfigURL", pacUrl);
                        }
                    }
                    else
                    {
                        RegistrySetValue(registry, "ProxyEnable", 0);
                        RegistrySetValue(registry, "ProxyServer", "");
                        RegistrySetValue(registry, "AutoConfigURL", "");
                    }
                    IEProxyUpdate(config, sysProxyMode);
                    SystemProxy.NotifyIE();
                    //Must Notify IE first, or the connections do not chanage
                    CopyProxySettingFromLan();
                }
                catch (Exception e)
                {
                    Logging.LogUsefulException(e);
                    // TODO this should be moved into views
                    MessageBox.Show(I18N.GetString("Failed to update registry"));
                }
            }
        }
        public static void Update(Configuration config, bool forceDisable)
        {
            bool global  = config.global;
            bool enabled = config.enabled;

            if (forceDisable)
            {
                enabled = false;
            }
            try
            {
                RegistryKey registry =
                    Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                                                    true);
                if (enabled)
                {
                    if (global)
                    {
                        registry.SetValue("ProxyEnable", 1);
                        registry.SetValue("ProxyServer", "127.0.0.1:" + config.localPort.ToString());
                        registry.SetValue("AutoConfigURL", "");
                    }
                    else
                    {
                        string pacUrl;
                        if (config.useOnlinePac && !string.IsNullOrEmpty(config.pacUrl))
                        {
                            pacUrl = config.pacUrl;
                        }
                        else
                        {
                            pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now);
                        }
                        registry.SetValue("ProxyEnable", 0);
                        registry.SetValue("ProxyServer", "");
                        registry.SetValue("AutoConfigURL", pacUrl);
                    }
                }
                else
                {
                    registry.SetValue("ProxyEnable", 0);
                    registry.SetValue("ProxyServer", "");
                    registry.SetValue("AutoConfigURL", "");
                }
                SystemProxy.NotifyIE();
                //Must Notify IE first, or the connections do not chanage
                CopyProxySettingFromLan();
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                // TODO this should be moved into views
                MessageBox.Show(I18N.GetString("Failed to update registry"));
            }
        }
 private void UpdateSystemProxy()
 {
     if (_config.enabled)
     {
         SystemProxy.Enable();
     }
     else
     {
         SystemProxy.Disable();
     }
 }
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     local.Stop();
     polipoRunner.Stop();
     if (_config.enabled)
     {
         SystemProxy.Disable();
     }
 }
        public void Stop()
        {
            if (_stopped)
            {
                return;
            }
            _stopped = true;

            StopPortMap();

            _listener?.Stop();
            _privoxyRunner?.Stop();
            SystemProxy.Restore();
            ServerTransferTotal.Save(_transfer, Global.GuiConfig.Configs);
        }
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     _listener?.Stop();
     StopPlugins();
     privoxyRunner?.Stop();
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true);
     }
     Encryption.RNG.Close();
 }
        public void Stop()
        {
            _config = Configuration.Load();
            if (_listener != null)
            {
                _listener.Stop();
            }
            StopPlugins();
            if (privoxyRunner != null)
            {
                privoxyRunner.Stop();
            }

            SystemProxy.Update(_config, true, null);
            Encryption.RNG.Close();
        }
示例#8
0
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     if (_listener != null)
     {
         _listener.Stop();
     }
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true, null);
     }
     Encryption.RNG.Close();
 }
 private void UpdateSystemProxy()
 {
     if (_config.enabled)
     {
         SystemProxy.Update(_config, false);
         _systemProxyIsDirty = true;
     }
     else
     {
         // only switch it off if we have switched it on
         if (_systemProxyIsDirty)
         {
             SystemProxy.Update(_config, false);
             _systemProxyIsDirty = false;
         }
     }
 }
        private static void CopyProxySettingFromLan()
        {
            RegistryKey registry = null;

            try
            {
                registry = OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", true);
                var defaultValue = registry.GetValue("DefaultConnectionSettings");
                var connections  = registry.GetValueNames();
                foreach (String each in connections)
                {
                    switch (each.ToUpperInvariant())
                    {
                    case "DEFAULTCONNECTIONSETTINGS":
                    case "LAN CONNECTION":
                    case "SAVEDLEGACYSETTINGS":
                        continue;

                    default:
                        //set all the connections's proxy as the lan
                        registry.SetValue(each, defaultValue);
                        continue;
                    }
                }
                SystemProxy.NotifyIE();
            }
            catch (IOException e)
            {
                Logging.LogUsefulException(e);
            }
            finally
            {
                if (registry != null)
                {
                    try
                    {
                        registry.Close();
                    }
                    catch (Exception e)
                    {
                        Logging.LogUsefulException(e);
                    }
                }
            }
        }
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     _pacServer.Stop();
     if (privoxyRunner != null)
     {
         privoxyRunner.Stop();
     }
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true, null);
     }
     Encryption.RNG.Close();
 }
        private void UpdateSystemProxy()
        {
#if !_CONSOLE
            if (_config.sysProxyMode != (int)ProxyMode.NoModify)
            {
                SystemProxy.Update(_config, false);
                _systemProxyIsDirty = true;
            }
            else
            {
                // only switch it off if we have switched it on
                if (_systemProxyIsDirty)
                {
                    SystemProxy.Update(_config, false);
                    _systemProxyIsDirty = false;
                }
            }
#endif
        }
示例#13
0
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     _tcpListener?.Stop();
     _udpListener?.Stop();
     StopPlugins();
     if (privoxyRunner != null)
     {
         privoxyRunner.Stop();
     }
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true, null);
     }
 }
示例#14
0
 public static void Disable()
 {
     try
     {
         RegistryKey registry =
             Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                                             true);
         registry.SetValue("ProxyEnable", 0);
         registry.SetValue("ProxyServer", "");
         registry.SetValue("AutoConfigURL", "");
         SystemProxy.NotifyIE();
         CopyProxySettingFromLan();
     }
     catch (Exception)
     {
         MessageBox.Show("can not change registry!");
         throw;
     }
 }
示例#15
0
 public static void Disable()
 {
     try
     {
         RegistryKey registry =
             Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                                             true);
         registry.SetValue("ProxyEnable", 0);
         registry.SetValue("ProxyServer", "");
         registry.SetValue("AutoConfigURL", "");
         SystemProxy.NotifyIE();
         CopyProxySettingFromLan();
     }
     catch (Exception e)
     {
         Logging.LogUsefulException(e);
         // TODO this should be moved into views
         MessageBox.Show(I18N.GetString("Failed to update registry"));
     }
 }
示例#16
0
 public static void Enable()
 {
     try
     {
         RegistryKey registry =
             Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                                             true);
         registry.SetValue("ProxyEnable", 0);
         registry.SetValue("ProxyServer", "");
         registry.SetValue("AutoConfigURL", "http://127.0.0.1:8090/pac?t=" + GetTimestamp(DateTime.Now));
         SystemProxy.NotifyIE();
         //Must Notify IE first, or the connections do not chanage
         CopyProxySettingFromLan();
     }
     catch (Exception)
     {
         MessageBox.Show("can not change registry!");
         throw;
     }
 }
示例#17
0
        public ShadowsocksController()
        {
/***************************************************<Start> add by Ian.May 2016/10/15****************************************************/
// for destructing fogNodes at closing stage, should not be handed from _config;(shallow copy)
/***************************************************<Start> add by Ian.May 2016/10/15****************************************************/
            _configBackup      = Configuration.Load();
            _clientUser        = ClientUser.Load();
            isShadowFogMode    = true;
            isInitialStartup   = true;
            isShadowFogStarted = false;

            SystemProxy.Update(_configBackup, true);// forcedisable = true ,means force _config.enabled = false to update(close) system proxy;
/****************************************************<End> add by Ian.May 2016/10/15*****************************************************/

            _config = Configuration.Load();
            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
            _strategyManager        = new StrategyManager(this);
            StartReleasingMemory();
            StartTrafficStatistics(61);
        }
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     if (_listener != null)
     {
         _listener.Stop();
     }
     if (polipoRunner != null)
     {
         polipoRunner.Stop();
     }
     if (_config.enabled)
     {
         SystemProxy.Update(_config, true);
     }
 }
 public void Stop()
 {
     if (stopped)
     {
         return;
     }
     stopped = true;
     if (local != null)
     {
         local.Stop();
     }
     if (polipoRunner != null)
     {
         polipoRunner.Stop();
     }
     if (_config.enabled)
     {
         SystemProxy.Disable();
     }
 }
        private static void CopyProxySettingFromLan()
        {
            RegistryKey registry = null;

            try
            {
                registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", true);
                var defaultValue = registry.GetValue("DefaultConnectionSettings");
                var connections  = registry.GetValueNames();
                foreach (String each in connections)
                {
                    if (!(each.Equals("DefaultConnectionSettings") ||
                          each.Equals("LAN Connection") ||
                          each.Equals("SavedLegacySettings")))
                    {
                        //set all the connections's proxy as the lan
                        registry.SetValue(each, defaultValue);
                    }
                }
                SystemProxy.NotifyIE();
            }
            catch (IOException e)
            {
                Logging.LogUsefulException(e);
            }
            finally
            {
                if (registry != null)
                {
                    try
                    {
                        registry.Close();
                    }
                    catch (Exception e)
                    {
                        Logging.LogUsefulException(e);
                    }
                }
            }
        }
 private void UpdateSystemProxy()
 {
     SystemProxy.Update(_config, false, _pacServer);
 }
        public static void Update(Configuration config, bool forceDisable)
        {
            bool global  = config.sysProxyMode == (int)ProxyMode.Global;
            bool enabled = config.sysProxyMode != (int)ProxyMode.NoModify;

            if (forceDisable)
            {
                enabled = false;
            }
            RegistryKey registry = null;

            try
            {
                registry = OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
                if (enabled)
                {
                    if (global)
                    {
                        RegistrySetValue(registry, "ProxyEnable", 1);
                        RegistrySetValue(registry, "ProxyServer", "127.0.0.1:" + config.localPort.ToString());
                        RegistrySetValue(registry, "AutoConfigURL", "");
                    }
                    else
                    {
                        string pacUrl;
                        pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now);
                        RegistrySetValue(registry, "ProxyEnable", 0);
                        RegistrySetValue(registry, "ProxyServer", "");
                        RegistrySetValue(registry, "AutoConfigURL", pacUrl);
                    }
                }
                else
                {
                    RegistrySetValue(registry, "ProxyEnable", 0);
                    RegistrySetValue(registry, "ProxyServer", "");
                    RegistrySetValue(registry, "AutoConfigURL", "");
                }
                //Set AutoDetectProxy Off
                IEAutoDetectProxy(false);
                SystemProxy.NotifyIE();
                //Must Notify IE first, or the connections do not chanage
                CopyProxySettingFromLan();
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                // TODO this should be moved into views
                MessageBox.Show(I18N.GetString("Failed to update registry"));
            }
            finally
            {
                if (registry != null)
                {
                    try
                    {
                        registry.Close();
                    }
                    catch (Exception e)
                    {
                        Logging.LogUsefulException(e);
                    }
                }
            }
        }
 private void UpdateSystemProxy()
 {
     SystemProxy.Update(Global.GuiConfig, _pacServer);
 }
        private void UpdateSystemProxy()
        {
#if !_CONSOLE
            SystemProxy.Update(_config, false);
#endif
        }
示例#25
0
        public static void Update(Configuration config, bool forceDisable)
        {
            int sysProxyMode = config.sysProxyMode;

            if (sysProxyMode == (int)ProxyMode.NoModify)
            {
                return;
            }
            if (forceDisable)
            {
                sysProxyMode = (int)ProxyMode.Direct;
            }
            bool    global  = sysProxyMode == (int)ProxyMode.Global;
            bool    enabled = sysProxyMode != (int)ProxyMode.Direct;
            Version win8    = new Version("6.2");
            //if (Environment.OSVersion.Version.CompareTo(win8) < 0)
            {
                using (RegistryKey registry = OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true))
                {
                    try
                    {
                        if (enabled)
                        {
                            if (global)
                            {
                                RegistrySetValue(registry, "ProxyEnable", 1);
                                RegistrySetValue(registry, "ProxyServer", "127.0.0.1:" + config.localPort.ToString());
                                RegistrySetValue(registry, "AutoConfigURL", "");
                            }
                            else
                            {
                                string pacUrl;
                                // pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?" + "auth=" + config.localAuthPassword + "&t=" + Util.Utils.GetTimestamp(DateTime.Now);
                                pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?" + "auth=" + config.localAuthPassword; //+ "&t=" + Util.Utils.GetTimestamp(DateTime.Now);
                                RegistrySetValue(registry, "ProxyEnable", 0);
                                RegistrySetValue(registry, "ProxyServer", "");
                                RegistrySetValue(registry, "AutoConfigURL", pacUrl);
                            }
                        }
                        else
                        {
                            RegistrySetValue(registry, "ProxyEnable", 0);
                            RegistrySetValue(registry, "ProxyServer", "");
                            RegistrySetValue(registry, "AutoConfigURL", "");
                        }
                        IEProxyUpdate(config, sysProxyMode);
                        SystemProxy.NotifyIE();
                        //Must Notify IE first, or the connections do not chanage
                        CopyProxySettingFromLan();
                    }
                    catch (Exception e)
                    {
                        Logging.LogUsefulException(e);
                        // TODO this should be moved into views
                        //MessageBox.Show(I18N.GetString("Failed to update registry"));
                    }
                }
            }

            /* if (Environment.OSVersion.Version.CompareTo(win8) >= 0)
             * {
             *  try
             *  {
             *      if (enabled)
             *      {
             *          if (global)
             *          {
             *              WinINet.SetIEProxy(true, true, "127.0.0.1:" + config.localPort.ToString(), "");
             *          }
             *          else
             *          {
             *              string pacUrl;
             *              pacUrl = $"http://127.0.0.1:{config.localPort}/pac?auth={config.localAuthPassword}&t={Util.Utils.GetTimestamp(DateTime.Now)}";
             *              WinINet.SetIEProxy(true, false, "", pacUrl);
             *          }
             *      }
             *      else
             *      {
             *          WinINet.SetIEProxy(false, false, "", "");
             *      }
             *  }
             *  catch (Exception ex)
             *  {
             *      Logging.LogUsefulException(ex);
             *  }
             * }*/
        }