diff --git a/TraceRoute/Components/App.razor b/TraceRoute/Components/App.razor index 8b7528c..4294267 100644 --- a/TraceRoute/Components/App.razor +++ b/TraceRoute/Components/App.razor @@ -4,7 +4,7 @@ - TODO: TITLE - TraceRoute + TraceRoute diff --git a/TraceRoute/Controllers/APIController.cs b/TraceRoute/Controllers/APIController.cs index f145d0a..feb53e1 100644 --- a/TraceRoute/Controllers/APIController.cs +++ b/TraceRoute/Controllers/APIController.cs @@ -48,7 +48,8 @@ public class APIController(ILoggerFactory LoggerFactory, ServerListService serve [HttpPost("api/presence")] public async Task ReceivePresence([FromBody] ServerEntry server) { - _logger.LogInformation("Received presence from: {0}", server.url); + _logger.LogInformation("Received presence from: {0}, public IP: {1}", server.url, + Request.HttpContext.Connection.RemoteIpAddress!.ToString()); ServerEntry? checkInfo = await _serverListService.GetRemoteServerInfo(server); if (checkInfo != null && checkInfo.Equals(server)) diff --git a/TraceRoute/Dockerfile b/TraceRoute/Dockerfile index b72fe42..dace422 100644 --- a/TraceRoute/Dockerfile +++ b/TraceRoute/Dockerfile @@ -39,5 +39,6 @@ RUN dotnet publish "./TraceRoute.csproj" -c $BUILD_CONFIGURATION -o /app/publish FROM base AS final WORKDIR /app ENV ASPNETCORE_URLS=http://+:80 +ENV ASPNETCORE_HTTP_PORTS=80 COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "TraceRoute.dll"] \ No newline at end of file diff --git a/TraceRoute/Program.cs b/TraceRoute/Program.cs index fbf56d0..1061c3f 100644 --- a/TraceRoute/Program.cs +++ b/TraceRoute/Program.cs @@ -1,9 +1,10 @@ -using System.IO.Compression; -using System.Runtime.CompilerServices; -using Blazored.Toast; +using Blazored.Toast; using log4net; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.ResponseCompression; +using System.IO.Compression; +using System.Net; +using System.Runtime.CompilerServices; using TraceRoute.Components; using TraceRoute.Helpers; using TraceRoute.Services; @@ -13,12 +14,10 @@ var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseIISIntegration(); //Optional for IIS deployment +builder.Services.AddControllersWithViews(); builder.Services.AddRazorComponents().AddInteractiveServerComponents(); builder.Services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; }); ; builder.Services.AddRazorPages(); - -//builder.Services.AddRazorPages(); -builder.Services.AddControllersWithViews(); builder.Services.AddSingleton(); builder.Services.AddHttpClient(); builder.Services.AddHttpClient(); @@ -32,12 +31,6 @@ builder.Services.AddHostedService(provider => provider.GetRequiredService()); builder.Services.AddBlazoredToast(); -//Forward headers configuration for reverse proxy -builder.Services.Configure(options => { - options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; - options.KnownNetworks.Clear(); - options.KnownProxies.Clear(); -}); //WebMarkupMin builder.Services.AddWebMarkupMin( options => @@ -86,11 +79,6 @@ options.Level = CompressionLevel.Optimal; }); -//Forwardedfor -builder.Services.Configure(options => -{ - options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; -}); //Cors allow all (required for remote traces) builder.Services.AddCors(o => o.AddPolicy("AllowAll", builder => { @@ -109,9 +97,10 @@ app.UseAntiforgery(); app.MapRazorComponents().AddInteractiveServerRenderMode(); app.MapRazorPages(); +app.MapControllers(); // app.MapBlazorHub(); - app.UseMiddleware(); +app.UseStatusCodePages(); //Cors allow all (required for remote traces) app.UseCors("AllowAll"); @@ -119,8 +108,12 @@ // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment() || true) { - app.UseStatusCodePagesWithReExecute("/Error", "?statusCode={0}"); - app.UseExceptionHandler("/Error"); + app.UseStatusCodePagesWithReExecute("/error", "?statusCode={0}"); + app.UseExceptionHandler(new ExceptionHandlerOptions() + { + AllowStatusCode404Response = true, + ExceptionHandlingPath = "/error" + }); app.UseHsts(); } @@ -149,8 +142,7 @@ r.Context.Response.Headers.Append("Cache-Control", "max-age=31536000"); } } - } - ); + }); //I record the starting events app.Lifetime.ApplicationStarted.Register(() => { _logger.Info($"Application started, environment: {builder.Environment.EnvironmentName}"); }); diff --git a/TraceRoute/Services/StoreServerURLFilter.cs b/TraceRoute/Services/StoreServerURLFilter.cs index df6ddf9..1574f60 100644 --- a/TraceRoute/Services/StoreServerURLFilter.cs +++ b/TraceRoute/Services/StoreServerURLFilter.cs @@ -30,7 +30,7 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next) { if (string.IsNullOrEmpty(ServerURL)) { - string uriString = $"{context.Request.Scheme}://{context.Request.Host}/"; + string uriString = $"https://{context.Request.Host}/"; //I assume we are in the production environment if (Uri.TryCreate(uriString, UriKind.Absolute, out var location)) { ServerURL = location.AbsoluteUri; diff --git a/TraceRoute/TraceRoute.csproj b/TraceRoute/TraceRoute.csproj index 4af51a5..38a061d 100644 --- a/TraceRoute/TraceRoute.csproj +++ b/TraceRoute/TraceRoute.csproj @@ -22,7 +22,7 @@ - + diff --git a/TraceRoute/wwwroot/js/site.js b/TraceRoute/wwwroot/js/site.js index 845bce4..9a9c08a 100644 --- a/TraceRoute/wwwroot/js/site.js +++ b/TraceRoute/wwwroot/js/site.js @@ -86,6 +86,7 @@ function drawPath(HostList) { } } polyline = L.polyline(latlngs, { color: 'red' }).addTo(map); + map.fitBounds(polyline.getBounds()); } function hideKeyboard() { diff --git a/TraceRoute/wwwroot/js/site.min.js b/TraceRoute/wwwroot/js/site.min.js index 2f510d5..eb31304 100644 --- a/TraceRoute/wwwroot/js/site.min.js +++ b/TraceRoute/wwwroot/js/site.min.js @@ -1 +1 @@ -function initMap(){map=L.map("map",{preferCanvas:!0}).setView([0,0],2);L.Icon.Default.imagePath="lib/leaflet/images/";const n=L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:19,attribution:'© OpenStreetMap<\/a>'}).addTo(map);L.Map.include({getMarkerById:function(n){var t=null;return this.eachLayer(function(i){i instanceof L.Marker&&i.options.id===n&&(t=i)}),t}})}function addMarker(n,t,i,r){var u=L.marker([n,t],{id:"marker_"+i}).bindTooltip(i,{permanent:!0,direction:"right"}).on("mouseover",hilightHopTable).on("click",function(){DotNetHelper.invokeMethodAsync("OnShowIpDetails",r)}).addTo(map);markers.push(u)}function setDotNetHelper(n){window.DotNetHelper=n}function hilightHopTable(){var t=this.getTooltip(),n=".tr_hop_"+t.getContent();$(n).addClass("highlight");setTimeout(function(){$(n).removeClass("highlight")},2e3)}function hilightTooltip(n){const i=$(n).data("index-value"),t=map.getMarkerById("marker_"+i);t!=null&&($(t._icon).addClass("highlight"),setTimeout(function(){$(t._icon).removeClass("highlight")},1e3))}function clearMarkersAndPaths(){map.eachLayer(n=>{(n._latlng!=undefined||n._path!=undefined)&&n.remove(),n===polyline&&map.removeLayer(n)});markers=[];polyline=undefined}function drawPath(n){var t=[],i;if(n.find(n=>n.details==undefined||n.details.isp==undefined)==undefined){for(let r=0;rOpenStreetMap<\/a>'}).addTo(map);L.Map.include({getMarkerById:function(n){var t=null;return this.eachLayer(function(i){i instanceof L.Marker&&i.options.id===n&&(t=i)}),t}})}function addMarker(n,t,i,r){var u=L.marker([n,t],{id:"marker_"+i}).bindTooltip(i,{permanent:!0,direction:"right"}).on("mouseover",hilightHopTable).on("click",function(){DotNetHelper.invokeMethodAsync("OnShowIpDetails",r)}).addTo(map);markers.push(u)}function setDotNetHelper(n){window.DotNetHelper=n}function hilightHopTable(){var t=this.getTooltip(),n=".tr_hop_"+t.getContent();$(n).addClass("highlight");setTimeout(function(){$(n).removeClass("highlight")},2e3)}function hilightTooltip(n){const i=$(n).data("index-value"),t=map.getMarkerById("marker_"+i);t!=null&&($(t._icon).addClass("highlight"),setTimeout(function(){$(t._icon).removeClass("highlight")},1e3))}function clearMarkersAndPaths(){map.eachLayer(n=>{(n._latlng!=undefined||n._path!=undefined)&&n.remove(),n===polyline&&map.removeLayer(n)});markers=[];polyline=undefined}function drawPath(n){var t=[],i;if(n.find(n=>n.details==undefined||n.details.isp==undefined)==undefined){for(let r=0;r await Task.CompletedTask; }); Assert.IsNotEmpty(filter.GetServerURL()); - Assert.AreEqual("http://localhost/", filter.GetServerURL()); + Assert.AreEqual("https://localhost/", filter.GetServerURL()); } } }