Ejemplo n.º 1
0
        public void SaveConfiguration(CurrentUserConfiguration configuration, string password)
        {
            var    jsonConfiguration      = JsonConvert.SerializeObject(configuration);
            string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, password);

            FileModification.WriteFile(ConfigurationPath, encryptedConfiguration);
        }
Ejemplo n.º 2
0
        public void CreateNewConfiguration(string password)
        {
            CurrentUserConfiguration configuration = new CurrentUserConfiguration()
            {
                ProfileList = new List <Profile>()
            };

            SaveConfiguration(configuration, password);
        }
        private void SaveUserConfiguration(CurrentUserConfiguration userConfiguration)
        {
            var    jsonConfiguration      = JsonConvert.SerializeObject(userConfiguration);
            string encryptedConfiguration = EncryptingHelper.Encrypt(jsonConfiguration, _configurationPassword);

            FileModification.CreateFolderIfNotExists($"{_programSettingsPath}\\.backOnTrack");

            FileModification.WriteFile(GetProxyUserConfigurationPath(), encryptedConfiguration);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var proxy = new LocalWebProxy();
            CurrentUserConfiguration newConfiguration = new CurrentUserConfiguration();
            Profile newProfile = Profile.CreateProfile("Google", false, true);

            newProfile.EntryList.Add(Entry.CreateBlockEntry("google.com", false, true));

            proxy.ApplyUserConfigurationOnProxy(newConfiguration, false);
            proxy.StartProxy();
            Console.Read();
            proxy.QuitProxy();
        }
 public static List <string> GetListOfActiveBlockEntries(CurrentUserConfiguration usedConfiguration)
 {
     return((
                from profile in usedConfiguration.ProfileList
                from entry in profile.EntryList
                where
                profile.ProfileIsEnabled &&
                entry.EntryType == EntryType.Block &&
                entry.IsEnabled &&
                entry.SystemLevelBlockingIsEnabled
                select entry.Url
                ).ToList());
 }
        public void ApplyingConfiguration(CurrentUserConfiguration newConfiguration)
        {
            if (!HostFileExists())
            {
                CreateHostFile();
            }

            AddAllLinesFromHostFileIntoEntryList();
            AddMissingEntriesIntoEntryList(newConfiguration);
            RemoveNotActiveEntriesFromEntryList(newConfiguration);

            SaveHostFile();
            _hostEntries.Clear();
        }
Ejemplo n.º 7
0
        public void ListsShouldBeEmptyAfterInsertingEmptyUserConfiguration()
        {
            //Arrange
            userConfiguration = new CurrentUserConfiguration();

            //Act
            proxyUserConfiguration.ApplyUserConfiguration(userConfiguration);

            //Assert
            proxyUserConfiguration.GetListOfBlockedSites().Count.Should().Be(0);
            proxyUserConfiguration.GetListOfRegexBlockedSites().Count.Should().Be(0);
            proxyUserConfiguration.GetListOfRedirectSites().Count.Should().Be(0);
            proxyUserConfiguration.GetListOfRegexRedirectSites().Count.Should().Be(0);
        }
        public void UpdateConfiguration(CurrentUserConfiguration newConfiguration)
        {
            if (ProxyIsRunning) // mutex for proxyConfiguration
            {
                ProxyIsEnabled = false;
            }

            _webProxy.ApplyUserConfigurationOnProxy(newConfiguration);

            if (ProxyIsRunning)
            {
                ProxyIsEnabled = true;
            }
        }
        public void ApplyUserConfiguration(CurrentUserConfiguration userConfiguration, bool saveConfiguration = true)
        {
            _currentConfiguration = userConfiguration;
            _listOfRedirectSites.Clear();
            _listOfRegexRedirectSites.Clear();
            FillListOfBlockedSites();
            FillListOfRegexBlockedSites();
            FillListOfRedirectSites();
            FillListOfRegexRedirectSites();

            if (saveConfiguration)
            {
                SaveUserConfiguration(userConfiguration);
            }
        }
        public void ConfigurationWasSuccessfullyLoadedFromEnryptedText()
        {
            //Arrange
            string encryptedUserConfiguration = "QLiHt6rADqprmc0LqINtIxV2q+jApusXxgXL5KoHhLefOl+kKRPcFQQD0E9lIPo0L0UMjhSHdLvLOG0/GFUoQjYlB8RednefsikQDLXQMLFXSoyHMjWsqw/wODSnn4Ke";
            string passwordToDecrypt          = "admin";
            CurrentUserConfiguration userConfigurationToCheck = new CurrentUserConfiguration()
            {
                ProfileList = new List <Profile>()
            };

            //Act
            var result = UserConfigurationSupplier.DecryptConfiguration(encryptedUserConfiguration, passwordToDecrypt);

            //Assert
            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(userConfigurationToCheck);
        }
        public void RemoveNotActiveEntriesFromEntryList(CurrentUserConfiguration newConfiguration)
        {
            List <string> listOfActiveBlockEntries = GetListOfActiveBlockEntries(newConfiguration).Select(x => $"127.0.0.1  {x} #BackOnTrackEntry").ToList();

            for (int i = _hostEntries.Count - 1; i >= 0; i--)
            {
                var currentHostEntry = _hostEntries[i];
                if (currentHostEntry.Content.Contains("#BackOnTrackEntry"))
                {
                    //this is a #BackOnTrackEntry
                    if (!listOfActiveBlockEntries.Contains(currentHostEntry.Content))
                    {
                        //old entry
                        _hostEntries.RemoveAt(i);
                    }
                }
            }
        }
        public void AddMissingEntriesIntoEntryList(CurrentUserConfiguration newConfiguration)
        {
            List <string> listOfActiveBlockEntries = GetListOfActiveBlockEntries(newConfiguration);

            List <string> stringListOfEntries = _hostEntries.Select(x => x.Content).ToList();

            if (listOfActiveBlockEntries.Count != 0)
            {
                foreach (string blockedAddress in listOfActiveBlockEntries)
                {
                    string entryLine = $"127.0.0.1  {blockedAddress} #BackOnTrackEntry";
                    if (!stringListOfEntries.Contains(entryLine))
                    {
                        _hostEntries.Add(new HostEntry()
                        {
                            Content = entryLine
                        });
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public MainView(CurrentUserConfiguration userConfiguration, string password)
        {
            _runningApplication = RunningApplication.Instance();

            if (!_runningApplication.UnitTestSetup)
            {
                InitializeComponent();
                App.Current.MainWindow = _runningApplication.UI.MainView; //fix for the dialogWindow
            }

            UserConfiguration = userConfiguration;
            _password         = password;

            if (!_runningApplication.UnitTestSetup)
            {
                WindowIsShown = true;
            }
            else
            {
                WindowIsShown = false;
            }

            IsInEntryEditingMode = false;
        }
Ejemplo n.º 14
0
 public void ApplyUserConfigurationOnSystemLevel(CurrentUserConfiguration newConfiguration)
 {
     systemLevel.ApplyingConfiguration(newConfiguration);
 }
Ejemplo n.º 15
0
 public void SpecificSetup()
 {
     proxyUserConfiguration = new ProxyUserConfiguration(TempFolder.Name);
     userConfiguration      = new CurrentUserConfiguration();
     newProfile             = Profile.CreateProfile("Google", false, true);
 }
Ejemplo n.º 16
0
 public void SetCurrentUserConfiguration(CurrentUserConfiguration configuration)
 {
     UserConfiguration = configuration;
 }
Ejemplo n.º 17
0
 public void ApplyUserConfigurationOnProxy(CurrentUserConfiguration userConfigurations, bool saveConfiguration = true)
 {
     _currentConfiguration.ApplyUserConfiguration(userConfigurations, saveConfiguration);
 }
Ejemplo n.º 18
0
 public void ApplyUserConfigurationOnProxy(CurrentUserConfiguration newConfiguration)
 {
     _runningApplication.Services.WebProxy.UpdateConfiguration(newConfiguration);
 }