From 35de32ea2d272753a412ed8832d9d3748936b661 Mon Sep 17 00:00:00 2001 From: Cristian Pufu Date: Sat, 24 Aug 2024 16:51:25 +0300 Subject: [PATCH] Add index.html --- .../HttpTunnel/HttpAppExtensions.cs | 40 ++- src/Tunnelite.Server/wwwroot/index.html | 263 ++++++++++++++++++ 2 files changed, 297 insertions(+), 6 deletions(-) create mode 100644 src/Tunnelite.Server/wwwroot/index.html diff --git a/src/Tunnelite.Server/HttpTunnel/HttpAppExtensions.cs b/src/Tunnelite.Server/HttpTunnel/HttpAppExtensions.cs index f4448d0..9964988 100644 --- a/src/Tunnelite.Server/HttpTunnel/HttpAppExtensions.cs +++ b/src/Tunnelite.Server/HttpTunnel/HttpAppExtensions.cs @@ -31,6 +31,13 @@ public static void UseHttpTunneling(this WebApplication app) } else { + // reserved + if (payload.Subdomain.Equals("localhost", StringComparison.OrdinalIgnoreCase) || + payload.Subdomain.Equals("tunnelite", StringComparison.OrdinalIgnoreCase)) + { + payload.Subdomain = RandomSubdomain(); + } + // don't hijack existing subdomain from another client if (tunnelStore.Tunnels.TryGetValue(payload.Subdomain, out var tunnel)) { @@ -48,7 +55,18 @@ public static void UseHttpTunneling(this WebApplication app) tunnelStore.Tunnels.AddOrUpdate(payload.Subdomain, payload, (key, oldValue) => payload); tunnelStore.Clients.AddOrUpdate(payload.ClientId, payload.Subdomain, (key, oldValue) => payload.Subdomain); - var tunnelUrl = $"{context.Request.Scheme}://{payload.Subdomain}.{context.Request.Host}{context.Request.PathBase}"; + var subdomain = context.Request.Host.Host.Split('.')[0]; + + var tunnelUrl = string.Empty; + + if (subdomain.Equals("localhost", StringComparison.OrdinalIgnoreCase)) + { + tunnelUrl = $"{context.Request.Scheme}://{context.Request.Host}{context.Request.PathBase}"; + } + else + { + tunnelUrl = $"{context.Request.Scheme}://{payload.Subdomain}.{context.Request.Host}{context.Request.PathBase}"; + } context.Response.StatusCode = StatusCodes.Status201Created; await context.Response.WriteAsJsonAsync(new @@ -222,18 +240,18 @@ await context.Response.WriteAsJsonAsync(new pattern: "/", httpMethods: supportedMethods, handler: (HttpContext context, IHubContext hubContext, HttpRequestsQueue requestsQueue, HttpTunnelStore connectionStore, ILogger logger) => - TunnelRequestAsync(context, hubContext, requestsQueue, connectionStore, path: string.Empty, logger)); + TunnelRequestAsync(app, context, hubContext, requestsQueue, connectionStore, path: string.Empty, logger)); app.MapMethods( pattern: "/{**path}", httpMethods: supportedMethods, handler: (HttpContext context, IHubContext hubContext, HttpRequestsQueue requestsQueue, HttpTunnelStore connectionStore, string path, ILogger logger) => - TunnelRequestAsync(context, hubContext, requestsQueue, connectionStore, path, logger)); + TunnelRequestAsync(app, context, hubContext, requestsQueue, connectionStore, path, logger)); app.MapHub("/wsshttptunnel"); } - static async Task TunnelRequestAsync(HttpContext context, IHubContext hubContext, HttpRequestsQueue requestsQueue, HttpTunnelStore tunnelStore, string path, ILogger logger) + static async Task TunnelRequestAsync(WebApplication app, HttpContext context, IHubContext hubContext, HttpRequestsQueue requestsQueue, HttpTunnelStore tunnelStore, string path, ILogger logger) { try { @@ -247,8 +265,18 @@ static async Task TunnelRequestAsync(HttpContext context, IHubContext + + + + + Tunnelite - Secure Local Tunneling Solution | ngrok alternative + + + + + + +
+ +
+ +
+
+

Tunnelite

+

Secure tunneling to your local applications

+ Get Started +

Open-source and free to use

+ View on GitHub +
+ +
+
+

Expose Local Apps

+

Share your locally-hosted web applications for testing or demos.

+
+
+

Test Webhooks

+

Easily test and debug webhook integrations by exposing your local endpoints to the internet.

+
+
+

Hackathon Ready

+

Quickly share dev builds during hackathons and collaborative coding sessions.

+
+
+

Secure Access

+

Provide internet access to services behind firewalls without exposing incoming ports.

+
+
+ +
+

Installation

+

To install Tunnelite as a global tool, use the following command:

+

.NET CLI

+
dotnet tool install --global Tunnelite
+ +

NUKE

+
nuke :add-package Tunnelite
+ +

Cake

+
#tool dotnet:?package=Tunnelite
+ +
+ +
+

Usage

+

Once installed, you can use the tunnelite command to create a tunnel to your local application.

+
tunnelite http://localhost:3000
+ +

This command returns a public URL with an auto-generated subdomain.

+
+ +
+

Self-Hosting

+

Tunnelite allows you to self-host the server, giving you full control over your tunneling infrastructure. This feature is perfect for organizations that require enhanced security or customization.

+

To self-host Tunnelite:

+
    +
  1. Clone the repository
  2. +
  3. Configure your app server settings
  4. +
  5. Deploy the app server on your own infrastructure
  6. +
+

Once your self-hosted server is set up, you can connect to it using the following command:

+
tunnelite http://localhost:3000 --publicUrl yourServerUrl
+ + +

Requirements

+

To successfully self-host Tunnelite, you'll need:

+
    +
  • SSL wildcard certificate for your domain
  • +
  • Wildcard DNS record pointing to your server's IP address
  • +
+

These requirements ensure that Tunnelite can generate secure subdomains for your tunnels and route traffic correctly to your self-hosted server.

+
+
+ + + +
Copied to clipboard!
+ + + + \ No newline at end of file