예제 #1
0
 /**
  * Decompress a NZB, load it into simplexml and return.
  *
  * @param string $guid Release guid.
  *
  * @return bool|\SimpleXMLElement
  *
  * @access public
  */
 public function LoadNZB($guid)
 {
     // Fetch the NZB location using the GUID.
     $nzbPath = $this->nzb->NZBPath($guid);
     if ($nzbPath === false) {
         if ($this->echooutput) {
             echo PHP_EOL . $guid . ' appears to be missing the nzb file, skipping.' . PHP_EOL;
         }
         return false;
     }
     $nzbContents = Utility::unzipGzipFile($nzbPath);
     if (!$nzbContents) {
         if ($this->echooutput) {
             echo PHP_EOL . 'Unable to decompress: ' . $nzbPath . ' - ' . fileperms($nzbPath) . ' - may have bad file permissions, skipping.' . PHP_EOL;
         }
         return false;
     }
     $nzbFile = @simplexml_load_string($nzbContents);
     if (!$nzbFile) {
         if ($this->echooutput) {
             echo PHP_EOL . "Unable to load NZB: {$guid} appears to be an invalid NZB, skipping." . PHP_EOL;
         }
         return false;
     }
     return $nzbFile;
 }
예제 #2
0
파일: NZBGet.php 프로젝트: sebst3r/nZEDb
    /**
     * Send a NZB to NZBGet.
     *
     * @param string $guid Release identifier.
     *
     * @return bool|mixed
     *
     * @access public
     */
    public function sendNZBToNZBGet($guid)
    {
        $relData = $this->Releases->getByGuid($guid);
        $string = Utility::unzipGzipFile($this->NZB->getNZBPath($guid));
        $string = $string === false ? '' : $string;
        $encoded = base64_encode($string);
        $header = <<<NZBGet_NZB
<?xml version="1.0"?>
<methodCall>
\t<methodName>append</methodName>
\t<params>
\t\t<param>
\t\t\t<value><string>{$relData['searchname']}</string></value>
\t\t</param>
\t\t<param>
\t\t\t<value><string>{$relData['category_name']}</string></value>
\t\t</param>
\t\t<param>
\t\t\t<value><i4>0</i4></value>
\t\t</param>
\t\t<param>
\t\t\t<value><boolean>>False</boolean></value>
\t\t</param>
\t\t<param>
\t\t\t<value>
\t\t\t\t<string>
{$encoded}
\t\t\t\t</string>
\t\t\t</value>
\t\t</param>
\t</params>
</methodCall>
NZBGet_NZB;
        Utility::getUrl(['url' => $this->fullURL . 'append', 'method' => 'post', 'postdata' => $header, 'verifycert' => false]);
    }
예제 #3
0
 /**
  * Create NZB files from complete releases.
  *
  * @param int|string $groupID (optional)
  *
  * @return int
  * @access public
  */
 public function createNZBs($groupID)
 {
     $startTime = time();
     if ($this->echoCLI) {
         $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Create the NZB, delete collections/binaries/parts."));
     }
     $releases = $this->pdo->queryDirect(sprintf("\n\t\t\t\tSELECT SQL_NO_CACHE CONCAT(COALESCE(cp.title,'') , CASE WHEN cp.title IS NULL THEN '' ELSE ' > ' END , c.title) AS title,\n\t\t\t\t\tr.name, r.id, r.guid\n\t\t\t\tFROM releases r\n\t\t\t\tINNER JOIN category c ON r.categoryid = c.id\n\t\t\t\tINNER JOIN category cp ON cp.id = c.parentid\n\t\t\t\tWHERE %s nzbstatus = 0", !empty($groupID) ? ' r.group_id = ' . $groupID . ' AND ' : ' '));
     $nzbCount = 0;
     if ($releases && $releases->rowCount()) {
         $total = $releases->rowCount();
         // Init vars for writing the NZB's.
         $this->nzb->initiateForWrite($groupID);
         foreach ($releases as $release) {
             if ($this->nzb->writeNZBforReleaseId($release['id'], $release['guid'], $release['name'], $release['title']) === true) {
                 $nzbCount++;
                 if ($this->echoCLI) {
                     echo $this->pdo->log->primaryOver("Creating NZBs and deleting Collections:\t" . $nzbCount . '/' . $total . "\r");
                 }
             }
         }
     }
     $totalTime = time() - $startTime;
     if ($this->echoCLI) {
         $this->pdo->log->doEcho($this->pdo->log->primary(number_format($nzbCount) . ' NZBs created/Collections deleted in ' . $totalTime . ' seconds.' . PHP_EOL . 'Total time: ' . $this->pdo->log->primary($this->consoleTools->convertTime($totalTime)) . PHP_EOL));
     }
     return $nzbCount;
 }
예제 #4
0
 /**
  * Get list of contents inside a release's NZB file.
  *
  * @return bool
  */
 protected function _getNZBContents()
 {
     $nzbPath = $this->_nzb->NZBPath($this->_release['guid']);
     if ($nzbPath === false) {
         $this->_echo('NZB not found for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     $nzbContents = Misc::unzipGzipFile($nzbPath);
     if (!$nzbContents) {
         $this->_echo('NZB is empty or broken for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     // Get a list of files in the nzb.
     $this->_nzbContents = $this->_nzb->nzbFileList($nzbContents, ['no-file-key' => false, 'strip-count' => true]);
     if (count($this->_nzbContents) === 0) {
         $this->_echo('NZB is potentially broken for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     // Sort keys.
     ksort($this->_nzbContents, SORT_NATURAL);
     return true;
 }
예제 #5
0
 /**
  * Get list of contents inside a release's NZB file.
  *
  * @return bool
  */
 protected function _getNZBContents()
 {
     $nzbPath = $this->_nzb->NZBPath($this->_release['guid']);
     if ($nzbPath === false) {
         $this->_echo('NZB not found for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     $nzbContents = Utility::unzipGzipFile($nzbPath);
     if (!$nzbContents) {
         $this->_echo('NZB is empty or broken for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     // Get a list of files in the nzb.
     $this->_nzbContents = $this->_nzb->nzbFileList($nzbContents);
     if (count($this->_nzbContents) === 0) {
         $this->_echo('NZB is potentially broken for GUID: ' . $this->_release['guid'], 'warning');
         return $this->_decrementPasswordStatus();
     }
     // Sort the files inside the NZB.
     usort($this->_nzbContents, ['\\nzedb\\processing\\post\\ProcessAdditional', '_sortNZB']);
     return true;
 }
예제 #6
0
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\ConsoleTools;
use nzedb\NZB;
use nzedb\ReleaseImage;
use nzedb\Releases;
use nzedb\db\Settings;
$pdo = new Settings();
if ($argc < 3 || !isset($argv[1]) || isset($argv[1]) && !is_numeric($argv[1])) {
    exit($pdo->log->error("\nIncorrect argument suppplied. This script will delete all duplicate releases matching on name, fromname, group_id and size.\n" . "Unfortunately, I can not guarantee which copy will be deleted.\n\n" . "php remove_exact_dupes.php 10 exact             ...: To delete all duplicates added within the last 10 hours.\n" . "php remove_exact_dupes.php 10 near              ...: To delete all duplicates with size variation of 1% and added within the last 10 hours.\n" . "php remove_exact_dupes.php 0 exact              ...: To delete all duplicates.\n" . "php remove_exact_dupes.php 0 near               ...: To delete all duplicates with size variation of 1%.\n" . "php remove_exact_dupes.php 10 exact dupes/      ...: To delete all duplicates added within the last 10 hours and save a copy of the nzb to dupes folder.\n"));
}
$crosspostt = $argv[1];
$releases = new Releases(['Settings' => $pdo]);
$count = $total = $all = 0;
$nzb = new NZB($pdo);
$ri = new ReleaseImage($pdo);
$consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$size = ' size ';
if ($argv[2] === 'near') {
    $size = ' size between (size *.99) AND (size * 1.01) ';
}
if ($crosspostt != 0) {
    $query = sprintf('SELECT max(id) AS id, id AS idx, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name, fromname, group_id,' . $size . 'HAVING COUNT(*) > 1', $crosspostt);
} else {
    $query = sprintf('SELECT max(id) AS id, id AS idx, guid FROM releases GROUP BY name, fromname, group_id,' . $size . 'HAVING COUNT(*) > 1');
}
do {
    $resrel = $pdo->queryDirect($query);
    if ($resrel instanceof \Traversable) {
        $total = $resrel->rowCount();
예제 #7
0
파일: Releases.php 프로젝트: sebst3r/nZEDb
 /**
  * @param $guids
  *
  * @return string
  */
 public function getZipped($guids)
 {
     $nzb = new NZB($this->pdo);
     $zipFile = new \ZipFile();
     foreach ($guids as $guid) {
         $nzbPath = $nzb->NZBPath($guid);
         if ($nzbPath) {
             $nzbContents = Utility::unzipGzipFile($nzbPath);
             if ($nzbContents) {
                 $filename = $guid;
                 $r = $this->getByGuid($guid);
                 if ($r) {
                     $filename = $r['searchname'];
                 }
                 $zipFile->addFile($nzbContents, $filename . '.nzb');
             }
         }
     }
     return $zipFile->file();
 }
예제 #8
0
파일: NZBExport.php 프로젝트: sebst3r/nZEDb
 /**
  * Export to user specified folder.
  *
  * @param array $params
  *
  * @return bool
  *
  * @access public
  */
 public function beginExport($params)
 {
     $gzip = false;
     if ($params[4] === true) {
         $gzip = true;
     }
     $fromDate = $toDate = '';
     $path = $params[0];
     // Check if the path ends with dir separator.
     if (substr($path, -1) !== DS) {
         $path .= DS;
     }
     // Check if it's a directory.
     if (!is_dir($path)) {
         $this->echoOut('Folder does not exist: ' . $path);
         return $this->returnValue();
     }
     // Check if we can write to it.
     if (!is_writable($path)) {
         $this->echoOut('Folder is not writable: ' . $path);
         return $this->returnValue();
     }
     // Check if the from date is the proper format.
     if (isset($params[1]) && $params[1] !== '') {
         if (!$this->checkDate($params[1])) {
             return $this->returnValue();
         }
         $fromDate = $params[1];
     }
     // Check if the to date is the proper format.
     if (isset($params[2]) && $params[2] !== '') {
         if (!$this->checkDate($params[2])) {
             return $this->returnValue();
         }
         $toDate = $params[2];
     }
     // Check if the group_id exists.
     if (isset($params[3]) && $params[3] !== 0) {
         if (!is_numeric($params[3])) {
             $this->echoOut('The group ID is not a number: ' . $params[3]);
             return $this->returnValue();
         }
         $groups = $this->pdo->query('SELECT id, name FROM groups WHERE id = ' . $params[3]);
         if (count($groups) === 0) {
             $this->echoOut('The group ID is not in the DB: ' . $params[3]);
             return $this->returnValue();
         }
     } else {
         $groups = $this->pdo->query('SELECT id, name FROM groups');
     }
     $exported = 0;
     // Loop over groups to take less RAM.
     foreach ($groups as $group) {
         $currentExport = 0;
         // Get all the releases based on the parameters.
         $releases = $this->releases->getForExport($fromDate, $toDate, $group['id']);
         $totalFound = count($releases);
         if ($totalFound === 0) {
             if ($this->echoCLI) {
                 echo 'No releases found to export for group: ' . $group['name'] . PHP_EOL;
             }
             continue;
         }
         if ($this->echoCLI) {
             echo 'Found ' . $totalFound . ' releases to export for group: ' . $group['name'] . PHP_EOL;
         }
         // Create a path to store the new NZB files.
         $currentPath = $path . $this->safeFilename($group['name']) . DS;
         if (!is_dir($currentPath)) {
             mkdir($currentPath);
         }
         foreach ($releases as $release) {
             // Get path to the NZB file.
             $nzbFile = $this->nzb->NZBPath($release["guid"]);
             // Check if it exists.
             if ($nzbFile === false) {
                 if ($this->echoCLI) {
                     echo 'Unable to find NZB for release with GUID: ' . $release['guid'];
                 }
                 continue;
             }
             // Create path to current file.
             $currentFile = $currentPath . $this->safeFilename($release['searchname']);
             // Check if the user wants them in gzip, copy it if so.
             if ($gzip) {
                 if (!copy($nzbFile, $currentFile . '.nzb.gz')) {
                     if ($this->echoCLI) {
                         echo 'Unable to export NZB with GUID: ' . $release['guid'];
                     }
                     continue;
                 }
                 // If not, decompress it and create a file to store it in.
             } else {
                 $nzbContents = Utility::unzipGzipFile($nzbFile);
                 if (!$nzbContents) {
                     if ($this->echoCLI) {
                         echo 'Unable to export NZB with GUID: ' . $release['guid'];
                     }
                     continue;
                 }
                 $fh = fopen($currentFile . '.nzb', 'w');
                 fwrite($fh, $nzbContents);
                 fclose($fh);
             }
             $currentExport++;
             if ($this->echoCLI && $currentExport % 10 === 0) {
                 echo 'Exported ' . $currentExport . ' of ' . $totalFound . ' nzbs for group: ' . $group['name'] . "\r";
             }
         }
         if ($this->echoCLI && $currentExport > 0) {
             echo 'Exported ' . $currentExport . ' of ' . $totalFound . ' nzbs for group: ' . $group['name'] . PHP_EOL;
         }
         $exported += $currentExport;
     }
     if ($exported > 0) {
         $this->echoOut('Exported total of ' . $exported . ' NZB files to ' . $path);
     }
     return $this->returnValue();
 }
예제 #9
0
<?php

/* Fixes NZB files with a blank first line. */
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\NZB;
use nzedb\db\Settings;
$pdo = new Settings();
if (isset($argv[1]) && $argv[1] == "true") {
    $timestart = time();
    $nzbcount = $brokencount = 0;
    $guids = $pdo->queryDirect("SELECT guid FROM releases WHERE nzbstatus = 1 ORDER BY postdate DESC");
    echo $pdo->log->primary("Be patient, this WILL take a very long time, make sure to kill all nZEDb scripts first. There are " . number_format($guids->rowCount()) . " NZB files to scan.");
    $nzb = new NZB($pdo);
    if ($guids instanceof \Traversable) {
        foreach ($guids as $guid) {
            $nzbpath = $nzb->NZBPath($guid["guid"]);
            if ($nzbpath !== false) {
                $nzbcount++;
                $nzbfile = nzedb\utility\Misc::unzipGzipFile($nzbpath);
                if ($nzbfile && preg_match('/^[\\r\\n]+<\\?xml/', $nzbfile)) {
                    $brokencount++;
                    $nzbfile = preg_replace('/^[\\r\\n]+<\\?xml/i', '<?xml', $nzbfile);
                    $nzb = preg_replace('/<\\/nzb>.+/i', '</nzb>', $nzbfile);
                    unlink($nzbpath);
                    $fp = gzopen($nzbpath, 'w6');
                    if ($fp) {
                        gzwrite($fp, $nzb, strlen($nzb));
                        gzclose($fp);
                        chmod($nzbpath, 0777);
                    }
                }
예제 #10
0
파일: filelist.php 프로젝트: sebst3r/nZEDb
<?php

use nzedb\NZB;
use nzedb\Releases;
use nzedb\utility\Utility;
if (!$page->users->isLoggedIn()) {
    $page->show403();
}
if (isset($_GET["id"])) {
    $releases = new Releases(['Settings' => $page->settings]);
    $rel = $releases->getByGuid($_GET["id"]);
    if (!$rel) {
        $page->show404();
    }
    $nzb = new NZB($page->settings);
    $nzbpath = $nzb->getNZBPath($_GET["id"]);
    if (!file_exists($nzbpath)) {
        $page->show404();
    }
    $nzbfile = Utility::unzipGzipFile($nzbpath);
    $ret = $nzb->nzbFileList($nzbfile);
    $offset = isset($_REQUEST["offset"]) && ctype_digit($_REQUEST['offset']) ? $_REQUEST["offset"] : 0;
    $page->smarty->assign('pagertotalitems', sizeof($ret));
    $page->smarty->assign('pageroffset', $offset);
    $page->smarty->assign('pageritemsperpage', ITEMS_PER_PAGE);
    $page->smarty->assign('pagerquerybase', WWW_TOP . "/filelist/" . $_GET["id"] . "/&amp;offset=");
    $page->smarty->assign('pagerquerysuffix', "#results");
    $pager = $page->smarty->fetch("pager.tpl");
    $page->smarty->assign('pager', $pager);
    $page->smarty->assign('rel', $rel);
    $page->smarty->assign('files', array_slice($ret, $offset, ITEMS_PER_PAGE));
예제 #11
0
파일: nzb-reorg.php 프로젝트: kaibosh/nZEDb
<?php

require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\ConsoleTools;
use nzedb\NZB;
use nzedb\db\Settings;
if (!isset($argv[1]) || !isset($argv[2])) {
    exit("ERROR: You must supply the level you want to reorganize it to, and the source directory  (You would use: 3 .../nZEDb/resources/nzb/ to move it to 3 levels deep)\n");
}
$pdo = new Settings();
$nzb = new NZB($pdo);
$consoleTools = new ConsoleTools();
$newLevel = $argv[1];
$sourcePath = $argv[2];
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourcePath));
$filestoprocess = [];
$iFilesProcessed = $iFilesCounted = 0;
$time = TIME();
echo "\nReorganizing files to Level {$newLevel} from: {$sourcePath} This could take a while...\n";
//$consoleTools = new \ConsoleTools();
foreach ($objects as $filestoprocess => $nzbFile) {
    if ($nzbFile->getExtension() != "gz") {
        continue;
    }
    $newFileName = $nzb->getNZBPath(str_replace(".nzb.gz", "", $nzbFile->getBasename()), $newLevel, true);
    if ($newFileName != $nzbFile) {
        rename($nzbFile, $newFileName);
        chmod($newFileName, 0777);
    }
    $iFilesProcessed++;
    if ($iFilesProcessed % 100 == 0) {
예제 #12
0
/**
 * Compress an imported NZB and store it inside the nzbfiles folder.
 *
 * @param string $relguid    The guid of the release.
 * @param string $nzb        String containing the imported NZB.
 * @param NZB    $NZB
 * @param object $pdo
 *
 * @return bool
 *
 */
function copyNZBforImport($relguid, $nzb, $NZB, $pdo)
{
    $path = $NZB->getNZBPath($relguid, 0, true);
    $fp = gzopen($path, 'w5');
    if ($fp && $nzb) {
        $date1 = htmlspecialchars(date('F j, Y, g:i a O'), ENT_QUOTES, 'utf-8');
        $article = preg_replace('/dtd">\\s*<nzb xmlns=/', "dtd\">\n<!-- NZB Generated by: nZEDb " . $pdo->version() . ' ' . $date1 . " -->\n<nzb xmlns=", $nzb);
        gzwrite($fp, preg_replace('/<\\/file>\\s*(<!--.+)?\\s*<\\/nzb>\\s*/si', "</file>\n  <!--GrabNZBs-->\n</nzb>", $article));
        gzclose($fp);
        // Chmod to fix issues some users have with file permissions.
        chmod($path, 0777);
        return true;
    } else {
        echo "ERROR: NZB already exists?\n";
        return false;
    }
}
예제 #13
0
function create_guids($live, $delete = false)
{
    $pdo = new Settings();
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $timestart = TIME();
    $relcount = $deleted = $total = 0;
    $relrecs = false;
    if ($live == "true") {
        $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC"));
    } else {
        if ($live == "limited") {
            $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC LIMIT 10000"));
        }
    }
    if ($relrecs) {
        $total = $relrecs->rowCount();
    }
    if ($total > 0) {
        echo $pdo->log->header("Creating nzb_guids for " . number_format($total) . " releases.");
        $releases = new Releases(['Settings' => $pdo]);
        $nzb = new NZB($pdo);
        $releaseImage = new ReleaseImage($pdo);
        $reccnt = 0;
        if ($relrecs instanceof \Traversable) {
            foreach ($relrecs as $relrec) {
                $reccnt++;
                $nzbpath = $nzb->NZBPath($relrec['guid']);
                if ($nzbpath !== false) {
                    $nzbfile = Utility::unzipGzipFile($nzbpath);
                    if ($nzbfile) {
                        $nzbfile = @simplexml_load_string($nzbfile);
                    }
                    if (!$nzbfile) {
                        if (isset($delete) && $delete == 'delete') {
                            //echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n";
                            $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                            $deleted++;
                        }
                        continue;
                    }
                    $binary_names = array();
                    foreach ($nzbfile->file as $file) {
                        $binary_names[] = $file["subject"];
                    }
                    if (count($binary_names) == 0) {
                        if (isset($delete) && $delete == 'delete') {
                            //echo "\n".$nzb->NZBPath($relrec['guid'])." has no binaries, deleting release.\n";
                            $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                            $deleted++;
                        }
                        continue;
                    }
                    asort($binary_names);
                    foreach ($nzbfile->file as $file) {
                        if ($file["subject"] == $binary_names[0]) {
                            $segment = $file->segments->segment;
                            $nzb_guid = md5($segment);
                            $pdo->queryExec("UPDATE releases set nzb_guid = " . $pdo->escapestring($nzb_guid) . " WHERE id = " . $relrec["id"]);
                            $relcount++;
                            $consoletools->overWritePrimary("Created: [" . $deleted . "] " . $consoletools->percentString($reccnt, $total) . " Time:" . $consoletools->convertTimer(TIME() - $timestart));
                            break;
                        }
                    }
                } else {
                    if (isset($delete) && $delete == 'delete') {
                        //echo $pdo->log->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting.");
                        $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage);
                    }
                }
            }
        }
        if ($relcount > 0) {
            echo "\n";
        }
        echo $pdo->log->header("Updated " . $relcount . " release(s). This script ran for " . $consoletools->convertTime(TIME() - $timestart));
    } else {
        echo $pdo->log->info('Query time: ' . $consoletools->convertTime(TIME() - $timestart));
        exit($pdo->log->info("No releases are missing the guid."));
    }
}
예제 #14
0
파일: NZBImport.php 프로젝트: sebst3r/nZEDb
 /**
  * @param array $filesToProcess List of NZB files to import.
  * @param bool|string $useNzbName Use the NZB file name as release name?
  * @param bool $delete Delete the NZB when done?
  * @param bool $deleteFailed Delete the NZB if failed importing?
  *
  * @return string|bool
  *
  * @access public
  */
 public function beginImport($filesToProcess, $useNzbName = false, $delete = true, $deleteFailed = true)
 {
     // Get all the groups in the DB.
     if (!$this->getAllGroups()) {
         if ($this->browser) {
             return $this->retVal;
         } else {
             return false;
         }
     }
     $start = date('Y-m-d H:i:s');
     $nzbsImported = $nzbsSkipped = 0;
     // Loop over the file names.
     foreach ($filesToProcess as $nzbFile) {
         // Check if the file is really there.
         if (is_file($nzbFile)) {
             // Get the contents of the NZB file as a string.
             if (strtolower(substr($nzbFile, -7)) === '.nzb.gz') {
                 $nzbString = Utility::unzipGzipFile($nzbFile);
             } else {
                 $nzbString = file_get_contents($nzbFile);
             }
             if ($nzbString === false) {
                 $this->echoOut('ERROR: Unable to read: ' . $nzbFile);
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
             // Load it as a XML object.
             $nzbXML = @simplexml_load_string($nzbString);
             if ($nzbXML === false || strtolower($nzbXML->getName()) != 'nzb') {
                 $this->echoOut('ERROR: Unable to load NZB XML data: ' . $nzbFile);
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
             // Try to insert the NZB details into the DB.
             $inserted = $this->scanNZBFile($nzbXML, $useNzbName ? str_ireplace('.nzb', '', basename($nzbFile)) : false);
             if ($inserted) {
                 // Try to copy the NZB to the NZB folder.
                 $path = $this->nzb->getNZBPath($this->relGuid, 0, true);
                 // Try to compress the NZB file in the NZB folder.
                 $fp = gzopen($path, 'w5');
                 gzwrite($fp, $nzbString);
                 gzclose($fp);
                 if (!is_file($path)) {
                     $this->echoOut('ERROR: Problem compressing NZB file to: ' . $path);
                     // Remove the release.
                     $this->pdo->queryExec(sprintf("DELETE FROM releases WHERE guid = %s", $this->pdo->escapeString($this->relGuid)));
                     if ($deleteFailed) {
                         @unlink($nzbFile);
                     }
                     $nzbsSkipped++;
                     continue;
                 } else {
                     if ($delete) {
                         // Remove the nzb file.
                         @unlink($nzbFile);
                     }
                     $nzbsImported++;
                     continue;
                 }
             } else {
                 if ($deleteFailed) {
                     @unlink($nzbFile);
                 }
                 $nzbsSkipped++;
                 continue;
             }
         } else {
             $this->echoOut('ERROR: Unable to fetch: ' . $nzbFile);
             $nzbsSkipped++;
             continue;
         }
     }
     $this->echoOut('Proccessed ' . $nzbsImported . ' NZBs in ' . (strtotime(date('Y-m-d H:i:s')) - strtotime($start)) . ' seconds, ' . $nzbsSkipped . ' NZBs were skipped.');
     if ($this->browser) {
         return $this->retVal;
     } else {
         return true;
     }
 }
예제 #15
0
require_once './config.php';
use nzedb\Releases;
use nzedb\NZB;
use nzedb\utility\Misc;
$page = new AdminPage();
if (!$page->users->isLoggedIn()) {
    $page->show403();
}
if (isset($_GET['id'])) {
    $releases = new Releases(['Settings' => $page->settings]);
    $release = $releases->getByGuid($_GET['id']);
    if ($release === false) {
        $page->show404();
    }
    $nzb = new NZB($page->settings);
    $nzbPath = $nzb->getNZBPath($_GET['id']);
    if (!file_exists($nzbPath)) {
        $page->show404();
    }
    $nzbFile = Misc::unzipGzipFile($nzbPath);
    $files = $nzb->nzbFileList($nzbFile);
    $page->smarty->assign('release', $release);
    $page->smarty->assign('files', $files);
    $page->title = "File List";
    $page->meta_title = "View Nzb file list";
    $page->meta_keywords = "view,nzb,file,list,description,details";
    $page->meta_description = "View Nzb File List";
    $page->content = $page->smarty->fetch('release-files.tpl');
    $page->render();
}
예제 #16
0
파일: getnzb.php 프로젝트: EeGgSs/nZEDb
            $rel->updateGrab($guid);
            $page->users->addDownloadRequest($uid);
            if (isset($_GET["del"]) && $_GET["del"] == 1) {
                $page->users->delCartByUserAndRelease($guid, $uid);
            }
        }
        $filename = date("Ymdhis") . ".nzb.zip";
        header("Content-type: application/octet-stream");
        header("Content-disposition: attachment; filename=" . $filename);
        echo $zip;
        die;
    } else {
        $page->show404();
    }
}
$nzb = new NZB($page->settings);
if (isset($_GET["id"])) {
    $reldata = $rel->getByGuid($_GET["id"]);
    $nzbpath = $nzb->getNZBPath($_GET["id"]);
    if (!file_exists($nzbpath)) {
        header("X-DNZB-RCode: 404");
        header("X-DNZB-RText: NZB file not found!");
        $page->show404();
    }
    if ($reldata) {
        $rel->updateGrab($_GET["id"]);
        $page->users->addDownloadRequest($uid);
        $page->users->incrementGrabs($uid);
        if (isset($_GET["del"]) && $_GET["del"] == 1) {
            $page->users->delCartByUserAndRelease($_GET["id"], $uid);
        }