public ProxyEntry GetProxyEntryFromSettings(Guid networkId) { string nwId = networkId.ToString(); ProxyEntry proxy = new ProxyEntry(); if (!String.IsNullOrEmpty(this.Settings[nwId + "_Url"])) { proxy.Url[ProxyScheme.All] = this.Settings[nwId + "_Url"]; proxy.Port[ProxyScheme.All] = this.Settings.ContainsKey(nwId + "_Port") ? int.Parse(this.Settings[nwId + "_Port"]) : 0; } else { foreach (var key in this.Settings.Keys) { if (key.Contains(nwId + "_Url_")) { proxy.Url[key.Split('_')[2]] = this.Settings[key]; } if (key.Contains(nwId + "_Port_")) { proxy.Port[key.Split('_')[2]] = int.Parse(this.Settings[key]); } } } proxy.IsAutoConf = this.Settings.ContainsKey(nwId + "_IsAutoConf") ? bool.Parse(this.Settings[nwId + "_IsAutoConf"]) : false; proxy.IsAutoDetect = this.Settings.ContainsKey(nwId + "_IsAutoDetect") ? bool.Parse(this.Settings[nwId + "_IsAutoDetect"]) : false; proxy.ByPassLocal = this.Settings.ContainsKey(nwId + "_ByPassLocal") ? bool.Parse(this.Settings[nwId + "_ByPassLocal"]) : false; proxy.Exceptions = this.Settings[nwId + "_Exceptions"]; proxy.RequiresAuthentication = this.Settings.ContainsKey(nwId + "_RequiresAuthentication") ? bool.Parse(this.Settings[nwId + "_RequiresAuthentication"]) : false; proxy.AuthenticationUsername = this.Settings[nwId + "_AuthenticationUsername"]; proxy.AuthenticationPassword = Decrypt(this.Settings[nwId + "_AuthenticationPassword"]); return proxy; }
public override void Activate(ProxyEntry proxy, Guid networkId) { string key1 = "HKEY_CURRENT_USER\\Software\\TortoiseSVN\\Servers\\global"; string key2 = "HKEY_CURRENT_USER\\Software\\Tigris.org\\Subversion\\Servers\\global"; RegistryHelper.SetStringValue(key1, "http-proxy-exceptions", proxy.Exceptions); RegistryHelper.SetStringValue(key2, "http-proxy-exceptions", proxy.Exceptions); RegistryHelper.SetStringValue(key1, "http-proxy-host", proxy.Url.FirstEntry()); RegistryHelper.SetStringValue(key2, "http-proxy-host", proxy.Url.FirstEntry()); RegistryHelper.SetStringValue(key1, "http-proxy-port", proxy.Port.FirstEntry()); RegistryHelper.SetStringValue(key2, "http-proxy-port", proxy.Port.FirstEntry()); if (proxy.RequiresAuthentication) { RegistryHelper.SetStringValue(key1, "http-proxy-username", proxy.AuthenticationUsername); RegistryHelper.SetStringValue(key2, "http-proxy-username", proxy.AuthenticationUsername); RegistryHelper.SetStringValue(key1, "http-proxy-password", proxy.AuthenticationPassword); RegistryHelper.SetStringValue(key2, "http-proxy-password", proxy.AuthenticationPassword); } else { RegistryHelper.SetStringValue(key1, "http-proxy-username", string.Empty); RegistryHelper.SetStringValue(key2, "http-proxy-username", string.Empty); RegistryHelper.SetStringValue(key1, "http-proxy-password", string.Empty); RegistryHelper.SetStringValue(key2, "http-proxy-password", string.Empty); } }
public void SetProxyEntryToSettings(Guid networkId, ProxyEntry proxy) { string nwId = networkId.ToString(); this.Settings.Remove(nwId + "_Url_" + ProxyScheme.All.ToString()); this.Settings.Remove(nwId + "_Port_" + ProxyScheme.All.ToString()); foreach (var key in proxy.Url.Keys) { this.Settings[nwId + "_Url_" + key.ToString()] = proxy.Url[key]; this.Settings[nwId + "_Port_" + key.ToString()] = proxy.Port[key].ToString(); } //remove old storage system this.Settings.Remove(nwId + "_Url"); this.Settings.Remove(nwId + "_Port"); this.Settings[nwId + "_IsAutoConf"] = proxy.IsAutoConf.ToString(); this.Settings[nwId + "_IsAutoDetect"] = proxy.IsAutoDetect.ToString(); this.Settings[nwId + "_ByPassLocal"] = proxy.ByPassLocal.ToString(); this.Settings[nwId + "_Exceptions"] = proxy.Exceptions; this.Settings[nwId + "_RequiresAuthentication"] = proxy.RequiresAuthentication.ToString(); this.Settings[nwId + "_AuthenticationUsername"] = proxy.AuthenticationUsername; this.Settings[nwId + "_AuthenticationPassword"] = Encrypt(proxy.AuthenticationPassword); OnSettingsChanged(); if (HostApplication != null) { HostApplication.SetStatusText(this, ActionResources.Saved_Status); } }
internal void SetDefaultProxy(ProxyEntry proxyEntry) { if (this.proxy.Port.FirstEntry() == 0 && String.IsNullOrEmpty(this.proxy.Url.FirstEntry())) { SetProxyToUI(proxyEntry); } }
private void buttonSave_Click(object sender, RoutedEventArgs e) { if (proxy == null) { proxy = new ProxyEntry(); } CleanUpStores(); PrepareSave(); proxy.Url = this.urlStore; proxy.Port = this.portStore; proxy.IsAutoConf = checkBoxAutoConfig.IsChecked.Value; proxy.IsAutoDetect = checkBoxAutoDetect.IsChecked.Value; proxy.ByPassLocal = checkBoxBypass.IsChecked.Value; proxy.Exceptions = textBoxExceptions.Text; proxy.RequiresAuthentication = checkBoxRequiresAuthentication.IsChecked.Value; proxy.AuthenticationUsername = textBoxUsername.Text; proxy.AuthenticationPassword = passwordBoxPassword.Password; try { this.proxySwitcherAction.ValidateEntry(proxy); this.proxySwitcherAction.SetProxyEntryToSettings(this.networkId, proxy); } catch (ProxyValidationException ex) { this.proxySwitcherAction.HostApplication.SetStatusText(this.proxySwitcherAction, ex.Message, true); } }
private void SetProxyToUI(ProxyEntry proxyEntry) { if (proxyEntry == null) { return; } this.urlStore = proxyEntry.Url; this.portStore = proxyEntry.Port; fireEvent = false; checkBoxUseSame.IsChecked = proxyEntry.Url.IsAllSet || proxyEntry.Url.Keys.Length < 1; SelectScheme(proxyEntry.Url.FirstScheme()); textBoxUrl.Text = proxyEntry.Url.FirstEntry(); textBoxPort.Text = proxyEntry.Port.FirstEntry().ToString(); textBoxExceptions.Text = proxyEntry.Exceptions; checkBoxAutoConfig.IsChecked = proxyEntry.IsAutoConf; checkBoxAutoDetect.IsChecked = proxyEntry.IsAutoDetect; checkBoxBypass.IsChecked = proxyEntry.ByPassLocal; checkBoxRequiresAuthentication.IsChecked = proxyEntry.RequiresAuthentication; textBoxUsername.Text = proxyEntry.AuthenticationUsername; passwordBoxPassword.Password = proxyEntry.AuthenticationPassword; fireEvent = true; }
public override void Activate(ProxyEntry proxy, Guid networkId) { IniHelper helper = new IniHelper(GetOperaIniFile()); if (proxy.IsAutoConf) { helper.SetValue("Proxy", "Automatic Proxy Configuration URL", proxy.Url.FirstEntry()); helper.SetValue("Proxy", "Use Automatic Proxy Configuration", "1"); } else { if (proxy.Url.IsAllSet) { helper.SetValue("Proxy", "HTTP server", proxy.Url[ProxyScheme.All] + ":" + proxy.Port[ProxyScheme.All].ToString()); helper.SetValue("Proxy", "HTTPS server", proxy.Url[ProxyScheme.All] + ":" + proxy.Port[ProxyScheme.All].ToString()); helper.SetValue("Proxy", "Use HTTP", "1"); helper.SetValue("Proxy", "Use HTTPS", "1"); } else { if (proxy.Url.ContainsKey(ProxyScheme.HTTP)) { helper.SetValue("Proxy", "HTTP server", proxy.Url[ProxyScheme.HTTP] + ":" + proxy.Port[ProxyScheme.HTTP].ToString()); helper.SetValue("Proxy", "Use HTTP", "1"); } if (proxy.Url.ContainsKey(ProxyScheme.HTTPS)) { helper.SetValue("Proxy", "HTTPS server", proxy.Url[ProxyScheme.HTTPS] + ":" + proxy.Port[ProxyScheme.HTTPS].ToString()); helper.SetValue("Proxy", "Use HTTPS", "1"); } if (proxy.Url.ContainsKey(ProxyScheme.FTP)) { helper.SetValue("Proxy", "FTP server", proxy.Url[ProxyScheme.FTP] + ":" + proxy.Port[ProxyScheme.FTP].ToString()); helper.SetValue("Proxy", "Use FTP", "1"); } } if (String.IsNullOrEmpty(proxy.Exceptions)) { helper.SetValue("Proxy", "No Proxy Servers Check", "0"); } else { helper.SetValue("Proxy", "No Proxy Servers", proxy.Exceptions); helper.SetValue("Proxy", "No Proxy Servers Check", "1"); } if (proxy.ByPassLocal) { helper.SetValue("Proxy", "Use Proxy On Local Names Check", "0"); } else { helper.SetValue("Proxy", "Use Proxy On Local Names Check", "1"); } } helper.Save(); }
public ProxySwitcherUserControl(ProxySwitcherAction proxySwitcherAction, Guid networkId) : this() { this.proxySwitcherAction = proxySwitcherAction; this.networkId = networkId; this.proxy = this.proxySwitcherAction.GetProxyEntryFromSettings(networkId); PopulateSchemeComboBox(); SetProxyToUI(proxy); }
public ProxySwitcherUserControl(ProxySwitcherAction proxySwitcherAction, Guid networkId) : this() { this.proxySwitcherAction = proxySwitcherAction; this.networkId = networkId; this.proxy = this.proxySwitcherAction.GetProxyEntryFromSettings(networkId); PopulateSchemeComboBox(); SetProxyToUI(proxy); }
public override void Activate(ProxyEntry entry, Guid networkId) { string proxy = entry.Url.FirstEntry() + ":" + entry.Port.FirstEntry().ToString(); string sid = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value; if (!entry.IsAutoConf) //only if not autoconf. autoconf is set in enable/disableProxy { RegistryHelper.SetStringValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", proxy); RegistryHelper.SetStringValue(@"HKEY_USERS\" + sid + @"\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", proxy); if (entry.ByPassLocal || !String.IsNullOrEmpty(entry.Exceptions)) { string byPassString = entry.Exceptions; if (entry.ByPassLocal) { if (byPassString.Length != 0) byPassString += ";<local>"; else byPassString = "<local>"; } RegistryHelper.SetStringValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride", byPassString); RegistryHelper.SetStringValue(@"HKEY_USERS\" + sid + @"\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride", byPassString); } else { RegistryHelper.DeleteEntry(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride"); RegistryHelper.DeleteEntry(@"HKEY_USERS\" + sid + @"\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride"); } } if (!entry.IsAutoConf) { RegistryHelper.SetDWordValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 1); RegistryHelper.SetDWordValue(@"HKEY_USERS\" + sid + @"\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 1); } else { RegistryHelper.SetStringValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "AutoConfigURL", entry.Url.FirstEntry()); RegistryHelper.SetStringValue(@"HKEY_USERS\" + sid + @"\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "AutoConfigURL", entry.Url.FirstEntry()); } RefreshIESettings(); }
public override void Activate(ProxyEntry proxy, Guid networkId) { string file = GetProfileFolder(networkId); // all if (String.IsNullOrEmpty(GetProfileToSwitch(networkId))) { foreach (string profPath in GetAllProfiles(networkId)) { file = Path.Combine(file, profPath); file = Path.Combine(file, "prefs.js"); EnableProxy(file, proxy); } } else { file = Path.Combine(file, GetProfileToSwitch(networkId)); file = Path.Combine(file, "prefs.js"); EnableProxy(file, proxy); } }
public ProxyEntry GetProxyEntryFromSettings(Guid networkId) { string nwId = networkId.ToString(); ProxyEntry proxy = new ProxyEntry(); if (!String.IsNullOrEmpty(this.Settings[nwId + "_Url"])) { proxy.Url[ProxyScheme.All] = this.Settings[nwId + "_Url"]; proxy.Port[ProxyScheme.All] = this.Settings.ContainsKey(nwId + "_Port") ? int.Parse(this.Settings[nwId + "_Port"]) : 0; } else { foreach (var key in this.Settings.Keys) { if (key.Contains(nwId + "_Url_")) { proxy.Url[key.Split('_')[2]] = this.Settings[key]; } if (key.Contains(nwId + "_Port_")) { proxy.Port[key.Split('_')[2]] = int.Parse(this.Settings[key]); } } } proxy.IsAutoConf = this.Settings.ContainsKey(nwId + "_IsAutoConf") ? bool.Parse(this.Settings[nwId + "_IsAutoConf"]) : false; proxy.IsAutoDetect = this.Settings.ContainsKey(nwId + "_IsAutoDetect") ? bool.Parse(this.Settings[nwId + "_IsAutoDetect"]) : false; proxy.ByPassLocal = this.Settings.ContainsKey(nwId + "_ByPassLocal") ? bool.Parse(this.Settings[nwId + "_ByPassLocal"]) : false; proxy.Exceptions = this.Settings[nwId + "_Exceptions"]; proxy.RequiresAuthentication = this.Settings.ContainsKey(nwId + "_RequiresAuthentication") ? bool.Parse(this.Settings[nwId + "_RequiresAuthentication"]) : false; proxy.AuthenticationUsername = this.Settings[nwId + "_AuthenticationUsername"]; proxy.AuthenticationPassword = Decrypt(this.Settings[nwId + "_AuthenticationPassword"]); return(proxy); }
private void SetProxyToUI(ProxyEntry proxyEntry) { if (proxyEntry == null) return; this.urlStore = proxyEntry.Url; this.portStore = proxyEntry.Port; fireEvent = false; checkBoxUseSame.IsChecked = proxyEntry.Url.IsAllSet || proxyEntry.Url.Keys.Length < 1; SelectScheme(proxyEntry.Url.FirstScheme()); textBoxUrl.Text = proxyEntry.Url.FirstEntry(); textBoxPort.Text = proxyEntry.Port.FirstEntry().ToString(); textBoxExceptions.Text = proxyEntry.Exceptions; checkBoxAutoConfig.IsChecked = proxyEntry.IsAutoConf; checkBoxAutoDetect.IsChecked = proxyEntry.IsAutoDetect; checkBoxBypass.IsChecked = proxyEntry.ByPassLocal; checkBoxRequiresAuthentication.IsChecked = proxyEntry.RequiresAuthentication; textBoxUsername.Text = proxyEntry.AuthenticationUsername; passwordBoxPassword.Password = proxyEntry.AuthenticationPassword; fireEvent = true; }
/// <summary> /// Should throw a ProxyValidationException on error. /// </summary> /// <param name="proxy"></param> public virtual void ValidateEntry(ProxyEntry proxy) { }
private void EnableProxy(string file, ProxyEntry proxy) { string content = ""; using (StreamReader sr = new StreamReader(file)) { content = sr.ReadToEnd(); } StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (StringReader sr = new StringReader(content)) { while (true) { string line = sr.ReadLine(); if (line == null) break; if (line.StartsWith("user_pref(\"network.proxy.type")) continue; if (line.StartsWith("user_pref(\"network.proxy.autoconfig_url")) continue; if (line.StartsWith("user_pref(\"network.proxy.http")) continue; if (line.StartsWith("user_pref(\"network.proxy.http_port")) continue; if (line.StartsWith("user_pref(\"network.proxy.ssl")) continue; if (line.StartsWith("user_pref(\"network.proxy.ssl_port")) continue; if (line.StartsWith("user_pref(\"network.proxy.ftp")) continue; if (line.StartsWith("user_pref(\"network.proxy.ftp_port")) continue; if (line.StartsWith("user_pref(\"network.proxy.socks")) continue; if (line.StartsWith("user_pref(\"network.proxy.socks_port")) continue; if (line.StartsWith("user_pref(\"network.proxy.no_proxies_on")) continue; if (line.StartsWith("user_pref(\"network.proxy.share_proxy_settings")) continue; sw.WriteLine(line); } } if (proxy.IsAutoConf) { sw.WriteLine("user_pref(\"network.proxy.autoconfig_url\", \"" + proxy.Url.FirstEntry() + "\");"); sw.WriteLine("user_pref(\"network.proxy.type\", 2);"); } else if (proxy.IsAutoDetect) { sw.WriteLine("user_pref(\"network.proxy.type\", 4);"); } else { if (proxy.Url.IsAllSet) { sw.WriteLine("user_pref(\"network.proxy.http\", \"" + proxy.Url[ProxyScheme.All] + "\");"); sw.WriteLine("user_pref(\"network.proxy.http_port\", " + proxy.Port[ProxyScheme.All].ToString() + ");"); sw.WriteLine("user_pref(\"network.proxy.ssl\", \"" + proxy.Url[ProxyScheme.All] + "\");"); sw.WriteLine("user_pref(\"network.proxy.ssl_port\", " + proxy.Port[ProxyScheme.All].ToString() + ");"); sw.WriteLine("user_pref(\"network.proxy.ftp\", \"" + proxy.Url[ProxyScheme.All] + "\");"); sw.WriteLine("user_pref(\"network.proxy.ftp_port\", " + proxy.Port[ProxyScheme.All].ToString() + ");"); sw.WriteLine("user_pref(\"network.proxy.socks\", \"" + proxy.Url[ProxyScheme.All] + "\");"); sw.WriteLine("user_pref(\"network.proxy.socks_port\", " + proxy.Port[ProxyScheme.All].ToString() + ");"); } else { if (proxy.Url.ContainsKey(ProxyScheme.HTTP)) { sw.WriteLine("user_pref(\"network.proxy.http\", \"" + proxy.Url[ProxyScheme.HTTP] + "\");"); sw.WriteLine("user_pref(\"network.proxy.http_port\", " + proxy.Port[ProxyScheme.HTTP].ToString() + ");"); } if (proxy.Url.ContainsKey(ProxyScheme.HTTPS)) { sw.WriteLine("user_pref(\"network.proxy.ssl\", \"" + proxy.Url[ProxyScheme.HTTPS] + "\");"); sw.WriteLine("user_pref(\"network.proxy.ssl_port\", " + proxy.Port[ProxyScheme.HTTPS].ToString() + ");"); } if (proxy.Url.ContainsKey(ProxyScheme.FTP)) { sw.WriteLine("user_pref(\"network.proxy.ftp\", \"" + proxy.Url[ProxyScheme.FTP] + "\");"); sw.WriteLine("user_pref(\"network.proxy.ftp_port\", " + proxy.Port[ProxyScheme.FTP].ToString() + ");"); } if (proxy.Url.ContainsKey(ProxyScheme.SOCKS)) { sw.WriteLine("user_pref(\"network.proxy.socks\", \"" + proxy.Url[ProxyScheme.SOCKS] + "\");"); sw.WriteLine("user_pref(\"network.proxy.socks_port\", " + proxy.Port[ProxyScheme.SOCKS].ToString() + ");"); } } string noProxies = proxy.Exceptions; if (proxy.ByPassLocal) noProxies = "localhost, 127.0.0.1, " + noProxies; sw.WriteLine("user_pref(\"network.proxy.no_proxies_on\", \"" + noProxies + "\");"); sw.WriteLine("user_pref(\"network.proxy.share_proxy_settings\", true);"); sw.WriteLine("user_pref(\"network.proxy.type\", 1);"); } } using (StreamWriter sw = new StreamWriter(file)) { sw.Write(sb.ToString()); } }
public override void Activate(ProxyEntry proxy, Guid networkId) { string prx = string.Empty; if (proxy.Url.IsAllSet) prx = proxy.Url[ProxyScheme.All] + ":" + proxy.Port[ProxyScheme.All].ToString(); else { foreach (var scheme in proxy.Url.Keys) { prx += String.Format("{0}={1}:{2};", scheme.ToString().ToLower(), proxy.Url[scheme], proxy.Port[scheme]); } } string sid = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value; // 01=disabled, 03=enabled, 05=auto config, 09=auto detect, 0b=auto detect and manual proxy, 0D=auto config und auto detect byte enabled = (byte)03; if (proxy.IsAutoDetect && !String.IsNullOrEmpty(prx)) enabled = (byte)11; //11=0b else if (proxy.IsAutoConf && proxy.IsAutoDetect) enabled = (byte)13; //13=0d else if (proxy.IsAutoConf) enabled = (byte)05; else if (proxy.IsAutoDetect) enabled = (byte)09; //Convert Proxy Addresses to Bytes byte[] proxyBytes = Encoding.Default.GetBytes(prx); byte entryLength = (byte)proxyBytes.Length; if (proxy.IsAutoConf) { proxyBytes = new byte[0]; entryLength = 0; } byte[] configStart = new byte[] { 70, 00, 00, 00, 01, 00, 00, 03, enabled, 00, 00, 00, entryLength, 00, 00, 00 }; string byPassString = string.Empty; if (proxy.ByPassLocal || !String.IsNullOrEmpty(proxy.Exceptions)) { byPassString = proxy.Exceptions; if (proxy.ByPassLocal) { if (byPassString.Length != 0) byPassString += ";<local>"; else byPassString = "<local>"; } } //Convert Exceptions to Bytes byte[] exceptions = Encoding.Default.GetBytes(byPassString); int autoConfigUrlArrayLength = 0; byte[] autoConfigUrl = new byte[0]; if (proxy.IsAutoConf) { autoConfigUrl = Encoding.Default.GetBytes(proxy.Url.FirstEntry()); autoConfigUrlArrayLength = autoConfigUrl.Length; } int lastPosition = 0; //Set Merged byte[] merged = new byte[configStart.Length + proxyBytes.Length + 4 + exceptions.Length + 4 + autoConfigUrlArrayLength + 31]; //Add ConfigStart to Merged configStart.CopyTo(merged, lastPosition); lastPosition = configStart.Length; //Add ProxyServers to Merged proxyBytes.CopyTo(merged, lastPosition); lastPosition += proxyBytes.Length; //Convert exceptions string length to Hex Values string hexString = exceptions.Length.ToString("x"); //first character should be 0 if string is not even length hexString = (hexString.Length % 2 == 0 ? "" : "0") + hexString; //Convert Hex String to Byte Array int NumberChars = hexString.Length; byte[] bytes = new byte[NumberChars / 2]; for (int i = 0; i < NumberChars; i += 2) { bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16); } //Reverse Byte Array Array.Reverse(bytes); Array.Resize(ref bytes, 4); bytes.CopyTo(merged, lastPosition); lastPosition += 4; //Add Exceptions to Merged exceptions.CopyTo(merged, lastPosition); lastPosition += exceptions.Length; //Add AutoConfigURL to Merged new byte[] { (byte)autoConfigUrl.Length, 0, 0, 0 }.CopyTo(merged, lastPosition); lastPosition += 4; if (proxy.IsAutoConf) { autoConfigUrl.CopyTo(merged, lastPosition); lastPosition += autoConfigUrl.Length; } new byte[31].CopyTo(merged, lastPosition); if (UseDialUp(networkId)) { string connectionName = GetDialUpName(networkId); RegistryHelper.SetBinaryValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", connectionName, merged); } else { RegistryHelper.SetBinaryValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings", merged); } RefreshIESettings(); }
public override ProxyEntry GetDefaultProxy() { ProxyEntry proxy = new ProxyEntry(); IniHelper helper = new IniHelper(GetOperaIniFile()); proxy.IsAutoConf = (helper.GetValue("Proxy", "Use Automatic Proxy Configuration") == "1"); if (proxy.IsAutoConf) { proxy.Url[ProxyScheme.All] = helper.GetValue("Proxy", "Automatic Proxy Configuration URL"); } else { string[] urlPort = helper.GetValue("Proxy", "HTTP server").Split(':'); proxy.Url[ProxyScheme.All] = urlPort[0]; int port; if (urlPort.Length > 1 && int.TryParse(urlPort[1], out port)) proxy.Port[ProxyScheme.All] = port; } return proxy; }
public override ProxyEntry GetDefaultProxy() { byte[] binValue = (byte[])RegistryHelper.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings"); ProxyEntry proxy = new ProxyEntry(); proxy.IsAutoConf = (binValue[8] == (byte)05); List<byte> proxyUrlPortBytes = new List<byte>(); var length = binValue[12] + 16; for (int i = 16; i < length; i++) { proxyUrlPortBytes.Add(binValue[i]); } string val = Encoding.Default.GetString(proxyUrlPortBytes.ToArray()); int httpIndex = val.IndexOf("http="); if (httpIndex > 0) { int endIndex = val.IndexOf(";", httpIndex + 1); val = val.Substring(httpIndex + "http=".Length, endIndex - httpIndex - "http=".Length); } string[] urlPort = val.Split(':'); if (urlPort[0].Contains("=")) return proxy; proxy.Url[ProxyScheme.All] = urlPort[0]; int port; if (urlPort.Length > 1 && int.TryParse(urlPort[1], out port)) proxy.Port[ProxyScheme.All] = port; return proxy; }
public override void ValidateEntry(ProxyEntry proxy) { if (proxy.Exceptions.Contains("/")) throw new ProxyValidationException(DefaultResources.ProxyExceptionsError); }
private void buttonSave_Click(object sender, RoutedEventArgs e) { if (proxy == null) proxy = new ProxyEntry(); CleanUpStores(); PrepareSave(); proxy.Url = this.urlStore; proxy.Port = this.portStore; proxy.IsAutoConf = checkBoxAutoConfig.IsChecked.Value; proxy.IsAutoDetect = checkBoxAutoDetect.IsChecked.Value; proxy.ByPassLocal = checkBoxBypass.IsChecked.Value; proxy.Exceptions = textBoxExceptions.Text; proxy.RequiresAuthentication = checkBoxRequiresAuthentication.IsChecked.Value; proxy.AuthenticationUsername = textBoxUsername.Text; proxy.AuthenticationPassword = passwordBoxPassword.Password; try { this.proxySwitcherAction.ValidateEntry(proxy); this.proxySwitcherAction.SetProxyEntryToSettings(this.networkId, proxy); } catch (ProxyValidationException ex) { this.proxySwitcherAction.HostApplication.SetStatusText(this.proxySwitcherAction, ex.Message, true); } }
public override void Activate(ProxyEntry proxy, Guid networkId) { string prx = string.Empty; if (proxy.Url.IsAllSet) prx = proxy.Url[ProxyScheme.All] + ":" + proxy.Port[ProxyScheme.All].ToString(); else { foreach (var scheme in proxy.Url.Keys) { prx += String.Format("{0}={1}:{2};", scheme.ToString().ToLower(), proxy.Url[scheme], proxy.Port[scheme]); } } string sid = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value; // 01=disabled, 03=enabled, 05=auto config, 09=auto detect, 0D=auto config und auto detect byte enabled = (byte)03; if (proxy.IsAutoConf && proxy.IsAutoDetect) enabled = (byte)13; //13=0d else if (proxy.IsAutoConf) enabled = (byte)05; else if (proxy.IsAutoDetect) enabled = (byte)09; byte[] proxyBytes = Encoding.Default.GetBytes(prx); byte entryLength = (byte)proxyBytes.Length; if (proxy.IsAutoConf) { proxyBytes = new byte[0]; entryLength = 0; } byte[] configStart = new byte[] { 70, 00, 00, 00, 01, 00, 00, 03, enabled, 00, 00, 00, entryLength, 00, 00, 00 }; string byPassString = string.Empty; if (proxy.ByPassLocal || !String.IsNullOrEmpty(proxy.Exceptions)) { byPassString = proxy.Exceptions; if (proxy.ByPassLocal) { if (byPassString.Length != 0) byPassString += ";<local>"; else byPassString = "<local>"; } } byte[] exceptions = Encoding.Default.GetBytes(byPassString); int autoConfigUrlArrayLength = 0; byte[] autoConfigUrl = new byte[0]; if (proxy.IsAutoConf) { autoConfigUrl = Encoding.Default.GetBytes(proxy.Url.FirstEntry()); autoConfigUrlArrayLength = autoConfigUrl.Length; } int lastPosition = 0; byte[] merged = new byte[configStart.Length + proxyBytes.Length + 4 + exceptions.Length + 4 + autoConfigUrlArrayLength + 31]; configStart.CopyTo(merged, lastPosition); lastPosition = configStart.Length; proxyBytes.CopyTo(merged, lastPosition); lastPosition += proxyBytes.Length; if (exceptions.Length > 255) { //length is 379. in hex: 17B. muss in der reg als 17 und 0B eingetragen werden //int l1 = exceptions.Length - 356; //int l2 = 11; //new byte[] { (byte)l1, (byte)l2, 0, 0 }.CopyTo(merged, lastPosition); } else { new byte[] { (byte)exceptions.Length, 0, 0, 0 }.CopyTo(merged, lastPosition); } lastPosition += 4; exceptions.CopyTo(merged, lastPosition); lastPosition += exceptions.Length; new byte[] { (byte)autoConfigUrl.Length, 0, 0, 0 }.CopyTo(merged, lastPosition); lastPosition += 4; if (proxy.IsAutoConf) { autoConfigUrl.CopyTo(merged, lastPosition); lastPosition += autoConfigUrl.Length; } new byte[31].CopyTo(merged, lastPosition); if (UseDialUp(networkId)) { string connectionName = GetDialUpName(networkId); RegistryHelper.SetBinaryValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", connectionName, merged); } else { RegistryHelper.SetBinaryValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections", "DefaultConnectionSettings", merged); } RefreshIESettings(); }
internal void SetDefaultProxy(ProxyEntry proxyEntry) { if (this.proxy.Port.FirstEntry() == 0 && String.IsNullOrEmpty(this.proxy.Url.FirstEntry())) SetProxyToUI(proxyEntry); }
public override void Activate(ProxySwitcher.Actions.ProxyBase.ProxyEntry proxy, Guid networkId) { var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Skype", "shared.xml"); if (!File.Exists(file)) { this.HostApplication.SetStatusText(this, "Skype config file not found", true); return; } var http = false; var socks = false; string proxyUrl = string.Empty; if (proxy.Url.IsAllSet) { proxyUrl = String.Format("{0}:{1}", proxy.Url[ProxyScheme.All], proxy.Port[ProxyScheme.All]); http = true; } else { if (proxy.Url.ContainsKey(ProxyScheme.HTTP)) { proxyUrl = String.Format("{0}:{1}", proxy.Url[ProxyScheme.HTTP], proxy.Port[ProxyScheme.HTTP]); http = true; } if (proxy.Url.ContainsKey(ProxyScheme.HTTPS)) { proxyUrl = String.Format("{0}:{1}", proxy.Url[ProxyScheme.HTTPS], proxy.Port[ProxyScheme.HTTPS]); http = true; } if (proxy.Url.ContainsKey(ProxyScheme.SOCKS)) { proxyUrl = String.Format("{0}:{1}", proxy.Url[ProxyScheme.SOCKS], proxy.Port[ProxyScheme.SOCKS]); http = false; socks = true; } } var doc = XDocument.Load(file); var connectionElement = doc.Root.XPathSelectElement("Lib/Connection"); XElement proxyElement = null; if (http) { proxyElement = connectionElement.XPathSelectElement("HttpsProxy"); } else if (socks) { proxyElement = connectionElement.XPathSelectElement("SocksProxy"); } if (proxyElement == null) { var addrElement = new XElement("Addr", proxyUrl); var enableElement = new XElement("Enable", "1"); if (http) { connectionElement.Add(new XElement("HttpsProxy", addrElement, enableElement)); } else if (socks) { connectionElement.Add(new XElement("SocksProxy", addrElement, enableElement)); } } else { var addr = proxyElement.Element("Addr"); addr.SetValue(proxyUrl); var enabl = proxyElement.Element("Enable"); enabl.SetValue("1"); } doc.Save(file); }
public abstract void Activate(ProxyEntry proxy, Guid networkId);
/// <summary> /// Should throw a ProxyValidationException on error. /// </summary> /// <param name="proxy"></param> public virtual void ValidateEntry(ProxyEntry proxy) { }
public abstract void Activate(ProxyEntry proxy, Guid networkId);
public void SetProxyEntryToSettings(Guid networkId, ProxyEntry proxy) { string nwId = networkId.ToString(); this.Settings.Remove(nwId + "_Url_" + ProxyScheme.All.ToString()); this.Settings.Remove(nwId + "_Port_" + ProxyScheme.All.ToString()); foreach (var key in proxy.Url.Keys) { this.Settings[nwId + "_Url_" + key.ToString()] = proxy.Url[key]; this.Settings[nwId + "_Port_" + key.ToString()] = proxy.Port[key].ToString(); } //remove old storage system this.Settings.Remove(nwId + "_Url"); this.Settings.Remove(nwId + "_Port"); this.Settings[nwId + "_IsAutoConf"] = proxy.IsAutoConf.ToString(); this.Settings[nwId + "_IsAutoDetect"] = proxy.IsAutoDetect.ToString(); this.Settings[nwId + "_ByPassLocal"] = proxy.ByPassLocal.ToString(); this.Settings[nwId + "_Exceptions"] = proxy.Exceptions; this.Settings[nwId + "_RequiresAuthentication"] = proxy.RequiresAuthentication.ToString(); this.Settings[nwId + "_AuthenticationUsername"] = proxy.AuthenticationUsername; this.Settings[nwId + "_AuthenticationPassword"] = Encrypt(proxy.AuthenticationPassword); OnSettingsChanged(); if (HostApplication != null) HostApplication.SetStatusText(this, ActionResources.Saved_Status); }