/**
  * Common Checks needed to use GLPI
  *
  * @return 2 : creation error 1 : delete error 0: OK
  **/
 static function commonCheckForUseGLPI()
 {
     global $CFG_GLPI;
     $error = 0;
     // Title
     echo "<tr><th>" . __('Test done') . "</th><th >" . __('Results') . "</th></tr>";
     // Parser test
     echo "<tr class='tab_bg_1'><td class='b left'>" . __('Testing PHP Parser') . "</td>";
     // PHP Version  - exclude PHP3, PHP 4 and zend.ze1 compatibility
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         // PHP > 5.3 ok, now check PHP zend.ze1_compatibility_mode
         if (ini_get("zend.ze1_compatibility_mode") == 1) {
             $error = 2;
             echo "<td class='red'>\n                  <img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('GLPI is not compatible with the option zend.ze1_compatibility_mode = On.') . "</td>";
         } else {
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('PHP version is at least 5.3.0 - Perfect!') . "\"\n                       title=\"" . __s('PHP version is at least 5.3.0 - Perfect!') . "\"></td>";
         }
     } else {
         // PHP <5
         $error = 2;
         echo "<td class='red'>\n               <img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('You must install at least PHP 5.3.0.') . "</td>";
     }
     echo "</tr>";
     // Check for mysql extension ni php
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('MySQL Improved extension test') . "</td>";
     if (class_exists("mysqli")) {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png'\n                    alt=\"" . __s('Ok - the MySQLi class exist - Perfect!') . "\"\n                    title=\"" . __s('Ok - the MySQLi class exist - Perfect!') . "\"></td>";
     } else {
         echo "<td class='red'>";
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('You must install the MySQL Improved extension for PHP.') . "</td>";
         $error = 2;
     }
     echo "</tr>";
     // session test
     echo "<tr class='tab_bg_1'><td class='b left'>" . __('Sessions test') . "</td>";
     // check whether session are enabled at all!!
     if (!extension_loaded('session')) {
         $error = 2;
         echo "<td class='red b'>" . __('Your parser PHP is not installed with sessions support!') . "</td>";
     } else {
         if (isset($_SESSION["Test_session_GLPI"]) && $_SESSION["Test_session_GLPI"] == 1 || isset($_SESSION["glpi_currenttime"])) {
             // From Update
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('Sessions support is available - Perfect!') . "\" title=\"" . __s('Sessions support is available - Perfect!') . "\"></td>";
         } else {
             if ($error != 2) {
                 echo "<td class='red'>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/orangebutton.png'>" . __('Make sure that sessions support has been activated in your php.ini') . "</td>";
                 $error = 1;
             }
         }
     }
     echo "</tr>";
     // Test for session auto_start
     if (ini_get('session.auto_start') == 1) {
         echo "<tr class='tab_bg_1'><td class='b'>" . __('Test session auto start') . "</td>";
         echo "<td class='red'>";
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('session.auto_start is activated. See .htaccess file in the GLPI root for more information.') . "</td></tr>";
         $error = 2;
     }
     // Test for option session use trans_id loaded or not.
     echo "<tr class='tab_bg_1'>";
     echo "<td class='left b'>" . __('Test if Session_use_trans_sid is used') . "</td>";
     if (isset($_POST[session_name()]) || isset($_GET[session_name()])) {
         echo "<td class='red'>";
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('You must desactivate the Session_use_trans_id option in your php.ini') . "</td>";
         $error = 2;
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('Ok - the sessions works (no problem with trans_id) - Perfect!') . "\" title=\"" . __s('Ok - the sessions works (no problem with trans_id) - Perfect!') . "\"></td>";
     }
     echo "</tr>";
     // Test for sybase extension loaded or not.
     echo "<tr class='tab_bg_1'>";
     echo "<td class='left b'>" . __('magic_quotes_sybase extension test') . "</td>";
     if (ini_get('magic_quotes_sybase')) {
         echo "<td class='red'>";
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('GLPI does not work with the magic_quotes_sybase option. Please turn it off and retry') . "</td>";
         $error = 2;
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s("The magic_quotes_sybase option isn't active on your server - Perfect!") . "\" title=\"" . __s("The magic_quotes_sybase option isn't active on your server - Perfect!") . "\"></td>";
     }
     echo "</tr>";
     // Test for ctype extension loaded or not (forhtmlawed)
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('Test ctype functions') . "</td>";
     if (!function_exists('ctype_digit')) {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __("GLPI can't work correctly without the ctype functions") . "></td>";
         $error = 2;
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('The functionality is found - Perfect!') . "\" title=\"" . __s('The functionality is found - Perfect!') . "\"></td>";
     }
     echo "</tr>";
     // Test for json_encode function.
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('Test json functions') . "</td>";
     if (!function_exists('json_encode') || !function_exists('json_decode')) {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __("GLPI can't work correctly without the json_encode and json_decode functions") . "></td>";
         $error = 2;
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('The functionality is found - Perfect!') . "\" title=\"" . __s('The functionality is found - Perfect!') . "\"></td>";
     }
     echo "</tr>";
     // Test for mbstring extension.
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('Mbstring extension test') . "</td>";
     if (!extension_loaded('mbstring')) {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('Mbstring extension of your parser PHP is not installed') . "></td>";
         $error = 2;
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('The functionality is found - Perfect!') . "\" title=\"" . __s('The functionality is found - Perfect!') . "\"></td>";
     }
     echo "</tr>";
     // Test for GD extension.
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('GD extension test') . "</td>";
     if (!extension_loaded('gd')) {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . __('GD extension of your parser PHP is not installed') . "></td>";
         $error = 2;
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('The functionality is found - Perfect!') . "\" title=\"" . __s('The functionality is found - Perfect!') . "\"></td>";
     }
     echo "</tr>";
     // Test for Cryptographic extension.
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('Cryptography test') . "</td>";
     if (Auth::isCryptOk()) {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('The functionality is found - Perfect!') . "\" title=\"" . __s('The functionality is found - Perfect!') . "\"></td>";
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/orangebutton.png' alt=\"" . __s('PHP >= 5.3.7 recommended, with crypt extension') . "\" title=\"" . __s('PHP >= 5.3.7 recommended, with crypt extension') . "\"></td>";
         $error = 1;
     }
     echo "</tr>";
     // memory test
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('Allocated memory test') . "</td>";
     //Get memory limit
     $mem = self::getMemoryLimit();
     switch (self::checkMemoryLimit()) {
         case 0:
             // memory_limit not compiled -> no memory limit
         // memory_limit not compiled -> no memory limit
         case 1:
             // memory_limit compiled and unlimited
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('Unlimited memory - Perfect!') . "\" title=\"" . __s('Unlimited memory - Perfect!') . "\"></td>";
             break;
         case 2:
             //Insufficient memory
             $showmem = $mem / 1048576;
             echo "<td class='red'><img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>" . "<span class='b'>" . sprintf(__('%1$s: %2$s'), __('Allocated memory'), sprintf(__('%1$s %2$s'), $showmem, __('Mio'))) . "</span>" . "<br>" . __('A minimum of 64Mio is commonly required for GLPI.') . "<br>" . __('Try increasing the memory_limit parameter in the php.ini file.') . "</td>";
             $error = 2;
             break;
         case 3:
             //Got enough memory, going to the next step
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/greenbutton.png' alt=\"" . __s('Allocated memory > 64Mio - Perfect!') . "\" title=\"" . __s('Allocated memory > 64Mio - Perfect!') . "\"></td>";
             break;
     }
     echo "</tr>";
     $suberr = Config::checkWriteAccessToDirs();
     if ($suberr > $error) {
         $error = $suberr;
     }
     $suberr = self::checkSELinux();
     if ($suberr > $error) {
         $error = $suberr;
     }
     return $error;
 }
Example #2
0
 /**
  * Common Checks needed to use GLPI
  *
  * @return 2 : creation error 1 : delete error 0: OK
  **/
 static function commonCheckForUseGLPI()
 {
     global $CFG_GLPI;
     $error = 0;
     // Title
     echo "<tr><th>" . __('Test done') . "</th><th >" . __('Results') . "</th></tr>";
     // Parser test
     echo "<tr class='tab_bg_1'><td class='b left'>" . __('Testing PHP Parser') . "</td>";
     // PHP Version  - exclude PHP3, PHP 4 and zend.ze1 compatibility
     if (version_compare(PHP_VERSION, GLPI_MIN_PHP) >= 0) {
         // PHP version ok, now check PHP zend.ze1_compatibility_mode
         if (ini_get("zend.ze1_compatibility_mode") == 1) {
             $error = 2;
             echo "<td class='red'>\n                  <img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . __('GLPI is not compatible with the option zend.ze1_compatibility_mode = On.') . "</td>";
         } else {
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . sprintf(__s('PHP version is at least %s - Perfect!'), GLPI_MIN_PHP) . "\"\n                       title=\"" . sprintf(__s('PHP version is at least %s - Perfect!'), GLPI_MIN_PHP) . "\"></td>";
         }
     } else {
         // PHP <5
         $error = 2;
         echo "<td class='red'>\n               <img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . sprintf(__('You must install at least PHP %s.'), GLPI_MIN_PHP) . "</td>";
     }
     echo "</tr>";
     // session test
     echo "<tr class='tab_bg_1'><td class='b left'>" . __('Sessions test') . "</td>";
     // check whether session are enabled at all!!
     if (!extension_loaded('session')) {
         $error = 2;
         echo "<td class='red b'>" . __('Your parser PHP is not installed with sessions support!') . "</td>";
     } else {
         if (isset($_SESSION["Test_session_GLPI"]) && $_SESSION["Test_session_GLPI"] == 1 || isset($_SESSION["glpi_currenttime"])) {
             // From Update
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Sessions support is available - Perfect!') . "\" title=\"" . __s('Sessions support is available - Perfect!') . "\"></td>";
         } else {
             if ($error != 2) {
                 echo "<td class='red'>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/warning_min.png'>" . __('Make sure that sessions support has been activated in your php.ini') . "</td>";
                 $error = 1;
             }
         }
     }
     echo "</tr>";
     // Test for session auto_start
     if (ini_get('session.auto_start') == 1) {
         echo "<tr class='tab_bg_1'><td class='b'>" . __('Test session auto start') . "</td>";
         echo "<td class='red'>";
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . __('session.auto_start is activated. See .htaccess file in the GLPI root for more information.') . "</td></tr>";
         $error = 2;
     }
     // Test for option session use trans_id loaded or not.
     echo "<tr class='tab_bg_1'>";
     echo "<td class='left b'>" . __('Test if Session_use_trans_sid is used') . "</td>";
     if (isset($_POST[session_name()]) || isset($_GET[session_name()])) {
         echo "<td class='red'>";
         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . __('You must desactivate the Session_use_trans_id option in your php.ini') . "</td>";
         $error = 2;
     } else {
         echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Ok - the sessions works (no problem with trans_id) - Perfect!') . "\" title=\"" . __s('Ok - the sessions works (no problem with trans_id) - Perfect!') . "\"></td>";
     }
     echo "</tr>";
     $extensions_to_check = ['mysqli' => ['required' => true], 'ctype' => ['required' => true, 'function' => 'ctype_digit'], 'fileinfo' => ['required' => true, 'class' => 'finfo'], 'json' => ['required' => true, 'function' => 'json_encode'], 'mbstring' => ['required' => true], 'zlib' => ['required' => true], 'curl' => ['required' => true], 'gd' => ['required' => false], 'ldap' => ['required' => false], 'imap' => ['required' => false]];
     //check for PHP extensions
     foreach ($extensions_to_check as $ext => $params) {
         $success = true;
         if (isset($params['function'])) {
             if (!function_exists($params['function'])) {
                 $success = false;
             }
         } else {
             if (isset($param['class'])) {
                 if (!class_exists($params['class'])) {
                     $success = false;
                 }
             } else {
                 if (!extension_loaded($ext)) {
                     $success = false;
                 }
             }
         }
         echo "<tr class=\"tab_bg_1\"><td class=\"left b\">" . sprintf(__('%s extension test'), $ext) . "</td>";
         if ($success) {
             $msg = sprintf(__('%s extension is installed'), $ext);
             echo "<td><img src=\"{$CFG_GLPI['root_doc']}/pics/ok_min.png\"\n                    alt=\"{$msg}\"\n                    title=\"{$msg}\"></td>";
         } else {
             if (isset($params['required']) && $params['required'] === true) {
                 if ($error < 2) {
                     $error = 2;
                 }
                 echo "<td class=\"red\"><img src=\"{$CFG_GLPI['root_doc']}/pics/ko_min.png\"> " . sprintf(__('%s extension is missing'), $ext) . "</td>";
             } else {
                 if ($error < 1) {
                     $error = 1;
                 }
                 echo "<td><img src=\"{$CFG_GLPI['root_doc']}/pics/warning_min.png\"> " . sprintf(__('%s extension is not present'), $ext) . "</td>";
             }
         }
         echo "</tr>";
     }
     // memory test
     echo "<tr class='tab_bg_1'><td class='left b'>" . __('Allocated memory test') . "</td>";
     //Get memory limit
     $mem = self::getMemoryLimit();
     switch (self::checkMemoryLimit()) {
         case 0:
             // memory_limit not compiled -> no memory limit
         // memory_limit not compiled -> no memory limit
         case 1:
             // memory_limit compiled and unlimited
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Unlimited memory - Perfect!') . "\" title=\"" . __s('Unlimited memory - Perfect!') . "\"></td>";
             break;
         case 2:
             //Insufficient memory
             $showmem = $mem / 1048576;
             echo "<td class='red'><img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . "<span class='b'>" . sprintf(__('%1$s: %2$s'), __('Allocated memory'), sprintf(__('%1$s %2$s'), $showmem, __('Mio'))) . "</span>" . "<br>" . __('A minimum of 64Mio is commonly required for GLPI.') . "<br>" . __('Try increasing the memory_limit parameter in the php.ini file.') . "</td>";
             $error = 2;
             break;
         case 3:
             //Got enough memory, going to the next step
             echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Allocated memory > 64Mio - Perfect!') . "\" title=\"" . __s('Allocated memory > 64Mio - Perfect!') . "\"></td>";
             break;
     }
     echo "</tr>";
     $suberr = Config::checkWriteAccessToDirs();
     if ($suberr > $error) {
         $error = $suberr;
     }
     $suberr = self::checkSELinux();
     if ($suberr > $error) {
         $error = $suberr;
     }
     return $error;
 }