/**
  * stops a bittorrent-client
  *
  * @param $torrent name of the torrent
  * @param $aliasFile alias-file of the torrent
  * @param $kill kill-param
  * @param $return return-param
  */
 function doStopTorrentClient($torrent, $aliasFile, $torrentPid = "", $return = "")
 {
     // set some vars
     $this->torrent = $torrent;
     $this->alias = $aliasFile;
     // set pidfile
     if ($this->pidFile == "") {
         // pid-file not set in subclass. use a default
         $this->pidFile = $this->cfg["torrent_file_path"] . $this->alias . ".pid";
     }
     // We are going to write a '0' on the front of the stat file so that
     // the BT client will no to stop -- this will report stats when it dies
     $this->owner = getOwner($this->torrent);
     include_once "AliasFile.php";
     // read the alias file + create AliasFile object
     $this->af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $this->alias, $this->owner, $this->cfg, $this->handlerName);
     if ($this->af->percent_done < 100) {
         // The torrent is being stopped but is not completed dowloading
         $this->af->percent_done = ($this->af->percent_done + 100) * -1;
         $this->af->running = "0";
         $this->af->time_left = "Torrent Stopped";
     } else {
         // Torrent was seeding and is now being stopped
         $this->af->percent_done = 100;
         $this->af->running = "0";
         $this->af->time_left = "Download Succeeded!";
     }
     include_once "RunningTorrent.php";
     // see if the torrent process is hung.
     if (!is_file($this->pidFile)) {
         $runningTorrents = getRunningTorrents();
         foreach ($runningTorrents as $key => $value) {
             $rt = RunningTorrent::getRunningTorrentInstance($value, $this->cfg, $this->handlerName);
             if ($rt->statFile == $this->alias) {
                 AuditAction($this->cfg["constants"]["error"], "Posible Hung Process " . $rt->processId);
                 //    $callResult = exec("kill ".$rt->processId);
             }
         }
     }
     // Write out the new Stat File
     $this->af->WriteFile();
     // flag the torrent as stopped (in db)
     // blame me for this dirty shit, i am lazy. of course this should be
     // hooked into the place where client really dies.
     stopTorrentSettings($this->torrent);
     //
     AuditAction($this->cfg["constants"]["kill_torrent"], $this->torrent);
     if (!empty($return)) {
         sleep(3);
         // set pid
         if (isset($torrentPid) && $torrentPid != "") {
             $this->pid = $torrentPid;
         } else {
             $this->pid = trim(shell_exec($this->cfg['bin_cat'] . " " . $this->pidFile));
         }
         // kill it
         $this->callResult = exec("kill " . $this->pid);
         // try to remove the pid file
         @unlink($this->pidFile);
     }
 }
Example #2
0
function queueSettings()
{
    global $cfg;
    include_once "AliasFile.php";
    include_once "RunningTorrent.php";
    include_once "QueueManager.php";
    $queueManager = QueueManager::getQueueManagerInstance($cfg);
    // QueueManager Running ?
    $queueManagerRunning = false;
    $shutdown = getRequestVar('s');
    if (isset($shutdown) && $shutdown == "1") {
        $queueManagerRunning = false;
    } else {
        if ($queueManager->isQueueManagerRunning()) {
            $queueManagerRunning = true;
        } else {
            if ($queueManager->managerName == "tfqmgr") {
                if ($queueManager->isQueueManagerReadyToStart()) {
                    $queueManagerRunning = false;
                } else {
                    $queueManagerRunning = true;
                }
            } else {
                $queueManagerRunning = false;
            }
        }
    }
    // head
    DisplayHead("Administration - Queue Settings");
    // Admin Menu
    displayMenu();
    // message section
    $message = getRequestVar('m');
    if (isset($message) && $message != "") {
        echo '<table cellpadding="5" cellspacing="0" border="0" width="100%">';
        echo '<tr><td align="center" bgcolor="' . $cfg["table_header_bg"] . '"><strong>';
        echo urldecode($message);
        echo '</strong></td></tr></table>';
    }
    // Queue Manager Section
    echo "<div align=\"center\">";
    echo "<a name=\"QManager\" id=\"QManager\"></a>";
    echo "<table width=\"100%\" border=1 bordercolor=\"" . $cfg["table_admin_border"] . "\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"" . $cfg["table_data_bg"] . "\">";
    echo "<tr><td bgcolor=\"" . $cfg["table_header_bg"] . "\" background=\"themes/" . $cfg["theme"] . "/images/bar.gif\">";
    echo "<font class=\"title\">";
    //if(checkQManager() > 0)
    //	   echo "&nbsp;&nbsp;<img src=\"images/green.gif\" align=\"absmiddle\" align=\"absmiddle\"> Queue Manager Running [PID=".getQManagerPID()." with ".strval(getRunningTorrentCount())." torrent(s)]";
    if ($queueManagerRunning) {
        echo "&nbsp;&nbsp;<img src=\"images/green.gif\" align=\"absmiddle\" align=\"absmiddle\"> Queue Manager Running (" . $queueManager->managerName . "; pid: " . $queueManager->getQueueManagerPid() . ")";
    } else {
        echo "&nbsp;&nbsp;<img src=\"images/black.gif\" align=\"absmiddle\"> Queue Manager Off";
    }
    echo "</font>";
    echo "</td></tr><tr><td align=\"center\">";
    ?>
	<script language="JavaScript">
	function validateSettings()
	{
		var rtnValue = true;
		var msg = "";
		if (isNumber(document.theForm.maxServerThreads.value) == false)
		{
			msg = msg + "* Max Server Threads must be a valid number.\n";
			document.theForm.maxServerThreads.focus();
		}
		if (isNumber(document.theForm.maxUserThreads.value) == false)
		{
			msg = msg + "* Max User Threads must be a valid number.\n";
			document.theForm.maxUserThreads.focus();
		}
		if (isNumber(document.theForm.sleepInterval.value) == false)
		{
			msg = msg + "* Sleep Interval must be a valid number.\n";
			document.theForm.sleepInterval.focus();
		}

		if (msg != "")
		{
			rtnValue = false;
			alert("Please check the following:\n\n" + msg);
		}

		return rtnValue;
	}
	function isNumber(sText)
	{
		var ValidChars = "0123456789.";
		var IsNumber = true;
		var Char;

		for (i = 0; i < sText.length && IsNumber == true; i++)
		{
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1)
			{
				IsNumber = false;
			}
		}

		return IsNumber;
	}
	</script>
	<div align="center">

		<table cellpadding="5" cellspacing="0" border="0" width="100%">

<?php 
    //if ((! $queueManager->isQueueManagerRunning()) && ( !$queueManager->isQueueManagerReadyToStart())) {
    if (isset($shutdown) && $shutdown == "1") {
        echo '<tr><br>';
        echo '<td align="center" colspan="2">';
        echo 'QueueManager going down... Please Wait.';
        echo '<br><br></td>';
        echo '</tr>';
    } else {
        echo '<form name="controlForm" action="admin.php?op=controlQueueManager" method="post">';
        if ($queueManagerRunning) {
            echo '<input type="Hidden" name="a" value="stop">';
            echo '<tr><br>';
            echo '<td align="center" colspan="2">';
            echo '<input type="Submit" value="Stop QueueManager">';
            echo '<br><br></td>';
            echo '</tr>';
        } else {
            echo '<input type="Hidden" name="a" value="start">';
            echo '<tr>';
            echo '<td align="left" width="350" valign="top"><strong>Choose Queue Manager</strong><br>';
            echo '<u>Note</u> : tfQManager only supports tornado-clients.';
            echo '</td>';
            echo '<td>';
            echo '<select name="queuemanager">';
            echo '<option value="tfqmgr"';
            if ($cfg["queuemanager"] == "tfqmgr") {
                echo " selected";
            }
            echo '>tfqmgr</option>';
            echo '<option value="Qmgr"';
            if ($cfg["queuemanager"] == "Qmgr") {
                echo " selected";
            }
            echo '>Qmgr</option>';
            echo '<option value="tfQManager"';
            if ($cfg["queuemanager"] == "tfQManager") {
                echo " selected";
            }
            echo '>tfQManager</option>';
            echo '</select>';
            echo '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td align="center" colspan="2">';
            echo '<input type="Submit" value="Start QueueManager">';
            echo '<br><br></td>';
            echo '</tr>';
        }
        echo '</form>';
    }
    ?>

			<form name="theForm" action="admin.php?op=updateQueueSettings" method="post" onsubmit="return validateSettings()">

			<tr>
			 <td colspan="2" align="center" bgcolor="<?php 
    echo $cfg["table_header_bg"];
    ?>
">
			  <strong>tfqmgr</strong>&nbsp;
			  <?php 
    echo '(';
    printSuperAdminLink('?q=1', 'log');
    echo ' | ';
    printSuperAdminLink('?q=2', 'ps');
    if (isset($shutdown) && $shutdown == "1") {
    } else {
        if ($queueManagerRunning && $queueManager->managerName == "tfqmgr") {
            echo ' | ';
            printSuperAdminLink('?q=3', 'status');
        }
    }
    echo ' )';
    ?>
			 </td>
			</tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>perl Path</strong><br>
				Specify the path to perl (/usr/bin/perl):
				</td>
				<td valign="top">
					<input name="perlCmd" type="Text" maxlength="254" value="<?php 
    echo $cfg["perlCmd"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["perlCmd"]);
    ?>
				</td>
			</tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>tfqmgr Path</strong><br>
				Specify the path of tfqmgr (/var/www/tfqmgr):
				</td>
				<td valign="top">
					<input name="tfqmgr_path" type="Text" maxlength="254" value="<?php 
    echo $cfg["tfqmgr_path"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["tfqmgr_path"] . "/tfqmgr.pl");
    ?>
				</td>
			</tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>fluxcli Path</strong><br>
				Specify the path where fluxcli.php is. (/var/www):
				</td>
				<td valign="top">
					<input name="tfqmgr_path_fluxcli" type="Text" maxlength="254" value="<?php 
    echo $cfg["tfqmgr_path_fluxcli"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["tfqmgr_path_fluxcli"] . "/fluxcli.php");
    ?>
				</td>
			</tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>Limit Torrent Global</strong><br>
				Specify the maximum number of torrents the server will allow to run at one time (admins may override this):
				</td>
				<td valign="top">
					<input name="tfqmgr_limit_global" type="Text" maxlength="3" value="<?php 
    echo $cfg["tfqmgr_limit_global"];
    ?>
" size="3">
				</td>
			</tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>Limit Torrent Per User</strong><br>
				Specify the maximum number of torrents a single user may run at one time:
				</td>
				<td valign="top">
					<input name="tfqmgr_limit_user" type="Text" maxlength="3" value="<?php 
    echo $cfg["tfqmgr_limit_user"];
    ?>
" size="3">
				</td>
			</tr>

			<tr><td colspan="2" align="center" bgcolor="<?php 
    echo $cfg["table_header_bg"];
    ?>
"><strong>Qmgr</strong></td></tr>
			<tr>
			   <td align="left" width="350" valign="top"><strong>Path to Qmgr scripts</strong><br>
			   Specify the path to the Qmgr.pl and Qmgrd.pl scripts:
			   </td>
			   <td valign="top">
				   <input name="Qmgr_path" type="Text" maxlength="254" value="<?php 
    echo $cfg["Qmgr_path"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["Qmgr_path"] . "/Qmgrd.pl");
    ?>
			   </td>
			</tr>
			<tr>
			   <td align="left" width="350" valign="top"><strong>Max User Torrents</strong><br>
			   Total number of torrents to allow a single user at once:
			   </td>
			   <td valign="top">
				   <input name="Qmgr_maxUserTorrents" type="Text" maxlength="3" value="<?php 
    echo $cfg["Qmgr_maxUserTorrents"];
    ?>
" size="3">
			   </td>
			</tr>
			<tr>
			   <td align="left" width="350" valign="top"><strong>Max Total Torrents</strong><br>
			   Total number of torrents the server will run at once:
			   </td>
			   <td valign="top">
				   <input name="Qmgr_maxTotalTorrents" type="Text" maxlength="3" value="<?php 
    echo $cfg["Qmgr_maxTotalTorrents"];
    ?>
" size="3">
			   </td>
			</tr>
			<tr>
			   <td align="left" width="350" valign="top"><strong>Perl's Path</strong><br>
			   Specify the path to perl:
			   </td>
			   <td valign="top">
				   <input name="Qmgr_perl" type="Text" maxlength="254" value="<?php 
    echo $cfg["Qmgr_perl"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["Qmgr_perl"]);
    ?>
			   </td>
			</tr>
			<tr>
			   <td align="left" width="350" valign="top"><strong>Fluxcli.php path</strong><br>
			   Specify the path to the fluxcli executable:
			   </td>
			   <td valign="top">
				   <input name="Qmgr_fluxcli" type="Text" maxlength="254" value="<?php 
    echo $cfg["Qmgr_fluxcli"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["Qmgr_fluxcli"] . "/fluxcli.php");
    ?>
			   </td>
			</tr>
			<tr>
			   <td align="left" width="350" valign="top"><strong>Qmgrd host</strong><br>
			   The host running the Qmgrd.pl script, probably localhost:
			   </td>
			   <td valign="top">
				   <input name="Qmgr_host" type="Text" maxlength="254" value="<?php 
    echo $cfg["Qmgr_host"];
    ?>
" size="15">
			   </td>
			</tr>
			<tr>
			   <td align="left" width="250" valign="top"><strong>Qmgrd port</strong><br>
			   the port number to run the Qmgrd.pl script on:
			   </td>
			   <td valign="top">
				   <input name="Qmgr_port" type="Text" maxlength="5" value="<?php 
    echo $cfg["Qmgr_port"];
    ?>
" size="5">
			   </td>
			</tr>

			<tr><td colspan="2" align="center" bgcolor="<?php 
    echo $cfg["table_header_bg"];
    ?>
"><strong>tfQManager</strong></td></tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>tfQManager Path</strong><br>
				Specify the path to the tfQManager.py python script:
				</td>
				<td valign="top">
					<input name="tfQManager" type="Text" maxlength="254" value="<?php 
    echo $cfg["tfQManager"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["tfQManager"]);
    ?>
				</td>
			</tr>

			<tr>
				<td align="left" width="350" valign="top"><strong>Max Server Threads</strong><br>
				Specify the maximum number of torrents the server will allow to run at
				one time (admins may override this):
				</td>
				<td valign="top">
					<input name="maxServerThreads" type="Text" maxlength="3" value="<?php 
    echo $cfg["maxServerThreads"];
    ?>
" size="3">
				</td>
			</tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>Max User Threads</strong><br>
				Specify the maximum number of torrents a single user may run at
				one time:
				</td>
				<td valign="top">
					<input name="maxUserThreads" type="Text" maxlength="3" value="<?php 
    echo $cfg["maxUserThreads"];
    ?>
" size="3">
				</td>
			</tr>
			<tr>
				<td align="left" width="350" valign="top"><strong>Polling Interval</strong><br>
				Number of seconds the Queue Manager will sleep before checking for new torrents to run:
				</td>
				<td valign="top">
					<input name="sleepInterval" type="Text" maxlength="3" value="<?php 
    echo $cfg["sleepInterval"];
    ?>
" size="3">
				</td>
			</tr>
			<tr><td colspan="2"><hr noshade></td></tr>
			<tr>
				<td align="center" colspan="2">
				<input type="Submit" value="Update Settings">
				</td>
			</tr>
			</form>
		</table>


		</div>
	<br>
<?php 
    echo "</td></tr>";
    echo "</table></div>";
    $displayQueue = True;
    $displayRunningTorrents = True;
    // Its a timming thing.
    if ($displayRunningTorrents) {
        // get Running Torrents.
        $runningTorrents = getRunningTorrents();
    }
    // _queue_
    if ($displayQueue) {
        echo "\n";
        echo "<table width=\"760\" border=1 bordercolor=\"" . $cfg["table_admin_border"] . "\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"" . $cfg["table_data_bg"] . "\">";
        echo "<tr><td colspan=6 bgcolor=\"" . $cfg["table_header_bg"] . "\" background=\"themes/" . $cfg["theme"] . "/images/bar.gif\">";
        echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>";
        echo "<td><img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\"> Queued Items </font></td>";
        echo "</tr></table>";
        echo "</td></tr>";
        echo "<tr>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"15%\"><div align=center class=\"title\">" . _USER . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _FILE . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"15%\"><div align=center class=\"title\">" . _TIMESTAMP . "</div></td>";
        echo "</tr>";
        echo "\n";
        echo $queueManager->formattedQueueList();
        echo "</table>";
    }
    // _queue_
    if ($displayRunningTorrents) {
        $output = "";
        echo "\n";
        echo "<table width=\"760\" border=1 bordercolor=\"" . $cfg["table_admin_border"] . "\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"" . $cfg["table_data_bg"] . "\">";
        echo "<tr><td colspan=6 bgcolor=\"" . $cfg["table_header_bg"] . "\" background=\"themes/" . $cfg["theme"] . "/images/bar.gif\">";
        echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>";
        echo "<td><img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\"> Running Items </font></td>";
        echo "</tr></table>";
        echo "</td></tr>";
        echo "<tr>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"15%\"><div align=center class=\"title\">" . _USER . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _FILE . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"1%\"><div align=center class=\"title\">" . str_replace(" ", "<br>", _FORCESTOP) . "</div></td>";
        echo "</tr>";
        echo "\n";
        // get running tornado torrents and List them out.
        $runningTorrents = getRunningTorrents("tornado");
        foreach ($runningTorrents as $key => $value) {
            $rt = RunningTorrent::getRunningTorrentInstance($value, $cfg, "tornado");
            $output .= $rt->BuildAdminOutput();
        }
        // get running transmission torrents and List them out.
        $runningTorrents = getRunningTorrents("transmission");
        foreach ($runningTorrents as $key => $value) {
            $rt = RunningTorrent::getRunningTorrentInstance($value, $cfg, "transmission");
            $output .= $rt->BuildAdminOutput();
        }
        if (strlen($output) == 0) {
            $output = "<tr><td colspan=3><div class=\"tiny\" align=center>No Running Torrents</div></td></tr>";
        }
        echo $output;
        echo "</table>";
    }
    DisplayFoot(true, true);
}
Example #3
0
 // create AliasFile object
 $af = new AliasFile($cfg["torrent_file_path"] . $alias_file, $the_user);
 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($cfg["constants"]["kill_torrent"], $kill_torrent);
 $return = getRequestVar('return');
 if (!empty($return)) {
     sleep(3);
     passthru("kill " . $kill);
Example #4
0
function queueSettings()
{
    global $cfg;
    include_once "AliasFile.php";
    include_once "RunningTorrent.php";
    DisplayHead("Administration - Search Settings");
    // Admin Menu
    displayMenu();
    // Queue Manager Section
    echo "<div align=\"center\">";
    echo "<a name=\"QManager\" id=\"QManager\"></a>";
    echo "<table width=\"100%\" border=1 bordercolor=\"" . $cfg["table_admin_border"] . "\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"" . $cfg["table_data_bg"] . "\">";
    echo "<tr><td bgcolor=\"" . $cfg["table_header_bg"] . "\" background=\"themes/" . $cfg["theme"] . "/images/bar.gif\">";
    echo "<font class=\"title\">";
    if (checkQManager() > 0) {
        echo "&nbsp;&nbsp;<img src=\"images/green.gif\" align=\"absmiddle\" align=\"absmiddle\"> Queue Manager Running [PID=" . getQManagerPID() . " with " . strval(getRunningTorrentCount()) . " torrent(s)]";
    } else {
        echo "&nbsp;&nbsp;<img src=\"images/black.gif\" align=\"absmiddle\"> Queue Manager Off";
    }
    echo "</font>";
    echo "</td></tr><tr><td align=\"center\">";
    ?>
    <script language="JavaScript">
    function validateSettings()
    {
        var rtnValue = true;
        var msg = "";
        if (isNumber(document.theForm.maxServerThreads.value) == false)
        {
            msg = msg + "* Max Server Threads must be a valid number.\n";
            document.theForm.maxServerThreads.focus();
        }
        if (isNumber(document.theForm.maxUserThreads.value) == false)
        {
            msg = msg + "* Max User Threads must be a valid number.\n";
            document.theForm.maxUserThreads.focus();
        }
        if (isNumber(document.theForm.sleepInterval.value) == false)
        {
            msg = msg + "* Sleep Interval must be a valid number.\n";
            document.theForm.sleepInterval.focus();
        }

        if (msg != "")
        {
            rtnValue = false;
            alert("Please check the following:\n\n" + msg);
        }

        return rtnValue;
    }

    function isNumber(sText)
    {
        var ValidChars = "0123456789.";
        var IsNumber = true;
        var Char;

        for (i = 0; i < sText.length && IsNumber == true; i++)
        {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1)
            {
                IsNumber = false;
            }
        }

        return IsNumber;
    }
    </script>

    <div align="center">

         <table cellpadding="5" cellspacing="0" border="0" width="100%">
            <form name="theForm" action="admin.php?op=updateConfigSettings" method="post" onsubmit="return validateSettings()">
            <input type="Hidden" name="continue" value="queueSettings">
            <tr>
                <td align="left" width="350" valign="top"><strong>Enable Queue Manager</strong><br>
                Enable the Queue Manager to allow users to queue torrents:
                </td>
                <td>
                    <select name="AllowQueing">
                            <option value="1">true</option>
                            <option value="0" <?php 
    if (!$cfg["AllowQueing"]) {
        echo "selected";
    }
    ?>
>false</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="left" width="350" valign="top"><strong>tfQManager Path</strong><br>
                Specify the path to the tfQManager python script:
                </td>
                <td valign="top">
                    <input name="tfQManager" type="Text" maxlength="254" value="<?php 
    echo $cfg["tfQManager"];
    ?>
" size="55"><?php 
    echo validateFile($cfg["tfQManager"]);
    ?>
                </td>
            </tr>
<!-- Only used for develpment or if you really really know what you are doing
            <tr>
                <td align="left" width="350" valign="top"><strong>Enable Queue Manager Debugging</strong><br>
                Creates huge log files only for debugging.  DO NOT KEEP THIS MODE ON:
                </td>
                <td>
                    <select name="debugTorrents">
                        <option value="1">true</option>
                        <option value="0" <?php 
    if (array_key_exists("debugTorrents", $cfg)) {
        if (!$cfg["debugTorrents"]) {
            echo "selected";
        }
    } else {
        insertSetting("debugTorrents", false);
        echo "selected";
    }
    ?>
>false</option>
                    </select>
                </td>
            </tr>
-->
            <tr>
                <td align="left" width="350" valign="top"><strong>Max Server Threads</strong><br>
                Specify the maximum number of torrents the server will allow to run at
                one time (admins may override this):
                </td>
                <td valign="top">
                    <input name="maxServerThreads" type="Text" maxlength="3" value="<?php 
    echo $cfg["maxServerThreads"];
    ?>
" size="3">
                </td>
            </tr>
            <tr>
                <td align="left" width="350" valign="top"><strong>Max User Threads</strong><br>
                Specify the maximum number of torrents a single user may run at
                one time:
                </td>
                <td valign="top">
                    <input name="maxUserThreads" type="Text" maxlength="3" value="<?php 
    echo $cfg["maxUserThreads"];
    ?>
" size="3">
                </td>
            </tr>
            <tr>
                <td align="left" width="350" valign="top"><strong>Polling Interval</strong><br>
                Number of seconds the Queue Manager will sleep before checking for new torrents to run:
                </td>
                <td valign="top">
                    <input name="sleepInterval" type="Text" maxlength="3" value="<?php 
    echo $cfg["sleepInterval"];
    ?>
" size="3">
                </td>
            </tr>
            <tr>
                <td align="center" colspan="2">
                <br><br>
                <input type="Submit" value="Update Settings">
                </td>
            </tr>
            </form>
        </table>


        </div>
    <br>
<?php 
    echo "</td></tr>";
    echo "</table></div>";
    $displayQueue = True;
    $displayRunningTorrents = True;
    // Its a timming thing.
    if ($displayRunningTorrents) {
        // get Running Torrents.
        $runningTorrents = getRunningTorrents();
    }
    if ($displayQueue) {
        $output = "";
        echo "\n";
        echo "<table width=\"760\" border=1 bordercolor=\"" . $cfg["table_admin_border"] . "\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"" . $cfg["table_data_bg"] . "\">";
        echo "<tr><td colspan=6 bgcolor=\"" . $cfg["table_header_bg"] . "\" background=\"themes/" . $cfg["theme"] . "/images/bar.gif\">";
        echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>";
        echo "<td><img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\"> Queued Items </font></td>";
        echo "</tr></table>";
        echo "</td></tr>";
        echo "<tr>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"15%\"><div align=center class=\"title\">" . _USER . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _FILE . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"15%\"><div align=center class=\"title\">" . _TIMESTAMP . "</div></td>";
        echo "</tr>";
        echo "\n";
        $qDir = $cfg["torrent_file_path"] . "queue/";
        if (is_dir($cfg["torrent_file_path"])) {
            if (is_writable($cfg["torrent_file_path"]) && !is_dir($qDir)) {
                @mkdir($qDir, 0777);
            }
            // get Queued Items and List them out.
            $output .= "";
            $handle = @opendir($qDir);
            while ($filename = readdir($handle)) {
                if ($filename != "tfQManager.log") {
                    if ($filename != "." && $filename != ".." && strpos($filename, ".pid") == 0) {
                        $output .= "<tr>";
                        $output .= "<td><div class=\"tiny\">";
                        $af = new AliasFile(str_replace("queue/", "", $qDir) . str_replace(".Qinfo", "", $filename), "");
                        $output .= $af->torrentowner;
                        $output .= "</div></td>";
                        $output .= "<td><div align=center><div class=\"tiny\" align=\"left\">" . str_replace(array(".Qinfo", ".stat"), "", $filename) . "</div></td>";
                        $output .= "<td><div class=\"tiny\" align=\"center\">" . date(_DATETIMEFORMAT, strval(filectime($qDir . $filename))) . "</div></td>";
                        $output .= "</tr>";
                        $output .= "\n";
                    }
                }
            }
            closedir($handle);
        }
        if (strlen($output) == 0) {
            $output = "<tr><td colspan=3><div class=\"tiny\" align=center>Queue is Empty</div></td></tr>";
        }
        echo $output;
        echo "</table>";
    }
    if ($displayRunningTorrents) {
        $output = "";
        echo "\n";
        echo "<table width=\"760\" border=1 bordercolor=\"" . $cfg["table_admin_border"] . "\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"" . $cfg["table_data_bg"] . "\">";
        echo "<tr><td colspan=6 bgcolor=\"" . $cfg["table_header_bg"] . "\" background=\"themes/" . $cfg["theme"] . "/images/bar.gif\">";
        echo "<table width=\"100%\" cellpadding=0 cellspacing=0 border=0><tr>";
        echo "<td><img src=\"images/properties.png\" width=18 height=13 border=0>&nbsp;&nbsp;<font class=\"title\"> Running Items </font></td>";
        echo "</tr></table>";
        echo "</td></tr>";
        echo "<tr>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"15%\"><div align=center class=\"title\">" . _USER . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _FILE . "</div></td>";
        echo "<td bgcolor=\"" . $cfg["table_header_bg"] . "\" width=\"1%\"><div align=center class=\"title\">" . str_replace(" ", "<br>", _FORCESTOP) . "</div></td>";
        echo "</tr>";
        echo "\n";
        // get running torrents and List them out.
        $runningTorrents = getRunningTorrents();
        if (is_array($runningTorrents)) {
            foreach ($runningTorrents as $key => $value) {
                $rt = new RunningTorrent($value);
                $output .= $rt->BuildAdminOutput();
            }
        }
        if (strlen($output) == 0) {
            $output = "<tr><td colspan=3><div class=\"tiny\" align=center>No Running Torrents</div></td></tr>";
        }
        echo $output;
        echo "</table>";
    }
    DisplayFoot();
}
 /**
  * stops a bittorrent-client
  *
  * @param $torrent name of the torrent
  * @param $aliasFile alias-file of the torrent
  * @param $torrentPid
  * @param $return return-param
  */
 function doStopTorrentClient($torrent, $aliasFile, $torrentPid = "", $return = "")
 {
     // set some vars
     $this->torrent = $torrent;
     $this->alias = $aliasFile;
     // set pidfile
     if ($this->pidFile == "") {
         // pid-file not set in subclass. use a default
         $this->pidFile = $this->cfg["torrent_file_path"] . $this->alias . ".pid";
     }
     // We are going to write a '0' on the front of the stat file so that
     // the BT client will no to stop -- this will report stats when it dies
     $this->owner = getOwner($this->torrent);
     include_once "AliasFile.php";
     // read the alias file + create AliasFile object
     $this->af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $this->alias, $this->owner, $this->cfg, $this->handlerName);
     if ($this->af->percent_done < 100) {
         // The torrent is being stopped but is not completed dowloading
         $this->af->percent_done = ($this->af->percent_done + 100) * -1;
         $this->af->running = "0";
         $this->af->time_left = "Torrent Stopped";
     } else {
         // Torrent was seeding and is now being stopped
         $this->af->percent_done = 100;
         $this->af->running = "0";
         $this->af->time_left = "Download Succeeded!";
     }
     include_once "RunningTorrent.php";
     // see if the torrent process is hung.
     if (!is_file($this->pidFile)) {
         $runningTorrents = getRunningTorrents();
         foreach ($runningTorrents as $key => $value) {
             $rt = RunningTorrent::getRunningTorrentInstance($value, $this->cfg, $this->handlerName);
             if ($rt->statFile == $this->alias) {
                 AuditAction($this->cfg["constants"]["error"], "Posible Hung Process " . $rt->processId);
                 //    $callResult = exec("kill ".$rt->processId);
             }
         }
     }
     // Write out the new Stat File
     $this->af->WriteFile();
     // flag the torrent as stopped (in db)
     // blame me for this dirty shit, i am lazy. of course this should be
     // hooked into the place where client really dies.
     stopTorrentSettings($this->torrent);
     //
     if (!empty($return)) {
         AuditAction($this->cfg["constants"]["kill_torrent"], $this->torrent);
         sleep(3);
         // set pid
         if (isset($torrentPid) && $torrentPid != "") {
             // test for valid pid-var
             if (preg_match('/^[0-9]+$/', $torrentPid)) {
                 $this->pid = $torrentPid;
             } else {
                 AuditAction($this->cfg["constants"]["error"], "Invalid kill-param : " . $this->cfg["user"] . " tried to kill " . $torrentPid);
                 global $argv;
                 if (isset($argv)) {
                     die("Invalid kill-param : " . $torrentPid);
                 } else {
                     showErrorPage("Invalid kill-param : <br>" . htmlentities($torrentPid, ENT_QUOTES));
                 }
             }
         } else {
             $data = "";
             if ($fileHandle = @fopen($this->pidFile, 'r')) {
                 while (!@feof($fileHandle)) {
                     $data .= @fgets($fileHandle, 64);
                 }
                 @fclose($fileHandle);
             }
             $this->pid = trim($data);
         }
         // kill it
         $this->callResult = exec("kill " . escapeshellarg($this->pid));
         // try to remove the pid file
         @unlink($this->pidFile);
     }
 }
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 = "&nbsp;";
        $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;
        }
    }
}