internal string GetPACContent()
 {
     if (!File.Exists(PAC_FILE))
     {
         GeositeUpdater.MergeAndWritePACFile(config.geositeGroup, config.geositeBlacklistMode);
     }
     return(File.ReadAllText(PAC_FILE, Encoding.UTF8));
 }
 public string TouchPACFile()
 {
     if (!File.Exists(PAC_FILE))
     {
         GeositeUpdater.MergeAndWritePACFile(config.geositeGroup, config.geositeBlacklistMode);
     }
     return(PAC_FILE);
 }
Example #3
0
 internal string GetPACContent()
 {
     if (!File.Exists(PAC_FILE))
     {
         GeositeUpdater.MergeAndWritePACFile(config.geositeDirectGroups, config.geositeProxiedGroups, config.geositePreferDirect);
     }
     return(File.ReadAllText(PAC_FILE, Encoding.UTF8));
 }
Example #4
0
 public string TouchPACFile()
 {
     if (!File.Exists(PAC_FILE))
     {
         GeositeUpdater.MergeAndWritePACFile(config.geositeDirectGroups, config.geositeProxiedGroups, config.geositePreferDirect);
     }
     return(PAC_FILE);
 }
Example #5
0
 private void PacDaemon_UserRuleFileChanged(object sender, EventArgs e)
 {
     GeositeUpdater.MergeAndWritePACFile(_config.geositeGroup, _config.geositeBlacklistMode);
     UpdateSystemProxy();
 }
Example #6
0
        protected void Reload()
        {
            Encryption.RNG.Reload();
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();

            NLogConfig.LoadConfiguration();

            StatisticsConfiguration = StatisticsStrategyConfiguration.Load();

            privoxyRunner = privoxyRunner ?? new PrivoxyRunner();

            _pacDaemon = _pacDaemon ?? new PACDaemon(_config);
            _pacDaemon.PACFileChanged      += PacDaemon_PACFileChanged;
            _pacDaemon.UserRuleFileChanged += PacDaemon_UserRuleFileChanged;
            _pacServer = _pacServer ?? new PACServer(_pacDaemon);
            _pacServer.UpdatePACURL(_config); // So PACServer works when system proxy disabled.

            GeositeUpdater.ResetEvent();
            GeositeUpdater.UpdateCompleted += PacServer_PACUpdateCompleted;
            GeositeUpdater.Error           += PacServer_PACUpdateError;

            availabilityStatistics.UpdateConfiguration(this);
            _listener?.Stop();
            StopPlugins();

            // don't put PrivoxyRunner.Start() before pacServer.Stop()
            // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
            // though UseShellExecute is set to true now
            // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
            privoxyRunner.Stop();
            try
            {
                var strategy = GetCurrentStrategy();
                strategy?.ReloadServers();

                StartPlugin();
                privoxyRunner.Start(_config);

                TCPRelay tcpRelay = new TCPRelay(this, _config);
                tcpRelay.OnConnected += UpdateLatency;
                tcpRelay.OnInbound   += UpdateInboundCounter;
                tcpRelay.OnOutbound  += UpdateOutboundCounter;
                tcpRelay.OnFailed    += (o, e) => GetCurrentStrategy()?.SetFailure(e.server);

                UDPRelay udpRelay = new UDPRelay(this);
                List <Listener.IService> services = new List <Listener.IService>
                {
                    tcpRelay,
                    udpRelay,
                    _pacServer,
                    new PortForwarder(privoxyRunner.RunningPort)
                };
                _listener = new Listener(services);
                _listener.Start(_config);
            }
            catch (Exception e)
            {
                // translate Microsoft language into human language
                // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
                if (e is SocketException se)
                {
                    if (se.SocketErrorCode == SocketError.AddressAlreadyInUse)
                    {
                        e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e);
                    }
                    else if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception(I18N.GetString("Port {0} is reserved by system", _config.localPort), e);
                    }
                }
                logger.LogUsefulException(e);
                ReportError(e);
            }

            ConfigChanged?.Invoke(this, new EventArgs());
            UpdateSystemProxy();
            Utils.ReleaseMemory(true);
        }
Example #7
0
 private void PacDaemon_UserRuleFileChanged(object sender, EventArgs e)
 {
     GeositeUpdater.MergeAndWritePACFile(_config.geositeDirectGroups, _config.geositeProxiedGroups, _config.geositePreferDirect);
     UpdateSystemProxy();
 }
 public void UpdatePACFromGeosite()
 {
     GeositeUpdater.UpdatePACFromGeosite(_config);
 }
Example #9
0
        protected void Reload()
        {
            Encryption.RNG.Reload();
            // some logic in configuration updated the config when saving, we need to read it again
            _config = Configuration.Load();
            Configuration.Process(ref _config);

            NLogConfig.LoadConfiguration();

            logger.Info($"WPF Localization Extension|Current culture: {LocalizeDictionary.CurrentCulture}");

            // set User-Agent for httpClient
            try
            {
                if (!string.IsNullOrWhiteSpace(_config.userAgentString))
                {
                    httpClient.DefaultRequestHeaders.Add("User-Agent", _config.userAgentString);
                }
            }
            catch
            {
                // reset userAgent to default and reapply
                Configuration.ResetUserAgent(_config);
                httpClient.DefaultRequestHeaders.Add("User-Agent", _config.userAgentString);
            }

            privoxyRunner = privoxyRunner ?? new PrivoxyRunner();

            _pacDaemon = _pacDaemon ?? new PACDaemon(_config);
            _pacDaemon.PACFileChanged      += PacDaemon_PACFileChanged;
            _pacDaemon.UserRuleFileChanged += PacDaemon_UserRuleFileChanged;
            _pacServer = _pacServer ?? new PACServer(_pacDaemon);
            _pacServer.UpdatePACURL(_config); // So PACServer works when system proxy disabled.

            GeositeUpdater.ResetEvent();
            GeositeUpdater.UpdateCompleted += PacServer_PACUpdateCompleted;
            GeositeUpdater.Error           += PacServer_PACUpdateError;

            _tcpListener?.Stop();
            _udpListener?.Stop();
            StopPlugins();

            // don't put PrivoxyRunner.Start() before pacServer.Stop()
            // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
            // though UseShellExecute is set to true now
            // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
            privoxyRunner.Stop();
            try
            {
                var strategy = GetCurrentStrategy();
                strategy?.ReloadServers();

                StartPlugin();
                privoxyRunner.Start(_config);

                TCPRelay tcpRelay = new TCPRelay(this, _config);
                tcpRelay.OnInbound  += UpdateInboundCounter;
                tcpRelay.OnOutbound += UpdateOutboundCounter;
                tcpRelay.OnFailed   += (o, e) => GetCurrentStrategy()?.SetFailure(e.server);

                UDPRelay udpRelay = new UDPRelay(this);
                _tcpListener = new TCPListener(_config, new List <IStreamService>
                {
                    tcpRelay,
                    _pacServer,
                    new PortForwarder(privoxyRunner.RunningPort),
                });
                _tcpListener.Start();
                _udpListener = new UDPListener(_config, new List <IDatagramService>
                {
                    udpRelay,
                });
                _udpListener.Start();
            }
            catch (Exception e)
            {
                // translate Microsoft language into human language
                // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
                if (e is SocketException se)
                {
                    if (se.SocketErrorCode == SocketError.AddressAlreadyInUse)
                    {
                        e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e);
                    }
                    else if (se.SocketErrorCode == SocketError.AccessDenied)
                    {
                        e = new Exception(I18N.GetString("Port {0} is reserved by system", _config.localPort), e);
                    }
                }
                logger.LogUsefulException(e);
                ReportError(e);
            }

            ConfigChanged?.Invoke(this, new EventArgs());
            UpdateSystemProxy();
        }