Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoding121 committed Oct 11, 2015
1 parent 887add6 commit e332c90
Show file tree
Hide file tree
Showing 23 changed files with 590 additions and 685 deletions.
1 change: 1 addition & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
Expand Down
3 changes: 2 additions & 1 deletion Titanium.Web.Proxy.Test/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>
</configuration>
53 changes: 23 additions & 30 deletions Titanium.Web.Proxy.Test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,79 +1,72 @@
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;
using Titanium.Web.Proxy.Helpers;

namespace Titanium.Web.Proxy.Test
{
public class Program
{
static ProxyTestController controller = new ProxyTestController();
private static readonly ProxyTestController Controller = new ProxyTestController();

public static void Main(string[] args)
{
//On Console exit make sure we also exit the proxy
NativeMethods.handler = new NativeMethods.ConsoleEventDelegate(ConsoleEventCallback);
NativeMethods.SetConsoleCtrlHandler(NativeMethods.handler, true);

NativeMethods.Handler = ConsoleEventCallback;
NativeMethods.SetConsoleCtrlHandler(NativeMethods.Handler, true);


Console.Write("Do you want to monitor HTTPS? (Y/N):");

if (Console.ReadLine().Trim().ToLower() == "y")
var readLine = Console.ReadLine();
if (readLine != null && readLine.Trim().ToLower() == "y")
{
controller.EnableSSL = true;

Controller.EnableSsl = true;
}

Console.Write("Do you want to set this as a System Proxy? (Y/N):");

if (Console.ReadLine().Trim().ToLower() == "y")
var line = Console.ReadLine();
if (line != null && line.Trim().ToLower() == "y")
{
controller.SetAsSystemProxy = true;

Controller.SetAsSystemProxy = true;
}

//Start proxy controller
controller.StartProxy();
Controller.StartProxy();

Console.WriteLine("Hit any key to exit..");
Console.WriteLine();
Console.Read();

controller.Stop();
Controller.Stop();
}


static bool ConsoleEventCallback(int eventType)
private static bool ConsoleEventCallback(int eventType)
{
if (eventType == 2)
{
try
{
controller.Stop();

Controller.Stop();
}
catch
{
// ignored
}
catch { }
}
return false;
}

}

internal static class NativeMethods
{
// Keeps it from getting garbage collected
internal static ConsoleEventDelegate Handler;

[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);

// Pinvoke
internal delegate bool ConsoleEventDelegate(int eventType);


// Keeps it from getting garbage collected
internal static ConsoleEventDelegate handler;
}

}
}
7 changes: 5 additions & 2 deletions Titanium.Web.Proxy.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

[assembly: AssemblyTitle("Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
Expand All @@ -17,9 +17,11 @@
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.

[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM

[assembly: Guid("33a2109d-0312-4c94-aa51-fbb2a83e63ab")]

// Version information for an assembly consists of the following four values:
Expand All @@ -32,5 +34,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
33 changes: 7 additions & 26 deletions Titanium.Web.Proxy.Test/ProxyTestController.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.DirectoryServices.AccountManagement;
using System.DirectoryServices.ActiveDirectory;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy;
using Titanium.Web.Proxy.Helpers;



namespace Titanium.Web.Proxy.Test
{
public partial class ProxyTestController
public class ProxyTestController
{

public int ListeningPort { get; set; }
public bool EnableSSL { get; set; }
public bool EnableSsl { get; set; }
public bool SetAsSystemProxy { get; set; }

public void StartProxy()
{

ProxyServer.BeforeRequest += OnRequest;
ProxyServer.BeforeResponse += OnResponse;

ProxyServer.EnableSSL = EnableSSL;
ProxyServer.EnableSsl = EnableSsl;

ProxyServer.SetAsSystemProxy = SetAsSystemProxy;

Expand All @@ -40,9 +27,9 @@ public void StartProxy()

ProxyServer.ListeningPort = ProxyServer.ListeningPort;

Console.WriteLine(String.Format("Proxy listening on local machine port: {0} ", ProxyServer.ListeningPort));

Console.WriteLine("Proxy listening on local machine port: {0} ", ProxyServer.ListeningPort);
}

public void Stop()
{
ProxyServer.BeforeRequest -= OnRequest;
Expand All @@ -52,13 +39,11 @@ public void Stop()
}



//Test On Request, intecept requests
//Read browser URL send back to proxy by the injection script in OnResponse event
public void OnRequest(object sender, SessionEventArgs e)
{

Console.WriteLine(e.RequestURL);
Console.WriteLine(e.RequestUrl);

////read request headers
//var requestHeaders = e.RequestHeaders;
Expand All @@ -82,7 +67,6 @@ public void OnRequest(object sender, SessionEventArgs e)
//{
// e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
//}

}

//Test script injection
Expand Down Expand Up @@ -112,9 +96,6 @@ public void OnResponse(object sender, SessionEventArgs e)
// e.SetResponseBodyString(modified);
// }
//}

}

}

}
}
Loading

0 comments on commit e332c90

Please sign in to comment.