fix: alias detection, offline page, backend redirect working
Joomla: Repo Health / Access control (push) Has been cancelled
Joomla: Update Server / Update updates.xml (push) Has been cancelled
Joomla: Repo Health / Release configuration (push) Has been cancelled
Joomla: Repo Health / Scripts governance (push) Has been cancelled
Joomla: Repo Health / Repository health (push) Has been cancelled

- Removed primaryHost check from getCurrentAlias() — just look up
  current host in aliases list directly
- Handle Joomla subform stdClass→array conversion
- Strip trailing slashes from alias domains
- Moved handleSiteAlias() to onAfterRoute (client type resolved)
- Use http_response_code(503) + die() for offline page
- Cast offline value to string for comparison

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-05-24 03:34:52 -05:00
parent b827b3382a
commit dca452e49d
@@ -129,9 +129,6 @@ class MokoWaaS extends CMSPlugin
// Security: HTTPS redirect (runs for all clients)
$this->enforceHttps();
// Site alias handling: offline page and backend redirect
$this->handleSiteAlias();
// MokoWaaS API endpoints (run before routing)
$mokoAction = $this->app->input->get('mokowaas', '');
@@ -896,6 +893,9 @@ class MokoWaaS extends CMSPlugin
*/
public function onAfterRoute()
{
// Site alias handling: offline page and backend redirect
$this->handleSiteAlias();
if (!$this->app->isClient('administrator'))
{
return;
@@ -2779,7 +2779,12 @@ class MokoWaaS extends CMSPlugin
{
if (is_string($aliases))
{
$aliases = json_decode($aliases, false);
$aliases = json_decode($aliases);
}
if (is_object($aliases))
{
$aliases = (array) $aliases;
}
if (is_array($aliases))
@@ -2790,7 +2795,7 @@ class MokoWaaS extends CMSPlugin
{
$a = (object) $a;
if (isset($a->domain) && strcasecmp(trim($a->domain), $currentHost) === 0)
if (isset($a->domain) && strcasecmp(rtrim(trim($a->domain), '/'), $currentHost) === 0)
{
$isAlias = true;
break;
@@ -2812,9 +2817,8 @@ class MokoWaaS extends CMSPlugin
protected function getCurrentAlias()
{
$currentHost = $_SERVER['HTTP_HOST'] ?? '';
$primaryHost = $this->getPrimaryHost();
if (empty($currentHost) || strcasecmp($currentHost, $primaryHost) === 0)
if (empty($currentHost))
{
return null;
}
@@ -2826,22 +2830,29 @@ class MokoWaaS extends CMSPlugin
return null;
}
// Subform returns JSON string or array
// Subform returns JSON string, array, or stdClass
if (is_string($aliases))
{
$aliases = json_decode($aliases, false);
$aliases = json_decode($aliases);
}
if (!is_array($aliases))
// Convert object to array (Joomla subform stores as {"key0":{...},"key1":{...}})
if (is_object($aliases))
{
$aliases = (array) $aliases;
}
if (!is_array($aliases) || empty($aliases))
{
return null;
}
// Look up the current host in the aliases list — if found, it's an alias
foreach ($aliases as $alias)
{
$alias = (object) $alias;
if (isset($alias->domain) && strcasecmp(trim($alias->domain), $currentHost) === 0)
if (isset($alias->domain) && strcasecmp(rtrim(trim($alias->domain), '/'), $currentHost) === 0)
{
return $alias;
}
@@ -2881,7 +2892,7 @@ class MokoWaaS extends CMSPlugin
}
// Offline: show maintenance page for frontend requests
if (!empty($alias->offline) && $alias->offline === '1'
if (!empty($alias->offline) && (string) $alias->offline === '1'
&& $this->app->isClient('site'))
{
// Allow health API to still respond
@@ -2893,7 +2904,7 @@ class MokoWaaS extends CMSPlugin
$message = $alias->offline_message ?? 'This site is currently offline for maintenance.';
$brandName = $this->params->get('brand_name', 'MokoWaaS');
header('HTTP/1.1 503 Service Unavailable');
http_response_code(503);
header('Retry-After: 3600');
header('Content-Type: text/html; charset=utf-8');
echo '<!DOCTYPE html><html><head><meta charset="utf-8">';
@@ -2905,7 +2916,7 @@ class MokoWaaS extends CMSPlugin
echo '<h1>' . htmlspecialchars($brandName) . '</h1>';
echo '<p>' . htmlspecialchars($message) . '</p>';
echo '</div></body></html>';
$this->app->close();
die();
}
}