/**
  * startQueueManager
  */
 function startQueueManager()
 {
     // is there a stat and torrent dir?
     if (is_dir($this->cfg["torrent_file_path"])) {
         if (is_writable($this->cfg["torrent_file_path"]) && !is_dir($this->cfg["torrent_file_path"] . "queue/")) {
             //Then create it
             mkdir($this->cfg["torrent_file_path"] . "queue/", 0777);
         }
     }
     if ($this->checkQManager() == 0) {
         $cmd1 = "cd " . $this->cfg["path"] . "TFQUSERNAME";
         if (!array_key_exists("pythonCmd", $this->cfg)) {
             insertSetting("pythonCmd", "/usr/bin/python");
         }
         if (!array_key_exists("debugTorrents", $this->cfg)) {
             insertSetting("debugTorrents", false);
         }
         if (!$this->cfg["debugTorrents"]) {
             $pyCmd = $this->cfg["pythonCmd"] . " -OO";
         } else {
             $pyCmd = $this->cfg["pythonCmd"];
         }
         $btphp = "'" . $cmd1 . "; HOME=" . $this->cfg["path"] . "; export HOME; nohup " . $pyCmd . " " . $this->cfg["btclient_tornado_bin"] . " '";
         $startCommand = $pyCmd . " " . $this->cfg["tfQManager"] . " " . $this->cfg["torrent_file_path"] . "queue/ " . escapeshellarg($this->limitGlobal) . " " . $this->limitUser . " " . $this->cfg["sleepInterval"] . " " . $btphp . " > /dev/null &";
         $result = exec($startCommand);
         sleep(2);
         // wait for it to start prior to getting pid
         $this->pid = $this->getQManagerPID();
         AuditAction($this->cfg["constants"]["QManager"], "Started PID:" . $this->pid);
         // set status
         $this->status = 2;
         return true;
     } else {
         AuditAction($this->cfg["constants"]["QManager"], "QManager Already Started  PID:" . $this->getQManagerPID());
         return true;
     }
 }
/**
 * save Settings
 *
 * @param $dbTable
 * @param $settings
 */
function saveSettings($dbTable, $settings)
{
    global $cfg, $db;
    foreach ($settings as $key => $value) {
        if (array_key_exists($key, $cfg)) {
            if (is_array($cfg[$key]) || is_array($value)) {
                if (serialize($cfg[$key]) != serialize($value)) {
                    updateSetting($dbTable, $key, $value);
                }
            } elseif ($cfg[$key] != $value) {
                updateSetting($dbTable, $key, $value);
            }
        } else {
            insertSetting($dbTable, $key, $value);
        }
    }
}
예제 #3
0
         $priolist = implode(',', array_slice($priolist, 1, $priolist[0]));
         $command .= " --priority " . escapeshellarg($priolist);
     }
     if ($cfg["cmd_options"]) {
         $command .= " " . escapeshellarg($cfg["cmd_options"]);
     }
     $command .= " > /dev/null &";
     if ($cfg["AllowQueing"] && $queue == "1") {
         //  This file is being queued.
     } else {
         // This flie is being started manually.
         if (!array_key_exists("pythonCmd", $cfg)) {
             insertSetting("pythonCmd", "/usr/bin/python");
         }
         if (!array_key_exists("debugTorrents", $cfg)) {
             insertSetting("debugTorrents", "0");
         }
         if (!$cfg["debugTorrents"]) {
             $pyCmd = escapeshellarg($cfg["pythonCmd"]) . " -OO";
         } else {
             $pyCmd = escapeshellarg($cfg["pythonCmd"]);
         }
         $command = "cd " . $cfg["path"] . $owner . "; HOME=" . $cfg["path"] . "; export HOME; nohup " . $pyCmd . " " . escapeshellarg($cfg["btphpbin"]) . " " . $command;
     }
 } else {
     // Must be using the Original BitTorrent Client
     // This is now being required to allow Queing functionality
     //$command = "cd " . $cfg["path"] . $owner . "; nohup " . $cfg["btphpbin"] . " ".$runtime." ".$sharekill." ".$cfg["torrent_file_path"].$alias.".stat ".$owner." --responsefile \"".$cfg["torrent_file_path"].$torrent."\" --display_interval 5 --max_download_rate ". $drate ." --max_upload_rate ".$rate." --max_uploads ".$maxuploads." --minport ".$minport." --maxport ".$maxport." --rerequest_interval ".$rerequest." ".$cfg["cmd_options"]." > /dev/null &";
     $messages .= "<b>Error</b> BitTornado is only supported Client at this time.<br>";
 }
 // write the session to close so older version of PHP will not hang
 /**
  * starts a bittorrent-client
  * @param $torrent name of the torrent
  * @param $interactive (1|0) : is this a interactive startup with dialog ?
  */
 function startTorrentClient($torrent, $interactive)
 {
     // do tornado special-pre-start-checks
     // check to see if the path to the python script is valid
     if (!is_file($this->cfg["btclient_tornado_bin"])) {
         AuditAction($this->cfg["constants"]["error"], "Error  Path for " . $this->cfg["btclient_tornado_bin"] . " is not valid");
         if (IsAdmin()) {
             $this->status = -1;
             header("location: admin.php?op=configSettings");
             return;
         } else {
             $this->status = -1;
             $this->messages .= "<b>Error</b> TorrentFlux settings are not correct (path to python script is not valid) -- please contact an admin.<br>";
             return;
         }
     }
     // prepare starting of client
     parent::prepareStartTorrentClient($torrent, $interactive);
     // prepare succeeded ?
     if ($this->status != 2) {
         $this->status = -1;
         $this->messages .= "<b>Error</b> parent::prepareStartTorrentClient(" . $torrent . "," . $interactive . ") failed<br>";
         return;
     }
     // build the command-string
     $skipHashCheck = "";
     if (!empty($this->skip_hash_check) && getTorrentDataSize($torrent) > 0) {
         $skipHashCheck = " --check_hashes 0";
     }
     $this->command = $this->runtime;
     $this->command .= " " . $this->sharekill_param;
     $this->command .= " " . escapeshellarg($this->cfg["torrent_file_path"] . $this->alias . ".stat");
     $this->command .= " " . $this->owner;
     $this->command .= " --responsefile " . escapeshellarg($this->cfg["torrent_file_path"] . $this->torrent);
     $this->command .= " --display_interval 5";
     $this->command .= " --max_download_rate " . $this->drate;
     $this->command .= " --max_upload_rate " . $this->rate;
     $this->command .= " --max_uploads " . $this->maxuploads;
     $this->command .= " --minport " . $this->port;
     $this->command .= " --maxport " . $this->maxport;
     $this->command .= " --rerequest_interval " . $this->rerequest;
     $this->command .= " --super_seeder " . $this->superseeder;
     $this->command .= " --max_connections " . $this->maxcons;
     $this->command .= $skipHashCheck;
     if (file_exists($this->cfg["torrent_file_path"] . $this->alias . ".prio")) {
         $priolist = explode(',', file_get_contents($this->cfg["torrent_file_path"] . $this->alias . ".prio"));
         $priolist = implode(',', array_slice($priolist, 1, $priolist[0]));
         $this->command .= " --priority " . $priolist;
     }
     if (strlen($this->cfg["btclient_tornado_options"]) > 0) {
         $this->command .= " " . $this->cfg["btclient_tornado_options"];
     }
     $this->command .= " > /dev/null &";
     if ($this->cfg["AllowQueing"] && $this->queue == "1") {
         //  This file is queued.
     } else {
         // This file is started manually.
         if (!array_key_exists("pythonCmd", $this->cfg)) {
             insertSetting("pythonCmd", "/usr/bin/python");
         }
         if (!array_key_exists("debugTorrents", $this->cfg)) {
             insertSetting("debugTorrents", "0");
         }
         $pyCmd = "";
         if (!$this->cfg["debugTorrents"]) {
             $pyCmd = $this->cfg["pythonCmd"] . " -OO";
         } else {
             $pyCmd = $this->cfg["pythonCmd"];
         }
         $this->command = "cd " . escapeshellarg($this->savepath) . "; HOME=" . escapeshellarg($this->cfg["path"]) . "; export HOME;" . $this->umask . " nohup " . $this->nice . $pyCmd . " " . escapeshellarg($this->cfg["btclient_tornado_bin"]) . " " . $this->command;
     }
     // start the client
     parent::doStartTorrentClient();
 }
function saveSettings($settings)
{
    global $cfg, $db;
    if ($settings == null) {
        return;
    }
    foreach ($settings as $key => $value) {
        if (array_key_exists($key, $cfg)) {
            if (is_array($cfg[$key]) || is_array($value)) {
                if (serialize($cfg[$key]) != serialize($value)) {
                    updateSetting($key, $value);
                }
            } elseif ($cfg[$key] != $value) {
                updateSetting($key, $value);
            } else {
                // Nothing has Changed..
            }
        } else {
            insertSetting($key, $value);
        }
    }
}
예제 #6
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();
}
예제 #7
0
function startQManager($maxServerThreads = 5, $maxUserThreads = 2, $sleepInterval = 10)
{
    global $cfg;
    // is there a stat and torrent dir?
    if (is_dir($cfg["torrent_file_path"])) {
        if (is_writable($cfg["torrent_file_path"]) && !is_dir($cfg["torrent_file_path"] . "queue/")) {
            //Then create it
            mkdir($cfg["torrent_file_path"] . "queue/", 0777);
        }
    }
    if (checkQManager() == 0) {
        $cmd1 = "cd " . $cfg["path"] . "TFQUSERNAME";
        if (!array_key_exists("pythonCmd", $cfg)) {
            insertSetting("pythonCmd", "/usr/bin/python");
        }
        if (!array_key_exists("debugTorrents", $cfg)) {
            insertSetting("debugTorrents", false);
        }
        if (!$cfg["debugTorrents"]) {
            $pyCmd = $cfg["pythonCmd"] . " -OO";
        } else {
            $pyCmd = $cfg["pythonCmd"];
        }
        $btphp = "'" . $cmd1 . "; HOME=" . $cfg["path"] . "; export HOME; nohup " . $pyCmd . " " . $cfg["btphpbin"] . " '";
        $command = $pyCmd . " " . $cfg["tfQManager"] . " " . $cfg["torrent_file_path"] . "queue/ " . escapeshellarg($maxServerThreads) . " " . escapeshellarg($maxUserThreads) . " " . escapeshellarg($sleepInterval) . " " . $btphp . " > /dev/null &";
        //$command = $pyCmd . " " . $cfg["tfQManager"] . " ".$cfg["torrent_file_path"]."queue/ ".$maxServerThreads." ".$maxUserThreads." ".$sleepInterval." ".$btphp." > /dev/null2>&1 & &";
        $result = exec($command);
        sleep(2);
        // wait for it to start prior to getting pid
        AuditAction($cfg["constants"]["QManager"], "Started PID:" . getQManagerPID());
    } else {
        AuditAction($cfg["constants"]["QManager"], "QManager Already Started  PID:" . getQManagerPID());
    }
}