Current Directory: /home/astoriaah/www/plugins/system/admintools/feature
Viewing File: /home/astoriaah/www/plugins/system/admintools/feature/emailonlogin.php
<?php
/**
* @package admintools
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
defined('_JEXEC') || die;
class AtsystemFeatureEmailonlogin extends AtsystemFeatureAbstract
{
protected $loadOrder = 220;
/**
* Is this feature enabled?
*
* @return bool
*/
public function isEnabled()
{
if (!$this->container->platform->isBackend())
{
return false;
}
if ($this->isAdminAccessAttempt())
{
return false;
}
$user = $this->container->platform->getUser();
if ($user->guest)
{
return false;
}
$email = $this->cparams->getValue('emailonadminlogin', '');
return !empty($email);
}
/**
* Sends an email upon accessing an administrator page other than the login screen
*/
public function onAfterInitialise()
{
// Check if the session flag is set (avoid sending thousands of emails!)
$flag = $this->container->platform->getSessionVar('waf.loggedin', 0, 'plg_admintools');
if ($flag == 1)
{
return true;
}
// Set the flag to prevent sending more emails
$this->container->platform->setSessionVar('waf.loggedin', 1, 'plg_admintools');
// Load the component's administrator translation files
$jlang = Factory::getLanguage();
$jlang->load('com_admintools', JPATH_ADMINISTRATOR, 'en-GB', true);
$jlang->load('com_admintools', JPATH_ADMINISTRATOR, $jlang->getDefault(), true);
$jlang->load('com_admintools', JPATH_ADMINISTRATOR, null, true);
// Get the site name
$config = $this->container->platform->getConfig();
// Construct the replacement table
$substitutions = $this->exceptionsHandler->getEmailVariables(Text::_('COM_ADMINTOOLS_WAFEMAILTEMPLATE_REASON_ADMINLOGINSUCCESS'));
// Let's get the most suitable email template
$template = $this->exceptionsHandler->getEmailTemplate('adminloginsuccess', true);
// Got no template, the user didn't published any email template, or the template doesn't want us to
// send a notification email. Anyway, let's stop here.
if (!$template)
{
return true;
}
else
{
$subject = $template[0];
$body = $template[1];
}
foreach ($substitutions as $k => $v)
{
$subject = str_replace($k, $v, $subject);
$body = str_replace($k, $v, $body);
}
// Send the email
try
{
$mailer = Factory::getMailer();
$mailfrom = $config->get('mailfrom');
$fromname = $config->get('fromname');
$recipients = explode(',', $this->cparams->getValue('emailonadminlogin', ''));
$recipients = array_map('trim', $recipients);
foreach ($recipients as $recipient)
{
if (empty($recipient))
{
continue;
}
// This line is required because SpamAssassin is BROKEN
$mailer->Priority = 3;
$mailer->isHtml(true);
$mailer->setSender([$mailfrom, $fromname]);
// Resets the recipients, otherwise they will pile up
$mailer->clearAllRecipients();
if ($mailer->addRecipient($recipient) === false)
{
// Failed to add a recipient?
continue;
}
$mailer->setSubject($subject);
$mailer->setBody($body);
$mailer->Send();
}
}
catch (Exception $e)
{
// Joomla! 3.5 and later throw an exception when crap happens instead of suppressing it and returning false
}
return true;
}
}