first commit
This commit is contained in:
9
plugins/quickicon/akeebabackup/.htaccess
Normal file
9
plugins/quickicon/akeebabackup/.htaccess
Normal file
@@ -0,0 +1,9 @@
|
||||
<IfModule !mod_authz_core.c>
|
||||
Order deny,allow
|
||||
Deny from all
|
||||
</IfModule>
|
||||
<IfModule mod_authz_core.c>
|
||||
<RequireAll>
|
||||
Require all denied
|
||||
</RequireAll>
|
||||
</IfModule>
|
||||
86
plugins/quickicon/akeebabackup/akeebabackup.xml
Normal file
86
plugins/quickicon/akeebabackup/akeebabackup.xml
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--~
|
||||
~ @package akeebabackup
|
||||
~ @copyright Copyright (c)2006-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
~ @license GNU General Public License version 3, or later
|
||||
-->
|
||||
|
||||
<extension type="plugin" group="quickicon" method="upgrade">
|
||||
<name>PLG_QUICKICON_AKEEBABACKUP</name>
|
||||
<version>9.4.4</version>
|
||||
<creationDate>2022-11-30</creationDate>
|
||||
<author>Nicholas K. Dionysopoulos</author>
|
||||
<authorEmail>nicholas@dionysopoulos.me</authorEmail>
|
||||
<authorUrl>https://www.akeeba.com</authorUrl>
|
||||
<copyright>Copyright (c)2006-2022 Nicholas K. Dionysopoulos</copyright>
|
||||
<license>GNU General Public License version 3, or later</license>
|
||||
<description>PLG_QUICKICON_AKEEBABACKUP_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Quickicon\AkeebaBackup</namespace>
|
||||
|
||||
<files>
|
||||
<folder plugin="akeebabackup">services</folder>
|
||||
<folder>src</folder>
|
||||
|
||||
<filename>.htaccess</filename>
|
||||
<filename>web.config</filename>
|
||||
</files>
|
||||
|
||||
<media destination="plg_quickicon_akeebabackup" folder="media">
|
||||
<folder>css</folder>
|
||||
|
||||
<file>joomla.asset.json</file>
|
||||
</media>
|
||||
|
||||
<languages folder="language">
|
||||
<language tag="en-GB">en-GB/plg_quickicon_akeebabackup.ini</language>
|
||||
<language tag="en-GB">en-GB/plg_quickicon_akeebabackup.sys.ini</language>
|
||||
</languages>
|
||||
|
||||
<config addfieldpath="/administrator/components/com_akeebabackup/src/Field"
|
||||
addfieldprefix="Akeeba\Component\AkeebaBackup\Administrator\Field"
|
||||
>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field name="enablewarning"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_QUICKICON_AKEEBABACKUP_LBL_WARNINGS"
|
||||
description="PLG_QUICKICON_AKEEBABACKUP_DESC_WARNINGS"
|
||||
default="1"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field name="warnfailed"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_QUICKICON_AKEEBABACKUP_LBL_WARNFAILED"
|
||||
description="PLG_QUICKICON_AKEEBABACKUP_DESC_WARNFAILED"
|
||||
default="1"
|
||||
showon="enablewarning:1"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field name="maxbackupperiod"
|
||||
type="number"
|
||||
label="PLG_QUICKICON_AKEEBABACKUP_LBL_PERIOD"
|
||||
description="PLG_QUICKICON_AKEEBABACKUP_DESC_PERIOD"
|
||||
min="1"
|
||||
max="87600"
|
||||
step="1"
|
||||
default="24"/>
|
||||
|
||||
<field name="profileid"
|
||||
type="backupprofiles"
|
||||
default="1"
|
||||
label="PLG_QUICKICON_AKEEBABACKUP_PROFILE_LABEL"
|
||||
class="advancedSelect"
|
||||
description="PLG_QUICKICON_AKEEBABACKUP_PROFILE_DESC"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
55
plugins/quickicon/akeebabackup/services/provider.php
Normal file
55
plugins/quickicon/akeebabackup/services/provider.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* @package akeebabackup
|
||||
* @copyright Copyright (c)2006-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Extension\PluginInterface;
|
||||
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Quickicon\AkeebaBackup\Extension\AkeebaBackup;
|
||||
|
||||
return new class implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->registerServiceProvider(new MVCFactory('Akeeba\\Component\\AkeebaBackup'));
|
||||
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container)
|
||||
{
|
||||
$config = (array) PluginHelper::getPlugin('quickicon', 'akeebabackup');
|
||||
|
||||
$plugin = new AkeebaBackup(
|
||||
$container->get(DispatcherInterface::class),
|
||||
Factory::getApplication()->getDocument(),
|
||||
$config
|
||||
);
|
||||
|
||||
$plugin->setMVCFactory($container->get(MVCFactoryInterface::class));
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
$plugin->setDatabase($container->get('DatabaseDriver'));
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
245
plugins/quickicon/akeebabackup/src/Extension/AkeebaBackup.php
Normal file
245
plugins/quickicon/akeebabackup/src/Extension/AkeebaBackup.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* @package akeebabackup
|
||||
* @copyright Copyright (c)2006-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Quickicon\AkeebaBackup\Extension;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use Akeeba\Component\AkeebaBackup\Administrator\Model\StatisticsModel;
|
||||
use Akeeba\Engine\Factory;
|
||||
use Akeeba\Engine\Platform;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Date\Date;
|
||||
use Joomla\CMS\Document\Document;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryAwareTrait;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Database\DatabaseAwareInterface;
|
||||
use Joomla\Database\DatabaseAwareTrait;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
use Joomla\Module\Quickicon\Administrator\Event\QuickIconsEvent;
|
||||
|
||||
class AkeebaBackup extends CMSPlugin implements SubscriberInterface, DatabaseAwareInterface
|
||||
{
|
||||
use DatabaseAwareTrait;
|
||||
use MVCFactoryAwareTrait;
|
||||
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* The document.
|
||||
*
|
||||
* @var Document
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $document;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DispatcherInterface $subject The object to observe
|
||||
* @param Document $document The document
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'group', 'params', 'language'
|
||||
* (this list is not meant to be comprehensive).
|
||||
*
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function __construct(DispatcherInterface $subject, Document $document, array $config = [])
|
||||
{
|
||||
parent::__construct($subject, $config);
|
||||
|
||||
$this->document = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of events this subscriber will listen to.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
// Only subscribe events if the component is installed and enabled
|
||||
if (!ComponentHelper::isEnabled('com_akeebabackup'))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'onGetIcons' => 'getAkeebaBackupStatus',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the Quick Icons module is constructing its set
|
||||
* of icons. You can return an array which defines a single icon and it will
|
||||
* be rendered right after the stock Quick Icons.
|
||||
*
|
||||
* @param QuickIconsEvent $event The event object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function getAkeebaBackupStatus(QuickIconsEvent $event)
|
||||
{
|
||||
$context = $event->getContext();
|
||||
|
||||
$user = $this->getApplication()->getIdentity();
|
||||
if ($context !== 'update_quickicon' || !$user->authorise('core.manage', 'com_installer'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the Akeeba Engine, if required
|
||||
if (!defined('AKEEBAENGINE'))
|
||||
{
|
||||
// Necessary defines for Akeeba Engine
|
||||
define('AKEEBAENGINE', 1);
|
||||
define('AKEEBAROOT', JPATH_ADMINISTRATOR . '/components/com_akeebabackup/engine');
|
||||
|
||||
// Make sure we have a profile set throughout the component's lifetime
|
||||
$profile_id = $this->getApplication()->getSession()->get('akeebebackup.profile');
|
||||
|
||||
if (is_null($profile_id))
|
||||
{
|
||||
$this->getApplication()->getSession()->set('akeebabackup.profile', 1);
|
||||
}
|
||||
|
||||
// Is Akeeba Engine available?
|
||||
$engineFactoryFile = AKEEBAROOT . '/Factory.php';
|
||||
|
||||
if (!file_exists($engineFactoryFile) || !is_readable($engineFactoryFile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to load the Akeeba Engine
|
||||
@include_once $engineFactoryFile;
|
||||
|
||||
if (!class_exists('Akeeba\Engine\Factory'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Platform::addPlatform('joomla', JPATH_ADMINISTRATOR . '/components/com_akeebabackup/platform/Joomla');
|
||||
|
||||
// !!! IMPORTANT !!! DO NOT REMOVE! This triggers Akeeba Engine's autoloader. Without it the next line fails!
|
||||
$DO_NOT_REMOVE = Platform::getInstance();
|
||||
|
||||
// Set the DBO to the Akeeba Engine platform for Joomla
|
||||
Platform\Joomla::setDbDriver($this->getDatabase());
|
||||
}
|
||||
|
||||
// Set up the default icon
|
||||
$url = Uri::base();
|
||||
$url = rtrim($url, '/');
|
||||
|
||||
$profileId = (int) $this->params->get('profileid', 1);
|
||||
$token = $this->getApplication()->getSession()->getToken();
|
||||
|
||||
if ($profileId <= 0)
|
||||
{
|
||||
$profileId = 1;
|
||||
}
|
||||
|
||||
$ret = [
|
||||
'link' => Route::_('index.php?option=com_akeebabackup&view=Backup&autostart=1&returnurl=' . base64_encode($url) . '&profileid=' . $profileId . "&$token=1"),
|
||||
'image' => 'icon-akeebabackup',
|
||||
'icon' => '',
|
||||
'text' => Text::_('PLG_QUICKICON_AKEEBABACKUP_OK'),
|
||||
'class' => 'success',
|
||||
'id' => 'plg_quickicon_akeebabackup',
|
||||
'group' => 'MOD_QUICKICON_MAINTENANCE',
|
||||
];
|
||||
|
||||
// Do I need to parse backup warnings?
|
||||
if ($this->params->get('enablewarning', 0) == 0)
|
||||
{
|
||||
// Do not remove; required to load the Akeeba Engine configuration
|
||||
$engineConfig = Factory::getConfiguration();
|
||||
Platform::getInstance()->load_configuration(1);
|
||||
|
||||
// Get the latest backup ID
|
||||
$filters = [
|
||||
[
|
||||
'field' => 'tag',
|
||||
'operand' => '<>',
|
||||
'value' => 'restorepoint',
|
||||
],
|
||||
];
|
||||
$ordering = [
|
||||
'by' => 'backupstart',
|
||||
'order' => 'DESC',
|
||||
];
|
||||
|
||||
/** @var StatisticsModel $model */
|
||||
$model = $this->getMVCFactory()->createModel('Statistics', 'Administrator');
|
||||
$list = $model->getStatisticsListWithMeta(false, $filters, $ordering);
|
||||
$record = null;
|
||||
|
||||
if (!empty($list))
|
||||
{
|
||||
$record = (object) array_shift($list);
|
||||
}
|
||||
|
||||
// Warn if there is no backup whatsoever
|
||||
$warning = is_null($record);
|
||||
|
||||
// Process "failed backup" warnings, if specified
|
||||
if ((!is_null($record) && $this->params->get('warnfailed', 0) == 0))
|
||||
{
|
||||
$warning = (($record->status == 'fail') || ($record->status == 'run'));
|
||||
}
|
||||
|
||||
// Process "stale backup" warnings, if necessary
|
||||
if (!$warning && !is_null($record))
|
||||
{
|
||||
$maxperiod = $this->params->get('maxbackupperiod', 24);
|
||||
$lastBackupRaw = $record->backupstart;
|
||||
$lastBackupObject = new Date($lastBackupRaw);
|
||||
$lastBackup = $lastBackupObject->toUnix();
|
||||
$maxBackup = time() - $maxperiod * 3600;
|
||||
$warning = ($lastBackup < $maxBackup);
|
||||
}
|
||||
|
||||
// If we have a warning we need to update the quick icon class and text
|
||||
if ($warning)
|
||||
{
|
||||
$ret['text'] = Text::_('PLG_QUICKICON_AKEEBABACKUP_BACKUPREQUIRED');
|
||||
$ret['class'] = 'danger';
|
||||
}
|
||||
}
|
||||
|
||||
// Load the CSS
|
||||
$this->document->getWebAssetManager()
|
||||
->getRegistry()->addExtensionRegistryFile('plg_quickicon_akeebabackup');
|
||||
$this->document->getWebAssetManager()
|
||||
->useStyle('plg_quickicon_akeebabackup.icons');
|
||||
|
||||
// Add the icon to the result array
|
||||
$result = $event->getArgument('result', []);
|
||||
|
||||
$result[] = [
|
||||
$ret,
|
||||
];
|
||||
|
||||
$event->setArgument('result', $result);
|
||||
}
|
||||
}
|
||||
16
plugins/quickicon/akeebabackup/web.config
Normal file
16
plugins/quickicon/akeebabackup/web.config
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
This only works on IIS 7 or later. See https://www.iis.net/configreference/system.webserver/security/requestfiltering/fileextensions
|
||||
-->
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<security>
|
||||
<requestFiltering>
|
||||
<fileExtensions allowUnlisted="false" >
|
||||
<clear />
|
||||
<add fileExtension=".html" allowed="true"/>
|
||||
</fileExtensions>
|
||||
</requestFiltering>
|
||||
</security>
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user