commit 0ab177abc7d2440480a84013ee4f4a7633817fd5 Author: ebolo Date: Thu Jan 23 08:54:08 2025 +0700 init: initial commit for the project diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38bece4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/.idea/.idea.CaddyManager/.idea/encodings.xml b/.idea/.idea.CaddyManager/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.CaddyManager/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/CaddyManager.sln b/CaddyManager.sln new file mode 100644 index 0000000..866f332 --- /dev/null +++ b/CaddyManager.sln @@ -0,0 +1,21 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CaddyManager", "CaddyManager\CaddyManager.csproj", "{48F15175-A1B9-457D-9CA2-04C241F3435C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EC202984-FC85-4101-B801-1E8AA4E9C4DD}" + ProjectSection(SolutionItems) = preProject + compose.yaml = compose.yaml + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {48F15175-A1B9-457D-9CA2-04C241F3435C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48F15175-A1B9-457D-9CA2-04C241F3435C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48F15175-A1B9-457D-9CA2-04C241F3435C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48F15175-A1B9-457D-9CA2-04C241F3435C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/CaddyManager/CaddyManager.csproj b/CaddyManager/CaddyManager.csproj new file mode 100644 index 0000000..aad5d47 --- /dev/null +++ b/CaddyManager/CaddyManager.csproj @@ -0,0 +1,26 @@ + + + + net9.0 + enable + enable + Linux + + + + + .dockerignore + + + + + + + + + + + + + + diff --git a/CaddyManager/Components/App.razor b/CaddyManager/Components/App.razor new file mode 100644 index 0000000..43e2f5e --- /dev/null +++ b/CaddyManager/Components/App.razor @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CaddyManager/Components/Layout/MainLayout.razor b/CaddyManager/Components/Layout/MainLayout.razor new file mode 100644 index 0000000..a168a7d --- /dev/null +++ b/CaddyManager/Components/Layout/MainLayout.razor @@ -0,0 +1,43 @@ +@inherits LayoutComponentBase + +@* Required *@ + + + +@* Needed for dialogs *@ + + +@* Needed for snackbars *@ + + + + + + + + + + + Caddy Manager + + + Reverse Proxies + Global Caddyfile + Settings + + + + + @Body + + + + +@code{ + private bool _open = false; + + private void ToggleDrawer() + { + _open = !_open; + } +} \ No newline at end of file diff --git a/CaddyManager/Components/Pages/Caddyfile.razor b/CaddyManager/Components/Pages/Caddyfile.razor new file mode 100644 index 0000000..4f7cc1a --- /dev/null +++ b/CaddyManager/Components/Pages/Caddyfile.razor @@ -0,0 +1,66 @@ +@page "/caddyfile" + +Weather + +

Weather

+ +

This component demonstrates showing data.

+ +@if (forecasts == null) +{ +

+ Loading... +

+} +else +{ + + + + + + + + + + + @foreach (var forecast in forecasts) + { + + + + + + + } + +
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
+} + +@code { + private WeatherForecast[]? forecasts; + + protected override async Task OnInitializedAsync() + { + // Simulate asynchronous loading to demonstrate a loading indicator + await Task.Delay(500); + + var startDate = DateOnly.FromDateTime(DateTime.Now); + var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; + forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = startDate.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = summaries[Random.Shared.Next(summaries.Length)] + }).ToArray(); + } + + private class WeatherForecast + { + public DateOnly Date { get; set; } + public int TemperatureC { get; set; } + public string? Summary { get; set; } + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + } + +} \ No newline at end of file diff --git a/CaddyManager/Components/Pages/Error.razor b/CaddyManager/Components/Pages/Error.razor new file mode 100644 index 0000000..9d7c6be --- /dev/null +++ b/CaddyManager/Components/Pages/Error.razor @@ -0,0 +1,36 @@ +@page "/Error" +@using System.Diagnostics + +Error + +

Error.

+

An error occurred while processing your request.

+ +@if (ShowRequestId) +{ +

+ Request ID: @RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+ +@code{ + [CascadingParameter] private HttpContext? HttpContext { get; set; } + + private string? RequestId { get; set; } + private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + protected override void OnInitialized() => + RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; + +} \ No newline at end of file diff --git a/CaddyManager/Components/Pages/ReverseProxies.razor b/CaddyManager/Components/Pages/ReverseProxies.razor new file mode 100644 index 0000000..3f196b6 --- /dev/null +++ b/CaddyManager/Components/Pages/ReverseProxies.razor @@ -0,0 +1,24 @@ +@page "/" +@using CaddyManager.Contracts.Caddy +@inject ICaddyService CaddyService + +Home + + + @foreach(var caddyConfig in _availableCaddyConfigurations) + { + + + } + + +@code +{ + List _availableCaddyConfigurations = []; + + protected override Task OnInitializedAsync() + { + _availableCaddyConfigurations = CaddyService.GetExistingCaddyConfigurations(); + return base.OnInitializedAsync(); + } +} diff --git a/CaddyManager/Components/Pages/Settings.razor b/CaddyManager/Components/Pages/Settings.razor new file mode 100644 index 0000000..ec4cef2 --- /dev/null +++ b/CaddyManager/Components/Pages/Settings.razor @@ -0,0 +1,21 @@ +@page "/settings" +@using CaddyManager.Contracts.Caddy +@inject ICaddyService CaddyService + +Counter + +

Counter

+ +

Current count: @currentCount

+ +Click me + +@code { + private int currentCount = 0; + + private void IncrementCount() + { + Console.WriteLine(string.Join('\n', CaddyService.GetExistingCaddyConfigurations())); + } + +} \ No newline at end of file diff --git a/CaddyManager/Components/Routes.razor b/CaddyManager/Components/Routes.razor new file mode 100644 index 0000000..ae94e9e --- /dev/null +++ b/CaddyManager/Components/Routes.razor @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CaddyManager/Components/_Imports.razor b/CaddyManager/Components/_Imports.razor new file mode 100644 index 0000000..4be395c --- /dev/null +++ b/CaddyManager/Components/_Imports.razor @@ -0,0 +1,11 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop +@using CaddyManager +@using CaddyManager.Components +@using MudBlazor \ No newline at end of file diff --git a/CaddyManager/Configurations/Caddy/CaddyServiceConfigurations.cs b/CaddyManager/Configurations/Caddy/CaddyServiceConfigurations.cs new file mode 100644 index 0000000..52b55d3 --- /dev/null +++ b/CaddyManager/Configurations/Caddy/CaddyServiceConfigurations.cs @@ -0,0 +1,11 @@ +namespace CaddyManager.Configurations.Caddy; + +/// +/// Wraps the configurations for Caddy service +/// +public class CaddyServiceConfigurations +{ + public const string Caddy = "Caddy"; + + public string ConfigDir { get; set; } = "/config"; +} \ No newline at end of file diff --git a/CaddyManager/Contracts/Caddy/ICaddyService.cs b/CaddyManager/Contracts/Caddy/ICaddyService.cs new file mode 100644 index 0000000..6b147f4 --- /dev/null +++ b/CaddyManager/Contracts/Caddy/ICaddyService.cs @@ -0,0 +1,13 @@ +namespace CaddyManager.Contracts.Caddy; + +/// +/// Contracts for Caddy Service to help monitor the available Caddy configurations +/// +public interface ICaddyService +{ + /// + /// Returns the existing Caddy configurations within the configured directory + /// + /// + List GetExistingCaddyConfigurations(); +} \ No newline at end of file diff --git a/CaddyManager/Contracts/Configurations/IConfigurationsService.cs b/CaddyManager/Contracts/Configurations/IConfigurationsService.cs new file mode 100644 index 0000000..9914434 --- /dev/null +++ b/CaddyManager/Contracts/Configurations/IConfigurationsService.cs @@ -0,0 +1,14 @@ +using CaddyManager.Configurations.Caddy; + +namespace CaddyManager.Contracts.Configurations; + +/// +/// Contract for the services providing the configurations for the application +/// +public interface IConfigurationsService +{ + /// + /// Configurations for Caddy service + /// + CaddyServiceConfigurations CaddyServiceConfigurations { get; } +} \ No newline at end of file diff --git a/CaddyManager/Dockerfile b/CaddyManager/Dockerfile new file mode 100644 index 0000000..d15122c --- /dev/null +++ b/CaddyManager/Dockerfile @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 8080 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["CaddyManager/CaddyManager.csproj", "CaddyManager/"] +RUN dotnet restore "CaddyManager/CaddyManager.csproj" +COPY . . +WORKDIR "/src/CaddyManager" +RUN dotnet build "CaddyManager.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "CaddyManager.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "CaddyManager.dll"] diff --git a/CaddyManager/Program.cs b/CaddyManager/Program.cs new file mode 100644 index 0000000..3acbd61 --- /dev/null +++ b/CaddyManager/Program.cs @@ -0,0 +1,37 @@ +using CaddyManager.Components; +using MudBlazor.Services; +using NetCore.AutoRegisterDi; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services + .AddMudServices() + .AddRazorComponents() + .AddInteractiveServerComponents(); + +// Auto register all the Services, Repositories that we have had within the code base +builder.Services.RegisterAssemblyPublicNonGenericClasses() + .Where(t => t.Name.EndsWith("Service") || t.Name.EndsWith("Repository")) + .AsPublicImplementedInterfaces(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error", createScopeForErrors: true); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); + + +app.UseAntiforgery(); + +app.MapStaticAssets(); +app.MapRazorComponents() + .AddInteractiveServerRenderMode(); + +app.Run(); \ No newline at end of file diff --git a/CaddyManager/Properties/launchSettings.json b/CaddyManager/Properties/launchSettings.json new file mode 100644 index 0000000..12cfcea --- /dev/null +++ b/CaddyManager/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:8080", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:8081;http://localhost:8080", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } + } diff --git a/CaddyManager/Services/CaddyService.cs b/CaddyManager/Services/CaddyService.cs new file mode 100644 index 0000000..3a10322 --- /dev/null +++ b/CaddyManager/Services/CaddyService.cs @@ -0,0 +1,17 @@ +using CaddyManager.Configurations.Caddy; +using CaddyManager.Contracts.Caddy; +using CaddyManager.Contracts.Configurations; + +namespace CaddyManager.Services; + +/// +public class CaddyService(IConfigurationsService configurationsService) : ICaddyService +{ + private CaddyServiceConfigurations _configurations => configurationsService.CaddyServiceConfigurations; + + /// + public List GetExistingCaddyConfigurations() + { + return Directory.GetFiles(_configurations.ConfigDir).ToList(); + } +} \ No newline at end of file diff --git a/CaddyManager/Services/Configurations/ConfigurationsService.cs b/CaddyManager/Services/Configurations/ConfigurationsService.cs new file mode 100644 index 0000000..dc4c415 --- /dev/null +++ b/CaddyManager/Services/Configurations/ConfigurationsService.cs @@ -0,0 +1,15 @@ +using CaddyManager.Configurations.Caddy; +using CaddyManager.Contracts.Configurations; +using NetCore.AutoRegisterDi; + +namespace CaddyManager.Services.Configurations; + +/// +[RegisterAsSingleton] +public class ConfigurationsService(IConfiguration configuration) : IConfigurationsService +{ + /// + public CaddyServiceConfigurations CaddyServiceConfigurations => + configuration.GetSection(CaddyServiceConfigurations.Caddy).Get() ?? + new CaddyServiceConfigurations(); +} \ No newline at end of file diff --git a/CaddyManager/appsettings.Development.json b/CaddyManager/appsettings.Development.json new file mode 100644 index 0000000..5495448 --- /dev/null +++ b/CaddyManager/appsettings.Development.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "Caddy": { + "ConfigDir": "/Users/ebolo/Code/caddy/config" + } +} diff --git a/CaddyManager/appsettings.json b/CaddyManager/appsettings.json new file mode 100644 index 0000000..8de4892 --- /dev/null +++ b/CaddyManager/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "Caddy": { + "ConfigDir": "/root/compose/caddy/config" + } +} diff --git a/CaddyManager/wwwroot/app.css b/CaddyManager/wwwroot/app.css new file mode 100644 index 0000000..e69de29 diff --git a/CaddyManager/wwwroot/favicon.png b/CaddyManager/wwwroot/favicon.png new file mode 100644 index 0000000..8422b59 Binary files /dev/null and b/CaddyManager/wwwroot/favicon.png differ diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..91058e1 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,6 @@ +services: + caddymanager: + image: caddymanager + build: + context: . + dockerfile: CaddyManager/Dockerfile