function scrape($url, $infohash = '') { global $TABLE_PREFIX; if (isset($url)) { $url_c = parse_url($url); $extannunce = ($url_c['scheme'] == 'udp' ? 'http' : $url_c['scheme']) . '://' . $url_c['host']; $extannunce .= isset($url_c['port']) ? ':' . $url_c['port'] : ''; $extannunce .= substr_replace($url_c['path'], 'scrape', strbipos($url_c['path'], 'announce') + 1, 8); $extannunce .= isset($url_c['query']) ? '?' . $url_c['query'] : ''; //die($extannunce); if ($infohash != '') { $ihash = array(); $ihash = explode("','", $infohash); $info_hash = ''; foreach ($ihash as $myihash) { $info_hash .= '&info_hash=' . escapeURL($myihash); } $info_hash = substr($info_hash, 1); $stream = get_remote_file($extannunce . (substr_count($extannunce, '?') > 0 ? '&' : '?') . $info_hash); } else { $stream = get_remote_file($extannunce); } //$stream=trim(stristr($stream,'d5:files')); $stream = trim($stream); if (strpos($stream, 'd5:files') === false) { $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash == '' ? '' : ' AND info_hash IN ("' . $infohash . '")')); write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (not connectable)', ''); return; } $array = BDecode($stream); if (!isset($array) || $array == false || !isset($array['files'])) { $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash == '' ? '' : ' AND info_hash IN ("' . $infohash . '")')); write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (not bencode data)', ''); return; } $files = $array['files']; if (!is_array($files)) { $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash == '' ? '' : ' AND info_hash IN ("' . $infohash . '")')); write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (probably deleted torrent(s))', ''); return; } foreach ($files as $hash => $data) { $seeders = $data['complete']; $leechers = $data['incomplete']; $completed = isset($data['downloaded']) ? $data['downloaded'] : 0; $torrenthash = bin2hex(stripslashes($hash)); $ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW(), lastsuccess=NOW(), seeds=' . $seeders . ', leechers=' . $leechers . ', finished=' . $completed . ' WHERE announce_url = "' . $url . '"' . ($hash == '' ? '' : ' AND info_hash="' . $torrenthash . '";')); if (mysql_affected_rows() == 1) { write_log('SUCCESS update external torrent from ' . $url . ' tracker (infohash: ' . $torrenthash . ')', ''); } } } }
function add_dos_link($link, $target, $title, $method) { require_once $PHP_INCLUDE_PATH . "hash.php"; require_once $PHP_INCLUDE_PATH . "validate.php"; if (isValidURL($link) && isValidURL($target)) { $target = escapeURL($target); $link = escapeURL($link); } else { die("Invalid url entered."); } $title = htmlentities($_POST['title']); if (is_banned_domain($target)) { die("This domain is disallowed."); } $res = exec_query("SELECT * FROM dos_links WHERE link='" . mysql_real_escape_string($link) . "' AND target='" . mysql_real_escape_string($target) . "' AND title='" . mysql_real_escape_string($title) . "' AND use_get=" . $method . ";"); if (mysql_num_rows($res) != 0) { $row = mysql_fetch_assoc($res); return $row['hash']; } else { $hash = calc_new_hash($link . $target . $title); $res = insert_new_entry($hash, $link, $title, $target, $method); return $hash; } }
function scrape($url, $infohash = "") { global $db; if (isset($url)) { $u = urldecode($url); $extannunce = str_replace("announce", "scrape", $u); $purl = parse_url($extannunce); $port = isset($purl["port"]) ? $purl["port"] : "80"; $path = isset($purl["path"]) ? $purl["path"] : "/scrape.php"; $an = ($purl["scheme"] != "http" ? $purl["scheme"] . "://" : "") . $purl["host"]; $fd = @fsockopen($an, $port, $errno, $errstr, 60); if ($fd) { if ($infohash != "") { $ihash = array(); $ihash = explode("','", $infohash); $info_hash = ""; foreach ($ihash as $myihash) { $info_hash .= "&info_hash=" . escapeURL($myihash); } $info_hash = substr($info_hash, 1); fputs($fd, "GET " . $path . "?" . $info_hash . " HTTP/1.0\r\nHost: somehost.net\r\n\r\n"); } else { fputs($fd, "GET " . $path . " HTTP/1.0\r\nHost: somehost.net\r\n\r\n"); } $stream = ""; while (!feof($fd)) { $stream .= fgets($fd, 4096); if (strlen($stream) > 100000) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (response too big)", ""); @fclose($fd); return; } } } else { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not connectable)", ""); return; } @fclose($fd); $stream = utf8::trim(stristr($stream, "d5:files")); if (strpos($stream, "d5:files") === false) { // if host answer but stream is not valid encoded file try old metod // will work only with standard http $ihash = array(); $ihash = explode("','", $infohash); $info_hash = ""; foreach ($ihash as $myihash) { $info_hash .= "&info_hash=" . escapeURL($myihash); } $info_hash = substr($info_hash, 1); $fd = fopen($extannunce . ($infohash != "" ? "?{$info_hash}" : ""), "rb"); if ($fd) { while (!feof($fd)) { $stream .= fread($fd, 4096); if (strlen($stream) > 100000) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (response too big)", ""); @fclose($fd); return; } } } else { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not connectable)", ""); return; } } $array = bencdec::decode($stream); if (!isset($array)) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not bencode data)", ""); return; } if ($array == false) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not bencode data)", ""); return; } if (!isset($array["files"])) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " torrent from " . $url . " tracker (not bencode data)", ""); return; } $files = $array["files"]; if (!is_array($files)) { $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')")); write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (probably deleted torrent(s))", ""); return; } foreach ($files as $hash => $data) { $seeders = (int) $data["complete"]; $leechers = (int) $data["incomplete"]; if (isset($data["downloaded"])) { $completed = (int) $data["downloaded"]; } else { $completed = "0"; } $torrenthash = bin2hex(stripslashes($hash)); $ret = $db->query("UPDATE namemap SET lastupdate = NOW(), lastsuccess = NOW() WHERE announce_url = '" . $url . "'" . ($hash == "" ? "" : " AND namemap.info_hash = '" . $torrenthash . "'")); $ret = $db->query("UPDATE summary INNER JOIN namemap ON namemap.info_hash = summary.info_hash SET summary.seeds = " . $seeders . ", summary.leechers = " . $leechers . ", summary.finished = " . $completed . " WHERE summary.info_hash = '" . $torrenthash . "' AND namemap.announce_url = '" . $url . "'"); if ($db->affected_rows == 1) { write_log("SUCCESS update external torrent from " . $url . " tracker (infohash: " . $torrenthash . ")", ""); } } } }
function getCategoryLinkById($blogid, $id) { if ($id === null || $id === 0) { return ''; } $result = getCategoryNameById($blogid, $id); if ($children = getParentCategoryId($blogid, $id)) { $result = rawurlencode(htmlspecialchars(escapeURL(getCategoryNameById($blogid, $children)))) . '/' . rawurlencode(htmlspecialchars(escapeURL($result))); } else { $result = rawurlencode(htmlspecialchars(escapeURL($result))); } return $result; }