Source for file checks.php

Documentation is available at checks.php

  1. <?php
  2. /**
  3. * Pre- and post-install checks of the setup
  4. *
  5. @author     Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage Installer
  11. *
  12. @todo   rewrite installer test suite as objects
  13. *          All tests in the test suite should report their outcome in a consistent manner,
  14. *           making it easy for humans or computer programs to understand and to process them.
  15. *           The following test states, defined by EARL (the Evaluation And Report Language),
  16. *           have proved useful:
  17. *           - cannotTell
  18. *           - fail
  19. *           - notApplicable
  20. *           - notTested
  21. *           - pass
  22. */
  23.  
  24. /**
  25. * Check installation to see if required and optional components are installed.
  26. * Also check to see if entered data is valid
  27. */
  28. function check_preinst($data{
  29.   $s array();
  30.   $error $warn false;
  31.   ini_set('track_errors'true);
  32.   // check kit: check that a Bumblebee installation can be found
  33.   $REBASE_INSTALL '..'.DIRECTORY_SEPARATOR;
  34.   set_include_path($REBASE_INSTALL.PATH_SEPARATOR.get_include_path());
  35.   $NON_FATAL_CONFIG true;
  36.   $php_errormsg '';
  37.   if (include 'inc/config.php'{
  38.     $s["GOODFound installation of Bumblebee version $BUMBLEBEEVERSION.";
  39.   else {
  40.     $s["ERRORI couldn't find any evidence of a Bumblebee installation herePHP said:<blockquote>\n$php_errormsg</blockquote>";
  41.     $error true;
  42.   }
  43.   if ($php_errormsg !== ''{
  44.     $s["ERROR: Configuration didn't load properly. "
  45.            ."Bumblebee said:<blockquote>\n$php_errormsg</blockquote>";
  46.     $error true;
  47.   else {
  48.     $s["GOOD: Configuration loaded successfully";
  49.   }
  50.   // check kit: check that php-gettext can be found
  51.   if (include_once 'php-gettext/gettext.inc'{
  52.     $s["WARNING: <a href='https://savannah.nongnu.org/projects/php-gettext/'>php-gettext</a> internationali[sz]ation layer not found. Translations will not be available. "
  53.            ."PHP said:<pre>\n$php_errormsg</pre>";
  54.     $warn true;
  55.     if (function_exists('T_')) {
  56.       function T_($sreturn $s}
  57.     }
  58.   else {
  59.     $s["GOOD: php-gettext found for generating translated content.";
  60.   }
  61.   // check kit: LDAP and RADIUS modules
  62.   if ((include 'Auth/Auth.php'|| (include_once 'PEAR.php')) {
  63.     $s["WARNING: <a href='http://pear.php.net/'>PEAR::Auth</a> modules not found. LDAP and RADIUS authentication unavailable. "
  64.            ."PHP said:<blockquote>\n$php_errormsg</blockquote>";
  65.     $warn true;
  66.   else {
  67.     // check individually for LDAP and RADIUS here? but will that just cause a PHP crash if they are not installed?
  68.     if (extension_loaded('ldap')) {
  69.       //$b = new Auth("LDAP", array(), '', false);
  70.       $s["WARNING: PHP's <a href='http://php.net/ldap'>LDAP extension</a> was not found. LDAP authentication unavailable.";
  71.       $warn true;
  72.     else {
  73.       $s["GOOD: LDAP extension found for LDAP authentication.";
  74.     }
  75.     if (extension_loaded('radius')) {
  76.       //$b = new Auth("RADIUS", array("servers" => array()), "", false);    // hangs if radius module not installed
  77.       $s["WARNING: PHP's <a href='http://pecl.php.net/package/radius'>RADIUS extension</a> was not found. RADIUS authentication unavailable.";
  78.       $warn true;
  79.     else {
  80.       $s["GOOD: PECL RADIUS extension found for RADIUS authentication.";
  81.     }
  82.   }
  83.   // check kit: see if TCPDF is installed
  84.   if ((include 'tcpdf/tcpdf.php')) {
  85.     $s["WARNING: Free PDF library <a href='http://tcpdf.sf.net/'>TCPDF</a> not found. Will not be able to generate PDF reports.";
  86.     $warn true;
  87.   else {
  88.     $s["GOOD: TCPDF library found for generating PDF reports.";
  89.   }
  90.  
  91.   // check username: make sure admin username meets Bumblebee requirements\
  92.   include('inc/passwords.php');
  93.   if (is_valid_username($data['bbAdmin'])) {
  94.     $s["ERROR: The username you have chosen for your Admin user ('".$data['bbAdmin']."') "
  95.           ."will not be able to log into Bumblebee due to restrictions on valid usernames in "
  96.           ."<code>config/bumblebee.ini</code>. Either change the username you have chosen or "
  97.           ."relax the restrictions specficied by <code>[auth].validUserRegexp</code> in that file.";
  98.     $error true;
  99.   else {
  100.     $s["GOOD: Admin username is valid.";
  101.   }
  102.  
  103.   // check password strength of admin password
  104.   list ($strength$messagepasswordStrength($data['bbAdminPass']);
  105.   if ($strength == 2{
  106.     $s["ERRORAdmin user's password is poor$message";
  107.     $error true;
  108.   elseif ($strength == 1{
  109.     $s["WARNINGAdmin user's password is poor$message";
  110.     $warn true;
  111.   else {
  112.     $s["GOODAdmin user's password seems ok$message";
  113.   }
  114.  
  115.   // check password strength of database password
  116.   list ($strength$messagepasswordStrength($data['sqlPass']);
  117.   if ($strength == 2{
  118.     $s["ERRORDatabase user's password is poor$message";
  119.     $error true;
  120.   elseif ($strength == 1{
  121.     $s["WARNINGDatabase user's password is poor$message";
  122.     $warn true;
  123.   else {
  124.     $s["GOODDatabase user's password seems ok$message";
  125.   }
  126.  
  127.   if ($error{
  128.     $s["<b>Errors were detected. Please fix them and reload this page to perform these tests again.</b>";
  129.   }
  130.   if ($warn{
  131.     $s["<b>Warnings were emitted. Please check to see if they are important to your setup and correct them if necessary. Reload this page to perform these tests again.</b>";
  132.   }
  133.   if ($error && $warn{
  134.     $s["<b>Excellent! Your setup looks fine.</b>";
  135.   }
  136.   return "<h2>Results</h2>"
  137.         ."Checking to see if your kit looks good...<br />\n".parseTests($s);
  138. }
  139.  
  140. /**
  141. * Check installation to see if required and optional components are installed.
  142. * post-inst auto-test of db, environment, auth modules etc.
  143. * post-inst test that .ini files are protected by .htaccess
  144. * check that admin can log in ok using auth.php
  145. */
  146. function check_postinst($data{
  147.   $s array();
  148.   $error $warn false;
  149.   ini_set('track_errors'true);
  150.   // check that we can load the config correctly
  151.   $REBASE_INSTALL '..'.DIRECTORY_SEPARATOR;
  152.   $NON_FATAL_CONFIG true;
  153.   $php_errormsg '';
  154.   if ((require_once 'inc/config.php'|| $php_errormsg !== ''{
  155.     $s["ERROR: Configuration didn't load properly. "
  156.            ."Bumblebee said:<blockquote>\n$php_errormsg</blockquote>";
  157.     $error true;
  158.   else {
  159.     $s["GOOD: Configuration loaded successfully";
  160.   }
  161.   // check that we can login to the db
  162.   $NON_FATAL_DB true;
  163.   $DB_CONNECT_DEBUG true;
  164.   $php_errormsg '';
  165.   if ((require_once 'inc/db.php'|| $php_errormsg !== ''{
  166.     $s["ERROR: Unable to connect to database. "
  167.            ."PHP said:<blockquote>\n$php_errormsg</blockquote>";
  168.     $error true;
  169.   else {
  170.     $s["GOOD: Successfully connected to database";
  171.   }
  172.   if ($error{
  173.     // check that the admin user can log into the system
  174.     echo '<!-- checking admin login -->';
  175.     require_once 'inc/bb/auth.php';
  176.     $loginData array();
  177.     $loginData['username'$data['bbAdmin'];
  178.     $loginData['pass']     $data['bbAdminPass'];
  179.     $auth new BumblebeeAuth($loginDatatrue);
  180.     if ($auth->isLoggedIn()) {
  181.       $auth->DEBUG=10;
  182.       $s["ERROR: Admin user cannot log in to Bumblebee with username and password supplied. Bumblebee said:"
  183.             . "<blockquote>".$auth->loginError()."</blockquote>";
  184.       $error true;
  185.     else {
  186.       $s[.= "GOOD: Admin can log in to Bumblebee with this username and password.";
  187.       $auth->logout();  // destroy the session cookie so the user has to log in
  188.     }
  189.   }
  190.  
  191.   // check to see if ini files are accessible to outsiders using HTTP
  192.   echo '<!-- checking access to config files -->';
  193.   require_once 'inc/menu.php';
  194.   $htdbini    makeAbsURL('/config/db.ini');
  195.   $localdbini '..'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'db.ini';
  196.   if (ini_get('allow_url_fopen')) {
  197.     $s["WARNING: The accessibility of your ini files (and passwords!) to outsiders cannot be checked."
  198.           ."You can enable the PHP option <code>allow_url_fopen</code> in the <code>php.ini</code> file and rerun this test,"
  199.           ."or you can see if you are able to download the file yourself through your browser: "
  200.           ."<a href='$htdbinitarget='_blank'>config/db.ini</a>.";
  201.     $warn true;
  202.   else {
  203.     if ($dbinidata file_get_contents($htdbini)) {
  204.       // then something was downloaded
  205.       if ($dbinidata == file_get_contents($localdbini)) {
  206.         $s["ERROR: it appears that your db.ini file can be downloaded from your webserver, exposing your "
  207.               ."database passwords. Try it for yourself: "
  208.               ."<a href='$htdbinitarget='_blank'>config/db.ini</a>. "
  209.               ."You really want to correct that either in your webserver's configuration or in a local .htaccess file.";
  210.         $error true;
  211.       else {
  212.           $s["WARNING: it appears something can be downloaded from your webserver from the config/db.ini file, "
  213.                 ."however, I was unable to verify what it was. Please try it for yourself: "
  214.                 ."<a href='$htdbinitarget='_blank'>config/db.ini</a>. "
  215.                 ."You really want to make sure that the db.ini (and ldap.ini etc) file cannot be accessed as it "
  216.                 ."contains your password information.";
  217.           $warn true;
  218.       }
  219.     elseif (preg_match('/\s403 Forbidden/'$php_errormsg)) {
  220.       $s["GOOD: db.ini file is protected against downloading (gives 403 Forbidden).";
  221.     elseif (preg_match('/\s404 Not Found/'$php_errormsg)) {
  222.       $s["WARNING: db.ini file gave a 404 Not Found error. If you have manually moved the config files "
  223.             ."out of the webserver's file tree then that's fine, but if you haven't done this then your "
  224.             ."setup in <code>bumblebee.ini</codeis specifying an incorrect location for your Bumblebee installation. (I looked in <code>$htdbini</codeand <code>$localdbini</code>.)";
  225.     else {
  226.         $s["WARNING: db.ini file appears to be protected against downloading, "
  227.               ."but I didn't get a 403 Forbidden error. "
  228.               ."Please try it for yourself: "
  229.               ."<a href='$htdbinitarget='_blank'>config/db.ini</a>. "
  230.               ."You really want to make sure that the db.ini (and ldap.ini etc) file cannot be accessed as it "
  231.               ."contains your password information.";
  232.         $warn true;
  233.     }
  234.   }
  235.  
  236.   // check to see if bumblebee.ini has the right place for the installation
  237.   echo '<!-- checking ini file base location -->';
  238.   $htbb[]  makeAbsURL();
  239.   $htbb[]  makeAbsURL('/');
  240.   if (ini_get('allow_url_fopen')) {
  241.     $s["WARNING: I can't test to see that your bumblebee.ini file points to the right URL.."
  242.           ."You can enable the PHP option <code>allow_url_fopen</code> in the <code>php.ini</code> file and rerun this test,"
  243.           ."or you can see if you are able to download the file yourself through your browser: "
  244.           ."<a href='$htbb[0]target='_blank'>check 1</a"
  245.           ."<a href='$htbb[1]target='_blank'>check 2</a>.";
  246.     $warn true;
  247.   else {
  248.     $htbbdata[file_get_contents($htbb[0]);
  249.     $htbbdata[file_get_contents($htbb[1]);
  250.     if ($htbbdata[0|| $htbbdata[1]{
  251.       // then something was downloaded
  252.       // strip the magicTag out of the html as it changes every time
  253.       $htbbdata[0preg_replace('@name="magicTag" value=".+?"@'''$htbbdata[0]);
  254.       $htbbdata[1preg_replace('@name="magicTag" value=".+?"@'''$htbbdata[1]);
  255.       if ($htbbdata[0!= $htbbdata[1]{
  256.         $s["ERRORI got different results when I tried to go to <a href='$htbb[0]target='_blank'>check 1</a"
  257.               ."and <a href='$htbb[1]target='_blank'>check 2</a>.";
  258.               //echo "......".$htbbdata[0]."......".$htbbdata[1]."......";
  259.               #for ($len=0; $len < strlen($htbbdata[0]); $len++) {
  260.               #  if ($htbbdata[0]{$len} != $htbbdata[1]{$len}) {
  261.               #    print "$len ".$htbbdata[0]{$len}.'  '.$htbbdata[1]{$len}."<br/>";
  262.               #  }
  263.               #}
  264.         $error true;
  265.       elseif (preg_match('/Bumblebee/'$htbbdata[0])) {
  266.         $s["WARNINGI was able to find a webpage at your <a href='$htbb[0]target='_blank'>configured location</a>, "
  267.               ."but I couldn't find any evidence that it was a Bumblebee installation.";
  268.         $warn true;
  269.       else {
  270.         $s["GOODI could find your installation through your web server (found at {$htbb[0]} and {$htbb[1]}).";
  271.       }
  272.     else {
  273.       $s["ERRORI couldn't find a web page at your  <a href='$htbb[0]target='_blank'>configured location</a>.";
  274.       $error true;
  275.     }
  276.   }
  277.  
  278.   if ($error{
  279.     $s["<b>Errors were detected. Please fix them and reload this page.</b>";
  280.   }
  281.   if ($warn{
  282.     $s["<b>Warnings were emitted. Please check to see if they are important to your setup and correct them if necessary.</b>";
  283.   }
  284.   if ($error && $warn{
  285.     $s["<b>Excellent! Your setup looks fine.</b>";
  286.   }
  287.   return "<h2>Post-install check results</h2>"
  288.         ."Checking your setup works now you've installed the db.ini file and created the database...<br />\n"
  289.         .parseTests($s);
  290. }
  291.  
  292.  
  293. /**
  294. * Parse the test results and do some pretty printing of them
  295. @param array $results 
  296. @return string pretty printed results
  297. */
  298. function parseTests($r{
  299.   $replace array(
  300.               '/^GOOD:/'    => '<span class="good">GOOD:</span>',
  301.               '/^WARNING:/' => '<span class="warn">WARNING:</span>',
  302.               '/^ERROR:/'   => '<span class="error">ERROR:</span>'
  303.              );
  304.   $s preg_replace(array_keys($replace)array_values($replace)$r);
  305.   return join($s"<br />\n");
  306. }
  307.  
  308.  
  309. /**
  310. * Check the strength of the password
  311. @param string $password 
  312. @return array list(integer (0=ok, 1=warn, 2=err), string description)
  313. */
  314. function passwordStrength($password{
  315.   $advice "Use at least 8 characters and include numbers, upper and lower case letters and some punctuation.";
  316.   if (preg_match("/^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$/"$password)) {
  317.     // password at least 8 chars and contains uppercase, lowercase, digits and punctuation
  318.     return array(0"password seems strong enough");
  319.   }
  320.   if (preg_match("/^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$/"$password)) {
  321.     // password at least 7 chars and contains two out of uppercase, lowercase, digits and punctuation
  322.     return array(1"This password is relatively weak$advice");
  323.   }
  324.   if (strlen($password8{
  325.     // password doesn't have lots of letters and numbers but at least it has 8 characters...
  326.     return array(1"This password is quite weak$advice");
  327.   }
  328.   // password is exceedingly poor
  329.   return array(1"This password is very weak$advice");
  330. }
  331.  
  332. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:04 +0000 by phpDocumentor 1.3.0