コード例 #1
0
 public static function open()
 {
     // attempt to connect
     try {
         self::$db = new SQLite3($_SERVER['tracker']['db_path'], SQLITE3_OPEN_READWRITE);
     } catch (Exception $e) {
         // try and remove the file if one exist, it may be corrupted
         if (file_exists($_SERVER['tracker']['db_path'])) {
             @unlink($_SERVER['tracker']['db_path']);
         }
         // attempt creation
         try {
             self::$db = new SQLite3($_SERVER['tracker']['db_path']);
         } catch (Exception $e) {
             // relay the specific error message
             tracker_error($e->getMessage() . ' - verify chmod 0777 on db directory');
         }
         // create database tables
         self::$db->exec('BEGIN TRANSACTION; ' . 'CREATE TABLE IF NOT EXISTS peers ' . '(info_hash BLOB, peer_id BLOB, compact BLOB, ip TEXT, ' . 'port INTEGER DEFAULT 0, state INTEGER DEFAULT 0, ' . 'updated INTEGER DEFAULT 0); ' . 'CREATE TABLE IF NOT EXISTS tasks' . '(name TEXT, value INTEGER DEFAULT 0); ' . 'CREATE UNIQUE INDEX IF NOT EXISTS i0 ' . 'ON peers(info_hash, peer_id); ' . 'COMMIT;') or tracker_error('failed to create database tables');
     }
     // tweak sqlite performance
     self::$db->exec('PRAGMA synchronous = OFF; ' . 'PRAGMA journal_mode = MEMORY; ' . 'PRAGMA temp_store = MEMORY;') or tracker_error('failed to set sqlite3 options');
 }
コード例 #2
0
ファイル: scrape.php プロジェクト: istrwei/peertracker
    // open database
    peertracker::open();
    // display stats
    peertracker::stats();
    // close database
    peertracker::close();
    // exit immediately
    exit;
}
// strip auto-escaped data
if (get_magic_quotes_gpc()) {
    $_GET['info_hash'] = stripslashes($_GET['info_hash']);
}
// 20-bytes - info_hash
// sha-1 hash of torrent being tracked
if (!isset($_GET['info_hash']) || strlen($_GET['info_hash']) != 20) {
    // full scrape disabled
    if (!$_SERVER['tracker']['full_scrape']) {
        exit;
    } else {
        unset($_GET['info_hash']);
    }
}
// Handle Request //////////////////////////////////////////////////////////////////////////////////
// open database
peertracker::open();
// perform scrape
peertracker::scrape();
// close database
peertracker::close();
コード例 #3
0
ファイル: tracker.mysql.php プロジェクト: istrwei/peertracker
 public static function close()
 {
     // trigger __destruct()
     self::$api = null;
 }
コード例 #4
0
ファイル: help.php プロジェクト: istrwei/peertracker
function optimizeMySQL()
{
    // we need to locate tracker.mysql.php
    // first, try the most obvious location.. which should be in the
    // same directory as the ./help.php file being ran
    if (is_readable('./tracker.mysql.php')) {
        // require
        require './tracker.mysql.php';
    } elseif (findFile(realpath('.'), 'tracker.mysql.php')) {
        // require
        chdir(dirname($_GET['found_file_path']));
        require './tracker.mysql.php';
    } else {
        $_GET['notice'] = 'no';
        $_GET['message'] = '' . "Could not locate the <em>tracker.mysql.php</em> file. " . "Make sure all of the necessary tracker files have been uploaded. ";
        return;
    }
    // open db
    peertracker::open();
    // optimize
    if (peertracker::$api->query("CHECK TABLE `{$_SERVER['tracker']['db_prefix']}peers`") && peertracker::$api->query("ANALYZE TABLE `{$_SERVER['tracker']['db_prefix']}peers`") && peertracker::$api->query("REPAIR TABLE `{$_SERVER['tracker']['db_prefix']}peers`") && peertracker::$api->query("OPTIMIZE TABLE `{$_SERVER['tracker']['db_prefix']}peers`")) {
        // no errors, hopefully???
        $_GET['notice'] = 'yes';
        $_GET['message'] = 'Your MySQL Tracker Database has been optimized.';
    } else {
        $_GET['notice'] = 'no';
        $_GET['message'] = 'Could not optimize the MySQL Database.';
    }
    // close
    peertracker::close();
}
コード例 #5
0
 public static function open()
 {
     // attempt to connect
     self::$db = pg_connect("host='{$_SERVER['tracker']['db_host']}' dbname='{$_SERVER['tracker']['db_name']}' " . "user='******'tracker']['db_user']}' password='******'tracker']['db_pass']}'") or tracker_error('database error - ' . pg_last_error(self::$db));
 }