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;
         }
     }
 }
 public function latestMacFromIP($ipaddress)
 {
     // We limit the selection to a machine that has connected in the last
     // hour, (this may need to be updated in the future with
     // CallingStationId for multiple APs)
     $sql = sprintf("SELECT username from radpostauth\n                        WHERE FramedIPAddress=%s\n                        AND username LIKE '__-__-__-__-__-__'\n                        AND authdate > TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 HOUR))\n\n                        ORDER BY ID DESC\n                        LIMIT 1", $this->db->quote($ipaddress));
     $mac = $this->db->queryOne($sql);
     if (PEAR::isError($mac)) {
         \Grase\ErrorHandling::fatalDatabaseError(T_('Retrieving MAC from IP failed: '), $mac);
     }
     // Check its a MAC address??
     return $mac;
 }
Esempio n. 3
0
 public function deleteVoucher($vouchername)
 {
     $delete = $this->radmin->prepare("DELETE FROM vouchers WHERE VoucherName=?");
     $result = $delete->execute(array($vouchername));
     if ($result === false) {
         ErrorHandling::fatalDatabaseError(T_('Delete Voucher query failed:  '), $result);
     }
     \AdminLog::getInstance()->log("Voucher {$vouchername} deleted");
     return $result;
 }
 public function log_cron($action)
 {
     $affected =& $this->log_sql->execute(array(date('Y-m-d H:i:s'), 'CRON', $this->ip, $action));
     // Always check that result is not an error
     if (PEAR::isError($affected)) {
         \Grase\ErrorHandling::fatalError('Creating CRON Log Entry failed: ' . $affected->getMessage());
     }
     return $affected;
 }
 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();
 }