public void CancelSelectedCountriesList() { StringBuilder strConfig = new StringBuilder(); int nStart; strConfig.Append(Tor.ReadTorrc()); if (!String.IsNullOrWhiteSpace(strConfig.ToString())) { nStart = strConfig.ToString().IndexOf("StrictNodes"); if (nStart != -1) { strConfig.Remove(nStart, 13); } nStart = strConfig.ToString().IndexOf("ExitNodes"); if (nStart != -1) { int nEnd = strConfig.ToString().IndexOf("\r\n", nStart + 1); if (nEnd < 0) { strConfig.Remove(nStart, strConfig.Length - nStart); } else { strConfig.Remove(nStart, nEnd - nStart); } } string strResult = strConfig.ToString(); Tor.WriteTorrc(strResult); Task t = Task.Run(() => { bool bResult; bResult = Tor.SendSimpleSignal("SIGNAL RELOAD\r\n"); bResult = Tor.SendSimpleSignal("SIGNAL NEWNYM\r\n"); }); } Settings.Remove("Selected countries list"); Settings.Remove("Selected cities list"); Settings.Remove("Selected regions list"); StatusViewModel svm = MSProApp.Locator.StatusVM; CitiesViewModel civm = MSProApp.Locator.CitiesVM; Device.BeginInvokeOnMainThread(() => { if (SelectedCountriesList.Count > 0) { SelectedCountriesList.Clear(); } if (svm.SelectedRegionsList.Count > 0) { svm.SelectedRegionsList.Clear(); } if (civm.SelectedCitiesList.Count > 0) { civm.SelectedCitiesList.Clear(); } }); }
public bool ApplySettings() { StringBuilder strConfig = new StringBuilder(); StringBuilder ExcludedCodesResult = new StringBuilder(); int nStart; strConfig.Append(Tor.ReadTorrc()); if (!String.IsNullOrWhiteSpace(strConfig.ToString())) { if (TorPort != 0) { nStart = strConfig.ToString().IndexOf("SOCKSPort"); if (nStart != -1) { int nEnd = strConfig.ToString().IndexOf(Environment.NewLine, nStart + 1); if (nEnd < 0) { strConfig.Remove(nStart, strConfig.Length - nStart); } else { strConfig.Remove(nStart, nEnd - nStart); } } strConfig.Append("SOCKSPort " + TorPort.ToString() + Environment.NewLine); Settings.SetInt("Tor port", TorPort); } if (TorControlPort != 0) { nStart = strConfig.ToString().IndexOf("ControlPort"); if (nStart != -1) { int nEnd = strConfig.ToString().IndexOf(Environment.NewLine, nStart + 1); if (nEnd < 0) { strConfig.Remove(nStart, strConfig.Length - nStart); } else { strConfig.Remove(nStart, nEnd - nStart); } } strConfig.Append("ControlPort " + TorControlPort.ToString() + Environment.NewLine); Settings.SetInt("Tor control port", TorControlPort); } Tor.WriteTorrc(strConfig.ToString()); } StringBuilder strPolipoConfig = new StringBuilder(); strPolipoConfig.Append(Tor.ReadPolipoConf()); if (PolipoPort != 0) { nStart = strPolipoConfig.ToString().IndexOf("proxyPort="); if (nStart != -1) { int nEnd = strPolipoConfig.ToString().IndexOf(Environment.NewLine, nStart + 1); if (nEnd < 0) { strPolipoConfig.Remove(nStart, strPolipoConfig.Length - nStart); } else { strPolipoConfig.Remove(nStart, nEnd - nStart); } } strPolipoConfig.Append("proxyPort=" + PolipoPort.ToString() + Environment.NewLine); //socksParentProxy nStart = strPolipoConfig.ToString().IndexOf("socksParentProxy="); if (nStart != -1) { int nEnd = strPolipoConfig.ToString().IndexOf(Environment.NewLine, nStart + 1); if (nEnd < 0) { strPolipoConfig.Remove(nStart, strPolipoConfig.Length - nStart); } else { strPolipoConfig.Remove(nStart, nEnd - nStart); } } strPolipoConfig.Append("socksParentProxy=\"localhost\\:" + TorPort.ToString() + "\"" + Environment.NewLine); Tor.WritePolipoConf(strPolipoConfig.ToString()); Settings.SetInt("Polipo port", PolipoPort); } /* * if (IsStartOnBoot != Settings.GetBool("Start on boot", false)) //Applys changes * { * if (IsStartOnBoot) * { * // * } * else * { * // * } * } */ //смена цепи и перезагрузка настроек tor bool bResult; Task t = Task.Run(() => { bResult = Tor.SendSimpleSignal("SIGNAL RELOAD\r\n"); bResult = Tor.SendSimpleSignal("SIGNAL NEWNYM\r\n"); }); return(true); }
public bool ApplySelectedCountriesList() { if (SelectedCountriesList.Count <= 0) { return(false); } //удаление серверов предыдущей страны StringBuilder strConfig = new StringBuilder(); StringBuilder ExcludedCodesResult = new StringBuilder(); int nStart; strConfig.Append(Tor.ReadTorrc()); if (!String.IsNullOrWhiteSpace(strConfig.ToString())) { nStart = strConfig.ToString().IndexOf("StrictNodes"); if (nStart != -1) { strConfig.Remove(nStart, 13); } nStart = strConfig.ToString().IndexOf("ExitNodes"); if (nStart != -1) { int nEnd = strConfig.ToString().IndexOf("\r\n", nStart + 1); if (nEnd < 0) { strConfig.Remove(nStart, strConfig.Length - nStart); } else { strConfig.Remove(nStart, nEnd - nStart); } } string strResult = strConfig.ToString(); strResult += "\r\n"; } StringBuilder strNewExitCountriesEntry = new StringBuilder(); //if (rbtnListModeInclude.IsChecked == true) //{ for (int i = 0; i < SelectedCountriesList.Count; i++) { strNewExitCountriesEntry.Append("{"); strNewExitCountriesEntry.Append(Tor.CountryToCode(SelectedCountriesList.ElementAt(i))); strNewExitCountriesEntry.Append("},"); } strNewExitCountriesEntry.Remove(strNewExitCountriesEntry.Length - 1, 1); //} /* * if (rbtnListModeExclude.IsChecked == true) * { * strNewExitCountriesEntry.Append(AllCountriesCodes.ToUpper()); * strNewExitCountriesEntry.Append(","); * StringBuilder CodeToRemove = new StringBuilder(); * for (int i = 0; i < lbSelectedCountries.Items.Count; i++) * { * CodeToRemove.Clear(); * CodeToRemove.Append("{"); * CodeToRemove.Append(Tor.CountryToCode(lbSelectedCountries.Items.GetItemAt(i).ToString())); * CodeToRemove.Append("},"); * strNewExitCountriesEntry.Replace(CodeToRemove.ToString(), ""); * } * strNewExitCountriesEntry.Remove(strNewExitCountriesEntry.Length - 1, 1); * } */ //write country codes if (!String.IsNullOrEmpty(strNewExitCountriesEntry.ToString())) { strConfig.Append("StrictNodes 1\r\n"); strConfig.Append("ExitNodes "); strConfig.Append(strNewExitCountriesEntry); strConfig.Append("\r\n"); Tor.WriteTorrc(strConfig.ToString()); } else { return(false); } //смена цепи и перезагрузка настроек tor bool bResult; Task t = Task.Run(() => { bResult = Tor.SendSimpleSignal("SIGNAL RELOAD\r\n"); bResult = Tor.SendSimpleSignal("SIGNAL NEWNYM\r\n"); }); StatusViewModel svm = MSProApp.Locator.StatusVM; CitiesViewModel civm = MSProApp.Locator.CitiesVM; Device.BeginInvokeOnMainThread(() => { svm.SelectedRegionsList.ReplaceRange(SelectedCountriesList); if (civm.SelectedCitiesList.Count > 0) { civm.SelectedCitiesList.Clear(); } }); Settings.SetStringCollection("Selected countries list", SelectedCountriesList); Settings.Remove("Selected cities list"); Settings.SetStringCollection("Selected regions list", SelectedCountriesList); //var test=Settings.GetStringCollection("Selected cities list"); return(true); }
public bool ApplySelectedCitiesList() { if (SelectedCitiesList.Count <= 0) { return(false); } //удаление серверов предыдущей страны StringBuilder strConfig = new StringBuilder(); StringBuilder ExcludedCodesResult = new StringBuilder(); int nStart; strConfig.Append(Tor.ReadTorrc()); if (!String.IsNullOrWhiteSpace(strConfig.ToString())) { nStart = strConfig.ToString().IndexOf("StrictNodes"); if (nStart != -1) { strConfig.Remove(nStart, 13); } nStart = strConfig.ToString().IndexOf("ExitNodes"); if (nStart != -1) { int nEnd = strConfig.ToString().IndexOf(Environment.NewLine, nStart + 1); if (nEnd < 0) { strConfig.Remove(nStart, strConfig.Length - nStart); } else { strConfig.Remove(nStart, nEnd - nStart); } } //string strResult = strConfig.ToString(); //strResult += "\r\n"; } StringBuilder SelectedRoutersFingerprints = new StringBuilder(); foreach (string SelectedCity in SelectedCitiesList) { var SelectedCitiesGroup = from SelectedGroup in AllCitiesList where SelectedGroup.Name == SelectedCity select SelectedGroup; foreach (City curcity in SelectedCitiesGroup) { string reply = ""; Task ts = Task.Run(() => { //desc/name/ reply = Tor.SendSignal("GETINFO desc/name/" + curcity.RouterName + Environment.NewLine); }); ts.Wait(); if (String.IsNullOrEmpty(reply)) { continue; } int end = reply.IndexOf("uptime"); int start = reply.IndexOf("fingerprint "); string fingerprint = reply.Substring(start + 12, end - start - 12); fingerprint = fingerprint.Replace(" ", String.Empty); SelectedRoutersFingerprints.Append(fingerprint); SelectedRoutersFingerprints.Append(","); } } if (SelectedRoutersFingerprints.Length > 0) { SelectedRoutersFingerprints.Remove(SelectedRoutersFingerprints.Length - 1, 1); SelectedRoutersFingerprints.Append(Environment.NewLine); } //write country codes if (!String.IsNullOrEmpty(SelectedRoutersFingerprints.ToString())) { nStart = strConfig.ToString().IndexOf("StrictNodes"); if (nStart != -1) { strConfig.Remove(nStart, 13); } nStart = strConfig.ToString().IndexOf("ExitNodes"); if (nStart != -1) { int nEnd = strConfig.ToString().IndexOf(Environment.NewLine, nStart + 1); if (nEnd < 0) { strConfig.Remove(nStart, strConfig.Length - nStart); } else { strConfig.Remove(nStart, nEnd - nStart); } } strConfig.Append("StrictNodes 1\r\n"); strConfig.Append("ExitNodes "); strConfig.Append(SelectedRoutersFingerprints.ToString()); Tor.WriteTorrc(strConfig.ToString()); } else { return(false); } //смена цепи и перезагрузка настроек tor bool bResult; Task t = Task.Run(() => { bResult = Tor.SendSimpleSignal("SIGNAL RELOAD\r\n"); bResult = Tor.SendSimpleSignal("SIGNAL NEWNYM\r\n"); }); StatusViewModel svm = MSProApp.Locator.StatusVM; CountriesViewModel cvm = MSProApp.Locator.CountriesVM; Device.BeginInvokeOnMainThread(() => { svm.SelectedRegionsList.ReplaceRange(SelectedCitiesList); if (cvm.SelectedCountriesList.Count > 0) { cvm.SelectedCountriesList.Clear(); } }); Settings.SetStringCollection("Selected cities list", SelectedCitiesList); Settings.Remove("Selected countries list"); Settings.SetStringCollection("Selected regions list", SelectedCitiesList); return(true); }