2026-02-26 20:22:24 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2026-05-23 22:41:46 -05:00
|
|
|
* @package MokoWaaS
|
|
|
|
|
* @subpackage pkg_mokowaas
|
|
|
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
|
|
|
|
* @license GNU General Public License version 3 or later; see LICENSE
|
2026-02-26 20:22:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
|
use Joomla\CMS\Installer\InstallerAdapter;
|
|
|
|
|
use Joomla\CMS\Log\Log;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-05-23 22:41:46 -05:00
|
|
|
* Package installation script for MokoWaaS.
|
2026-02-26 20:22:24 +00:00
|
|
|
*
|
2026-05-24 03:46:05 -05:00
|
|
|
* Handles migration from standalone plugin to package, enables plugins,
|
|
|
|
|
* and triggers heartbeat registration on install/update.
|
2026-02-26 20:22:24 +00:00
|
|
|
*
|
2026-05-23 22:41:46 -05:00
|
|
|
* @since 2.2.0
|
2026-02-26 20:22:24 +00:00
|
|
|
*/
|
2026-05-23 22:41:46 -05:00
|
|
|
class Pkg_MokowaasInstallerScript
|
2026-02-26 20:22:24 +00:00
|
|
|
{
|
|
|
|
|
/**
|
2026-05-23 22:41:46 -05:00
|
|
|
* Runs after package installation/update.
|
2026-02-26 20:22:24 +00:00
|
|
|
*
|
2026-05-23 22:41:46 -05:00
|
|
|
* @param string $type Installation type
|
|
|
|
|
* @param InstallerAdapter $parent Parent installer
|
2026-04-07 16:11:21 -05:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
2026-05-23 22:41:46 -05:00
|
|
|
* @since 2.2.0
|
2026-04-07 16:11:21 -05:00
|
|
|
*/
|
2026-05-23 22:41:46 -05:00
|
|
|
public function postflight($type, $parent)
|
2026-04-07 16:11:21 -05:00
|
|
|
{
|
2026-05-30 14:02:39 -05:00
|
|
|
// Remove legacy extensions from before the package rewrite
|
|
|
|
|
$this->cleanupLegacyExtensions();
|
|
|
|
|
|
2026-05-24 03:46:05 -05:00
|
|
|
$this->enablePlugin('system', 'mokowaas');
|
2026-06-02 08:12:26 -05:00
|
|
|
$this->enablePlugin('system', 'mokowaas_firewall');
|
|
|
|
|
$this->enablePlugin('system', 'mokowaas_tenant');
|
|
|
|
|
$this->enablePlugin('system', 'mokowaas_devtools');
|
|
|
|
|
$this->enablePlugin('system', 'mokowaas_monitor');
|
2026-05-24 03:46:05 -05:00
|
|
|
$this->enablePlugin('webservices', 'mokowaas');
|
2026-05-30 12:50:11 -05:00
|
|
|
$this->enablePlugin('task', 'mokowaasdemo');
|
2026-05-30 22:45:54 -05:00
|
|
|
$this->enablePlugin('task', 'mokowaassync');
|
2026-05-24 03:46:05 -05:00
|
|
|
|
2026-06-02 08:12:26 -05:00
|
|
|
// Migrate params from core plugin to feature plugins (one-time)
|
|
|
|
|
$this->migrateFeatureParams();
|
|
|
|
|
|
2026-06-02 08:53:47 -05:00
|
|
|
// Set up cpanel module on the admin dashboard
|
|
|
|
|
$this->setupCpanelModule();
|
|
|
|
|
|
2026-05-24 03:53:33 -05:00
|
|
|
// Mark MokoWaaS extensions as protected (prevents disable/uninstall at framework level)
|
|
|
|
|
$this->protectExtensions();
|
|
|
|
|
|
2026-05-31 11:23:54 -05:00
|
|
|
// Clean up stale/duplicate update sites
|
|
|
|
|
$this->cleanupStaleUpdateSites();
|
|
|
|
|
|
2026-05-24 03:46:05 -05:00
|
|
|
// Trigger heartbeat registration
|
|
|
|
|
$this->sendHeartbeat();
|
2026-04-07 16:22:01 -05:00
|
|
|
}
|
|
|
|
|
|
2026-05-30 14:02:39 -05:00
|
|
|
/**
|
|
|
|
|
* Remove legacy/stale extension entries and filesystem remnants.
|
|
|
|
|
*
|
|
|
|
|
* The old standalone plugin was named "mokowaasbrand" (plg_system_mokowaasbrand).
|
|
|
|
|
* After the rewrite into the pkg_mokowaas package, the old entries and files
|
|
|
|
|
* may linger — especially on sites restored from old backups.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @since 02.21.00
|
|
|
|
|
*/
|
|
|
|
|
private function cleanupLegacyExtensions(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
|
|
|
|
|
|
|
|
|
// Legacy element names to remove from #__extensions
|
|
|
|
|
$legacy = [
|
|
|
|
|
$db->quote('mokowaasbrand'),
|
|
|
|
|
$db->quote('plg_system_mokowaasbrand'),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Delete from #__extensions
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->delete($db->quoteName('#__extensions'))
|
|
|
|
|
->where($db->quoteName('element') . ' IN (' . implode(',', $legacy) . ')');
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$affected = $db->execute();
|
|
|
|
|
$count = $db->getAffectedRows();
|
|
|
|
|
|
|
|
|
|
// Remove legacy plugin files from the filesystem
|
|
|
|
|
$legacyDirs = [
|
|
|
|
|
JPATH_PLUGINS . '/system/mokowaasbrand',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($legacyDirs as $dir)
|
|
|
|
|
{
|
|
|
|
|
if (is_dir($dir))
|
|
|
|
|
{
|
|
|
|
|
$this->rmdirRecursive($dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($count > 0)
|
|
|
|
|
{
|
|
|
|
|
Factory::getApplication()->enqueueMessage(
|
|
|
|
|
sprintf('Removed %d legacy MokoWaaS extension(s).', $count),
|
|
|
|
|
'message'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Log::add(
|
|
|
|
|
sprintf('Cleaned up %d legacy MokoWaaS extension entries', $count),
|
|
|
|
|
Log::INFO,
|
|
|
|
|
'mokowaas'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
Log::add('Legacy cleanup error: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Recursively remove a directory.
|
|
|
|
|
*
|
|
|
|
|
* @param string $dir Directory path
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @since 02.21.00
|
|
|
|
|
*/
|
|
|
|
|
private function rmdirRecursive(string $dir): void
|
|
|
|
|
{
|
|
|
|
|
$items = new \RecursiveIteratorIterator(
|
|
|
|
|
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
|
|
|
|
|
\RecursiveIteratorIterator::CHILD_FIRST
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($items as $item)
|
|
|
|
|
{
|
|
|
|
|
if ($item->isDir())
|
|
|
|
|
{
|
|
|
|
|
@rmdir($item->getPathname());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
@unlink($item->getPathname());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@rmdir($dir);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 16:28:08 -05:00
|
|
|
/**
|
2026-05-23 22:41:46 -05:00
|
|
|
* Enable a plugin by group and element.
|
2026-04-07 16:39:08 -05:00
|
|
|
*
|
2026-05-23 22:41:46 -05:00
|
|
|
* @param string $group Plugin group
|
|
|
|
|
* @param string $element Plugin element name
|
2026-04-07 16:39:08 -05:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
2026-05-23 22:41:46 -05:00
|
|
|
* @since 2.2.0
|
2026-04-07 16:39:08 -05:00
|
|
|
*/
|
2026-05-23 22:41:46 -05:00
|
|
|
private function enablePlugin(string $group, string $element): void
|
2026-04-07 16:39:08 -05:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-05-23 22:41:46 -05:00
|
|
|
$db = Factory::getDbo();
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__extensions'))
|
|
|
|
|
->set($db->quoteName('enabled') . ' = 1')
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
|
|
|
|
->where($db->quoteName('folder') . ' = ' . $db->quote($group))
|
|
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote($element));
|
|
|
|
|
$db->setQuery($query);
|
2026-05-21 15:42:58 -05:00
|
|
|
$db->execute();
|
|
|
|
|
}
|
2026-05-23 22:41:46 -05:00
|
|
|
catch (\Throwable $e)
|
2026-03-26 13:53:24 -05:00
|
|
|
{
|
2026-05-23 22:41:46 -05:00
|
|
|
Log::add('Error enabling plugin ' . $group . '/' . $element . ': ' . $e->getMessage(), Log::WARNING, 'jerror');
|
2026-03-26 13:53:24 -05:00
|
|
|
}
|
2026-02-26 20:22:24 +00:00
|
|
|
}
|
2026-05-24 03:46:05 -05:00
|
|
|
|
2026-05-24 03:53:33 -05:00
|
|
|
/**
|
|
|
|
|
* Set the protected flag on all MokoWaaS extensions.
|
|
|
|
|
*
|
|
|
|
|
* Joomla's protected flag prevents disabling and uninstalling at the
|
|
|
|
|
* framework level — no plugin-side interception needed.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @since 02.03.10
|
|
|
|
|
*/
|
|
|
|
|
private function protectExtensions(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
2026-05-30 14:02:39 -05:00
|
|
|
|
|
|
|
|
// All MokoWaaS elements: package, system plugin, component,
|
|
|
|
|
// webservices plugins, task plugin
|
|
|
|
|
$elements = [
|
|
|
|
|
$db->quote('pkg_mokowaas'),
|
|
|
|
|
$db->quote('mokowaas'),
|
2026-06-02 08:12:26 -05:00
|
|
|
$db->quote('mokowaas_firewall'),
|
|
|
|
|
$db->quote('mokowaas_tenant'),
|
|
|
|
|
$db->quote('mokowaas_devtools'),
|
|
|
|
|
$db->quote('mokowaas_monitor'),
|
2026-05-30 14:02:39 -05:00
|
|
|
$db->quote('com_mokowaas'),
|
2026-06-02 08:53:47 -05:00
|
|
|
$db->quote('mod_mokowaas_cpanel'),
|
2026-05-30 14:02:39 -05:00
|
|
|
$db->quote('mokowaasdemo'),
|
2026-05-30 22:45:54 -05:00
|
|
|
$db->quote('mokowaassync'),
|
2026-05-30 14:02:39 -05:00
|
|
|
$db->quote('perfectpublisher'),
|
2026-06-02 09:57:49 -05:00
|
|
|
$db->quote('mokoonyx'),
|
2026-05-30 14:02:39 -05:00
|
|
|
];
|
|
|
|
|
|
2026-05-24 03:53:33 -05:00
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__extensions'))
|
|
|
|
|
->set($db->quoteName('protected') . ' = 1')
|
|
|
|
|
->set($db->quoteName('locked') . ' = 0')
|
2026-05-30 14:02:39 -05:00
|
|
|
->where($db->quoteName('element') . ' IN (' . implode(',', $elements) . ')');
|
2026-05-24 03:53:33 -05:00
|
|
|
$db->setQuery($query);
|
|
|
|
|
$db->execute();
|
2026-05-30 14:02:39 -05:00
|
|
|
|
|
|
|
|
// Ensure update server stays enabled
|
|
|
|
|
$this->enableUpdateServer();
|
2026-05-24 03:53:33 -05:00
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
Log::add('Error protecting MokoWaaS extensions: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 11:23:54 -05:00
|
|
|
/**
|
|
|
|
|
* Remove stale and duplicate MokoWaaS update site entries.
|
|
|
|
|
*
|
|
|
|
|
* Keeps only the package-level update site pointing to the dynamic
|
|
|
|
|
* MokoGitea endpoint. Removes plugin-level entries, old static URLs,
|
|
|
|
|
* and orphaned #__updates rows tied to deleted update sites.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
2026-05-31 12:40:05 -05:00
|
|
|
* @since 02.31.00
|
2026-05-31 11:23:54 -05:00
|
|
|
*/
|
|
|
|
|
private function cleanupStaleUpdateSites(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
2026-06-02 08:12:26 -05:00
|
|
|
$dynamicUrl = 'https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/updates.xml';
|
2026-05-31 11:23:54 -05:00
|
|
|
|
|
|
|
|
// Find all MokoWaaS update sites
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->select($db->quoteName(['update_site_id', 'location']))
|
|
|
|
|
->from($db->quoteName('#__update_sites'))
|
|
|
|
|
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoWaaS%')
|
|
|
|
|
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoWaaS%') . ')');
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$sites = $db->loadObjectList();
|
|
|
|
|
|
|
|
|
|
$keepId = null;
|
|
|
|
|
$removeIds = [];
|
|
|
|
|
|
|
|
|
|
foreach ($sites as $site)
|
|
|
|
|
{
|
|
|
|
|
if ($site->location === $dynamicUrl && $keepId === null)
|
|
|
|
|
{
|
|
|
|
|
$keepId = (int) $site->update_site_id;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$removeIds[] = (int) $site->update_site_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($removeIds))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$idList = implode(',', $removeIds);
|
|
|
|
|
|
|
|
|
|
// Remove orphaned #__updates rows
|
|
|
|
|
$db->setQuery(
|
|
|
|
|
$db->getQuery(true)
|
|
|
|
|
->delete($db->quoteName('#__updates'))
|
|
|
|
|
->where($db->quoteName('update_site_id') . ' IN (' . $idList . ')')
|
|
|
|
|
)->execute();
|
|
|
|
|
|
|
|
|
|
// Remove link rows
|
|
|
|
|
$db->setQuery(
|
|
|
|
|
$db->getQuery(true)
|
|
|
|
|
->delete($db->quoteName('#__update_sites_extensions'))
|
|
|
|
|
->where($db->quoteName('update_site_id') . ' IN (' . $idList . ')')
|
|
|
|
|
)->execute();
|
|
|
|
|
|
|
|
|
|
// Remove stale update sites
|
|
|
|
|
$db->setQuery(
|
|
|
|
|
$db->getQuery(true)
|
|
|
|
|
->delete($db->quoteName('#__update_sites'))
|
|
|
|
|
->where($db->quoteName('update_site_id') . ' IN (' . $idList . ')')
|
|
|
|
|
)->execute();
|
|
|
|
|
|
|
|
|
|
$count = count($removeIds);
|
|
|
|
|
|
|
|
|
|
if ($count > 0)
|
|
|
|
|
{
|
|
|
|
|
Factory::getApplication()->enqueueMessage(
|
|
|
|
|
sprintf('Cleaned up %d stale MokoWaaS update site(s).', $count),
|
|
|
|
|
'message'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
Log::add('Error cleaning up stale update sites: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 14:02:39 -05:00
|
|
|
/**
|
2026-05-31 10:36:53 -05:00
|
|
|
* Ensure the MokoWaaS update server entry stays enabled and points
|
|
|
|
|
* to the correct dynamic endpoint with the license key attached.
|
2026-05-30 14:02:39 -05:00
|
|
|
*
|
2026-05-31 10:36:53 -05:00
|
|
|
* Migrates legacy static URLs (raw/branch/main/updates.xml) to the
|
|
|
|
|
* dynamic MokoGitea update feed, and syncs the license key from
|
|
|
|
|
* plugin params into extra_query so Joomla sends it as dlid.
|
2026-05-30 14:02:39 -05:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @since 02.21.00
|
|
|
|
|
*/
|
|
|
|
|
private function enableUpdateServer(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
|
|
|
|
|
2026-06-02 08:12:26 -05:00
|
|
|
$staticUrl = 'https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/updates.xml';
|
|
|
|
|
|
|
|
|
|
// Migrate old dynamic URL to static raw file URL
|
2026-05-31 10:36:53 -05:00
|
|
|
$db->setQuery(
|
|
|
|
|
$db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__update_sites'))
|
2026-06-02 08:12:26 -05:00
|
|
|
->set($db->quoteName('location') . ' = ' . $db->quote($staticUrl))
|
|
|
|
|
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoWaaS%')
|
|
|
|
|
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoWaaS%') . ')')
|
|
|
|
|
->where($db->quoteName('location') . ' != ' . $db->quote($staticUrl))
|
2026-05-31 10:36:53 -05:00
|
|
|
);
|
|
|
|
|
$db->execute();
|
|
|
|
|
|
|
|
|
|
// Enable all MokoWaaS update sites
|
2026-05-30 14:02:39 -05:00
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__update_sites'))
|
|
|
|
|
->set($db->quoteName('enabled') . ' = 1')
|
|
|
|
|
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoWaaS%')
|
|
|
|
|
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoWaaS%') . ')');
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$db->execute();
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
Log::add('Error enabling update server: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 03:46:05 -05:00
|
|
|
/**
|
|
|
|
|
* Send heartbeat to the MokoWaaS monitoring receiver.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @since 02.03.08
|
|
|
|
|
*/
|
|
|
|
|
private function sendHeartbeat(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->select($db->quoteName('params'))
|
|
|
|
|
->from($db->quoteName('#__extensions'))
|
|
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote('mokowaas'))
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
|
|
|
|
->where($db->quoteName('folder') . ' = ' . $db->quote('system'));
|
|
|
|
|
$params = json_decode((string) $db->setQuery($query)->loadResult());
|
|
|
|
|
|
|
|
|
|
$healthToken = $params->health_api_token ?? '';
|
|
|
|
|
|
|
|
|
|
if (empty($healthToken))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$siteUrl = rtrim(\Joomla\CMS\Uri\Uri::root(), '/');
|
|
|
|
|
$siteName = Factory::getConfig()->get('sitename', 'Joomla');
|
|
|
|
|
|
|
|
|
|
$payload = json_encode([
|
|
|
|
|
'site_url' => $siteUrl,
|
|
|
|
|
'site_name' => $siteName,
|
|
|
|
|
'health_token' => $healthToken,
|
|
|
|
|
'action' => 'register',
|
|
|
|
|
], JSON_UNESCAPED_SLASHES);
|
|
|
|
|
|
|
|
|
|
$ch = curl_init('https://bench.mokoconsulting.tech/api/waas-heartbeat/register');
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
|
|
'Content-Type: application/json',
|
|
|
|
|
'X-MokoWaaS-Key: moko-waas-hb-2026-x9k4m',
|
|
|
|
|
]);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
|
|
if ($code >= 200 && $code < 300)
|
|
|
|
|
{
|
|
|
|
|
Factory::getApplication()->enqueueMessage('Grafana heartbeat: site registered', 'message');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
// Silent failure — heartbeat is non-critical
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-02 08:12:26 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* One-time migration of params from the monolithic core plugin to
|
|
|
|
|
* the new feature plugins. Copies security, tenant, and dev params.
|
2026-06-02 08:53:47 -05:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @since 02.32.00
|
|
|
|
|
*/
|
|
|
|
|
private function setupCpanelModule(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
|
|
|
|
|
|
|
|
|
// Enable the module
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__extensions'))
|
|
|
|
|
->set($db->quoteName('enabled') . ' = 1')
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('module'))
|
|
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote('mod_mokowaas_cpanel'));
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$db->execute();
|
|
|
|
|
|
|
|
|
|
// Check if a module instance already exists in #__modules
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->select('COUNT(*)')
|
|
|
|
|
->from($db->quoteName('#__modules'))
|
|
|
|
|
->where($db->quoteName('module') . ' = ' . $db->quote('mod_mokowaas_cpanel'));
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
|
|
|
|
|
if ((int) $db->loadResult() > 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the module instance on the cpanel position
|
|
|
|
|
$module = (object) [
|
|
|
|
|
'title' => 'MokoWaaS',
|
|
|
|
|
'note' => '',
|
|
|
|
|
'content' => '',
|
2026-06-02 09:08:25 -05:00
|
|
|
'ordering' => 0,
|
2026-06-02 09:24:00 -05:00
|
|
|
'position' => 'top',
|
2026-06-02 08:53:47 -05:00
|
|
|
'checked_out' => null,
|
|
|
|
|
'checked_out_time' => null,
|
|
|
|
|
'publish_up' => null,
|
|
|
|
|
'publish_down' => null,
|
|
|
|
|
'published' => 1,
|
|
|
|
|
'module' => 'mod_mokowaas_cpanel',
|
2026-06-02 09:07:57 -05:00
|
|
|
'access' => 6, // Super Users only
|
2026-06-02 08:53:47 -05:00
|
|
|
'showtitle' => 1,
|
|
|
|
|
'params' => '{"show_health":"1","show_plugins":"1"}',
|
|
|
|
|
'client_id' => 1, // Administrator
|
|
|
|
|
'language' => '*',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$db->insertObject('#__modules', $module, 'id');
|
|
|
|
|
$moduleId = (int) $module->id;
|
|
|
|
|
|
|
|
|
|
if ($moduleId)
|
|
|
|
|
{
|
|
|
|
|
// Assign to all admin pages
|
|
|
|
|
$map = (object) [
|
|
|
|
|
'moduleid' => $moduleId,
|
|
|
|
|
'menuid' => 0, // 0 = all pages
|
|
|
|
|
];
|
|
|
|
|
$db->insertObject('#__modules_menu', $map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
Log::add('CPanel module setup error: ' . $e->getMessage(), Log::WARNING, 'mokowaas');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* One-time migration of params from the monolithic core plugin to
|
|
|
|
|
* the new feature plugins. Copies security, tenant, and dev params.
|
2026-06-02 08:12:26 -05:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @since 02.32.00
|
|
|
|
|
*/
|
|
|
|
|
private function migrateFeatureParams(): void
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
|
|
|
|
|
|
|
|
|
// Read core plugin params
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->select($db->quoteName('params'))
|
|
|
|
|
->from($db->quoteName('#__extensions'))
|
|
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote('mokowaas'))
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
|
|
|
|
->where($db->quoteName('folder') . ' = ' . $db->quote('system'));
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$coreParamsJson = (string) $db->loadResult();
|
|
|
|
|
|
|
|
|
|
if (empty($coreParamsJson) || $coreParamsJson === '{}')
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$core = json_decode($coreParamsJson, true);
|
|
|
|
|
|
|
|
|
|
if (empty($core))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check migration marker
|
|
|
|
|
if (!empty($core['_params_migrated_032']))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Firewall params
|
|
|
|
|
$firewallKeys = [
|
|
|
|
|
'force_https', 'admin_session_timeout', 'trusted_ips',
|
|
|
|
|
'password_min_length', 'password_require_uppercase',
|
|
|
|
|
'password_require_number', 'password_require_special',
|
|
|
|
|
'upload_allowed_types', 'upload_max_size_mb',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Tenant params
|
|
|
|
|
$tenantKeys = [
|
|
|
|
|
'restrict_installer', 'allow_extension_updates', 'hide_sysinfo',
|
|
|
|
|
'restrict_global_config', 'restrict_template_editing',
|
|
|
|
|
'disable_install_url', 'hidden_menu_items',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// DevTools params
|
|
|
|
|
$devtoolsKeys = ['dev_mode', 'reset_hits', 'delete_versions'];
|
|
|
|
|
|
|
|
|
|
$migrations = [
|
|
|
|
|
'mokowaas_firewall' => $firewallKeys,
|
|
|
|
|
'mokowaas_tenant' => $tenantKeys,
|
|
|
|
|
'mokowaas_devtools' => $devtoolsKeys,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($migrations as $element => $keys)
|
|
|
|
|
{
|
|
|
|
|
$featureParams = [];
|
|
|
|
|
|
|
|
|
|
foreach ($keys as $key)
|
|
|
|
|
{
|
|
|
|
|
if (isset($core[$key]))
|
|
|
|
|
{
|
|
|
|
|
$featureParams[$key] = $core[$key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($featureParams))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$db->setQuery(
|
|
|
|
|
$db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__extensions'))
|
|
|
|
|
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($featureParams)))
|
|
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote($element))
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
|
|
|
|
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
|
|
|
|
|
)->execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set migration marker on core plugin
|
|
|
|
|
$core['_params_migrated_032'] = 1;
|
|
|
|
|
$db->setQuery(
|
|
|
|
|
$db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__extensions'))
|
|
|
|
|
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($core)))
|
|
|
|
|
->where($db->quoteName('element') . ' = ' . $db->quote('mokowaas'))
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
|
|
|
|
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
|
|
|
|
|
)->execute();
|
|
|
|
|
|
|
|
|
|
Factory::getApplication()->enqueueMessage(
|
|
|
|
|
'MokoWaaS: migrated settings to feature plugins (Firewall, Tenant, DevTools).',
|
|
|
|
|
'message'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
catch (\Throwable $e)
|
|
|
|
|
{
|
|
|
|
|
Log::add('Feature param migration error: ' . $e->getMessage(), Log::WARNING, 'mokowaas');
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-26 20:22:24 +00:00
|
|
|
}
|