diff -x config.php -Naur TF2.1/functions.php TF2.1-resumeall/functions.php --- TF2.1/functions.php 2006-04-05 00:58:14.000000000 -0400 +++ TF2.1-resumeall/functions.php 2006-06-27 23:11:38.000000000 -0400 @@ -94,6 +94,23 @@ $create_time = time(); + /* + * Allow localhost clients to issue + * stopall and resumeall commands without + * logging in. + INSTALL: + patch -Np1 < patchfile + */ + if(($cfg["ip"] == '127.0.0.1') + && (array_key_exists('resumeall',$_GET) + || array_key_exists('stopall',$_GET)) + // prevent other params from being modified + && (count($_GET) == 1) + ) + { + $cfg["theme"] = $cfg["default_theme"]; + $cfg["language_file"] = $cfg["default_language"]; + return; + } + if(!isset($_SESSION['user'])) { header('location: login.php'); diff -x config.php -Naur TF2.1/index.php TF2.1-resumeall/index.php --- TF2.1/index.php 2006-04-01 00:15:07.000000000 -0500 +++ TF2.1-resumeall/index.php 2006-06-28 00:01:57.000000000 -0400 @@ -477,6 +477,168 @@ } // End File Upload +// Did the user issue the stop all command? +$stopall = getRequestVar('stopall'); + +if (!($stopall == '') && IsAdmin($cfg["user"]) == true) +{ + include_once("AliasFile.php"); + include_once("RunningTorrent.php"); + $dirName = $cfg["torrent_file_path"]; + $screenStatus = shell_exec("ps x -w -w"); + $arList = array(); + $totals = array_fill(1, 5, 0); + $file_filter = getFileFilter($cfg["file_types_array"]); + $handle = opendir($dirName); + $lastUser = ""; + while ($entry = readdir($handle)) + { + if ($entry != "." && $entry != "..") + { + if (is_dir($dirName."/".$entry)) + { + // don't do a thing + } else { + if (ereg($file_filter, $entry)) + { + $key = filemtime($dirName."/".$entry).md5($entry); + $arList[$key] = $entry; + } + } + } + } + foreach($arList as $entry) { + $the_user = getOwner($entry); + $alias = getAliasName($entry).".stat"; + $af = new AliasFile($cfg["torrent_file_path"].$alias, $the_user); + if ($af->running != "2" && $af->time_left != "Torrent Died") + { + if ($af->percent_done < 100) + { + // The torrent is being stopped but is not completed dowloading + $af->percent_done = ($af->percent_done + 100) * -1; + $af->running = "0"; + $af->time_left = "Torrent Stopped"; + } else { + // Torrent was seeding and is now being stopped + $af->percent_done = 100; + $af->running = "0"; + $af->time_left = "Download Succeeded!"; + } + + // see if the torrent process is hung. + if (!is_file($cfg["torrent_file_path"].$alias_file.".pid")) + { + $runningTorrents = getRunningTorrents(); + foreach ($runningTorrents as $key => $value) + { + $rt = new RunningTorrent($value); + if ($rt->statFile == $alias_file) { + AuditAction($cfg["constants"]["error"], "Posible Hung Process " . $rt->processId); + // $result = exec("kill ".$rt->processId); + } + } + } + + // Write out the new Stat File + $af->WriteFile(); + } + } + AuditAction("ADMIN", "Stop All Torrents"); + header("location: index.php"); +} + +// Did the user issue the resume all command? +$resumeall = getRequestVar('resumeall'); + +if ( + ( + !($resumeall == '') && + ( + IsAdmin($cfg["user"]) || + ($cfg["ip"] == '127.0.0.1') // Allows resuming at startup + ) + ) == true + ) +{ + include_once("AliasFile.php"); + $dirName = $cfg["torrent_file_path"]; + $screenStatus = shell_exec("ps x -w -w"); + $arList = array(); + $totals = array_fill(1, 5, 0); + $file_filter = getFileFilter($cfg["file_types_array"]); + $handle = opendir($dirName); + $lastUser = ""; + while ($entry = readdir($handle)) + { + if ($entry != "." && $entry != "..") + { + if (is_dir($dirName."/".$entry)) + { + // don't do a thing + } else { + if (ereg($file_filter, $entry)) + { + $key = filemtime($dirName."/".$entry).md5($entry); + $arList[$key] = $entry; + } + } + } + } + foreach($arList as $entry) + { + $the_user = getOwner($entry); + $alias = getAliasName($entry).".stat"; + $af = new AliasFile($cfg["torrent_file_path"].$alias, $the_user); + if ( + ($af->running == 0 && $af->percent_done <= 100) || + ($af->running == 1 && $af->percent_done == 0 && $af->time_left == "") + ) + { + $superseeder = ($af->percent_done < 100 ? 0 : 1); // become a superseeder if the xfer is done + $af->StartTorrentFile(); // this only writes out the stat file (does not start torrent) + //$command = "cd ".$cfg["path"].$the_user."; HOME=".$cfg["path"]."; export HOME; nohup ".$cfg["btphpbin"]." ".$cfg["torrent_dies_when_done"]." -1 ".$cfg["torrent_file_path"].$alias." ".$the_user." --responsefile '".$cfg["torrent_file_path"].$entry."' --display_interval 5 --max_upload_rate ".$cfg["max_upload_rate"]." --max_uploads ".$cfg["max_uploads"]." --minport ".$cfg["minport"]." --maxport ".$cfg["maxport"]." --super_seeder ".$superseeder." ".$cfg["cmd_options"]." > /dev/null &"; + $command = $cfg["torrent_dies_when_done"]." ".$cfg["sharekill"]." ".$cfg["torrent_file_path"].$alias." ".$the_user." --responsefile '".$cfg["torrent_file_path"].$entry."' --display_interval 5 --max_download_rate ". $cfg["max_download_rate"]." --max_upload_rate ".$cfg["max_upload_rate"]." --max_uploads ".$cfg["max_uploads"]." --minport ".$cfg["minport"]." --maxport ".$cfg["maxport"]." --rerequest_interval ".$cfg["rerequest_interval"]." --super_seeder ".$superseeder; + + if(file_exists($cfg["torrent_file_path"].$alias.".prio")) { + $priolist = explode(',',file_get_contents($cfg["torrent_file_path"].$alias.".prio")); + $priolist = implode(',',array_slice($priolist,1,$priolist[0])); + $command .= " --priority ".$priolist; + } + + $command .= " ".$cfg["cmd_options"]." > /dev/null &"; + if (! array_key_exists("pythonCmd", $cfg)) + { + insertSetting("pythonCmd","/usr/bin/python"); + } + + if (! array_key_exists("debugTorrents", $cfg)) + { + insertSetting("debugTorrents", "0"); + } + + if (!$cfg["debugTorrents"]) + { + $pyCmd = $cfg["pythonCmd"] . " -OO"; + }else{ + $pyCmd = $cfg["pythonCmd"]; + } + + $command = "cd " . $cfg["path"] . $the_user . "; HOME=".$cfg["path"]."; export HOME; nohup " . $pyCmd . " " .$cfg["btphpbin"] . " " . $command; + $result = exec($command); + + // slow down and wait for threads to kick off. + // otherwise on fast servers it will kill stop it before it gets a chance to run. + sleep(1); + + $af->WriteFile(); + } + } + AuditAction("ADMIN", "Start All Torrents"); + + header("location: index.php"); +} + // if a file was set to be deleted then delete it $delfile = getRequestVar('delfile'); if(! $delfile == '') @@ -668,6 +830,10 @@ { myWindow = window.open (name_file,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=530') } +function ConfirmStopAll() +{ + return confirm("Stop all torrents?"); +} function ConfirmDelete(file) { return confirm(": " + file) @@ -833,6 +999,14 @@ | ">My Directory + | + Start/Resume All Torrents '; + echo 'Stop All Torrents'; + } + ?>