public function processPasswordedReleases($echooutput = false) { $maxattemptstocheckpassworded = 5; $potentiallypasswordedfileregex = "/\\.(ace|cab|tar|gz)\$/i"; $numfound = 0; $numpasswd = 0; $numpot = 0; $numnone = 0; $db = new DB(); $nntp = new Nntp(); $rar = new RarInfo(); $rar->setMaxBytes(4000); if ($echooutput) { echo "Checking for passworded releases.\n\n"; } // // Get out all releases which have not been checked more than max attempts for password. // $result = $db->query(sprintf("select ID from releases where passwordstatus between %d and -1", ($maxattemptstocheckpassworded + 1) * -1)); if (count($result) > 0) { $nntp->doConnect(); foreach ($result as $row) { // // get out all files for this release, if it contains no rars, mark as Releases::PASSWD_NONE // if it contains rars, try and retrieve the message for the first rar and inspect its filename // if rar file is encrypted set as Releases::PASSWD_RAR, if it contains an ace/cab etc // mark as Releases::PASSWD_POTENTIAL, otherwise set as Releases::PASSWD_NONE. // $numfound++; // // Go through the binaries for this release looking for a rar // $binresult = $db->query(sprintf("select binaries.ID, binaries.name, groups.name as groupname from binaries inner join groups on groups.ID = binaries.groupID where releaseID = %d order by relpart", $row["ID"])); $msgid = -1; $bingroup = ""; foreach ($binresult as $binrow) { if (preg_match("/\\W(?:part0*1|(?!part\\d+)[^.]+)\\.rar(?!\\.)/i", $binrow["name"])) { $bingroup = $binrow["groupname"]; echo "Checking " . $binrow["name"] . " for password.\n"; $part = $db->queryOneRow(sprintf("select messageID from parts where binaryID = %d order by partnumber", $binrow["ID"])); if (isset($part["messageID"])) { $msgid = $part["messageID"]; break; } } } $passStatus = Releases::PASSWD_NONE; // // no part of binary found matching a rar, so it cant be progressed further // if ($msgid != -1) { $fetchedBinary = $nntp->getMessage($bingroup, $msgid); if ($fetchedBinary === false) { $db->query(sprintf("update releases set passwordstatus = passwordstatus - 1 where ID = %d", $row["ID"])); continue; } if ($rar->setData($fetchedBinary)) { // // whole archive password protected // if ($rar->isEncrypted) { $passStatus = Releases::PASSWD_RAR; } else { $files = $rar->getFileList(); foreach ($files as $file) { // // individual file rar passworded // if ($file['pass'] == true) { $passStatus = Releases::PASSWD_RAR; break; } else { if (preg_match($potentiallypasswordedfileregex, $file["name"])) { $passStatus = Releases::PASSWD_POTENTIAL; break; } } } } } } // // increment reporting stats // if ($passStatus == Releases::PASSWD_RAR) { $numpasswd++; } elseif ($passStatus == Releases::PASSWD_POTENTIAL) { $numpot++; } else { $numnone++; } $db->query(sprintf("update releases set passwordstatus = %d where ID = %d", $passStatus, $row["ID"])); } $nntp->doQuit(); } if ($echooutput) { echo sprintf("Finished checking for passwords for %d releases (%d passworded, %d potential, %d none).\n\n", $numfound, $numpasswd, $numpot, $numnone); } }
public function processAdditional() { $maxattemptstocheckpassworded = 5; $processSample = $this->site->ffmpegpath != '' ? true : false; $processMediainfo = $this->site->mediainfopath != '' ? true : false; $processPasswords = $this->site->unrarpath != '' ? true : false; $tmpPath = $this->site->tmpunrarpath; if (substr($tmpPath, -strlen('/')) != '/') { $tmpPath = $tmpPath . '/'; } $db = new DB(); $nntp = new Nntp(); // // Get out all releases which have not been checked more than max attempts for password. // $result = $db->query(sprintf("select r.ID, r.guid, r.name, c.disablepreview from releases r \n\t\t\tleft join category c on c.ID = r.categoryID\n\t\t\twhere (r.passwordstatus between %d and -1)\n\t\t\tor (r.haspreview = -1 and c.disablepreview = 0)\t\t\t\n\t\t", ($maxattemptstocheckpassworded + 1) * -1)); $rescount = sizeof($result); echo "Post-processing {$rescount} releases\n"; if ($rescount > 0) { $nntp->doConnect(); foreach ($result as $rel) { // Per release defaults $passStatus = array(Releases::PASSWD_NONE); $blnTookMediainfo = false; $blnTookSample = $rel['disablepreview'] == 1 ? true : false; //only attempt sample if not disabled if ($blnTookSample) { $db->query(sprintf("update releases set haspreview = 0 where id = %d", $rel['ID'])); } // // Go through the binaries for this release looking for a rar, a sample, and a mediafile // $sql = sprintf("select binaries.ID, binaries.name, groups.name as groupname from binaries inner join groups on groups.ID = binaries.groupID where releaseID = %d order by relpart", $rel["ID"]); $binresult = $db->query($sql); $msgid = array(); $samplemsgid = $mediamsgid = -1; $bingroup = $samplegroup = $mediagroup = ""; $norar = 0; echo "\n" . $rel['name'] . " has " . sizeof($binresult) . " binaries\n"; foreach ($binresult as $binrow) { if (preg_match("/\\W\\.r00/i", $binrow["name"])) { $norar = 1; } if (preg_match("/sample/i", $binrow["name"]) && !preg_match("/\\.par2|\\.srs/i", $binrow["name"])) { echo "Detected sample file " . $binrow["name"] . "\n"; $samplepart = $db->queryOneRow(sprintf("select messageID from parts where binaryID = %d order by partnumber limit 1", $binrow["ID"])); if (isset($samplepart["messageID"])) { $samplegroup = $binrow["groupname"]; $samplemsgid = $samplepart["messageID"]; } } if (preg_match('/\\.(' . $this->mediafileregex . ')[\\. "\\)\\]]/i', $binrow["name"]) && !preg_match("/\\.par2|\\.srs/i", $binrow["name"])) { $mediapart = $db->queryOneRow(sprintf("select messageID from parts where binaryID = %d order by partnumber limit 1", $binrow["ID"])); if (isset($mediapart["messageID"]) && $mediapart['messageID'] != $samplemsgid) { echo "Detected media file " . $binrow["name"] . "\n"; $mediagroup = $binrow["groupname"]; $mediamsgid = $mediapart["messageID"]; } } if (preg_match("/\\W(?:part0*1|(?!part\\d+)[^.]+)\\.rar(?!\\.)/i", $binrow["name"]) && !preg_match("/[-_\\.]sub/i", $binrow["name"])) { echo "Detected RAR " . $binrow["name"] . "\n"; $part = $db->queryOneRow(sprintf("select messageID from parts where binaryID = %d order by partnumber limit 1", $binrow["ID"])); if (isset($part["messageID"])) { $bingroup = $binrow["groupname"]; $msgid[] = $part["messageID"]; } } } // attempt to process sample file if ($samplemsgid != -1 && $processSample && $blnTookSample === false) { echo "Processing Sample\n"; echo "-Fetching binary {$samplemsgid}\n"; $sampleBinary = $nntp->getMessage($samplegroup, $samplemsgid); if ($sampleBinary === false) { echo "-Couldnt fetch binary {$samplemsgid}\n"; $samplemsgid = -1; } else { $samplefile = $tmpPath . 'sample.avi'; file_put_contents($samplefile, $sampleBinary); $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); if ($blnTookSample) { $this->updateReleaseHasPreview($rel['guid']); } unlink($samplefile); } unset($sampleBinary); } // attempt to process loose media file if ($mediamsgid != -1 && ($processSample && $blnTookSample === false || $processMediainfo)) { echo "Processing loose media file\n"; echo "-Fetching binary {$mediamsgid}\n"; $mediaBinary = $nntp->getMessage($mediagroup, $mediamsgid); if ($mediaBinary === false) { echo "-Couldnt fetch binary {$mediamsgid}\n"; $mediamsgid = -1; // can't get the media so we'll try from the .rar } else { $mediafile = $tmpPath . 'sample.avi'; file_put_contents($mediafile, $mediaBinary); if ($processSample && $blnTookSample === false) { $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); if ($blnTookSample) { $this->updateReleaseHasPreview($rel['guid']); } } if ($processMediainfo) { $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']); } unlink($mediafile); } unset($mediaBinary); } if (!empty($msgid) && ($this->site->checkpasswordedrar > 0 || $processSample && $blnTookSample === false || $processMediainfo)) { echo "Processing RAR files\n"; $mysqlkeepalive = 0; foreach ($msgid as $mid) { echo "-Fetching binary " . $mid . " (" . ++$mysqlkeepalive . ")\n"; $fetchedBinary = $nntp->getMessage($bingroup, $mid); if ($fetchedBinary === false) { echo "-Failed fetching binary\n"; $db->query(sprintf("update releases set passwordstatus = passwordstatus - 1 where ID = %d", $rel['ID'])); continue; } else { $relFiles = $this->processReleaseFiles($fetchedBinary, $rel['ID']); if ($this->site->checkpasswordedrar > 0 && $processPasswords) { $passStatus[] = $this->processReleasePasswords($fetchedBinary, $tmpPath, $this->site->unrarpath, $this->site->checkpasswordedrar); } // we need to unrar the fetched binary if checkpasswordedrar wasnt 2 if ($this->site->checkpasswordedrar < 2 && $processPasswords) { $rarfile = $tmpPath . 'rarfile.rar'; file_put_contents($rarfile, $fetchedBinary); $execstring = '"' . $this->site->unrarpath . '" e -ai -ep -c- -id -r -kb -p- -y -inul "' . $rarfile . '" "' . $tmpPath . '"'; $output = runCmd($execstring); unlink($rarfile); } if ($processSample && $blnTookSample === false) { $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); if ($blnTookSample) { $this->updateReleaseHasPreview($rel['guid']); } } if ($processMediainfo && $blnTookMediainfo === false) { $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']); } if ($mysqlkeepalive % 25 == 0) { $db->query("select 1"); } } //clean up all files foreach (glob($tmpPath . '*') as $v) { unlink($v); } } //end foreach msgid } elseif (empty($msgid) && $norar == 1) { $passStatus[] = Releases::PASSWD_POTENTIAL; } $hpsql = ''; if (!$blnTookSample) { $hpsql = ', haspreview = 0'; } $sql = sprintf("update releases set passwordstatus = %d %s where ID = %d", max($passStatus), $hpsql, $rel["ID"]); $db->query($sql); } //end foreach result $nntp->doQuit(); } }