establishDBConnection() static public method

Establish a connection to a mysql server (main or replicate)
static public establishDBConnection ( $use_slave, $required, $display = true )
$use_slave try to connect to slave server first not to main server
$required connection to the specified server is required (if connection failed, do not try to connect to the other server)
$display display error message (true by default)
    echo "GLPI_DB_OK\n";
} else {
    echo "GLPI_DB_PROBLEM\n";
    $ok_master = false;
}
// Slave and master ok;
$ok = $ok_slave && $ok_master;
// Check session dir (usefull when NFS mounted))
if (is_dir(GLPI_SESSION_DIR) && is_writable(GLPI_SESSION_DIR)) {
    echo "GLPI_SESSION_DIR_OK\n";
} else {
    echo "GLPI_SESSION_DIR_PROBLEM\n";
    $ok = false;
}
// Reestablished DB connection
if (($ok_master || $ok_slave) && DBConnection::establishDBConnection(false, false, false)) {
    // Check LDAP Auth connections
    $ldap_methods = getAllDatasFromTable('glpi_authldaps', '`is_active`=1');
    if (count($ldap_methods)) {
        echo "Check LDAP servers:";
        foreach ($ldap_methods as $method) {
            echo " " . $method['name'];
            if (AuthLDAP::tryToConnectToServer($method, $method["rootdn"], Toolbox::decrypt($method["rootdn_passwd"], GLPIKEY))) {
                echo "_OK";
            } else {
                echo "_PROBLEM";
                $ok = false;
            }
            echo "\n";
        }
    } else {
 /**
  * This method return GLPI status (same as status.php)
  *
  * @param $params    array of option : ignored
  * @param $protocol        the communication protocol used
  *
  * @return an response ready to be encode
  **/
 static function methodStatus($params, $protocol)
 {
     global $DB;
     if (isset($params['help'])) {
         return array('help' => 'bool,optional');
     }
     $resp = array();
     $ok_master = true;
     $ok_slave = true;
     $ok = true;
     // Check slave server connection
     if (DBConnection::isDBSlaveActive()) {
         $DBslave = DBConnection::getDBSlaveConf();
         if (is_array($DBslave->dbhost)) {
             $hosts = $DBslave->dbhost;
         } else {
             $hosts = array($DBslave->dbhost);
         }
         foreach ($hosts as $num => $name) {
             $diff = DBConnection::getReplicateDelay($num);
             if ($diff > 1000000000) {
                 $resp['slavedb_' . $num] = "offline";
                 $ok_slave = false;
             } else {
                 if ($diff) {
                     $resp['slavedb_' . $num] = $diff;
                     if ($diff > HOUR_TIMESTAMP) {
                         $ok_slave = false;
                     }
                 } else {
                     $resp['slavedb_' . $num] = "ok";
                 }
             }
         }
     } else {
         $resp['slavedb'] = "not configured";
     }
     // Check main server connection
     if (DBConnection::establishDBConnection(false, true, false)) {
         $resp['maindb'] = "ok";
     } else {
         $resp['slavedb'] = "offline";
         $ok_master = false;
     }
     // Slave and master ok;
     $ok = $ok_slave && $ok_master;
     // Check session dir (usefull when NFS mounted))
     if (is_dir(GLPI_SESSION_DIR) && is_writable(GLPI_SESSION_DIR)) {
         $resp['sessiondir'] = "ok";
     } else {
         $resp['sessiondir'] = "not writable";
         $ok = false;
     }
     // Reestablished DB connection
     if (($ok_master || $ok_slave) && DBConnection::establishDBConnection(false, false, false)) {
         // Check Auth connections
         $auth = new Auth();
         $auth->getAuthMethods();
         $ldap_methods = $auth->authtypes["ldap"];
         if (count($ldap_methods)) {
             foreach ($ldap_methods as $method) {
                 if ($method['is_active']) {
                     if (AuthLdap::tryToConnectToServer($method, $method["rootdn"], Toolbox::decrypt($method["rootdn_passwd"], GLPIKEY))) {
                         $resp['LDAP_' . $method['name']] = "ok";
                     } else {
                         $resp['LDAP_' . $method['name']] = "offline";
                         $ok = false;
                     }
                 }
             }
         }
     }
     if ($ok) {
         $resp['glpi'] = "ok";
     } else {
         $resp['glpi'] = "error";
     }
     return $resp;
 }
示例#3
0
        echo "<p>Error: GLPI seems to not be configured properly.</p>";
        echo "<p>config_db.php file is missing.</p>";
        echo "<p>Please restart the install process.</p>";
        echo "<p><a class='red' href='" . $CFG_GLPI['root_doc'] . "'>Click here to proceed</a></p>";
        echo "</div>";
        Html::nullFooter();
    } else {
        echo "Error: GLPI seems to not be configured properly.\n";
        echo "config_db.php file is missing.\n";
        echo "Please connect to GLPI web interface to complete the install process.\n";
    }
    die;
} else {
    require_once GLPI_CONFIG_DIR . "/config_db.php";
    //Database connection
    DBConnection::establishDBConnection(isset($USEDBREPLICATE) ? $USEDBREPLICATE : 0, isset($DBCONNECTION_REQUIRED) ? $DBCONNECTION_REQUIRED : 0);
    // *************************** Statics config options **********************
    // ********************options d'installation statiques*********************
    // *************************************************************************
    //Options from DB, do not touch this part.
    // Default Use mode
    if (!isset($_SESSION['glpi_use_mode'])) {
        $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
    }
    $config_object = new Config();
    $current_config = array();
    if (!isset($_GET['donotcheckversion']) && (isset($TRY_OLD_CONFIG_FIRST) || isset($_SESSION['TRY_OLD_CONFIG_FIRST']) && $_SESSION['TRY_OLD_CONFIG_FIRST'])) {
        // backup case
        if (isset($_SESSION['TRY_OLD_CONFIG_FIRST'])) {
            unset($_SESSION['TRY_OLD_CONFIG_FIRST']);
        }
示例#4
0
文件: status.php 项目: korial29/glpi
}

// Slave and master ok;
$ok = $ok_slave && $ok_master;

// Check session dir (useful when NFS mounted))
if (is_dir(GLPI_SESSION_DIR) && is_writable(GLPI_SESSION_DIR)) {
   echo "GLPI_SESSION_DIR_OK\n";
} else {
   echo "GLPI_SESSION_DIR_PROBLEM\n";
   $ok = false;
}

// Reestablished DB connection
if (($ok_master || $ok_slave )
    && DBConnection::establishDBConnection(false, false, false)) {

   // Check LDAP Auth connections
   $ldap_methods = getAllDatasFromTable('glpi_authldaps', '`is_active`=1');

   if (count($ldap_methods)) {
      echo "Check LDAP servers:";

      foreach ($ldap_methods as $method) {
         echo " ".$method['name'];
         if (AuthLDAP::tryToConnectToServer($method, $method["rootdn"],
                                            Toolbox::decrypt($method["rootdn_passwd"],
                                            GLPIKEY))) {
            echo "_OK";
         } else {
            echo "_PROBLEM";