Example #1
0
function wobi_install()
{
    if (get_option('wobi_content' == '') || !get_option('wobi_content')) {
        $prefix = "rt_";
        $makenamemap = 'CREATE TABLE ' . $prefix . 'namemap (info_hash char(40) NOT NULL default "", filename varchar(250) NOT NULL default "", url varchar(250) NOT NULL default "", size bigint(20) unsigned NOT NULL, pubDate varchar(25) NOT NULL default "", PRIMARY KEY(info_hash)) ENGINE = innodb';
        $makesummary = 'CREATE TABLE ' . $prefix . 'summary (info_hash char(40) NOT NULL default "", dlbytes bigint unsigned NOT NULL default 0, seeds int unsigned NOT NULL default 0, leechers int unsigned NOT NULL default 0, finished int unsigned NOT NULL default 0, lastcycle int unsigned NOT NULL default "0", lastSpeedCycle int unsigned NOT NULL DEFAULT "0", speed bigint unsigned NOT NULL default 0, piecelength int(11) NOT NULL default -1, numpieces int(11) NOT NULL default 0, PRIMARY KEY (info_hash)) ENGINE = innodb';
        $maketimestamps = 'CREATE TABLE ' . $prefix . 'timestamps (info_hash char(40) not null, sequence int unsigned not null auto_increment, bytes bigint unsigned not null, delta smallint unsigned not null, primary key(sequence), key sorting (info_hash)) ENGINE = innodb';
        $makespeedlimit = 'CREATE TABLE ' . $prefix . 'speedlimit (uploaded bigint(25) NOT NULL default 0, total_uploaded bigint(30) NOT NULL default 0, started bigint(25) NOT NULL default 0) ENGINE = innodb';
        $makewebseedfiles = 'CREATE TABLE ' . $prefix . 'webseedfiles (info_hash char(40) default NULL, filename char(250) NOT NULL default "", startpiece int(11) NOT NULL default 0, endpiece int(11) NOT NULL default 0, startpieceoffset int(11) NOT NULL default 0, fileorder int(11) NOT NULL default 0, UNIQUE KEY fileseq (info_hash,fileorder)) ENGINE = innodb';
        mysql_query($makesummary) or die(_wobi_errorMessage() . "Can't make the summary table: " . mysql_error() . "</p>");
        mysql_query($makenamemap) or die(_wobi_errorMessage() . "Can't make the namemap table: " . mysql_error() . "</p>");
        mysql_query($maketimestamps) or die(_wobi_errorMessage() . "Can't make the timestamps table: " . mysql_error() . "</p>");
        mysql_query($makespeedlimit) or die(_wobi_errorMessage() . "Can't make the speedlimit table: " . mysql_error() . "</p>");
        mysql_query($makewebseedfiles) or die(_wobi_errorMessage() . "Can't make the webseedfiles table: " . mysql_error() . "</p>");
        mysql_query("INSERT INTO " . $prefix . "speedlimit values (0,0,0)") or die(_wobi_errorMessage() . "Can't insert zeros into speedlimit table: " . mysql_error() . "</p>");
        echo "<p class=\"success\">Database was created successfully!</p><br><br>";
        add_option('wobi_content', 'on');
    }
    // if(get_option('wobi_config' == '') || !get_option('wobi_config')){
    $fpath = WP_CONTENT_DIR . "/plugins/wobi-bittorrent/dbconfig.php";
    $f = fopen($fpath, "w");
    fwrite($f, "<?php\n");
    fwrite($f, '$dbhost = \'' . DB_HOST . "';\n");
    fwrite($f, '$dbuser = \'' . DB_USER . "';\n");
    fwrite($f, '$dbpass = \'' . DB_PASSWORD . "';\n");
    fwrite($f, '$database = \'' . DB_NAME . "';\n");
    fwrite($f, '$website_url = \'' . WP_CONTENT_DIR . "/plugins/wobi-bittorrent';\n\n");
    fclose($f);
    //  echo "<p class=\"success\">Config file created successfully!</p><br><br>";
    //    add_option('wobi_config', 'on');
    //}
    /*
        // register widget
        if (function_exists('register_sidebar_widget'))
        register_sidebar_widget('Smart YouTube', 'yte_widget'); 
    
        if (function_exists('register_widget_control')) 
        register_widget_control('Smart YouTube', 'yte_widgetcontrol');
    */
}
Example #2
0
File: wobi.php Project: j3k0/Wobi
function _wobi_addTorrent($torrent_file_path, $torrent_file_url, $file_path, $file_url)
{
    require "config.php";
    $tracker_url = WOBI_TRACKER_URL;
    $httpseed = true;
    $tmp1 = explode("/wp-content/", $file_path);
    $relative_path = "../../" . $tmp1[1];
    $getrightseed = false;
    $httpftplocation = $file_url;
    $target_path = "torrents/";
    $autoset = true;
    $filename = "";
    // $file_path; // Extracted from torrent (if $autoset)
    $url = "{$file_url}";
    // Extracted from torrent (if $autoset)
    $hash = "";
    // Extracted from torrent (if $autoset)
    // TODO: Only if not already connected.
    // $db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Couldn't connect to the database, contact the administrator.</p>");
    // mysql_select_db($database) or die(errorMessage() . "Can't open the database.</p>");
    require_once "funcsv2.php";
    require_once "BDecode.php";
    require_once "BEncode.php";
    // Check for errors, we don't care right?
    $fd = fopen($torrent_file_path, "rb") or die(_wobi_errorMessage() . "File upload error 1</p>\n");
    // is_uploaded_file($torrent_file_path) or die(_wobi_errorMessage() . "File upload error 2</p>\n");
    $alltorrent = fread($fd, filesize($torrent_file_path));
    $array = BDecode($alltorrent);
    if (!$array) {
        $wobi_error = _wobi_errorMessage() . "Error: The parser was unable to load your torrent.  Please re-create and re-upload the torrent.</p>\n";
        return false;
    }
    if (strtolower($array["announce"]) != $tracker_url) {
        $wobi_error = _wobi_errorMessage() . "Error: The tracker announce URL does not match this:<br>{$tracker_url}<br>Please re-create and re-upload the torrent.</p>\n";
        return false;
    }
    if ($httpseed && $relative_path == "") {
        $wobi_error = _wobi_errorMessage() . "Error: HTTP seeding was checked however no relative path was given.</p>\n";
        return false;
    }
    if ($httpseed && $relative_path != "") {
        if (Substr($relative_path, -1) == "/") {
            if (!is_dir($relative_path)) {
                $wobi_error = _wobi_errorMessage() . "Error: HTTP seeding relative path ends in / but is not a valid directory.</p>\n";
                return false;
            }
        } else {
            if (!is_file($relative_path)) {
                $wobi_error = _wobi_errorMessage() . "Error: HTTP seeding relative path is not a valid file.</p>\n";
                return false;
            }
        }
    }
    if ($getrightseed && $httpftplocation == "") {
        $wobi_error = _wobi_errorMessage() . "Error: GetRight HTTP seeding was checked however no URL was given.</p>\n";
        return false;
    }
    if ($getrightseed && (Substr($httpftplocation, 0, 7) != "http://" && Substr($httpftplocation, 0, 6) != "ftp://")) {
        $wobi_error = _wobi_errorMessage() . "Error: GetRight HTTP seeding URL must start with http:// or ftp://</p>\n";
        return false;
    }
    $hash = @sha1(BEncode($array["info"]));
    fclose($fd);
    $target_path = $target_path . basename($torrent_file_path);
    $move_torrent = rename($torrent_file_path, $target_path);
    if ($move_torrent == false) {
        $wobi_error = errorMessage() . "Unable to move {$torrent_file_path} to torrents/</p>\n";
    }
    if (!empty($filename)) {
        // XXX can probably remove this...
        $filename = clean($filename);
    }
    if (!empty($url)) {
        // XXX and this
        $url = clean($url);
    }
    if ($autoset) {
        if (strlen($filename) == 0 && isset($array["info"]["name"])) {
            $filename = $array["info"]["name"];
        }
    }
    //figure out total size of all files in torrent
    $info = $array["info"];
    $total_size = 0;
    if (isset($info["files"])) {
        foreach ($info["files"] as $file) {
            $total_size = $total_size + $file["length"];
        }
    } else {
        $total_size = $info["length"];
    }
    //Validate torrent file, make sure everything is correct
    $filename = mysql_escape_string($filename);
    $filename = htmlspecialchars(clean($filename));
    $url = htmlspecialchars(mysql_escape_string($url));
    if (strlen($hash) != 40 || !verifyHash($hash)) {
        $wobi_error = _wobi_errorMessage() . "Error: Info hash must be exactly 40 hex bytes.</p>\n";
        return false;
    }
    if (Substr($url, 0, 7) != "http://" && $url != "") {
        $wobi_error = _wobi_errorMessage() . "Error: The Torrent URL does not start with http:// Make sure you entered a correct URL.</p>\n";
        return false;
    }
    $query = "INSERT INTO " . $prefix . "namemap (info_hash, filename, url, size, pubDate) VALUES (\"{$hash}\", \"{$filename}\", \"{$url}\", \"{$total_size}\", \"" . date('D, j M Y h:i:s') . "\")";
    $status = makeTorrent($hash, true);
    quickQuery($query);
    chmod($target_path, 0644);
    if ($status) {
        $wobi_error = "<p class=\"success\">Torrent was added successfully.</p>\n";
        require_once "wobi_functions.php";
        _wobi_addWebseedfiles($target_path, $relative_path, $httpftplocation, $hash);
        return true;
    } else {
        $wobi_error = _wobi_errorMessage() . "There were some errors. Check if this torrent has been added previously.</p>\n";
        return false;
    }
}