public ProxyClient(IProxyServer server, ISharkClient shark) { Disposed = false; Id = RandomIdGenerator.NewId(); Server = server; Shark = shark; }
/// <summary> /// Creates a new instance of the plugin manager class /// </summary> /// <param name="server"> the proxy server this plugin manager belongs to </param> public PluginManager(IProxyServer server) { Server = server; _logger = LogManager.GetLogger("Plugin Manager"); TriggerPlugin = new TriggerPlugin(_plugins); _plugins.AddRange(LoadPlugins ()); }
public HttpProxyClient(TcpClient tcp, IProxyServer server, ISharkClient shark, ILogger <HttpProxyClient> logger, IServiceProvider servicdeProvider) : base(server, shark) { ServiceProvider = servicdeProvider; Logger = logger; _client = tcp; _stream = _client.GetStream(); _request = new HttpProxyRequest(); _pipe = new Pipe(DefaultPipeOptions); _httpFailed = false; }
protected virtual void SendRequest() { //throw new NotImplementedException("Override SendRequest and implement"); WSHttpBinding binding = new WSHttpBinding(); binding.SendTimeout = new TimeSpan(1, 0, 0); binding.ReceiveTimeout = new TimeSpan(1, 0, 0); EndpointAddress address = new EndpointAddress("http://localhost:3344/ProxyServer.svc"); ChannelFactory <IProxyServer> channelFactory = new ChannelFactory <IProxyServer>(binding, address); IProxyServer service = channelFactory.CreateChannel(); _result = service.ProcessRequest(_request); EndRequest(null); }
public Socks5Client(TcpClient tcp, IProxyServer server, ISharkClient shark, ILogger <Socks5Client> logger, IConfiguration configuration, IServiceProvider servicdeProvider) : base(server, shark) { Logger = logger; ServiceProvider = servicdeProvider; _client = tcp; _stream = _client.GetStream(); _pipe = new Pipe(DefaultPipeOptions); _socksFailed = false; _udpBuffer = new byte[1500]; _lastEndpoint = new IPEndPoint(0, 0); if (!bool.TryParse(configuration["privoxy:supported"], out _supportPrivoxy)) { _supportPrivoxy = false; } }
/// <summary> /// Shows the home view. /// </summary> /// <param name="navigator">The navigator.</param> /// <param name="proxyServer">The proxy server.</param> /// <param name="socksListeningPort">The socks listening port.</param> /// <param name="minimized">if set to <c>true</c> [minimized].</param> /// <param name="firstStart">if set to <c>true</c> [first start].</param> private void ShowHome(INavigator navigator, IProxyServer proxyServer, int socksListeningPort, bool minimized, bool firstStart) { var viewModel = navigator.Show( delegate(HomeViewModel vm) { if (firstStart) { vm.CurrentView = null; } vm.ProxyServer = proxyServer; if (socksListeningPort > 0) { vm.CanSetSocksListeningPort = false; vm.SocksListeningPort = socksListeningPort; } vm.RouteUpdated += delegate { CheckUpdate(proxyServer.Routes.FirstOrDefault()); }; }); if (!minimized) { viewModel.Show = true; } }
protected override void OnStart(string[] args) { XmlConfigurator.Configure (); _server = new ProxyServer (); _server.Start (); }
private void RegisterProxyChannel() { Hashtable ht = new Hashtable(); ht["name"] = "ProxyChannel" + this.HESName; ht["port"] = this.HESPort+1000; TcpChannel channel = new TcpChannel(ht, null, null); ChannelServices.RegisterChannel(channel, false); object obj = Activator.GetObject(typeof(IProxyServer), "tcp://"+proxyIp+":"+proxyPort+"/ProxyServerService"); proxy = (IProxyServer)obj; proxy.sendServerInfo(info); }
/// <summary> /// Shows the home view. /// </summary> /// <param name="navigator">The navigator.</param> /// <param name="proxyServer">The proxy server.</param> /// <param name="socksListeningPort">The socks listening port.</param> /// <param name="minimized">if set to <c>true</c> [minimized].</param> /// <param name="firstStart">if set to <c>true</c> [first start].</param> private void ShowHome(INavigator navigator, IProxyServer proxyServer, int socksListeningPort, bool minimized, bool firstStart) { var viewModel = navigator.Show( delegate(HomeViewModel vm) { if (firstStart) vm.CurrentView = null; vm.ProxyServer = proxyServer; if (socksListeningPort > 0) { vm.CanSetSocksListeningPort = false; vm.SocksListeningPort = socksListeningPort; } vm.RouteUpdated += delegate { CheckUpdate(proxyServer.Routes.FirstOrDefault()); }; }); if (!minimized) viewModel.Show = true; }
private static void Main(string[] args) { var config = Path.Combine(AppContext.BaseDirectory, "config.yml"); var showHelp = false; var optionSet = new OptionSet() { { "c|config=", "config file path, default ${appRoot}/config.yml", (string path) => { if (!string.IsNullOrEmpty(path)) { config = Path.GetFullPath(path); } } }, { "h|help", "show this message and exit", h => showHelp = h != null } }; try { optionSet.Parse(args); if (!showHelp) { var root = Path.GetDirectoryName(AppContext.BaseDirectory); Host.CreateDefaultBuilder(args) .UseContentRoot(root) .ConfigureAppConfiguration(builder => { builder.AddInMemoryCollection(new Dictionary <string, string>() { ["appRoot"] = root, ["configRoot"] = Path.GetDirectoryName(config) }) .AddYamlFile(config, true, false); }) .ConfigureServices((context, serviceCollection) => { var configuration = context.Configuration; if (!int.TryParse(configuration["backlog"], out int backlog)) { backlog = (int)SocketOptionName.MaxConnections; } if (!Enum.TryParse <LogLevel>(configuration["logLevel"], out var logLevel)) { #if DEBUG logLevel = LogLevel.Debug; #else logLevel = LogLevel.Information; #endif } if (!ushort.TryParse(configuration["client:port"], out var localPort)) { localPort = 1080; } var localAddr = configuration["client:host"]; if (string.IsNullOrEmpty(localAddr)) { localAddr = "127.0.0.1"; } if (!Enum.TryParse <ProxyProtocol>(configuration["client:protocol"], out var protocol)) { protocol = ProxyProtocol.Socks5; } if (!ushort.TryParse(configuration["shark:port"], out var remotePort)) { remotePort = 12306; } var remoteAddr = configuration["shark:host"]; if (string.IsNullOrEmpty(remoteAddr)) { remoteAddr = "127.0.0.1"; } if (!int.TryParse(configuration["shark:max"], out var maxCount)) { maxCount = 0; } var pluginRoot = configuration["pluginRoot"]; if (string.IsNullOrEmpty(pluginRoot)) { pluginRoot = Path.Combine(AppContext.BaseDirectory, "plugins"); } serviceCollection .AddHostedService <Worker>() .AddOptions() .Configure <BindingOptions>(option => { option.EndPoint = new IPEndPoint(IPAddress.Parse(localAddr), localPort); option.Backlog = backlog; }) .Configure <ProxyRemoteOptions>(options => { options.Remote = new HostData() { Address = remoteAddr, Port = remotePort, }; options.MaxClientCount = maxCount; }) .Configure <GenericOptions <ICryptor> >(options => { options.Name = configuration["shark:crypto"]; }) .Configure <GenericOptions <IKeyGenerator> >(options => { options.Name = configuration["shark:keygen"]; }) .Configure <GenericOptions <IAuthenticator> >(options => { options.Name = configuration["shark:auth"]; }) .AddLogging(builder => { builder.AddConsole(); builder.SetMinimumLevel(logLevel); }) .AddScoped <ISharkClient, SharkClient>() .AddTransient(provider => { IProxyServer server = null; switch (protocol) { case ProxyProtocol.Socks5: server = ActivatorUtilities.CreateInstance <Socks5Server>(provider); break; case ProxyProtocol.Http: server = ActivatorUtilities.CreateInstance <HttpProxyServer>(provider); break; default: break; } return(server); }); new PluginLoader(pluginRoot).Load(serviceCollection, configuration); }).Build().Run(); } else { optionSet.WriteOptionDescriptions(Console.Out); } } catch (OptionException e) { Console.WriteLine(e.Message); optionSet.WriteOptionDescriptions(Console.Out); } }
public Task AddProxyServer(IProxyServer proxyServer) { _proxyServerDict[proxyServer.Id] = proxyServer; return(proxyServer.Start()); }