-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontroller.php
More file actions
139 lines (129 loc) · 4.32 KB
/
Copy pathcontroller.php
File metadata and controls
139 lines (129 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/*
* @package BFStop Component (com_bfstop) for Joomla!
* @author Bernhard Froehler
* @copyright (C) Bernhard Froehler
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
**/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\MVC\Controller\BaseController;
require_once(JPATH_ADMINISTRATOR.'/components/com_bfstop/helpers/params.php');
$htaccesshelper = JPATH_SITE.'/plugins/system/bfstop/helpers/htaccess.php';
if (file_exists(stream_resolve_include_path($htaccesshelper)))
{
require_once($htaccesshelper);
}
class BFStopController extends BaseController
{
function display($cachable = false, $urlparams = false)
{
$input = Factory::getApplication()->input;
$view = $input->getCmd('view', 'blocklist');
$pluginInstalled = $this->checkWhetherPluginInstalled();
if (!$pluginInstalled)
{
return;
}
$this->warnIfAdminUserExists();
$this->warnIfHtAccessNotWorking();
$input->set('view', $view);
parent::display($cachable);
}
function warnIfAdminUserExists()
{
try
{
$db = Factory::getDBO();
$query = "SELECT COUNT(*) FROM #__users u WHERE u.username='admin'";
$db->setQuery($query);
if ($db->loadResult() > 0)
{
$application = Factory::getApplication();
$application->enqueueMessage(Text::_('COM_BFSTOP_WARNING_ADMIN_USER_EXISTS'), 'warning');
}
}
catch (Exception $e)
{
$application = Factory::getApplication();
$application->enqueueMessage("Database exception occurred: ".$e->getMessage(), 'warning');
}
}
function warnIfHtAccessNotWorking()
{
$htaccessPath = BFStopParamHelper::get('htaccessPath', 'params', JPATH_ROOT);
$htaccessPath = $htaccessPath === "" ? JPATH_ROOT : $htaccessPath;
$htaccess = new BFStopHtAccess($htaccessPath, null);
$req = $htaccess->checkRequirements();
if (!$req['apacheserver'] ||
!$req['found'] ||
!$req['readable'] ||
!$req['writeable'])
// TODO: add check whether .htaccess actually is effective!
{
$application = Factory::getApplication();
$application->enqueueMessage(Text::_('COM_BFSTOP_WARNING_HTACCESS_NOT_WORKING')
// .'found='.$req['found'].', readable='.$req['readable'].', writeable='.$req['writeable'].', apache='.$req['apacheserver']
, 'warning');
}
}
function checkSameMajorMinor($version1, $version2)
{
$ver1arr = explode($version1, ".");
$ver2arr = explode($version2, ".");
return count($ver1arr) >= 2 && count($ver2arr) >= 2 && $ver1arr[0] === $ver2arr[0] && $ver1arr[1] == $ver2arr[1];
}
function getVersion($manifest_cache)
{
$json = json_decode($manifest_cache);
return (property_exists($json, "version")) ? $json->version : '';
}
function checkWhetherPluginInstalled()
{
try
{
$db = Factory::getDBO();
$query = "SELECT manifest_cache,enabled FROM #__extensions WHERE name='plg_system_bfstop'";
$db->setQuery($query);
$plugin = $db->loadObject();
if (is_null($plugin))
{
$application = Factory::getApplication();
$application->enqueueMessage(Text::_('COM_BFSTOP_WARNING_PLUGIN_NOT_INSTALLED'), 'warning');
return false;
}
$query = "SELECT manifest_cache FROM #__extensions WHERE name='com_bfstop'";
$db->setQuery($query);
$component = $db->loadObject();
if (is_null($component))
{
$application = Factory::getApplication();
$application->enqueueMessage(Text::_('COM_BFSTOP_WARNING_CANNOT_RETRIEVE_COMPONENT_CACHE'), 'warning');
return false;
}
$plugin_version = $this->getVersion($plugin->manifest_cache);
$component_version = $this->getVersion($component->manifest_cache);
if ($this->checkSameMajorMinor($component_version, $plugin_version))
{
$application = Factory::getApplication();
$application->enqueueMessage(Text::_('COM_BFSTOP_WARNING_COMPONENT_PLUGIN_DIFFERENT_VERSION'), 'warning');
return false;
}
if ($plugin->enabled != 1)
{
$application = Factory::getApplication();
$application->enqueueMessage(Text::sprintf('COM_BFSTOP_WARNING_PLUGIN_DISABLED', Route::_('index.php?option=com_plugins&view=plugins', false)), 'warning');
// this is not a "hard" failure; we can still manage the tables!
// return false;
}
return true;
}
catch (Exception $e)
{
$application = Factory::getApplication();
$application->enqueueMessage("Database exception occurred: ".$e->getMessage(), 'warning');
}
}
}