diagnoser.lib.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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. echo $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. global $_configuration;
  178. $message2 = '';
  179. if ($access_url_id === 1) {
  180. if (api_is_windows_os()) {
  181. $message2 .= get_lang('SpaceUsedOnSystemCannotBeMeasuredOnWindows');
  182. } else {
  183. $dir = api_get_path(SYS_PATH);
  184. $du = exec('du -sh '.$dir, $err);
  185. list($size, $none) = explode("\t", $du);
  186. $limit = 0;
  187. if (isset($_configuration[$access_url_id])) {
  188. if (isset($_configuration[$access_url_id]['hosting_limit_disk_space'])) {
  189. $limit = $_configuration[$access_url_id]['hosting_limit_disk_space'];
  190. }
  191. }
  192. $message2 .= sprintf(get_lang('TotalSpaceUsedByPortalXLimitIsYMB'), $size, $limit);
  193. }
  194. }
  195. $array[] = $this->build_setting(
  196. self::STATUS_OK,
  197. '[FILES]',
  198. 'hosting_limit_disk_space',
  199. '#',
  200. $size,
  201. 0,
  202. null,
  203. $message2
  204. );
  205. }
  206. return $array;
  207. }
  208. /**
  209. * Functions to get the data for the php diagnostics.
  210. *
  211. * @return array of data
  212. */
  213. public function get_php_data()
  214. {
  215. $array = [];
  216. // General Functions
  217. $version = phpversion();
  218. $status = $version > REQUIRED_PHP_VERSION ? self::STATUS_OK : self::STATUS_ERROR;
  219. $array[] = $this->build_setting(
  220. $status,
  221. '[PHP]',
  222. 'phpversion()',
  223. 'http://www.php.net/manual/en/function.phpversion.php',
  224. phpversion(),
  225. '>= '.REQUIRED_PHP_VERSION,
  226. null,
  227. get_lang('PHPVersionInfo')
  228. );
  229. $setting = ini_get('output_buffering');
  230. $req_setting = 1;
  231. $status = $setting >= $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  232. $array[] = $this->build_setting(
  233. $status,
  234. '[INI]',
  235. 'output_buffering',
  236. 'http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering',
  237. $setting,
  238. $req_setting,
  239. 'on_off',
  240. get_lang('OutputBufferingInfo')
  241. );
  242. $setting = ini_get('file_uploads');
  243. $req_setting = 1;
  244. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  245. $array[] = $this->build_setting(
  246. $status,
  247. '[INI]',
  248. 'file_uploads',
  249. 'http://www.php.net/manual/en/ini.core.php#ini.file-uploads',
  250. $setting,
  251. $req_setting,
  252. 'on_off',
  253. get_lang('FileUploadsInfo')
  254. );
  255. $setting = ini_get('magic_quotes_runtime');
  256. $req_setting = 0;
  257. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  258. $array[] = $this->build_setting(
  259. $status,
  260. '[INI]',
  261. 'magic_quotes_runtime',
  262. 'http://www.php.net/manual/en/ini.core.php#ini.magic-quotes-runtime',
  263. $setting,
  264. $req_setting,
  265. 'on_off',
  266. get_lang('MagicQuotesRuntimeInfo')
  267. );
  268. $setting = ini_get('safe_mode');
  269. $req_setting = 0;
  270. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  271. $array[] = $this->build_setting(
  272. $status,
  273. '[INI]',
  274. 'safe_mode',
  275. 'http://www.php.net/manual/en/ini.core.php#ini.safe-mode',
  276. $setting,
  277. $req_setting,
  278. 'on_off',
  279. get_lang('SafeModeInfo')
  280. );
  281. $setting = ini_get('register_globals');
  282. $req_setting = 0;
  283. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  284. $array[] = $this->build_setting(
  285. $status,
  286. '[INI]',
  287. 'register_globals',
  288. 'http://www.php.net/manual/en/ini.core.php#ini.register-globals',
  289. $setting,
  290. $req_setting,
  291. 'on_off',
  292. get_lang('RegisterGlobalsInfo')
  293. );
  294. $setting = ini_get('short_open_tag');
  295. $req_setting = 0;
  296. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  297. $array[] = $this->build_setting(
  298. $status,
  299. '[INI]',
  300. 'short_open_tag',
  301. 'http://www.php.net/manual/en/ini.core.php#ini.short-open-tag',
  302. $setting,
  303. $req_setting,
  304. 'on_off',
  305. get_lang('ShortOpenTagInfo')
  306. );
  307. $setting = ini_get('magic_quotes_gpc');
  308. $req_setting = 0;
  309. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  310. $array[] = $this->build_setting(
  311. $status,
  312. '[INI]',
  313. 'magic_quotes_gpc',
  314. 'http://www.php.net/manual/en/ini.core.php#ini.magic_quotes_gpc',
  315. $setting,
  316. $req_setting,
  317. 'on_off',
  318. get_lang('MagicQuotesGpcInfo')
  319. );
  320. $setting = ini_get('display_errors');
  321. $req_setting = 0;
  322. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  323. $array[] = $this->build_setting(
  324. $status,
  325. '[INI]',
  326. 'display_errors',
  327. 'http://www.php.net/manual/en/ini.core.php#ini.display_errors',
  328. $setting,
  329. $req_setting,
  330. 'on_off',
  331. get_lang('DisplayErrorsInfo')
  332. );
  333. $setting = ini_get('default_charset');
  334. if ($setting == '') {
  335. $setting = null;
  336. }
  337. $req_setting = 'UTF-8';
  338. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  339. $array[] = $this->build_setting(
  340. $status,
  341. '[INI]',
  342. 'default_charset',
  343. 'http://www.php.net/manual/en/ini.core.php#ini.default-charset',
  344. $setting,
  345. $req_setting,
  346. null,
  347. get_lang('DefaultCharsetInfo')
  348. );
  349. $setting = ini_get('max_execution_time');
  350. $req_setting = '300 ('.get_lang('Minimum').')';
  351. $status = $setting >= 300 ? self::STATUS_OK : self::STATUS_WARNING;
  352. $array[] = $this->build_setting(
  353. $status,
  354. '[INI]',
  355. 'max_execution_time',
  356. 'http://www.php.net/manual/en/ini.core.php#ini.max-execution-time',
  357. $setting,
  358. $req_setting,
  359. null,
  360. get_lang('MaxExecutionTimeInfo')
  361. );
  362. $setting = ini_get('max_input_time');
  363. $req_setting = '300 ('.get_lang('Minimum').')';
  364. $status = $setting >= 300 ? self::STATUS_OK : self::STATUS_WARNING;
  365. $array[] = $this->build_setting(
  366. $status,
  367. '[INI]',
  368. 'max_input_time',
  369. 'http://www.php.net/manual/en/ini.core.php#ini.max-input-time',
  370. $setting,
  371. $req_setting,
  372. null,
  373. get_lang('MaxInputTimeInfo')
  374. );
  375. $setting = ini_get('memory_limit');
  376. $req_setting = '>= '.REQUIRED_MIN_MEMORY_LIMIT.'M';
  377. $status = self::STATUS_ERROR;
  378. if ((float) $setting >= REQUIRED_MIN_MEMORY_LIMIT) {
  379. $status = self::STATUS_OK;
  380. }
  381. $array[] = $this->build_setting(
  382. $status,
  383. '[INI]',
  384. 'memory_limit',
  385. 'http://www.php.net/manual/en/ini.core.php#ini.memory-limit',
  386. $setting,
  387. $req_setting,
  388. null,
  389. get_lang('MemoryLimitInfo')
  390. );
  391. $setting = ini_get('post_max_size');
  392. $req_setting = '>= '.REQUIRED_MIN_POST_MAX_SIZE.'M';
  393. $status = self::STATUS_ERROR;
  394. if ((float) $setting >= REQUIRED_MIN_POST_MAX_SIZE) {
  395. $status = self::STATUS_OK;
  396. }
  397. $array[] = $this->build_setting(
  398. $status,
  399. '[INI]',
  400. 'post_max_size',
  401. 'http://www.php.net/manual/en/ini.core.php#ini.post-max-size',
  402. $setting,
  403. $req_setting,
  404. null,
  405. get_lang('PostMaxSizeInfo')
  406. );
  407. $setting = ini_get('upload_max_filesize');
  408. $req_setting = '>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M';
  409. $status = self::STATUS_ERROR;
  410. if ((float) $setting >= REQUIRED_MIN_UPLOAD_MAX_FILESIZE) {
  411. $status = self::STATUS_OK;
  412. }
  413. $array[] = $this->build_setting(
  414. $status,
  415. '[INI]',
  416. 'upload_max_filesize',
  417. 'http://www.php.net/manual/en/ini.core.php#ini.upload_max_filesize',
  418. $setting,
  419. $req_setting,
  420. null,
  421. get_lang('UploadMaxFilesizeInfo')
  422. );
  423. $setting = ini_get('upload_tmp_dir');
  424. $status = self::STATUS_OK;
  425. $array[] = $this->build_setting(
  426. $status,
  427. '[INI]',
  428. 'upload_tmp_dir',
  429. 'http://www.php.net/manual/en/ini.core.php#ini.upload_tmp_dir',
  430. $setting,
  431. '',
  432. null,
  433. get_lang('UploadTmpDirInfo')
  434. );
  435. $setting = ini_get('variables_order');
  436. $req_setting = 'GPCS';
  437. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_ERROR;
  438. $array[] = $this->build_setting(
  439. $status,
  440. '[INI]',
  441. 'variables_order',
  442. 'http://www.php.net/manual/en/ini.core.php#ini.variables-order',
  443. $setting,
  444. $req_setting,
  445. null,
  446. get_lang('VariablesOrderInfo')
  447. );
  448. $setting = ini_get('session.gc_maxlifetime');
  449. $req_setting = '4320';
  450. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  451. $array[] = $this->build_setting(
  452. $status,
  453. '[SESSION]',
  454. 'session.gc_maxlifetime',
  455. 'http://www.php.net/manual/en/ini.core.php#session.gc-maxlifetime',
  456. $setting,
  457. $req_setting,
  458. null,
  459. get_lang('SessionGCMaxLifetimeInfo')
  460. );
  461. if (api_check_browscap()) {
  462. $setting = true;
  463. } else {
  464. $setting = false;
  465. }
  466. $req_setting = true;
  467. $status = $setting == $req_setting ? self::STATUS_OK : self::STATUS_WARNING;
  468. $array[] = $this->build_setting(
  469. $status,
  470. '[INI]',
  471. 'browscap',
  472. 'http://www.php.net/manual/en/misc.configuration.php#ini.browscap',
  473. $setting,
  474. $req_setting,
  475. 'on_off',
  476. get_lang('BrowscapInfo')
  477. );
  478. // Extensions
  479. $extensions = [
  480. 'gd' => [
  481. 'link' => 'http://www.php.net/gd',
  482. 'expected' => 1,
  483. 'comment' => get_lang('ExtensionMustBeLoaded'),
  484. ],
  485. 'pdo_mysql' => [
  486. 'link' => 'http://php.net/manual/en/ref.pdo-mysql.php',
  487. 'expected' => 1,
  488. 'comment' => get_lang('ExtensionMustBeLoaded'),
  489. ],
  490. 'pcre' => [
  491. 'link' => 'http://www.php.net/pcre',
  492. 'expected' => 1,
  493. 'comment' => get_lang('ExtensionMustBeLoaded'),
  494. ],
  495. 'session' => [
  496. 'link' => 'http://www.php.net/session',
  497. 'expected' => 1,
  498. 'comment' => get_lang('ExtensionMustBeLoaded'),
  499. ],
  500. 'standard' => [
  501. 'link' => 'http://www.php.net/spl',
  502. 'expected' => 1,
  503. 'comment' => get_lang('ExtensionMustBeLoaded'),
  504. ],
  505. 'zlib' => [
  506. 'link' => 'http://www.php.net/zlib',
  507. 'expected' => 1,
  508. 'comment' => get_lang('ExtensionMustBeLoaded'),
  509. ],
  510. 'xsl' => [
  511. 'link' => 'http://be2.php.net/xsl',
  512. 'expected' => 2,
  513. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  514. ],
  515. 'curl' => [
  516. 'link' => 'http://www.php.net/curl',
  517. 'expected' => 2,
  518. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  519. ],
  520. 'Zend OPcache' => [
  521. 'link' => 'http://www.php.net/opcache',
  522. 'expected' => 2,
  523. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  524. ],
  525. 'apcu' => [
  526. 'link' => 'http://www.php.net/apcu',
  527. 'expected' => 2,
  528. 'comment' => get_lang('ExtensionShouldBeLoaded'),
  529. ],
  530. ];
  531. foreach ($extensions as $extension => $data) {
  532. $url = $data['link'];
  533. $expected_value = $data['expected'];
  534. $comment = $data['comment'];
  535. $loaded = extension_loaded($extension);
  536. $status = $loaded ? self::STATUS_OK : self::STATUS_ERROR;
  537. $array[] = $this->build_setting(
  538. $status,
  539. '[EXTENSION]',
  540. get_lang('LoadedExtension').': '.$extension,
  541. $url,
  542. $loaded,
  543. $expected_value,
  544. 'yes_no_optional',
  545. $comment
  546. );
  547. }
  548. return $array;
  549. }
  550. /**
  551. * Functions to get the data for the mysql diagnostics.
  552. *
  553. * @return array of data
  554. */
  555. public function get_database_data()
  556. {
  557. $array = [];
  558. $em = Database::getManager();
  559. $connection = $em->getConnection();
  560. $host = $connection->getHost();
  561. $db = $connection->getDatabase();
  562. $port = $connection->getPort();
  563. $driver = $connection->getDriver()->getName();
  564. $array[] = $this->build_setting(
  565. self::STATUS_INFORMATION,
  566. '[Database]',
  567. 'driver',
  568. '',
  569. $driver,
  570. null,
  571. null,
  572. get_lang('Driver')
  573. );
  574. $array[] = $this->build_setting(
  575. self::STATUS_INFORMATION,
  576. '[Database]',
  577. 'host',
  578. '',
  579. $host,
  580. null,
  581. null,
  582. get_lang('MysqlHostInfo')
  583. );
  584. $array[] = $this->build_setting(
  585. self::STATUS_INFORMATION,
  586. '[Database]',
  587. 'port',
  588. '',
  589. $port,
  590. null,
  591. null,
  592. get_lang('Port')
  593. );
  594. $array[] = $this->build_setting(
  595. self::STATUS_INFORMATION,
  596. '[Database]',
  597. 'Database name',
  598. '',
  599. $db,
  600. null,
  601. null,
  602. get_lang('Name')
  603. );
  604. return $array;
  605. }
  606. /**
  607. * Functions to get the data for the webserver diagnostics.
  608. *
  609. * @return array of data
  610. */
  611. public function get_webserver_data()
  612. {
  613. $array = [];
  614. $array[] = $this->build_setting(
  615. self::STATUS_INFORMATION,
  616. '[SERVER]',
  617. '$_SERVER["SERVER_NAME"]',
  618. 'http://be.php.net/reserved.variables.server',
  619. $_SERVER["SERVER_NAME"],
  620. null,
  621. null,
  622. get_lang('ServerNameInfo')
  623. );
  624. $array[] = $this->build_setting(
  625. self::STATUS_INFORMATION,
  626. '[SERVER]',
  627. '$_SERVER["SERVER_ADDR"]',
  628. 'http://be.php.net/reserved.variables.server',
  629. $_SERVER["SERVER_ADDR"],
  630. null,
  631. null,
  632. get_lang('ServerAddessInfo')
  633. );
  634. $array[] = $this->build_setting(
  635. self::STATUS_INFORMATION,
  636. '[SERVER]',
  637. '$_SERVER["SERVER_PORT"]',
  638. 'http://be.php.net/reserved.variables.server',
  639. $_SERVER["SERVER_PORT"],
  640. null,
  641. null,
  642. get_lang('ServerPortInfo')
  643. );
  644. $array[] = $this->build_setting(
  645. self::STATUS_INFORMATION,
  646. '[SERVER]',
  647. '$_SERVER["SERVER_SOFTWARE"]',
  648. 'http://be.php.net/reserved.variables.server',
  649. $_SERVER["SERVER_SOFTWARE"],
  650. null,
  651. null,
  652. get_lang('ServerSoftwareInfo')
  653. );
  654. $array[] = $this->build_setting(
  655. self::STATUS_INFORMATION,
  656. '[SERVER]',
  657. '$_SERVER["REMOTE_ADDR"]',
  658. 'http://be.php.net/reserved.variables.server',
  659. $_SERVER["REMOTE_ADDR"],
  660. null,
  661. null,
  662. get_lang('ServerRemoteInfo')
  663. );
  664. $array[] = $this->build_setting(
  665. self::STATUS_INFORMATION,
  666. '[SERVER]',
  667. '$_SERVER["HTTP_USER_AGENT"]',
  668. 'http://be.php.net/reserved.variables.server',
  669. $_SERVER["HTTP_USER_AGENT"],
  670. null,
  671. null,
  672. get_lang('ServerUserAgentInfo')
  673. );
  674. $array[] = $this->build_setting(
  675. self::STATUS_INFORMATION,
  676. '[SERVER]',
  677. '$_SERVER["SERVER_PROTOCOL"]',
  678. 'http://be.php.net/reserved.variables.server',
  679. $_SERVER["SERVER_PROTOCOL"],
  680. null,
  681. null,
  682. get_lang('ServerProtocolInfo')
  683. );
  684. $array[] = $this->build_setting(
  685. self::STATUS_INFORMATION,
  686. '[SERVER]',
  687. 'php_uname()',
  688. 'http://be2.php.net/php_uname',
  689. php_uname(),
  690. null,
  691. null,
  692. get_lang('UnameInfo')
  693. );
  694. $array[] = $this->build_setting(
  695. self::STATUS_INFORMATION,
  696. '[SERVER]',
  697. '$_SERVER["HTTP_X_FORWARDED_FOR"]',
  698. 'http://be.php.net/reserved.variables.server',
  699. (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : ''),
  700. null,
  701. null,
  702. get_lang('ServerXForwardedForInfo')
  703. );
  704. return $array;
  705. }
  706. /**
  707. * Additional functions needed for fast integration.
  708. */
  709. public function build_setting(
  710. $status,
  711. $section,
  712. $title,
  713. $url,
  714. $current_value,
  715. $expected_value,
  716. $formatter,
  717. $comment
  718. ) {
  719. switch ($status) {
  720. case self::STATUS_OK:
  721. $img = 'bullet_green.png';
  722. break;
  723. case self::STATUS_WARNING:
  724. $img = 'bullet_orange.png';
  725. break;
  726. case self::STATUS_ERROR:
  727. $img = 'bullet_red.png';
  728. break;
  729. case self::STATUS_INFORMATION:
  730. $img = 'bullet_blue.png';
  731. break;
  732. }
  733. $image = Display::return_icon($img, $status);
  734. $url = $this->get_link($title, $url);
  735. $formatted_current_value = $current_value;
  736. $formatted_expected_value = $expected_value;
  737. if ($formatter) {
  738. if (method_exists($this, 'format_'.$formatter)) {
  739. $formatted_current_value = call_user_func([$this, 'format_'.$formatter], $current_value);
  740. $formatted_expected_value = call_user_func([$this, 'format_'.$formatter], $expected_value);
  741. }
  742. }
  743. return [$image, $section, $url, $formatted_current_value, $formatted_expected_value, $comment];
  744. }
  745. /**
  746. * Create a link with a url and a title.
  747. *
  748. * @param $title
  749. * @param $url
  750. *
  751. * @return string the url
  752. */
  753. public function get_link($title, $url)
  754. {
  755. return '<a href="'.$url.'" target="about:bank">'.$title.'</a>';
  756. }
  757. /**
  758. * @param int $value
  759. *
  760. * @return string
  761. */
  762. public function format_yes_no_optional($value)
  763. {
  764. $return = '';
  765. switch ($value) {
  766. case 0:
  767. $return = get_lang('No');
  768. break;
  769. case 1:
  770. $return = get_lang('Yes');
  771. break;
  772. case 2:
  773. $return = get_lang('Optional');
  774. break;
  775. }
  776. return $return;
  777. }
  778. /**
  779. * @param $value
  780. *
  781. * @return string
  782. */
  783. public function format_yes_no($value)
  784. {
  785. return $value ? get_lang('Yes') : get_lang('No');
  786. }
  787. /**
  788. * @param int $value
  789. *
  790. * @return string
  791. */
  792. public function format_on_off($value)
  793. {
  794. $value = intval($value);
  795. if ($value > 1) {
  796. // Greater than 1 values are shown "as-is", they may be interpreted as "On" later.
  797. return $value;
  798. }
  799. // These are the values 'On' and 'Off' used in the php-ini file. Translation (get_lang()) is not needed here.
  800. return $value ? 'On' : 'Off';
  801. }
  802. }