diff --git a/README.md b/README.md index 81472d9a6..ea81ca2a4 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,9 @@ # SETUP -<<<<<<< HEAD - * These scripts were written and tested on Ubuntu 12.10 where bash is located at /bin/bash. You may need to create a symlink or edit these scripts accordingly. - -======= * tmux 1.6 or newer is needed to runs these scripts. This script relies on tmux reporting that the "Pane is dead". That is how the script knows that is nothing running in that pane and to restart it for another loop. Seeing "Pane is dead" is normal and expected. * These scripts were written and tested on Ubuntu 12.10 where bash is located at /bin/bash. You may need to create a symlink or edit these scripts accordingly. ->>>>>>> dev * Please backup your database first. Something like this should do it. ```bash diff --git a/bin/cleanup_scripts.sh b/bin/cleanup_scripts.sh deleted file mode 100755 index 2daaf234b..000000000 --- a/bin/cleanup_scripts.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh - -LASTOPTIMIZE1=`date +%s` -LASTOPTIMIZE2=`date +%s` -LASTOPTIMIZE3=`date +%s` -LASTOPTIMIZE4=`date +%s` -i=1 -while [ $i -gt 0 ] - - do - -#create releases from binaries -cd $NEWZNAB_PATH -[ -f update_releases.php ] && $PHP update_releases.php - -CURRTIME=`date +%s` -#every 15 minutes and during first loop -DIFF=$(($CURRTIME-$LASTOPTIMIZE1)) -if [ "$DIFF" -gt 900 ] || [ $i -eq 1 ] -then - LASTOPTIMIZE1=`date +%s` - cd $NEWZNAB_PATH - [ -f update_predb.php ] && $PHP update_predb.php true -fi - -CURRTIME=`date +%s` -#every 2 hours and during first loop -DIFF=$(($CURRTIME-$LASTOPTIMIZE2)) -if [ "$DIFF" -gt 7200 ] || [ $i -eq 1 ] -then - LASTOPTIMIZE2=`date +%s` - cd $TESTING_PATH - [ -f update_parsing.php ] && $PHP update_parsing.php - [ -f removespecial.php ] && $PHP removespecial.php - if [[ $CLEANUP == "true" ]]; then - [ -f update_cleanup.php ] && $PHP update_cleanup.php - fi -fi - -CURRTIME=`date +%s` -#every 12 hours -DIFF=$(($CURRTIME-$LASTOPTIMIZE3)) -if [ "$DIFF" -gt 43200 ] -then - LASTOPTIMIZE3=`date +%s` - cd $NEWZNAB_PATH - [ -f optimise_db.php ] && $PHP optimise_db.php -fi - -CURRTIME=`date +%s` -#every 12 hours and during 1st loop -DIFF=$(($CURRTIME-$LASTOPTIMIZE4)) -if [ "$DIFF" -gt 43200 ] || [ $i -eq 1 ] -then - LASTOPTIMIZE4=`date +%s` - cd $NEWZNAB_PATH - [ -f update_tvschedule.php ] && $PHP update_tvschedule.php - [ -f update_theaters.php ] && $PHP update_theaters.php -fi - -i=`expr $i + 1` -echo "waiting $NEWZNAB_POST_SLEEP_TIME seconds..." -sleep $NEWZNAB_POST_SLEEP_TIME - -done diff --git a/bin/innodb/lib/backfill.php b/bin/innodb/lib/backfill.php new file mode 100755 index 000000000..6e34c2d7c --- /dev/null +++ b/bin/innodb/lib/backfill.php @@ -0,0 +1,300 @@ +db = new DB(); + } + else + { + $this->db = $db; + } + $this->n = "\n"; + } + + /** + * Update all active groups categories and descriptions. + */ + function backfillAllGroups($groupName='', $backfillDate=null) + { + $n = $this->n; + $groups = new Groups; + $res = false; + if ($groupName != '') + { + $grp = $groups->getByName($groupName); + if ($grp) + $res = array($grp); + } + else + { + $res = $groups->getActive(); + } + + if ($res) + { + $nntp = new Nntp(); + $nntp->doConnect(); + + foreach($res as $groupArr) + { + $this->backfillGroup($nntp, $groupArr, $backfillDate); + } + + $nntp->doQuit(); + } + else + { + echo "No groups specified. Ensure groups are added to newznab's database for updating.$n"; + } + } + + /** + * Update a group back to a specified date. + */ + function backfillGroup($nntp, $groupArr, $backfillDate=null) + { + $this->db->disableAutoCommit(); //Turn off auto committing + + $binaries = new Binaries($this->db); + + $n = $this->n; + $this->startGroup = microtime(true); + + echo 'Processing '.$groupArr['name'].$n; + + $data = $nntp->selectGroup($groupArr['name']); + if(PEAR::isError($data)) + { + echo "Could not select group (bad name?): {$groupArr['name']}$n"; + + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return; + } + if ($backfillDate) + $targetpost = $this->daytopost($nntp,$groupArr['name'],$this->dateToDays($backfillDate),TRUE); // get targetpost based on date + else + $targetpost = $this->daytopost($nntp,$groupArr['name'],$groupArr['backfill_target'],TRUE); //get targetpost based on days target + if($groupArr['first_record'] == 0 || $groupArr['backfill_target'] == 0) + { + echo "Group ".$groupArr['name']." has invalid numbers. Have you run update on it? Have you set the backfill days amount?$n"; + + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return; + } + + echo "Group ".$data["group"].": server has ".$data['first']." - ".$data['last'].", or ~"; + echo((int) (($this->postdate($nntp,$data['last'],FALSE) - $this->postdate($nntp,$data['first'],FALSE))/86400)); + echo " days.".$n."Local first = ".$groupArr['first_record']." ("; + echo((int) ((date('U') - $this->postdate($nntp,$groupArr['first_record'],FALSE))/86400)); + echo " days). Backfill target of ".$groupArr['backfill_target']."days is post $targetpost.$n"; + + if($targetpost >= $groupArr['first_record']) //if our estimate comes back with stuff we already have, finish + { + echo "Nothing to do, we already have the target post.$n $n"; + + $this->db->commit(); //Not an error so commit and re-enable autocommitting + $this->db->enableAutoCommit(); + return ""; + } + //get first and last part numbers from newsgroup + if($targetpost < $data['first']) + { + echo "WARNING: Backfill came back as before server's first. Setting targetpost to server first.$n"; + echo "Skipping Group $n"; + + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return ""; + } + //calculate total number of parts + $total = $groupArr['first_record'] - $targetpost; + $done = false; + //set first and last, moving the window by maxxMssgs + $last = $groupArr['first_record'] - 1; + $first = $last - $binaries->messagebuffer + 1; //set initial "chunk" + if($targetpost > $first) //just in case this is the last chunk we needed + $first = $targetpost; + while($done === false) + { + $binaries->startLoop = microtime(true); + echo "Getting ".($last-$first+1)." parts (".($first-$targetpost)." in queue)".$n; + flush(); + $success = $binaries->scan($nntp, $groupArr, $first, $last, 'backfill'); + if (!$success) + { + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return ""; + } + + $this->db->mysqliQuery(sprintf("UPDATE groups SET first_record = %s, last_updated = now() WHERE ID = %d", $this->db->escapeString($first), $groupArr['ID'])); + + $this->db->commit(); //At this point we are ready to commit a set up updates to the db. + + if($first==$targetpost) + $done = true; + else + { //Keep going: set new last, new first, check for last chunk. + $last = $first - 1; + $first = $last - $binaries->messagebuffer + 1; + if($targetpost > $first) + $first = $targetpost; + } + } + $first_record_postdate = $this->postdate($nntp,$first,false); + $this->db->mysqliQuery(sprintf("UPDATE groups SET first_record_postdate = FROM_UNIXTIME(".$first_record_postdate."), last_updated = now() WHERE ID = %d", $groupArr['ID'])); //Set group's first postdate + + $this->db->commit(); //Commit and re-enable auto committing we are done with this group. + $this->db->enableAutoCommit(); + + $timeGroup = number_format(microtime(true) - $this->startGroup, 2); + echo "Group processed in $timeGroup seconds $n"; + } + + /** + * Returns single timestamp from a local article number. + */ + function postdate($nntp,$post,$debug=true) + { + $n = $this->n; + $attempts=0; + do + { + $msgs = $nntp->getOverview($post."-".$post,true,false); + if(PEAR::isError($msgs)) + { + echo "Error {$msgs->code}: {$msgs->message}$n"; + echo "Returning from postdate$n"; + return ""; + } + + if(!isset($msgs[0]['Date']) || $msgs[0]['Date']=="" || is_null($msgs[0]['Date'])) + { + $success=false; + } else { + $date = $msgs[0]['Date']; + $success=true; + } + if($debug && $attempts > 0) echo "retried $attempts time(s)".$n; + $attempts++; + } while($attempts <= 3 && $success == false); + + if (!$success) { return ""; } + + if($debug) echo "DEBUG: postdate for post: $post came back $date ("; + $date = strtotime($date); + if($debug) echo "$date seconds unixtime or ".$this->daysOld($date)." days)".$n; + return $date; + } + + /** + * Calculates the post number for a given number of days back in a group. + */ + function daytopost($nntp, $group, $days, $debug=true) + { + $n = $this->n; + $pddebug = false; //DEBUG every postdate call?!?! + if ($debug) echo "INFO: daytopost finding post for $group $days days back.".$n; + + $data = $nntp->selectGroup($group); + if(PEAR::isError($data)) + { + echo "Error {$data->code}: {$data->message}$n"; + echo "Returning from daytopost$n"; + return ""; + } + $goaldate = date('U')-(86400*$days); //goaltimestamp + $totalnumberofarticles = $data['last'] - $data['first']; + $upperbound = $data['last']; + $lowerbound = $data['first']; + + if ($debug) echo "Total Articles: $totalnumberofarticles $n Upper: $upperbound $n Lower: $lowerbound $n Goal: ".date("r", $goaldate)." ($goaldate) $n"; + if ($data['last']==PHP_INT_MAX) { echo "ERROR: Group data is coming back as php's max value. You should not see this since we use a patched Net_NNTP that fixes this bug.$n"; die(); } + + $firstDate = $this->postdate($nntp, $data['first'], $pddebug); + $lastDate = $this->postdate($nntp, $data['last'], $pddebug); + if ($goaldate < $firstDate) + { + echo "WARNING: Backfill target of $days day(s) is older than the first article stored on your news server.$n"; + echo "Starting from the first available article (".date("r", $firstDate)." or ".$this->daysOld($firstDate)." days).$n"; + return $data['first']; + } + elseif ($goaldate > $lastDate) + { + echo "ERROR: Backfill target of $days day(s) is newer than the last article stored on your news server.$n"; + echo "To backfill this group you need to set Backfill Days to at least ".ceil($this->daysOld($lastDate)+1)." days (".date("r", $lastDate-86400).").$n"; + return ""; + } + if ($debug) echo "DEBUG: Searching for postdate $n Goaldate: $goaldate (".date("r", $goaldate).") $n Firstdate: $firstDate (".((is_int($firstDate))?date("r", $firstDate):'n/a').") $n Lastdate: $lastDate (".date("r", $lastDate).") $n"; + + $interval = floor(($upperbound - $lowerbound) * 0.5); + $dateofnextone = ""; + $templowered = ""; + + if ($debug) echo "Start: ".$data['first']." $n End: ".$data['last']." $n Interval: $interval $n"; + + $dateofnextone = $lastDate; + + while($this->daysOld($dateofnextone) < $days) //match on days not timestamp to speed things up + { + $nskip = 1; + while(($tmpDate = $this->postdate($nntp,($upperbound-$interval),$pddebug))>$goaldate) + { + $upperbound = $upperbound - $interval - ($nskip - 1); + if($debug) echo "New upperbound ($upperbound) is ".$this->daysOld($tmpDate)." days old. $n"; + $nskip = $nskip * 2; + } + if(!$templowered) + { + $interval = ceil(($interval/2)); + if($debug) echo "Set interval to $interval articles. $n"; + } + $dateofnextone = $this->postdate($nntp,($upperbound-1),$pddebug); + + $skip = 1; + while(!$dateofnextone) + { + $upperbound = $upperbound - $skip; + $skip = $skip * 2; + if($debug) echo "Getting next article date... $upperbound\n"; + $dateofnextone = $this->postdate($nntp,($upperbound-1),$pddebug); + } + } + echo "Determined to be article $upperbound which is ".$this->daysOld($dateofnextone)." days old (".date("r", $dateofnextone).") $n"; + return $upperbound; + } + + /** + * Calculate the number of days from a timestamp. + */ + private function daysOld($timestamp) + { + return round((time()-$timestamp)/86400, 1); + } + + /** + * Calculate the number of days from a date. + */ + private function dateToDays($backfillDate) + { + return floor(-($backfillDate - time())/(60*60*24)); + } +} diff --git a/bin/innodb/lib/groups.php b/bin/innodb/lib/groups.php new file mode 100755 index 000000000..571f5b5bb --- /dev/null +++ b/bin/innodb/lib/groups.php @@ -0,0 +1,27 @@ +query("SELECT * FROM groups WHERE active = 1 ORDER BY name"); + } + + /** + * Get a group row by name. + */ + public function getByName($grp) + { + $db = new DB(); + return $db->queryOneRow(sprintf("select * from groups where name = '%s' ", $grp)); + } + +} diff --git a/bin/innodb/lib/innodb/backfill.php b/bin/innodb/lib/innodb/backfill.php new file mode 100755 index 000000000..b91a5bc0e --- /dev/null +++ b/bin/innodb/lib/innodb/backfill.php @@ -0,0 +1,300 @@ +db = new DB(); + } + else + { + $this->db = $db; + } + $this->n = "\n"; + } + + /** + * Update all active groups categories and descriptions. + */ + function backfillAllGroups($groupName='', $backfillDate=null) + { + $n = $this->n; + $groups = new Groups; + $res = false; + if ($groupName != '') + { + $grp = $groups->getByName($groupName); + if ($grp) + $res = array($grp); + } + else + { + $res = $groups->getActive(); + } + + if ($res) + { + $nntp = new Nntp(); + $nntp->doConnect(); + + foreach($res as $groupArr) + { + $this->backfillGroup($nntp, $groupArr, $backfillDate); + } + + $nntp->doQuit(); + } + else + { + echo "No groups specified. Ensure groups are added to newznab's database for updating.$n"; + } + } + + /** + * Update a group back to a specified date. + */ + function backfillGroup($nntp, $groupArr, $backfillDate=null) + { + $this->db->disableAutoCommit(); //Turn off auto committing + + $binaries = new Binaries($this->db); + + $n = $this->n; + $this->startGroup = microtime(true); + + echo 'Processing '.$groupArr['name'].$n; + + $data = $nntp->selectGroup($groupArr['name']); + if(PEAR::isError($data)) + { + echo "Could not select group (bad name?): {$groupArr['name']}$n"; + + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return; + } + if ($backfillDate) + $targetpost = $this->daytopost($nntp,$groupArr['name'],$this->dateToDays($backfillDate),TRUE); // get targetpost based on date + else + $targetpost = $this->daytopost($nntp,$groupArr['name'],$groupArr['backfill_target'],TRUE); //get targetpost based on days target + if($groupArr['first_record'] == 0 || $groupArr['backfill_target'] == 0) + { + echo "Group ".$groupArr['name']." has invalid numbers. Have you run update on it? Have you set the backfill days amount?$n"; + + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return; + } + + echo "Group ".$data["group"].": server has ".$data['first']." - ".$data['last'].", or ~"; + echo((int) (($this->postdate($nntp,$data['last'],FALSE) - $this->postdate($nntp,$data['first'],FALSE))/86400)); + echo " days.".$n."Local first = ".$groupArr['first_record']." ("; + echo((int) ((date('U') - $this->postdate($nntp,$groupArr['first_record'],FALSE))/86400)); + echo " days). Backfill target of ".$groupArr['backfill_target']."days is post $targetpost.$n"; + + if($targetpost >= $groupArr['first_record']) //if our estimate comes back with stuff we already have, finish + { + echo "Nothing to do, we already have the target post.$n $n"; + + $this->db->commit(); //Not an error so commit and re-enable autocommitting + $this->db->enableAutoCommit(); + return ""; + } + //get first and last part numbers from newsgroup + if($targetpost < $data['first']) + { + echo "WARNING: Backfill came back as before server's first. Setting targetpost to server first.$n"; + echo "Skipping Group $n"; + + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return ""; + } + //calculate total number of parts + $total = $groupArr['first_record'] - $targetpost; + $done = false; + //set first and last, moving the window by maxxMssgs + $last = $groupArr['first_record'] - 1; + $first = $last - $binaries->messagebuffer + 1; //set initial "chunk" + if($targetpost > $first) //just in case this is the last chunk we needed + $first = $targetpost; + while($done === false) + { + $binaries->startLoop = microtime(true); + echo "Getting ".($last-$first+1)." parts (".($first-$targetpost)." in queue)".$n; + flush(); + $success = $binaries->scan($nntp, $groupArr, $first, $last, 'backfill'); + if (!$success) + { + $this->db->rollback(); //Rollback and re-enable autocommitting + $this->db->enableAutoCommit(); + return ""; + } + + $this->db->mysqliQuery(sprintf("UPDATE groups SET first_record = %s, last_updated = now() WHERE ID = %d", $this->db->escapeString($first), $groupArr['ID'])); + + $this->db->commit(); //At this point we are ready to commit a set up updates to the db. + + if($first==$targetpost) + $done = true; + else + { //Keep going: set new last, new first, check for last chunk. + $last = $first - 1; + $first = $last - $binaries->messagebuffer + 1; + if($targetpost > $first) + $first = $targetpost; + } + } + $first_record_postdate = $this->postdate($nntp,$first,false); + $this->db->mysqliQuery(sprintf("UPDATE groups SET first_record_postdate = FROM_UNIXTIME(".$first_record_postdate."), last_updated = now() WHERE ID = %d", $groupArr['ID'])); //Set group's first postdate + + $this->db->commit(); //Commit and re-enable auto committing we are done with this group. + $this->db->enableAutoCommit(); + + $timeGroup = number_format(microtime(true) - $this->startGroup, 2); + echo "Group processed in $timeGroup seconds $n"; + } + + /** + * Returns single timestamp from a local article number. + */ + function postdate($nntp,$post,$debug=true) + { + $n = $this->n; + $attempts=0; + do + { + $msgs = $nntp->getOverview($post."-".$post,true,false); + if(PEAR::isError($msgs)) + { + echo "Error {$msgs->code}: {$msgs->message}$n"; + echo "Returning from postdate$n"; + return ""; + } + + if(!isset($msgs[0]['Date']) || $msgs[0]['Date']=="" || is_null($msgs[0]['Date'])) + { + $success=false; + } else { + $date = $msgs[0]['Date']; + $success=true; + } + if($debug && $attempts > 0) echo "retried $attempts time(s)".$n; + $attempts++; + } while($attempts <= 3 && $success == false); + + if (!$success) { return ""; } + + if($debug) echo "DEBUG: postdate for post: $post came back $date ("; + $date = strtotime($date); + if($debug) echo "$date seconds unixtime or ".$this->daysOld($date)." days)".$n; + return $date; + } + + /** + * Calculates the post number for a given number of days back in a group. + */ + function daytopost($nntp, $group, $days, $debug=true) + { + $n = $this->n; + $pddebug = false; //DEBUG every postdate call?!?! + if ($debug) echo "INFO: daytopost finding post for $group $days days back.".$n; + + $data = $nntp->selectGroup($group); + if(PEAR::isError($data)) + { + echo "Error {$data->code}: {$data->message}$n"; + echo "Returning from daytopost$n"; + return ""; + } + $goaldate = date('U')-(86400*$days); //goaltimestamp + $totalnumberofarticles = $data['last'] - $data['first']; + $upperbound = $data['last']; + $lowerbound = $data['first']; + + if ($debug) echo "Total Articles: $totalnumberofarticles $n Upper: $upperbound $n Lower: $lowerbound $n Goal: ".date("r", $goaldate)." ($goaldate) $n"; + if ($data['last']==PHP_INT_MAX) { echo "ERROR: Group data is coming back as php's max value. You should not see this since we use a patched Net_NNTP that fixes this bug.$n"; die(); } + + $firstDate = $this->postdate($nntp, $data['first'], $pddebug); + $lastDate = $this->postdate($nntp, $data['last'], $pddebug); + if ($goaldate < $firstDate) + { + echo "WARNING: Backfill target of $days day(s) is older than the first article stored on your news server.$n"; + echo "Starting from the first available article (".date("r", $firstDate)." or ".$this->daysOld($firstDate)." days).$n"; + return $data['first']; + } + elseif ($goaldate > $lastDate) + { + echo "ERROR: Backfill target of $days day(s) is newer than the last article stored on your news server.$n"; + echo "To backfill this group you need to set Backfill Days to at least ".ceil($this->daysOld($lastDate)+1)." days (".date("r", $lastDate-86400).").$n"; + return ""; + } + if ($debug) echo "DEBUG: Searching for postdate $n Goaldate: $goaldate (".date("r", $goaldate).") $n Firstdate: $firstDate (".((is_int($firstDate))?date("r", $firstDate):'n/a').") $n Lastdate: $lastDate (".date("r", $lastDate).") $n"; + + $interval = floor(($upperbound - $lowerbound) * 0.5); + $dateofnextone = ""; + $templowered = ""; + + if ($debug) echo "Start: ".$data['first']." $n End: ".$data['last']." $n Interval: $interval $n"; + + $dateofnextone = $lastDate; + + while($this->daysOld($dateofnextone) < $days) //match on days not timestamp to speed things up + { + $nskip = 1; + while(($tmpDate = $this->postdate($nntp,($upperbound-$interval),$pddebug))>$goaldate) + { + $upperbound = $upperbound - $interval - ($nskip - 1); + if($debug) echo "New upperbound ($upperbound) is ".$this->daysOld($tmpDate)." days old. $n"; + $nskip = $nskip * 2; + } + if(!$templowered) + { + $interval = ceil(($interval/2)); + if($debug) echo "Set interval to $interval articles. $n"; + } + $dateofnextone = $this->postdate($nntp,($upperbound-1),$pddebug); + + $skip = 1; + while(!$dateofnextone) + { + $upperbound = $upperbound - $skip; + $skip = $skip * 2; + if($debug) echo "Getting next article date... $upperbound\n"; + $dateofnextone = $this->postdate($nntp,($upperbound-1),$pddebug); + } + } + echo "Determined to be article $upperbound which is ".$this->daysOld($dateofnextone)." days old (".date("r", $dateofnextone).") $n"; + return $upperbound; + } + + /** + * Calculate the number of days from a timestamp. + */ + private function daysOld($timestamp) + { + return round((time()-$timestamp)/86400, 1); + } + + /** + * Calculate the number of days from a date. + */ + private function dateToDays($backfillDate) + { + return floor(-($backfillDate - time())/(60*60*24)); + } +} diff --git a/bin/innodb/lib/innodb/binaries.php b/bin/innodb/lib/innodb/binaries.php new file mode 100755 index 000000000..0179b2d02 --- /dev/null +++ b/bin/innodb/lib/innodb/binaries.php @@ -0,0 +1,741 @@ +n = "\n"; + + $s = new Sites(); + $site = $s->get(); + $this->compressedHeaders = ($site->compressedheaders == "1") ? true : false; + $this->messagebuffer = (!empty($site->maxmssgs)) ? $site->maxmssgs : 20000; + $this->NewGroupScanByDays = ($site->newgroupscanmethod == "1") ? true : false; + $this->NewGroupMsgsToScan = (!empty($site->newgroupmsgstoscan)) ? $site->newgroupmsgstoscan : 50000; + $this->NewGroupDaysToScan = (!empty($site->newgroupdaystoscan)) ? $site->newgroupdaystoscan : 3; + + $this->blackList = array(); //cache of our black/white list + $this->message = array(); + + if($db == null) + { + $this->db = new DB(); + } + else + { + $this->db = $db; + } + + } + + /* + * Allows you to set the db that the current object should use + */ + public function setDB($db) + { + $this->db = $db; + } + + /** + * Process headers and store in database for all active groups. + */ + function updateAllGroups() + { + $n = $this->n; + $groups = new Groups; + $res = $groups->getActive(); + + $s = new Sites(); + echo $s->getLicense(); + + if ($res) + { + shuffle($res); + $alltime = microtime(true); + echo 'Updating: '.sizeof($res).' groups - Using compression? '.(($this->compressedHeaders)?'Yes':'No').$n; + + $nntp = new Nntp(); + $nntp->doConnect(); + + $pos = 0; + foreach($res as $groupArr) + { + $pos++; + echo 'Group '.$pos.' of '.sizeof($res).$n; + $this->message = array(); + $this->updateGroup($nntp, $groupArr); + } + + $nntp->doQuit(); + echo 'Updating completed in '.number_format(microtime(true) - $alltime, 2).' seconds'.$n; + } + else + { + echo "No groups specified. Ensure groups are added to newznab's database and activated before updating.$n"; + } + } + + /** + * Process headers and store in database for a group. + */ + function updateGroup($nntp=null, $groupArr) + { + $this->db->disableAutoCommit(); + + $blnDoDisconnect = false; + if ($nntp == null) + { + $nntp = new Nntp(); + $nntp->doConnect(); + $this->message = array(); + $blnDoDisconnect = true; + } + + $backfill = new Backfill(); + $n = $this->n; + $this->startGroup = microtime(true); + + echo 'Processing '.$groupArr['name'].$n; + + // Connect to server + $data = $nntp->selectGroup($groupArr['name']); + if (PEAR::isError($data)) + { + echo "Could not select group (bad name?): {$groupArr['name']}$n"; + + $this->db->rollback(); //Rollback and re-enable auto committing + $this->db->enableAutoCommit(); + return; + } + + //Attempt to repair any missing parts before grabbing new ones + $this->partRepair($nntp, $groupArr); + + //Get first and last part numbers from newsgroup + $last = $grouplast = $data['last']; + + // For new newsgroups - determine here how far you want to go back. + if ($groupArr['last_record'] == 0) + { + if ($this->NewGroupScanByDays) + { + $first = $backfill->daytopost($nntp, $groupArr['name'], $this->NewGroupDaysToScan, true); + if ($first == '') + { + echo "Skipping group: {$groupArr['name']}$n"; + + $this->db->rollback(); //Rollback and re-enable auto committing + $this->db->enableAutoCommit(); + return; + } + } + else + { + if ($data['first'] > ($data['last'] - $this->NewGroupMsgsToScan)) + $first = $data['first']; + else + $first = $data['last'] - $this->NewGroupMsgsToScan; + } + $first_record_postdate = $backfill->postdate($nntp, $first, false); + $this->db->mysqliQuery(sprintf("UPDATE groups SET first_record = %s, first_record_postdate = FROM_UNIXTIME(".$first_record_postdate.") WHERE ID = %d", $this->db->escapeString($first), $groupArr['ID'])); + } + else + { + if ($data['last'] < $groupArr['last_record']) + { + echo "Warning: Server's last num {$data['last']} is lower than the local last num {$groupArr['last_record']}".$n; + + $this->db->rollback(); //Rollback and re-enable auto committing + $this->db->enableAutoCommit(); + return; + } + $first = $groupArr['last_record'] + 1; + } + + // Generate postdates for first and last records, for those that upgraded + if ((is_null($groupArr['first_record_postdate']) || is_null($groupArr['last_record_postdate'])) && ($groupArr['last_record'] != "0" && $groupArr['first_record'] != "0")) + $this->db->mysqliQuery(sprintf("UPDATE groups SET first_record_postdate = FROM_UNIXTIME(".$backfill->postdate($nntp,$groupArr['first_record'],false)."), last_record_postdate = FROM_UNIXTIME(".$backfill->postdate($nntp,$groupArr['last_record'],false).") WHERE ID = %d", $groupArr['ID'])); + + // Deactivate empty groups + if (($data['last'] - $data['first']) <= 5) + $this->db->mysqliQuery(sprintf("UPDATE groups SET active = %s, last_updated = now() WHERE ID = %d", $this->db->escapeString('0'), $groupArr['ID'])); + + // Calculate total number of parts + $total = $grouplast - $first + 1; + + // If total is bigger than 0 it means we have new parts in the newsgroup + if($total > 0) + { + echo "Group ".$data["group"]." has ".number_format($total)." new parts.".$n; + echo "First: ".$data['first']." Last: ".$data['last']." Local last: ".$groupArr['last_record'].$n; + if ($groupArr['last_record'] == 0) + echo "New group starting with ".(($this->NewGroupScanByDays) ? $this->NewGroupDaysToScan." days" : $this->NewGroupMsgsToScan." messages")." worth.".$n; + + $done = false; + + // Get all the parts (in portions of $this->messagebuffer to not use too much memory) + while ($done === false) + { + $this->startLoop = microtime(true); + + if ($total > $this->messagebuffer) + { + if ($first + $this->messagebuffer > $grouplast) + $last = $grouplast; + else + $last = $first + $this->messagebuffer; + } + + echo "Getting ".number_format($last-$first+1)." parts (".$first." to ".$last.") - ".number_format($grouplast - $last)." in queue".$n; + flush(); + + //get headers from newsgroup + $lastId = $this->scan($nntp, $groupArr, $first, $last); + if ($lastId === false) + { + //scan failed - skip group + + $this->db->rollback(); //Rollback and re-enable auto committing + $this->db->enableAutoCommit(); + return; + } + $this->db->mysqliQuery(sprintf("UPDATE groups SET last_record = %s, last_updated = now() WHERE ID = %d", $this->db->escapeString($lastId), $groupArr['ID'])); + + $this->db->commit(); //At this point we are ready to commit a whole group to the db. + + if ($last == $grouplast) + $done = true; + else + { + $last = $lastId; + $first = $last + 1; + } + } + + $last_record_postdate = $backfill->postdate($nntp,$last,false); + $this->db->mysqliQuery(sprintf("UPDATE groups SET last_record_postdate = FROM_UNIXTIME(".$last_record_postdate."), last_updated = now() WHERE ID = %d", $groupArr['ID'])); //Set group's last postdate + $timeGroup = number_format(microtime(true) - $this->startGroup, 2); + echo "Group processed in $timeGroup seconds $n $n"; + } + else + { + echo "No new records for ".$data["group"]." (first $first last $last total $total) grouplast ".$groupArr['last_record'].$n.$n; + } + + if ($blnDoDisconnect) + { + $nntp->doQuit(); + } + + /* + * Got through the updating of this group successfully + * so commit and re-enable the auto committing. + */ + $this->db->commit(); //For anything not yet committed. + $this->db->enableAutoCommit(); + + } + + /** + * Download a range of usenet messages. Store binaries with subjects matching a + * specific pattern in the database. + */ + function scan($nntp, $groupArr, $first, $last, $type='update') + { + $n = $this->n; + $this->startHeaders = microtime(true); + + if ($this->compressedHeaders) + $msgs = $nntp->getXOverview($first."-".$last, true, false); + else + $msgs = $nntp->getOverview($first."-".$last, true, false); + + if (PEAR::isError($msgs) && $msgs->code == 400) + { + echo "NNTP connection timed out. Reconnecting...$n"; + $nntp->doConnect(); + $nntp->selectGroup($groupArr['name']); + if ($this->compressedHeaders) + $msgs = $nntp->getXOverview($first."-".$last, true, false); + else + $msgs = $nntp->getOverview($first."-".$last, true, false); + } + + $rangerequested = range($first, $last); + $msgsreceived = array(); + $msgsblacklisted = array(); + $msgsignored = array(); + $msgsinserted = array(); + $msgsnotinserted = array(); + + $timeHeaders = number_format(microtime(true) - $this->startHeaders, 2); + + if(PEAR::isError($msgs)) + { + echo "Error {$msgs->code}: {$msgs->message}$n"; + echo "Skipping group$n"; + return false; + } + + $this->startUpdate = microtime(true); + if (is_array($msgs)) + { + //loop headers, figure out parts + foreach($msgs AS $msg) + { + if (!isset($msg['Number'])) + continue; + + $msgsreceived[] = $msg['Number']; + $msgPart = $msgTotalParts = 0; + + $pattern = '|\((\d+)[\/](\d+)\)|i'; + preg_match_all($pattern, $msg['Subject'], $matches, PREG_PATTERN_ORDER); + $matchcnt = sizeof($matches[0]); + for ($i=0; $i<$matchcnt; $i++) + { + $msgPart = $matches[1][$i]; + $msgTotalParts = $matches[2][$i]; + } + + if (!isset($msg['Subject']) || $matchcnt == 0) // not a binary post most likely.. continue + { + $msgsignored[] = $msg['Number']; + continue; + } + + //Filter binaries based on black/white list + if ($this->isBlackListed($msg, $groupArr['name'])) + { + $msgsblacklisted[] = $msg['Number']; + continue; + } + + if((int)$msgPart > 0 && (int)$msgTotalParts > 0) + { + $subject = utf8_encode(trim(preg_replace('|\('.$msgPart.'[\/]'.$msgTotalParts.'\)|i', '', $msg['Subject']))); + + if(!isset($this->message[$subject])) + { + $this->message[$subject] = $msg; + $this->message[$subject]['MaxParts'] = (int) $msgTotalParts; + $this->message[$subject]['Date'] = strtotime($this->message[$subject]['Date']); + } + if((int)$msgPart > 0) + { + $this->message[$subject]['Parts'][(int)$msgPart] = array('Message-ID' => substr($msg['Message-ID'],1,-1), 'number' => $msg['Number'], 'part' => (int)$msgPart, 'size' => $msg['Bytes']); + } + } + } + unset($msg); + unset($msgs); + $count = 0; + $updatecount = 0; + $partcount = 0; + $maxnum = $last; + + $rangenotreceived = array_diff($rangerequested, $msgsreceived); + + + if ($type != 'partrepair') + echo "Received ".sizeof($msgsreceived)." articles of ".($last-$first+1)." requested, ".sizeof($msgsblacklisted)." blacklisted, ".sizeof($msgsignored)." not binaries $n"; + + if ($type == 'update' && sizeof($msgsreceived) == 0) + { + echo "Error: Server did not return any articles.$n"; + echo "Skipping group$n"; + return false; + } + + if (sizeof($rangenotreceived) > 0) { + switch($type) + { + case 'backfill': + //don't add missing articles + break; + case 'partrepair': + case 'update': + default: + $this->addMissingParts($rangenotreceived, $groupArr['ID']); + break; + } + echo "Server did not return ".count($rangenotreceived)." article(s).$n"; + } + + if(isset($this->message) && count($this->message)) + { + $maxnum = $first; + //insert binaries and parts into database. when binary already exists; only insert new parts + foreach($this->message AS $subject => $data) + { + if(isset($data['Parts']) && count($data['Parts']) > 0 && $subject != '') + { + $binaryHash = md5($subject.$data['From'].$groupArr['ID']); + $res = $this->db->mysqliQueryOneRow(sprintf("SELECT ID FROM binaries WHERE binaryhash = %s", $this->db->escapeString($binaryHash))); + if(!$res) + { + $sql = sprintf("INSERT INTO binaries (name, fromname, date, xref, totalparts, groupID, binaryhash, dateadded) VALUES (%s, %s, FROM_UNIXTIME(%s), %s, %s, %d, %s, now())", $this->db->escapeString($subject), $this->db->escapeString($data['From']), $this->db->escapeString($data['Date']), $this->db->escapeString($data['Xref']), $this->db->escapeString($data['MaxParts']), $groupArr['ID'], $this->db->escapeString($binaryHash)); + $binaryID = $this->db->mysqliQueryInsert($sql); + $count++; + if ($count%500==0) echo "$count bin adds..."; + } + else + { + $binaryID = $res["ID"]; + $updatecount++; + if ($updatecount%500==0) echo "$updatecount bin updates..."; + } + + foreach($data['Parts'] AS $partdata) + { + $maxnum = ($partdata['number'] > $maxnum) ? $partdata['number'] : $maxnum; + $partcount++; + $pidata = $this->db->mysqliQueryInsert(sprintf("INSERT INTO parts (binaryID, messageID, number, partnumber, size, dateadded) VALUES (%d, %s, %s, %s, %s, now())", $binaryID, $this->db->escapeString($partdata['Message-ID']), $this->db->escapeString($partdata['number']), $this->db->escapeString(round($partdata['part'])), $this->db->escapeString($partdata['size'])), false); + if (!$pidata) { + $msgsnotinserted[] = $partdata['number']; + } else { + $msgsinserted[] = $partdata['number']; + } + } + } + } + //TODO: determine whether to add to missing articles if insert failed + if (sizeof($msgsnotinserted) > 0) + { + echo 'WARNING: ' . count($msgsnotinserted) . ' Parts failed to insert'.$n; + $this->addMissingParts($msgsnotinserted, $groupArr['ID']); + } + if (($count >= 500) || ($updatecount >= 500)) { echo $n; } //line break for bin adds output + } + $timeUpdate = number_format(microtime(true) - $this->startUpdate, 2); + $timeLoop = number_format(microtime(true)-$this->startLoop, 2); + + if ($type != 'partrepair') + { + echo number_format($count).' new, '.number_format($updatecount).' updated, '.number_format($partcount).' parts.'; + echo " $timeHeaders headers, $timeUpdate update, $timeLoop range.$n"; + } + unset($this->message); + unset($data); + return $maxnum; + } + else + { + echo "Error: Can't get parts from server (msgs not array) $n"; + echo "Skipping group$n"; + return false; + } + } + + /** + * Go through all rows in partrepair table and see if theyve arrived on usenet yet. + */ + private function partRepair($nntp, $groupArr) + { + $n = $this->n; + + //get all parts in partrepair table + + $missingParts = $this->db->mysqliQuery(sprintf("SELECT * FROM partrepair WHERE groupID = %d AND attempts < 5 ORDER BY numberID ASC LIMIT 30000", $groupArr['ID'])); + $partsRepaired = $partsFailed = 0; + + if (sizeof($missingParts) > 0) + { + echo 'Attempting to repair '.sizeof($missingParts).' parts...'; + + //loop through each part to group into ranges + $ranges = array(); + $lastnum = $lastpart = 0; + foreach($missingParts as $part) + { + if (($lastnum+1) == $part['numberID']) { + $ranges[$lastpart] = $part['numberID']; + } else { + $lastpart = $part['numberID']; + $ranges[$lastpart] = $part['numberID']; + } + $lastnum = $part['numberID']; + } + + //download missing parts in ranges + foreach($ranges as $partfrom=>$partto) + { + $this->startLoop = microtime(true); + + echo "."; + + //get article from newsgroup + $this->scan($nntp, $groupArr, $partfrom, $partto, 'partrepair'); + + //check if the articles were added + $articles = implode(',', range($partfrom, $partto)); + $sql = sprintf("SELECT pr.ID, pr.numberID, p.number from partrepair pr LEFT JOIN parts p ON p.number = pr.numberID WHERE pr.groupID=%d AND pr.numberID IN (%s) ORDER BY pr.numberID ASC", $groupArr['ID'], $articles); + + $result = $this->db->mysqliQueryDirect($sql); + while ($r = mysqli_fetch_assoc($result)) + { + if (isset($r['number']) && $r['number'] == $r['numberID']) + { + $partsRepaired++; + + //article was added, delete from partrepair + $this->db->mysqliQuery(sprintf("DELETE FROM partrepair WHERE ID=%d", $r['ID'])); + } + else + { + $partsFailed++; + + //article was not added, increment attempts + $this->db->mysqliQuery(sprintf("UPDATE partrepair SET attempts=attempts+1 WHERE ID=%d", $r['ID'])); + } + } + } + + echo $n.$partsRepaired.' parts repaired.'.$n; + } + + //remove articles that we cant fetch after 5 attempts + $this->db->mysqliQuery(sprintf("DELETE FROM partrepair WHERE attempts >= 5 AND groupID = %d", $groupArr['ID'])); + + } + + /** + * Insert a missing part to the database. + */ + private function addMissingParts($numbers, $groupID) + { + + $added = false; + $insertStr = "INSERT INTO partrepair (numberID, groupID) VALUES "; + foreach($numbers as $number) + { + if ($number > 0) + { + $added = true; + $insertStr .= sprintf("(%u, %d), ", $number, $groupID); + } + } + if ($added) + { + $insertStr = substr($insertStr, 0, -2); + $insertStr .= " ON DUPLICATE KEY UPDATE attempts=attempts+1"; + return $this->db->mysqliQueryInsert($insertStr, false); + } + + return -1; + } + + /** + * Return internally cached list of binary blacklist patterns. + */ + public function retrieveBlackList() + { + if (is_array($this->blackList) && !empty($this->blackList)) { return $this->blackList; } + $blackList = $this->getBlacklist(true); + $this->blackList = $blackList; + return $blackList; + } + + /** + * Test if a message subject is blacklisted. + */ + public function isBlackListed($msg, $groupName) + { + $blackList = $this->retrieveBlackList(); + $field = array(); + if (isset($msg["Subject"])) + $field[Binaries::BLACKLIST_FIELD_SUBJECT] = $msg["Subject"]; + + if (isset($msg["From"])) + $field[Binaries::BLACKLIST_FIELD_FROM] = $msg["From"]; + + if (isset($msg["Message-ID"])) + $field[Binaries::BLACKLIST_FIELD_MESSAGEID] = $msg["Message-ID"]; + + foreach ($blackList as $blist) + { + if (preg_match('/^'.$blist['groupname'].'$/i', $groupName)) + { + //blacklist + if ($blist['optype'] == 1) + { + if (preg_match('/'.$blist['regex'].'/i', $field[$blist['msgcol']])) { + return true; + } + } + else if ($blist['optype'] == 2) + { + if (!preg_match('/'.$blist['regex'].'/i', $field[$blist['msgcol']])) { + return true; + } + } + } + } + + return false; + } + + /** + * Rawsearch. Perform a simple like match on binary subjects matching a pattern. + */ + public function search($search, $limit=1000, $excludedcats=array()) + { + + + // + // if the query starts with a ^ it indicates the search is looking for items which start with the term + // still do the like match, but mandate that all items returned must start with the provided word + // + $words = explode(" ", $search); + $searchsql = ""; + $intwordcount = 0; + if (count($words) > 0) + { + foreach ($words as $word) + { + // + // see if the first word had a caret, which indicates search must start with term + // + if ($intwordcount == 0 && (strpos($word, "^") === 0)) + $searchsql.= sprintf(" and b.name like %s", $this->db->escapeString(substr($word, 1)."%")); + else + $searchsql.= sprintf(" and b.name like %s", $this->db->escapeString("%".$word."%")); + + $intwordcount++; + } + } + + $exccatlist = ""; + if (count($excludedcats) > 0) + $exccatlist = " and b.categoryID not in (".implode(",", $excludedcats).") "; + + $res = $this->db->mysqliQuery(sprintf(" + SELECT b.*, + g.name AS group_name, + r.guid, + (SELECT COUNT(ID) FROM parts p where p.binaryID = b.ID) as 'binnum' + FROM binaries b + INNER JOIN groups g ON g.ID = b.groupID + LEFT OUTER JOIN releases r ON r.ID = b.releaseID + WHERE 1=1 %s %s order by DATE DESC LIMIT %d ", + $searchsql, $exccatlist, $limit)); + + return $res; + } + + /** + * Get all binaries for a release. + */ + public function getForReleaseId($id) + { + return $this->db->mysqliQuery(sprintf("select binaries.* from binaries where releaseID = %d order by relpart", $id)); + } + + /** + * Get a binary row. + */ + public function getById($id) + { + + return $this->db->mysqliQueryOneRow(sprintf("select binaries.*, groups.name as groupname from binaries left outer join groups on binaries.groupID = groups.ID where binaries.ID = %d ", $id)); + } + + /** + * Get list of blacklists from database. + */ + public function getBlacklist($activeonly=true) + { + + $where = ""; + if ($activeonly) + $where = " where binaryblacklist.status = 1 "; + + return $this->db->mysqliQuery("SELECT binaryblacklist.ID, binaryblacklist.optype, binaryblacklist.status, binaryblacklist.description, binaryblacklist.groupname AS groupname, binaryblacklist.regex, + groups.ID AS groupID, binaryblacklist.msgcol FROM binaryblacklist + left outer JOIN groups ON groups.name = binaryblacklist.groupname + ".$where." + ORDER BY coalesce(groupname,'zzz')"); + } + + /** + * Get a blacklist row from database. + */ + public function getBlacklistByID($id) + { + return $this->db->mysqliQueryOneRow(sprintf("select * from binaryblacklist where ID = %d ", $id)); + } + + /** + * Delete a blacklist row from database. + */ + public function deleteBlacklist($id) + { + + return $this->db->mysqliQuery(sprintf("delete from binaryblacklist where ID = %d", $id)); + } + + /** + * Update a blacklist row. + */ + public function updateBlacklist($regex) + { + + $groupname = $regex["groupname"]; + if ($groupname == "") + $groupname = "null"; + else + { + $groupname = preg_replace("/a\.b\./i", "alt.binaries.", $groupname); + $groupname = sprintf("%s", $this->db->escapeString($groupname)); + } + + $this->db->mysqliQuery(sprintf("update binaryblacklist set groupname=%s, regex=%s, status=%d, description=%s, optype=%d, msgcol=%d where ID = %d ", $groupname, $this->db->escapeString($regex["regex"]), $regex["status"], $this->db->escapeString($regex["description"]), $regex["optype"], $regex["msgcol"], $regex["id"])); + } + + /** + * Add a new blacklist row. + */ + public function addBlacklist($regex) + { + + + $groupname = $regex["groupname"]; + if ($groupname == "") + $groupname = "null"; + else + { + $groupname = preg_replace("/a\.b\./i", "alt.binaries.", $groupname); + $groupname = sprintf("%s", $this->db->escapeString($groupname)); + } + + return $this->db->mysqliQueryInsert(sprintf("insert into binaryblacklist (groupname, regex, status, description, optype, msgcol) values (%s, %s, %d, %s, %d, %d) ", + $groupname, $this->db->escapeString($regex["regex"]), $regex["status"], $this->db->escapeString($regex["description"]), $regex["optype"], $regex["msgcol"])); + } + + /** + * Add a new binary row and its associated parts. + */ + public function delete($id) + { + + $this->db->mysqliQuery(sprintf("delete from parts where binaryID = %d", $id)); + $this->db->mysqliQuery(sprintf("delete from binaries where ID = %d", $id)); + } +} diff --git a/bin/innodb/lib/nntp.php b/bin/innodb/lib/nntp.php new file mode 100755 index 000000000..5d068cdb7 --- /dev/null +++ b/bin/innodb/lib/nntp.php @@ -0,0 +1,312 @@ +connect(NNTP_SERVER, $enc, NNTP_PORT); + if(PEAR::isError($ret)) + { + echo "Cannot connect to server ".NNTP_SERVER.(!$enc?" (nonssl) ":"(ssl) ").": ".$ret->getMessage(); + die(); + } + if(!defined(NNTP_USERNAME) && NNTP_USERNAME!="" ) + { + $ret2 = $this->authenticate(NNTP_USERNAME, NNTP_PASSWORD); + if(PEAR::isError($ret2)) + { + echo "Cannot authenticate to server ".NNTP_SERVER.(!$enc?" (nonssl) ":" (ssl) ")." - ".NNTP_USERNAME." (".$ret2->getMessage().")"; + die(); + } + } + } + + /** + * End an NNTP connection. + */ + function doQuit() + { + $this->quit(); + } + + /** + * Retrieve an NNTP message and decode it. + */ + function getMessage($groupname, $partMsgId) + { + $summary = $this->selectGroup($groupname); + $message = $dec = ''; + + if (PEAR::isError($summary)) + { + echo "NntpPrc : ".substr($summary->getMessage(), 0, 30)."\n"; + return false; + } + + $body = $this->getBody('<'.$partMsgId.'>', true); + if (PEAR::isError($body)) + { + //echo 'NntpPrc : Error fetching part number '.$partMsgId.' in '.$groupname.' (Server response: '. $body->getMessage().')\n'; + return false; + } + + $message = $this->decodeYenc($body); + if (!$message) + { + // + // Yenc decode failed + // + return false; + } + + echo $message . "\n"; + return $message; + } + + /** + * Retrieve a series of NNTP messages and decode them. + */ + function getMessages($groupname, $msgIds) + { + $summary = $this->selectGroup($groupname); + $message = $dec = ''; + + if (PEAR::isError($summary)) + { + echo "NntpPrc : ".substr($summary->getMessage(), 0, 30)."\n"; + return false; + } + + foreach($msgIds as $msgId) + { + $messageID = '<'.$msgId.'>'; + $body = $this->getBody($messageID, true); + if (PEAR::isError($body)) + { + //echo 'NntpPrc : Error fetching '.$messageID.' in '.$groupname.' (Server response: '. $body->getMessage().')'; + return false; + } + + $dec = $this->decodeYenc($body); + if (!$dec) + { + // + // Yenc decode failed + // + return false; + } + + $message .= $dec; + } + return $message; + } + + /** + * Retrieve all NNTP messages associated with a binaries.ID + */ + function getBinary($binaryId, $isNfo=false) + { + $db = new DB(); + $bin = new Binaries(); + + $binary = $bin->getById($binaryId); + if (!$binary) + return false; + + $summary = $this->selectGroup($binary['groupname']); + $message = $dec = ''; + + if (PEAR::isError($summary)) + { + echo "NntpPrc : ".substr($summary->getMessage(), 0, 30)."\n"; + return false; + } + + $resparts = $db->query(sprintf("SELECT size, partnumber, messageID FROM parts WHERE binaryID = %d ORDER BY partnumber", $binaryId)); + + // + // Dont attempt to download nfos which are larger than one part. + // + if (sizeof($resparts) > 1 && $isNfo === true) + { + return false; + } + + foreach($resparts as $part) + { + $messageID = '<'.$part['messageID'].'>'; + $body = $this->getBody($messageID, true); + if (PEAR::isError($body)) + { + //echo 'NntpPrc : Error fetching part number '.$part['messageID'].' in '.$binary['groupname'].' (Server response: '. $body->getMessage().')'; + return false; + } + + $dec = $this->decodeYenc($body); + if (!$dec) + { + // + // Yenc decode failed + // + return false; + } + + $message .= $dec; + } + return $message; + } + + /** + * Get XZVER for a range of NNTP messages. + */ + function getXOverview($range, $_names = true, $_forceNames = true) + { + // Fetch overview from server + $overview = $this->cmdXZver($range); + if (PEAR::isError($overview)) { + return $overview; + } + + // Use field names from overview format as keys? + if ($_names) + { + // Already cached? + if (is_null($this->_overviewFormatCache)) { + // Fetch overview format + $format = $this->getOverviewFormat($_forceNames, true); + if (PEAR::isError($format)){ + return $format; + } + + // Prepend 'Number' field + $format = array_merge(array('Number' => false), $format); + + // Cache format + $this->_overviewFormatCache = $format; + } + else + { + $format = $this->_overviewFormatCache; + } + + // Loop through all articles + foreach ($overview as $key => $article) + { + if (sizeof($format) == sizeof($article)) + { + //Replace overview using $format as keys, $article as values + $overview[$key] = array_combine(array_keys($format), $article); + + // If article prefixed by field name, remove it + foreach($format as $fkey=>$fval) + { + if ($fval === true) + { + $overview[$key][$fkey] = trim(str_replace($fkey.':', '', $overview[$key][$fkey])); + } + } + } + } + } + + switch (true) + { + // Expect one article + case is_null($range); + case is_int($range); + case is_string($range) && ctype_digit($range): + case is_string($range) && substr($range, 0, 1) == '<' && substr($range, -1, 1) == '>': + if (count($overview) == 0) { + return false; + } else { + return reset($overview); + } + break; + + // Expect multiple articles + default: + return $overview; + } + } + + /** + * Send XZVER command over NNTP connection. + */ + function cmdXZver($range = NULL) + { + if (is_null($range)) + $command = 'XZVER'; + else + $command = 'XZVER ' . $range; + + $response = $this->_sendCommand($command); + + switch ($response) { + case 224: // 224, RFC2980: 'Overview information follows' + $data = $this->_getTextResponse(); + + //de-yenc + $dec = $this->decodeYenc(implode("\r\n", $data)); + if (!$dec) + { + $this->throwError("yenc decode failure"); + } + + //inflate deflated string + $data = explode("\r\n", gzinflate($dec)); + + foreach ($data as $key => $value) + $data[$key] = explode("\t", ltrim($value)); + + return $data; + break; + case 412: // 412, RFC2980: 'No news group current selected' + $this->throwError("No news group current selected ({$this->_currentStatusResponse()})", $response); + break; + case 420: // 420, RFC2980: 'No article(s) selected' + $this->throwError("No article(s) selected ({$this->_currentStatusResponse()})", $response); + break; + case 502: // 502 RFC2980: 'no permission' + $this->throwError("No permission ({$this->_currentStatusResponse()})", $response); + break; + case 500: // 500 RFC2980: 'unknown command' + $this->throwError("XZver not supported ({$this->_currentStatusResponse()})", $response); + break; + default: + return $this->_handleUnexpectedResponse($response); + } + } + + /** + * Decode a yenc encoded string. + */ + function decodeYenc($yencodedvar) + { + $input = array(); + preg_match("/^(=ybegin.*=yend[^$]*)$/ims", $yencodedvar, $input); + if (isset($input[1])) + { + $ret = ""; + $input = trim(preg_replace("/\r\n/im", "", preg_replace("/(^=yend.*)/im", "", preg_replace("/(^=ypart.*\\r\\n)/im", "", preg_replace("/(^=ybegin.*\\r\\n)/im", "", $input[1], 1), 1), 1))); + + for( $chr = 0; $chr < strlen($input) ; $chr++) + $ret .= ($input[$chr] != "=" ? chr(ord($input[$chr]) - 42) : chr((ord($input[++$chr]) - 64) - 42)); + + return $ret; + } + return false; + } +} diff --git a/bin/innodb/lib/site.php b/bin/innodb/lib/site.php new file mode 100755 index 000000000..a9d6fd6e1 --- /dev/null +++ b/bin/innodb/lib/site.php @@ -0,0 +1,146 @@ +row2Object($form); + + if (substr($site->nzbpath, strlen($site->nzbpath) - 1) != '/') + $site->nzbpath = $site->nzbpath."/"; + + // + // Validate site settings + // + if ($site->mediainfopath != "" && !is_file($site->mediainfopath)) + return Sites::ERR_BADMEDIAINFOPATH; + + if ($site->ffmpegpath != "" && !is_file($site->ffmpegpath)) + return Sites::ERR_BADFFMPEGPATH; + + if ($site->unrarpath != "" && !is_file($site->unrarpath)) + return Sites::ERR_BADUNRARPATH; + + if ($site->nzbpath != "" && !file_exists($site->nzbpath)) + return Sites::ERR_BADNZBPATH; + + if ($site->checkpasswordedrar == 2 && !is_file($site->unrarpath)) + return Sites::ERR_DEEPNOUNRAR; + + if ($site->tmpunrarpath != "" && !file_exists($site->tmpunrarpath)) + return Sites::ERR_BADTMPUNRARPATH; + + if ($site->lamepath != "" && !file_exists($site->lamepath)) + return Sites::ERR_BADLAMEPATH; + + if ($site->sabcompletedir != "" && !file_exists($site->sabcompletedir)) + return Sites::ERR_SABCOMPLETEPATH; + + $sql = $sqlKeys = array(); + foreach($form as $settingK=>$settingV) + { + $sql[] = sprintf("WHEN %s THEN %s", $db->escapeString($settingK), $db->escapeString(trim($settingV))); + $sqlKeys[] = $db->escapeString($settingK); + } + + $db->query(sprintf("UPDATE site SET value = CASE setting %s END WHERE setting IN (%s)", implode(' ', $sql), implode(', ', $sqlKeys))); + + return $site; + } + + public function get() + { + $db = new DB(); + $rows = $db->query("select * from site"); + + if ($rows === false) + return false; + + return $this->rows2Object($rows); + } + + public function rows2Object($rows) + { + $obj = new stdClass; + foreach($rows as $row) + $obj->{$row['setting']} = $row['value']; + + $obj->{'version'} = $this->version(); + return $obj; + } + + public function row2Object($row) + { + $obj = new stdClass; + $rowKeys = array_keys($row); + foreach($rowKeys as $key) + $obj->{$key} = $row[$key]; + + return $obj; + } + + public function getUnappliedPatches($site) + { + preg_match("/\d+/", $site->dbversion, $matches); + $currentrev = $matches[0]; + + $patchpath = WWW_DIR."../db/patch/0.2.3/"; + $patchfiles = glob($patchpath."*.sql"); + $missingpatch = array(); + foreach($patchfiles as $file) + { + $filecontents = file_get_contents($file); + if (preg_match("/Rev\: (\d+)/", $filecontents, $matches)) + { + $patchrev = $matches[1]; + if ($patchrev > $currentrev) + $missingpatch[] = $file; + } + } + return $missingpatch; + } + + public function updateItem($setting, $value) + { + $db = new DB(); + $sql = sprintf("update site set value = %s where setting = %s", $db->escapeString($value), $db->escapeString($setting)); + return $db->query($sql); + } + + public function updateLatestRegexRevision($rev) + { + return $this->updateItem("latestregexrevision", $rev); + } + + public function getLicense($html=false) + { + $n = "\r\n"; + if ($html) + $n = "
"; + + return $n."newznab ".$this->version()." Copyright (C) ".date("Y")." newznab.com".$n." + +This program is distributed with a commercial licence. See LICENCE.txt for +further details.".$n; + } +} diff --git a/bin/lib/postprocess4.php b/bin/lib/postprocess4.php deleted file mode 100755 index 4eafcfca7..000000000 --- a/bin/lib/postprocess4.php +++ /dev/null @@ -1,975 +0,0 @@ -echooutput = $echooutput; - $s = new Sites(); - $this->site = $s->get(); - - $this->mediafileregex = 'AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG'; - $this->audiofileregex = 'MP3|AAC|OGG'; - $this->mp3SavePath = WWW_DIR.'covers/audio/'; - } - - /** - * Perform all post processing. - */ - public function processAll() - { - //$this->>processAdditional2(); - //$this->processNfos(); - //$this->processUnwanted(); - //$this->processMovies(); - //$this->processMusic(); - //$this->processBooks(); - //$this->processGames(); - //$this->processTv(); - //$this->processMusicFromMediaInfo(); - //$this->processOtherMiscCategory(); - //$this->processUnknownCategory(); - } - - public function processUnwanted() - { - $r = new Releases; - $db = new DB; - $currTime_ori = $db->queryOneRow("SELECT NOW() as now"); - - // - // Delete any passworded releases - // - if($this->site->deletepasswordedrelease == 1) - { - echo "PostPrc : Removing unwanted releases\n"; - $result = $db->query("select ID from releases where passwordstatus > 0"); - foreach ($result as $row) - $r->delete($row["ID"]); - } - - // - // Delete any releases which are older than site's release retention days - // - if($this->site->releaseretentiondays != 0) - { - echo "PostPrc : Deleting releases older than ".$this->site->releaseretentiondays." days\n"; - - $result = $db->query(sprintf("select ID from releases where postdate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->releaseretentiondays)); - foreach ($result as $row) - $r->delete($row["ID"]); - } - - // - // Delete any audiopreviews older than site->audiopreviewprune days - // - if($this->site->audiopreviewprune > 0) - { - $result = $db->query(sprintf("select guid from releases where categoryID like '3%%' and haspreview = 2 and adddate < %s - interval %d day", $db->escapeString($currTime_ori["now"]), $this->site->audiopreviewprune)); - - echo "PostPrc : Deleting ".count($result)." audio previews older than ".$this->site->audiopreviewprune." days\n"; - foreach ($result as $row) - { - $r->updateHasPreview($row["guid"], 0); - $this->deleteAudioSample($row["guid"]); - } - } - - // - // Delete any releases suspected of being spam/virus - // - if($this->site->removespam != 0) - { - $spamIDs = array(); - - // - // all releases where the only file inside the rars is *.exe and they are not in the PC category - // - $sql = "select releasefiles.releaseID as ID from releasefiles inner join ( select releaseID, count(*) as totnum from releasefiles group by releaseID ) x on x.releaseID = releasefiles.releaseID and x.totnum = 1 inner join releases on releases.ID = releasefiles.releaseID left join releasenfo on releasenfo.releaseID = releases.ID where (releasefiles.name like '%.exe' or releasefiles.name like '%.scr') and (releases.categoryID not in (4000,4010,4020,4030,4040,4050) or (releases.categoryID in (4000,4010,4020,4030,4040,4050) and releasenfo.ID is null)) group by releasefiles.releaseID"; - $result = $db->query($sql); - $spamIDs = array_merge($result, $spamIDs); - - // - // all releases containing exe not in permitted categories - // - if ($this->site->exepermittedcategories != '') - { - $sql = sprintf("select releasefiles.releaseID as ID from releasefiles inner join releases on releases.ID = releasefiles.releaseID left join releasenfo on releasenfo.releaseID = releases.ID where releasefiles.name like '%%.exe' and releases.categoryID not in (%s) group by releasefiles.releaseID", $this->site->exepermittedcategories); - $result = $db->query($sql); - $spamIDs = array_merge($result, $spamIDs); - } - - // - // delete all releases which contain a file with password.url in it - // - $sql = "select distinct releasefiles.releaseID as ID from releasefiles where name = 'password.url'"; - $result = $db->query($sql); - $spamIDs = array_merge($result, $spamIDs); - - // - // all releases where the only file inside the rars is *.rar - // - $sql = "select releasefiles.releaseID as ID from releasefiles inner join ( select releaseID, count(*) as totnum from releasefiles group by releaseID ) x on x.releaseID = releasefiles.releaseID and x.totnum = 1 inner join releases on releases.ID = releasefiles.releaseID where releasefiles.name like '%.rar' group by releasefiles.releaseID"; - $result = $db->query($sql); - $spamIDs = array_merge($result, $spamIDs); - - // - // all audio which contains a file with .exe in - // - $sql = "select distinct r.ID from releasefiles rf inner join releases r on r.id = rf.releaseID and r.categoryID like '3%' where rf.name like '%.exe'"; - $result = $db->query($sql); - $spamIDs = array_merge($result, $spamIDs); - - if (count($spamIDs) > 0) - { - echo "PostPrc : Deleting ".count($spamIDs)." spam releases\n" ; - foreach ($spamIDs as $row) - $r->delete($row["ID"]); - } - } - } - - /** - * Process nfo files - */ - public function processNfos() - { - if ($this->site->lookupnfo == 1) - { - $nfo = new Nfo($this->echooutput); - $nfo->processNfoFiles($this->site->lookupimdb, $this->site->lookuptvrage); - } - } - - /** - * Lookup imdb if enabled - */ - public function processMovies() - { - if ($this->site->lookupimdb == 1) - { - $movie = new Movie($this->echooutput); - $movie->processMovieReleases(); - } - } - - /** - * Lookup music if enabled - */ - public function processMusic() - { - if ($this->site->lookupmusic == 1) - { - $music = new Music($this->echooutput); - $music->processMusicReleases(); - } - } - - /** - * Lookup book if enabled - */ - public function processBooks() - { - if ($this->site->lookupbooks == 1) - { - $book = new Book($this->echooutput); - $book->processBookReleases(); - } - } - - /** - * Lookup games if enabled - */ - public function processGames() - { - if ($this->site->lookupgames == 1) - { - $console = new Console($this->echooutput); - $console->processConsoleReleases(); - } - } - - /** - * Work out any categories which were not assigned by regex or determinecategory - * Done in post process as releasevideo/audio will have been performed by now. - */ - public function processUnknownCategory() - { - $db = new DB; - $sql = sprintf("select ID from releases where categoryID = %d", Category::CAT_NOT_DETERMINED); - $result = $db->query($sql); - $rescount = sizeof($result); - if ($rescount > 0) - { - echo "PostPrc : Attempting to fix ".$rescount." uncategorised release(s)\n"; - - $sql = sprintf("update releases inner join releasevideo rv on rv.releaseID = releases.ID set releases.categoryID = %d where imdbid is not null and categoryid = %d and videocodec = 'XVID'", Category::CAT_MOVIE_SD, Category::CAT_NOT_DETERMINED); - $result = $db->query($sql); - - $sql = sprintf("update releases inner join releasevideo rv on rv.releaseID = releases.ID set releases.categoryID = %d where imdbid is not null and categoryid = %d and videocodec = 'V_MPEG4/ISO/AVC'", Category::CAT_MOVIE_HD, Category::CAT_NOT_DETERMINED); - $result = $db->query($sql); - - $sql = sprintf("update releases set categoryID = %d where categoryID = %d", Category::CAT_MISC, Category::CAT_NOT_DETERMINED); - $result = $db->query($sql); - } - } - - /** - * Process all TV related releases which will assign their series/episode/rage data - */ - public function processTv() - { - if ($this->site->lookupanidb == 1) - { - $anidb = new AniDB($this->echooutput); - $anidb->animetitlesUpdate(); - $anidb->processAnimeReleases(); - } - - if ($this->site->lookuptvrage == 1) - { - $tvrage = new TVRage($this->echooutput); - $tvrage->processTvReleases(($this->site->lookuptvrage==1)); - } - - if ($this->site->lookupthetvdb == 1) - { - $thetvdb = new TheTVDB($this->echooutput); - $thetvdb->processReleases(); - } - } - - /** - * Process releases without a proper name and try to look it up in the nfo - */ - public function processOtherMiscCategory($numToProcess = 10) - { - $db = new DB(); - - $res = $db->query(sprintf("select r.searchname, r.ID, r.guid, g.name as groupname from releases r inner join releasenfo rn on rn.releaseID = r.ID left join groups g on g.ID = r.groupID where (r.categoryID = %d or r.categoryID = %d) order by r.ID desc limit %d", Category::CAT_MISC, Category::CAT_NOT_DETERMINED, $numToProcess)); - - if ($res) - { - $rescount = sizeof($res); - - if ($this->echooutput) - echo "PostPrc : Attempting to categorise ".$rescount." Other-Misc releases\n"; - - foreach($res as $rel) - { - $filenameRes = $db->query(sprintf("select dirname from predb where filename = %s limit 2", $db->escapeString($rel['searchname']))); - if (count($filenameRes) == 1) - $foundName = $filenameRes[0]['dirname']; - else - { - $nfoRes = $db->queryOneRow(sprintf("select uncompress(nfo) as nfo from releasenfo where releaseID = %d", $rel['ID'])); - $nfo = $nfoRes['nfo']; - - $foundName = ''; - //Typical scene regex - if (preg_match('/(?PSource\s*?:|fix fornuke)?(?:\s|\]|\[)?(?P[a-z0-9\']+(?:\.|_)[a-z0-9\.\-_\'&]+\-[a-z0-9&]+)(?:\s|\[|\])/i', $nfo, $matches)) - { - if (empty($matches['source'])) - $foundName = $matches['name']; - } - //IMAGiNE releases - elseif(preg_match('/\*\s+([a-z0-9]+(?:\.|_| )[a-z0-9\.\_\- ]+ \- imagine)\s+\*/i', $nfo, $matches)) - { - $foundName = $matches[1]; - } - //SANTi releases - elseif(preg_match('/\b([a-z0-9]+(?:\.|_| )[a-z0-9\.\_\- \']+\-santi)\b/i', $nfo, $matches)) - { - $foundName = $matches[1]; - } - } - - if ($foundName != '') - { - $category = new Category(); - $categoryID = $category->determineCategory($rel['groupname'], $foundName); - $name = str_replace(' ', '_', $foundName); - $searchname = str_replace('_', ' ', $foundName); - - $db->query(sprintf("UPDATE releases SET name = %s, searchname = %s, categoryID = %d WHERE ID = %d", $db->escapeString($name), $db->escapeString($searchname), $categoryID, $rel['ID'])); - } - } - } - } - - /** - * Check for passworded releases, RAR contents and Sample/Media info - */ - public function processAdditional4() - { - require_once(WWW_DIR."/lib/nntp.php"); - - $maxattemptstocheckpassworded = 5; - $numtoProcess = 100; - $processVideoSample = ($this->site->ffmpegpath != '') ? true : false; - $processMediainfo = ($this->site->mediainfopath != '') ? true : false; - $processPasswords = ($this->site->unrarpath != '') ? true : false; - $processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false; - - $tmpPath = $this->site->tmpunrarpath; - $tmpPath .= '4'; - if (substr($tmpPath, -strlen( '/' ) ) != '/') - { - $tmpPath = $tmpPath.'/'; - } - - if (!file_exists($tmpPath)) - mkdir($tmpPath, 0766, true); - - $db = new DB; - $nntp = new Nntp; - $nzb = new Nzb; - - // - // 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 - left join category c on c.ID = r.categoryID - where (r.passwordstatus between %d and -1) - or (r.haspreview = -1 and c.disablepreview = 0) order by r.guid desc limit %d, %d ", ($maxattemptstocheckpassworded + 1) * -1, 7 * $numtoProcess, $numtoProcess )); - - $iteration = $rescount = sizeof($result); - if ($rescount > 0) - { - echo "Post processing by guid on ".$rescount." releases ..."; - $nntpconnected = false; - - foreach ($result as $rel) - { - echo $iteration--."."; - - // 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 - // - $nzbInfo = new nzbInfo; - $nzbfile = $nzb->getNZBPath($rel['guid'], $this->site->nzbpath); - if (!$nzbInfo->loadFromFile($nzbfile)) - { - continue; - } - $norar = 0; - - foreach($nzbInfo->nzb as $nzbsubject) - { - if (preg_match("/\w\.r00/i", $nzbsubject['subject'])) - $norar= 1; - } - - // attempt to process video sample file - if(!empty($nzbInfo->samplefiles) && $processVideoSample && $blnTookSample === false) - { - $sampleFile = $nzbInfo->samplefiles[0]; //first detected sample - $sampleMsgids = array_slice($sampleFile['segments'], 0, 1); //get first segment, increase to get more of the sample - $sampleGroup = $sampleFile['groups'][0]; - - //echo "PostPrc : Fetching ".implode($sampleMsgids, ', ')." from {$sampleGroup}\n"; - if (!$nntpconnected) - { - $nntp->doConnect(); - $nntpconnected = true; - } - - $sampleBinary = $nntp->getMessages($sampleGroup, $sampleMsgids); - if ($sampleBinary === false) - echo "\nPostPrc : Couldnt fetch sample\n"; - 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(!empty($nzbInfo->mediafiles) && (($processVideoSample && $blnTookSample === false) || $processMediainfo)) - { - $mediaFile = $nzbInfo->mediafiles[0]; //first detected media file - $mediaMsgids = array_slice($mediaFile['segments'], 0, 2); //get first two segments - $mediaGroup = $mediaFile['groups'][0]; - - //echo "PostPrc : Fetching ".implode($mediaMsgids, ', ')." from {$mediaGroup}\n"; - if (!$nntpconnected) - { - $nntp->doConnect(); - $nntpconnected = true; - } - $mediaBinary = $nntp->getMessages($mediaGroup, $mediaMsgids); - if ($mediaBinary === false) - echo "\nPostPrc : Couldnt fetch media file\n"; - else - { - $mediafile = $tmpPath.'sample.avi'; - - file_put_contents($mediafile, $mediaBinary); - - if ($processVideoSample && $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); - } - - // attempt to process audio sample file - if(!empty($nzbInfo->audiofiles) && $processAudioSample && $blnTookSample === false) - { - $audioFile = $nzbInfo->audiofiles[0]; //first detected audio file - $audioMsgids = array_slice($audioFile['segments'], 0, 1); //get first segment - $audioGroup = $audioFile['groups'][0]; - - //echo "PostPrc : Fetching ".implode($audioMsgids, ', ')." from {$audioGroup}\n"; - if (!$nntpconnected) - { - $nntp->doConnect(); - $nntpconnected = true; - } - $audioBinary = $nntp->getMessages($audioGroup, $audioMsgids); - if ($audioBinary === false) - echo "\nPostPrc : Couldnt fetch audio sample\n"; - else - { - $audiofile = $tmpPath.'sample.mp3'; - - file_put_contents($audiofile, $audioBinary); - - $blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']); - if ($blnTookSample !== false) - $this->updateReleaseHasPreview($rel['guid'], 2); - - if ($processMediainfo) - $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']); - - if ($this->site->lamepath != "") - $this->lameAudioSample($this->site->lamepath, $rel['guid']); - - unlink($audiofile); - } - unset($audioBinary); - } - - if (!empty($nzbInfo->rarfiles) && ($this->site->checkpasswordedrar > 0 || (($processVideoSample || $processAudioSample) && $blnTookSample === false) || $processMediainfo)) - { - $mysqlkeepalive = 0; - foreach($nzbInfo->rarfiles as $rarFile) - { - //dont process any more rars if a passworded rar has been detected and the site is set to automatically delete them - if ($this->site->deletepasswordedrelease == 1 && max($passStatus) == Releases::PASSWD_RAR) - { - echo "-Skipping processing of rar {$rarFile['subject']} as this release has already been marked as passworded.\n"; - continue; - } - - $rarMsgids = array_slice($rarFile['segments'], 0, 1); //get first segment - $rarGroup = $rarFile['groups'][0]; - - //echo "PostPrc : Fetching ".implode($rarMsgids, ', ')." from {$rarGroup} (".++$mysqlkeepalive.")\n"; - if (!$nntpconnected) - { - $nntp->doConnect(); - $nntpconnected = true; - } - $fetchedBinary = $nntp->getMessages($rarGroup, $rarMsgids); - if ($fetchedBinary === false) - { - echo "\nPostPrc : Failed fetching rar file\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, false, true); - unlink($rarfile); - } - - if ($processVideoSample && $blnTookSample === false) - { - $blnTookSample = $this->getSample($tmpPath, $this->site->ffmpegpath, $rel['guid']); - if ($blnTookSample) - $this->updateReleaseHasPreview($rel['guid']); - } - - $blnTookAudioSample = false; - if ($processAudioSample && $blnTookSample === false) - { - $blnTookSample = $this->getAudioSample($tmpPath, $rel['guid']); - if ($blnTookSample) - { - $blnTookAudioSample = true; - $this->updateReleaseHasPreview($rel['guid'], 2); - } - } - - if ($processMediainfo && $blnTookMediainfo === false) - { - $blnTookMediainfo = $this->getMediainfo($tmpPath, $this->site->mediainfopath, $rel['ID']); - } - - // - // Has to be done after mediainfo - // - if ($blnTookAudioSample && $this->site->lamepath != "") - $this->lameAudioSample($this->site->lamepath, $rel['guid']); - - if ($mysqlkeepalive % 25 == 0) - $db->query("select 1"); - } - - //clean up all files - foreach(glob($tmpPath.'*') as $v) - { - unlink($v); - } - - } //end foreach msgid - } - elseif(empty($nzbInfo->rarfiles) && $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 - - if ($nntpconnected) - { - $nntp->doQuit(); - } - - echo "\n"; - } - } - - /** - * Work out all files contained inside a rar - */ - public function processReleaseFiles($fetchedBinary, $relid) - { - $retval = array(); - $rar = new RarInfo; - $rf = new ReleaseFiles; - $db = new DB; - - if ($rar->setData($fetchedBinary)) - { - $files = $rar->getFileList(); - foreach ($files as $file) - { - $rf->add($relid, $file['name'], $file['size'], $file['date'], $file['pass'] ); - $retval[] = $file['name']; - } - - } - unset($fetchedBinary); - return $retval; - } - - /** - * Work out if a release is passworded - */ - public function processReleasePasswords($fetchedBinary, $tmpPath, $unrarPath, $checkpasswordedrar) - { - $passStatus = Releases::PASSWD_NONE; - $potentiallypasswordedfileregex = "/\.(ace|cab|tar|gz)$/i"; - $definetlypasswordedfileregex = "/password/i"; - $rar = new RarInfo; - $filecount = 0; - - $rarfile = $tmpPath.'rarfile.rar'; - file_put_contents($rarfile, $fetchedBinary); - - if ($rar->open($rarfile)) - { - if ($rar->isEncrypted) - { - $passStatus = Releases::PASSWD_RAR; - } - else - { - $files = $rar->getFileList(true); - foreach ($files as $file) - { - $filecount++; - // - // individual file rar passworded - // - if ($file['pass'] == 1 || preg_match($definetlypasswordedfileregex, $file["name"])) - { - $passStatus = Releases::PASSWD_RAR; - } - - // - // individual file looks suspect - // - elseif (preg_match($potentiallypasswordedfileregex, $file["name"]) && $passStatus != Releases::PASSWD_RAR) - { - $passStatus = Releases::PASSWD_POTENTIAL; - } - } - - // - // Deep Checking - // - if ($checkpasswordedrar == 2) - { - - $israr = $this->isRar($rarfile); - for ($i=0;$iisRar($tmpPath.$israr[$i]); - - if (is_array($tmp)) - // it's a rar - { - for ($x=0;$xopen($rarfile)) - { - if ($rar->isEncrypted) - { - return 1; - } - else - { - $files = $rar->getFileList(true); - foreach ($files as $file) - { - $filelist[] = $file['name']; - if ($file['pass'] == true) - // - // individual file rar passworded - // - { - return 2; - // passworded - } - } - return ($filelist); - // normal rar - } - } - else - { - return 0; - // not a rar - } - } - - /** - * Work out all files contained inside a rar - */ - public function getMediainfo($ramdrive,$mediainfo,$releaseID) - { - $retval = false; - $mediafiles = glob($ramdrive.'*.*'); - if (is_array($mediafiles)) - { - foreach($mediafiles as $mediafile) - { - if (preg_match("/\.(".$this->mediafileregex.'|'.$this->audiofileregex.")$/i",$mediafile)) - { - $execstring = '"'.$mediainfo.'" --Output=XML "'.$mediafile.'"'; - $xmlarray = runCmd($execstring); - - if (is_array($xmlarray)) - { - $xmlarray = implode("\n",$xmlarray); - $re = new ReleaseExtra(); - $re->addFull($releaseID,$xmlarray); - $re->addFromXml($releaseID,$xmlarray); - $retval = true; - } - else - { - echo "PostPrc : Failed to process mediainfo for ".$mediafile." release (".$releaseID.")\n"; - } - } - } - } - else - { - echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n"; - } - return $retval; - } - - /** - * Get a sample from a release using ffmpeg - */ - public function getSample($ramdrive, $ffmpeginfo, $releaseguid) - { - $ri = new ReleaseImage(); - $retval = false; - - $samplefiles = glob($ramdrive.'*.*'); - if (is_array($samplefiles)) - { - foreach($samplefiles as $samplefile) - { - if (preg_match("/\.(".$this->mediafileregex.")$/i",$samplefile)) - { - $execstring = '"'.$ffmpeginfo.'" -q:v 0 -i "'.$samplefile.'" -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"'; - $output = runCmd($execstring, false, true); - $all_files = scandir($ramdrive,1); - if(preg_match("/zzzz\d{3}\.jpg/",$all_files[1])) - { - $ri->saveImage($releaseguid.'_thumb', $ramdrive.$all_files[1], $ri->imgSavePath, 800, 600); - $retval = true; - } - - //clean up all files - foreach(glob($ramdrive.'*.jpg') as $v) - { - unlink($v); - } - } - } - } - else - { - echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n"; - } - return $retval; - } - - /** - * Has to be performed after mediainfo, as lame strips id3 tags. - */ - public function lameAudioSample($lameinfo, $releaseguid) - { - $minacceptableencodefilesize = 10000; - $samplefile = $this->mp3SavePath.$releaseguid.'.mp3'; - - if (file_exists($samplefile)) - { - $outfile = $this->mp3SavePath.$releaseguid.'_l.mp3'; - - // - // lame the sample down to 96kb and replace it. alternatives could be - // V8 for low quality variable. - // - $execstring = '"'.$lameinfo.'" -b 96 "'.$samplefile.'" "'.$outfile.'"'; - $output = runCmd($execstring, false, true); - - // - // lame can create bad/small files if the source was corrupt - // if it creates a file thats surprisingly small, then ignore it and retain - // original - // - if (file_exists($outfile)) - { - if (filesize($outfile) < $minacceptableencodefilesize) - unlink($outfile); - else - { - unlink($samplefile); - rename($outfile, $samplefile); - - return true; - } - } - } - - return false; - } - - /** - * Get an audio sample from a release. - */ - public function getAudioSample($ramdrive, $releaseguid) - { - $retval = false; - - $audiofiles = glob($ramdrive.'*.*'); - if (is_array($audiofiles)) - { - foreach($audiofiles as $audiofile) - { - if (preg_match("/\.(".$this->audiofileregex.")$/i",$audiofile)) - { - if (copy($audiofile, $this->mp3SavePath.$releaseguid.'.mp3') !== false) - $retval = true; - else - echo "PostPrc : Failed to get audio sample from ".$audiofile."\n"; - } - } - } - else - { - echo "PostPrc: Couldn't open temp drive ".$ramdrive."\n"; - } - return $retval; - } - - /** - * Delete an audio sample from a release. - */ - public function deleteAudioSample($releaseguid) - { - $preview = $this->mp3SavePath.$releaseguid.'.mp3'; - if (file_exists($preview)) - unlink($preview); - } - - /** - * Update release to indicate a preview has been obtained. - */ - public function updateReleaseHasPreview($guid, $prevtype=1) - { - $rel = new Releases; - $rel->updateHasPreview($guid, $prevtype); - } - - /** - * Process untagged music releases using information from mediainfo if config permits. - */ - public function processMusicFromMediaInfo() - { - $processMediainfo = ($this->site->mediainfopath != '') ? true : false; - $processAudioSample = ($this->site->saveaudiopreview == 1) ? true : false; - $processMusic = ($this->site->lookupmusic == 1) ? true : false; - - if ($processMusic && $processMediainfo && $processAudioSample) - { - $music = new Music($this->echooutput); - $ret = $music->processMusicReleaseFromMediaInfo(); - return $ret; - } - - return false; - } -} - diff --git a/bin/monitor.php b/bin/monitor.php index d9ae087c8..19d7f7324 100755 --- a/bin/monitor.php +++ b/bin/monitor.php @@ -6,29 +6,6 @@ require_once(WWW_DIR."/lib/postprocess.php"); $db = new DB(); //initial queries -<<<<<<< HEAD -$book_query = "SELECT COUNT(*) AS cnt from releases where bookinfoID IS NULL and categoryID = 7020;"; -$book_query2 = "SELECT COUNT(*) AS cnt from releases where categoryID = 7020;"; -$console_query = "SELECT COUNT(*) AS cnt from releases where consoleinfoID IS NULL and categoryID in ( select ID from category where parentID = 1000 );"; -$console_query2 = "SELECT COUNT(*) AS cnt from releases where categoryID in ( select ID from category where parentID = 1000 );"; -$movie_query = "SELECT COUNT(*) AS cnt from releases where imdbID IS NULL and categoryID in ( select ID from category where parentID = 2000 );"; -$movie_query2 = "SELECT COUNT(*) AS cnt from releases where categoryID in ( select ID from category where parentID = 2000 );"; -$music_query = "SELECT COUNT(*) AS cnt from releases where musicinfoID IS NULL and categoryID in ( select ID from category where parentID = 3000 );"; -$music_query2 = "SELECT COUNT(*) AS cnt from releases where categoryID in ( select ID from category where parentID = 3000 );"; -$pc_query = "SELECT COUNT(*) AS cnt from releases r left join category c on c.ID = r.categoryID where (categoryID in ( select ID from category where parentID = 4000)) and ((r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0));"; -$pc_query2 = "SELECT COUNT(*) AS cnt from releases where categoryID in ( select ID from category where parentID = 4000 );"; -$tvrage_query = "SELECT COUNT(*) AS cnt, ID from releases where rageID = -1 and categoryID in ( select ID from category where parentID = 5000 );"; -$tvrage_query2 = "SELECT COUNT(*) AS cnt, ID from releases where categoryID in ( select ID from category where parentID = 5000 );"; -$releases_query = "SELECT COUNT(*) AS cnt from releases"; -$work_remaining_query = "SELECT COUNT(*) AS cnt from releases r left join category c on c.ID = r.categoryID where (r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0);"; - -//initial counts -$releases_start = $db->query($releases_query); -$releases_start = $releases_start[0]['cnt']; - - - -======= //books to process $book_query = "SELECT COUNT(*) AS cnt from releases where bookinfoID IS NULL and categoryID = 7020;"; //books in db @@ -98,7 +75,6 @@ $_string1 = "\033[1;33mThis means that the script has no work to do and the pane $_string2 = "\033[1;33mYou have disabled this in edit_these.sh and therefore has no work to do and the pane is idle until the next time the script is called.\033[0m"; $_sleep_string = "\033[1;34msleeping\033[0m "; ->>>>>>> dev $time = TIME(); $time2 = TIME(); $time3 = TIME(); @@ -115,21 +91,12 @@ while($i>0) $min = ($mins % 60); $day = ($days % 24); $hr = ($hrs % 24); -<<<<<<< HEAD //loop counts $releases_loop = $db->query($releases_query); $releases_loop = $releases_loop[0]['cnt']; -======= - - //loop counts - $releases_loop = $db->query($releases_query); - $releases_loop = $releases_loop[0]['cnt']; - - ->>>>>>> dev $sleeptime = getenv('MONITOR_UPDATE'); if ($i!=1) { sleep($sleeptime); @@ -190,54 +157,6 @@ while($i>0) elseif ( $hr > 0 ) { $time_string = "\033[38;5;208m$hr\033[0m $string_hr, \033[38;5;020m$min\033[0m $string_min."; } else { $time_string = "\033[38;5;020m$min\033[0m $string_min."; } -<<<<<<< HEAD - //get totals inside loop - $book_releases_proc = $db->query($book_query); - $book_releases_proc = $book_releases_proc[0]['cnt']; - $book_releases_now = $db->query($book_query2); - $book_releases_now = $book_releases_now[0]['cnt']; - $console_releases_proc = $db->query($console_query); - $console_releases_proc = $console_releases_proc[0]['cnt']; - $console_releases_now = $db->query($console_query2); - $console_releases_now = $console_releases_now[0]['cnt']; - $movie_releases_proc = $db->query($movie_query); - $movie_releases_proc = $movie_releases_proc[0]['cnt']; - $movie_releases_now = $db->query($movie_query2); - $movie_releases_now = $movie_releases_now[0]['cnt']; - $music_releases_proc = $db->query($music_query); - $music_releases_proc = $music_releases_proc[0]['cnt']; - $music_releases_now = $db->query($music_query2); - $music_releases_now = $music_releases_now[0]['cnt']; - $pc_releases_proc = $db->query($pc_query); - $pc_releases_proc = $pc_releases_proc[0]['cnt']; - $pc_releases_now = $db->query($pc_query2); - $pc_releases_now = $pc_releases_now[0]['cnt']; - $tvrage_releases_proc = $db->query($tvrage_query); - $tvrage_releases_proc = $tvrage_releases_proc[0]['cnt']; - $tvrage_releases_now = $db->query($tvrage_query2); - $tvrage_releases_now = $tvrage_releases_now[0]['cnt']; - $releases_now = $db->query($releases_query); - $releases_now = $releases_now[0]['cnt']; - $work_remaining_now = $db->query($work_remaining_query); - $work_remaining_now = $work_remaining_now[0]['cnt']; - $releases_since_start = $releases_now - $releases_start; - $releases_since_loop = $releases_now - $releases_loop; - $additional_releases_now = $releases_now - $book_releases_now - $console_releases_now - $movie_releases_now - $music_releases_now - $pc_releases_now - $tvrage_releases_now; - - passthru('clear'); - printf("\033[1;34mMonitor\033[0m has been running for: \033[38;5;160m$day\033[0m");printf(" days, "); - printf("\033[38;5;208m$hr\033[0m");printf(" hrs, "); - printf("\033[38;5;020m$min\033[0m");printf(" min\n"); - printf("The script updates every $sleeptime seconds.\n"); - printf("$releases_since_loop releases added since last update.\n\n"); - - printf("$releases_now releases in your database.\n"); - printf("$releases_since_start releases have been added.\n\n"); - - $mask = "%16s %10s %10s \n"; - printf($mask, "Category", "In Process", "In Database"); - printf($mask, "===============", "==========", "=========="); -======= passthru('clear'); printf("\033[1;34mMonitor\033[0m has been running for: $time_string\n"); @@ -251,7 +170,6 @@ while($i>0) printf($mask, "Category", "In Process", "In Database"); printf($mask, "===============", "==========", "==========\033[0m"); printf($mask, "NZB's to import","$_nzbs_to_import_now","$_nzbs_process"); ->>>>>>> dev printf($mask, "Books(7020)","$book_releases_proc","$book_releases_now"); printf($mask, "Console(1000)","$console_releases_proc","$console_releases_now"); printf($mask, "Movie(2000)","$movie_releases_proc","$movie_releases_now"); @@ -260,9 +178,6 @@ while($i>0) printf($mask, "TVShows(5000)","$tvrage_releases_proc","$tvrage_releases_now"); printf($mask, "Additional Proc","$work_remaining_now","$additional_releases_now"); -<<<<<<< HEAD - $i=$i+1; -======= if ((TIME() - $time2) >= 900 ) { shell_exec("tmux respawnp -t Newznab-dev:1.0 'cd $_newznab_path && $_php update_predb.php true && date && echo \"$_string\"' 2>&1 1> /dev/null"); $time2 = TIME(); @@ -367,7 +282,7 @@ while($i>0) shell_exec("tmux respawnp -t Newznab-dev:0.15 'cd $_newznab_path && $_php update_releases.php && date && echo \"$_sleep_string $_rel_sleep seconds...\" && sleep $_rel_sleep && echo \"$_string\"' 2>&1 1> /dev/null"); $i++; ->>>>>>> dev } ?> + diff --git a/bin/monitor.sh b/bin/monitor.sh deleted file mode 100755 index 720c0cedd..000000000 --- a/bin/monitor.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP monitor.php - -done - diff --git a/bin/postProcessing1.sh b/bin/postProcessing1.sh deleted file mode 100755 index 9d49ca07f..000000000 --- a/bin/postProcessing1.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processBooks.php - -done diff --git a/bin/postProcessing2.sh b/bin/postProcessing2.sh deleted file mode 100755 index 790936766..000000000 --- a/bin/postProcessing2.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processGames.php - -done diff --git a/bin/postProcessing3.sh b/bin/postProcessing3.sh deleted file mode 100755 index ba3c2b62d..000000000 --- a/bin/postProcessing3.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processMovies.php - -done diff --git a/bin/postProcessing4.sh b/bin/postProcessing4.sh deleted file mode 100755 index e064f8859..000000000 --- a/bin/postProcessing4.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processMusic.php - -done diff --git a/bin/postProcessing5.sh b/bin/postProcessing5.sh deleted file mode 100755 index 984ffdc3c..000000000 --- a/bin/postProcessing5.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processTv.php - -done diff --git a/bin/postProcessing6.sh b/bin/postProcessing6.sh deleted file mode 100755 index 7f3ba0209..000000000 --- a/bin/postProcessing6.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processOthers.php - -done diff --git a/bin/postprocess_nfo.sh b/bin/postprocess_nfo.sh deleted file mode 100755 index 205c64877..000000000 --- a/bin/postprocess_nfo.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP postprocess_nfo.php - -done - diff --git a/bin/processAlternate2.php b/bin/processAlternate2.php index 67a54e3bc..2dc88ded1 100755 --- a/bin/processAlternate2.php +++ b/bin/processAlternate2.php @@ -3,42 +3,8 @@ require_once("config.php"); require_once("lib/postprocess2.php"); -<<<<<<< HEAD -$db = new DB(); -$query = "select count(*) from releases r left join category c on c.ID = r.categoryID where ((r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0))"; - -$i=1; -while($i=1) -{ - $result = mysql_query($query); - - if (empty($result)) { - $result = $db->queryDirect($query); - if (empty($result)) { - $message = 'Invalid query: ' . mysql_error() . "\n"; - $message .= 'Whole query: ' . $query; - die($message); - } - } - - while ($row = mysql_fetch_assoc($result)) { - $count = $row['count(*)']; - } - - if ($count > 0) { - $postprocess = new PostProcess2(true); - $postprocess->processAdditional2(); - } else { - echo "$count releases left to process\n"; - sleep(15); - } -} - -mysql_free_result($result); -======= $postprocess = new PostProcess2(true); $postprocess->processAdditional2(); ->>>>>>> dev ?> diff --git a/bin/processAlternate2.sh b/bin/processAlternate2.sh deleted file mode 100755 index 244ad4104..000000000 --- a/bin/processAlternate2.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processAlternate2.php - -done - diff --git a/bin/processAlternate3.sh b/bin/processAlternate3.sh deleted file mode 100755 index baf17b32b..000000000 --- a/bin/processAlternate3.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processAlternate3.php - -done - diff --git a/bin/processAlternate4.php b/bin/processAlternate4.php index 89411b544..d8b4ce78c 100755 --- a/bin/processAlternate4.php +++ b/bin/processAlternate4.php @@ -1,48 +1,10 @@ queryDirect($query); - if (empty($result)) { - $message = 'Invalid query: ' . mysql_error() . "\n"; - $message .= 'Whole query: ' . $query; - die($message); - } - } - - while ($row = mysql_fetch_assoc($result)) { - $count = $row['count(*)']; - } - - if ($count > 1000) { - $postprocess = new PostProcess4(true); - $postprocess->processAdditional4(); - } else { - echo "$count releases left to process\n"; - sleep(15); - } -} - -mysql_free_result($result); -======= require_once("config.php"); require_once("lib/postprocess4.php"); $postprocess = new PostProcess4(true); $postprocess->processAdditional4(); ->>>>>>> dev ?> diff --git a/bin/processAlternate4.sh b/bin/processAlternate4.sh deleted file mode 100755 index c31799861..000000000 --- a/bin/processAlternate4.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -while : -do - - $PHP processAlternate4.php - -done - diff --git a/bin/processBooks.php b/bin/processBooks.php index 9dc404b6c..5ec20761d 100755 --- a/bin/processBooks.php +++ b/bin/processBooks.php @@ -3,31 +3,8 @@ require_once("config.php"); require_once(WWW_DIR."/lib/postprocess.php"); -<<<<<<< HEAD -$db = new DB(); -$query = "SELECT COUNT(*) AS cnt from releases where bookinfoID IS NULL and categoryID = 7020;"; - -$i=1; -while($i=1) -{ - $result = $db->query($query); - $count = $result[0]['cnt']; - - if ($count > 0) { - $postprocess = new PostProcess(true); - $postprocess->processBooks(); - } else { - printf("BookPrc : Processing $count book releases\n"); - sleep(15); - } -} - -mysql_free_result($result); -======= $postprocess = new PostProcess(true); $postprocess->processBooks(); ->>>>>>> dev ?> - diff --git a/bin/processGames.php b/bin/processGames.php index b132e8dc9..b4585d9a2 100755 --- a/bin/processGames.php +++ b/bin/processGames.php @@ -3,30 +3,8 @@ require_once("config.php"); require_once(WWW_DIR."/lib/postprocess.php"); -<<<<<<< HEAD -$db = new DB(); -$query = "SELECT COUNT(*) AS cnt from releases where consoleinfoID IS NULL and categoryID in ( select ID from category where parentID = 1000 );"; - -$i=1; -while($i=1) -{ - $result = $db->query($query); - $count = $result[0]['cnt']; - - if ($count > 0) { - $postprocess = new PostProcess(true); - $postprocess->processGames(); - } else { - printf("ConsPrc : Processing $count console releases\n"); - sleep(15); - } -} - -mysql_free_result($result); -======= $postprocess = new PostProcess(true); $postprocess->processGames(); ->>>>>>> dev ?> diff --git a/bin/processMovies.php b/bin/processMovies.php index 7669104f4..8354a197c 100755 --- a/bin/processMovies.php +++ b/bin/processMovies.php @@ -3,30 +3,8 @@ require_once("config.php"); require_once(WWW_DIR."/lib/postprocess.php"); -<<<<<<< HEAD -$db = new DB(); -$query = "SELECT COUNT(*) AS cnt from releases where imdbID IS NULL and categoryID in ( select ID from category where parentID = 2000 );"; - -$i=1; -while($i=1) -{ - $result = $db->query($query); - $count = $result[0]['cnt']; - - if ($count > 0) { - $postprocess = new PostProcess(true); - $postprocess->processMovies(); - } else { - printf("MovProc : Processing $count movie releases\n"); - sleep(15); - } -} - -mysql_free_result($result); -======= $postprocess = new PostProcess(true); $postprocess->processMovies(); ->>>>>>> dev ?> diff --git a/bin/processMusic.php b/bin/processMusic.php index 170eecb75..d7b3f4a26 100755 --- a/bin/processMusic.php +++ b/bin/processMusic.php @@ -3,30 +3,8 @@ require_once("config.php"); require_once(WWW_DIR."/lib/postprocess.php"); -<<<<<<< HEAD -$db = new DB(); -$query = "SELECT COUNT(*) AS cnt from releases where musicinfoID IS NULL and categoryID in ( select ID from category where parentID = 3000 );"; - -$i=1; -while($i=1) -{ - $result = $db->query($query); - $count = $result[0]['cnt']; - - if ($count > 0) { - $postprocess = new PostProcess(true); - $postprocess->processMusic(); - } else { - printf("MusicPr : Processing $count audio releases\n"); - sleep(15); - } -} - -mysql_free_result($result); -======= $postprocess = new PostProcess(true); $postprocess->processMusic(); ->>>>>>> dev ?> diff --git a/bin/processTv.php b/bin/processTv.php index 40d0f60ac..77e9b21fa 100755 --- a/bin/processTv.php +++ b/bin/processTv.php @@ -3,30 +3,8 @@ require_once("config.php"); require_once(WWW_DIR."/lib/postprocess.php"); -<<<<<<< HEAD -$db = new DB(); -$query = "SELECT COUNT(*) AS cnt, ID from releases where rageID = -1 and categoryID in ( select ID from category where parentID = 5000 );"; - -$i=1; -while($i=1) -{ - $result = $db->query($query); - $count = $result[0]['cnt']; - - if ($count > 0) { - $postprocess = new PostProcess(true); - $postprocess->processTv(); - } else { - printf("TVRage : no work to be done\n"); - sleep(15); - } -} - -mysql_free_result($result); -======= $postprocess = new PostProcess(true); $postprocess->processTv(); ->>>>>>> dev ?> diff --git a/bin/workhorse.sh b/bin/workhorse.sh deleted file mode 100755 index 3714e20ec..000000000 --- a/bin/workhorse.sh +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/env bash -set -e - -source ../edit_these.sh -eval $( $SED -n "/^define/ { s/.*('\([^']*\)', '*\([^']*\)'*);/export \1=\"\2\"/; p }" "$NEWZPATH"/www/config.php ) - -#query for db to increment backfill -MYSQL_CMD="UPDATE groups set backfill_target=backfill_target+1 where active=1 and backfill_target<$MAXDAYS;" - -#queries for db for totals -book_query="SELECT COUNT(*) from releases where bookinfoID IS NULL and categoryID = 7020;" -console_query="SELECT COUNT(*) from releases where consoleinfoID IS NULL and categoryID in ( select ID from category where parentID = 1000 );" -movie_query="SELECT COUNT(*) from releases where imdbID IS NULL and categoryID in ( select ID from category where parentID = 2000 );" -music_query="SELECT COUNT(*) from releases where musicinfoID IS NULL and categoryID in ( select ID from category where parentID = 3000 );" -pc_query="SELECT COUNT(*) from releases r left join category c on c.ID = r.categoryID where (categoryID in ( select ID from category where parentID = 4000)) and ((r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0));" -tvrage_query="SELECT COUNT(*) from releases where rageID = -1 and categoryID in ( select ID from category where parentID = 5000 );" -work_remaining_query="SELECT COUNT(*) from releases r left join category c on c.ID = r.categoryID where (r.passwordstatus between -6 and -1) or (r.haspreview = -1 and c.disablepreview = 0);" - - -#query db for totals -function getCount() { -RELEASE_COUNT1=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${book_query}"` -RELEASE_COUNT2=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${console_query}"` -RELEASE_COUNT3=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${movie_query}"` -RELEASE_COUNT4=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${music_query}"` -RELEASE_COUNT5=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${pc_query}"` -RELEASE_COUNT6=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${tvrage_query}"` -RELEASE_COUNT7=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${work_remaining_query}"` -} - -if [ "$THREADS" == "true" -a "$INNODB" == "true" ]; then - while : - do - #sum of totals - getCount - TOTAL_COUNT=$(($RELEASE_COUNT1 + $RELEASE_COUNT2 + $RELEASE_COUNT3 + $RELEASE_COUNT4 + $RELEASE_COUNT5 + $RELEASE_COUNT6 + $RELEASE_COUNT7)) - - #make active groups current - if [[ $BINARIES == "true" ]] ; then - cd $NEWZNAB_PATH - [ -f update_binaries_threaded.php ] && $PHP update_binaries_threaded.php - fi - if [[ $TOTAL_COUNT -le $MAX_RELEASES ]]; then - #import nzb's - if [[ $IMPORT == "true" ]] ; then - cd $INNODB_PATH - [ -f nzb-import.php ] && $PHP nzb-import.php ${NZBS} & - fi - - #get backfill for all active groups - if [[ $BACKFILL == "true" ]] ; then - cd $NEWZNAB_PATH - [ -f backfill_threaded.php ] && $PHP backfill_threaded.php - fi - - wait - - #increment backfill days - if [[ $BACKFILL == "true" ]] ; then - $MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -e "${MYSQL_CMD}" - fi - else - echo "$TOTAL_COUNT unprocessed releases exceeds your threshold of $MAX_RELEASES..." - fi - - echo "Import scripts waiting $NEWZNAB_IMPORT_SLEEP_TIME seconds..." - sleep $NEWZNAB_IMPORT_SLEEP_TIME - - done - -elif [ "$THREADS" != "true" -a "$INNODB" == "true" ]; then - while : - do - #sum of totals - getCount - TOTAL_COUNT=$(($RELEASE_COUNT1 + $RELEASE_COUNT2 + $RELEASE_COUNT3 + $RELEASE_COUNT4 + $RELEASE_COUNT5 + $RELEASE_COUNT6 + $RELEASE_COUNT7)) - - #make active groups current - if [[ $BINARIES == "true" ]] ; then - cd $INNODB_PATH - [ -f update_binaries.php ] && $PHP update_binaries.php - fi - - if [[ $TOTAL_COUNT -le $MAX_RELEASES ]]; then - #import nzb's - if [[ $IMPORT == "true" ]] ; then - cd $INNODB_PATH - [ -f nzb-import.php ] && $PHP nzb-import.php ${NZBS} & - fi - - #get backfill for all active groups - if [[ $BACKFILL == "true" ]] ; then - cd $INNODB_PATH - [ -f backfill.php ] && $PHP backfill.php - fi - - wait - - #increment backfill days - if [[ $BACKFILL == "true" ]] ; then - $MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -e "${MYSQL_CMD}" - fi - else - echo "$TOTAL_COUNT unprocessed releases exceeds your threshold of $MAX_RELEASES..." - fi - - echo "Import scripts waiting $NEWZNAB_IMPORT_SLEEP_TIME seconds..." - sleep $NEWZNAB_IMPORT_SLEEP_TIME - - done - -elif [ "$THREADS" == "true" -a "$INNODB" != "true" ]; then - while : - do - #sum of totals - getCount - TOTAL_COUNT=$(($RELEASE_COUNT1 + $RELEASE_COUNT2 + $RELEASE_COUNT3 + $RELEASE_COUNT4 + $RELEASE_COUNT5 + $RELEASE_COUNT6 + $RELEASE_COUNT7)) - - #make active groups current - if [[ $BINARIES == "true" ]] ; then - cd $NEWZNAB_PATH - [ -f update_binaries_threaded.php ] && $PHP update_binaries_threaded.php - fi - - if [[ $TOTAL_COUNT -le $MAX_RELEASES ]]; then - #import nzb's - if [[ $IMPORT == "true" ]] ; then - cd $ADMIN_PATH - [ -f nzb-importmodified.php ] && $PHP nzb-importmodified.php ${NZBS} & - fi - - #make active groups current - if [[ $BINARIES == "true" ]] ; then - cd $NEWZNAB_PATH - [ -f update_binaries_threaded.php ] && $PHP update_binaries_threaded.php - fi - - #get backfill for all active groups - if [[ $BACKFILL == "true" ]] ; then - cd $NEWZNAB_PATH - [ -f backfill_threaded.php ] && $PHP backfill_threaded.php - fi - - wait - - #increment backfill days - if [[ $BACKFILL == "true" ]] ; then - $MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -e "${MYSQL_CMD}" - fi - else - echo "$TOTAL_COUNT unprocessed releases exceeds your threshold of $MAX_RELEASES..." - fi - - echo "Import scripts waiting $NEWZNAB_IMPORT_SLEEP_TIME seconds..." - sleep $NEWZNAB_IMPORT_SLEEP_TIME - - done - -elif [ "$THREADS" != "true" -a "$INNODB" != "true" ]; then - while : - do - - #sum of totals - getCount - TOTAL_COUNT=$(($RELEASE_COUNT1 + $RELEASE_COUNT2 + $RELEASE_COUNT3 + $RELEASE_COUNT4 + $RELEASE_COUNT5 + $RELEASE_COUNT6 + $RELEASE_COUNT7)) - - #make active groups current - if [[ $BINARIES == "true" ]] ; then - cd $NEWZNAB_PATH - [ -f update_binaries.php ] && $PHP update_binaries.php - fi - - if [[ $TOTAL_COUNT -le $MAX_RELEASES ]]; then - #import nzb's - if [[ $IMPORT == "true" ]] ; then - cd $ADMIN_PATH - [ -f nzb-importmodified.php ] && $PHP nzb-importmodified.php ${NZBS} & - fi - - - #get backfill for all active groups - if [[ $BACKFILL == "true" ]] ; then - cd $NEWZNAB_PATH - [ -f backfill.php ] && $PHP backfill.php - fi - - wait - - #increment backfill days - if [[ $BACKFILL == "true" ]] ; then - $MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -e "${MYSQL_CMD}" - fi - - else - echo "$TOTAL_COUNT unprocessed releases exceeds your threshold of $MAX_RELEASES..." - fi - - echo "Import scripts waiting $NEWZNAB_IMPORT_SLEEP_TIME seconds..." - sleep $NEWZNAB_IMPORT_SLEEP_TIME - - done - -fi - diff --git a/conf/tmux.conf b/conf/tmux.conf index b22910869..4126a4016 100755 --- a/conf/tmux.conf +++ b/conf/tmux.conf @@ -33,11 +33,7 @@ set-option -g status-interval 30 # Example of using a shell command in the status line #set -g status-right "#[fg=yellow]#(uptime | cut -d ',' -f 2-)" #set -g status-right "#[fg=red]#(ls -1 changeme | wc -l) NZB's left to process #[fg=yellow]#(uptime | cut -d ',' -f 2-)" -<<<<<<< HEAD:conf/.tmux.conf -set -g status-right "#[fg=red]#(ls -1 changeme | wc -l) NZB's left to process #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Used: \"$3\" MB\";}') #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Free: \"$4\" MB\";}') #[fg=yellow]#(free -m | grep 'Swap' | awk '{ print \"Swap Used: \"$3\" MB\";}') #[fg=yellow]#(uptime | cut -d ',' -f 2-)" -======= set -g status-right "#[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Used: \"$3\" MB\";}') #[fg=yellow]#(free -m | grep 'Mem' | awk '{ print \"Ram Free: \"$4\" MB\";}') #[fg=yellow]#(free -m | grep 'Swap' | awk '{ print \"Swap Used: \"$3\" MB\";}') #[fg=yellow]#(uptime | cut -d ',' -f 2-)" ->>>>>>> dev:conf/tmux.conf set-option -g status-right-length 200 #set -g status-right '#[fg=green][#[fg=blue]%Y-%m-%d #[fg=white]%H:%M#[default] #($HOME/bin/battery)#[fg=green]]' diff --git a/edit_these.sh b/edit_these.sh index 685e12aee..ac4ef83a7 100755 --- a/edit_these.sh +++ b/edit_these.sh @@ -8,29 +8,6 @@ export NEWZPATH="/var/www/newznab" export NEWZNAB_PATH=$NEWZPATH"/misc/update_scripts" export TESTING_PATH=$NEWZPATH"/misc/testing" export ADMIN_PATH=$NEWZPATH"/www/admin" -<<<<<<< HEAD -export INNODB_PATH=$TESTING_PATH"/innodb" - -#Select the user name that will run these scripts -export USERNAME="what is your name" - -#Enter the session name to be used by tmux -export TMUX_SESSION="Newznab-tmux" - -#Set, in seconds - how often the monitor.php script should up, 0 may cause errors -export MONITOR_UPDATE="60" - -#Set, in seconds - this includes import_nzb, backfill and current fill, 0 may cause errors -export NEWZNAB_IMPORT_SLEEP_TIME="60" - -#Set, in seconds - this is for post processing - sleep between loops, 0 may cause errors -export NEWZNAB_POST_SLEEP_TIME="1" - -#Set the maximum days tp backfill -export MAXDAYS="210" - -#Set the path to the nzb dump you downloaded from torrents -======= export INNODB_PATH=$DIR"/bin/innodb" #Post Processing Additional is the processing that downloads rar and attempts to get info for your site @@ -59,7 +36,6 @@ export MAXDAYS="210" #Set the path to the nzb dump you downloaded from torrents, theis is the path to bulk files folder of nzbs #this does not recurse through subfolders ->>>>>>> dev export NZBS="/path/to/nzbs" #Choose to run the threaded or non-threaded newznab scripts true/false @@ -84,10 +60,6 @@ export BACKFILL="true" #Choose to run import nzb script true/false export IMPORT="true" -<<<<<<< HEAD -#Set the max amount of unprocessed releases and still allow import or backfill to run -export MAX_RELEASES="30000" -======= #Choose to run optimise_db script true/false #set to false by default, you should test the optimse scripts in bin/innodb first export OPTIMISE="true" @@ -95,17 +67,13 @@ export OPTIMISE="true" #Set the max amount of unprocessed releases and still allow nzb-import, backfill and update_releases to run #set to 0 to disable export MAX_RELEASES="0" ->>>>>>> dev #Specify your SED binary export SED="/bin/sed" #export SED="/usr/local/bin/gsed" #Select some monitoring script, if they are not installed, it will not affect the running of the scripts -<<<<<<< HEAD -======= #these are set to false by default, enable if you want them ->>>>>>> dev export USE_HTOP="false" export USE_NMON="false" export USE_BWMNG="false" @@ -141,11 +109,5 @@ if [[ $USE_MYTOP == "true" ]]; then command -v mytop >/dev/null 2>&1|| { echo >&2 "I require mytop but it's not installed. Aborting."; exit 1; } && export MYTOP=`command -v mytop` fi if [[ $USE_VNSTAT == "true" ]]; then -<<<<<<< HEAD - command -v vnstat >/dev/null 2>&1|| { echo >&2 "I require vnstat but it's not installed. Aborting."; exit 1; } && export VNSTAT=`command -v vnstat` -fi - -======= command -v vnstat >/dev/null 2>&1|| { echo >&2 "I require vnstat but it's not installed. Aborting."; exit 1; } && export VNSTAT=`command -v vnstat` fi ->>>>>>> dev diff --git a/set_perms.sh b/set_perms.sh index 7c8eb7324..827682ad4 100755 --- a/set_perms.sh +++ b/set_perms.sh @@ -17,25 +17,7 @@ if [[ $AGREED == "no" ]]; then exit fi -<<<<<<< HEAD -echo -e "\033[38;5;148mcp $TESTING_PATH/nzb-importmodified.php $NEWZPATH/www/admin/" -cp $TESTING_PATH/nzb-importmodified.php $NEWZPATH/www/admin/ - -if [ -d "/home/$USERNAME" ]; then - echo "cp conf/.tmux.conf /home/$USERNAME/.tmux.conf" - cp conf/.tmux.conf /home/$USERNAME/.tmux.conf - $SED -i 's,'changeme,"$NZBS"',' "/home/$USERNAME/.tmux.conf" -fi -if [ -d "$HOME" ]; then - echo "cp conf/.tmux.conf $HOME/.tmux.conf" - cp conf/.tmux.conf $HOME/.tmux.conf - $SED -i 's,'changeme,"$NZBS"',' "$HOME/.tmux.conf" -fi - -echo "Editing $NEWZPATH/www/lib/postprocess.php" -======= echo -e "\033[38;5;148mEditing $NEWZPATH/www/lib/postprocess.php" ->>>>>>> dev if [ ! -f $NEWZPATH/www/lib/postprocess.php.orig ]; then cp $NEWZPATH/www/lib/postprocess.php $NEWZPATH/www/lib/postprocess.php.orig fi diff --git a/start.sh b/start.sh index 0bb4d58cb..48ccbb02a 100755 --- a/start.sh +++ b/start.sh @@ -17,11 +17,6 @@ if [[ $AGREED == "no" ]]; then echo "Please edit the edit_these.sh file" exit fi -<<<<<<< HEAD - -printf "\033]0; $TMUX_SESSION\007\003\n" -$TMUX new-session -d -s $TMUX_SESSION -n NewzNab 'cd bin && echo "monitor Working......" && nice -n 19 ./monitor.sh && exec bash -i' -======= #TMPUNRAR_QUERY="SELECT value from site where ID = 66;" #TMPUNRAR_PATH=`$MYSQL -u$DB_USER -h $DB_HOST --password=$DB_PASSWORD $DB_NAME -s -N -e "${TMPUNRAR_PATH}"` #echo "$TMPUNRAR_PATH"; @@ -72,25 +67,10 @@ $SED -i 's,'changeme,"$NZBS"',' "conf/tmux_user.conf" printf "\033]0; $TMUX_SESSION\007\003\n" $TMUX -f conf/tmux_user.conf new-session -d -s $TMUX_SESSION -n $TMUX_SESSION 'cd bin && echo "monitor Working......" && nice -n 19 $PHP monitor.php -i' ->>>>>>> dev $TMUX selectp -t 0 $TMUX splitw -h -p 72 'echo "..."' $TMUX splitw -h -p 50 'echo "..."' $TMUX selectp -t 0 -<<<<<<< HEAD -$TMUX splitw -v -p 65 'cd bin && echo "processNfos Working......" && sleep 3 && nice -n 19 ./postprocess_nfo.sh && exec bash -i' -$TMUX splitw -v -p 75 'cd bin && echo "processAdditional Thread #1 Working......" && sleep 6 && nice -n 19 ./processAlternate2.sh && exec bash -i' -$TMUX splitw -v -p 67 'cd bin && echo "processAdditional Thread #2 Working......" && sleep 9 && nice -n 19 ./processAlternate3.sh && exec bash -i' -$TMUX splitw -v -p 50 'cd bin && echo "processAdditional Thread #3 Working......" && sleep 12 && nice -n 19 ./processAlternate4.sh && exec bash -i' -$TMUX selectp -t 5 -$TMUX splitw -v -p 83 'cd bin && echo "Processing Games....." && sleep 15 && nice -n 19 ./postProcessing2.sh && exec bash -i' -$TMUX splitw -v -p 80 'cd bin && echo "Processing Movies....." && sleep 18 && nice -n 19 ./postProcessing3.sh && exec bash -i' -$TMUX splitw -v -p 75 'cd bin && echo "Processing Music....." && sleep 21 && nice -n 19 ./postProcessing4.sh && exec bash -i' -$TMUX splitw -v -p 67 'cd bin && echo "Processing TV....." && sleep 24 && nice -n 19 ./postProcessing5.sh && exec bash -i' -$TMUX splitw -v -p 50 'cd bin && echo "Processing Other....." && sleep 27 && nice -n 19 ./postProcessing6.sh && exec bash -i' -$TMUX selectp -t 11 -$TMUX splitw -v -p 50 'cd bin && echo "create Releases Working......" && nice -n 15 ./cleanup_scripts.sh && exec bash -i' -======= $TMUX splitw -v -p 65 'echo "..."' $TMUX splitw -v -p 80 'echo "..."' $TMUX splitw -v -p 75 'echo "..."' @@ -113,7 +93,6 @@ $TMUX selectp -t 0 $TMUX splitw -v -p 50 'echo "..."' $TMUX selectp -t 2 $TMUX splitw -v -p 50 'echo "..."' ->>>>>>> dev if [[ $USE_HTOP == "true" ]]; then $TMUX new-window -n htop '$HTOP'