From 0ab177abc7d2440480a84013ee4f4a7633817fd5 Mon Sep 17 00:00:00 2001 From: ebolo Date: Thu, 23 Jan 2025 08:54:08 +0700 Subject: [PATCH] init: initial commit for the project --- .dockerignore | 25 +++++++ .gitignore | 5 ++ .idea/.idea.CaddyManager/.idea/encodings.xml | 4 ++ CaddyManager.sln | 21 ++++++ CaddyManager/CaddyManager.csproj | 26 +++++++ CaddyManager/Components/App.razor | 23 ++++++ .../Components/Layout/MainLayout.razor | 43 ++++++++++++ CaddyManager/Components/Pages/Caddyfile.razor | 66 ++++++++++++++++++ CaddyManager/Components/Pages/Error.razor | 36 ++++++++++ .../Components/Pages/ReverseProxies.razor | 24 +++++++ CaddyManager/Components/Pages/Settings.razor | 21 ++++++ CaddyManager/Components/Routes.razor | 6 ++ CaddyManager/Components/_Imports.razor | 11 +++ .../Caddy/CaddyServiceConfigurations.cs | 11 +++ CaddyManager/Contracts/Caddy/ICaddyService.cs | 13 ++++ .../Configurations/IConfigurationsService.cs | 14 ++++ CaddyManager/Dockerfile | 23 ++++++ CaddyManager/Program.cs | 37 ++++++++++ CaddyManager/Properties/launchSettings.json | 23 ++++++ CaddyManager/Services/CaddyService.cs | 17 +++++ .../Configurations/ConfigurationsService.cs | 15 ++++ CaddyManager/appsettings.Development.json | 11 +++ CaddyManager/appsettings.json | 12 ++++ CaddyManager/wwwroot/app.css | 0 CaddyManager/wwwroot/favicon.png | Bin 0 -> 1148 bytes compose.yaml | 6 ++ 26 files changed, 493 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 .idea/.idea.CaddyManager/.idea/encodings.xml create mode 100644 CaddyManager.sln create mode 100644 CaddyManager/CaddyManager.csproj create mode 100644 CaddyManager/Components/App.razor create mode 100644 CaddyManager/Components/Layout/MainLayout.razor create mode 100644 CaddyManager/Components/Pages/Caddyfile.razor create mode 100644 CaddyManager/Components/Pages/Error.razor create mode 100644 CaddyManager/Components/Pages/ReverseProxies.razor create mode 100644 CaddyManager/Components/Pages/Settings.razor create mode 100644 CaddyManager/Components/Routes.razor create mode 100644 CaddyManager/Components/_Imports.razor create mode 100644 CaddyManager/Configurations/Caddy/CaddyServiceConfigurations.cs create mode 100644 CaddyManager/Contracts/Caddy/ICaddyService.cs create mode 100644 CaddyManager/Contracts/Configurations/IConfigurationsService.cs create mode 100644 CaddyManager/Dockerfile create mode 100644 CaddyManager/Program.cs create mode 100644 CaddyManager/Properties/launchSettings.json create mode 100644 CaddyManager/Services/CaddyService.cs create mode 100644 CaddyManager/Services/Configurations/ConfigurationsService.cs create mode 100644 CaddyManager/appsettings.Development.json create mode 100644 CaddyManager/appsettings.json create mode 100644 CaddyManager/wwwroot/app.css create mode 100644 CaddyManager/wwwroot/favicon.png create mode 100644 compose.yaml 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 0000000000000000000000000000000000000000..8422b59695935d180d11d5dbe99653e711097819 GIT binary patch literal 1148 zcmV-?1cUpDP)9h26h2-Cs%i*@Moc3?#6qJID|D#|3|2Hn7gTIYEkr|%Xjp);YgvFmB&0#2E2b=| zkVr)lMv9=KqwN&%obTp-$<51T%rx*NCwceh-E+=&e(oLO`@Z~7gybJ#U|^tB2Pai} zRN@5%1qsZ1e@R(XC8n~)nU1S0QdzEYlWPdUpH{wJ2Pd4V8kI3BM=)sG^IkUXF2-j{ zrPTYA6sxpQ`Q1c6mtar~gG~#;lt=s^6_OccmRd>o{*=>)KS=lM zZ!)iG|8G0-9s3VLm`bsa6e ze*TlRxAjXtm^F8V`M1%s5d@tYS>&+_ga#xKGb|!oUBx3uc@mj1%=MaH4GR0tPBG_& z9OZE;->dO@`Q)nr<%dHAsEZRKl zedN6+3+uGHejJp;Q==pskSAcRcyh@6mjm2z-uG;s%dM-u0*u##7OxI7wwyCGpS?4U zBFAr(%GBv5j$jS@@t@iI8?ZqE36I^4t+P^J9D^ELbS5KMtZ z{Qn#JnSd$15nJ$ggkF%I4yUQC+BjDF^}AtB7w348EL>7#sAsLWs}ndp8^DsAcOIL9 zTOO!!0!k2`9BLk25)NeZp7ev>I1Mn={cWI3Yhx2Q#DnAo4IphoV~R^c0x&nw*MoIV zPthX?{6{u}sMS(MxD*dmd5rU(YazQE59b|TsB5Tm)I4a!VaN@HYOR)DwH1U5y(E)z zQqQU*B%MwtRQ$%x&;1p%ANmc|PkoFJZ%<-uq%PX&C!c-7ypis=eP+FCeuv+B@h#{4 zGx1m0PjS~FJt}3mdt4c!lel`1;4W|03kcZRG+DzkTy|7-F~eDsV2Tx!73dM0H0CTh zl)F-YUkE1zEzEW(;JXc|KR5{ox%YTh{$%F$a36JP6Nb<0%#NbSh$dMYF-{ z1_x(Vx)}fs?5_|!5xBTWiiIQHG<%)*e=45Fhjw_tlnmlixq;mUdC$R8v#j( zhQ$9YR-o%i5Uc`S?6EC51!bTRK=Xkyb<18FkCKnS2;o*qlij1YA@-nRpq#OMTX&RbL<^2q@0qja!uIvI;j$6>~k@IMwD42=8$$!+R^@5o6HX(*n~