PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/ot2sen/Molajo
PHP | 244 lines | 154 code | 25 blank | 65 comment | 14 complexity | 959b154b8ed5afbfa1941a2a2053b718 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: sysinfo.php 21518 2011-06-10 21:38:12Z chdemko $
  4. * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // no direct access
  8. defined('_JEXEC') or die;
  9. jimport('joomla.application.component.model');
  10. /**
  11. * @package Joomla.Administrator
  12. * @subpackage com_admin
  13. * * * @since 1.0
  14. */
  15. class AdminModelSysInfo extends JModel
  16. {
  17. /**
  18. * @var array some php settings
  19. */
  20. protected $php_settings = null;
  21. /**
  22. * @var array config values
  23. */
  24. protected $config = null;
  25. /**
  26. * @var array somme system values
  27. */
  28. protected $info = null;
  29. /**
  30. * @var string php info
  31. */
  32. protected $php_info = null;
  33. /**
  34. * @var array informations about writable state of directories
  35. */
  36. protected $directories = null;
  37. /**
  38. * @var string The current editor.
  39. */
  40. protected $editor = null;
  41. /**
  42. * Method to get the ChangeLog
  43. *
  44. * @return array some php settings
  45. */
  46. function &getPhpSettings()
  47. {
  48. if (is_null($this->php_settings))
  49. {
  50. $this->php_settings = array();
  51. $this->php_settings['safe_mode'] = ini_get('safe_mode') == '1';
  52. $this->php_settings['display_errors'] = ini_get('display_errors') == '1';
  53. $this->php_settings['short_open_tag'] = ini_get('short_open_tag') == '1';
  54. $this->php_settings['file_uploads'] = ini_get('file_uploads') == '1';
  55. $this->php_settings['magic_quotes_gpc'] = ini_get('magic_quotes_gpc') == '1';
  56. $this->php_settings['register_globals'] = ini_get('register_globals') == '1';
  57. $this->php_settings['output_buffering'] = (bool) ini_get('output_buffering');
  58. $this->php_settings['open_basedir'] = ini_get('open_basedir');
  59. $this->php_settings['session.save_path'] = ini_get('session.save_path');
  60. $this->php_settings['session.auto_start'] = ini_get('session.auto_start');
  61. $this->php_settings['disable_functions'] = ini_get('disable_functions');
  62. $this->php_settings['xml'] = extension_loaded('xml');
  63. $this->php_settings['zlib'] = extension_loaded('zlib');
  64. $this->php_settings['mbstring'] = extension_loaded('mbstring');
  65. $this->php_settings['iconv'] = function_exists('iconv');
  66. }
  67. return $this->php_settings;
  68. }
  69. /**
  70. * method to get the config
  71. *
  72. * @return array config values
  73. */
  74. function &getConfig()
  75. {
  76. if (is_null($this->config))
  77. {
  78. $registry = MolajoFactory::getConfig();
  79. $this->config = $registry->toArray();
  80. $hidden = array('host', 'user', 'password', 'ftp_user', 'ftp_pass', 'smtpuser', 'smtppass');
  81. foreach($hidden as $key) {
  82. $this->config[$key] = 'xxxxxx';
  83. }
  84. }
  85. return $this->config;
  86. }
  87. /**
  88. * method to get the system information
  89. *
  90. * @return array system information values
  91. */
  92. function &getInfo()
  93. {
  94. if (is_null($this->info))
  95. {
  96. $this->info = array();
  97. $version = new MolajoVersion();
  98. $platform = new JPlatform();
  99. $db = MolajoFactory::getDBO();
  100. if (isset($_SERVER['SERVER_SOFTWARE'])) {
  101. $sf = $_SERVER['SERVER_SOFTWARE'];
  102. }
  103. else {
  104. $sf = getenv('SERVER_SOFTWARE');
  105. }
  106. $this->info['php'] = php_uname();
  107. $this->info['dbversion'] = $db->getVersion();
  108. $this->info['dbcollation'] = $db->getCollation();
  109. $this->info['phpversion'] = phpversion();
  110. $this->info['server'] = $sf;
  111. $this->info['sapi_name'] = php_sapi_name();
  112. $this->info['version'] = $version->getLongVersion();
  113. $this->info['platform'] = $platform->getLongVersion();
  114. $this->info['useragent'] = phpversion() <= '4.2.1' ? getenv("HTTP_USER_AGENT") : $_SERVER['HTTP_USER_AGENT'];
  115. }
  116. return $this->info;
  117. }
  118. /**
  119. * method to get the PHP info
  120. *
  121. * @return string PHP info
  122. */
  123. function &getPHPInfo()
  124. {
  125. if (is_null($this->php_info))
  126. {
  127. ob_start();
  128. date_default_timezone_set('UTC');
  129. phpinfo(INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES);
  130. $phpinfo = ob_get_contents();
  131. ob_end_clean();
  132. preg_match_all('#<body[^>]*>(.*)</body>#siU', $phpinfo, $output);
  133. $output = preg_replace('#<table[^>]*>#', '<table class="adminlist">', $output[1][0]);
  134. $output = preg_replace('#(\w),(\w)#', '\1, \2', $output);
  135. $output = preg_replace('#<hr />#', '', $output);
  136. $output = str_replace('<div class="center">', '', $output);
  137. $output = preg_replace('#<tr class="h">(.*)<\/tr>#', '<thead><tr class="h">$1</tr></thead><tbody>', $output);
  138. $output = str_replace('</table>', '</tbody></table>', $output);
  139. $output = str_replace('</div>', '', $output);
  140. $this->php_info = $output;
  141. }
  142. return $this->php_info;
  143. }
  144. /**
  145. * method to get the directory states
  146. *
  147. * @return array states of directories
  148. */
  149. public function getDirectory() {
  150. if (is_null($this->directories))
  151. {
  152. $this->directories = array();
  153. $registry = MolajoFactory::getConfig();
  154. jimport('joomla.filesystem.folder');
  155. $cparams = JComponentHelper::getParams('com_media');
  156. $this->_addDirectory('administrator/components', JPATH_ADMINISTRATOR.'/components');
  157. $this->_addDirectory('administrator/language', JPATH_ADMINISTRATOR.'/language');
  158. // List all admin languages
  159. $admin_langs = JFolder::folders(JPATH_ADMINISTRATOR.'/language');
  160. foreach($admin_langs as $alang) {
  161. $this->_addDirectory('administrator/language/' . $alang, JPATH_ADMINISTRATOR.'/language/'.$alang);
  162. }
  163. // List all manifests folders
  164. $manifests = JFolder::folders(JPATH_ADMINISTRATOR.'/manifests');
  165. foreach($manifests as $_manifest) {
  166. $this->_addDirectory('administrator/manifests/' . $_manifest, JPATH_ADMINISTRATOR.'/manifests/'.$_manifest);
  167. }
  168. $this->_addDirectory('administrator/modules', JPATH_ADMINISTRATOR.'/modules');
  169. $this->_addDirectory('administrator/templates', JPATH_THEMES);
  170. $this->_addDirectory('components', JPATH_SITE.'/components');
  171. $this->_addDirectory($cparams->get('image_path'), JPATH_SITE.'/'.$cparams->get('image_path'));
  172. $image_folders = JFolder::folders(JPATH_SITE.'/'.$cparams->get('image_path'));
  173. // List all images folders
  174. foreach ($image_folders as $folder) {
  175. $this->_addDirectory('images/' . $folder, JPATH_SITE.'/'.$cparams->get('image_path').'/'.$folder);
  176. }
  177. $this->_addDirectory('language', JPATH_SITE.'/language');
  178. // List all site languages
  179. $site_langs = JFolder::folders(JPATH_SITE . '/language');
  180. foreach ($site_langs as $slang) {
  181. $this->_addDirectory('language/' . $slang, JPATH_SITE.'/language/'.$slang);
  182. }
  183. $this->_addDirectory('libraries', JPATH_LIBRARIES);
  184. $this->_addDirectory('media', JPATH_SITE.'/media');
  185. $this->_addDirectory('modules', JPATH_SITE.'/modules');
  186. $this->_addDirectory('plugins', JPATH_PLUGINS);
  187. $plugin_groups = JFolder::folders(JPATH_PLUGINS);
  188. foreach ($plugin_groups as $folder) {
  189. $this->_addDirectory('plugins/' . $folder, JPATH_PLUGINS.'/'.$folder);
  190. }
  191. $this->_addDirectory('templates', JPATH_SITE.'/templates');
  192. $this->_addDirectory('configuration.php', JPATH_CONFIGURATION.'/configuration.php');
  193. $this->_addDirectory('cache', JPATH_SITE.'/cache', 'COM_ADMIN_CACHE_DIRECTORY');
  194. $this->_addDirectory('administrator/cache', JPATH_CACHE, 'COM_ADMIN_CACHE_DIRECTORY');
  195. $this->_addDirectory($registry->get('log_path', JPATH_ROOT . '/log'), $registry->get('log_path', JPATH_ROOT.'/log'), 'COM_ADMIN_LOG_DIRECTORY');
  196. $this->_addDirectory($registry->get('tmp_path', JPATH_ROOT . '/tmp'), $registry->get('tmp_path', JPATH_ROOT.'/tmp'), 'COM_ADMIN_TEMP_DIRECTORY');
  197. }
  198. return $this->directories;
  199. }
  200. private function _addDirectory($name, $path, $message = '') {
  201. $this->directories[$name] = array('writable' => is_writable($path), 'message' => $message);
  202. }
  203. /**
  204. * method to get the editor
  205. *
  206. * @return string the default editor
  207. *
  208. * has to be removed (it is present in the config...)
  209. */
  210. function &getEditor()
  211. {
  212. if (is_null($this->editor))
  213. {
  214. $config = MolajoFactory::getConfig();
  215. $this->editor = $config->get('editor');
  216. }
  217. return $this->editor;
  218. }
  219. }