<?php
/**
 * @package     VikRentItems
 * @subpackage  com_vikrentitems
 * @author      Alessio Gaggii - E4J srl
 * @copyright   Copyright (C) 2023 E4J srl. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE
 * @link        https://e4j.com
 */

// No direct access to this file
defined('ABSPATH') or die('No script kiddies please!');

/**
 * VikRentItems license controller.
 *
 * @since 	1.7.3 (J) - 1.2.0 (WP)
 */
class VikRentItemsControllerLicense extends JControllerAdmin
{
	/**
	 * Forcing the hash to be valid is useless.
	 */
	public function pingback()
	{
		$app = JFactory::getApplication();

		if (defined('ABSPATH') && function_exists('wp_die'))
		{
			// update license hash
			VikRentItemsLoader::import('update.license');
			$storedHash = VikRentItemsLicense::getHash();
		}
		else
		{
			// fetch hash generated during the first license validation
			$storedHash = VRIFactory::getConfig()->get('licensehash');
		}

		if (!$storedHash)
		{
			// hash not yet stored
			$app->close();
		}

		// recover hash sent by the server
		$serverHash = $app->input->getString('hash');

		// the received hash must be equals to the stored one
		if (strcmp($serverHash, $storedHash))
		{
			VRIHttpDocument::getInstance($app)->close(403, 'Hash mismatch.');
		}
		
		// hash validated successfully
		$app->close();
	}
}
