if ($af->percent_done > 0 && $af->percent_done < 100) { // has downloaded something at some point, mark it is incomplete $af->running = "0"; $af->time_left = "Torrent Stopped"; } if ($af->percent_done == 0 || $af->percent_done == "") { $af->running = "2"; $af->time_left = ""; } if ($af->percent_done == 100) { // Torrent was seeding and is now being stopped $af->running = "0"; $af->time_left = "Download Succeeded!"; } // Write out the new Stat File $af->WriteFile(); // Remove Qinfo file. @unlink($cfg["torrent_file_path"] . "queue/" . $alias_file . ".Qinfo"); AuditAction($cfg["constants"]["unqueued_torrent"], $QEntry); } else { // torrent has been started... try and kill it. AuditAction($cfg["constants"]["unqueued_torrent"], $QEntry . "has been started -- TRY TO KILL IT"); header("location: index.php?alias_file=" . $alias_file . "&kill=true&kill_torrent=" . urlencode($QEntry)); exit; } header("location: index.php"); exit; } $drivespace = getDriveSpace($cfg["path"]); /************************************************************ ************************************************************/
function getDirList($dirName) { global $cfg, $db; include_once "AliasFile.php"; include_once "RunningTorrent.php"; $runningTorrents = getRunningTorrents(); $arList = array(); $file_filter = getFileFilter($cfg["file_types_array"]); if (is_dir($dirName)) { $handle = opendir($dirName); } else { // nothing to read if (IsAdmin()) { echo "<b>ERROR:</b> " . $dirName . " Path is not valid. Please edit <a href='admin.php?op=configSettings'>settings</a><br>"; } else { echo "<b>ERROR:</b> Contact an admin the Path is not valid.<br>"; } return; } $lastUser = ""; $arUserTorrent = array(); $arListTorrent = array(); 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; } } } } // sort the files by date krsort($arList); foreach ($arList as $entry) { $output = ""; $displayname = $entry; $show_run = true; $torrentowner = getOwner($entry); $owner = IsOwner($cfg["user"], $torrentowner); $kill_id = ""; $estTime = " "; $alias = getAliasName($entry) . ".stat"; $af = new AliasFile($dirName . $alias, $torrentowner); $timeStarted = ""; $torrentfilelink = ""; if (!file_exists($dirName . $alias)) { $af->running = "2"; // file is new $af->size = getDownloadSize($dirName . $entry); $af->WriteFile(); } if (strlen($entry) >= 47) { // needs to be trimmed $displayname = substr($entry, 0, 44); $displayname .= "..."; } // find out if any screens are running and take their PID and make a KILL option foreach ($runningTorrents as $key => $value) { $rt = new RunningTorrent($value); if ($rt->statFile == $alias) { if ($kill_id == "") { $kill_id = $rt->processId; } else { // there is more than one PID for this torrent // Add it so it can be killed as well. $kill_id .= "|" . $rt->processId; } } } // Check to see if we have a pid without a process. if (is_file($cfg["torrent_file_path"] . $alias . ".pid") && empty($kill_id)) { // died outside of tf and pid still exists. @unlink($cfg["torrent_file_path"] . $alias . ".pid"); if ($af->percent_done < 100 && $af->percent_done >= 0) { // The file is not running and the percent done needs to be changed $af->percent_done = ($af->percent_done + 100) * -1; } $af->running = "0"; $af->time_left = "Torrent Died"; $af->up_speed = ""; $af->down_speed = ""; // write over the status file so that we can display a new status $af->WriteFile(); } if ($cfg["enable_torrent_download"]) { $torrentfilelink = "<a href=\"maketorrent.php?download=" . urlencode($entry) . "\"><img src=\"images/down.gif\" width=9 height=9 title=\"Download Torrent File\" border=0 align=\"absmiddle\"></a>"; } $hd = getStatusImage($af); $output .= "<tr><td class=\"tiny\"><img src=\"images/" . $hd->image . "\" width=16 height=16 title=\"" . $hd->title . $entry . "\" border=0 align=\"absmiddle\">" . $torrentfilelink . $displayname . "</td>"; $output .= "<td align=\"right\"><font class=\"tiny\">" . formatBytesToKBMGGB($af->size) . "</font></td>"; $output .= "<td align=\"center\"><a href=\"message.php?to_user="******"\"><font class=\"tiny\">" . $torrentowner . "</font></a></td>"; $output .= "<td valign=\"bottom\"><div align=\"center\">"; if ($af->running == "2") { $output .= "<i><font color=\"#32cd32\">" . _NEW . "</font></i>"; } elseif ($af->running == "3") { $estTime = "Waiting..."; $qDateTime = ''; if (is_file($dirName . "queue/" . $alias . ".Qinfo")) { $qDateTime = date("m/d/Y H:i:s", strval(filectime($dirName . "queue/" . $alias . ".Qinfo"))); } $output .= "<i><font color=\"#000000\" onmouseover=\"return overlib('" . _QUEUED . ": " . $qDateTime . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">" . _QUEUED . "</font></i>"; } else { if ($af->time_left != "" && $af->time_left != "0") { $estTime = $af->time_left; } $sql_search_time = "Select time from tf_log where action like '%Upload' and file like '" . $entry . "%'"; $result_search_time = $db->Execute($sql_search_time); list($uploaddate) = $result_search_time->FetchRow(); $lastUser = $torrentowner; $sharing = $af->sharing . "%"; $graph_width = 1; $progress_color = "#00ff00"; $background = "#000000"; $bar_width = "4"; $popup_msg = _ESTIMATEDTIME . ": " . $af->time_left; $popup_msg .= "<br>" . _DOWNLOADSPEED . ": " . $af->down_speed; $popup_msg .= "<br>" . _UPLOADSPEED . ": " . $af->up_speed; $popup_msg .= "<br>" . _SHARING . ": " . $sharing; $popup_msg .= "<br>Seeds: " . $af->seeds; $popup_msg .= "<br>Peers: " . $af->peers; $popup_msg .= "<br>" . _USER . ": " . $torrentowner; $eCount = 0; foreach ($af->errors as $key => $value) { if (strpos($value, " (x")) { $curEMsg = substr($value, strpos($value, " (x") + 3); $eCount += substr($curEMsg, 0, strpos($curEMsg, ")")); } else { $eCount += 1; } } $popup_msg .= "<br>" . _ERRORSREPORTED . ": " . strval($eCount); $popup_msg .= "<br>" . _UPLOADED . ": " . date("m/d/Y H:i:s", $uploaddate); if (is_file($dirName . $alias . ".pid")) { $timeStarted = "<br>" . _STARTED . ": " . date("m/d/Y H:i:s", strval(filectime($dirName . $alias . ".pid"))); } // incriment the totals if (!isset($cfg["total_upload"])) { $cfg["total_upload"] = 0; } if (!isset($cfg["total_download"])) { $cfg["total_download"] = 0; } $cfg["total_upload"] = $cfg["total_upload"] + GetSpeedValue($af->up_speed); $cfg["total_download"] = $cfg["total_download"] + GetSpeedValue($af->down_speed); if ($af->percent_done >= 100) { if (trim($af->up_speed) != "" && $af->running == "1") { $popup_msg .= $timeStarted; $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" style=\"font-size:7pt;\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">seeding (" . $af->up_speed . ") " . $sharing . "</a>"; } else { $popup_msg .= "<br>" . _ENDED . ": " . date("m/d/Y H:i:s", strval(filemtime($dirName . $alias))); $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\"><i><font color=red>" . _DONE . "</font></i></a>"; } $show_run = false; } else { if ($af->percent_done < 0) { $popup_msg .= $timeStarted; $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\"><i><font color=\"#989898\">" . _INCOMPLETE . "</font></i></a>"; $show_run = true; } else { $popup_msg .= $timeStarted; if ($af->percent_done > 1) { $graph_width = $af->percent_done; } if ($graph_width == 100) { $background = $progress_color; } $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">"; $output .= "<font class=\"tiny\"><strong>" . $af->percent_done . "%</strong> @ " . $af->down_speed . "</font></a><br>"; $output .= "<table width=\"100\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; $output .= "<tr><td background=\"themes/" . $cfg["theme"] . "/images/progressbar.gif\" bgcolor=\"" . $progress_color . "\"><img src=\"images/blank.gif\" width=\"" . $graph_width . "\" height=\"" . $bar_width . "\" border=\"0\"></td>"; $output .= "<td bgcolor=\"" . $background . "\"><img src=\"images/blank.gif\" width=\"" . (100 - $graph_width) . "\" height=\"" . $bar_width . "\" border=\"0\"></td>"; $output .= "</tr></table>"; } } } $output .= "</div></td>"; $output .= "<td><div class=\"tiny\" align=\"center\">" . $estTime . "</div></td>"; $output .= "<td><div align=center>"; $torrentDetails = _TORRENTDETAILS; if ($lastUser != "") { $torrentDetails .= "\n" . _USER . ": " . $lastUser; } $output .= "<a href=\"details.php?torrent=" . urlencode($entry); if ($af->running == 1) { $output .= "&als=false"; } $output .= "\"><img src=\"images/properties.png\" width=18 height=13 title=\"" . $torrentDetails . "\" border=0></a>"; if ($owner || IsAdmin($cfg["user"])) { if ($kill_id != "" && $af->percent_done >= 0 && $af->running == 1) { $output .= "<a href=\"index.php?alias_file=" . $alias . "&kill=" . $kill_id . "&kill_torrent=" . urlencode($entry) . "\"><img src=\"images/kill.gif\" width=16 height=16 title=\"" . _STOPDOWNLOAD . "\" border=0></a>"; $output .= "<img src=\"images/delete_off.gif\" width=16 height=16 border=0>"; } else { if ($torrentowner == "n/a") { $output .= "<img src=\"images/run_off.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; } else { if ($af->running == "3") { $output .= "<a href=\"index.php?alias_file=" . $alias . "&dQueue=" . $kill_id . "&QEntry=" . urlencode($entry) . "\"><img src=\"images/queued.gif\" width=16 height=16 title=\"" . _DELQUEUE . "\" border=0></a>"; } else { if (!is_file($cfg["torrent_file_path"] . $alias . ".pid")) { // Allow Avanced start popup? if ($cfg["advanced_start"]) { if ($show_run) { $output .= "<a href=\"#\" onclick=\"StartTorrent('startpop.php?torrent=" . urlencode($entry) . "')\"><img src=\"images/run_on.gif\" width=16 height=16 title=\"" . _RUNTORRENT . "\" border=0></a>"; } else { $output .= "<a href=\"#\" onclick=\"StartTorrent('startpop.php?torrent=" . urlencode($entry) . "')\"><img src=\"images/seed_on.gif\" width=16 height=16 title=\"" . _SEEDTORRENT . "\" border=0></a>"; } } else { // Quick Start if ($show_run) { $output .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?torrent=" . urlencode($entry) . "\"><img src=\"images/run_on.gif\" width=16 height=16 title=\"" . _RUNTORRENT . "\" border=0></a>"; } else { $output .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?torrent=" . urlencode($entry) . "\"><img src=\"images/seed_on.gif\" width=16 height=16 title=\"" . _SEEDTORRENT . "\" border=0></a>"; } } } else { // pid file exists so this may still be running or dieing. $output .= "<img src=\"images/run_off.gif\" width=16 height=16 border=0 title=\"" . _STOPPING . "\">"; } } } if (!is_file($cfg["torrent_file_path"] . $alias . ".pid")) { $deletelink = $_SERVER['PHP_SELF'] . "?alias_file=" . $alias . "&delfile=" . urlencode($entry); $output .= "<a href=\"" . $deletelink . "\" onclick=\"return ConfirmDelete('" . $entry . "')\"><img src=\"images/delete_on.gif\" width=16 height=16 title=\"" . _DELETE . "\" border=0></a>"; } else { // pid file present so process may be still running. don't allow deletion. $output .= "<img src=\"images/delete_off.gif\" width=16 height=16 title=\"" . _STOPPING . "\" border=0>"; } } } else { $output .= "<img src=\"images/locked.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; $output .= "<img src=\"images/locked.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; } $output .= "</div>"; $output .= "</td>"; $output .= "</tr>\n"; // Is this torrent for the user list or the general list? if ($cfg["user"] == getOwner($entry)) { array_push($arUserTorrent, $output); } else { array_push($arListTorrent, $output); } } closedir($handle); // Now spit out the junk echo "<table bgcolor=\"" . $cfg["table_data_bg"] . "\" width=\"100%\" bordercolor=\"" . $cfg["table_border_dk"] . "\" border=1 cellpadding=3 cellspacing=0>"; if (sizeof($arUserTorrent) > 0) { echo "<tr><td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . $cfg["user"] . ": " . _TORRENTFILE . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">Size</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _USER . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _STATUS . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ESTIMATEDTIME . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ADMIN . "</div></td>"; echo "</tr>\n"; foreach ($arUserTorrent as $torrentrow) { echo $torrentrow; } } if (sizeof($arListTorrent) > 0) { echo "<tr><td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _TORRENTFILE . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">Size</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _USER . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _STATUS . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ESTIMATEDTIME . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ADMIN . "</div></td>"; echo "</tr>\n"; foreach ($arListTorrent as $torrentrow) { echo $torrentrow; } } }