function makeRequest($request, $useAlt = false)
 {
     $refererURI = isset($_SESSION['lastOutBoundURI']) ? $_SESSION['lastOutBoundURI'] : "http://" . $this->mainURL;
     $request = $useAlt ? "http://" . $this->altURL . $request : "http://" . $this->mainURL . $request;
     // require SimpleHTTP
     require_once "inc/classes/SimpleHTTP.php";
     // get data
     $this->htmlPage = SimpleHTTP::getData($request, $refererURI);
     // return
     return SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK;
 }
/**
 * (internal) Function with which metafiles are downloaded and injected
 *
 * @param $url url to download
 * @param $type
 */
function _dispatcher_processDownload($url, $type = 'torrent', $ext = '.torrent')
{
    global $cfg;
    $filename = "";
    $downloadMessages = array();
    if (!empty($url)) {
        $arURL = explode("/", $url);
        $filename = urldecode($arURL[count($arURL) - 1]);
        // get the file name
        $filename = str_replace(array("'", ","), "", $filename);
        $filename = stripslashes($filename);
        // Check to see if url has something like ?passkey=12345
        // If so remove it.
        if (($point = strrpos($filename, "?")) !== false) {
            $filename = substr($filename, 0, $point);
        }
        $ret = strrpos($filename, ".");
        if ($ret === false) {
            $filename .= $ext;
        } else {
            if (!strcmp(strtolower(substr($filename, -strlen($ext))), $ext) == 0) {
                $filename .= $ext;
            }
        }
        $url = str_replace(" ", "%20", $url);
        // This is to support Sites that pass an id along with the url for downloads.
        $tmpId = tfb_getRequestVar("id");
        if (!empty($tmpId)) {
            $url .= "&id=" . $tmpId;
        }
        // retrieve the file
        require_once "inc/classes/SimpleHTTP.php";
        $content = "";
        switch ($type) {
            default:
            case 'torrent':
                $content = SimpleHTTP::getTorrent($url);
                break;
            case 'nzb':
                $content = SimpleHTTP::getNzb($url);
                break;
        }
        if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK && strlen($content) > 0) {
            $fileNameBackup = $filename;
            $filename = SimpleHTTP::getFilename();
            if ($filename != "") {
                $filename = strpos($filename, $ext) !== false ? tfb_cleanFileName($filename) : tfb_cleanFileName($filename . $ext);
            }
            if ($filename == "" || $filename === false || transferExists($filename)) {
                $filename = tfb_cleanFileName($fileNameBackup);
                if ($filename === false || transferExists($filename)) {
                    $filename = tfb_cleanFileName($url . $ext);
                    if ($filename === false || transferExists($filename)) {
                        $filename = tfb_cleanFileName(md5($url . strval(@microtime())) . $ext);
                        if ($filename === false || transferExists($filename)) {
                            // Error
                            array_push($downloadMessages, "failed to get a valid transfer-filename for " . $url);
                        }
                    }
                }
            }
            if (empty($downloadMessages)) {
                // no messages
                // check if content contains html
                if ($cfg['debuglevel'] > 0) {
                    if (strpos($content, "<br />") !== false) {
                        AuditAction($cfg["constants"]["debug"], "download-content contained html : " . htmlentities(addslashes($url), ENT_QUOTES));
                    }
                }
                if (is_file($cfg["transfer_file_path"] . $filename)) {
                    // Error
                    array_push($downloadMessages, "the file " . $filename . " already exists on the server.");
                } else {
                    // write to file
                    $handle = false;
                    $handle = @fopen($cfg["transfer_file_path"] . $filename, "w");
                    if (!$handle) {
                        array_push($downloadMessages, "cannot open " . $filename . " for writing.");
                    } else {
                        $result = @fwrite($handle, $content);
                        @fclose($handle);
                        if ($result === false) {
                            array_push($downloadMessages, "cannot write content to " . $filename . ".");
                        }
                    }
                }
            }
        } else {
            $msgs = SimpleHTTP::getMessages();
            if (count($msgs) > 0) {
                $downloadMessages = array_merge($downloadMessages, $msgs);
            }
        }
        if (empty($downloadMessages)) {
            // no messages
            AuditAction($cfg["constants"]["url_upload"], $filename);
            // inject
            injectTransfer($filename);
            // instant action ?
            $actionId = tfb_getRequestVar('aid');
            if ($actionId > 1) {
                $ch = ClientHandler::getInstance(getTransferClient($filename));
                switch ($actionId) {
                    case 3:
                        $ch->start($filename, false, true);
                        break;
                    case 2:
                        $ch->start($filename, false, false);
                        break;
                }
                if (count($ch->messages) > 0) {
                    $downloadMessages = array_merge($downloadMessages, $ch->messages);
                }
            }
        }
    } else {
        array_push($downloadMessages, "Invalid Url : " . $url);
    }
    if (count($downloadMessages) > 0) {
        AuditAction($cfg["constants"]["error"], $cfg["constants"]["url_upload"] . " :: " . $filename);
        @error("There were Problems", "", "", $downloadMessages);
    }
}
 /**
  * download and save a torrent-file
  *
  * @return boolean
  */
 function _saveTorrent($url, $title)
 {
     global $cfg;
     $content = SimpleHTTP::getTorrent($url);
     if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK) {
         // filename
         $filename = SimpleHTTP::getFilename();
         if ($filename != "") {
             $filename = strpos($filename, ".torrent") !== false ? tfb_cleanFileName($filename) : tfb_cleanFileName($filename . ".torrent");
         }
         if ($filename == "" || $filename === false || transferExists($filename)) {
             $filename = tfb_cleanFileName($title . ".torrent");
             if ($filename === false || transferExists($filename)) {
                 $filename = tfb_cleanFileName($url . ".torrent");
                 if ($filename === false || transferExists($filename)) {
                     $filename = tfb_cleanFileName(md5($url . strval(@microtime())) . ".torrent");
                     if ($filename === false || transferExists($filename)) {
                         // Error
                         $msg = "failed to get a valid transfer-filename for " . $url;
                         array_push($this->messages, $msg);
                         AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg);
                         $this->_outputError($msg . "\n");
                         return false;
                     }
                 }
             }
         }
         // file
         $file = $this->_dirSave . $filename;
         // check if file already exists
         if (@is_file($file)) {
             // Error
             $msg = "the file " . $file . " already exists in " . $this->_dirSave;
             array_push($this->messages, $msg);
             AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg);
             $this->_outputError($msg . "\n");
             return false;
         }
         // write file
         $handle = false;
         $handle = @fopen($file, "w");
         if (!$handle) {
             $msg = "cannot open " . $file . " for writing.";
             array_push($this->messages, $msg);
             AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg);
             $this->_outputError($msg . "\n");
             return false;
         }
         $result = @fwrite($handle, $content);
         @fclose($handle);
         if ($result === false) {
             $msg = "cannot write content to " . $file . ".";
             array_push($this->messages, $msg);
             AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg);
             $this->_outputError($msg . "\n");
             return false;
         }
         // add to file-array
         array_push($this->_filesSaved, array('url' => $url, 'title' => $title, 'filename' => $filename, 'file' => $file));
         // output
         $this->_outputMessage("torrent saved : \n url: " . $url . "\n file: " . $file . "\n");
         // return
         return true;
     } else {
         // last op was not ok
         $msgs = SimpleHTTP::getMessages();
         $this->_outputError("could not download torrent with title " . $title . " from url " . $url . " : \n" . implode("\n", $msgs));
         return false;
     }
 }
Beispiel #4
0
 function Parse($rss_url)
 {
     // Load RSS file
     require_once "inc/classes/SimpleHTTP.php";
     $rss_content = SimpleHTTP::getData($rss_url);
     if (SimpleHTTP::getState() != SIMPLEHTTP_STATE_OK) {
         // last op was not ok
         // log
         global $cfg;
         $msgs = SimpleHTTP::getMessages();
         AuditAction($cfg["constants"]["error"], "lastRSS: could not download feed-data from url " . $rss_url . " (" . implode("; ", $msgs) . ")");
         // return false
         return false;
     }
     // result-array
     $result = array();
     // document encoding
     $result['encoding'] = $this->my_preg_match("'encoding=[\\'\"](.*?)[\\'\"]'si", $rss_content);
     // if document codepage is specified, use it
     if ($result['encoding'] != '') {
         $this->rsscp = $result['encoding'];
         // This is used in my_preg_match()
     } else {
         // otherwise use the default codepage
         $this->rsscp = $this->default_cp;
         // This is used in my_preg_match()
     }
     // CHANNEL info
     if (preg_match("'<channel.*?>(.*?)</channel>'si", $rss_content, $out_channel)) {
         foreach ($this->_channeltags as $channeltag) {
             $temp = $this->my_preg_match("'<{$channeltag}.*?>(.*?)</{$channeltag}>'si", $out_channel[1]);
             if ($temp != '') {
                 $result[$channeltag] = $temp;
             }
             // Set only if not empty
         }
     }
     // If date_format is specified and lastBuildDate is valid
     if ($this->date_format != '' && ($timestamp = strtotime($result['lastBuildDate'])) !== -1) {
         // convert lastBuildDate to specified date format
         $result['lastBuildDate'] = date($this->date_format, $timestamp);
     }
     // TEXTINPUT info
     preg_match("'<textinput(|[^>]*[^/])>(.*?)</textinput>'si", $rss_content, $out_textinfo);
     // This a little strange regexp means:
     // Look for tag <textinput> with or without any attributes, but skip truncated version <textinput /> (it's not beginning tag)
     if (isset($out_textinfo[2])) {
         foreach ($this->_textinputtags as $textinputtag) {
             $temp = $this->my_preg_match("'<{$textinputtag}.*?>(.*?)</{$textinputtag}>'si", $out_textinfo[2]);
             if ($temp != '') {
                 $result['textinput_' . $textinputtag] = $temp;
             }
             // Set only if not empty
         }
     }
     // IMAGE info
     preg_match("'<image.*?>(.*?)</image>'si", $rss_content, $out_imageinfo);
     if (isset($out_imageinfo[1])) {
         foreach ($this->_imagetags as $imagetag) {
             $temp = $this->my_preg_match("'<{$imagetag}.*?>(.*?)</{$imagetag}>'si", $out_imageinfo[1]);
             if ($temp != '') {
                 $result['image_' . $imagetag] = $temp;
             }
             // Set only if not empty
         }
     }
     // ITEMS
     preg_match_all("'<item(| .*?)>(.*?)</item>'si", $rss_content, $items);
     $rss_items = $items[2];
     $i = 0;
     $result['items'] = array();
     // create array even if there are no items
     foreach ($rss_items as $rss_item) {
         // If number of items is lower then limit: parse one item
         if ($i < $this->items_limit || $this->items_limit == 0) {
             foreach ($this->_itemtags as $itemtag) {
                 $temp = $this->my_preg_match("'<{$itemtag}.*?>(.*?)</{$itemtag}>'si", $rss_item);
                 if ($temp != '') {
                     $result['items'][$i][$itemtag] = $temp;
                 }
                 // Set only if not empty
             }
             // Strip HTML tags and other bullshit from DESCRIPTION
             if ($this->stripHTML && $result['items'][$i]['description']) {
                 $result['items'][$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['description'])));
             }
             // Strip HTML tags and other bullshit from TITLE
             if ($this->stripHTML && $result['items'][$i]['title']) {
                 $result['items'][$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['title'])));
             }
             // If date_format is specified and pubDate is valid
             if ($this->date_format != '' && ($timestamp = strtotime($result['items'][$i]['pubDate'])) !== -1) {
                 // convert pubDate to specified date format
                 $result['items'][$i]['pubDate'] = date($this->date_format, $timestamp);
             }
             // Item counter
             $i++;
         }
     }
     $result['items_count'] = $i;
     return $result;
 }
Beispiel #5
0
function _dir_WgetFile($url, $target_dir)
{
    require_once 'inc/functions/functions.core.tfb.php';
    global $cfg;
    $filename = "";
    $downloadMessages = array();
    if (!empty($url)) {
        $arURL = explode("/", $url);
        $filename = urldecode($arURL[count($arURL) - 1]);
        // get the file name
        $filename = str_replace(array("'", ","), "", $filename);
        $filename = stripslashes($filename);
        // Check to see if url has something like ?passkey=12345
        // If so remove it.
        if (($point = strrpos($filename, "?")) !== false) {
            $filename = substr($filename, 0, $point);
        }
        $ret = strrpos($filename, ".");
        $url = str_replace(" ", "%20", $url);
        // This is to support Sites that pass an id along with the url for downloads.
        $tmpId = tfb_getRequestVar("id");
        if (!empty($tmpId)) {
            $url .= "&id=" . $tmpId;
        }
        // retrieve the file
        require_once "inc/classes/SimpleHTTP.php";
        $content = SimpleHTTP::getData($url);
        if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK && strlen($content) > 0) {
            $fileNameBackup = $filename;
            $filename = SimpleHTTP::getFilename();
            if ($filename != "") {
                $filename = _dir_cleanFileName($filename);
            }
            if ($filename == "" || $filename === false) {
                $filename = _dir_cleanFileName($fileNameBackup);
                if ($filename === false || $filename == "") {
                    $filename = _dir_cleanFileName(SimpleHTTP::getRealUrl($url));
                    if ($filename === false || $filename == "") {
                        $filename = _dir_cleanFileName(md5($url . strval(@microtime())));
                        if ($filename === false || $filename == "") {
                            // Error
                            array_push($downloadMessages, "failed to get a valid filename for " . $url);
                        }
                    }
                }
            }
            if (empty($downloadMessages)) {
                // no messages
                // check if content contains html
                if ($cfg['debuglevel'] > 0) {
                    if (strpos($content, "<br />") !== false) {
                        AuditAction($cfg["constants"]["debug"], "download-content contained html : " . htmlentities(addslashes($url), ENT_QUOTES));
                    }
                }
                if (is_file($target_dir . $filename)) {
                    // Error
                    array_push($downloadMessages, "the file " . $filename . " already exists on the server.");
                } else {
                    // write to file
                    $handle = false;
                    $handle = @fopen($target_dir . $filename, "w");
                    if (!$handle) {
                        array_push($downloadMessages, "cannot open " . $target_dir . $filename . " for writing.");
                    } else {
                        $result = @fwrite($handle, $content);
                        @fclose($handle);
                        if ($result === false) {
                            array_push($downloadMessages, "cannot write content to " . $filename . ".");
                        }
                    }
                }
            }
        } else {
            $msgs = SimpleHTTP::getMessages();
            if (count($msgs) > 0) {
                $downloadMessages = array_merge($downloadMessages, $msgs);
            }
        }
        if (empty($downloadMessages)) {
            // no messages
            AuditAction($cfg["constants"]["url_upload"], $filename);
        }
    } else {
        array_push($downloadMessages, "Invalid Url : " . $url);
    }
    if (count($downloadMessages) > 0) {
        AuditAction($cfg["constants"]["error"], $cfg["constants"]["url_upload"] . " :: " . $filename);
        @error("There were Problems", "", "", $downloadMessages);
    }
}
/**
 * (internal) Function with which metafiles are downloaded and injected
 *
 * @param $url url to download
 * @param $type
 */
function _dispatcher_processDownload($url, $type = 'torrent', $ext = '.torrent')
{
    global $cfg;
    $filename = "";
    $downloadMessages = array();
    $origurl = $url;
    // Added by deadeyes; copied as later $url gets changed
    if (!empty($url)) {
        $hash = false;
        // Added by deadeyes to detect a magnet link
        if ($type === 'torrent' && strlen(stristr($url, 'magnet:')) > 0) {
            $client = getTransferClient('magnet.torrent');
            // We have a magnet link :D
            if ($client == 'transmissionrpc' && $cfg["transmission_rpc_enable"]) {
                require_once 'inc/functions/functions.rpc.transmission.php';
                $hash = addTransmissionTransfer($cfg['uid'], $url, $cfg['path'] . $cfg['user']);
                if (isHash($hash)) {
                    startTransmissionTransfer($hash);
                }
            }
            if (($client == 'vuzerpc' || $client == 'azureus') && $cfg["vuze_rpc_enable"]) {
                require_once 'inc/functions/functions.rpc.vuze.php';
                $hash = addVuzeMagnetTransfer($cfg['uid'], $url, $cfg['transfer_file_path']);
            }
            if ($cfg['debuglevel'] > 0) {
                AuditAction($cfg["constants"]["debug"], "Download Magnet ({$client}) : {$hash} " . htmlentities(addslashes($url), ENT_QUOTES));
            }
        }
        if (!$hash) {
            // not a magnet torrent..
            $arURL = explode("/", $url);
            $filename = urldecode($arURL[count($arURL) - 1]);
            // get the file name
            $filename = str_replace(array("'", ","), "", $filename);
            $filename = stripslashes($filename);
            // Check to see if url has something like ?passkey=12345
            // If so remove it.
            if (($point = strrpos($filename, "?")) !== false) {
                $filename = substr($filename, 0, $point);
            }
            $ret = strrpos($filename, ".");
            if ($ret === false) {
                $filename .= $ext;
            } else {
                if (!strcmp(strtolower(substr($filename, -strlen($ext))), $ext) == 0) {
                    $filename .= $ext;
                }
            }
            $url = str_replace(" ", "%20", $url);
            // This is to support Sites that pass an id along with the url for downloads.
            $tmpId = tfb_getRequestVar("id");
            if (!empty($tmpId)) {
                $url .= "&id=" . $tmpId;
            }
            // retrieve the file
            require_once "inc/classes/SimpleHTTP.php";
            $content = "";
            switch ($type) {
                default:
                case 'torrent':
                    $content = SimpleHTTP::getTorrent($url);
                    break;
                case 'nzb':
                    $content = SimpleHTTP::getNzb($url);
                    break;
            }
            if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK && strlen($content) > 0) {
                $fileNameBackup = $filename;
                $filename = SimpleHTTP::getFilename();
                if ($filename != "") {
                    $filename = strpos($filename, $ext) !== false ? tfb_cleanFileName($filename) : tfb_cleanFileName($filename . $ext);
                }
                if (empty($filename) || transferExists($filename)) {
                    $filename = substr($cfg['user'], 0, 3) . "_" . date('ymdHis') . "_" . sprintf('%x', crc32($filename)) . $ext;
                }
                /*
                if (($filename == "") || ($filename === false) || (transferExists($filename))) {
                	$filename = tfb_cleanFileName($fileNameBackup);
                	if (($filename === false) || (transferExists($filename))) {
                		$filename = tfb_cleanFileName($url.$ext);
                		if (($filename === false) || (transferExists($filename))) {
                			$filename = tfb_cleanFileName(md5($url.strval(@microtime())).$ext);
                			if (($filename === false) || (transferExists($filename))) {
                				// Error
                				array_push($downloadMessages , "failed to get a valid transfer-filename for ".$url);
                			}
                		}
                	}
                }
                */
                if (empty($downloadMessages)) {
                    // no messages
                    // check if content contains html
                    if ($cfg['debuglevel'] > 0) {
                        if (strpos($content, "<br />") !== false) {
                            AuditAction($cfg["constants"]["debug"], "download-content contained html : " . htmlentities(addslashes($url), ENT_QUOTES));
                        }
                    }
                    if (is_file($cfg["transfer_file_path"] . $filename)) {
                        // Error
                        array_push($downloadMessages, "the file " . $filename . " already exists on the server.");
                    } else {
                        // write to file
                        $handle = false;
                        $handle = @fopen($cfg["transfer_file_path"] . $filename, "w");
                        if (!$handle) {
                            array_push($downloadMessages, "cannot open " . $filename . " for writing.");
                        } else {
                            $result = @fwrite($handle, $content);
                            @fclose($handle);
                            if ($result === false) {
                                array_push($downloadMessages, "cannot write content to " . $filename . ".");
                            }
                        }
                    }
                }
            } else {
                $msgs = SimpleHTTP::getMessages();
                if (count($msgs) > 0) {
                    $downloadMessages = array_merge($downloadMessages, $msgs);
                }
            }
            if (empty($downloadMessages) && is_file($cfg["transfer_file_path"] . $filename)) {
                // no messages
                AuditAction($cfg["constants"]["url_upload"], $filename);
                // inject
                injectTransfer($filename);
                // instant action ?
                $actionId = tfb_getRequestVar('aid');
                if ($actionId > 1) {
                    $ch = ClientHandler::getInstance(getTransferClient($filename));
                    switch ($actionId) {
                        case 3:
                            $ch->start($filename, false, true);
                            break;
                        case 2:
                            $ch->start($filename, false, false);
                            break;
                    }
                    if (count($ch->messages) > 0) {
                        $downloadMessages = array_merge($downloadMessages, $ch->messages);
                    }
                }
            }
        }
    } else {
        array_push($downloadMessages, "Invalid Url : " . $url);
    }
    if (count($downloadMessages) > 0) {
        AuditAction($cfg["constants"]["error"], $cfg["constants"]["url_upload"] . " :: " . $filename);
        @error("There were Problems", "", "", $downloadMessages);
    }
}