Esempio n. 1
0
 private function loadSettingsFromFile($dbSettingsFile)
 {
     // Check that databaseSettingsFile is valid
     if (!is_readable($dbSettingsFile)) {
         ErrorHandling::fatalNoDatabaseError(T_("DB Config File isn't a valid file.") . "({$dbSettingsFile})");
     }
     $settings = file($dbSettingsFile);
     foreach ($settings as $setting) {
         list($key, $value) = explode(":", $setting);
         $value = trim($value);
         switch ($key) {
             case 'sql_username':
                 $this->user = $value;
                 break;
             case 'sql_password':
                 $this->pass = $value;
                 break;
             case 'sql_server':
                 $this->host = $value;
                 break;
             case 'sql_database':
             case 'sql_radmindatabase':
                 $this->db = $value;
                 break;
         }
     }
 }
 private function __construct($db, $Auth)
 {
     $this->db =& $db;
     $this->Auth =& $Auth;
     $this->ip = $this->ipCheck();
     if (!$this->checkTablesExist()) {
         $this->createTables();
     }
     // TODO: Make timestamp auto update in sql
     // Share SQL Query between functions
     $this->log_sql = $this->db->prepare('INSERT INTO adminlog
     	(`timestamp`, username, ipaddress, action)
     	VALUES (?, ?, ?, ?)', array('timestamp', 'text', 'text', 'text'), MDB2_PREPARE_MANIP);
     //var_dump($this->db);
     //var_dump($this->log_sql);
     if (PEAR::isError($this->log_sql)) {
         \Grase\ErrorHandling::fatalNoDatabaseError("Preparing logging statement failed: " . $this->log_sql->getMessage());
     }
 }
 private function connectDatabase()
 {
     $this->radminDatabaseSettings = $this->loadSettingsFromFile($this->radminDatabaseSettingsFile);
     $this->radiusDatabaseSettings = $this->loadSettingsFromFile($this->radiusDatabaseSettingsFile);
     // Set options and DSN
     $db_settings = $this->radiusDatabaseSettings;
     $this->radiusDSN = array("phptype" => "mysql", "username" => $db_settings['sql_username'], "password" => $db_settings['sql_password'], "hostspec" => $db_settings['sql_server'], "database" => $db_settings['sql_database'], "new_link" => true);
     $this->radiusOptions = array('portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE, 'emulate_prepared' => true);
     $db_settings = $this->radminDatabaseSettings;
     $this->radminDSN = array("phptype" => "mysql", "username" => $db_settings['sql_username'], "password" => $db_settings['sql_password'], "hostspec" => $db_settings['sql_server'], "database" => $db_settings['sql_radmindatabase'], 'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE, "new_link" => true);
     $this->radminOptions = array('portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE, 'emulate_prepared' => true);
     // Connect
     $this->radiusDB =& MDB2::connect($this->radiusDSN, $this->radiusOptions);
     if (PEAR::isError($this->radiusDB)) {
         //TODO Send more of error handler to error handling (i.e. userinfo in database errors, for debugging (stderr?))
         \Grase\ErrorHandling::fatalNoDatabaseError($this->radiusDB->getMessage() . " RADIUS<br/>The RADIUS database does not exist");
     }
     // Set mode for Radius DB
     $this->radiusDB->setFetchMode(MDB2_FETCHMODE_ASSOC);
     $this->radminDB =& MDB2::connect($this->radminDSN, $this->radminOptions);
     if (PEAR::isError($this->radminDB)) {
         // Attempt to create the radminDB? TODO: Make nicer?
         $this->radiusDB->loadModule('Manager');
         $this->radiusDB->createDatabase($db_settings['sql_radmindatabase']);
         $this->radminDB =& MDB2::connect($this->radminDSN, $this->radminOptions);
         if (PEAR::isError($this->radminDB)) {
             \Grase\ErrorHandling::fatalNoDatabaseError($this->radminDB->getMessage() . " RADMIN");
         }
     }
     // Set mode for Radmin DB
     $this->radminDB->setFetchMode(MDB2_FETCHMODE_ASSOC);
     // Enable DEBUG with GET request (see Explain_Queries below)
     // DEBUG is disabled in production environments, this should never be uncommented in a package we are building. TODO CHECK!
     //if(isset($_GET['debug'])) $this->debugDB();
 }