diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index d56e202..dcbd55e 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -9,47 +9,47 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: '18' - cache: 'npm' + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'npm' - - name: Install dependencies - run: npm ci + - name: Install dependencies + run: npm ci - - name: Build Svelte app - run: npm run build + - name: Build Svelte app + run: npm run build - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - name: Login to Gitea Container Registry - uses: docker/login-action@v2 - with: - registry: git.vinylnostalgia.com - username: ${{ secrets.RUNNER_USERNAME }} - password: ${{ secrets.RUNNER_PASSWORD }} + - name: Login to Gitea Container Registry + uses: docker/login-action@v2 + with: + registry: git.vinylnostalgia.com + username: ${{ secrets.RUNNER_USERNAME }} + password: ${{ secrets.RUNNER_PASSWORD }} - - name: Generate Docker metadata - id: meta - uses: docker/metadata-action@v4 - with: - images: git.vinylnostalgia.com/mo/ava - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=sha + - name: Generate Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: git.vinylnostalgia.com/mo/caddyui + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 58d5b1c..4389c05 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -17,211 +17,216 @@ Textarea, Spinner } from 'flowbite-svelte'; - import { fly, fade } from 'svelte/transition'; import type { Upstream, CAInfo } from './CaddyService'; - let config: Record = {}; + // State variables + let config = {}; let upstreams: Upstream[] = []; let caInfo: CAInfo | null = null; - let caCertificates: string = ''; - let showConfigModal: boolean = false; - let showCAModal: boolean = false; - let loadingConfig: boolean = false; - let loadingUpstreams: boolean = false; - let newConfig: string = ''; - let configPath: string = ''; - let caId: string = 'local'; - let activeTab: string = 'config'; + let caCertificates = ''; + let showConfigModal = false; + let showCAModal = false; + let loadingConfig = false; + let loadingUpstreams = false; + let newConfig = ''; + let configPath = ''; + let caId = 'local'; + let activeTab = 'config'; // Tracks the active tab - configStore.subscribe((value) => (config = value)); - upstreamsStore.subscribe((value) => (upstreams = value)); + // Subscribe to stores + configStore.subscribe((value: any) => (config = value)); + upstreamsStore.subscribe((value: any) => (upstreams = value)); onMount(async () => { await refreshData(); }); - async function refreshData(): Promise { + // Fetch and refresh data + async function refreshData() { + loadingConfig = true; try { - loadingConfig = true; await CaddyService.getConfig(); await CaddyService.getUpstreams(); } catch (error) { - alert(`Failed to refresh data: ${(error as Error).message}`); + alert(`Error refreshing data: ${(error as Error).message}`); } finally { loadingConfig = false; loadingUpstreams = false; } } - async function handleUpdateConfig(): Promise { + // Update configuration + async function handleUpdateConfig() { try { loadingConfig = true; await CaddyService.updateConfig(configPath, JSON.parse(newConfig)); await refreshData(); showConfigModal = false; } catch (error) { - alert(`Failed to update config: ${(error as Error).message}`); + alert(`Error updating config: ${(error as Error).message}`); } finally { loadingConfig = false; } } - async function handleLoadConfig(): Promise { + // Load new configuration + async function handleLoadConfig() { try { loadingConfig = true; await CaddyService.loadConfig(JSON.parse(newConfig)); await refreshData(); showConfigModal = false; } catch (error) { - alert(`Failed to load config: ${(error as Error).message}`); + alert(`Error loading config: ${(error as Error).message}`); } finally { loadingConfig = false; } } - async function handleStopServer(): Promise { + // Stop the Caddy server + async function handleStopServer() { if (confirm('Are you sure you want to stop the Caddy server?')) { try { await CaddyService.stopServer(); alert('Caddy server stopped successfully'); } catch (error) { - alert(`Failed to stop server: ${(error as Error).message}`); + alert(`Error stopping server: ${(error as Error).message}`); } } } - async function handleGetCAInfo(): Promise { + // Fetch CA information + async function handleGetCAInfo() { try { caInfo = await CaddyService.getCAInfo(caId); caCertificates = await CaddyService.getCACertificates(caId); showCAModal = true; } catch (error) { - alert(`Failed to get CA info: ${(error as Error).message}`); + alert(`Error fetching CA info: ${(error as Error).message}`); } } + // Change active tab function handleTabChange(tab: string) { activeTab = tab; } - - import { Cog, ServerCrash, Shield, RefreshCw } from 'lucide-svelte'; -
-

Caddy UI

+
+
+

Caddy Dashboard

+

+ Manage your Caddy server configurations, upstreams, and CA information easily. +

+
- handleTabChange('config')} title="Configuration" - class="flex items-center gap-2" - > + /> handleTabChange('upstreams')} title="Upstreams" - class="flex items-center gap-2" - > - + /> handleTabChange('ca_management')} title="CA Management" - class="flex items-center gap-2" - > + /> - + {#if activeTab === 'config'} -
+
-
-

Current Configuration

- -
+ {#if loadingConfig}
{:else} -
{JSON.stringify(
-							config,
-							null,
-							2
-						)}
+
+            {JSON.stringify(config, null, 2)}
+          
{/if}
-
+ {/if} {#if activeTab === 'upstreams'} -
+
-

Upstreams

+
+

Upstreams

+
{#if loadingUpstreams}
{:else} -
- - - Address - Requests - Fails - - - {#each upstreams as upstream} - - {upstream.address} - {upstream.num_requests} - {upstream.fails} - - {/each} - -
-
+ + + Address + Requests + Fails + + + {#each upstreams as upstream} + + {upstream.address} + {upstream.num_requests} + {upstream.fails} + + {/each} + +
{/if}
-
+ {/if} {#if activeTab === 'ca_management'} -
+
-

CA Management

-
- - +
+

CA Management

+
+
+ +
-
+
{/if} + +
+ +
-
- -
- - -

Update Configuration

+ + +

Update Configuration