PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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