function auth($user, $pass, $args)
 {
     $r = $db_pw = false;
     $dsn = access_query("authanydb", 0);
     $col_login = access_query("authanydblogincolumn", 0) or $col_login = "******";
     $col_pass = access_query("authanydbpasswordcolumn", 0) or $col_pass = "******";
     $desc = parse_url($dsn);
     $desc["database"] = strtok($desc["path"], "/");
     $table = strtok("/");
     $dsn = substr($dsn, 0, strrpos($dsn, "/"));
     if (function_exists("newadoconnection") && ($db = NewAdoConnection($desc["scheme"])) && $db->connect($desc["host"], $desc["user"], $desc["pass"], $desc["database"])) {
         $user = $db->qstr($user);
         $SQL = "SELECT {$col_pass} FROM {$table} WHERE {$col_login}={$user}";
         if ($row = $db->GetRow($SQL)) {
             $db_pw = $row[0];
         }
         $db->Close();
     } elseif (class_exists("DB")) {
         $db = DB::connect($dsn);
         $user = $db->quoteString($user);
         $SQL = "SELECT {$col_pass} FROM {$table} WHERE {$col_login}='{$user}'";
         if ($row = $db->getRow($SQL)) {
             $db_pw = $row[0];
         }
     } elseif (function_exists("dbx_connect") && ($db = dbx_connect($desc["scheme"], $desc["host"], $desc["database"], $desc["user"], $desc["pass"]))) {
         $user = dbx_escape_string($db, $user);
         $SQL = "SELECT {$col_pass} FROM {$table} WHERE {$col_login}='{$user}'";
         if ($result = dbx_query($db, $SQL)) {
             $db_pw = $result->data[0][0];
         }
         dbx_close($db);
     } else {
         techo("mod_auth_anydb: no database interface used (db auth problem?)", NW_EL_WARNING);
         return $r = false;
     }
     $r = strlen($db_pw) && strlen($pass) && ($db_pw == $pass or $db_pw == crypt($pass, substr($db_pw, 0, 2)) or $db_pw == md5($pass));
     return $r;
 }
Exemplo n.º 2
0
 function garbageCollection($maxlifetime)
 {
     $this->flushPreload();
     $query = sprintf('DELETE FROM %s WHERE (expires <= %d AND expires > 0) OR changed <= (NOW() - %d)', $this->cache_table, time(), $maxlifetime);
     $res = dbx_query($this->db, $query);
     if (dbx_error($this->db)) {
         return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__);
     }
     $query = sprintf('select sum(length(cachedata)) as CacheSize from %s', $this->cache_table);
     $res = dbx_query($this->db, $query);
     //if cache is to big.
     if ($res->data[0][CacheSize] > $this->highwater) {
         //find the lowwater mark.
         $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table);
         $res = dbx_query($this->db, $query);
         $keep_size = 0;
         $i = 0;
         while ($keep_size < $this->lowwater && $i < $res->rows) {
             $keep_size += $res->data[$i][size];
             $i++;
         }
         //delete all entries, which were changed before the "lowwwater mark"
         $query = sprintf('delete from %s where changed <= %s', $this->cache_table, $res->data[$i][changed]);
         $res = dbx_query($this->db, $query);
     }
 }
Exemplo n.º 3
0
 /**
  * Read string data from database
  */
 function read($table, $fields, $where = '')
 {
     if (count($fields) > 0) {
         // Query table for data
         $query = 'SELECT `' . dbx_escape_string($this->handle, implode('`,`', $fields)) . '` FROM `' . dbx_escape_string($this->handle, $table) . '`;';
         if (isset($where) && !empty($where) && $where != '') {
             // Fetch only some
             $query = 'SELECT `' . dbx_escape_string($this->handle, implode('`,`', $fields)) . '` FROM `' . dbx_escape_string($this->handle, $table) . '` WHERE ' . dbx_escape_string($this->handle, $where) . ';';
         }
         echo "[QUERY]: {$query}\n";
         $result = dbx_query($this->handle, $query);
         if (!is_object($result)) {
             die("Error performing READ query.<br />\nError returned: " . dbx_error($this->handle) . "\n");
         }
     } else {
         die("Please select at least one field to read!\n");
     }
     return $result;
 }
function da_sql_list_fields($table, $link, $config)
{
    $res = @dbx_query($link, "SELECT * FROM " . $table . " LIMIT 1 ;");
    if ($res) {
        $fields[num] = $res->cols;
    }
    $res = @dbx_query($link, "SELECT * FROM " . $table . " LIMIT 1 ;");
    if ($res) {
        $fields[res] = $res->info[name];
    } else {
        return NULL;
    }
    return $fields;
}
Exemplo n.º 5
0
function jz_db_query($link, $sql)
{
    return @dbx_query($link, $sql);
}
Exemplo n.º 6
0
 function anydb_query($sql, $db = "")
 {
     global $anydb_type;
     $db = anydb_handle($db);
     $res = false;
     if ($anydb_type == ANYDB_PEAR) {
         $res = $db->query($sql);
         if (DB::isError($res)) {
             $res = false;
         }
     } elseif ($anydb_type == ANYDB_ADO) {
         $res = $db->Execute($sql);
     } elseif ($anydb_type == ANYDB_DBX) {
         $res = dbx_query($db, $sql, DBX_RESULT_ASSOC);
     } elseif ($anydb_type == ANYDB_PG) {
         $res = pg_query($db, $sql);
     } elseif ($anydb_type == ANYDB_MY) {
         $res = mysql_query($sql, $db, MYSQL_ASSOC);
     }
     return $res;
 }
Exemplo n.º 7
0
 /**
  * This function is a very basic query executor. It shouldn't usually be used by you, as there are abstracted versions available.
  *
  * @param  string			The complete SQL query
  * @param  array			A DB connection
  * @param  ?integer		The maximum number of rows to affect (NULL: no limit)
  * @param  ?integer		The start row to affect (NULL: no specification)
  * @param  boolean		Whether to output an error on failure
  * @param  boolean		Whether to get the autoincrement ID created for an insert query
  * @return ?mixed			The results (NULL: no results), or the insert ID
  */
 function db_query($query, $db_parts, $max = NULL, $start = NULL, $fail_ok = false, $get_insert_id = false)
 {
     list($db, ) = $db_parts;
     if (isset($query[500000])) {
         $test_result = $this->db_query('SHOW VARIABLES LIKE \'max_allowed_packet\'', $db_parts, NULL, NULL, true);
         if (!is_array($test_result)) {
             return NULL;
         }
         if (intval($test_result[0]['Value']) < intval(strlen($query) * 1.2)) {
             if ($get_insert_id) {
                 fatal_exit(do_lang_tempcode('QUERY_FAILED_TOO_BIG', escape_html($query)));
             }
             return NULL;
         }
     }
     if ($max !== NULL && $start !== NULL) {
         $query .= ' LIMIT ' . strval($start) . ',' . strval($max);
     } elseif ($max !== NULL) {
         $query .= ' LIMIT ' . strval($max);
     } elseif ($start !== NULL) {
         $query .= ' LIMIT ' . strval($start) . ',30000000';
     }
     $results = @dbx_query($db, $query, DBX_RESULT_INFO);
     if ($results === 0 && (!$fail_ok || strpos(dbx_error($db), 'is marked as crashed and should be repaired') !== false)) {
         $err = dbx_error($db);
         if (function_exists('ocp_mark_as_escaped')) {
             ocp_mark_as_escaped($err);
         }
         if (!running_script('upgrader') && get_page_name() != 'admin_import') {
             if (!function_exists('do_lang') || is_null(do_lang('QUERY_FAILED', NULL, NULL, NULL, NULL, false))) {
                 fatal_exit(htmlentities('Query failed: ' . $query . ' : ' . $err));
             }
             fatal_exit(do_lang_tempcode('QUERY_FAILED', escape_html($query), $err));
         } else {
             echo htmlentities('Database query failed: ' . $query . ' [') . $err . htmlentities(']' . '<br />' . chr(10));
             return NULL;
         }
     }
     if (is_object($results) && (strtoupper(substr($query, 0, 7)) == 'SELECT ' || strtoupper(substr($query, 0, 8)) == '(SELECT ' || strtoupper(substr($query, 0, 8)) == 'EXPLAIN ' || strtoupper(substr($query, 0, 9)) == 'DESCRIBE ' || strtoupper(substr($query, 0, 5)) == 'SHOW ')) {
         return $this->db_get_query_rows($results);
     }
     if ($get_insert_id) {
         if (strtoupper(substr($query, 0, 7)) == 'UPDATE ') {
             if (function_exists('mysql_affected_rows')) {
                 return mysql_affected_rows($db->handle);
             } else {
                 return -1;
             }
         }
         //return mysql_insert_id($db->handle);
         if (strtoupper(substr($query, 0, 12)) == 'INSERT INTO ') {
             $table = substr($query, 12, strpos($query, ' ', 12) - 12);
             $rows = $this->db_query('SELECT MAX(id) AS x FROM ' . $table, $db_parts, 1, 0, false, false);
             return $rows[0]['x'];
         }
     }
     return NULL;
 }