/** * Initializes logger and database. */ function ProxyFramework($dbFile, $proxyChecker, $snapshotInterval, $proxyCheckInterval, $quarantineCheckInterval, $checkingThreadCap, $maxQuarantineRetries, $pidFile) { $this->logger = new LoggingImpl(); Helper::checkString("dbFile", $dbFile, $this->logger); Helper::checkNull("proxyChecker", $proxyChecker, $this->logger); $db = new DatabaseImpl($dbFile, array(100, 5, 15, 3, 13, 1, 1, 1, 1, 10, 6, 6, 4)); $db->cacheEntries(); //preemptively cache entries to make sure the db state is the same across all threads $uniqueIP = new UniqueIPDatabase(); // set up mutexes and shared data, as well as the signal handler $this->init(); $this->setVar(__INDEX_DATA, $db); $this->setVar(__INDEX_PIDS, array()); $this->setVar(__INDEX_CHECKING_THREAD_COUNT, 0); $this->setVar(__INDEX_UDATA, $uniqueIP); $this->proxyChecker = $proxyChecker; $this->snapshotInterval = $snapshotInterval; $this->proxyCheckInterval = $proxyCheckInterval; $this->quarantineCheckInterval = $quarantineCheckInterval; $this->checkingThreadCap = $checkingThreadCap; $this->maxQuarantineRetries = $maxQuarantineRetries; ProxyFramework::$pidFile = $pidFile; ProxyFramework::$instance = $this; ProxyFramework::$mainPid = posix_getpid(); }
drawGraph($files, array($bad, $good, $ssl, $fast)); print "drawing graph took: " . (microtime(true) - $start) . " secs\n"; $start = microtime(true); $fp = fopen('/usr/local/apache/htdocs/proxy_framework/stats', 'w+'); flock($fp, LOCK_EX); $udata = new UniqueIPDatabase(); fwrite($fp, $udata->getDatabase()->entryCount() . "\n"); $files = scandir(PF_DIR); $newfiles = array(); foreach ($files as $file) { if (strpos($file, "snapshot") !== false) { $newfiles[] = $file; } } $file = PF_DIR . "/" . $newfiles[count($newfiles) - 1]; $db = new DatabaseImpl($file); $good = count($db->searchEntries(SEARCH_FIELD_OFFSET | SEARCH_ARRAY, 8, 0)); fwrite($fp, "{$good}\n"); $bad = $db->entryCount() - $good; fwrite($fp, "{$bad}\n"); $fast = count($db->searchEntries(SEARCH_FIELD_OFFSET | SEARCH_COMPARE | SEARCH_ARRAY, 4, "<20", null, null, null, 0)); fwrite($fp, "{$fast}\n"); $slow = $good - $fast; fwrite($fp, "{$slow}\n"); $ssl = count($db->searchEntries(SEARCH_FIELD_OFFSET | SEARCH_ARRAY, 5, 1, null, null, 0)); fwrite($fp, "{$ssl}\n"); $http = count($db->searchEntries(SEARCH_FIELD_OFFSET | SEARCH_ARRAY, 7, PROXY, 0)); fwrite($fp, "{$http}\n"); $socks4 = count($db->searchEntries(SEARCH_FIELD_OFFSET | SEARCH_ARRAY, 7, SOCKS4, 0)); fwrite($fp, "{$socks4}\n"); $socks5 = count($db->searchEntries(SEARCH_FIELD_OFFSET | SEARCH_ARRAY, 7, SOCKS5, 0));
private function initializeReferencedDbs($fks, $initFks = false) { foreach ($fks as $fk) { if ($initFks) { $fk = explode($this->headerFieldSeparator, $fk); $this->fks[] = $fk; } // initialize referenced db $db = new DatabaseImpl($fk[0]); $db->cacheEntries(); $this->referencedDbs[] = $db; } }
<?php require_once "/usr/local/apache/ProxyFramework/DatabaseImpl.php"; $files = scandir("/usr/local/apache/ProxyFramework/"); $ports = new DatabaseImpl("/usr/local/apache/htdocs/proxy_framework/ports.db", array(5, 10)); $ippdb = new DatabaseImpl("/usr/local/apache/htdocs/proxy_framework/ipport.db", array(15, 5)); $pcounts = array(); $ipport = array(); foreach ($files as $f) { if (strpos($f, "snapshot-") !== false) { print "processing file {$f}...\n"; $db = new DatabaseImpl("/usr/local/apache/ProxyFramework/" . $f); $db->loadEntries($ent); foreach ($ent as $e) { if (!isset($pcounts[$e[1]])) { $pcounts[$e[1]] = 1; $ipport[$e[0]][$e[1]] = 1; $ipp[] = array($e[0], $e[1]); } else { if (!isset($ipport[$e[0]][$e[1]])) { $ipport[$e[0]][$e[1]] = 1; $ipp[] = array($e[0], $e[1]); $pcounts[$e[1]]++; } } } } } $ps = array(); foreach ($pcounts as $k => $v) { $ps[] = array($k, $v);
<?php require_once "/usr/local/apache/ProxyFramework/DatabaseImpl.php"; $db = new DatabaseImpl("/usr/local/apache/htdocs/proxy_framework/ports.db"); print "port count = " . $db->entryCount() . "\n";
if (count($newargs) == 1) { eval('$result = ' . $newargs[0] . ';'); return $result; } else { if (count($newargs) > 1) { $eval_str = 'array_intersect('; $eval_str .= implode(", ", $newargs); $eval_str .= ');'; //print("EVAL STR = $eval_str"); eval('$result = ' . $eval_str); return $result; } } } $file = PF_DIR . "/" . $newfiles[count($newfiles) - 1]; $db = new DatabaseImpl($file); if (count($_GET) > 0) { $results = array(); for ($i = 0; $i < 8; $i++) { if (isset($_GET["key" . $i])) { eval('$res' . $i . ' = $db->searchEntries(SEARCH_FIELD_OFFSET | SEARCH_ARRAY | SEARCH_COMPARE, $i, ' . ($i == 4 ? '"<=".' : '') . '$_GET["key".$i]);'); } } $filter = isset($res0) || isset($res1) || isset($res2) || isset($res3) || isset($res4) || isset($res5) || isset($res6) || isset($res7); if ($filter) { eval('$results = my_array_intersect($res0, $res1, $res2, $res3, $res4, $res5, $res6, $res7);'); if (count($results) > 0) { $db->loadEntries($proxies, $results, null, null, $_GET[sortColumn], $_GET[sortOrder]); } } }