Commit 7f9d8862 authored by justcoding121's avatar justcoding121 Committed by justcoding121

Enable Startup proxy change

Use proxy on launch as system HTTP proxy, enable HTTPS certificate
installation prompt; reset system proxy on exit
parent d2975b45
...@@ -10,7 +10,7 @@ Features ...@@ -10,7 +10,7 @@ Features
* Supports relaying of WebSockets * Supports relaying of WebSockets
* Supports script injection * Supports script injection
* Async using HTTPWebRequest class for better performance * Async using HTTPWebRequest class for better performance
* Simple and easy to read
Usage Usage
===== =====
...@@ -20,5 +20,4 @@ Refer the HTTP Proxy Server library in your project, look up sample project to l ...@@ -20,5 +20,4 @@ Refer the HTTP Proxy Server library in your project, look up sample project to l
Future updates Future updates
============ ============
* Cleanup code for better readability * Cleanup code for better readability
* Change system proxy settings to use our proxy on startup/stop
* Support HTTP 2.0 Once spec is ready * Support HTTP 2.0 Once spec is ready
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Security.Principal;
namespace Titanium.HTTPProxyServer
{
public class CredentialManager
{
public static Dictionary<string, WindowsPrincipal> Cache { get; set; }
}
}
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
using System.Text; using System.Text;
using System.IO; using System.IO;
using System.Net; using System.Net;
using HTTPProxyServer.Utility;
namespace HTTPProxyServer
namespace Titanium.HTTPProxyServer
{ {
public class SessionEventArgs : EventArgs public class SessionEventArgs : EventArgs
{ {
......
...@@ -4,7 +4,7 @@ using System.Linq; ...@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.IO; using System.IO;
namespace HTTPProxyServer.Utility namespace Titanium.HTTPProxyServer
{ {
public static class StreamUtilities public static class StreamUtilities
{ {
......
...@@ -9,12 +9,13 @@ using System.Net.Security; ...@@ -9,12 +9,13 @@ using System.Net.Security;
using System.Security.Authentication; using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Diagnostics; using System.Diagnostics;
using Titanium.HTTPProxyServer;
namespace HTTPProxyServer namespace Titanium.HTTPProxyServer
{ {
/// <summary>
/// Proxy Server Main class
/// </summary>
public partial class ProxyServer public partial class ProxyServer
{ {
...@@ -96,13 +97,11 @@ namespace HTTPProxyServer ...@@ -96,13 +97,11 @@ namespace HTTPProxyServer
private void Listen(Object obj) private void Listen(Object obj)
{ {
TcpListener listener = (TcpListener)obj; TcpListener listener = (TcpListener)obj;
CredentialManager.Cache = new Dictionary<string, System.Security.Principal.WindowsPrincipal>();
try try
{ {
while (true) while (true)
{ {
TcpClient client = listener.AcceptTcpClient(); TcpClient client = listener.AcceptTcpClient();
while (!ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(ProcessClient), client)) ; while (!ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(ProcessClient), client)) ;
} }
......
...@@ -6,7 +6,7 @@ using System.IO; ...@@ -6,7 +6,7 @@ using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.Net; using System.Net;
namespace HTTPProxyServer namespace Titanium.HTTPProxyServer
{ {
public partial class ProxyServer public partial class ProxyServer
{ {
......
...@@ -9,13 +9,12 @@ using System.Net.Security; ...@@ -9,13 +9,12 @@ using System.Net.Security;
using System.Security.Authentication; using System.Security.Authentication;
using System.Net.Sockets; using System.Net.Sockets;
using System.Diagnostics; using System.Diagnostics;
using HTTPProxyServer.Utility;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Reflection; using System.Reflection;
using Titanium.HTTPProxyServer;
namespace HTTPProxyServer
namespace Titanium.HTTPProxyServer
{ {
partial class ProxyServer partial class ProxyServer
...@@ -39,9 +38,6 @@ namespace HTTPProxyServer ...@@ -39,9 +38,6 @@ namespace HTTPProxyServer
ConnectionGroup = Dns.GetHostEntry(((IPEndPoint)client.Client.RemoteEndPoint).Address).HostName; ConnectionGroup = Dns.GetHostEntry(((IPEndPoint)client.Client.RemoteEndPoint).Address).HostName;
if (CredentialManager.Cache.ContainsKey(ConnectionGroup))
Thread.CurrentPrincipal = CredentialManager.Cache.First().Value;
clientStream = client.GetStream(); clientStream = client.GetStream();
clientStreamReader = new CustomBinaryReader(clientStream, Encoding.ASCII); clientStreamReader = new CustomBinaryReader(clientStream, Encoding.ASCII);
string securehost = null; string securehost = null;
......
...@@ -10,7 +10,7 @@ using System.Threading; ...@@ -10,7 +10,7 @@ using System.Threading;
using System.Security.Authentication; using System.Security.Authentication;
using System.Diagnostics; using System.Diagnostics;
namespace HTTPProxyServer namespace Titanium.HTTPProxyServer
{ {
partial class ProxyServer partial class ProxyServer
{ {
......
...@@ -74,18 +74,17 @@ ...@@ -74,18 +74,17 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CredentialManager.cs" /> <Compile Include="Request\RequestHandler.cs" />
<Compile Include="RequestHandler.cs" /> <Compile Include="Request\RequestManager.cs" />
<Compile Include="RequestManager.cs" /> <Compile Include="Response\ResponseManager.cs" />
<Compile Include="ResponseManager.cs" /> <Compile Include="Utility\CertificateUtility.cs" />
<Compile Include="Utility\CertificateUtils.cs" />
<Compile Include="Utility\CustomBinaryReader.cs" /> <Compile Include="Utility\CustomBinaryReader.cs" />
<Compile Include="Utility\OtherUtils.cs" /> <Compile Include="Utility\GeneralUtility.cs" />
<Compile Include="Compression\EncodeCompressionUtils.cs" /> <Compile Include="Utility\CompressionUtility.cs" />
<Compile Include="ProxyServer.cs" /> <Compile Include="ProxyServer.cs" />
<Compile Include="EventArgs\SessionEventArgs.cs" /> <Compile Include="EventArgs\SessionEventArgs.cs" />
<Compile Include="Utility\RawTCPRelay.cs" /> <Compile Include="Utility\RawTCPRelay.cs" />
<Compile Include="Utility\StreamExtensions.cs" /> <Compile Include="Extensions\StreamExtensions.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Properties\" /> <Folder Include="Properties\" />
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
\ No newline at end of file
...@@ -3,7 +3,7 @@ using System.Security.Cryptography.X509Certificates; ...@@ -3,7 +3,7 @@ using System.Security.Cryptography.X509Certificates;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
namespace HTTPProxyServer namespace Titanium.HTTPProxyServer
{ {
public partial class ProxyServer public partial class ProxyServer
{ {
......
...@@ -4,7 +4,7 @@ using System.Linq; ...@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.IO; using System.IO;
namespace HTTPProxyServer namespace Titanium.HTTPProxyServer
{ {
public partial class ProxyServer public partial class ProxyServer
{ {
......
...@@ -5,7 +5,7 @@ using System.Text; ...@@ -5,7 +5,7 @@ using System.Text;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
namespace HTTPProxyServer.Utility namespace Titanium.HTTPProxyServer
{ {
public class CustomBinaryReader : BinaryReader public class CustomBinaryReader : BinaryReader
{ {
......
...@@ -3,10 +3,9 @@ using System.Collections.Generic; ...@@ -3,10 +3,9 @@ using System.Collections.Generic;
using System.Net; using System.Net;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using HTTPProxyServer.Utility;
using System.Linq; using System.Linq;
namespace HTTPProxyServer namespace Titanium.HTTPProxyServer
{ {
public partial class ProxyServer public partial class ProxyServer
{ {
......
...@@ -3,12 +3,11 @@ using System.Collections.Generic; ...@@ -3,12 +3,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using HTTPProxyServer.Utility;
using System.Net.Security; using System.Net.Security;
using System.IO; using System.IO;
using System.Net; using System.Net;
namespace HTTPProxyServer namespace Titanium.HTTPProxyServer
{ {
public partial class ProxyServer public partial class ProxyServer
{ {
......
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013 # Visual Studio 2013
VisualStudioVersion = 12.0.30501.0 VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Library", "Library", "{B6DBABDC-C985-4872-9C38-B4E5079CBC4B}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B6DBABDC-C985-4872-9C38-B4E5079CBC4B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.HTTPProxyServer", "Titanium.HTTPProxyServer\Titanium.HTTPProxyServer.csproj", "{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.HTTPProxyServer", "Titanium.HTTPProxyServer\Titanium.HTTPProxyServer.csproj", "{8D73A1BE-868C-42D2-9ECE-F32CC1A02906}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.ProxyTest", "Titanium.ProxyTest\Titanium.ProxyTest.csproj", "{F3B7E553-1904-4E80-BDC7-212342B5C952}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.Proxy.Test", "Titanium.ProxyTest\Titanium.Proxy.Test.csproj", "{F3B7E553-1904-4E80-BDC7-212342B5C952}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -57,7 +57,7 @@ Global ...@@ -57,7 +57,7 @@ Global
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{8D73A1BE-868C-42D2-9ECE-F32CC1A02906} = {B6DBABDC-C985-4872-9C38-B4E5079CBC4B} {F3B7E553-1904-4E80-BDC7-212342B5C952} = {B6DBABDC-C985-4872-9C38-B4E5079CBC4B}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35 EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace Titanium.HTTPProxyServer.Test
{
public class Program
{
public static void Main(string[] args)
{
//On Console exit reset system proxy
handler = new ConsoleEventDelegate(ConsoleEventCallback);
SetConsoleCtrlHandler(handler, true);
//Start proxy controller
var controller = new ProxyTestController();
controller.StartProxy();
controller.Visited += PageVisited;
Console.WriteLine("Do you want to monitor HTTPS? (Y/N)");
if(Console.ReadLine().Trim().ToLower()=="y" )
{
InstallCertificate(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
SystemProxyUtility.EnableProxyHTTPS("localhost", controller.ListeningPort);
}
Console.WriteLine("Hit any key to exit");
Console.Read();
//Reset System Proxy on exit
SystemProxyUtility.DisableAllProxy();
FireFoxUtility.RemoveFirefox();
controller.Stop();
}
private static void InstallCertificate(string cerDirectory)
{
X509Certificate2 certificate = new X509Certificate2(Path.Combine(cerDirectory , "Titanium Proxy Test Root Certificate.cer"));
X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
store.Add(certificate);
store.Close();
X509Store store1 = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store1.Open(OpenFlags.ReadWrite);
store1.Add(certificate);
store1.Close();
}
private static void PageVisited(VisitedEventArgs e)
{
Console.WriteLine(string.Concat("Visited:", e.URL));
}
static bool ConsoleEventCallback(int eventType)
{
if (eventType == 2)
{
try
{
SystemProxyUtility.DisableAllProxy();
FireFoxUtility.RemoveFirefox();
}
catch { }
}
return false;
}
// Keeps it from getting garbage collected
static ConsoleEventDelegate handler;
// Pinvoke
private delegate bool ConsoleEventDelegate(int eventType);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
}
}
...@@ -3,42 +3,38 @@ using System.Collections.Generic; ...@@ -3,42 +3,38 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Net; using System.Net;
using Titanium.ProxyManager.Utitlity;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Titanium.ProxyManager;
using System.DirectoryServices.AccountManagement; using System.DirectoryServices.AccountManagement;
using System.DirectoryServices.ActiveDirectory; using System.DirectoryServices.ActiveDirectory;
using HTTPProxyServer; using Titanium;
using Titanium.HTTPProxyServer;
namespace Titanium.Proxy namespace Titanium.HTTPProxyServer.Test
{ {
public partial class Controller public partial class ProxyTestController
{ {
private List<string> _URLList = new List<string>(); private List<string> _URLList = new List<string>();
private string _lastURL = string.Empty; private string _lastURL = string.Empty;
private ProxyServer _server; private ProxyServer _server;
public static void Main(string[] args) public int ListeningPort { get; set; }
{
var controller = new Controller();
controller.StartProxy();
Console.WriteLine("To make Http(s) work install the test root certificate included in this project to both Personal and Trusted Root Certificate Authorities of client machine");
Console.WriteLine("Hit any key to exit");
Console.Read();
controller.Stop();
}
public void StartProxy() public void StartProxy()
{ {
_server = new ProxyServer(); _server = new ProxyServer();
_server.BeforeRequest += OnRequest; _server.BeforeRequest += OnRequest;
_server.BeforeResponse += OnResponse; _server.BeforeResponse += OnResponse;
_server.Start(); _server.Start();
SystemProxyUtility.EnableProxyHTTP("localhost", _server.ListeningPort);
FireFoxUtility.AddFirefox();
ListeningPort = _server.ListeningPort;
Console.WriteLine(String.Format("Proxy listening on local machine port: {0} ", _server.ListeningPort)); Console.WriteLine(String.Format("Proxy listening on local machine port: {0} ", _server.ListeningPort));
} }
...@@ -153,8 +149,6 @@ namespace Titanium.Proxy ...@@ -153,8 +149,6 @@ namespace Titanium.Proxy
} }
private Random random = new Random((int)DateTime.Now.Ticks); private Random random = new Random((int)DateTime.Now.Ticks);
private string RandomString(int size) private string RandomString(int size)
{ {
......
...@@ -51,21 +51,22 @@ ...@@ -51,21 +51,22 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Controller.cs" /> <Compile Include="ProxyTestController.cs" />
<Compile Include="Utility\ProcessDetails.cs" /> <Compile Include="Utility\Firefox.cs" />
<Compile Include="Utility\SystemProxyUtility.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="makecert.exe"> <Content Include="makecert.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="unity.debug.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
<None Include="Titanium Proxy Test Root Certificate.cer" /> <None Include="Titanium Proxy Test Root Certificate.cer">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Titanium.HTTPProxyServer\Titanium.HTTPProxyServer.csproj"> <ProjectReference Include="..\Titanium.HTTPProxyServer\Titanium.HTTPProxyServer.csproj">
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView> <ProjectView>ProjectFiles</ProjectView>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Titanium.HTTPProxyServer.Test
{
public class FireFoxUtility
{
public static void AddFirefox()
{
try
{
DirectoryInfo[] myProfileDirectory = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Mozilla\\Firefox\\Profiles\\").GetDirectories("*.default");
string myFFPrefFile = myProfileDirectory[0].FullName + "\\prefs.js";
if (File.Exists(myFFPrefFile))
{
// We have a pref file so let''s make sure it has the proxy setting
StreamReader myReader = new StreamReader(myFFPrefFile);
string myPrefContents = myReader.ReadToEnd();
myReader.Close();
if (myPrefContents.Contains("user_pref(\"network.proxy.type\", 0);"))
{
// Add the proxy enable line and write it back to the file
myPrefContents = myPrefContents.Replace("user_pref(\"network.proxy.type\", 0);", "");
File.Delete(myFFPrefFile);
File.WriteAllText(myFFPrefFile, myPrefContents);
}
}
}
catch (Exception)
{
// Only exception should be a read/write error because the user opened up FireFox so they can be ignored.
}
}
public static void RemoveFirefox()
{
try
{
DirectoryInfo[] myProfileDirectory = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Mozilla\\Firefox\\Profiles\\").GetDirectories("*.default");
string myFFPrefFile = myProfileDirectory[0].FullName + "\\prefs.js";
if (File.Exists(myFFPrefFile))
{
// We have a pref file so let''s make sure it has the proxy setting
StreamReader myReader = new StreamReader(myFFPrefFile);
string myPrefContents = myReader.ReadToEnd();
myReader.Close();
if (!myPrefContents.Contains("user_pref(\"network.proxy.type\", 0);"))
{
// Add the proxy enable line and write it back to the file
myPrefContents = myPrefContents + "\n\r" + "user_pref(\"network.proxy.type\", 0);";
File.Delete(myFFPrefFile);
File.WriteAllText(myFFPrefFile, myPrefContents);
}
}
}
catch (Exception)
{
// Only exception should be a read/write error because the user opened up FireFox so they can be ignored.
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Diagnostics;
namespace Titanium.ProxyManager.Utitlity
{
public class TcpHelperUtil
{
private const short MINIMUM_TOKEN_IN_A_LINE = 5;
private const string COMMAND_EXE = @"cmd.exe";
public static int GetProcessId(int port)
{
try
{
// execute netstat command for the given port
string commandArgument = string.Format("/c netstat -an -o -p tcp|findstr \":{0}.*ESTABLISHED", port);
string commandOut = ExecuteCommandAndCaptureOutput(COMMAND_EXE, commandArgument);
if (string.IsNullOrEmpty(commandOut))
{
// port is not in use
return 0;
}
string[] stringTokens = commandOut.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);
if (stringTokens.Length < MINIMUM_TOKEN_IN_A_LINE)
{
return 0;
}
if (stringTokens.Length == 10)
return int.Parse(stringTokens[9].Trim());
else
return 0;
}
catch { return 0; }
}
/// <summary>
/// Execute the given command and captures the output
/// </summary>
/// <param name="commandName"></param>
/// <param name="arguments"></param>
/// <returns></returns>
private static string ExecuteCommandAndCaptureOutput(string commandName, string arguments)
{
string commandOut = string.Empty;
Process process = new Process();
process.StartInfo.FileName = commandName;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
commandOut = process.StandardOutput.ReadToEnd();
string errors = process.StandardError.ReadToEnd();
try
{
process.WaitForExit(TimeSpan.FromSeconds(2).Milliseconds);
}
catch
{
}
return commandOut;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;
namespace Titanium.HTTPProxyServer.Test
{
public static class SystemProxyUtility
{
[DllImport("wininet.dll")]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
public const int INTERNET_OPTION_SETTINGS_CHANGED = 39;
public const int INTERNET_OPTION_REFRESH = 37;
static bool settingsReturn, refreshReturn;
static object prevProxyServer;
static object prevProxyEnable;
public static void EnableProxyHTTP(string hostname, int port)
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
prevProxyEnable = reg.GetValue("ProxyEnable");
prevProxyServer = reg.GetValue("ProxyServer");
reg.SetValue("ProxyEnable", 1);
reg.SetValue("ProxyServer", "http="+hostname+":" + port + ";");
refresh();
}
public static void EnableProxyHTTPS(string hostname, int port)
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
reg.SetValue("ProxyEnable", 1);
reg.SetValue("ProxyServer", "http=" + hostname + ":" + port + ";https=" + hostname + ":" + port);
refresh();
}
public static void DisableAllProxy()
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
reg.SetValue("ProxyEnable", prevProxyEnable);
if (prevProxyServer != null)
reg.SetValue("ProxyServer", prevProxyServer);
refresh();
}
private static void refresh()
{
settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="SqlCELogConnectionString" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=Log.sdf" />
<add name="SqlCEEventsConnectionString" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=Events.sdf" />
<add name="SqlCEFilesConnectionString" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=Files.sdf" />
<add name="SqlServerLogConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASXLog;Integrated Security=True;Enlist=False;" providerName="System.Data.SqlClient" />
<add name="SqlServerEventsConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASXEvents;Integrated Security=True;Enlist=False;" providerName="System.Data.SqlClient" />
<add name="SqlServerFilesConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASXFiles;Integrated Security=True;Enlist=False;" providerName="System.Data.SqlClient" />
<add name="SqlServerSettingsConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASXSettings;Integrated Security=True;Enlist=False;" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<unity configSource="unity.debug.xml" />
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" /></startup></configuration>
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\Titanium.ProxyManager.exe.config
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\makecert.exe
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\unity.debug.xml
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\Titanium.ProxyManager.exe
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\Titanium.ProxyManager.pdb
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\Titanium.HTTPProxyServer.dll
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\Ionic.Zip.dll
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\Titanium.HTTPProxyServer.pdb
C:\CodeRepository\Titanium\Titanium.ProxyTest\bin\Debug\Ionic.Zip.xml
C:\CodeRepository\Titanium\Titanium.ProxyTest\obj\Debug\Titanium.ProxyTest.csprojResolveAssemblyReference.cache
C:\CodeRepository\Titanium\Titanium.ProxyTest\obj\Debug\Titanium.ProxyManager.exe
C:\CodeRepository\Titanium\Titanium.ProxyTest\obj\Debug\Titanium.ProxyManager.pdb
<?xml version="1.0" encoding="utf-8" ?>
<unity>
<assembly name="Titanium.Interfaces"/>
<assembly name="Titanium.Data.Repository"/>
<containers>
<container>
<types>
<type type ="Titanium.Interfaces.Repository.ILogRepository,Titanium.Interfaces" mapTo="Titanium.Data.Repository.SqlServer.SqlServerLogRepository,Titanium.Data.Repository" />
<type type ="Titanium.Interfaces.Repository.IEventsRepository,Titanium.Interfaces" mapTo="Titanium.Data.Repository.SqlServer.SqlServerEventsRepository,Titanium.Data.Repository" />
<type type ="Titanium.Interfaces.Repository.ISettingsRepository,Titanium.Interfaces" mapTo="Titanium.Data.Repository.SqlServer.SqlServerSettingsRepository,Titanium.Data.Repository" />
</types>
</container>
</containers>
</unity>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment