Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TraceRoute/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="This utility provides a Trace Route functionality with a nice layout" />
<title>TODO: TITLE - TraceRoute</title>
<title>TraceRoute</title>
<link rel="stylesheet" href="@Assets["lib/twitter-bootstrap/css/bootstrap.min.css"]" />
<link rel="stylesheet" href="@Assets["css/site.css"]?t=@DateTime.Now.Ticks" />
<link rel="stylesheet" href="TraceRoute.styles.css">
Expand Down
3 changes: 2 additions & 1 deletion TraceRoute/Controllers/APIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class APIController(ILoggerFactory LoggerFactory, ServerListService serve
[HttpPost("api/presence")]
public async Task<bool> 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))
Expand Down
1 change: 1 addition & 0 deletions TraceRoute/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
36 changes: 14 additions & 22 deletions TraceRoute/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<StoreServerURLFilter>();
builder.Services.AddHttpClient<IpApiClient>();
builder.Services.AddHttpClient<TraceRouteApiClient>();
Expand All @@ -32,12 +31,6 @@
builder.Services.AddHostedService(provider => provider.GetRequiredService<ServerListService>());
builder.Services.AddBlazoredToast();

//Forward headers configuration for reverse proxy
builder.Services.Configure<ForwardedHeadersOptions>(options => {
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
//WebMarkupMin
builder.Services.AddWebMarkupMin(
options =>
Expand Down Expand Up @@ -86,11 +79,6 @@
options.Level = CompressionLevel.Optimal;
});

//Forwardedfor
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
//Cors allow all (required for remote traces)
builder.Services.AddCors(o => o.AddPolicy("AllowAll", builder =>
{
Expand All @@ -109,18 +97,23 @@
app.UseAntiforgery();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
app.MapRazorPages();
app.MapControllers();
// app.MapBlazorHub();

app.UseMiddleware<StoreServerURLFilter>();
app.UseStatusCodePages();

//Cors allow all (required for remote traces)
app.UseCors("AllowAll");

// 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();
}

Expand Down Expand Up @@ -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}"); });
Expand Down
2 changes: 1 addition & 1 deletion TraceRoute/Services/StoreServerURLFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion TraceRoute/TraceRoute.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ItemGroup>
<PackageReference Include="Blazored.Toast" Version="4.2.1" />
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="IPNetwork2" Version="3.1.764" />
<PackageReference Include="IPNetwork2" Version="3.1.767" />
<PackageReference Include="log4net" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
Expand Down
1 change: 1 addition & 0 deletions TraceRoute/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function drawPath(HostList) {
}
}
polyline = L.polyline(latlngs, { color: 'red' }).addTo(map);
map.fitBounds(polyline.getBounds());
}

function hideKeyboard() {
Expand Down
2 changes: 1 addition & 1 deletion TraceRoute/wwwroot/js/site.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion UnitTests/Services/StoreServerURLFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ await filter.InvokeAsync(contextAccessor.HttpContext!, async (context) =>
await Task.CompletedTask;
});
Assert.IsNotEmpty(filter.GetServerURL());
Assert.AreEqual("http://localhost/", filter.GetServerURL());
Assert.AreEqual("https://localhost/", filter.GetServerURL());
}
}
}
Loading