|
17 | 17 |
|
18 | 18 | namespace WP_Ultimo\Integrations\Providers\FrankenPHP; |
19 | 19 |
|
20 | | -use Psr\Log\LogLevel; |
21 | 20 | use WP_Ultimo\Integrations\Base_Capability_Module; |
22 | 21 | use WP_Ultimo\Integrations\Capabilities\Domain_Mapping_Capability; |
23 | 22 |
|
@@ -187,123 +186,44 @@ private function is_valid_multisite_domain(string $domain): bool { |
187 | 186 | * |
188 | 187 | * @param string $domain The domain name being mapped. |
189 | 188 | * @param int $site_id ID of the site receiving the mapping. |
| 189 | + * On-demand TLS handles certificate provisioning automatically on first |
| 190 | + * TLS handshake. The ask endpoint validates the domain. No explicit |
| 191 | + * provisioning needed — just log for observability. |
| 192 | + * |
190 | 193 | * @return void |
191 | 194 | */ |
192 | 195 | public function on_add_domain(string $domain, int $site_id): void { |
193 | 196 |
|
194 | | - $this->provision_certificate($domain); |
| 197 | + if (function_exists('wu_log_add')) { |
| 198 | + wu_log_add('integration-frankenphp', "Domain added: {$domain} (cert will be provisioned on first visit via on-demand TLS)"); |
| 199 | + } |
195 | 200 | } |
196 | 201 |
|
197 | 202 | /** |
198 | | - * Called when a mapped domain is removed. |
199 | | - * |
200 | | - * Caddy automatically stops serving certs for domains that fail the |
201 | | - * "ask" check on renewal, so no explicit cleanup is needed. |
| 203 | + * {@inheritdoc} |
202 | 204 | * |
203 | | - * @param string $domain The domain name being removed. |
204 | | - * @param int $site_id ID of the site. |
205 | | - * @return void |
| 205 | + * Caddy automatically stops renewing certs for domains that fail the |
| 206 | + * ask endpoint check, so no explicit cleanup is needed. |
206 | 207 | */ |
207 | 208 | public function on_remove_domain(string $domain, int $site_id): void { |
208 | 209 |
|
209 | | - // Caddy handles cleanup automatically via on-demand TLS renewal checks. |
210 | 210 | if (function_exists('wu_log_add')) { |
211 | 211 | wu_log_add('integration-frankenphp', "Domain removed: {$domain} (cert will expire naturally)"); |
212 | 212 | } |
213 | 213 | } |
214 | 214 |
|
215 | 215 | /** |
216 | | - * Called when a new subdomain is added. |
217 | | - * |
218 | | - * Subdomains under the main domain are covered by the wildcard cert |
219 | | - * or on-demand TLS, so no action needed. |
220 | | - * |
221 | | - * @param string $subdomain The subdomain being added. |
222 | | - * @param int $site_id ID of the site. |
223 | | - * @return void |
| 216 | + * {@inheritdoc} |
224 | 217 | */ |
225 | 218 | public function on_add_subdomain(string $subdomain, int $site_id): void { |
226 | 219 | } |
227 | 220 |
|
228 | 221 | /** |
229 | | - * Called when a subdomain is removed. |
230 | | - * |
231 | | - * @param string $subdomain The subdomain being removed. |
232 | | - * @param int $site_id ID of the site. |
233 | | - * @return void |
| 222 | + * {@inheritdoc} |
234 | 223 | */ |
235 | 224 | public function on_remove_subdomain(string $subdomain, int $site_id): void { |
236 | 225 | } |
237 | 226 |
|
238 | | - /** |
239 | | - * Add a Let's Encrypt TLS policy for a domain via Caddy's admin API. |
240 | | - * |
241 | | - * Caddy's Caddyfile adapter merges TLS policies when a catch-all block |
242 | | - * uses a static cert, so named blocks don't get their own ACME policy. |
243 | | - * This method patches the TLS connection policies at runtime to add |
244 | | - * an ACME-backed policy for the domain before the static-cert catch-all. |
245 | | - * |
246 | | - * @param string $domain The domain to provision. |
247 | | - * @return void |
248 | | - */ |
249 | | - private function provision_certificate(string $domain): void { |
250 | | - |
251 | | - /** @var FrankenPHP_Integration */ |
252 | | - $frankenphp = $this->get_integration(); |
253 | | - |
254 | | - // Get current TLS connection policies. |
255 | | - $current = $frankenphp->api_call( |
256 | | - '/config/apps/http/servers/srv0/tls_connection_policies', |
257 | | - [], |
258 | | - 'GET' |
259 | | - ); |
260 | | - |
261 | | - if (is_wp_error($current) || ! is_array($current)) { |
262 | | - if (function_exists('wu_log_add')) { |
263 | | - wu_log_add('integration-frankenphp', "Failed to read TLS policies for {$domain}", LogLevel::ERROR); |
264 | | - } |
265 | | - return; |
266 | | - } |
267 | | - |
268 | | - // Check if this domain already has a policy. |
269 | | - foreach ($current as $policy) { |
270 | | - $sni = $policy['match']['sni'] ?? []; |
271 | | - if (in_array($domain, $sni, true)) { |
272 | | - if (function_exists('wu_log_add')) { |
273 | | - wu_log_add('integration-frankenphp', "TLS policy already exists for {$domain}"); |
274 | | - } |
275 | | - return; |
276 | | - } |
277 | | - } |
278 | | - |
279 | | - // Insert a new ACME policy for this domain before the catch-all. |
280 | | - // Policies without certificate_selection use Caddy's default (ACME/Let's Encrypt). |
281 | | - $new_policy = ['match' => ['sni' => [$domain]]]; |
282 | | - |
283 | | - // Insert before the last entry (the catch-all with no SNI match). |
284 | | - array_splice($current, count($current) - 1, 0, [$new_policy]); |
285 | | - |
286 | | - $response = $frankenphp->api_call( |
287 | | - '/config/apps/http/servers/srv0/tls_connection_policies', |
288 | | - $current, |
289 | | - 'PATCH' |
290 | | - ); |
291 | | - |
292 | | - if (is_wp_error($response)) { |
293 | | - if (function_exists('wu_log_add')) { |
294 | | - wu_log_add( |
295 | | - 'integration-frankenphp', |
296 | | - "TLS policy error for {$domain}: " . $response->get_error_message(), |
297 | | - LogLevel::ERROR |
298 | | - ); |
299 | | - } |
300 | | - } else { |
301 | | - if (function_exists('wu_log_add')) { |
302 | | - wu_log_add('integration-frankenphp', "Let's Encrypt TLS policy added for {$domain}"); |
303 | | - } |
304 | | - } |
305 | | - } |
306 | | - |
307 | 227 | /** |
308 | 228 | * {@inheritdoc} |
309 | 229 | */ |
|
0 commit comments