Пример #1
0
 /**
  * Construct.
  *
  * @param array $options
  *     array(
  *         'Echo'        => bool        ; To echo to CLI or not.
  *         'NNTP'        => NNTP        ; Class NNTP.
  *         'Nfo'         => Nfo         ; Class Nfo.
  *         'NZB'         => NZB         ; Class NZB.
  *         'Settings'    => DB          ; Class nzedb\db\Settings.
  *         'PostProcess' => PostProcess ; Class PostProcess.
  *     )
  *
  * @access public
  */
 public function __construct(array $options = array())
 {
     $defaults = ['Echo' => false, 'NNTP' => null, 'Nfo' => null, 'NZB' => null, 'Settings' => null, 'PostProcess' => null];
     $options += $defaults;
     $this->echooutput = $options['Echo'] && nZEDb_ECHOCLI;
     $this->pdo = $options['Settings'] instanceof \nzedb\db\Settings ? $options['Settings'] : new \nzedb\db\Settings();
     $this->nntp = $options['NNTP'] instanceof NNTP ? $options['NNTP'] : new NNTP(['Echo' => $this->echooutput, 'Settings' => $this->pdo]);
     $this->nfo = $options['Nfo'] instanceof Nfo ? $options['Nfo'] : new Nfo(['Echo' => $this->echooutput, 'Settings' => $this->pdo]);
     $this->pp = $options['PostProcess'] instanceof PostProcess ? $options['PostProcess'] : new PostProcess(['Echo' => $this->echooutput, 'Nfo' => $this->nfo, 'Settings' => $this->pdo]);
     $this->nzb = $options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo);
     $this->lookuppar2 = $this->pdo->getSetting('lookuppar2') == 1 ? true : false;
     $this->alternateNNTP = $this->pdo->getSetting('alternate_nntp') == 1 ? true : false;
 }
Пример #2
0
 /**
  * Constructor.
  *
  * @param array $options Class instances / echo to CLI?
  */
 public function __construct(array $options = [])
 {
     $defaults = ['Echo' => true, 'CollectionsCleaning' => null, 'ColorCLI' => null, 'Logger' => null, 'Groups' => null, 'NNTP' => null, 'Settings' => null];
     $options += $defaults;
     $this->_echoCLI = $options['Echo'] && nZEDb_ECHOCLI;
     $this->_pdo = $options['Settings'] instanceof \nzedb\db\Settings ? $options['Settings'] : new \nzedb\db\Settings();
     $this->_groups = $options['Groups'] instanceof Groups ? $options['Groups'] : new \Groups(['Settings' => $this->_pdo]);
     $this->_colorCLI = $options['ColorCLI'] instanceof ColorCLI ? $options['ColorCLI'] : new \ColorCLI();
     $this->_nntp = $options['NNTP'] instanceof NNTP ? $options['NNTP'] : new \NNTP(['Echo' => $this->_colorCLI, 'Settings' => $this->_pdo, 'ColorCLI' => $this->_colorCLI]);
     $this->_collectionsCleaning = $options['CollectionsCleaning'] instanceof CollectionsCleaning ? $options['CollectionsCleaning'] : new \CollectionsCleaning();
     $this->_debug = nZEDb_DEBUG || nZEDb_LOGGING;
     if ($this->_debug) {
         try {
             $this->_debugging = $options['Logger'] instanceof Logger ? $options['Logger'] : new \Logger(['ColorCLI' => $this->_colorCLI]);
         } catch (\LoggerException $error) {
             $this->_debug = false;
         }
     }
     $this->messageBuffer = $this->_pdo->getSetting('maxmssgs') != '' ? $this->_pdo->getSetting('maxmssgs') : 20000;
     $this->_compressedHeaders = $this->_pdo->getSetting('compressedheaders') == 1 ? true : false;
     $this->_partRepair = $this->_pdo->getSetting('partrepair') == 0 ? false : true;
     $this->_newGroupScanByDays = $this->_pdo->getSetting('newgroupscanmethod') == 1 ? true : false;
     $this->_newGroupMessagesToScan = $this->_pdo->getSetting('newgroupmsgstoscan') != '' ? $this->_pdo->getSetting('newgroupmsgstoscan') : 50000;
     $this->_newGroupDaysToScan = $this->_pdo->getSetting('newgroupdaystoscan') != '' ? (int) $this->_pdo->getSetting('newgroupdaystoscan') : 3;
     $this->_partRepairLimit = $this->_pdo->getSetting('maxpartrepair') != '' ? (int) $this->_pdo->getSetting('maxpartrepair') : 15000;
     $this->_partRepairMaxTries = $this->_pdo->getSetting('partrepairmaxtries') != '' ? (int) $this->_pdo->getSetting('partrepairmaxtries') : 3;
     $this->_showDroppedYEncParts = $this->_pdo->getSetting('showdroppedyencparts') == 1 ? true : false;
     $this->_tablePerGroup = $this->_pdo->getSetting('tablepergroup') == 1 ? true : false;
     $this->blackList = [];
     $this->_blackListLoaded = false;
 }
Пример #3
0
 if ($argv[3] === 'all') {
     $other = 2;
 } else {
     if ($argv[3] === 'preid') {
         $other = 3;
     }
 }
 $setStatus = $argv[4] == "yes" ? 1 : 2;
 $show = 2;
 if (isset($argv[5]) && $argv[5] === 'show') {
     $show = 1;
 }
 $nntp = null;
 if ($argv[1] == 7 || $argv[1] == 8) {
     $nntp = new NNTP(['Settings' => $pdo]);
     if (($pdo->getSetting('alternate_nntp') == '1' ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) {
         echo $pdo->log->error("Unable to connect to usenet.\n");
         return;
     }
 }
 switch ($argv[1]) {
     case 1:
         $predb->parseTitles(1, $update, $other, $setStatus, $show);
         break;
     case 2:
         $predb->parseTitles(2, $update, $other, $setStatus, $show);
         break;
     case 3:
         $namefixer->fixNamesWithNfo(1, $update, $other, $setStatus, $show);
         break;
     case 4:
Пример #4
0
 /**
  * Lookup xxx if enabled.
  */
 public function processXXX()
 {
     if ($this->pdo->getSetting('lookupxxx') == 1) {
         (new \XXX(['Echo' => $this->echooutput, 'Settings' => $this->pdo]))->processXXXReleases();
     }
 }
Пример #5
0
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
require_once nZEDb_LIBS . 'AmazonProductAPI.php';
// Test if your amazon keys are working.
$pdo = new nzedb\db\Settings();
$pubkey = $pdo->getSetting('amazonpubkey');
$privkey = $pdo->getSetting('amazonprivkey');
$asstag = $pdo->getSetting('amazonassociatetag');
$obj = new AmazonProductAPI($pubkey, $privkey, $asstag);
$e = null;
try {
    $result = $obj->searchProducts("Adriana Koulias The Seal", AmazonProductAPI::BOOKS, "TITLE");
} catch (Exception $e) {
    $result = false;
}
if ($result !== false) {
    print_r($result);
    exit($pdo->log->header("\nLooks like it is working alright."));
} else {
    print_r($e);
    exit($pdo->log->error("\nThere was a problem attemtping to query amazon. Maybe your keys or wrong, or you are being throttled.\n"));
}
Пример #6
0
    /**
     * Delete releases using admin settings.
     * This deletes releases, regardless of group.
     *
     * @void
     * @access public
     */
    public function deleteReleases()
    {
        $startTime = time();
        $category = new \Category(['Settings' => $this->pdo]);
        $genres = new \Genres(['Settings' => $this->pdo]);
        $passwordDeleted = $duplicateDeleted = $retentionDeleted = $completionDeleted = $disabledCategoryDeleted = 0;
        $disabledGenreDeleted = $miscRetentionDeleted = $miscHashedDeleted = $categoryMinSizeDeleted = 0;
        // Delete old releases and finished collections.
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Delete old releases and passworded releases."));
        }
        // Releases past retention.
        if ($this->pdo->getSetting('releaseretentiondays') != 0) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE postdate < (NOW() - INTERVAL %d DAY)', $this->pdo->getSetting('releaseretentiondays')));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $retentionDeleted++;
                }
            }
        }
        // Passworded releases.
        if ($this->pdo->getSetting('deletepasswordedrelease') == 1) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE passwordstatus = %d', \Releases::PASSWD_RAR));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $passwordDeleted++;
                }
            }
        }
        // Possibly passworded releases.
        if ($this->pdo->getSetting('deletepossiblerelease') == 1) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE passwordstatus = %d', \Releases::PASSWD_POTENTIAL));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $passwordDeleted++;
                }
            }
        }
        if ($this->crossPostTime != 0) {
            // Crossposted releases.
            do {
                $releases = $this->pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name HAVING COUNT(name) > 1', $this->crossPostTime));
                $total = 0;
                if ($releases && $releases->rowCount()) {
                    $total = $releases->rowCount();
                    foreach ($releases as $release) {
                        $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                        $duplicateDeleted++;
                    }
                }
            } while ($total > 0);
        }
        if ($this->completion > 0) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE completion < %d AND completion > 0', $this->completion));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $completionDeleted++;
                }
            }
        }
        // Disabled categories.
        $disabledCategories = $category->getDisabledIDs();
        if (count($disabledCategories) > 0) {
            foreach ($disabledCategories as $disabledCategory) {
                $releases = $this->pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE categoryid = %d', $disabledCategory['id']));
                if ($releases instanceof \Traversable) {
                    foreach ($releases as $release) {
                        $disabledCategoryDeleted++;
                        $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    }
                }
            }
        }
        // Delete smaller than category minimum sizes.
        $categories = $this->pdo->queryDirect('
			SELECT c.id AS id,
			CASE WHEN c.minsize = 0 THEN cp.minsize ELSE c.minsize END AS minsize
			FROM category c
			INNER JOIN category cp ON cp.id = c.parentid
			WHERE c.parentid IS NOT NULL');
        if ($categories instanceof \Traversable) {
            foreach ($categories as $category) {
                if ($category['minsize'] > 0) {
                    $releases = $this->pdo->queryDirect(sprintf('
							SELECT r.id, r.guid
							FROM releases r
							WHERE r.categoryid = %d
							AND r.size < %d', $category['id'], $category['minsize']));
                    if ($releases instanceof \Traversable) {
                        foreach ($releases as $release) {
                            $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                            $categoryMinSizeDeleted++;
                        }
                    }
                }
            }
        }
        // Disabled music genres.
        $genrelist = $genres->getDisabledIDs();
        if (count($genrelist) > 0) {
            foreach ($genrelist as $genre) {
                $releases = $this->pdo->queryDirect(sprintf('
						SELECT id, guid
						FROM releases
						INNER JOIN (SELECT id AS mid FROM musicinfo WHERE musicinfo.genre_id = %d) mi
						ON musicinfoid = mid', $genre['id']));
                if ($releases instanceof \Traversable) {
                    foreach ($releases as $release) {
                        $disabledGenreDeleted++;
                        $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    }
                }
            }
        }
        // Misc other.
        if ($this->pdo->getSetting('miscotherretentionhours') > 0) {
            $releases = $this->pdo->queryDirect(sprintf('
					SELECT id, guid
					FROM releases
					WHERE categoryid = %d
					AND adddate <= NOW() - INTERVAL %d HOUR', \Category::CAT_MISC, $this->pdo->getSetting('miscotherretentionhours')));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $miscRetentionDeleted++;
                }
            }
        }
        // Misc hashed.
        if ($this->pdo->getSetting('mischashedretentionhours') > 0) {
            $releases = $this->pdo->queryDirect(sprintf('
					SELECT id, guid
					FROM releases
					WHERE categoryid = %d
					AND adddate <= NOW() - INTERVAL %d HOUR', \Category::CAT_OTHER_HASHED, $this->pdo->getSetting('mischashedretentionhours')));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $miscHashedDeleted++;
                }
            }
        }
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary('Removed releases: ' . number_format($retentionDeleted) . ' past retention, ' . number_format($passwordDeleted) . ' passworded, ' . number_format($duplicateDeleted) . ' crossposted, ' . number_format($disabledCategoryDeleted) . ' from disabled categories, ' . number_format($categoryMinSizeDeleted) . ' smaller than category settings, ' . number_format($disabledGenreDeleted) . ' from disabled music genres, ' . number_format($miscRetentionDeleted) . ' from misc->other' . number_format($miscHashedDeleted) . ' from misc->hashed' . ($this->completion > 0 ? ', ' . number_format($completionDeleted) . ' under ' . $this->completion . '% completion.' : '.')));
            $totalDeleted = $retentionDeleted + $passwordDeleted + $duplicateDeleted + $disabledCategoryDeleted + $disabledGenreDeleted + $miscRetentionDeleted + $miscHashedDeleted + $completionDeleted + $categoryMinSizeDeleted;
            if ($totalDeleted > 0) {
                $this->pdo->log->doEcho($this->pdo->log->primary("Removed " . number_format($totalDeleted) . ' releases in ' . $this->consoleTools->convertTime(time() - $startTime)));
            }
        }
    }
Пример #7
0
<?php

require_once dirname(__FILE__) . '/config.php';
use nzedb\processing\ProcessReleases;
$pdo = new \nzedb\db\Settings();
if (isset($argv[2]) && $argv[2] === 'true') {
    // Create the connection here and pass
    $nntp = new NNTP(['Settings' => $pdo]);
    if ($nntp->doConnect() !== true) {
        exit($pdo->log->error("Unable to connect to usenet."));
    }
}
if ($pdo->getSetting('tablepergroup') === 1) {
    exit($pdo->log->error("You are using 'tablepergroup', you must use releases_threaded.py"));
}
$groupName = isset($argv[3]) ? $argv[3] : '';
if (isset($argv[1]) && isset($argv[2])) {
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $releases = new ProcessReleases(['Settings' => $pdo, 'ConsoleTools' => $consoletools]);
    if ($argv[1] == 1 && $argv[2] == 'true') {
        $releases->processReleases(1, 1, $groupName, $nntp, true);
    } else {
        if ($argv[1] == 1 && $argv[2] == 'false') {
            $releases->processReleases(1, 2, $groupName, $nntp, true);
        } else {
            if ($argv[1] == 2 && $argv[2] == 'true') {
                $releases->processReleases(2, 1, $groupName, $nntp, true);
            } else {
                if ($argv[1] == 2 && $argv[2] == 'false') {
                    $releases->processReleases(2, 2, $groupName, $nntp, true);
                } else {
Пример #8
0
<?php

require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\processing\PostProcess;
$pdo = new nzedb\db\Settings();
$tmpPath = $pdo->getSetting('tmpunrarpath');
if (empty($tmpPath)) {
    exit('The tmpunrarpath site setting must not be empty!' . PHP_EOL);
}
if (substr($tmpPath, -1) !== DS) {
    $tmpPath .= DS;
}
$tmpPath .= 'u4e' . DS;
if (!is_dir($tmpPath)) {
    $old = umask(0777);
    @mkdir($tmpPath, 0777, true);
    @chmod($tmpPath, 0777);
    @umask($old);
    if (!is_dir($tmpPath)) {
        exit('Unable to create temp directory:' . $tmpPath . PHP_EOL);
    }
}
$unrarPath = $pdo->getSetting('unrarpath');
if (empty($unrarPath)) {
    exit('The site setting for the unrar path must not be empty!' . PHP_EOL);
}
$nntp = new NNTP(['Settings' => $pdo]);
$nfo = new Nfo(['Echo' => true, 'Settings' => $pdo]);
$nzbContents = new NZBContents(array('Settings' => $pdo, 'Echo' => true, 'Nfo' => $nfo, 'PostProcess' => new PostProcess(['Settings' => $pdo, 'Nfo' => $nfo]), 'NNTP' => $nntp));
$categorize = new Categorize(['Settings' => $pdo]);
$releases = $pdo->queryDirect(sprintf('
Пример #9
0
 public static function isPatched()
 {
     $versions = self::getValidVersionsFile();
     $pdo = new \nzedb\db\Settings();
     $patch = $pdo->getSetting(['section' => '', 'subsection' => '', 'name' => 'sqlpatch']);
     $ver = $versions->versions->sql->file;
     // Check database patch version
     if ($patch < $ver) {
         $message = "\nYour database is not up to date. Reported patch levels\n   Db: {$patch}\nfile: {$ver}\nPlease update.\n php " . nZEDb_ROOT . "cli/update_db.php true\n";
         if (self::isCLI()) {
             echo (new \ColorCLI())->error($message);
         }
         throw new \RuntimeException($message);
     }
     return true;
 }