PageRenderTime 27ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/joomla/administrator/components/com_admin/models/sysinfo.php

https://gitlab.com/ricardosanchez/prueba
PHP | 367 lines | 197 code | 58 blank | 112 comment | 25 complexity | e6ed49948ebf214eb858cca8bc2d2f32 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_admin
  5. *
  6. * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. use Joomla\Registry\Registry;
  11. /**
  12. * Model for the display of system information.
  13. *
  14. * @since 1.6
  15. */
  16. class AdminModelSysInfo extends JModelLegacy
  17. {
  18. /**
  19. * @var array Some PHP settings
  20. * @since 1.6
  21. */
  22. protected $php_settings = null;
  23. /**
  24. * @var array Config values
  25. * @since 1.6
  26. */
  27. protected $config = null;
  28. /**
  29. * @var array Some system values
  30. * @since 1.6
  31. */
  32. protected $info = null;
  33. /**
  34. * @var string PHP info
  35. * @since 1.6
  36. */
  37. protected $php_info = null;
  38. /**
  39. * Information about writable state of directories
  40. *
  41. * @var array
  42. * @since 1.6
  43. */
  44. protected $directories = null;
  45. /**
  46. * The current editor.
  47. *
  48. * @var string
  49. * @since 1.6
  50. */
  51. protected $editor = null;
  52. /**
  53. * Method to get the ChangeLog
  54. *
  55. * @return array some php settings
  56. *
  57. * @since 1.6
  58. */
  59. public function &getPhpSettings()
  60. {
  61. if (!is_null($this->php_settings))
  62. {
  63. return $this->php_settings;
  64. }
  65. $this->php_settings = array();
  66. $this->php_settings['safe_mode'] = ini_get('safe_mode') == '1';
  67. $this->php_settings['display_errors'] = ini_get('display_errors') == '1';
  68. $this->php_settings['short_open_tag'] = ini_get('short_open_tag') == '1';
  69. $this->php_settings['file_uploads'] = ini_get('file_uploads') == '1';
  70. $this->php_settings['magic_quotes_gpc'] = ini_get('magic_quotes_gpc') == '1';
  71. $this->php_settings['register_globals'] = ini_get('register_globals') == '1';
  72. $this->php_settings['output_buffering'] = (bool) ini_get('output_buffering');
  73. $this->php_settings['open_basedir'] = ini_get('open_basedir');
  74. $this->php_settings['session.save_path'] = ini_get('session.save_path');
  75. $this->php_settings['session.auto_start'] = ini_get('session.auto_start');
  76. $this->php_settings['disable_functions'] = ini_get('disable_functions');
  77. $this->php_settings['xml'] = extension_loaded('xml');
  78. $this->php_settings['zlib'] = extension_loaded('zlib');
  79. $this->php_settings['zip'] = function_exists('zip_open') && function_exists('zip_read');
  80. $this->php_settings['mbstring'] = extension_loaded('mbstring');
  81. $this->php_settings['iconv'] = function_exists('iconv');
  82. return $this->php_settings;
  83. }
  84. /**
  85. * Method to get the config
  86. *
  87. * @return array config values
  88. *
  89. * @since 1.6
  90. */
  91. public function &getConfig()
  92. {
  93. if (!is_null($this->config))
  94. {
  95. return $this->config;
  96. }
  97. $registry = new Registry(new JConfig);
  98. $this->config = $registry->toArray();
  99. $hidden = array('host', 'user', 'password', 'ftp_user', 'ftp_pass', 'smtpuser', 'smtppass');
  100. foreach ($hidden as $key)
  101. {
  102. $this->config[$key] = 'xxxxxx';
  103. }
  104. return $this->config;
  105. }
  106. /**
  107. * Method to get the system information
  108. *
  109. * @return array system information values
  110. *
  111. * @since 1.6
  112. */
  113. public function &getInfo()
  114. {
  115. if (!is_null($this->info))
  116. {
  117. return $this->info;
  118. }
  119. $this->info = array();
  120. $version = new JVersion;
  121. $platform = new JPlatform;
  122. $db = $this->getDbo();
  123. $this->info['php'] = php_uname();
  124. $this->info['dbversion'] = $db->getVersion();
  125. $this->info['dbcollation'] = $db->getCollation();
  126. $this->info['phpversion'] = phpversion();
  127. $this->info['server'] = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : getenv('SERVER_SOFTWARE');
  128. $this->info['sapi_name'] = php_sapi_name();
  129. $this->info['version'] = $version->getLongVersion();
  130. $this->info['platform'] = $platform->getLongVersion();
  131. $this->info['useragent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
  132. return $this->info;
  133. }
  134. /**
  135. * Method to get if phpinfo method is enabled from php.ini
  136. *
  137. * @return boolean True if enabled
  138. *
  139. * @since 3.4.1
  140. */
  141. public function phpinfoEnabled()
  142. {
  143. return !in_array('phpinfo', explode(',', ini_get('disable_functions')));
  144. }
  145. /**
  146. * Method to get the PHP info
  147. *
  148. * @return string PHP info
  149. *
  150. * @since 1.6
  151. */
  152. public function &getPHPInfo()
  153. {
  154. if (!$this->phpinfoEnabled())
  155. {
  156. $this->php_info = JText::_('COM_ADMIN_PHPINFO_DISABLED');
  157. return $this->php_info;
  158. }
  159. if (!is_null($this->php_info))
  160. {
  161. return $this->php_info;
  162. }
  163. ob_start();
  164. date_default_timezone_set('UTC');
  165. phpinfo(INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES);
  166. $phpInfo = ob_get_contents();
  167. ob_end_clean();
  168. preg_match_all('#<body[^>]*>(.*)</body>#siU', $phpInfo, $output);
  169. $output = preg_replace('#<table[^>]*>#', '<table class="table table-striped adminlist">', $output[1][0]);
  170. $output = preg_replace('#(\w),(\w)#', '\1, \2', $output);
  171. $output = preg_replace('#<hr />#', '', $output);
  172. $output = str_replace('<div class="center">', '', $output);
  173. $output = preg_replace('#<tr class="h">(.*)<\/tr>#', '<thead><tr class="h">$1</tr></thead><tbody>', $output);
  174. $output = str_replace('</table>', '</tbody></table>', $output);
  175. $output = str_replace('</div>', '', $output);
  176. $this->php_info = $output;
  177. return $this->php_info;
  178. }
  179. /**
  180. * Method to get the directory states
  181. *
  182. * @return array States of directories
  183. *
  184. * @since 1.6
  185. */
  186. public function getDirectory()
  187. {
  188. if (!is_null($this->directories))
  189. {
  190. return $this->directories;
  191. }
  192. $this->directories = array();
  193. $registry = JFactory::getConfig();
  194. $cparams = JComponentHelper::getParams('com_media');
  195. $this->_addDirectory('administrator/components', JPATH_ADMINISTRATOR . '/components');
  196. $this->_addDirectory('administrator/language', JPATH_ADMINISTRATOR . '/language');
  197. // List all admin languages
  198. $admin_langs = new DirectoryIterator(JPATH_ADMINISTRATOR . '/language');
  199. foreach ($admin_langs as $folder)
  200. {
  201. if (!$folder->isDir() || $folder->isDot())
  202. {
  203. continue;
  204. }
  205. $this->_addDirectory('administrator/language/' . $folder->getFilename(), JPATH_ADMINISTRATOR . '/language/' . $folder->getFilename());
  206. }
  207. // List all manifests folders
  208. $manifests = new DirectoryIterator(JPATH_ADMINISTRATOR . '/manifests');
  209. foreach ($manifests as $folder)
  210. {
  211. if (!$folder->isDir() || $folder->isDot())
  212. {
  213. continue;
  214. }
  215. $this->_addDirectory('administrator/manifests/' . $folder->getFilename(), JPATH_ADMINISTRATOR . '/manifests/' . $folder->getFilename());
  216. }
  217. $this->_addDirectory('administrator/modules', JPATH_ADMINISTRATOR . '/modules');
  218. $this->_addDirectory('administrator/templates', JPATH_THEMES);
  219. $this->_addDirectory('components', JPATH_SITE . '/components');
  220. $this->_addDirectory($cparams->get('image_path'), JPATH_SITE . '/' . $cparams->get('image_path'));
  221. // List all images folders
  222. $image_folders = new DirectoryIterator(JPATH_SITE . '/' . $cparams->get('image_path'));
  223. foreach ($image_folders as $folder)
  224. {
  225. if (!$folder->isDir() || $folder->isDot())
  226. {
  227. continue;
  228. }
  229. $this->_addDirectory('images/' . $folder->getFilename(), JPATH_SITE . '/' . $cparams->get('image_path') . '/' . $folder->getFilename());
  230. }
  231. $this->_addDirectory('language', JPATH_SITE . '/language');
  232. // List all site languages
  233. $site_langs = new DirectoryIterator(JPATH_SITE . '/language');
  234. foreach ($site_langs as $folder)
  235. {
  236. if (!$folder->isDir() || $folder->isDot())
  237. {
  238. continue;
  239. }
  240. $this->_addDirectory('language/' . $folder->getFilename(), JPATH_SITE . '/language/' . $folder->getFilename());
  241. }
  242. $this->_addDirectory('libraries', JPATH_LIBRARIES);
  243. $this->_addDirectory('media', JPATH_SITE . '/media');
  244. $this->_addDirectory('modules', JPATH_SITE . '/modules');
  245. $this->_addDirectory('plugins', JPATH_PLUGINS);
  246. $plugin_groups = new DirectoryIterator(JPATH_SITE . '/plugins');
  247. foreach ($plugin_groups as $folder)
  248. {
  249. if (!$folder->isDir() || $folder->isDot())
  250. {
  251. continue;
  252. }
  253. $this->_addDirectory('plugins/' . $folder->getFilename(), JPATH_PLUGINS . '/' . $folder->getFilename());
  254. }
  255. $this->_addDirectory('templates', JPATH_SITE . '/templates');
  256. $this->_addDirectory('configuration.php', JPATH_CONFIGURATION . '/configuration.php');
  257. // Is there a cache path in configuration.php?
  258. if ($cache_path = trim($registry->get('cache_path', '')))
  259. {
  260. // Frontend and backend use same directory for caching.
  261. $this->_addDirectory($cache_path, $cache_path, 'COM_ADMIN_CACHE_DIRECTORY');
  262. }
  263. else
  264. {
  265. $this->_addDirectory('cache', JPATH_SITE . '/cache', 'COM_ADMIN_CACHE_DIRECTORY');
  266. $this->_addDirectory('administrator/cache', JPATH_CACHE, 'COM_ADMIN_CACHE_DIRECTORY');
  267. }
  268. $this->_addDirectory($registry->get('log_path', JPATH_ROOT . '/log'), $registry->get('log_path', JPATH_ROOT . '/log'), 'COM_ADMIN_LOG_DIRECTORY');
  269. $this->_addDirectory($registry->get('tmp_path', JPATH_ROOT . '/tmp'), $registry->get('tmp_path', JPATH_ROOT . '/tmp'), 'COM_ADMIN_TEMP_DIRECTORY');
  270. return $this->directories;
  271. }
  272. /**
  273. * Method to add a directory
  274. *
  275. * @return void
  276. * @since 1.6
  277. */
  278. /**
  279. * Method to add a directory
  280. *
  281. * @param string $name Directory Name
  282. * @param string $path Directory path
  283. * @param string $message Message
  284. *
  285. * @return void
  286. */
  287. private function _addDirectory($name, $path, $message = '')
  288. {
  289. $this->directories[$name] = array('writable' => is_writable($path), 'message' => $message);
  290. }
  291. /**
  292. * Method to get the editor
  293. *
  294. * @return string The default editor
  295. *
  296. * @note: has to be removed (it is present in the config...)
  297. *
  298. * @since 1.6
  299. */
  300. public function &getEditor()
  301. {
  302. if (!is_null($this->editor))
  303. {
  304. return $this->editor;
  305. }
  306. $this->editor = JFactory::getConfig()->get('editor');
  307. return $this->editor;
  308. }
  309. }