diagnoser.lib.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class Diagnoser
  5. * Class that is responsible for generating diagnostic information about the system.
  6. *
  7. * @package chamilo.diagnoser
  8. *
  9. * @author Ivan Tcholakov, 2008, initial proposal and sample code.
  10. * @author spou595, 2009, implementation for Chamilo 2.x
  11. * @author Julio Montoya <gugli100@gmail.com>, 2010, port to chamilo 1.8.7, Some fixes
  12. */
  13. class Diagnoser
  14. {
  15. const STATUS_OK = 1;
  16. const STATUS_WARNING = 2;
  17. const STATUS_ERROR = 3;
  18. const STATUS_INFORMATION = 4;
  19. /**
  20. * Contructor.
  21. */
  22. public function __construct()
  23. {
  24. }
  25. /**
  26. * Show html table.
  27. */
  28. public function show_html()
  29. {
  30. $sections = [
  31. 'chamilo' => [
  32. 'lang' => 'Chamilo',
  33. 'info' => 'State of Chamilo requirements',
  34. ],
  35. 'php' => [
  36. 'lang' => 'PHP',
  37. 'info' => 'State of PHP settings on the server',
  38. ],
  39. 'database' => [
  40. 'lang' => 'Database',
  41. 'info' => 'Configuration settings of the database server. To check the database consistency after an upgrade, if you have access to the command line, you can use "php bin/doctrine.php orm:schema-tool:update --dump-sql". This will print a list of database changes that should be applied to your system in order to get the right structure. Index name changes can be ignored. Use "--force" instead of "--dump" to try and execute them in order.',
  42. ],
  43. 'webserver' => [
  44. 'lang' => get_lang('WebServer'),
  45. 'info' => 'Information about your webserver\'s configuration ',
  46. ],
  47. 'paths' => [
  48. 'lang' => 'Paths',
  49. 'info' => 'The following paths are called by their constant throughout Chamilo\'s code using the api_get_path() function. Here is a list of these paths and what they would be translated to on this portal.',
  50. ],
  51. ];
  52. $currentSection = isset($_GET['section']) ? $_GET['section'] : '';
  53. if (!in_array(trim($currentSection), array_keys($sections))) {
  54. $currentSection = 'chamilo';
  55. }
  56. $html = '<div class="tabbable"><ul class="nav nav-tabs">';
  57. foreach ($sections as $section => $details) {
  58. if ($currentSection === $section) {
  59. $html .= '<li class="active">';
  60. } else {
  61. $html .= '<li>';
  62. }
  63. $params['section'] = $section;
  64. $html .= '<a href="system_status.php?section='.$section.'">'.$details['lang'].'</a></li>';
  65. }
  66. $html .= '</ul><div class="tab-pane">';
  67. $data = call_user_func([$this, 'get_'.$currentSection.'_data']);
  68. echo $html;
  69. if ($currentSection != 'paths') {
  70. echo '<br />';
  71. echo Display::return_message($sections[$currentSection]['info'], 'normal');
  72. $table = new SortableTableFromArray($data, 1, 100);
  73. $table->set_header(0, '', false);
  74. $table->set_header(1, get_lang('Section'), false);
  75. $table->set_header(2, get_lang('Setting'), false);
  76. $table->set_header(3, get_lang('Current'), false);
  77. $table->set_header(4, get_lang('Expected'), false);
  78. $table->set_header(5, get_lang('Comment'), false);
  79. $table->display();
  80. } else {
  81. echo '<br />';
  82. echo Display::return_message($sections[$currentSection]['info'], 'normal');
  83. $headers = $data['headers'];
  84. $results = $data['data'];
  85. $table = new HTML_Table(['class' => 'data_table']);
  86. $column = 0;
  87. foreach ($headers as $header) {
  88. $table->setHeaderContents(0, $column, $header);
  89. $column++;
  90. }
  91. $row = 1;
  92. foreach ($results as $index => $rowData) {
  93. $table->setCellContents(
  94. $row,
  95. 0,
  96. $rowData
  97. );
  98. $table->setCellContents(
  99. $row,
  100. 1,
  101. $index
  102. );
  103. $row++;
  104. }
  105. $table->display();
  106. }
  107. echo '</div></div>';
  108. }
  109. /**
  110. * @return array
  111. */
  112. public function get_paths_data()
  113. {
  114. global $paths;
  115. $list = $paths[api_get_path(WEB_PATH)];
  116. $list['url_append'] = api_get_configuration_value('url_append');
  117. asort($list);
  118. return [
  119. 'headers' => ['Path', 'constant'],
  120. 'data' => $list,
  121. ];
  122. }
  123. /**
  124. * Functions to get the data for the chamilo diagnostics.
  125. *
  126. * @return array of data
  127. */
  128. public function get_chamilo_data()
  129. {
  130. $array = [];
  131. $writable_folders = [
  132. api_get_path(SYS_APP_PATH).'cache',
  133. api_get_path(SYS_COURSE_PATH),
  134. api_get_path(SYS_APP_PATH).'home',
  135. api_get_path(SYS_APP_PATH).'upload/users/',
  136. api_get_path(SYS_PATH).'main/default_course_document/images/',
  137. ];
  138. foreach ($writable_folders as $index => $folder) {
  139. $writable = is_writable($folder);
  140. $status = $writable ? self::STATUS_OK : self::STATUS_ERROR;
  141. $array[] = $this->build_setting(
  142. $status,
  143. '[FILES]',
  144. get_lang('IsWritable').': '.$folder,
  145. 'http://be2.php.net/manual/en/function.is-writable.php',
  146. $writable,
  147. 1,
  148. 'yes_no',
  149. get_lang('DirectoryMustBeWritable')
  150. );
  151. }
  152. $exists = file_exists(api_get_path(SYS_CODE_PATH).'install');
  153. $status = $exists ? self::STATUS_WARNING : self::STATUS_OK;
  154. $array[] = $this->build_setting(
  155. $status,
  156. '[FILES]',
  157. get_lang('DirectoryExists').': /install',
  158. 'http://be2.php.net/file_exists',
  159. $exists,
  160. 0,
  161. 'yes_no',
  162. get_lang('DirectoryShouldBeRemoved')
  163. );
  164. $app_version = api_get_setting('chamilo_database_version');
  165. $array[] = $this->build_setting(
  166. self::STATUS_INFORMATION,
  167. '[DB]',
  168. 'chamilo_database_version',
  169. '#',
  170. $app_version,
  171. 0,
  172. null,
  173. 'Chamilo DB version'
  174. );
  175. $access_url_id = api_get_current_access_url_id();
  176. if ($access_url_id === 1) {
  177. $size = '-';
  178. global $_configuration;
  179. $message2 = '';
  180. if ($access_url_id === 1) {
  181. if (api_is_windows_os()) {
  182. $message2 .= get_lang('SpaceUsedOnSystemCannotBeMeasuredOnWindows');
  183. } else {
  184. $dir = api_get_path(SYS_PATH);
  185. $du = exec('du -sh '.$dir, $err);
  186. list($size, $none) = explode("\t", $du);
  187. unset($none);
  188. $limit = 0;
  189. if (isset($_configuration[$access_url_id])) {
  190. if (isset($_configuration[$access_url_id]['hosting_limit_disk_space'])) {
  191. $limit = $_configuration[$access_url_id]['hosting_limit_disk_space'];
  192. }
  193. }
  194. $message2 .= sprintf(get_lang('TotalSpaceUsedByPortalXLimitIsYMB'), $size, $limit);
  195. }
  196. }
  197. $array[] = $this->build_setting(
  198. self::STATUS_OK,
  199. '[FILES]',
  200. 'hosting_limit_disk_space',
  201. '#',
  202. $size,
  203. 0,
  204. null,
  205. $message2
  206. );
  207. }
  208. $new_version = '-';
  209. $new_version_status = '';
  210. $file = api_get_path(SYS_CODE_PATH).'install/version.php';
  211. if (is_file($file)) {
  212. @include $file;
  213. }
  214. $array[] = $this->build_setting(
  215. self::STATUS_INFORMATION,
  216. '[CONFIG]',
  217. get_lang('VersionFromVersionFile'),
  218. '#',
  219. $new_version.' '.$new_version_status,
  220. '-',
  221. null,
  222. get_lang('TheVersionFromTheVersionFileIsUpdatedWithEachVersionIfMainInstallDirectoryIsPresent')
  223. );
  224. $array[] = $this->build_setting(
  225. self::STATUS_INFORMATION,
  226. '[CONFIG]',
  227. get_lang('VersionFromConfigFile'),
  228. '#',
  229. api_get_configuration_value('system_version'),
  230. $new_version,
  231. null,
  232. get_lang('TheVersionFromTheConfigurationFileShowsOnTheAdminPageButHasToBeChangedManuallyOnUpgrade')
  233. );
  234. return $array;
  235. }
  236. /**
  237. * Functions to get the data for the php diagnostics.
  238. *
  239. * @return array of data
  240. */
  241. public function get_php_data()
  242. {
  243. $array = [];
  244. // General Functions
  245. $version = phpversion();
  246. $status = $version > REQUIRED_PHP_VERSION ? self::STATUS_OK : self::STATUS_ERROR;
  247. $array[] = $this->build_setting(
  248. $status,
  249. '[PHP]',
  250. 'phpversion()',
  251. 'http://www.php.net/manual/en/function.phpversion.php',
  252. phpversion(),
  253. '>= '.REQUIRED_PHP_VERSION,
  254. null,
  255. get_lang('PHPVersionInfo')
  256. );
  257. $setting = ini_get('output_buffering');
  258. $req_setting = 1;
  259. $status = $setting >= $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  260. $array[] = $this->build_setting(
  261. $status,
  262. '[INI]',
  263. 'output_buffering',
  264. 'http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering',
  265. $setting,
  266. $req_setting,
  267. 'on_off',
  268. get_lang('OutputBufferingInfo')
  269. );
  270. $setting = ini_get('file_uploads');
  271. $req_setting = 1;
  272. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  273. $array[] = $this->build_setting(
  274. $status,
  275. '[INI]',
  276. 'file_uploads',
  277. 'http://www.php.net/manual/en/ini.core.php#ini.file-uploads',
  278. $setting,
  279. $req_setting,
  280. 'on_off',
  281. get_lang('FileUploadsInfo')
  282. );
  283. $setting = ini_get('magic_quotes_runtime');
  284. $req_setting = 0;
  285. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  286. $array[] = $this->build_setting(
  287. $status,
  288. '[INI]',
  289. 'magic_quotes_runtime',
  290. 'http://www.php.net/manual/en/ini.core.php#ini.magic-quotes-runtime',
  291. $setting,
  292. $req_setting,
  293. 'on_off',
  294. get_lang('MagicQuotesRuntimeInfo')
  295. );
  296. $setting = ini_get('safe_mode');
  297. $req_setting = 0;
  298. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  299. $array[] = $this->build_setting(
  300. $status,
  301. '[INI]',
  302. 'safe_mode',
  303. 'http://www.php.net/manual/en/ini.core.php#ini.safe-mode',
  304. $setting,
  305. $req_setting,
  306. 'on_off',
  307. get_lang('SafeModeInfo')
  308. );
  309. $setting = ini_get('register_globals');
  310. $req_setting = 0;
  311. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  312. $array[] = $this->build_setting(
  313. $status,
  314. '[INI]',
  315. 'register_globals',
  316. 'http://www.php.net/manual/en/ini.core.php#ini.register-globals',
  317. $setting,
  318. $req_setting,
  319. 'on_off',
  320. get_lang('RegisterGlobalsInfo')
  321. );
  322. $setting = ini_get('short_open_tag');
  323. $req_setting = 0;
  324. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  325. $array[] = $this->build_setting(
  326. $status,
  327. '[INI]',
  328. 'short_open_tag',
  329. 'http://www.php.net/manual/en/ini.core.php#ini.short-open-tag',
  330. $setting,
  331. $req_setting,
  332. 'on_off',
  333. get_lang('ShortOpenTagInfo')
  334. );
  335. $setting = ini_get('magic_quotes_gpc');
  336. $req_setting = 0;
  337. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  338. $array[] = $this->build_setting(
  339. $status,
  340. '[INI]',
  341. 'magic_quotes_gpc',
  342. 'http://www.php.net/manual/en/ini.core.php#ini.magic_quotes_gpc',
  343. $setting,
  344. $req_setting,
  345. 'on_off',
  346. get_lang('MagicQuotesGpcInfo')
  347. );
  348. $setting = ini_get('display_errors');
  349. $req_setting = 0;
  350. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  351. $array[] = $this->build_setting(
  352. $status,
  353. '[INI]',
  354. 'display_errors',
  355. 'http://www.php.net/manual/en/ini.core.php#ini.display_errors',
  356. $setting,
  357. $req_setting,
  358. 'on_off',
  359. get_lang('DisplayErrorsInfo')
  360. );
  361. $setting = ini_get('default_charset');
  362. if ($setting == '') {
  363. $setting = null;
  364. }
  365. $req_setting = 'UTF-8';
  366. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  367. $array[] = $this->build_setting(
  368. $status,
  369. '[INI]',
  370. 'default_charset',
  371. 'http://www.php.net/manual/en/ini.core.php#ini.default-charset',
  372. $setting,
  373. $req_setting,
  374. null,
  375. get_lang('DefaultCharsetInfo')
  376. );
  377. $setting = ini_get('max_execution_time');
  378. $req_setting = '300 ('.get_lang('Minimum').')';
  379. $status = $setting >= 300 ? self::STATUS_OK : self::STATUS_WARNING;
  380. $array[] = $this->build_setting(
  381. $status,
  382. '[INI]',
  383. 'max_execution_time',
  384. 'http://www.php.net/manual/en/ini.core.php#ini.max-execution-time',
  385. $setting,
  386. $req_setting,
  387. null,
  388. get_lang('MaxExecutionTimeInfo')
  389. );
  390. $setting = ini_get('max_input_time');
  391. $req_setting = '300 ('.get_lang('Minimum').')';
  392. $status = $setting >= 300 ? self::STATUS_OK : self::STATUS_WARNING;
  393. $array[] = $this->build_setting(
  394. $status,
  395. '[INI]',
  396. 'max_input_time',
  397. 'http://www.php.net/manual/en/ini.core.php#ini.max-input-time',
  398. $setting,
  399. $req_setting,
  400. null,
  401. get_lang('MaxInputTimeInfo')
  402. );
  403. $setting = ini_get('memory_limit');
  404. $req_setting = '>= '.REQUIRED_MIN_MEMORY_LIMIT.'M';
  405. $status = self::STATUS_ERROR;
  406. if ((float) $setting >= REQUIRED_MIN_MEMORY_LIMIT) {
  407. $status = self::STATUS_OK;
  408. }
  409. $array[] = $this->build_setting(
  410. $status,
  411. '[INI]',
  412. 'memory_limit',
  413. 'http://www.php.net/manual/en/ini.core.php#ini.memory-limit',
  414. $setting,
  415. $req_setting,
  416. null,
  417. get_lang('MemoryLimitInfo')
  418. );
  419. $setting = ini_get('post_max_size');
  420. $req_setting = '>= '.REQUIRED_MIN_POST_MAX_SIZE.'M';
  421. $status = self::STATUS_ERROR;
  422. if ((float) $setting >= REQUIRED_MIN_POST_MAX_SIZE) {
  423. $status = self::STATUS_OK;
  424. }
  425. $array[] = $this->build_setting(
  426. $status,
  427. '[INI]',
  428. 'post_max_size',
  429. 'http://www.php.net/manual/en/ini.core.php#ini.post-max-size',
  430. $setting,
  431. $req_setting,
  432. null,
  433. get_lang('PostMaxSizeInfo')
  434. );
  435. $setting = ini_get('upload_max_filesize');
  436. $req_setting = '>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M';
  437. $status = self::STATUS_ERROR;
  438. if ((float) $setting >= REQUIRED_MIN_UPLOAD_MAX_FILESIZE) {
  439. $status = self::STATUS_OK;
  440. }
  441. $array[] = $this->build_setting(
  442. $status,
  443. '[INI]',
  444. 'upload_max_filesize',
  445. 'http://www.php.net/manual/en/ini.core.php#ini.upload_max_filesize',
  446. $setting,
  447. $req_setting,
  448. null,
  449. get_lang('UploadMaxFilesizeInfo')
  450. );
  451. $setting = ini_get('upload_tmp_dir');
  452. $status = self::STATUS_OK;
  453. $array[] = $this->build_setting(
  454. $status,
  455. '[INI]',
  456. 'upload_tmp_dir',
  457. 'http://www.php.net/manual/en/ini.core.php#ini.upload_tmp_dir',
  458. $setting,
  459. '',
  460. null,
  461. get_lang('UploadTmpDirInfo')
  462. );
  463. $setting = ini_get('variables_order');
  464. $req_setting = 'GPCS';
  465. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  466. $array[] = $this->build_setting(
  467. $status,
  468. '[INI]',
  469. 'variables_order',
  470. 'http://www.php.net/manual/en/ini.core.php#ini.variables-order',
  471. $setting,
  472. $req_setting,
  473. null,
  474. get_lang('VariablesOrderInfo')
  475. );
  476. $setting = ini_get('session.gc_maxlifetime');
  477. $req_setting = '4320';
  478. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  479. $array[] = $this->build_setting(
  480. $status,
  481. '[SESSION]',
  482. 'session.gc_maxlifetime',
  483. 'http://www.php.net/manual/en/ini.core.php#session.gc-maxlifetime',
  484. $setting,
  485. $req_setting,
  486. null,
  487. get_lang('SessionGCMaxLifetimeInfo')
  488. );
  489. if (api_check_browscap()) {
  490. $setting = true;
  491. } else {
  492. $setting = false;
  493. }
  494. $req_setting = true;
  495. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  496. $array[] = $this->build_setting(
  497. $status,
  498. '[INI]',
  499. 'browscap',
  500. 'http://www.php.net/manual/en/misc.configuration.php#ini.browscap',
  501. $setting,
  502. $req_setting,
  503. 'on_off',
  504. get_lang('BrowscapInfo')
  505. );
  506. // Extensions
  507. $extensions = [
  508. 'gd' => [
  509. 'link' => 'http://www.php.net/gd',
  510. 'expected' => 1,
  511. 'comment' => get_lang('ExtensionMustBeLoaded'),
  512. ],
  513. 'pdo_mysql' => [
  514. 'link' => 'http://php.net/manual/en/ref.pdo-mysql.php',
  515. 'expected' => 1,
  516. 'comment' => get_lang('ExtensionMustBeLoaded'),
  517. ],
  518. 'pcre' => [
  519. 'link' => 'http://www.php.net/pcre',
  520. 'expected' => 1,
  521. 'comment' => get_lang('ExtensionMustBeLoaded'),
  522. ],
  523. 'session' => [
  524. 'link' => 'http://www.php.net/session',
  525. 'expected' => 1,
  526. 'comment' => get_lang('ExtensionMustBeLoaded'),
  527. ],
  528. 'standard' => [
  529. 'link' => 'http://www.php.net/spl',
  530. 'expected' => 1,
  531. 'comment' => get_lang('ExtensionMustBeLoaded'),
  532. ],
  533. 'zlib' => [
  534. 'link' => 'http://www.php.net/zlib',
  535. 'expected' => 1,
  536. 'comment' => get_lang('ExtensionMustBeLoaded'),
  537. ],
  538. 'xsl' => [
  539. 'link' => 'http://be2.php.net/xsl',
  540. 'expected' => 2,
  541. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  542. ],
  543. 'curl' => [
  544. 'link' => 'http://www.php.net/curl',
  545. 'expected' => 2,
  546. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  547. ],
  548. 'Zend OPcache' => [
  549. 'link' => 'http://www.php.net/opcache',
  550. 'expected' => 2,
  551. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  552. ],
  553. 'apcu' => [
  554. 'link' => 'http://www.php.net/apcu',
  555. 'expected' => 2,
  556. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  557. ],
  558. ];
  559. foreach ($extensions as $extension => $data) {
  560. $url = $data['link'];
  561. $expected_value = $data['expected'];
  562. $comment = $data['comment'];
  563. $loaded = extension_loaded($extension);
  564. $status = $loaded ? self::STATUS_OK : self::STATUS_ERROR;
  565. $array[] = $this->build_setting(
  566. $status,
  567. '[EXTENSION]',
  568. get_lang('LoadedExtension').': '.$extension,
  569. $url,
  570. $loaded,
  571. $expected_value,
  572. 'yes_no_optional',
  573. $comment
  574. );
  575. }
  576. return $array;
  577. }
  578. /**
  579. * Functions to get the data for the mysql diagnostics.
  580. *
  581. * @return array of data
  582. */
  583. public function get_database_data()
  584. {
  585. $array = [];
  586. $em = Database::getManager();
  587. $connection = $em->getConnection();
  588. $host = $connection->getHost();
  589. $db = $connection->getDatabase();
  590. $port = $connection->getPort();
  591. $driver = $connection->getDriver()->getName();
  592. $array[] = $this->build_setting(
  593. self::STATUS_INFORMATION,
  594. '[Database]',
  595. 'driver',
  596. '',
  597. $driver,
  598. null,
  599. null,
  600. get_lang('Driver')
  601. );
  602. $array[] = $this->build_setting(
  603. self::STATUS_INFORMATION,
  604. '[Database]',
  605. 'host',
  606. '',
  607. $host,
  608. null,
  609. null,
  610. get_lang('MysqlHostInfo')
  611. );
  612. $array[] = $this->build_setting(
  613. self::STATUS_INFORMATION,
  614. '[Database]',
  615. 'port',
  616. '',
  617. $port,
  618. null,
  619. null,
  620. get_lang('Port')
  621. );
  622. $array[] = $this->build_setting(
  623. self::STATUS_INFORMATION,
  624. '[Database]',
  625. 'Database name',
  626. '',
  627. $db,
  628. null,
  629. null,
  630. get_lang('Name')
  631. );
  632. return $array;
  633. }
  634. /**
  635. * Functions to get the data for the webserver diagnostics.
  636. *
  637. * @return array of data
  638. */
  639. public function get_webserver_data()
  640. {
  641. $array = [];
  642. $array[] = $this->build_setting(
  643. self::STATUS_INFORMATION,
  644. '[SERVER]',
  645. '$_SERVER["SERVER_NAME"]',
  646. 'http://be.php.net/reserved.variables.server',
  647. $_SERVER["SERVER_NAME"],
  648. null,
  649. null,
  650. get_lang('ServerNameInfo')
  651. );
  652. $array[] = $this->build_setting(
  653. self::STATUS_INFORMATION,
  654. '[SERVER]',
  655. '$_SERVER["SERVER_ADDR"]',
  656. 'http://be.php.net/reserved.variables.server',
  657. $_SERVER["SERVER_ADDR"],
  658. null,
  659. null,
  660. get_lang('ServerAddessInfo')
  661. );
  662. $array[] = $this->build_setting(
  663. self::STATUS_INFORMATION,
  664. '[SERVER]',
  665. '$_SERVER["SERVER_PORT"]',
  666. 'http://be.php.net/reserved.variables.server',
  667. $_SERVER["SERVER_PORT"],
  668. null,
  669. null,
  670. get_lang('ServerPortInfo')
  671. );
  672. $array[] = $this->build_setting(
  673. self::STATUS_INFORMATION,
  674. '[SERVER]',
  675. '$_SERVER["SERVER_SOFTWARE"]',
  676. 'http://be.php.net/reserved.variables.server',
  677. $_SERVER["SERVER_SOFTWARE"],
  678. null,
  679. null,
  680. get_lang('ServerSoftwareInfo')
  681. );
  682. $array[] = $this->build_setting(
  683. self::STATUS_INFORMATION,
  684. '[SERVER]',
  685. '$_SERVER["REMOTE_ADDR"]',
  686. 'http://be.php.net/reserved.variables.server',
  687. $_SERVER["REMOTE_ADDR"],
  688. null,
  689. null,
  690. get_lang('ServerRemoteInfo')
  691. );
  692. $array[] = $this->build_setting(
  693. self::STATUS_INFORMATION,
  694. '[SERVER]',
  695. '$_SERVER["HTTP_USER_AGENT"]',
  696. 'http://be.php.net/reserved.variables.server',
  697. $_SERVER["HTTP_USER_AGENT"],
  698. null,
  699. null,
  700. get_lang('ServerUserAgentInfo')
  701. );
  702. $array[] = $this->build_setting(
  703. self::STATUS_INFORMATION,
  704. '[SERVER]',
  705. '$_SERVER["SERVER_PROTOCOL"]',
  706. 'http://be.php.net/reserved.variables.server',
  707. $_SERVER["SERVER_PROTOCOL"],
  708. null,
  709. null,
  710. get_lang('ServerProtocolInfo')
  711. );
  712. $array[] = $this->build_setting(
  713. self::STATUS_INFORMATION,
  714. '[SERVER]',
  715. 'php_uname()',
  716. 'http://be2.php.net/php_uname',
  717. php_uname(),
  718. null,
  719. null,
  720. get_lang('UnameInfo')
  721. );
  722. $array[] = $this->build_setting(
  723. self::STATUS_INFORMATION,
  724. '[SERVER]',
  725. '$_SERVER["HTTP_X_FORWARDED_FOR"]',
  726. 'http://be.php.net/reserved.variables.server',
  727. (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : ''),
  728. null,
  729. null,
  730. get_lang('ServerXForwardedForInfo')
  731. );
  732. return $array;
  733. }
  734. /**
  735. * Additional functions needed for fast integration.
  736. *
  737. * @param int $status Status constant defining which icon to use to illustrate the info
  738. * @param string $section The name of the section this setting is included in
  739. * @param string $title The name of the setting (usually a translated string)
  740. * @param string $url A URL to point the user to regarding this setting, or '#' otherwise
  741. * @param mixed $current_value The current value for this setting
  742. * @param mixed $expected_value The expected value for this setting
  743. * @param string $formatter If this setting is expressed in some kind of format, which format to use
  744. * @param string $comment A translated string explaining what this setting represents
  745. *
  746. * @return array A list of elements to show in an array's row
  747. */
  748. public function build_setting(
  749. $status,
  750. $section,
  751. $title,
  752. $url,
  753. $current_value,
  754. $expected_value,
  755. $formatter,
  756. $comment
  757. ) {
  758. switch ($status) {
  759. case self::STATUS_OK:
  760. $img = 'bullet_green.png';
  761. break;
  762. case self::STATUS_WARNING:
  763. $img = 'bullet_orange.png';
  764. break;
  765. case self::STATUS_ERROR:
  766. $img = 'bullet_red.png';
  767. break;
  768. case self::STATUS_INFORMATION:
  769. default:
  770. $img = 'bullet_blue.png';
  771. break;
  772. }
  773. $image = Display::return_icon($img, $status);
  774. $url = $this->get_link($title, $url);
  775. $formatted_current_value = $current_value;
  776. $formatted_expected_value = $expected_value;
  777. if ($formatter) {
  778. if (method_exists($this, 'format_'.$formatter)) {
  779. $formatted_current_value = call_user_func([$this, 'format_'.$formatter], $current_value);
  780. $formatted_expected_value = call_user_func([$this, 'format_'.$formatter], $expected_value);
  781. }
  782. }
  783. return [$image, $section, $url, $formatted_current_value, $formatted_expected_value, $comment];
  784. }
  785. /**
  786. * Create a link with a url and a title.
  787. *
  788. * @param $title
  789. * @param $url
  790. *
  791. * @return string the url
  792. */
  793. public function get_link($title, $url)
  794. {
  795. return '<a href="'.$url.'" target="about:bank">'.$title.'</a>';
  796. }
  797. /**
  798. * @param int $value
  799. *
  800. * @return string
  801. */
  802. public function format_yes_no_optional($value)
  803. {
  804. $return = '';
  805. switch ($value) {
  806. case 0:
  807. $return = get_lang('No');
  808. break;
  809. case 1:
  810. $return = get_lang('Yes');
  811. break;
  812. case 2:
  813. $return = get_lang('Optional');
  814. break;
  815. }
  816. return $return;
  817. }
  818. /**
  819. * @param $value
  820. *
  821. * @return string
  822. */
  823. public function format_yes_no($value)
  824. {
  825. return $value ? get_lang('Yes') : get_lang('No');
  826. }
  827. /**
  828. * @param int $value
  829. *
  830. * @return string
  831. */
  832. public function format_on_off($value)
  833. {
  834. $value = intval($value);
  835. if ($value > 1) {
  836. // Greater than 1 values are shown "as-is", they may be interpreted as "On" later.
  837. return $value;
  838. }
  839. // These are the values 'On' and 'Off' used in the php-ini file. Translation (get_lang()) is not needed here.
  840. return $value ? 'On' : 'Off';
  841. }
  842. }