Esempio n. 1
0
function dba_fetch_assoc($handle)
{
    $assoc = array();
    for ($k = dba_firstkey($handle); $k != false; $k = dba_nextkey($handle)) {
        $assoc[$k] = dba_fetch($k, $handle);
        echo "\$k: {$k}, \$assoc[\$k]: " . $assoc[$k] . "\n";
    }
    return $assoc;
}
Esempio n. 2
0
 /**
  * Returns true if the iteration has more elements. (In other words, 
  * returns true if next would return an element rather than throwing 
  * an exception.)
  *
  * @return  bool
  */
 public function hasNext()
 {
     if (NULL === $this->_key) {
         // First call
         $this->_key = dba_firstkey($this->_fd);
     } else {
         // Subsequent calls
         $this->_key = dba_nextkey($this->_fd);
     }
     return is_string($this->_key);
 }
Esempio n. 3
0
 /**
  * Internal cleaning process.
  *
  * @param boolean $cleanAll
  *
  * @return void
  */
 protected function process($cleanAll = true)
 {
     $key = dba_firstkey($this->cache->getDba());
     while ($key !== false && $key !== null) {
         if (true === $cleanAll) {
             $this->cache->delete($key);
         } else {
             $this->cache->get($key);
         }
         $key = dba_nextkey($this->cache->getDba());
     }
     dba_optimize($this->cache->getDba());
 }
Esempio n. 4
0
 public function getKeys()
 {
     $db = dba_open($this->filePath, 'wl', 'db4');
     $key = dba_firstkey($db);
     $keys_array = array();
     while ($key != false) {
         if (true) {
             // remember the key to perform some action later
             $keys_array[] = $key;
         }
         $key = dba_nextkey($db);
     }
     dba_close($db);
     return $keys_array;
 }
Esempio n. 5
0
 function ALLFILES()
 {
     $id = dba_firstkey($this->handle);
     while ($id != false) {
         $p = strrpos($id, ".");
         $id = substr($id, 0, $p);
         $r[$id] = $id;
         $id = dba_nextkey($this->handle);
     }
     $r = array_values($r);
     return $r;
 }
Esempio n. 6
0
 /**
  * Returns an array of keys
  *
  * Note: Do not use this for databases containing large amounts 
  * of keys, use the iterator() method instead.
  *
  * @return  string[] keys
  * @throws  io.IOException in case fetching the keys fails
  * @see     xp://io.dba.DBAFile#iterator
  */
 public function keys()
 {
     $keys = array();
     if (NULL === ($k = dba_firstkey($this->_fd))) {
         throw new IOException('Could not fetch first key');
     }
     while (is_string($k)) {
         $keys[] = $k;
         $k = dba_nextkey($this->_fd);
     }
     return $keys;
 }
Esempio n. 7
0
 public function nextkey()
 {
     return dba_nextkey($this->handle);
 }
Esempio n. 8
0
File: Dba.php Progetto: schpill/thin
 public function getAll()
 {
     // reset cache
     $this->cache = [];
     $tmp = [];
     // read all
     for ($key = dba_firstkey($this->dbHandler); $key != false; $key = dba_nextkey($this->dbHandler)) {
         $v = dba_fetch($key, $this->dbHandler);
         // Convert
         $value = $this->decode($v);
         // Store
         $tmp[$key] = $value;
     }
     if ($this->useCache) {
         $this->cache = $tmp;
     }
     return $tmp;
 }
Esempio n. 9
0
function HyperCacheSizeLog($dbfile)
{
    $dbfile = "/usr/share/squid3/HyperCacheSizeLog.db";
    if (!is_file($dbfile)) {
        return;
    }
    $db_con = dba_open($path, "r", "db4");
    if (!$db_con) {
        return false;
    }
    $mainkey = dba_firstkey($db_con);
    while ($mainkey != false) {
        $val = 0;
        $array = unserialize(dba_fetch($mainkey, $db_con));
        $zDate = $mainkey;
        $mainkey = dba_nextkey($db_con);
        if (!is_array($data)) {
            continue;
        }
    }
    dba_close($db_con);
    $this->ok = true;
    return $wwwUH;
}
Esempio n. 10
0
function find_md5_loop($filemd5)
{
    $dbfile = "{$GLOBALS["HyperCacheStoragePath"]}/cache.db";
    $db_con = @dba_open($dbfile, "r", "db4");
    if (!$db_con) {
        events("analyze:: FATAL!!!::{$dbfile}, unable to open");
        return null;
    }
    $mainkey = dba_firstkey($db_con);
    while ($mainkey != false) {
        $array = unserialize(dba_fetch($mainkey, $db_con));
        $keymd5 = $array["md5file"];
        if ($keymd5 == $filemd5) {
            $uri = $mainkey;
            @dba_close($db_con);
            return $uri;
        }
        $mainkey = dba_nextkey($db_con);
    }
    @dba_close($db_con);
}
Esempio n. 11
0
File: Dba.php Progetto: nuklehed/zf2
 /**
  * Remove items matching given prefix
  *
  * @param string $prefix
  * @return boolean
  */
 public function clearByPrefix($prefix)
 {
     $options = $this->getOptions();
     $prefix = $options->getNamespace() . $options->getNamespaceSeparator() . $prefix;
     $prefixl = strlen($prefix);
     $result = true;
     $this->_open();
     do {
         // Workaround for PHP-Bug #62491 & #62492
         $recheck = false;
         $internalKey = dba_firstkey($this->handle);
         while ($internalKey !== false && $internalKey !== null) {
             if (substr($internalKey, 0, $prefixl) === $prefix) {
                 $result = dba_delete($internalKey, $this->handle) && $result;
                 $recheck = true;
             }
             $internalKey = dba_nextkey($this->handle);
         }
     } while ($recheck);
     return $result;
 }
Esempio n. 12
0
function list_keys()
{
    $res = array();
    if (!($id = dba_open(FILEDB_PATH, "wd", FILEDB_HANDLER))) {
        return ERROR;
    }
    for ($key = dba_firstkey($id); $key != false; $key = dba_nextkey($id)) {
        array_push($res, array($key, dba_fetch($key, $id)));
    }
    dba_close($id);
    return $res;
}
function parse_userauthdb($path, $uuid = null, $asmeta = false)
{
    $unix = new unix();
    $f = array();
    if ($GLOBALS["VERBOSE"]) {
        echo "Parsing {$path}\n";
    }
    if (!is_file($path)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$path} no such file\n";
        }
        return;
    }
    $db_con = dba_open($path, "r", "db4");
    if (!$db_con) {
        if ($asmeta) {
            meta_admin_mysql(1, "DB open failed {$path}", null, __FILE__, __LINE__);
        }
        echo "DB open failed\n";
        die;
    }
    $mainkey = dba_firstkey($db_con);
    while ($mainkey != false) {
        $val = 0;
        $array = unserialize(dba_fetch($mainkey, $db_con));
        $mac = $array["MAC"];
        if (strlen($mac) > 17) {
            $mac = clean_mac($mac);
        }
        $ipaddr = $array["IPADDR"];
        $uid = $array["uid"];
        $hostname = $array["hostname"];
        $UserAgent = $array["UserAgent"];
        $UserAgent = mysql_escape_string2($UserAgent);
        $uid = mysql_escape_string2($uid);
        $ipaddr = mysql_escape_string2($ipaddr);
        $mac = mysql_escape_string2($mac);
        $f[] = "('{$mainkey}','{$mac}','{$ipaddr}','{$uid}','{$hostname}','{$UserAgent}')";
        $mainkey = dba_nextkey($db_con);
    }
    dba_close($db_con);
    if (count($f) > 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "UserAutDB: INSERTING " . count($f) . " elements\n";
        }
        $q = new mysql_squid_builder();
        if ($uuid != null) {
            $q = new mysql_stats($uuid);
        }
        $sql = "INSERT IGNORE INTO UserAutDB (zmd5,MAC,ipaddr,uid,hostname,UserAgent) VALUES " . @implode(",", $f);
        $q->QUERY_SQL("TRUNCATE TABLE `UserAutDB`");
        $q->QUERY_SQL($sql);
    }
}
Esempio n. 14
0
function GetAllWikiPagenames($dbi)
{
    $namelist = array();
    $ctr = 0;
    $namelist[$ctr] = $key = dba_firstkey($dbi);
    while ($key = dba_nextkey($dbi)) {
        $ctr++;
        $namelist[$ctr] = $key;
    }
    return $namelist;
}
function ParseFile($tgz)
{
    $mysql = new mysql();
    if (!preg_match("#^(.+?)-[0-9]+-artica-php#", basename($tgz), $re)) {
        meta_events("Unable to find uuid in {$tgz}");
        return false;
    }
    $uuid = $re[1];
    $f = array();
    $GLOBALS["UUIDS"][$uuid] = true;
    $q = new mysql_uuid_meta($uuid);
    $tmpfile = $GLOBALS["CLASS_UNIX"]->FILE_TEMP() . ".db";
    $unix = new unix();
    if (!$unix->uncompress($tgz, $tmpfile)) {
        @unlink($tmpfile);
        meta_events("{$GLOBALS["UNCOMPRESSLOGS"]}");
        @unlink($tgz);
        return false;
    }
    $db_con = @dba_open($tmpfile, "r", "db4");
    if (!$db_con) {
        meta_events("Warning! DB open {$tmpfile} failed...");
        return false;
    }
    $mainkey = dba_firstkey($db_con);
    $c = 0;
    $n = 0;
    while ($mainkey != false) {
        $data = dba_fetch($mainkey, $db_con);
        $Array = unserialize($data);
        if (!is_array($Array)) {
            meta_events("{$mainkey} -> {$data} not an array...");
            $mainkey = dba_nextkey($db_con);
            continue;
        }
        $md5 = md5(serialize($Array));
        $date = $Array["DATE"];
        $time = strtotime($date);
        $xtime = date("Y-m-d H:i:s", $time);
        $hits = $Array["HITS"];
        $size = $Array["SIZE"];
        $mac = $Array["MAC"];
        $uid = $Array["UID"];
        $ipaddr = $Array["IPADDR"];
        $website = $Array["website"];
        $tablename = "squid_hourly_" . date("YmdH", $time);
        $f[$tablename][] = "('{$md5}','{$xtime}','{$website}','{$mac}','{$uid}','{$ipaddr}','{$hits}','{$size}')";
        if (count($f[$tablename]) > 2000) {
            meta_events("{$tablename} -> " . count($f[$tablename]));
            $prefix = "INSERT IGNORE INTO `{$tablename}` (`zdm5`,`zDate`,`sitename`,`mac`,`uid`,`ipaddr`,`hits`,`size`) VALUES ";
            if (!$q->create_squid_hourly($tablename)) {
                return false;
            }
            $q->QUERY_SQL($prefix . @implode(",", $f[$tablename]));
            if (!$q->ok) {
                meta_events($q->mysql_error);
                return false;
            }
            $f[$tablename] = array();
        }
        $mainkey = dba_nextkey($db_con);
    }
    if (count($f) > 0) {
        while (list($tablename, $rows) = each($f)) {
            meta_events("{$tablename} -> " . count($rows));
            $prefix = "INSERT IGNORE INTO `{$tablename}` (`zmd5`,`zDate`,`sitename`,`mac`,`uid`,`ipaddr`,`hits`,`size`) VALUES ";
            if (!$q->create_squid_hourly($tablename)) {
                return false;
            }
            $q->QUERY_SQL($prefix . @implode(",", $rows));
            if (!$q->ok) {
                meta_events($q->mysql_error);
                return false;
            }
        }
    }
    return true;
}
Esempio n. 16
0
 function nextkey()
 {
     return dba_nextkey($this->_dbh);
 }
Esempio n. 17
0
 function _match($word)
 {
     $words = array();
     for ($k = dba_firstkey($this->db); $k !== false; $k = dba_nextkey($this->db)) {
         if (isset($k[0]) and strcmp($k[0], "") > 0 and preg_match('@' . $word . '@', $k)) {
             $words[] = $k;
         }
     }
     return $words;
 }
Esempio n. 18
0
 /**
  * Retrieves the next key in the database.  Used with firstkey to
  * loop through records.
  * 
  * @access	public
  * @return	string
  * 
  */
 function nextkey()
 {
     return @dba_nextkey($this->connection);
 }
Esempio n. 19
0
 function next()
 {
     $this->key = dba_nextkey($this->obj->db);
 }
Esempio n. 20
0
<?php

// xxx
// dump the dict.cdb to dict.txt
//
define("_WORD_ALONE_", 0x4000000);
define("_WORD_PART_", 0x8000000);
$db = dba_open("dict.cdb", "r", "cdb");
$total = 0;
if ($key = dba_firstkey($db)) {
    do {
        $value = (int) dba_fetch($key, $db);
        if (!($value & _WORD_ALONE_)) {
            continue;
        }
        $value &= ~(_WORD_ALONE_ | _WORD_PART_);
        echo "{$key}\t\t{$value}\r\n";
        $total++;
    } while ($key = dba_nextkey($db));
}
dba_close($db);
echo "# total {$total}\n";
Esempio n. 21
0
<?php

$handler = 'db4';
require_once dirname(__FILE__) . '/test.inc';
$db = dba_open($db_filename, 'c', 'db4');
var_dump(dba_nextkey($db));
dba_close($db);
?>
===DONE===
Esempio n. 22
0
 function cleanup_nonce()
 {
     /*{{{*/
     $key = dba_firstkey($this->dbh);
     $now = time();
     $handle_later = array();
     while ($key != false) {
         # clean up old-NONCEs -> oauth_timestamp ;; OAuthServer->timestamp_threshold (300 sec)
         # give it some extra hour(s) eg. server changes time-zones...
         if (!strncmp($key, "nonce_", 6) && dba_fetch($key, $this->dbh) + 3900 < $now) {
             $handle_later[] = $key;
         }
         # same for old session-tokens.
         if (!strncmp($key, "session_", 8) && ($rv = dba_fetch($key, $this->dbh))) {
             $data = unserialize($rv);
             if ($data['created'] + 3900 < $now) {
                 $handle_later[] = $key;
             }
         }
         $key = dba_nextkey($this->dbh);
     }
     foreach ($handle_later as $key) {
         dba_delete($key, $this->dbh);
     }
 }
Esempio n. 23
0
File: Dba.php Progetto: tillk/vufind
 /**
  * Remove items matching given prefix
  *
  * @param string $prefix
  * @return bool
  */
 public function clearByPrefix($prefix)
 {
     $prefix = (string) $prefix;
     if ($prefix === '') {
         throw new Exception\InvalidArgumentException('No prefix given');
     }
     $options = $this->getOptions();
     $namespace = $options->getNamespace();
     $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator() . $prefix;
     $prefixL = strlen($prefix);
     $result = true;
     $this->_open();
     do {
         // Workaround for PHP-Bug #62491 & #62492
         $recheck = false;
         $internalKey = dba_firstkey($this->handle);
         while ($internalKey !== false && $internalKey !== null) {
             if (substr($internalKey, 0, $prefixL) === $prefix) {
                 $result = dba_delete($internalKey, $this->handle) && $result;
                 $recheck = true;
             }
             $internalKey = dba_nextkey($this->handle);
         }
     } while ($recheck);
     return $result;
 }
Esempio n. 24
0
 function keys()
 {
     $reader = $this->getReader();
     $k1 = dba_firstkey($reader);
     if (!$k1) {
         return array();
     }
     $result[] = $k1;
     $key = dba_nextkey($reader);
     while ($key) {
         $result[] = $key;
         $key = dba_nextkey($reader);
     }
     return $result;
 }
Esempio n. 25
0
function WhitelistedBase($url)
{
    $db_path = "/var/log/squid/ufdbgclient.white.db";
    $H = parse_url($url);
    $domain = $H["host"];
    $fam = new familysite();
    $familysite = $fam->GetFamilySites($domain);
    $WhitelistedBase_domain = WhitelistedBase_domain($domain);
    if ($WhitelistedBase_domain == 1) {
        return true;
    }
    $WhitelistedBase_domain = WhitelistedBase_domain($familysite);
    if ($WhitelistedBase_domain == 1) {
        return true;
    }
    if ($WhitelistedBase_domain == 2) {
        return false;
    }
    if (!is_file($db_path)) {
        if ($GLOBALS["DEBUG_WHITELIST"]) {
            events("WHITELIST:: {$db_path} -> no such file");
        }
        return false;
    }
    $db_con = dba_open($db_path, "r", "db4");
    if (!$db_con) {
        return false;
    }
    $mainkey = dba_firstkey($db_con);
    $domain_regex = str_replace(".", "\\.", $domain);
    $family_regex = str_replace(".", "\\.", $familysite);
    while ($mainkey != false) {
        $val = 0;
        if (trim($mainkey) == null) {
            $mainkey = dba_nextkey($db_con);
            continue;
        }
        if ($GLOBALS["DEBUG_WHITELIST"]) {
            events("WHITELIST:: WhitelistedBase: Checking {$mainkey} -> {$domain}");
        }
        if (preg_match("#{$mainkey}#", $domain)) {
            if ($GLOBALS["DEBUG_WHITELIST"]) {
                events("WHITELIST:: WhitelistedBase {$mainkey} MATCH {$domain}");
            }
            $GLOBALS["WhitelistedBase"][$domain] = true;
            dba_close($db_con);
            return true;
        }
        if ($GLOBALS["DEBUG_WHITELIST"]) {
            events("WHITELIST:: #{$mainkey}# NO MATCH {$domain}");
        }
        if (preg_match("#{$mainkey}#", $familysite)) {
            if ($GLOBALS["DEBUG_WHITELIST"]) {
                events("WHITELIST:: WhitelistedBase {$mainkey} MATCH {$familysite}");
            }
            $GLOBALS["WhitelistedBase"][$familysite] = true;
            dba_close($db_con);
            return true;
        }
        if ($GLOBALS["DEBUG_WHITELIST"]) {
            events("WHITELIST:: #{$mainkey}# NO MATCH {$domain}");
        }
        $mainkey = dba_nextkey($db_con);
    }
    dba_close($db_con);
    if ($GLOBALS["DEBUG_WHITELIST"]) {
        events("WHITELIST:: Assume {$domain} FALSE");
    }
    if ($GLOBALS["DEBUG_WHITELIST"]) {
        events("WHITELIST:: Assume {$familysite} FALSE");
    }
    if (!isset($GLOBALS["WhitelistedBase"])) {
        $GLOBALS["WhitelistedBase"] = array();
    }
    $CountOf = count($GLOBALS["WhitelistedBase"]);
    if ($GLOBALS["DEBUG_WHITELIST"]) {
        events("WHITELIST:: {$CountOf} domains in memory");
    }
    if ($CountOf > 5000) {
        $GLOBALS["WhitelistedBase"] = array();
    }
    $GLOBALS["WhitelistedBase"][$domain] = false;
    $GLOBALS["WhitelistedBase"][$familysite] = false;
    return false;
}
 /**
  * Returns the next key in the database, false if there is a problem
  *
  * @access  public
  * @return  mixed string on success, false on failure
  */
 function nextkey()
 {
     if ($this->isReadable()) {
         return dba_nextkey($this->_dba);
     } else {
         return false;
     }
 }
Esempio n. 27
0
 /**
  * Move forward to next element
  *
  * @return void
  * @throws Exception\RuntimeException
  */
 public function next()
 {
     if ($this->currentInternalKey === false) {
         throw new Exception\RuntimeException("Iterator is on an invalid state");
     }
     $this->currentInternalKey = dba_nextkey($this->handle);
     // Workaround for PHP-Bug #62492
     if ($this->currentInternalKey === null) {
         $this->currentInternalKey = false;
     }
 }
Esempio n. 28
0
 public function next()
 {
     $this->key = dba_nextkey($this->getHandle());
 }
<?php

require_once dirname(__FILE__) . '/test.inc';
echo "database handler: {$handler}\n";
if (($db_file = dba_open($db_filename, "n", $handler)) !== FALSE) {
    dba_insert("key1", "Content String 1", $db_file);
    dba_insert("key2", "Content String 2", $db_file);
    $a = dba_firstkey($db_file);
    $i = 0;
    while ($a) {
        $a = dba_nextkey($db_file);
        $i++;
    }
    echo $i;
    for ($i = 1; $i < 3; $i++) {
        echo dba_exists("key{$i}", $db_file) ? "Y" : "N";
    }
    echo "\n";
    var_dump(dba_optimize());
    var_dump(dba_optimize(""));
    var_dump(dba_optimize($db_file));
    dba_close($db_file);
} else {
    echo "Error creating database\n";
}
?>
===DONE===
Esempio n. 30
0
 /**
  * @return string
  */
 public function sNextkey()
 {
     return dba_nextkey($this->_hFile);
 }