Your IP : 216.73.216.85


Current Path : /home/smartconb/www/armencom33/administrator/components/com_eyesite/
Upload File :
Current File : /home/smartconb/www/armencom33/administrator/components/com_eyesite/controller.php

<?php
/********************************************************************
Product		: Eyesite
Date		: 11 January 2024
Copyright	: Les Arbres Design 2009-2024
Contact		: https://www.lesarbresdesign.info
Licence		: GNU General Public License
*********************************************************************/
defined('_JEXEC') or die('Restricted Access');

use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;

class EyesiteController extends BaseController
{

var $config_model;
var $app;

function __construct()
{
	parent::__construct();
	$this->registerTask('config_apply', 'config_save');
	$this->config_model = $this->getModel('config');
   	$this->app = Factory::getApplication();
}

function display($cachable = false, $urlparams = false)
{
	$data_model = $this->getModel('data');
	$config_data = $this->config_model->getData();
	require_once JPATH_ADMINISTRATOR.'/components/com_eyesite/helpers/env_check.php';
	LAE_Env_check::environment_check($this->config_model, $config_data);
	$view = $this->getView('main', 'html');
	$view->setModel($data_model);
	$view->display();
}

// if the plugin requests a scan from the back end, it calls the scan function
// this is the plugin Ajax thread so we can just run the scanner here

function scan()
{
	$input = Factory::getApplication()->input;
	LAE_trace::trace("Front end scan requested, GET data: ".print_r($input->post->getArray(),true), true);
	require_once JPATH_ADMINISTRATOR.'/components/com_eyesite/helpers/eyesite_scanner.php';
	require_once JPATH_ADMINISTRATOR.'/components/com_eyesite/models/config.php';
	require_once JPATH_ADMINISTRATOR.'/components/com_eyesite/models/history.php';
	require_once JPATH_ADMINISTRATOR.'/components/com_eyesite/models/data.php';
	$scanner = new LAE_scanner;
	$scanner->scan();
}

// add an Ajax request to the page that will start the scanner
// the request will time out after 1 second, but the scanner will run to completion

function scan_now()
{
    $this->checkToken();
	$secret = $this->app->get('secret');
	$lang = LAE_helper::get_lang_param('CURRENT');
	$url = Uri::root().'index.php?option=com_eyesite&task=scan&entry='.$secret.'&source=admin&format=raw&tmpl=component'.$lang;
	LAE_trace::trace("Admin scan requested: ".$url, true);
    $document = Factory::getDocument();
	$document->addScriptOptions('ey_scan', $url);
    $this->display();
}

function history_list()
{
	$view = $this->getView('history', 'html');
	$history_model = $this->getModel('history');
	$view->setModel($history_model);
	$view->display();
}

function history_item()
{
	$id = $this->input->get('id', '', 'INT');
	$history_model = $this->getModel('history');
	$history_data = $history_model->getOne($id);
	$view = $this->getView('history', 'html');
	$view->history_data = $history_data;
	$view->edit();
}

function history_delete()
{
	self::check_super_user();
    $this->checkToken();
	$history_model = $this->getModel('history');
	$history_model->delete();
	$this->setRedirect('index.php?option=com_eyesite&task=history_list');
}

function history_save()
{
	self::check_super_user();
    $this->checkToken();
	$history_model = $this->getModel('history');
	$id = $this->input->get('id', '', 'INT');
	$summary = $this->input->get('summary', '', 'STRING');
	$history_model->update_summary($id, $summary);
	$this->setRedirect('index.php?option=com_eyesite&task=history_list');
}

function history_reset()
{
	$this->input->set('search', '');
	$this->input->set('history_filter', 0);
	$this->input->set('limitstart', 0);
	$this->history_list();
}

function cancel_to_history_list()
{
	$this->setRedirect('index.php?option=com_eyesite&task=history_list');
}

function configure()
{
	$config_data = $this->config_model->getData();
	$view = $this->getView('config', 'html');
	$view->config_data = $config_data;
	$view->display();
}

function config_save()		// also config_apply
{
	self::check_super_user();
    $this->checkToken();
	$task = $this->input->get('task', '', 'STRING');			// 'config_save' or 'config_apply'
	$old_config_data = clone $this->config_model->getData();	// save the original config
	$post_data = $this->config_model->getPostData();			// get the new config
	$valid = $this->config_model->check();
	if ($valid)
		{
		$stored = $this->config_model->store();
		$diff_text = $this->config_model->difference($old_config_data);
		if (!empty($diff_text))
			{
			$subject = Text::sprintf('COM_EYESITE_CONFIG_CHANGE', Factory::getApplication()->get('sitename'));
			$ip_address = LAE_helper::getIPaddress();
			$sitename = Factory::getApplication()->get('sitename');
			$body_text = Text::sprintf('COM_EYESITE_CONFIG_CHANGE_DETAIL', $sitename, date('y-m-d'), date('H:i:s'), $ip_address);
			$body_text .= '<br><br>'.$diff_text;
			$history_model = $this->getModel('history');
            $history_model->store(LAE_HISTORY_CONFIG_CHANGE, $subject, $body_text);
			if (!empty($old_config_data->emailto))
				{
				$email_status = LAE_helper::send_email($old_config_data, $subject, $body_text);
				if ($email_status == '')
					$history_model->store(LAE_HISTORY_EMAIL_OK, $subject, $body_text.'<br><br>'.Text::_('COM_EYESITE_EMAIL_ACCEPTED'));
				else
					$history_model->store(LAE_HISTORY_EMAIL_FAILED, $subject, $body_text.'<br><br>'.$email_status);
				}
			}
		if ($stored && ($task == 'config_save'))
			{
			$this->setRedirect('index.php?option=com_eyesite');
			return;
			}
		}
	$view = $this->getView('config', 'html');
	$view->config_data = $post_data;
	$view->display();
}

function cancel_to_main()
{
	$this->setRedirect('index.php?option=com_eyesite');
}

function ajax_status()
{
	$data_model = $this->getModel('data');
	$data_model->getInfo();
	$config_data = $this->config_model->getData();
	$history_model = $this->getModel('history');
	$running = $history_model->scanning();
    if (substr(JVERSION,0,1) == '3')
        $progress_bar_class = "bar";
	else
        $progress_bar_class = "progress-bar";
        
	if ($data_model->totalCount == 0)
		echo '<h3>'.Text::_('COM_EYESITE_MONITOR_NOT').'</h3>';
	else
		echo '<h3>'.Text::sprintf('COM_EYESITE_MONITOR',$data_model->totalCount).'</h3>';

	if ($running)
		{
		echo '<div class="eyesite_scanning">'.Text::_('COM_EYESITE_SCANNER_SCANNING');
		if ($data_model->runningCount > 0)
			{
			echo ': '.Text::sprintf('COM_EYESITE_FILES_TO_CHECK',$data_model->runningCount);
            $files_processed = $data_model->totalCount - $data_model->runningCount;
            $percent = ($files_processed / $data_model->totalCount) * 100;
            echo '<div class="progress" ><div class="'.$progress_bar_class.'" style="width: '.$percent.'%;"></div></div>';
            }
		echo '</div>';
		}
	else
		{
		if ($data_model->latest_date != 0)
			echo '<div>'.Text::sprintf('COM_EYESITE_LAST_SCAN',$data_model->latest_date).'</div>';
		if ($data_model->notOkCount == 0)
			echo '<div class="eyesite_no_changes">'.Text::_('COM_EYESITE_SCANNER_NO_NEW').'</div>';
		else
			echo '<div class="eyesite_changes">'.Text::sprintf('COM_EYESITE_X_NEW_CHANGES',$data_model->notOkCount).'</div>';
		}
}

function email_test()			// Send a test email to the admin address
{
	$post_data = $this->config_model->getData();
    $email_to = $post_data->emailto;
    $mailer = $this->app->get('mailer');
	if (empty($email_to))
		{
		$msg = Text::_('COM_EYESITE_INVALID').' '.Text::_('COM_EYESITE_EMAIL_ADDRESS');	      
		$this->setRedirect('index.php?option=com_eyesite&task=configure',$msg,'error');
		return;
		}
	else
		{
        $email_text = Text::sprintf('COM_EYESITE_TEST_EMAIL_TEXT',$this->app->get('sitename'));
		$return_info = LAE_helper::send_email($post_data, $email_text, $email_text);
		if ($return_info == '')
			$this->app->enqueueMessage(Text::sprintf('COM_EYESITE_TEST_EMAIL_SENT_TO_XX', $email_to, $mailer),'message');
		else
			$this->app->enqueueMessage(Text::_('COM_EYESITE_EMAIL_SEND_FAILED').'<br>'.$return_info,'error');
		}	
	$view = $this->getView('config', 'html');
	$view->config_data = $post_data;
	$view->display();
}

function about()
{
	$view = $this->getView('about', 'html');
	$view->purchase_id = $this->config_model->get_plugin_tid();
	$view->display();
}

function save_about()
{
	self::check_super_user();
    $this->checkToken();
    $purchase_id = $this->input->get('purchase_id', '', 'STRING');
    if (!empty($purchase_id) and strlen($purchase_id) != 32)
        {
		$this->app->enqueueMessage(Text::_('COM_EYESITE_PURCHASE_ID_32'), 'error');
        $view = $this->getView('about', 'html');
		$view->purchase_id = $purchase_id;
        $view->display();
        }
    else
        {
		$this->config_model->save_plugin_tid($purchase_id);
		@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/latest_plg_eyesite.xml');
    	$this->setRedirect('index.php?option=com_eyesite&task=about');
        }
}
	
function trace_on()
{
    $this->checkToken();
	$config_data = $this->config_model->getData();
	LAE_trace::init_trace($config_data);
	$this->setRedirect('index.php?option=com_eyesite&task=about');
}

function trace_off()
{
    $this->checkToken();
	LAE_trace::delete_trace_file();
	$this->setRedirect('index.php?option=com_eyesite&task=about');
}

//-------------------------------------------------------------------------------
// Check if super user
//
static function check_super_user()
{
	$user = Factory::getApplication()->getIdentity();
    if ($user->authorise('core.admin'))
		return;
	$input = Factory::getApplication()->input;
	$referrer = $input->server->getString('HTTP_REFERER');
	if (!Uri::isInternal($referrer))
		$referrer = 'index.php';
	$msg = Text::_('JGLOBAL_AUTH_ACCESS_DENIED').': '.Text::_('JACTION_ADMIN_GLOBAL').' '.Text::_('JONLY');
	$app = Factory::getApplication();
	$app->enqueueMessage($msg, 'error');
	$app->redirect($referrer);
}

}