                                                                                                                                                                                
                                                                                                                                                                                
sessiongc.xml                                                                                       0000705                 00000004340 15242100754 0007262 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?xml version="1.0" encoding="utf-8"?>
<extension version="3.8" type="plugin" group="system" method="upgrade">
	<name>plg_system_sessiongc</name>
	<author>Joomla! Project</author>
	<creationDate>February 2018</creationDate>
	<copyright>(C) 2018 Open Source Matters, Inc.</copyright>
	<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
	<authorEmail>admin@joomla.org</authorEmail>
	<authorUrl>www.joomla.org</authorUrl>
	<version>3.8.6</version>
	<description>PLG_SYSTEM_SESSIONGC_XML_DESCRIPTION</description>
	<files>
		<filename plugin="sessiongc">sessiongc.php</filename>
	</files>
	<languages folder="language">
		<language tag="en-GB">en-GB/en-GB.plg_system_sessiongc.ini</language>
		<language tag="en-GB">en-GB/en-GB.plg_system_sessiongc.sys.ini</language>
	</languages>
	<config>
		<fields name="params">
			<fieldset name="basic">
				<field
					name="enable_session_gc"
					type="radio"
					label="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_GC_LABEL"
					description="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_GC_DESC"
					class="btn-group btn-group-yesno"
					default="1"
					filter="uint"
					>
					<option value="1">JYES</option>
					<option value="0">JNO</option>
				</field>

				<field
					name="enable_session_metadata_gc"
					type="radio"
					label="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_METADATA_GC_LABEL"
					description="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_METADATA_GC_DESC"
					class="btn-group btn-group-yesno"
					default="1"
					filter="uint"
					>
					<option value="1">JYES</option>
					<option value="0">JNO</option>
				</field>

				<field
					name="gc_probability"
					type="number"
					label="PLG_SYSTEM_SESSIONGC_GC_PROBABILITY_LABEL"
					description="PLG_SYSTEM_SESSIONGC_GC_PROBABILITY_DESC"
					filter="uint"
					validate="number"
					min="1"
					default="1"
					showon="enable_session_gc:1[OR]enable_session_metadata_gc:1"
				/>

				<field
					name="gc_divisor"
					type="number"
					label="PLG_SYSTEM_SESSIONGC_GC_DIVISOR_LABEL"
					description="PLG_SYSTEM_SESSIONGC_GC_DIVISOR_DESC"
					filter="uint"
					validate="number"
					min="1"
					default="100"
					showon="enable_session_gc:1[OR]enable_session_metadata_gc:1"
				/>
			</fieldset>
		</fields>
	</config>
</extension>
                                                                                                                                                                                                                                                                                                sessiongc.php                                                                                       0000705                 00000003311 15242100754 0007246 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
/**
 * @package     Joomla.Plugin
 * @subpackage  System.sessiongc
 *
 * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\MetadataManager;

/**
 * Garbage collection handler for session related data
 *
 * @since  3.8.6
 */
class PlgSystemSessionGc extends CMSPlugin
{
	/**
	 * Application object
	 *
	 * @var    CMSApplication
	 * @since  3.8.6
	 */
	protected $app;

	/**
	 * Database driver
	 *
	 * @var    JDatabaseDriver
	 * @since  3.8.6
	 */
	protected $db;

	/**
	 * Runs after the HTTP response has been sent to the client and performs garbage collection tasks
	 *
	 * @return  void
	 *
	 * @since   3.8.6
	 */
	public function onAfterRespond()
	{
		$session = Factory::getSession();

		if ($this->params->get('enable_session_gc', 1))
		{
			$probability = $this->params->get('gc_probability', 1);
			$divisor     = $this->params->get('gc_divisor', 100);

			$random = $divisor * lcg_value();

			if ($probability > 0 && $random < $probability)
			{
				$session->gc();
			}
		}

		if ($this->app->get('session_handler', 'none') !== 'database' && $this->params->get('enable_session_metadata_gc', 1))
		{
			$probability = $this->params->get('gc_probability', 1);
			$divisor     = $this->params->get('gc_divisor', 100);

			$random = $divisor * lcg_value();

			if ($probability > 0 && $random < $probability)
			{
				$metadataManager = new MetadataManager($this->app, $this->db);
				$metadataManager->deletePriorTo(time() - $session->getExpire());
			}
		}
	}
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       