Skip to content

Commit acb53c9

Browse files
committed
update
1 parent 31cc6c0 commit acb53c9

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

web/Modules/Caddy/App/Filament/Pages/CaddySettings.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ public function schema(): array
7777
->default('443')
7878
->numeric()
7979
->helperText('Port for Caddy to listen on for HTTPS requests'),
80+
81+
TextInput::make('caddy.cloudflare_api_token')
82+
->label('Cloudflare API Token')
83+
->password()
84+
->helperText('API token for Cloudflare DNS challenge. Required for wildcard SSL certificates. Get one from https://dash.cloudflare.com/profile/api-tokens/'),
85+
86+
Checkbox::make('caddy.enable_wildcard_ssl')
87+
->label('Enable Wildcard SSL (Cloudflare)')
88+
->helperText('Prefer wildcard SSL certificates for all domains if possible using Cloudflare DNS plugin.'),
89+
90+
TextInput::make('caddy.wildcard_domain')
91+
->label('Wildcard Base Domain')
92+
->placeholder('example.com')
93+
->helperText('Wildcard SSL will only be used for this domain and its subdomains.'),
8094
]),
8195

8296
Tabs\Tab::make('Apache Integration')

web/Modules/Caddy/App/Jobs/CaddyBuild.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ protected function generateCaddyfile(): void
170170
// Get static file paths from settings
171171
$staticPaths = setting('caddy.static_paths') ?? '';
172172

173+
// Get Cloudflare API token for DNS challenges
174+
$cloudflareApiToken = setting('caddy.cloudflare_api_token');
175+
173176
foreach ($getAllDomains as $domain) {
174177
$isBroken = false;
175178

@@ -230,6 +233,7 @@ protected function generateCaddyfile(): void
230233
'caddyBlocks' => $caddyBlocks,
231234
'caddyEmail' => $caddyEmail,
232235
'staticPaths' => $staticPaths,
236+
'cloudflareApiToken' => $cloudflareApiToken,
233237
])->render();
234238

235239
$caddyfile = preg_replace('~(*ANY)\A\s*\R|\s*(?!\r\n)\s$~mu', '', $caddyfile);
@@ -250,6 +254,22 @@ private function createCaddyBlock(Domain $domain, $apacheHttpPort): ?array
250254
return null;
251255
}
252256

257+
// //gi matcth the wilcard use tls_cloudflare
258+
//
259+
// $useWildcard = setting('caddy.enable_wildcard_ssl', false);
260+
// $cloudflareApiToken = setting('caddy.cloudflare_api_token');
261+
// $tls_cloudflare = false;
262+
// $wildcardDomain = null;
263+
// if ($useWildcard && $cloudflareApiToken && !empty($domain->domain)) {
264+
// if(strpos($domain->domain, '*') === false && strpos($domain->domain, '.') !== false) {
265+
// $tls_cloudflare = true;
266+
// $wildcardDomain = "*." . $domain->domain;
267+
// }
268+
// }
269+
//
270+
//
271+
272+
253273
return [
254274
'domain' => $domain->domain,
255275
'proxy_to' => "127.0.0.1:{$apacheHttpPort}",
@@ -265,12 +285,29 @@ private function createMasterDomainCaddyBlock(MasterDomain $masterDomain, $apach
265285
return null;
266286
}
267287

288+
// Wildcard SSL logic only for master domain
289+
$useWildcard = setting('caddy.enable_wildcard_ssl', false);
290+
$cloudflareApiToken = setting('caddy.cloudflare_api_token');
291+
$tls_cloudflare = false;
292+
$wildcardDomain = null;
293+
294+
// Only use wildcard if enabled and token is set for master domain
295+
if ($useWildcard && $cloudflareApiToken && !empty($masterDomain->domain)) {
296+
297+
298+
$tls_cloudflare = true;
299+
$wildcardDomain = "*." . $masterDomain->domain;
300+
}
301+
268302
return [
269303
'domain' => $masterDomain->domain,
304+
// 'wildcardDomain' => $wildcardDomain,
305+
// 'cloudflareApiToken' => $cloudflareApiToken,
270306
'proxy_to' => "127.0.0.1:{$apacheHttpPort}",
271307
'enable_ssl' => true,
272308
'enable_www' => true,
273309
'is_master' => true,
310+
// 'tls_cloudflare' => $tls_cloudflare,
274311
'document_root' => $masterDomain->document_root ?? "/var/www/{$masterDomain->domain}/public_html",
275312
];
276313
}

web/Modules/Caddy/resources/views/caddyfile-build.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
servers {
77
protocols h1 h2 h3
88
}
9+
910
}
1011

1112
@foreach($caddyBlocks as $block)
@@ -31,7 +32,6 @@
3132
ETag
3233
}
3334

34-
3535
@endif
3636

3737
# Proxy remaining requests to Apache
@@ -43,6 +43,8 @@
4343
}
4444
}
4545

46+
47+
4648
# Enable compression
4749
encode zstd gzip
4850

web/Modules/Caddy/shell-scripts/install-caddy.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ sudo chmod 644 /etc/caddy/Caddyfile
5555

5656
usermod -aG www-data caddy
5757

58+
sudo add-apt-repository ppa:longsleep/golang-backports -y
59+
sudo apt update -y
60+
sudo apt install golang-go -y
61+
62+
63+
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https -y
64+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-xcaddy-archive-keyring.gpg
65+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-xcaddy.list
66+
sudo apt update -y
67+
sudo apt install xcaddy -y
68+
cd /usr/bin
69+
xcaddy build --with github.com/caddy-dns/cloudflare
5870

5971

6072

0 commit comments

Comments
 (0)