function handleNzbAction($messageids, $userSession, $action, $hdr_spotnntp, $nzb_spotnntp) { if (!is_array($messageids)) { $messageids = array($messageids); } # if # Controleer de security $userSession['security']->fatalPermCheck(SpotSecurity::spotsec_retrieve_nzb, ''); if ($action != 'display') { $userSession['security']->fatalPermCheck(SpotSecurity::spotsec_download_integration, $action); } # if # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $nzbList = array(); foreach($messageids as $thisMsgId) { $fullSpot = $spotsOverview->getFullSpot($thisMsgId, $userSession['user']['userid'], $hdr_spotnntp); if (!empty($fullSpot['nzb'])) { $nzbList[] = array('spot' => $fullSpot, 'nzb' => $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp)); } # if } # foreach # send nzblist to NzbHandler plugin $nzbHandlerFactory = new NzbHandler_Factory(); $nzbHandler = $nzbHandlerFactory->build($this->_settings, $action, $userSession['user']['prefs']['nzbhandling']); $nzbHandler->processNzb($fullSpot, $nzbList); # en voeg hem toe aan de lijst met downloads if ($userSession['user']['prefs']['keep_downloadlist']) { if ($userSession['security']->allowed(SpotSecurity::spotsec_keep_own_downloadlist, '')) { foreach($messageids as $thisMsgId) { $this->_db->addToSpotStateList(SpotDb::spotstate_Down, $thisMsgId, $userSession['user']['userid']); } # foreach } # if } # if # en verstuur een notificatie $spotsNotifications = new SpotNotifications($this->_db, $this->_settings, $userSession); $spotsNotifications->sendNzbHandled($action, $fullSpot); } # handleNzbAction
function handleNzbAction($messageid, $action, $hdr_spotnntp, $nzb_spotnntp) { # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $fullSpot = $spotsOverview->getFullSpot($messageid, $hdr_spotnntp); $nzb = $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp); # handel dit alles af naar gelang de actie die gekozen is switch ($action) { case 'disable': break; # gewoon nzb file output geven # gewoon nzb file output geven case 'display': Header("Content-Type: application/x-nzb"); Header("Content-Disposition: attachment; filename=\"" . urlencode($fullSpot['title']) . ".nzb\""); echo $nzb; break; # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat case 'save': $this->saveNzbFile($fullSpot, $nzb); break; case 'runcommand': $this->saveNzbFile($fullSpot, $nzb); $this->runCommand($fullSpot); break; # runcommand # runcommand case 'push-sabnzbd': $this->runHttp($fullSpot, $nzb, $action); break; # push-sabnzbd # push-sabnzbd default: throw new Exception("Invalid action: " . $action); } # switch # en voeg hem toe aan de lijst met downloads if ($this->_settings['keep_downloadlist']) { $this->_db->addDownload($fullSpot['messageid']); } # if }
function handleNzbAction($messageids, $action, $hdr_spotnntp, $nzb_spotnntp) { if (!is_array($messageids)) { $messageids = array($messageids); } # if # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $nzbList = array(); foreach($messageids as $thisMsgId) { $fullSpot = $spotsOverview->getFullSpot($thisMsgId, $hdr_spotnntp); $nzbList[] = $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp); } # foreach # nu we alle nzb files hebben, trekken we de 'file' secties eruit, # en plakken die in onze overkoepelende nzb $nzbXml = simplexml_load_string('<?xml version="1.0" encoding="iso-8859-1" ?> <!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd"> <nzb xmlns="http://www.newzbin.com/DTD/2003/nzb"></nzb>'); $domNzbXml = dom_import_simplexml($nzbXml); foreach($nzbList as $nzb) { $oneNzbFile = simplexml_load_string($nzb); # add each file section to the larger XML object foreach($oneNzbFile->file as $file) { # Import the file into the larger NZB object $domFile = $domNzbXml->ownerDocument->importNode(dom_import_simplexml($file), TRUE); $domNzbXml->appendChild($domFile); } # foreach } # foreach $nzb = $nzbXml->asXml(); # handel dit alles af naar gelang de actie die gekozen is switch ($action) { case 'disable' : break; # gewoon nzb file output geven case 'display' : { Header("Content-Type: application/x-nzb"); Header("Content-Disposition: attachment; filename=\"" . urlencode($fullSpot['title']) . ".nzb\""); echo $nzb; break; } # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat case 'save' : $this->saveNzbFile($fullSpot, $nzb); break; case 'runcommand' : { $this->saveNzbFile($fullSpot, $nzb); $this->runCommand($fullSpot); break; } # runcommand case 'push-sabnzbd' : { $this->runHttp($fullSpot, $nzb, $action); break; } # push-sabnzbd default : throw new Exception("Invalid action: " . $action); } # switch # en voeg hem toe aan de lijst met downloads if ($this->_settings['keep_downloadlist']) { foreach($messageids as $thisMsgId) { $this->_db->addDownload($thisMsgId); } # foreach } # if } # handleNzbAction
function process($hdrList, $curMsg, $endMsg, $timer) { $this->displayStatus("progress", $curMsg . " till " . $endMsg); $spotParser = new SpotParser(); $signedCount = 0; $hdrsRetrieved = 0; $fullsRetrieved = 0; $msgCounter = 0; $modCount = 0; $skipCount = 0; $lastProcessedId = ''; $fullSpotDbList = array(); $spotDbList = array(); $moderationList = array(); $processingStartTime = time(); /* * Determine the cutoff date (unixtimestamp) from whereon we do not want to * load the spots */ if ($this->_settings->get('retention') > 0) { $retentionStamp = time() - $this->_settings->get('retention') * 24 * 60 * 60; } else { $retentionStamp = 0; } # else $this->debug('retentionStamp=' . $retentionStamp); $this->debug('hdrList=' . serialize($hdrList)); /** * We ask the database to match our messageid's we just retrieved with * the list of id's we have just retrieved from the server */ $dbIdList = $this->_db->matchSpotMessageIds($hdrList); $this->debug('dbIdList=' . serialize($dbIdList)); # if we need to fetch images or nzb files, we need an spotsoverview instance if ($this->_retrieveFull && $this->_prefetch_image || $this->_prefetch_nzb) { $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $spotsOverview->setActiveRetriever(true); /* * Only create a new NZB instance if the server differs from the * header host, else re-use the connection */ $settings_nntp_nzb = $this->_settings->get('nntp_nzb'); if ($this->_server['host'] == $settings_nntp_nzb['host']) { $nntp_nzb = $this->_spotnntp; } else { $nntp_nzb = new SpotNntp($settings_nntp_nzb); $nntp_nzb->selectGroup($this->_settings->get('nzb_group')); } # else } # if foreach ($hdrList as $msgheader) { $msgCounter++; $this->debug('foreach-loop, start. msgId= ' . $msgCounter); /* * Keep te usenet server alive when processing is slow. */ if ($processingStartTime - time() > 30) { $this->_spotnntp->sendNoop(); if (isset($nntp_nzb) && $nntp_nzb != $this->_spotnntp) { $nntp_nzb->sendNoop(); } # if $processingStartTime = time(); } # if /* * We keep track whether we actually fetched this header and fullspot * to add it to the database, because only then we can update the * titel from the spots title or rely on our database to fetch * the fullspot */ $didFetchHeader = false; $didFetchFullSpot = false; # Reset timelimit set_time_limit(120); # messageid to check $msgId = substr($msgheader['Message-ID'], 1, -1); /* * We prepare some variables to we don't have to perform an array * lookup for each check and the code is easier to read. */ $header_isInDb = isset($dbIdList['spot'][$msgId]); $fullspot_isInDb = isset($dbIdList['fullspot'][$msgId]); /* * If the spotheader is not yet added to the database, parse the header * information. * * If the header is present, but we don't have the fullspot yet or we are * running in 'retro' mode, parse the header as well because some fields * are only in the header and not in the full. * * We need some of those fields (for example KeyID) */ if (!$header_isInDb || (!$fullspot_isInDb || $this->_retro) && $this->_retrieveFull) { $hdrsRetrieved++; $this->debug('foreach-loop, parsingXover, start. msgId= ' . $msgCounter); $spot = $spotParser->parseXover($msgheader['Subject'], $msgheader['From'], $msgheader['Date'], $msgheader['Message-ID'], $this->_rsakeys); $this->debug('foreach-loop, parsingXover, done. msgId= ' . $msgCounter); /* * When a parse error occured, we ignore the spot, also unverified * spots are ignored */ if ($spot === false || !$spot['verified']) { $this->debug('foreach-loop, spot is either false or not verified'); continue; } # if /* * Special moderator commands always have keyid 2 */ if ($spot['keyid'] == 2) { $this->debug('foreach-loop, spot is a moderation spot'); $commandAr = explode(' ', strtolower($spot['title'])); $validCommands = array('delete', 'dispose', 'remove'); # is this one of the defined valid commands? if (in_array($commandAr[0], $validCommands) !== false) { $moderationList[$commandAr[1]] = 1; $modCount++; } # if } else { /* * Don't add spots older than specified for the retention stamp */ if ($retentionStamp > 0 && $spot['stamp'] < $retentionStamp && $this->_settings->get('retentiontype') == 'everything') { $this->debug('foreach-loop, spot is expired: ' . $spot['stamp']); continue; } elseif ($spot['stamp'] < $this->_settings->get('retrieve_newer_than')) { $this->debug('foreach-loop, spot is too old: ' . $spot['stamp']); $skipCount++; } else { /* * Do we have the header in the database? If not, lets add it */ if (!$header_isInDb) { $spotDbList[] = $spot; /* * Some buggy NNTP servers give us the same messageid * in one XOVER statement, hence we update the list of * messageid's we already have retrieved and are ready * to be added to the database */ $dbIdList['spot'][$msgId] = 1; $header_isInDb = true; $lastProcessedId = $msgId; $didFetchHeader = true; if ($spot['wassigned']) { $signedCount++; } # if } # if } # if } # else } else { $lastProcessedId = $msgId; } # else /* * We don't want to retrieve the fullspot if we don't have the header * in the database. Because we try to add headers in the above code we just have * to check if the header is in the database. * * We cannot collapse this code with the header fetching code because we want to * be able to add the fullspot to a system after all the headers are retrieved */ if ($header_isInDb && !$fullspot_isInDb) { /* * Don't add older fullspots than specified for the retention stamp */ if ($retentionStamp > 0 && strtotime($msgheader['Date']) < $retentionStamp) { continue; } # if if ($this->_retrieveFull) { $fullSpot = array(); try { $fullsRetrieved++; $this->debug('foreach-loop, getFullSpot, start. msgId= ' . $msgId); $fullSpot = $this->_spotnntp->getFullSpot($msgId); $this->debug('foreach-loop, getFullSpot, done. msgId= ' . $msgId); # add this spot to the database $fullSpotDbList[] = $fullSpot; $fullspot_isInDb = true; $didFetchFullSpot = true; /* * Some buggy NNTP servers give us the same messageid * in once XOVER statement, hence we update the list of * messageid's we already have retrieved and are ready * to be added to the database */ $dbIdList['fullspot'][$msgId] = 1; /* * Overwrite the spots' title because the fullspot contains the title in * UTF-8 format. * We also overwrite the spotterid from the spotsfull because the spotterid * is only in the header in more recent spots. */ if ($didFetchHeader) { $spotDbList[count($spotDbList) - 1]['title'] = $fullSpot['title']; $spotDbList[count($spotDbList) - 1]['spotterid'] = $fullSpot['spotterid']; } # if } catch (ParseSpotXmlException $x) { # swallow error } catch (Exception $x) { /** * Sometimes we get an 'No such article' error for a header we just retrieved, * if we want to retrieve the full article. This is messed up, but let's just * swallow the error */ if ($x->getCode() == 430) { } elseif ($x->getMessage() == 'String could not be parsed as XML') { } else { throw $x; } # else } # catch } # if retrievefull } # if fullspot is not in db yet if ($this->_retrieveFull && $header_isInDb && ($this->_prefetch_image || $this->_prefetch_nzb)) { try { /* * If we are running in 'retro' mode, it is possible both the header and spot are in the * database already, however -- we need the information from the fullspot so we retrieve it * again */ if (!$didFetchFullSpot) { $fullSpot = $this->_db->getFullSpot($msgId, SPOTWEB_ANONYMOUS_USERID); $fullSpot = array_merge($spotParser->parseFull($fullSpot['fullxml']), $fullSpot); } # if /* * Prefetch (cache) the spots' image */ if ($this->_prefetch_image) { /* * If the spot is older than 30 days, and the image is on the web, we do not * prefetch the image. */ if (is_array($fullSpot['image']) || $fullSpot['stamp'] > (int) time() - 30 * 24 * 60 * 60) { $this->debug('foreach-loop, getImage(), start. msgId= ' . $msgId); $spotsOverview->getImage($fullSpot, $nntp_nzb); $this->debug('foreach-loop, getImage(), done. msgId= ' . $msgId); } # if } # if /* * Prefetch (cache) the spots' NZB file */ if ($this->_prefetch_nzb) { /* * Only do so if we can expect an NZB file */ if (!empty($fullSpot['nzb']) && $fullSpot['stamp'] > 1290578400) { $this->debug('foreach-loop, getNzb(), start. msgId= ' . $msgId); $spotsOverview->getNzb($fullSpot, $nntp_nzb); $this->debug('foreach-loop, getNzb(), done. msgId= ' . $msgId); } # if } # if } catch (ParseSpotXmlException $x) { # swallow error } catch (Exception $x) { /** * Sometimes we get an 'No such article' error for a header we just retrieved, * if we want to retrieve the full article. This is messed up, but let's just * swallow the error */ if ($x->getCode() == 430) { } elseif ($x->getMessage() == 'String could not be parsed as XML') { } else { throw $x; } # else } # catch } # if prefetch image and/or nzb $this->debug('foreach-loop, done. msgId= ' . $msgCounter); } # foreach if (count($hdrList) > 0) { $this->displayStatus("hdrparsed", $hdrsRetrieved); $this->displayStatus("fullretrieved", $fullsRetrieved); $this->displayStatus("verified", $signedCount); $this->displayStatus("modcount", $modCount); $this->displayStatus("skipcount", $skipCount); $this->displayStatus("loopcount", count($hdrList)); } else { $this->displayStatus("hdrparsed", 0); $this->displayStatus("fullretrieved", 0); $this->displayStatus("verified", 0); $this->displayStatus("modcount", 0); $this->displayStatus("skipcount", 0); $this->displayStatus("loopcount", 0); } # else /* * Add the spots to the database and update the last article * number found */ $this->_db->addSpots($spotDbList, $fullSpotDbList); $this->debug('added Spots, spotDbList=' . serialize($spotDbList)); $this->debug('added Spots, fullSpotDbList=' . serialize($fullSpotDbList)); /* * Actually act on the moderation settings. We cannot process this inline * because a spot can be added and moderated within the same iteration */ switch ($this->_settings->get('spot_moderation')) { case 'disable': break; case 'markspot': $this->_db->markCommentsModerated($moderationList); $this->_db->markSpotsModerated($moderationList); break; # case 'markspot' # case 'markspot' default: $this->_db->removeSpots($moderationList); $this->_db->removeComments($moderationList); break; # default } # switch # update the maximum article id if ($this->_retro) { $this->_db->setMaxArticleid('spots_retro', $endMsg); } else { $this->_db->setMaxArticleid($this->_server['host'], $endMsg); } # if $this->debug('loop finished, setMaxArticleId=' . serialize($endMsg)); $this->displayStatus("timer", round(microtime(true) - $timer, 2)); return array('count' => count($hdrList), 'headercount' => $hdrsRetrieved, 'lastmsgid' => $lastProcessedId); }
function handleNzbAction($messageids, $action, $hdr_spotnntp, $nzb_spotnntp) { if (!is_array($messageids)) { $messageids = array($messageids); } # if # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $nzbList = array(); foreach ($messageids as $thisMsgId) { $fullSpot = $spotsOverview->getFullSpot($thisMsgId, $hdr_spotnntp); if (!empty($fullSpot['nzb'])) { $nzbList[] = array('spot' => $fullSpot, 'nzb' => $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp)); } # if } # foreach # nu we alle nzb files hebben, trekken we de 'file' secties eruit, # en plakken die in onze overkoepelende nzb switch ($this->_settings['nzbhandling']['prepare_action']) { case 'zip': $nzb = $this->zipNzbList($nzbList); $mimeType = 'application/x-zip-compressed'; $fileName = 'SpotWeb_' . microtime(true) . '.zip'; break; # zip # zip default: $nzb = $this->mergeNzbList($nzbList); $mimeType = 'application/x-nzb'; $fileName = urlencode($fullSpot['title']) . '.nzb'; break; # merge } # switch # handel dit alles af naar gelang de actie die gekozen is switch ($action) { case 'disable': break; # gewoon nzb file output geven # gewoon nzb file output geven case 'display': Header("Content-Type: " . $mimeType); Header("Content-Disposition: attachment; filename=\"" . $fileName . "\""); echo $nzb; break; # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat case 'save': $this->saveNzbFile($fullSpot, $nzb); break; case 'runcommand': $this->saveNzbFile($fullSpot, $nzb); $this->runCommand($fullSpot); break; # runcommand # runcommand case 'push-sabnzbd': $fileParams = array('content' => $nzb, 'name' => $fileName, 'mimetype' => $mimeType); $this->runHttp($fullSpot, $fileParams, $action); break; # push-sabnzbd # push-sabnzbd default: throw new Exception("Invalid action: " . $action); } # switch # en voeg hem toe aan de lijst met downloads if ($this->_settings['keep_downloadlist']) { foreach ($messageids as $thisMsgId) { $this->_db->addDownload($thisMsgId); } # foreach } # if }