/** * Delete release from Sphinx RT table. * @param array $identifiers ['g' => Release GUID(mandatory), 'id => ReleaseID(optional, pass false)] * @param nzedb\db\Settings $pdo */ public function deleteRelease($identifiers, nzedb\db\Settings $pdo) { if (!is_null($this->sphinxQL)) { if ($identifiers['i'] === false) { $identifiers['i'] = $pdo->queryOneRow(sprintf('SELECT id FROM releases WHERE guid = %s', $pdo->escapeString($identifiers['g']))); if ($identifiers['i'] !== false) { $identifiers['i'] = $identifiers['i']['id']; } } if ($identifiers['i'] !== false) { $this->sphinxQL->queryExec(sprintf('DELETE FROM releases_rt WHERE id = %s', $identifiers['i'])); } } }
/** * Gets the completion from the NZB, optionally looks if there is an NFO/PAR2 file. * * @param string $guid * @param int $relID * @param int $groupID * @param bool $nfoCheck * * @return array|bool * * @access public */ public function parseNZB($guid, $relID, $groupID, $nfoCheck = false) { $nzbFile = $this->LoadNZB($guid); if ($nzbFile !== false) { $messageID = $hiddenID = ''; $actualParts = $artificialParts = 0; $foundPAR2 = $this->lookuppar2 === false ? true : false; $foundNFO = $hiddenNFO = $nfoCheck === false ? true : false; foreach ($nzbFile->file as $nzbcontents) { foreach ($nzbcontents->segments->segment as $segment) { $actualParts++; } $subject = (string) $nzbcontents->attributes()->subject; if (preg_match('/(\\d+)\\)$/', $subject, $parts)) { $artificialParts += $parts[1]; } if ($foundNFO === false) { if (preg_match('/\\.\\b(nfo|inf|ofn)\\b(?![ .-])/i', $subject)) { $messageID = (string) $nzbcontents->segments->segment; $foundNFO = true; } } if ($foundNFO === false && $hiddenNFO === false) { if (preg_match('/\\(1\\/1\\)$/i', $subject) && !preg_match('/\\.(apk|bat|bmp|cbr|cbz|cfg|css|csv|cue|db|dll|doc|epub|exe|gif|htm|ico|idx|ini' . '|jpg|lit|log|m3u|mid|mobi|mp3|nib|nzb|odt|opf|otf|par|par2|pdf|psd|pps|png|ppt|r\\d{2,4}' . '|rar|sfv|srr|sub|srt|sql|rom|rtf|tif|torrent|ttf|txt|vb|vol\\d+\\+\\d+|wps|xml|zip)/i', $subject)) { $hiddenID = (string) $nzbcontents->segments->segment; $hiddenNFO = true; } } if ($foundPAR2 === false) { if (preg_match('/\\.(par[2" ]|\\d{2,3}").+\\(1\\/1\\)$/i', $subject)) { if ($this->pp->parsePAR2((string) $nzbcontents->segments->segment, $relID, $groupID, $this->nntp, 1) === true) { $this->pdo->queryExec(sprintf('UPDATE releases SET proc_par2 = 1 WHERE id = %d', $relID)); $foundPAR2 = true; } } } } if ($artificialParts <= 0 || $actualParts <= 0) { $completion = 0; } else { $completion = $actualParts / $artificialParts * 100; } if ($completion > 100) { $completion = 100; } $this->pdo->queryExec(sprintf('UPDATE releases SET completion = %d WHERE id = %d', $completion, $relID)); if ($foundNFO === true && strlen($messageID) > 1) { return array('hidden' => false, 'ID' => $messageID); } elseif ($hiddenNFO === true && strlen($hiddenID) > 1) { return array('hidden' => true, 'ID' => $hiddenID); } } return false; }
<?php /* * This script attemps to clean release names using the NFO, file name and release name, Par2 file. * A good way to use this script is to use it in this order: php fixReleaseNames.php 3 true other yes * php fixReleaseNames.php 5 true other yes * If you used the 4th argument yes, but you want to reset the status, * there is another script called resetRelnameStatus.php */ require_once dirname(__FILE__) . '/../../../www/config.php'; $n = "\n"; $pdo = new nzedb\db\Settings(); $namefixer = new NameFixer(['Settings' => $pdo]); $predb = new PreDb(['Echo' => true, 'Settings' => $pdo]); if (isset($argv[1]) && isset($argv[2]) && isset($argv[3]) && isset($argv[4])) { $update = $argv[2] == "true" ? 1 : 2; $other = 1; 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) {
<?php //This script will update all records in the gamesinfo table require_once dirname(__FILE__) . '/../../../www/config.php'; $pdo = new nzedb\db\Settings(); $game = new Games(['Echo' => true, 'Settings' => $pdo]); $res = $pdo->query(sprintf("SELECT searchname FROM releases WHERE gamesinfo_id IS NULL AND categoryid = 4050 ORDER BY id DESC LIMIT 100")); $total = count($res); if ($total > 0) { echo $pdo->log->header("Updating game info for " . number_format($total) . " releases."); foreach ($res as $arr) { $starttime = microtime(true); $gameInfo = $game->parseTitle($arr['searchname']); if ($gameInfo !== false) { $gameData = $game->updateGamesInfo($gameInfo); if ($gameData === false) { echo $pdo->log->primary($gameInfo['release'] . ' not found'); } } // amazon limits are 1 per 1 sec $diff = floor((microtime(true) - $starttime) * 1000000); if (1000000 - $diff > 0) { echo $pdo->log->alternate("Sleeping"); usleep(1000000 - $diff); } } }
/** * Attempt to get a better name from a par2 file and categorize the release. * * @note Called from NZBContents.php * * @param string $messageID MessageID from NZB file. * @param int $relID ID of the release. * @param int $groupID Group ID of the release. * @param NNTP $nntp Class NNTP * @param int $show Only show result or apply iy. * * @return bool */ public function parsePAR2($messageID, $relID, $groupID, &$nntp, $show) { if ($messageID === '') { return false; } $query = $this->pdo->queryOneRow(sprintf(' SELECT id, group_id, categoryid, name, searchname, UNIX_TIMESTAMP(postdate) AS post_date, id AS releaseid FROM releases WHERE isrenamed = 0 AND id = %d', $relID)); if ($query === false) { return false; } // Only get a new name if the category is OTHER. $foundName = true; if (!in_array((int) $query['categoryid'], array(\Category::CAT_BOOKS_OTHER, \Category::CAT_GAME_OTHER, \Category::CAT_MOVIE_OTHER, \Category::CAT_MUSIC_OTHER, \Category::CAT_PC_PHONE_OTHER, \Category::CAT_TV_OTHER, \Category::CAT_OTHER_HASHED, \Category::CAT_XXX_OTHER, \Category::CAT_MISC))) { $foundName = false; } // Get the PAR2 file. $par2 = $nntp->getMessages($this->groups->getByNameByID($groupID), $messageID, $this->alternateNNTP); if ($nntp->isError($par2)) { return false; } // Put the PAR2 into Par2Info, check if there's an error. $this->_par2Info->setData($par2); if ($this->_par2Info->error) { return false; } // Get the file list from Par2Info. $files = $this->_par2Info->getFileList(); if ($files !== false && count($files) > 0) { $filesAdded = 0; // Loop through the files. foreach ($files as $file) { if (!isset($file['name'])) { continue; } // If we found a name and added 10 files, stop. if ($foundName === true && $filesAdded > 10) { break; } if ($this->addpar2) { // Add to release files. if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf(' SELECT id FROM releasefiles WHERE releaseid = %d AND name = %s', $relID, $this->pdo->escapeString($file['name']))) === false) { // Try to add the files to the DB. if ($this->releaseFiles->add($relID, $file['name'], $file['size'], $query['post_date'], 0)) { $filesAdded++; } } } else { $filesAdded++; } // Try to get a new name. if ($foundName === false) { $query['textstring'] = $file['name']; if ($this->nameFixer->checkName($query, 1, 'PAR2, ', 1, $show) === true) { $foundName = true; } } } // If we found some files. if ($filesAdded > 0) { $this->debugging->log('PostProcess', 'parsePAR2', 'Added ' . $filesAdded . ' releasefiles from PAR2 for ' . $query['searchname'], \Logger::LOG_INFO); // Update the file count with the new file count + old file count. $this->pdo->queryExec(sprintf(' UPDATE releases SET rarinnerfilecount = rarinnerfilecount + %d WHERE id = %d', $filesAdded, $relID)); } if ($foundName === true) { return true; } } return false; }
<?php require_once dirname(__FILE__) . '/../../../www/config.php'; $pdo = new nzedb\db\Settings(); $count = $groups = 0; if (!isset($argv[1])) { passthru("clear"); exit($pdo->log->error("\nThis script will show all Active Groups. There is 1 required argument and 2 optional arguments.\n" . "The first argument of [date, releases] is used to sort the display by first_record_postdate or by the number of releases.\n" . "The second argument [ASC, DESC] sorts by ascending or descending.\n" . "The third argument will limit the return to that number of groups.\n" . "To sort the active groups by first_record_postdate and display only 20 groups run:\n" . "php {$argv['0']} date desc 20\n")); } passthru("clear"); if (isset($argv[1]) && $argv[1] == "date") { $order = "order by first_record_postdate"; } else { if (isset($argv[1]) && $argv[1] == "releases") { $order = "order by num_releases"; } else { $order = ""; } } if (isset($argv[2]) && ($argv[2] == "ASC" || $argv[2] == "asc")) { $sort = "ASC"; } else { if (isset($argv[2]) && ($argv[2] == "DESC" || $argv[2] == "desc")) { $sort = "DESC"; } else { $sort = ""; } } if (isset($argv[3]) && is_numeric($argv[3])) { $limit = "LIMIT " . $argv[3]; } else {
<?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")); }
/** * If a collection did not have the file count (ie: [00/12]) or the collection is incomplete after * $this->collectionDelayTime hours, set the collection to complete to create it into a release/nzb. * * @param array $group * @param string $where * * @void * @access private */ private function collectionFileCheckStage6(array &$group, &$where) { $this->pdo->queryExec(sprintf("\n\t\t\t\tUPDATE %s c SET filecheck = %d, totalfiles = (SELECT COUNT(b.id) FROM %s b WHERE b.collectionid = c.id)\n\t\t\t\tWHERE c.dateadded < NOW() - INTERVAL '%d' HOUR\n\t\t\t\tAND c.filecheck IN (%d, %d, 10) %s", $group['cname'], self::COLLFC_COMPPART, $group['bname'], $this->collectionDelayTime, self::COLLFC_DEFAULT, self::COLLFC_COMPCOLL, $where)); }
<?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 {
<?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('
* $options[2] => (string) Group name. */ case 'update_group_headers': $pdo = new \nzedb\db\Settings(); $nntp = nntp($pdo); $groups = new \Groups(['Settings' => $pdo]); $groupMySQL = $groups->getByName($options[2]); (new \Binaries(['NNTP' => $nntp, 'Groups' => $groups, 'Settings' => $pdo]))->updateGroup($groupMySQL); break; // Do a single group (update_binaries/backFill/update_releases/postprocess). // $options[2] => (int)groupID, group to work on // Do a single group (update_binaries/backFill/update_releases/postprocess). // $options[2] => (int)groupID, group to work on case 'update_per_group': if (is_numeric($options[2])) { $pdo = new \nzedb\db\Settings(); // Get the group info from MySQL. $groupMySQL = $pdo->queryOneRow(sprintf('SELECT * FROM groups WHERE id = %d', $options[2])); if ($groupMySQL === false) { exit('ERROR: Group not found with ID ' . $options[2] . PHP_EOL); } // Connect to NNTP. $nntp = nntp($pdo); $backFill = new \Backfill(['NNTP' => $nntp, 'Settings' => $pdo], true); // Update the group for new binaries. (new \Binaries(['NNTP' => $nntp, 'Settings' => $pdo]))->updateGroup($groupMySQL); // BackFill the group with 20k articles. $backFill->backfillAllGroups($groupMySQL['name'], 20000, 'normal'); // Check if we got anything from binaries/backFill, exit if not. collectionCheck($pdo, $options[2]); // Create releases.
/** * Delete all Collections/Binaries/Parts for a group ID. * * @param int $groupID The ID of the group. * * @note A trigger automatically deletes the parts/binaries. * * @return void */ public function purgeGroup($groupID) { $this->_pdo->queryExec(sprintf('DELETE c FROM collections c WHERE c.group_id = %d', $groupID)); }
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; }