primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,50 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Controller;
use Joomla\CMS\MVC\Controller\BaseController;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Admin Controller
*
* @since 1.6
*/
class DisplayController extends BaseController
{
/**
* View method
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe URL parameters and their variable types.
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
*
* @return static Supports chaining.
*
* @since 3.9
*/
public function display($cachable = false, $urlparams = [])
{
$viewName = $this->input->get('view', $this->default_view);
$format = $this->input->get('format', 'html');
// Check CSRF token for sysinfo export views
if ($viewName === 'sysinfo' && ($format === 'text' || $format === 'json')) {
// Check for request forgeries.
$this->checkToken('GET');
}
return parent::display($cachable, $urlparams);
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Dispatcher;
use Joomla\CMS\Dispatcher\ComponentDispatcher;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* ComponentDispatcher class for com_admin
*
* @since 4.0.0
*/
class Dispatcher extends ComponentDispatcher
{
/**
* com_admin does not require check permission, so we override checkAccess method and have it empty
*
* @return void
*/
protected function checkAccess()
{
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Extension;
use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Joomla\Component\Admin\Administrator\Service\HTML\Configuration;
use Joomla\Component\Admin\Administrator\Service\HTML\Directory;
use Joomla\Component\Admin\Administrator\Service\HTML\PhpSetting;
use Joomla\Component\Admin\Administrator\Service\HTML\System;
use Psr\Container\ContainerInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component class for com_admin
*
* @since 4.0.0
*/
class AdminComponent extends MVCComponent implements BootableExtensionInterface
{
use HTMLRegistryAwareTrait;
/**
* Booting the extension. This is the function to set up the environment of the extension like
* registering new class loaders, etc.
*
* If required, some initial set up can be done from services of the container, eg.
* registering HTML services.
*
* @param ContainerInterface $container The container
*
* @return void
*
* @since 4.0.0
*/
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('system', new System());
$this->getRegistry()->register('phpsetting', new PhpSetting());
$this->getRegistry()->register('directory', new Directory());
$this->getRegistry()->register('configuration', new Configuration());
}
}

View File

@ -0,0 +1,189 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Help\Help;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\Filesystem\Folder;
use Joomla\String\StringHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Admin Component Help Model
*
* @since 1.6
*/
class HelpModel extends BaseDatabaseModel
{
/**
* The search string
*
* @var string
* @since 1.6
*/
protected $help_search = null;
/**
* The page to be viewed
*
* @var string
* @since 1.6
*/
protected $page = null;
/**
* The ISO language tag
*
* @var string
* @since 1.6
*/
protected $lang_tag = null;
/**
* Table of contents
*
* @var array
* @since 1.6
*/
protected $toc = [];
/**
* URL for the latest version check
*
* @var string
* @since 1.6
*/
protected $latest_version_check = null;
/**
* Method to get the help search string
*
* @return string Help search string
*
* @since 1.6
*/
public function &getHelpSearch()
{
if (\is_null($this->help_search)) {
$this->help_search = Factory::getApplication()->getInput()->getString('helpsearch');
}
return $this->help_search;
}
/**
* Method to get the page
*
* @return string The page
*
* @since 1.6
*/
public function &getPage()
{
if (\is_null($this->page)) {
$this->page = Help::createUrl(Factory::getApplication()->getInput()->get('page', 'Start_Here'));
}
return $this->page;
}
/**
* Method to get the lang tag
*
* @return string lang iso tag
*
* @since 1.6
*/
public function getLangTag()
{
if (\is_null($this->lang_tag)) {
$this->lang_tag = Factory::getLanguage()->getTag();
if (!is_dir(JPATH_BASE . '/help/' . $this->lang_tag)) {
// Use English as fallback
$this->lang_tag = 'en-GB';
}
}
return $this->lang_tag;
}
/**
* Method to get the table of contents
*
* @return array Table of contents
*/
public function &getToc()
{
if (\count($this->toc)) {
return $this->toc;
}
// Get vars
$lang_tag = $this->getLangTag();
$help_search = $this->getHelpSearch();
// New style - Check for a TOC \JSON file
if (file_exists(JPATH_BASE . '/help/' . $lang_tag . '/toc.json')) {
$data = json_decode(file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/toc.json'));
// Loop through the data array
foreach ($data as $key => $value) {
$this->toc[$key] = Text::_('COM_ADMIN_HELP_' . $value);
}
// Sort the Table of Contents
asort($this->toc);
return $this->toc;
}
// Get Help files
$files = Folder::files(JPATH_BASE . '/help/' . $lang_tag, '\.xml$|\.html$');
foreach ($files as $file) {
$buffer = file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/' . $file);
if (!preg_match('#<title>(.*?)</title>#', $buffer, $m)) {
continue;
}
$title = trim($m[1]);
if (!$title) {
continue;
}
// Translate the page title
$title = Text::_($title);
// Strip the extension
$file = preg_replace('#\.xml$|\.html$#', '', $file);
if ($help_search && StringHelper::strpos(StringHelper::strtolower(strip_tags($buffer)), StringHelper::strtolower($help_search)) === false) {
continue;
}
// Add an item in the Table of Contents
$this->toc[$file] = $title;
}
// Sort the Table of Contents
asort($this->toc);
return $this->toc;
}
}

View File

@ -0,0 +1,732 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Version;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Model for the display of system information.
*
* @since 1.6
*/
class SysinfoModel extends BaseDatabaseModel
{
/**
* Some PHP settings
*
* @var array
* @since 1.6
*/
protected $php_settings = [];
/**
* Config values
*
* @var array
* @since 1.6
*/
protected $config = [];
/**
* Some system values
*
* @var array
* @since 1.6
*/
protected $info = [];
/**
* PHP info
*
* @var string
* @since 1.6
*/
protected $php_info = null;
/**
* Array containing the phpinfo() data.
*
* @var array
*
* @since 3.5
*/
protected $phpInfoArray;
/**
* Private/critical data that we don't want to share
*
* @var array
*
* @since 3.5
*/
protected $privateSettings = [
'phpInfoArray' => [
'CONTEXT_DOCUMENT_ROOT',
'Cookie',
'DOCUMENT_ROOT',
'extension_dir',
'error_log',
'Host',
'HTTP_COOKIE',
'HTTP_HOST',
'HTTP_ORIGIN',
'HTTP_REFERER',
'HTTP Request',
'include_path',
'mysql.default_socket',
'MYSQL_SOCKET',
'MYSQL_INCLUDE',
'MYSQL_LIBS',
'mysqli.default_socket',
'MYSQLI_SOCKET',
'PATH',
'Path to sendmail',
'pdo_mysql.default_socket',
'Referer',
'REMOTE_ADDR',
'SCRIPT_FILENAME',
'sendmail_path',
'SERVER_ADDR',
'SERVER_ADMIN',
'Server Administrator',
'SERVER_NAME',
'Server Root',
'session.name',
'session.save_path',
'upload_tmp_dir',
'User/Group',
'open_basedir',
],
'other' => [
'db',
'dbprefix',
'fromname',
'live_site',
'log_path',
'mailfrom',
'memcached_server_host',
'open_basedir',
'Origin',
'proxy_host',
'proxy_user',
'proxy_pass',
'redis_server_host',
'redis_server_auth',
'secret',
'sendmail',
'session.save_path',
'session_memcached_server_host',
'session_redis_server_host',
'session_redis_server_auth',
'sitename',
'smtphost',
'tmp_path',
'open_basedir',
],
];
/**
* System values that can be "safely" shared
*
* @var array
*
* @since 3.5
*/
protected $safeData;
/**
* Information about writable state of directories
*
* @var array
* @since 1.6
*/
protected $directories = [];
/**
* The current editor.
*
* @var string
* @since 1.6
*/
protected $editor = null;
/**
* Remove sections of data marked as private in the privateSettings
*
* @param array $dataArray Array with data that may contain private information
* @param string $dataType Type of data to search for a specific section in the privateSettings array
*
* @return array
*
* @since 3.5
*/
protected function cleanPrivateData(array $dataArray, string $dataType = 'other'): array
{
$dataType = isset($this->privateSettings[$dataType]) ? $dataType : 'other';
$privateSettings = $this->privateSettings[$dataType];
if (!$privateSettings) {
return $dataArray;
}
foreach ($dataArray as $section => $values) {
if (\is_array($values)) {
$dataArray[$section] = $this->cleanPrivateData($values, $dataType);
}
if (\in_array($section, $privateSettings, true)) {
$dataArray[$section] = $this->cleanSectionPrivateData($values);
}
}
return $dataArray;
}
/**
* Obfuscate section values
*
* @param mixed $sectionValues Section data
*
* @return string|array
*
* @since 3.5
*/
protected function cleanSectionPrivateData($sectionValues)
{
if (!\is_array($sectionValues)) {
if (strstr($sectionValues, JPATH_ROOT)) {
$sectionValues = 'xxxxxx';
}
return \strlen($sectionValues) ? 'xxxxxx' : '';
}
foreach ($sectionValues as $setting => $value) {
$sectionValues[$setting] = \strlen($value) ? 'xxxxxx' : '';
}
return $sectionValues;
}
/**
* Method to get the PHP settings
*
* @return array Some PHP settings
*
* @since 1.6
*/
public function &getPhpSettings(): array
{
if (!empty($this->php_settings)) {
return $this->php_settings;
}
$this->php_settings = [
'memory_limit' => \ini_get('memory_limit'),
'upload_max_filesize' => \ini_get('upload_max_filesize'),
'post_max_size' => \ini_get('post_max_size'),
'display_errors' => \ini_get('display_errors') == '1',
'short_open_tag' => \ini_get('short_open_tag') == '1',
'file_uploads' => \ini_get('file_uploads') == '1',
'output_buffering' => (int) \ini_get('output_buffering') !== 0,
'open_basedir' => \ini_get('open_basedir'),
'session.save_path' => \ini_get('session.save_path'),
'session.auto_start' => \ini_get('session.auto_start'),
'disable_functions' => \ini_get('disable_functions'),
'xml' => \extension_loaded('xml'),
'zlib' => \extension_loaded('zlib'),
'zip' => \function_exists('zip_open') && \function_exists('zip_read'),
'mbstring' => \extension_loaded('mbstring'),
'fileinfo' => \extension_loaded('fileinfo'),
'gd' => \extension_loaded('gd'),
'iconv' => \function_exists('iconv'),
'intl' => \function_exists('transliterator_transliterate'),
'max_input_vars' => \ini_get('max_input_vars'),
];
return $this->php_settings;
}
/**
* Method to get the config
*
* @return array config values
*
* @since 1.6
*/
public function &getConfig(): array
{
if (!empty($this->config)) {
return $this->config;
}
$registry = new Registry(new \JConfig());
$this->config = $registry->toArray();
$hidden = [
'host', 'user', 'password', 'ftp_user', 'ftp_pass',
'smtpuser', 'smtppass', 'redis_server_auth', 'session_redis_server_auth',
'proxy_user', 'proxy_pass', 'secret',
];
foreach ($hidden as $key) {
$this->config[$key] = 'xxxxxx';
}
return $this->config;
}
/**
* Method to get the system information
*
* @return array System information values
*
* @since 1.6
*/
public function &getInfo(): array
{
if (!empty($this->info)) {
return $this->info;
}
$db = $this->getDatabase();
$this->info = [
'php' => php_uname(),
'dbserver' => $db->getServerType(),
'dbversion' => $db->getVersion(),
'dbcollation' => $db->getCollation(),
'dbconnectioncollation' => $db->getConnectionCollation(),
'dbconnectionencryption' => $db->getConnectionEncryption(),
'dbconnencryptsupported' => $db->isConnectionEncryptionSupported(),
'phpversion' => PHP_VERSION,
'server' => $_SERVER['SERVER_SOFTWARE'] ?? getenv('SERVER_SOFTWARE'),
'sapi_name' => PHP_SAPI,
'version' => (new Version())->getLongVersion(),
'compatpluginenabled' => PluginHelper::isEnabled('behaviour', 'compat'),
'compatpluginparameters' => $this->getCompatPluginParameters(),
'useragent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
];
return $this->info;
}
private function getCompatPluginParameters()
{
$record = ExtensionHelper::getExtensionRecord('compat', 'plugin', 0, 'behaviour');
if ($record) {
$params = new Registry($record->params);
return ArrayHelper::toString($params->toArray(), ':', ', ');
}
return '';
}
/**
* Check if the phpinfo function is enabled
*
* @return boolean True if enabled
*
* @since 3.4.1
*/
public function phpinfoEnabled(): bool
{
// remove any spaces from the ini value before exploding it
$disabledFunctions = str_replace(' ', '', \ini_get('disable_functions'));
return !\in_array('phpinfo', explode(',', $disabledFunctions));
}
/**
* Method to get filter data from the model
*
* @param string $dataType Type of data to get safely
* @param bool $public If true no sensitive information will be removed
*
* @return array
*
* @since 3.5
*/
public function getSafeData(string $dataType, bool $public = true): array
{
if (isset($this->safeData[$dataType])) {
return $this->safeData[$dataType];
}
$methodName = 'get' . ucfirst($dataType);
if (!method_exists($this, $methodName)) {
return [];
}
$data = $this->$methodName($public);
$this->safeData[$dataType] = $this->cleanPrivateData($data, $dataType);
return $this->safeData[$dataType];
}
/**
* Method to get the PHP info
*
* @return string PHP info
*
* @since 1.6
*/
public function &getPHPInfo(): string
{
if (!$this->phpinfoEnabled()) {
$this->php_info = Text::_('COM_ADMIN_PHPINFO_DISABLED');
return $this->php_info;
}
if (!\is_null($this->php_info)) {
return $this->php_info;
}
ob_start();
date_default_timezone_set('UTC');
phpinfo(INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES);
$phpInfo = ob_get_clean();
preg_match_all('#<body[^>]*>(.*)</body>#siU', $phpInfo, $output);
$output = preg_replace('#<table[^>]*>#', '<table class="table">', $output[1][0]);
$output = preg_replace('#(\w),(\w)#', '\1, \2', $output);
$output = str_replace('<hr />', '', $output);
$output = str_replace('<div class="text-center">', '', $output);
$output = preg_replace('#<tr class="h">(.*)</tr>#', '<thead><tr class="h">$1</tr></thead><tbody>', $output);
$output = str_replace('</table>', '</tbody></table>', $output);
$output = str_replace('</div>', '', $output);
$this->php_info = $output;
return $this->php_info;
}
/**
* Get phpinfo() output as array
*
* @return array
*
* @since 3.5
*/
public function getPhpInfoArray(): array
{
// Already cached
if (null !== $this->phpInfoArray) {
return $this->phpInfoArray;
}
$phpInfo = $this->getPHPInfo();
$this->phpInfoArray = $this->parsePhpInfo($phpInfo);
return $this->phpInfoArray;
}
/**
* Method to get a list of installed extensions
*
* @return array installed extensions
*
* @since 3.5
*/
public function getExtensions(): array
{
$installed = [];
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__extensions'));
$db->setQuery($query);
try {
$extensions = $db->loadObjectList();
} catch (\Exception $e) {
try {
Log::add(Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()), Log::WARNING, 'jerror');
} catch (\RuntimeException $exception) {
Factory::getApplication()->enqueueMessage(
Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()),
'warning'
);
}
return $installed;
}
if (empty($extensions)) {
return $installed;
}
foreach ($extensions as $extension) {
if (\strlen($extension->name) == 0) {
continue;
}
$installed[$extension->name] = [
'name' => $extension->name,
'type' => $extension->type,
'state' => $extension->enabled ? Text::_('JENABLED') : Text::_('JDISABLED'),
'author' => 'unknown',
'version' => 'unknown',
'creationDate' => 'unknown',
'authorUrl' => 'unknown',
];
$manifest = new Registry($extension->manifest_cache);
$extraData = [
'author' => $manifest->get('author', ''),
'version' => $manifest->get('version', ''),
'creationDate' => $manifest->get('creationDate', ''),
'authorUrl' => $manifest->get('authorUrl', ''),
];
$installed[$extension->name] = array_merge($installed[$extension->name], $extraData);
}
return $installed;
}
/**
* Method to get the directory states
*
* @param bool $public If true no information is going to be removed
*
* @return array States of directories
*
* @throws \Exception
* @since 1.6
*/
public function getDirectory(bool $public = false): array
{
if (!empty($this->directories)) {
return $this->directories;
}
$this->directories = [];
$registry = Factory::getApplication()->getConfig();
$cparams = ComponentHelper::getParams('com_media');
$this->addDirectory('administrator/components', JPATH_ADMINISTRATOR . '/components');
$this->addDirectory('administrator/components/com_joomlaupdate', JPATH_ADMINISTRATOR . '/components/com_joomlaupdate');
$this->addDirectory('administrator/language', JPATH_ADMINISTRATOR . '/language');
// List all admin languages
$admin_langs = new \DirectoryIterator(JPATH_ADMINISTRATOR . '/language');
foreach ($admin_langs as $folder) {
if ($folder->isDot() || !$folder->isDir()) {
continue;
}
$this->addDirectory(
'administrator/language/' . $folder->getFilename(),
JPATH_ADMINISTRATOR . '/language/' . $folder->getFilename()
);
}
// List all manifests folders
$manifests = new \DirectoryIterator(JPATH_ADMINISTRATOR . '/manifests');
foreach ($manifests as $folder) {
if ($folder->isDot() || !$folder->isDir()) {
continue;
}
$this->addDirectory(
'administrator/manifests/' . $folder->getFilename(),
JPATH_ADMINISTRATOR . '/manifests/' . $folder->getFilename()
);
}
$this->addDirectory('administrator/modules', JPATH_ADMINISTRATOR . '/modules');
$this->addDirectory('administrator/templates', JPATH_THEMES);
$this->addDirectory('components', JPATH_SITE . '/components');
$this->addDirectory($cparams->get('image_path'), JPATH_SITE . '/' . $cparams->get('image_path'));
// List all images folders
$image_folders = new \DirectoryIterator(JPATH_SITE . '/' . $cparams->get('image_path'));
foreach ($image_folders as $folder) {
if ($folder->isDot() || !$folder->isDir()) {
continue;
}
$this->addDirectory(
'images/' . $folder->getFilename(),
JPATH_SITE . '/' . $cparams->get('image_path') . '/' . $folder->getFilename()
);
}
$this->addDirectory('language', JPATH_SITE . '/language');
// List all site languages
$site_langs = new \DirectoryIterator(JPATH_SITE . '/language');
foreach ($site_langs as $folder) {
if ($folder->isDot() || !$folder->isDir()) {
continue;
}
$this->addDirectory('language/' . $folder->getFilename(), JPATH_SITE . '/language/' . $folder->getFilename());
}
$this->addDirectory('libraries', JPATH_LIBRARIES);
$this->addDirectory('media', JPATH_SITE . '/media');
$this->addDirectory('modules', JPATH_SITE . '/modules');
$this->addDirectory('plugins', JPATH_PLUGINS);
$plugin_groups = new \DirectoryIterator(JPATH_SITE . '/plugins');
foreach ($plugin_groups as $folder) {
if ($folder->isDot() || !$folder->isDir()) {
continue;
}
$this->addDirectory('plugins/' . $folder->getFilename(), JPATH_PLUGINS . '/' . $folder->getFilename());
}
$this->addDirectory('templates', JPATH_SITE . '/templates');
$this->addDirectory('configuration.php', JPATH_CONFIGURATION . '/configuration.php');
// Is there a cache path in configuration.php?
if ($cache_path = trim($registry->get('cache_path', ''))) {
// Frontend and backend use same directory for caching.
$this->addDirectory($cache_path, $cache_path, 'COM_ADMIN_CACHE_DIRECTORY');
} else {
$this->addDirectory('administrator/cache', JPATH_CACHE, 'COM_ADMIN_CACHE_DIRECTORY');
}
$this->addDirectory('media/cache', JPATH_ROOT . '/media/cache', 'COM_ADMIN_MEDIA_CACHE_DIRECTORY');
if ($public) {
$this->addDirectory(
'log',
$registry->get('log_path', JPATH_ADMINISTRATOR . '/logs'),
'COM_ADMIN_LOG_DIRECTORY'
);
$this->addDirectory(
'tmp',
$registry->get('tmp_path', JPATH_ROOT . '/tmp'),
'COM_ADMIN_TEMP_DIRECTORY'
);
} else {
$this->addDirectory(
$registry->get('log_path', JPATH_ADMINISTRATOR . '/logs'),
$registry->get('log_path', JPATH_ADMINISTRATOR . '/logs'),
'COM_ADMIN_LOG_DIRECTORY'
);
$this->addDirectory(
$registry->get('tmp_path', JPATH_ROOT . '/tmp'),
$registry->get('tmp_path', JPATH_ROOT . '/tmp'),
'COM_ADMIN_TEMP_DIRECTORY'
);
}
return $this->directories;
}
/**
* Method to add a directory
*
* @param string $name Directory Name
* @param string $path Directory path
* @param string $message Message
*
* @return void
*
* @since 1.6
*/
private function addDirectory(string $name, string $path, string $message = ''): void
{
$this->directories[$name] = ['writable' => is_writable($path), 'message' => $message];
}
/**
* Method to get the editor
*
* @return string The default editor
*
* @note Has to be removed (it is present in the config...)
* @since 1.6
*/
public function &getEditor(): string
{
if (!\is_null($this->editor)) {
return $this->editor;
}
$this->editor = Factory::getApplication()->get('editor');
return $this->editor;
}
/**
* Parse phpinfo output into an array
* Source https://gist.github.com/sbmzhcn/6255314
*
* @param string $html Output of phpinfo()
*
* @return array
*
* @since 3.5
*/
protected function parsePhpInfo(string $html): array
{
$html = strip_tags($html, '<h2><th><td>');
$html = preg_replace('/<th[^>]*>([^<]+)<\/th>/', '<info>\1</info>', $html);
$html = preg_replace('/<td[^>]*>([^<]+)<\/td>/', '<info>\1</info>', $html);
$t = preg_split('/(<h2[^>]*>[^<]+<\/h2>)/', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
$r = [];
$count = \count($t);
$p1 = '<info>([^<]+)<\/info>';
$p2 = '/' . $p1 . '\s*' . $p1 . '\s*' . $p1 . '/';
$p3 = '/' . $p1 . '\s*' . $p1 . '/';
for ($i = 1; $i < $count; $i++) {
if (preg_match('/<h2[^>]*>([^<]+)<\/h2>/', $t[$i], $matches)) {
$name = trim($matches[1]);
$vals = explode("\n", $t[$i + 1]);
foreach ($vals as $val) {
// 3cols
if (preg_match($p2, $val, $matches)) {
$r[$name][trim($matches[1])] = [trim($matches[2]), trim($matches[3])];
} elseif (preg_match($p3, $val, $matches)) {
// 2cols
$r[$name][trim($matches[1])] = trim($matches[2]);
}
}
}
}
return $r;
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Service\HTML;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Class for rendering configuration values
*
* @since 4.0.0
*/
class Configuration
{
/**
* Method to generate a string for a value
*
* @param mixed $value The configuration value
*
* @return string Formatted and escaped string
*
* @since 4.0.0
*/
public function value($value): string
{
if (\is_bool($value)) {
return $value ? 'true' : 'false';
}
if (\is_array($value)) {
$value = implode(', ', $value);
}
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Service\HTML;
use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Utility class working with directory
*
* @since 1.6
*/
class Directory
{
/**
* Method to generate a (un)writable message for directory
*
* @param boolean $writable is the directory writable?
*
* @return string html code
*/
public function writable($writable)
{
if ($writable) {
return '<span class="badge bg-success">' . Text::_('COM_ADMIN_WRITABLE') . '</span>';
}
return '<span class="badge bg-danger">' . Text::_('COM_ADMIN_UNWRITABLE') . '</span>';
}
/**
* Method to generate a message for a directory
*
* @param string $dir the directory
* @param boolean $message the message
* @param boolean $visible is the $dir visible?
*
* @return string html code
*/
public function message($dir, $message, $visible = true)
{
$output = $visible ? $dir : '';
if (empty($message)) {
return $output;
}
return $output . ' <strong>' . Text::_($message) . '</strong>';
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Service\HTML;
use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Utility class working with phpsetting
*
* @since 1.6
*/
class PhpSetting
{
/**
* Method to generate a boolean message for a value
*
* @param boolean $val is the value set?
*
* @return string html code
*/
public function boolean($val)
{
return Text::_($val ? 'JON' : 'JOFF');
}
/**
* Method to generate a boolean message for a value
*
* @param boolean $val is the value set?
*
* @return string html code
*/
public function set($val)
{
return Text::_($val ? 'JYES' : 'JNO');
}
/**
* Method to generate a string message for a value
*
* @param string $val a php ini value
*
* @return string html code
*/
public function string($val)
{
return !empty($val) ? $val : Text::_('JNONE');
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\Service\HTML;
use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Utility class working with system
*
* @since 1.6
*/
class System
{
/**
* Method to generate a string message for a value
*
* @param string $val a php ini value
*
* @return string html code
*/
public function server($val)
{
return !empty($val) ? $val : Text::_('COM_ADMIN_NA');
}
}

View File

@ -0,0 +1,97 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\View\Help;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Admin\Administrator\Model\HelpModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTML View class for the Admin component
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* The search string
*
* @var string
* @since 1.6
*/
protected $helpSearch = null;
/**
* The page to be viewed
*
* @var string
* @since 1.6
*/
protected $page = null;
/**
* The iso language tag
*
* @var string
* @since 1.6
*/
protected $languageTag = null;
/**
* Table of contents
*
* @var array
* @since 1.6
*/
protected $toc = [];
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 1.6
*
* @throws \Exception
*/
public function display($tpl = null): void
{
/** @var HelpModel $model */
$model = $this->getModel();
$this->helpSearch = $model->getHelpSearch();
$this->page = $model->getPage();
$this->toc = $model->getToc();
$this->languageTag = $model->getLangTag();
$this->addToolbar();
parent::display($tpl);
}
/**
* Setup the Toolbar
*
* @return void
*
* @since 1.6
*/
protected function addToolbar(): void
{
ToolbarHelper::title(Text::_('COM_ADMIN_HELP'), 'support help_header');
}
}

View File

@ -0,0 +1,122 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\View\Sysinfo;
use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Admin\Administrator\Model\SysinfoModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Sysinfo View class for the Admin component
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* Some PHP settings
*
* @var array
* @since 1.6
*/
protected $phpSettings = [];
/**
* Config values
*
* @var array
* @since 1.6
*/
protected $config = [];
/**
* Some system values
*
* @var array
* @since 1.6
*/
protected $info = [];
/**
* PHP info
*
* @var string
* @since 1.6
*/
protected $phpInfo = null;
/**
* Information about writable state of directories
*
* @var array
* @since 1.6
*/
protected $directory = [];
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 1.6
*
* @throws \Exception
*/
public function display($tpl = null): void
{
// Access check.
if (!$this->getCurrentUser()->authorise('core.admin')) {
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
/** @var SysinfoModel $model */
$model = $this->getModel();
$this->phpSettings = $model->getPhpSettings();
$this->config = $model->getConfig();
$this->info = $model->getInfo();
$this->phpInfo = $model->getPHPInfo();
$this->directory = $model->getDirectory();
$this->addToolbar();
parent::display($tpl);
}
/**
* Setup the Toolbar
*
* @return void
*
* @since 1.6
*/
protected function addToolbar(): void
{
ToolbarHelper::title(Text::_('COM_ADMIN_SYSTEM_INFORMATION'), 'info-circle systeminfo');
$toolbar = $this->getDocument()->getToolbar();
$toolbar->linkButton('download', 'COM_ADMIN_DOWNLOAD_SYSTEM_INFORMATION_TEXT')
->url(Route::_('index.php?option=com_admin&view=sysinfo&format=text&' . Session::getFormToken() . '=1'));
$toolbar->linkButton('download', 'COM_ADMIN_DOWNLOAD_SYSTEM_INFORMATION_JSON')
->url(Route::_('index.php?option=com_admin&view=sysinfo&format=json&' . Session::getFormToken() . '=1'));
$toolbar->help('Site_System_Information');
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\View\Sysinfo;
use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\CMS\User\CurrentUserInterface;
use Joomla\CMS\User\CurrentUserTrait;
use Joomla\Component\Admin\Administrator\Model\SysinfoModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Sysinfo View class for the Admin component
*
* @since 3.5
*/
class JsonView extends AbstractView implements CurrentUserInterface
{
use CurrentUserTrait;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 3.5
*
* @throws \Exception
*/
public function display($tpl = null): void
{
// Access check.
if (!$this->getCurrentUser()->authorise('core.admin')) {
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
header('MIME-Version: 1.0');
header('Content-Disposition: attachment; filename="systeminfo-' . date('c') . '.json"');
header('Content-Transfer-Encoding: binary');
$data = $this->getLayoutData();
echo json_encode($data, JSON_PRETTY_PRINT);
Factory::getApplication()->close();
}
/**
* Get the data for the view
*
* @return array
*
* @since 3.5
*/
protected function getLayoutData(): array
{
/** @var SysinfoModel $model */
$model = $this->getModel();
return [
'info' => $model->getSafeData('info'),
'phpSettings' => $model->getSafeData('phpSettings'),
'config' => $model->getSafeData('config'),
'directories' => $model->getSafeData('directory', true),
'phpInfo' => $model->getSafeData('phpInfoArray'),
'extensions' => $model->getSafeData('extensions'),
];
}
}

View File

@ -0,0 +1,182 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Admin\Administrator\View\Sysinfo;
use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\CMS\User\CurrentUserInterface;
use Joomla\CMS\User\CurrentUserTrait;
use Joomla\Component\Admin\Administrator\Model\SysinfoModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Sysinfo View class for the Admin component
*
* @since 3.5
*/
class TextView extends AbstractView implements CurrentUserInterface
{
use CurrentUserTrait;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 3.5
*
* @throws \Exception
*/
public function display($tpl = null): void
{
// Access check.
if (!$this->getCurrentUser()->authorise('core.admin')) {
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
header('Content-Type: text/plain; charset=utf-8');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="systeminfo-' . date('c') . '.txt"');
header('Cache-Control: must-revalidate');
$data = $this->getLayoutData();
$lines = [];
foreach ($data as $sectionName => $section) {
$customRenderingMethod = 'render' . ucfirst($sectionName);
if (method_exists($this, $customRenderingMethod)) {
$lines[] = $this->$customRenderingMethod($section['title'], $section['data']);
} else {
$lines[] = $this->renderSection($section['title'], $section['data']);
}
}
echo str_replace(JPATH_ROOT, 'xxxxxx', implode("\n\n", $lines));
Factory::getApplication()->close();
}
/**
* Get the data for the view
*
* @return array
*
* @since 3.5
*/
protected function getLayoutData(): array
{
/** @var SysinfoModel $model */
$model = $this->getModel();
return [
'info' => [
'title' => Text::_('COM_ADMIN_SYSTEM_INFORMATION', true),
'data' => $model->getSafeData('info'),
],
'phpSettings' => [
'title' => Text::_('COM_ADMIN_PHP_SETTINGS', true),
'data' => $model->getSafeData('phpSettings'),
],
'config' => [
'title' => Text::_('COM_ADMIN_CONFIGURATION_FILE', true),
'data' => $model->getSafeData('config'),
],
'directories' => [
'title' => Text::_('COM_ADMIN_DIRECTORY_PERMISSIONS', true),
'data' => $model->getSafeData('directory', true),
],
'phpInfo' => [
'title' => Text::_('COM_ADMIN_PHP_INFORMATION', true),
'data' => $model->getSafeData('phpInfoArray'),
],
'extensions' => [
'title' => Text::_('COM_ADMIN_EXTENSIONS', true),
'data' => $model->getSafeData('extensions'),
],
];
}
/**
* Render a section
*
* @param string $sectionName Name of the section to render
* @param array $sectionData Data of the section to render
* @param integer $level Depth level for indentation
*
* @return string
*
* @since 3.5
*/
protected function renderSection(string $sectionName, array $sectionData, int $level = 0): string
{
$lines = [];
$margin = ($level > 0) ? str_repeat("\t", $level) : null;
$lines[] = $margin . '=============';
$lines[] = $margin . $sectionName;
$lines[] = $margin . '=============';
$level++;
foreach ($sectionData as $name => $value) {
if (\is_array($value)) {
if ($name == 'Directive') {
continue;
}
$lines[] = '';
$lines[] = $this->renderSection($name, $value, $level);
} else {
if (\is_bool($value)) {
$value = $value ? 'true' : 'false';
}
if (\is_int($name) && ($name == 0 || $name == 1)) {
// The term "Master" is used because it is the term used in phpinfo() and this is a text representation of that.
$name = ($name == 0 ? 'Local Value' : 'Master Value');
}
$lines[] = $margin . $name . ': ' . $value;
}
}
return implode("\n", $lines);
}
/**
* Specific rendering for directories
*
* @param string $sectionName Name of the section
* @param array $sectionData Directories information
* @param integer $level Starting level
*
* @return string
*
* @since 3.5
*/
protected function renderDirectories(string $sectionName, array $sectionData, int $level = -1): string
{
foreach ($sectionData as $directory => $data) {
$sectionData[$directory] = $data['writable'] ? ' writable' : ' NOT writable';
}
return $this->renderSection($sectionName, $sectionData, $level);
}
}