/** * get Vuze RPC torrent id (use it temporary, dont store it) * * @param $transfer * @return int */ function getVuzeTransferRpcId($transfer) { global $cfg; require_once 'inc/classes/VuzeRPC.php'; $rpc = VuzeRPC::getInstance(); $hash = getTransferHash($transfer); $torrents = $rpc->torrent_get_hashids(); $tid = false; if (array_key_exists(strtoupper($hash), $torrents)) { $tid = $torrents[strtoupper($hash)]; } return $tid; }
/** * gets scrape-info of a torrent as string * * @param $transfer name of the torrent * @return string with torrent-scrape-info */ function getTorrentScrapeInfo($transfer) { global $cfg; $hasClient = false; // transmissioncli if (!$cfg["transmission_rpc_enable"]) { $hasClient = true; $retVal = ""; $retVal = @shell_exec("HOME=" . tfb_shellencode($cfg["path"]) . "; export HOME; " . $cfg["btclient_transmission_bin"] . " -s " . tfb_shellencode($cfg["transfer_file_path"] . $transfer)); if (isset($retVal) && $retVal != "" && !preg_match('/.*failed.*/i', $retVal)) { return trim($retVal); } } else { require_once 'inc/functions/functions.transfer.php'; require_once 'inc/functions/functions.rpc.transmission.php'; if (isHash($transfer)) { $hash = $transfer; } else { $hash = getTransferHash($transfer); } $a = getTransmissionTransfer($hash, array("trackerStats")); if (!empty($a['trackerStats'])) { $stats = $a['trackerStats'][0]; return $stats['seederCount'] . ' seeder(s), ' . $stats['leecherCount'] . ' leecher(s).' . "\n"; } } // ttools.pl if (is_executable($cfg["perlCmd"])) { $hasClient = true; $retVal = ""; $retVal = @shell_exec($cfg["perlCmd"] . ' -I ' . tfb_shellencode($cfg["docroot"] . 'bin/ttools') . ' ' . tfb_shellencode($cfg["docroot"] . 'bin/ttools/ttools.pl') . ' -s ' . tfb_shellencode($cfg["transfer_file_path"] . $transfer)); if (isset($retVal) && $retVal != "" && !preg_match('/.*failed.*/i', $retVal)) { return trim($retVal); } } // failed return $hasClient ? "Scrape failed" : "No Scrape-Client"; }
/** * gets current status of one Transfer (realtime) * for transferStat popup * * @return array (stat) or Error String */ function monitorTransfer($transfer, $format = "rpc") { //by default, monitoring not available. // set vars $this->_setVarsForTransfer($transfer); if (isHash($transfer)) { $hash = $transfer; } else { $hash = getTransferHash($transfer); } if (empty($hash)) { return "Hash for {$transfer} was not found"; } //original rpc format, you can add fields here $fields = array('id', 'name', 'status', 'hashString', 'totalSize', 'downloadedEver', 'uploadedEver', 'percentDone', 'uploadRatio', 'peersConnected', 'peersGettingFromUs', 'peersSendingToUs', 'rateDownload', 'rateUpload', 'downloadLimit', 'uploadLimit', 'downloadLimited', 'uploadLimited', 'seedRatioLimit', 'seedRatioMode', 'downloadDir', 'eta', 'error', 'errorString'); $stat_rpc = getTransmissionTransfer($hash, $fields); $rpc = Transmission::getInstance(); if (is_array($stat_rpc)) { if ($format == "rpc") { return $stat_rpc; } else { return $rpc->rpc_to_tf($stat_rpc); } } return $rpc->lastError; }
@header("location: ../../index.php"); exit; } /******************************************************************************/ // transfer functions require_once 'inc/functions/functions.transfer.php'; // init template-instance tmplInitializeInstance($cfg["theme"], "page.transferHosts.tmpl"); // init transfer transfer_init(); $isTransmissionTransfer = false; if ($cfg["transmission_rpc_enable"] > 0) { if (isHash($transfer)) { $hash = $transfer; } else { $hash = getTransferHash($transfer); } require_once 'inc/functions/functions.rpc.transmission.php'; $isTransmissionTransfer = isTransmissionTransfer($hash); if (!$isTransmissionTransfer && $cfg["transmission_rpc_enable"] == 1) { $isTransmissionTransfer = getTransferClient($transfer) == 'transmissionrpc'; } } $list_host = array(); if ($isTransmissionTransfer) { $options = array('peers'); $transfer = getTransmissionTransfer($hash, $options); $isRunning = true; //TODO make this actually determine if the torrent is running if ($isRunning) { foreach ($transfer['peers'] as $peer) {
/** * _maintenanceDatabase */ function _maintenanceDatabase() { global $cfg, $db; // output $this->_outputMessage("database-maintenance...\n"); /* tf_transfers */ $this->_countProblems = 0; $this->_countFixed = 0; // output $this->_outputMessage("table-maintenance : tf_transfers\n"); // running-flag $sql = "SELECT transfer FROM tf_transfers WHERE running = '1'"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { while (list($tname) = $recordset->FetchRow()) { if (!isTransferRunning($tname)) { $this->_countProblems++; // t is not running, reset running-flag $this->_outputMessage("reset of running-flag for transfer which is not running : " . $tname . "\n"); $sql = "UPDATE tf_transfers SET running = '0' WHERE transfer = " . $db->qstr($tname); $db->Execute($sql); $this->_countFixed++; // output $this->_outputMessage("done.\n"); } } } // empty hash $sql = "SELECT transfer FROM tf_transfers WHERE hash = ''"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { $this->_countProblems += $rc; while (list($tname) = $recordset->FetchRow()) { // t has no hash, update $this->_outputMessage("updating transfer which has empty hash : " . $tname . "\n"); // get hash $thash = getTransferHash($tname); // update if (!empty($thash)) { $sql = "UPDATE tf_transfers SET hash = " . $db->qstr($thash) . " WHERE transfer = " . $db->qstr($tname); $db->Execute($sql); $this->_countFixed++; // output $this->_outputMessage("done.\n"); } } } // empty datapath $sql = "SELECT transfer FROM tf_transfers WHERE datapath = ''"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { $this->_countProblems += $rc; while (list($tname) = $recordset->FetchRow()) { // t has no datapath, update $this->_outputMessage("updating transfer which has empty datapath : " . $tname . "\n"); // get datapath $tDatapath = getTransferDatapath($tname); // update if ($tDatapath != "") { $sql = "UPDATE tf_transfers SET datapath = " . $db->qstr($tDatapath) . " WHERE transfer = " . $db->qstr($tname); $db->Execute($sql); $this->_countFixed++; // output $this->_outputMessage("done.\n"); } else { // output $this->_outputMessage("cannot get datapath for " . $tname . ".\n"); } } } // output + log if ($this->_countProblems == 0) { // output $this->_outputMessage("no problems found.\n"); } else { // DEBUG : log $msg = "found and fixed problems in tf_transfers : " . $this->_countFixed . "/" . $this->_countProblems; if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], "database-maintenance : table-maintenance : " . $msg); } // output $this->_outputMessage($msg . "\n"); } /* tf_transfer_totals */ $this->_countProblems = 0; $this->_countFixed = 0; // output $this->_outputMessage("table-maintenance : tf_transfer_totals\n"); $this->_countProblems = $db->GetOne("SELECT COUNT(*) FROM tf_transfer_totals WHERE tid = ''"); if ($this->_countProblems !== false && $this->_countProblems > 0) { // output $this->_outputMessage("found " . $this->_countProblems . " invalid entries, deleting...\n"); $sql = "DELETE FROM tf_transfer_totals WHERE tid = ''"; $result = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $this->_countFixed = $db->Affected_Rows(); // output $this->_outputMessage("done.\n"); $rCount = $this->_countFixed !== false ? $this->_countFixed : $this->_countProblems; // DEBUG : log $msg = "found and removed invalid totals-entries from tf_transfer_totals : " . $rCount . "/" . $this->_countProblems; if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], "database-maintenance : table-maintenance : " . $msg); } // output $this->_outputMessage($msg . "\n"); } else { // output $this->_outputMessage("no problems found.\n"); } // prune db $this->_maintenanceDatabasePrune(); /* done */ $this->_outputMessage("database-maintenance done.\n"); }
/** * maintenance * * @param $action */ function sa_maintenance($action = "") { global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain; if ($action == "") { return; } buildPage("m"); switch ($action) { case "0": // Maintenance-main $htmlTitle = "Maintenance"; $htmlMain .= '<p>Select the maintenance task you wish to perform below:<br><br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=1"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Main" border="0"> Main</a> - clean up stale files; resume stalled transfers'; $htmlMain .= '<p>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=2"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Kill" border="0"> Kill</a> - kill rebel processes'; $htmlMain .= '<p>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=3"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Clean" border="0"> Clean</a> - clean up stale cache/pid/template files'; $htmlMain .= '<p>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=4"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Repair" border="0"> Repair</a> - check for erroneous stat/pid files, fix bad db entries, prune old db items'; $htmlMain .= '<p>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=5"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Reset" border="0"> Reset</a> - reset transfer totals, xfer stats and personal settings'; $htmlMain .= '<p>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=6"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Lock" border="0"> Lock</a> - lock access to the frontend'; $htmlMain .= '<br><br>'; break; case "1": // Maintenance: Main $htmlTitle = "Maintenance - Main"; $htmlMain .= '<p>'; $htmlMain .= '<strong>Standard</strong><br>'; $htmlMain .= 'Standard Maintenance Run - same as on index-page and automatic called on every login<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=11"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Standard Maintenance-Run" border="0"> Standard Maintenance Run</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Extended</strong><br>'; $htmlMain .= 'Extended Maintenance Run - like a standard run but will also restart all dead transfers.<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=12"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="vlc-kill" border="0"> Extended Maintenance Run</a>'; $htmlMain .= '<br><br>'; break; case "11": // Maintenance: Main: Standard Maintenance-Run $htmlTitle = "Maintenance - Main - Standard Maintenance Run"; $htmlMain .= '<br>'; $htmlMain .= 'Standard Maintenance Run: '; require_once "inc/classes/MaintenanceAndRepair.php"; MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_STD); $htmlMain .= ' <font color="green">done</font>'; $htmlMain .= '<br><br>'; break; case "12": // Maintenance: Main $htmlTitle = "Maintenance - Main - Extended Maintenance Run"; $htmlMain .= '<br>'; $htmlMain .= 'Extended Maintenance Run: '; require_once "inc/classes/MaintenanceAndRepair.php"; MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_EXT); $htmlMain .= ' <font color="green">done</font>'; $htmlMain .= '<br><br>'; break; case "2": // Maintenance-Kill $htmlTitle = "Maintenance - Kill"; $htmlMain .= '<br>'; $htmlMain .= '<font color="red"><strong>DON\'T</strong> do this or you will screw up things for sure!</font><br><br>'; $htmlMain .= 'This is only meant as emergency \'last resort\' if things have already gone terribly wrong already.<br>Please use this only if you know what you are doing.<br><br><hr><strong>ALL the selected process types will be killed, not just those related to torrentflux-b4rt!!!</strong><hr><br>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>PHP</strong><br>'; $htmlMain .= 'Kill all PHP processes:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=21"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="php-kill" border="0"> PHP Kill</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Python</strong><br>'; $htmlMain .= 'Kill all python processes:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=22"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="python-kill" border="0"> Python Kill</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Perl</strong><br>'; $htmlMain .= 'Kill all perl processes:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=23"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="perl-kill" border="0"> Perl Kill</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Transmissioncli</strong><br>'; $htmlMain .= 'Kill all transmissioncli processes:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=24"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="transmissioncli-kill" border="0"> Transmissioncli Kill</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Wget</strong><br>'; $htmlMain .= 'Kill all wget processes:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=25"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="wget-kill" border="0"> Wget Kill</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>VLC</strong><br>'; $htmlMain .= 'Kill all VLC processes:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=26"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="vlc-kill" border="0"> VLC Kill</a>'; $htmlMain .= '<br><br>'; break; case "21": // Maintenance-Kill: php $htmlTitle = "Maintenance - Kill - PHP"; $htmlMain .= '<br>'; $htmlMain .= 'Kill all PHP processes: <font color="green">done</font>'; $htmlMain .= '<br><br>'; $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " php | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; $callResult = trim(shell_exec("killall -9 php 2> /dev/null")); if (isset($callResult) && $callResult != "") { $htmlMain .= '<br>'; $htmlMain .= 'Call Result: <br>'; $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>'; $htmlMain .= '<br>'; } sleep(2); // just 2 sec $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " php | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; break; case "22": // Maintenance-Kill: python $htmlTitle = "Maintenance - Kill - Python"; $htmlMain .= '<br>'; $htmlMain .= 'Kill all python processes: <font color="green">done</font>'; $htmlMain .= '<br><br>'; $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " python | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; $callResult = trim(shell_exec("killall -9 python 2> /dev/null")); if (isset($callResult) && $callResult != "") { $htmlMain .= '<br>'; $htmlMain .= 'Call Result: <br>'; $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>'; $htmlMain .= '<br>'; } sleep(2); // just 2 sec $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " python | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; break; case "23": // Maintenance-Kill: perl $htmlTitle = "Maintenance - Kill - Perl"; $htmlMain .= '<br>'; $htmlMain .= 'Kill all perl processes: <font color="green">done</font>'; $htmlMain .= '<br><br>'; $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " perl | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; $callResult = trim(shell_exec("killall -9 perl 2> /dev/null")); if (isset($callResult) && $callResult != "") { $htmlMain .= '<br>'; $htmlMain .= 'Call Result: <br>'; $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>'; $htmlMain .= '<br>'; } sleep(2); // just 2 sec $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " perl | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; break; case "24": // Maintenance-Kill: transmissioncli $htmlTitle = "Maintenance - Kill - Transmissioncli"; $htmlMain .= '<br>'; $htmlMain .= 'Kill all transmissioncli processes: <font color="green">done</font>'; $htmlMain .= '<br><br>'; $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " transmissioncli | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; $callResult = trim(shell_exec("killall -9 transmissioncli 2> /dev/null")); if (isset($callResult) && $callResult != "") { $htmlMain .= '<br>'; $htmlMain .= 'Call Result: <br>'; $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>'; $htmlMain .= '<br>'; } sleep(2); // just 2 sec $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " transmissioncli | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; break; case "25": // Maintenance-Kill: wget $htmlTitle = "Maintenance - Kill - Wget"; $htmlMain .= '<br>'; $htmlMain .= 'Kill all wget processes: <font color="green">done</font>'; $htmlMain .= '<br><br>'; $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " wget | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; $callResult = trim(shell_exec("killall -9 wget 2> /dev/null")); if (isset($callResult) && $callResult != "") { $htmlMain .= '<br>'; $htmlMain .= 'Call Result: <br>'; $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>'; $htmlMain .= '<br>'; } sleep(2); // just 2 sec $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " wget | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; break; case "26": // Maintenance-Kill: vlc $htmlTitle = "Maintenance - Kill - VLC"; $htmlMain .= '<br>'; $htmlMain .= 'Kill all VLC processes: <font color="green">done</font>'; $htmlMain .= '<br><br>'; $htmlMain .= '<strong>Process list (filtered) before call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " vlc | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; $callResult = trim(shell_exec("killall -9 vlc 2> /dev/null")); if (isset($callResult) && $callResult != "") { $htmlMain .= '<br>'; $htmlMain .= 'Call Result: <br>'; $htmlMain .= '<pre>' . tfb_htmlencode($callResult) . '</pre>'; $htmlMain .= '<br>'; } sleep(2); // just 2 sec $htmlMain .= '<strong>Process list (filtered) after call:</strong><br>'; $htmlMain .= '<pre>'; $htmlMain .= tfb_htmlencode(trim(shell_exec("ps auxww | " . $cfg['bin_grep'] . " vlc | " . $cfg['bin_grep'] . " -v grep"))); $htmlMain .= '</pre>'; $htmlMain .= '<br>'; break; case "3": // Maintenance-Clean $htmlTitle = "Maintenance - Clean"; $htmlMain .= '<br>Select the action to perform below:<br><hr><strong>Please stop any running transfers BEFORE cleaning the PID or cache files!!!</strong><hr><br>'; $htmlMain .= '<strong>Process ID (PID) File Leftovers</strong><br>'; $htmlMain .= 'Delete stale PID files from deleted transfers:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=31"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="pid-file-clean" border="0"> PID File Clean</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>BitTornado</strong><br>'; $htmlMain .= 'Delete the BitTornado cache:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=32"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="tornado-clean" border="0"> BitTornado Clean</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Transmission</strong><br>'; $htmlMain .= 'Delete Transmission cache:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=33"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="transmission-clean" border="0"> Transmission Clean</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>BitTorrent Mainline</strong><br>'; $htmlMain .= 'Delete BitTorrent Mainline cache:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=34"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="mainline-clean" border="0"> BitTorrent Mainline Clean</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Template Cache</strong><br>'; $htmlMain .= 'Delete the Torrentflux-b4rt template cache:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=35"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="template-cache-clean" border="0"> Template Cache Clean</a>'; $htmlMain .= '<br><br>'; break; case "31": // Maintenance-Clean: pid-file-clean $htmlTitle = "Maintenance - Clean - PID Files"; $htmlMain .= '<br><strong>Cleaning stale PID files:</strong><br>'; $result = ""; $transferList = getTransferArrayFromDB(); if ($dirHandle = @opendir($cfg["transfer_file_path"])) { while (false !== ($file = readdir($dirHandle))) { if (strlen($file) > 3 && substr($file, -4, 4) == ".pid") { $tname = substr($file, 0, -4); if (!in_array($tname, $transferList)) { // transfer not in db. delete pid-file. $result .= tfb_htmlencode($file) . "\n"; @unlink($cfg["transfer_file_path"] . $file); } } } closedir($dirHandle); } if (strlen($result) > 0) { $htmlMain .= '<br>Deleted stale PID files: <br><pre>' . $result . '</pre><br>'; } else { $htmlMain .= '<br>No stale PID files found.<br><br>'; } break; case "32": // Maintenance-Clean: tornado-clean $htmlTitle = "Maintenance - Clean - BitTornado"; $htmlMain .= '<br><strong>Cleaning BitTornado cache:</strong><br>'; $result = ""; $result .= cleanDir($cfg["path"] . '.BitTornado/datacache'); $result .= cleanDir($cfg["path"] . '.BitTornado/torrentcache'); $result .= cleanDir($cfg["path"] . '.BitTornado/piececache'); $result .= cleanDir($cfg["path"] . '.BitTornado/icons'); if (strlen($result) > 0) { $htmlMain .= '<br>Deleted cache: <br><pre>' . $result . '</pre><br>'; } else { $htmlMain .= '<br>Nothing found.<br><br>'; } break; case "33": // Maintenance-Clean: transmission-clean $htmlTitle = "Maintenance - Clean - Transmission"; $htmlMain .= '<br><strong>Cleaning Transmission cache:</strong><br>'; $result = ""; $hashes = array(); $transferList = getTransferArray(); foreach ($transferList as $transfer) { array_push($hashes, getTransferHash($transfer)); } if ($dirHandle = @opendir($cfg["path"] . ".transmission/cache/")) { while (false !== ($file = readdir($dirHandle))) { if ($file[0] == "r") { $thash = substr($file, -40); if (!in_array($thash, $hashes)) { // torrent not in db. delete cache-file. $result .= tfb_htmlencode($file) . "\n"; @unlink($cfg["path"] . ".transmission/cache/resume." . $thash); } } } closedir($dirHandle); } if (strlen($result) > 0) { $htmlMain .= '<br>Deleted cache: <br><pre>' . $result . '</pre><br>'; } else { $htmlMain .= '<br>Nothing found.<br><br>'; } break; case "34": // Maintenance-Clean: mainline-clean $htmlTitle = "Maintenance - Clean - BitTorrent Mainline"; $htmlMain .= '<br><strong>Cleaning BitTorrent Mainline cache:</strong><br>'; $result = ""; $result .= cleanDir($cfg["path"] . '.bittorrent/console/resume'); $result .= cleanDir($cfg["path"] . '.bittorrent/console/metainfo'); $result .= cleanDir($cfg["path"] . '.bittorrent/console/torrents'); $result .= cleanDir($cfg["path"] . '.bittorrent/mutex'); if (strlen($result) > 0) { $htmlMain .= '<br>Deleted cache: <br><pre>' . $result . '</pre><br>'; } else { $htmlMain .= '<br>Nothing found.<br><br>'; } break; case "35": // Maintenance-Clean:template-cache-clean $htmlTitle = "Maintenance - Clean - Template Cache"; $htmlMain .= '<br><strong>Cleaning Torrentflux-b4rt Template Cache:</strong><br>'; $result = cleanDir($cfg["path"] . '.templateCache'); if (strlen($result) > 0) { $htmlMain .= '<br>Deleted compiled templates: <br><pre>' . $result . '</pre><br>'; } else { $htmlMain .= '<br>No compiled templates found.<br><br>'; } break; case "4": // Maintenance: Repair $htmlTitle = "Maintenance - Repair"; $htmlMain .= '<br>'; $htmlMain .= '<hr><font color="red"><strong>DON\'T</strong> do this if your system is running as it should. You WILL break something.</font><hr>'; $htmlMain .= '<br>The \'Repair\' action will attempt to repair any problems such as out of synch stat files, erroneous PID files, bad hash entries in the database as well as pruning the database.<br><br>Only use this after a server-reboot, if transfers were killed or if there are other problems with the webapp that can\'t be resolved another way.<br>'; $htmlMain .= '<br><a href="' . _FILE_THIS . '?m=41"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Repair" border="0"> Repair</a>'; $htmlMain .= '<br><br>'; break; case "41": // Maintenance: Repair $htmlTitle = "Maintenance - Repair"; $htmlMain .= '<br>'; $htmlMain .= 'Repairing Torrentflux-b4rt:'; require_once "inc/classes/MaintenanceAndRepair.php"; MaintenanceAndRepair::repair(); $htmlMain .= ' <font color="green">done</font>'; $htmlMain .= '<br><br>'; break; case "5": // Maintenance: Reset $htmlTitle = "Maintenance - Reset"; $htmlMain .= '<br>Select the item you wish to reset below:<br><br>'; $htmlMain .= '<strong>Transfer Totals</strong><br>'; $htmlMain .= 'Reset the transfer totals (totals uploaded/downloaded in the transfer list):<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=51"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="transfer-totals" border="0"> Reset Transfer Totals</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Xfer Stats</strong><br>'; $htmlMain .= 'Reset the transfer statistics:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=52"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="xfer-stats" border="0"> Reset Xfer Stats</a>'; $htmlMain .= '<p>'; $htmlMain .= '<strong>Personal Settings</strong><br>'; $htmlMain .= 'Reset the personal settings of all users:<br>'; $htmlMain .= '<a href="' . _FILE_THIS . '?m=53"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="personal-settings" border="0"> Reset Personal Settings</a>'; $htmlMain .= '<br><br>'; break; case "51": // Maintenance: Reset - transfer-totals $htmlTitle = "Maintenance - Reset - Transfer Totals"; $htmlMain .= '<br>'; $htmlMain .= 'Resetting transfer totals:<br>'; $result = resetAllTransferTotals(); $htmlMain .= $result === true ? ' <font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result; $htmlMain .= '<br><br>'; break; case "52": // Maintenance: Reset - xfer $htmlTitle = "Maintenance - Reset - Transfer Statistics"; $htmlMain .= '<br>'; $htmlMain .= 'Resetting xfer stats:<br>'; $result = Xfer::resetStats(); $htmlMain .= $result === true ? ' <font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result; $htmlMain .= '<br><br>'; break; case "53": // Maintenance: Reset - personal-settings $htmlTitle = "Maintenance - Reset - Personal Settings"; $htmlMain .= '<br>'; $htmlMain .= 'Resetting personal settings:<br>'; $result = deleteAllUserSettings(); $htmlMain .= $result === true ? ' <font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result; $htmlMain .= '<br><br>'; break; case "6": // Maintenance: Lock $htmlTitle = "Maintenance - Lock Torrentflux-b4rt Frontend"; $htmlMain .= '<br>Lock/unlock access to the Torrentflux-b4rt frontend. Only the superadmin can access the locked frontend.<br><br><hr>'; switch ($cfg['webapp_locked']) { case 0: $htmlMain .= '<strong><font color="green">Frontend currently unlocked.</font></strong>'; break; case 1: $htmlMain .= '<strong><font color="red">Frontend currently locked.</font></strong>'; break; } $htmlMain .= '<hr><p>'; $htmlMain .= '<br><a href="' . _FILE_THIS . '?m=61"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Repair" border="0"> '; $htmlMain .= $cfg['webapp_locked'] == 1 ? 'Unlock' : 'Lock'; $htmlMain .= ' Frontend</a>'; $htmlMain .= '<br><br>'; break; case "61": // Maintenance: lock/unlock $htmlTitle = "Maintenance - Lock"; $htmlMain .= '<br>'; switch ($cfg['webapp_locked']) { case 0: $result = setWebappLock(1); $htmlMain .= "Locking frontend:<br>"; $htmlMain .= $result === true ? '<font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result; break; case 1: $result = setWebappLock(0); $htmlMain .= "Unlocking frontend:<br>"; $htmlMain .= $result === true ? '<font color="green">Done</font>' : '<br><font color="red">Error:</font><br>' . $result; break; } $htmlMain .= '<br><br>'; break; } printPage(); exit; }
$settingsAry['type'] = "wget"; $settingsAry['client'] = "wget"; } else { if (substr($transfer, -4) == ".nzb") { // this is nzbperl. $settingsAry['type'] = "nzb"; $settingsAry['client'] = "nzbperl"; } else { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer); @error("Invalid Transfer", "", "", array($transfer)); } } } } if (empty($settingsAry['hash'])) { $settingsAry['hash'] = getTransferHash($transfer); $transfers['settings'][$transfer] = $settingsAry; } if (empty($settingsAry['datapath'])) { $settingsAry["datapath"] = getTransferSavepath($transfer); $transfers['settings'][$transfer] = $settingsAry; } if (empty($settingsAry['savepath'])) { $settingsAry["savepath"] = getTransferSavepath($transfer); $transfers['settings'][$transfer] = $settingsAry; } if ($settingsAry["client"] == "") { // Fix FluAzu progression 100% (client to check, not set to "azureus", solved by mysql column enum to varchar ?) if (!$sf->seedlimit) { $sf->seedlimit = $settingsAry["sharekill"]; }
/** * gets current transfer-vals of a transfer * * @param $transfer * @return array with downtotal and uptotal */ function getTransferCurrent($transfer) { global $db, $transfers; $retVal = array(); // transfer from stat-file $sf = new StatFile($transfer); $retVal["uptotal"] = $sf->uptotal; $retVal["downtotal"] = $sf->downtotal; // transfer from db $torrentId = getTransferHash($transfer); $sql = "SELECT uptotal,downtotal FROM tf_transfer_totals WHERE tid = " . $db->qstr($torrentId); $result = $db->Execute($sql); $row = $result->FetchRow(); if (!empty($row)) { $retVal["uptotal"] -= $row["uptotal"]; $retVal["downtotal"] -= $row["downtotal"]; } return $retVal; }
/** * change torrent Owner (download same torrent again from another user) * * @param $transfer, $user * @return none */ function changeOwner($transfer, $user) { global $cfg, $db, $transfers; $oldowner = getOwner($transfer); if ($oldowner != $user) { if (file_exists($cfg["transfer_file_path"] . $transfer . ".stat")) { $sf = new StatFile($transfer, $user); $sf->transferowner = $user; $sf->write(); } $hash = getTransferHash($transfer); $uid = (int) GetUID($user); $sql = "INSERT INTO tf_transfer_totals(tid, uid, uptotal,downtotal) values (" . $db->qstr($hash) . "," . $uid . "," . "0,0" . ")"; $result = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } resetOwner($transfer); } }
/** * gets current transfer-vals of a transfer * * @param $transfer * @return array with downtotal and uptotal */ function getTransferCurrent($transfer) { global $db, $transfers; $retVal = array(); // set vars $this->_setVarsForTransfer($transfer); // transfer from stat-file $sf = new StatFile($transfer); $retVal["uptotal"] = $sf->uptotal; $retVal["downtotal"] = $sf->downtotal; // transfer from db $torrentId = getTransferHash($transfer); $uid = (int) GetUID($this->owner); $sql = "SELECT uptotal,downtotal FROM tf_transfer_totals WHERE tid = " . $db->qstr($torrentId) . " AND uid IN(0, {$uid}) ORDER BY uid DESC"; $result = $db->Execute($sql); $row = $result->FetchRow(); if (!empty($row)) { $retVal["uptotal"] -= $row["uptotal"]; $retVal["downtotal"] -= $row["downtotal"]; } return $retVal; }
/** * sets fields from default-vals * * @param $transfer */ function settingsDefault($transfer = "") { global $cfg; // transfer vars if ($transfer != "") { $this->_setVarsForTransfer($transfer); } // common vars $this->hash = getTransferHash($this->transfer); $this->datapath = getTransferDatapath($this->transfer); $this->savepath = getTransferSavepath($this->transfer); $this->running = 0; $this->rate = 0; $this->drate = $cfg["nzbperl_rate"]; $this->maxuploads = 1; $this->superseeder = 0; $this->runtime = "True"; $this->sharekill = 0; $this->minport = 1; $this->maxport = 65535; $this->maxcons = $cfg["nzbperl_conn"]; $this->rerequest = 1; }
/** * pieTransferPeers */ function image_pieTransferPeers() { global $cfg; // transfer-id $transfer = tfb_getRequestVar('transfer'); if (empty($transfer)) { Image::paintNoOp(); } // validate transfer $validTransfer = false; if (isHash($transfer)) { $hash = $transfer; } else { $hash = getTransferHash($transfer); } if ($cfg["transmission_rpc_enable"]) { require_once 'inc/functions/functions.rpc.transmission.php'; $options = array('trackerStats', 'peers'); $transTransfer = getTransmissionTransfer($hash, $options); // false if not found; TODO check if transmission enabled if (is_array($transTransfer)) { $validTransfer = true; $client = "transmissionrpc"; } } if (!$validTransfer) { // If not found in transmission transfer if (tfb_isValidTransfer($transfer)) { // stat $sf = new StatFile($transfer); $seeds = trim($sf->seeds); $peers = trim($sf->peers); // client-switch + get peer-data $peerData = array(); $peerData['seeds'] = 0; $peerData['peers'] = 0; $peerData['seedsLabel'] = $seeds != "" ? $seeds : 0; $peerData['peersLabel'] = $peers != "" ? $peers : 0; $client = getTransferClient($transfer); $validTransfer = true; } } if (!$validTransfer) { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer); Image::paintNoOp(); } switch ($client) { case "tornado": if ($seeds != "") { if (strpos($seeds, "+") !== false) { $seeds = preg_replace('/(\\d+)\\+.*/i', '${1}', $seeds); } if (is_numeric($seeds)) { $peerData['seeds'] = $seeds; } $peerData['seedsLabel'] = $seeds; } if ($peers != "") { if (strpos($peers, "+") !== false) { $peers = preg_replace('/(\\d+)\\+.*/i', '${1}', $peers); } if (is_numeric($peers)) { $peerData['peers'] = $peers; } $peerData['peersLabel'] = $peers; } break; case "transmission": case "transmissionrpc": $peers = sizeof($transTransfer['peers']); $seeds = 0; foreach ($transTransfer['trackerStats'] as $tracker) { $seeds += $tracker['seederCount'] == -1 ? 0 : $tracker['seederCount']; } $peerData['seedsLabel'] = $seeds; $peerData['seeds'] = $seeds; $peerData['peersLabel'] = $peers; $peerData['peers'] = $peers; break; case "vuzerpc": if (empty($seeds) || empty($peers)) { $ch = ClientHandler::getInstance($client); $running = $ch->monitorRunningTransfers(); $hash = strtoupper(getTransferHash($transfer)); if (!empty($running[$hash])) { $t = $running[$hash]; $peerData['seeds'] = $t['seeds']; $peerData['seedsLabel'] = $t['seeds']; $peerData['peers'] = $t['peers']; $peerData['peersLabel'] = $t['peers']; } } break; case "azureus": if ($seeds != "") { if (strpos($seeds, "(") !== false) { $seeds = preg_replace('/.*(\\d+) .*/i', '${1}', $seeds); } if (is_numeric($seeds)) { $peerData['seeds'] = $seeds; } $peerData['seedsLabel'] = $seeds; } if ($peers != "") { if (strpos($peers, "(") !== false) { $peers = preg_replace('/.*(\\d+) .*/i', '${1}', $peers); } if (is_numeric($peers)) { $peerData['peers'] = $peers; } $peerData['peersLabel'] = $peers; } break; case "mainline": if ($seeds != "" && is_numeric($seeds)) { $peerData['seeds'] = $seeds; $peerData['seedsLabel'] = $seeds; } if ($peers != "" && is_numeric($peers)) { $peerData['peers'] = $peers; $peerData['peersLabel'] = $peers; } break; case "wget": case "nzbperl": $peerData['seeds'] = $seeds != "" ? $seeds : 0; $peerData['peers'] = $peers != "" ? $peers : 0; break; default: AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer); Image::paintNoOp(); } // draw image Image::paintPie3D(202, 160, 100, 50, 200, 100, 20, Image::stringToRGBColor($cfg["body_data_bg"]), array($peerData['seeds'] + 1.0E-5, $peerData['peers'] + 1.0E-5), image_getColors(), array('Seeds : ' . $peerData['seedsLabel'], 'Peers : ' . $peerData['peersLabel']), 58, 130, 2, 14); }
/** * updates totals of a transfer */ function _updateTotals() { global $db; $tid = getTransferHash($this->transfer); $transferTotals = $this->getTransferTotal($this->transfer); $sql = $db->GetOne("SELECT 1 FROM tf_transfer_totals WHERE tid = " . $db->qstr($tid)) ? "UPDATE tf_transfer_totals SET uptotal = " . $db->qstr($transferTotals["uptotal"]) . ", downtotal = " . $db->qstr($transferTotals["downtotal"]) . " WHERE tid = " . $db->qstr($tid) : "INSERT INTO tf_transfer_totals (tid,uptotal,downtotal) VALUES (" . $db->qstr($tid) . "," . $db->qstr($transferTotals["uptotal"]) . "," . $db->qstr($transferTotals["downtotal"]) . ")"; $db->Execute($sql); // set transfers-cache cacheTransfersSet(); }
/** * resets totals of a transfer * * @param $transfer name of the transfer * @param $delete boolean if to delete meta-file * @return array */ function resetTransferTotals($transfer, $delete = false) { global $cfg, $db, $transfers; $msgs = array(); $tid = getTransferHash($transfer); // delete meta-file if ($delete) { $ch = ClientHandler::getInstance(getTransferClient($transfer)); $ch->delete($transfer); if (count($ch->messages) > 0) { $msgs = array_merge($msgs, $ch->messages); } } else { // reset in stat-file $sf = new StatFile($transfer, getOwner($transfer)); $sf->uptotal = 0; $sf->downtotal = 0; $sf->write(); } // reset in db $sql = "DELETE FROM tf_transfer_totals WHERE tid = " . $db->qstr($tid); $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } // set transfers-cache cacheTransfersSet(); return $msgs; }
/** * _maintenanceDatabase */ function _maintenanceDatabase() { global $cfg, $db; // output $this->_outputMessage("database-maintenance...\n"); /* tf_transfers */ $this->_countProblems = 0; $this->_countFixed = 0; // output $this->_outputMessage("table-maintenance : tf_transfers\n"); // running-flag $sql = "SELECT transfer FROM tf_transfers WHERE running = '1'"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { while (list($tname) = $recordset->FetchRow()) { if (!isTransferRunning($tname)) { $this->_countProblems++; // t is not running, reset running-flag $this->_outputMessage("reset of running-flag for transfer which is not running : " . $tname . "\n"); $sql = "UPDATE tf_transfers SET running = '0' WHERE transfer = " . $db->qstr($tname); $db->Execute($sql); $this->_countFixed++; // output $this->_outputMessage("done.\n"); } } } // empty hash $sql = "SELECT transfer FROM tf_transfers WHERE hash = ''"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { $this->_countProblems += $rc; while (list($tname) = $recordset->FetchRow()) { // t has no hash, update $this->_outputMessage("updating transfer which has empty hash : " . $tname . "\n"); // get hash $thash = getTransferHash($tname); // update if (!empty($thash)) { $sql = "UPDATE tf_transfers SET hash = " . $db->qstr($thash) . " WHERE transfer = " . $db->qstr($tname); $db->Execute($sql); $this->_countFixed++; // output $this->_outputMessage("done.\n"); } } } // empty datapath $sql = "SELECT transfer FROM tf_transfers WHERE datapath = ''"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { $this->_countProblems += $rc; while (list($tname) = $recordset->FetchRow()) { // t has no datapath, update $this->_outputMessage("updating transfer which has empty datapath : " . $tname . "\n"); // get datapath $tDatapath = getTransferDatapath($tname); // update if ($tDatapath != "") { $sql = "UPDATE tf_transfers SET datapath = " . $db->qstr($tDatapath) . " WHERE transfer = " . $db->qstr($tname); $db->Execute($sql); $this->_countFixed++; // output $this->_outputMessage("done.\n"); } else { // output $this->_outputMessage("cannot get datapath for " . $tname . ".\n"); } } } // output + log if ($this->_countProblems == 0) { // output $this->_outputMessage("no problems found.\n"); } else { // DEBUG : log $msg = "found and fixed problems in tf_transfers : " . $this->_countFixed . "/" . $this->_countProblems; if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], "database-maintenance : table-maintenance : " . $msg); } // output $this->_outputMessage($msg . "\n"); } /* tf_transfer_totals */ $this->_countProblems = 0; $this->_countFixed = 0; // output $this->_outputMessage("table-maintenance : tf_transfer_totals\n"); $this->_countProblems = $db->GetOne("SELECT COUNT(*) FROM tf_transfer_totals WHERE tid = ''"); if ($this->_countProblems !== false && $this->_countProblems > 0) { // output $this->_outputMessage("found " . $this->_countProblems . " invalid entries, deleting...\n"); $sql = "DELETE FROM tf_transfer_totals WHERE tid = ''"; $result = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $this->_countFixed = $db->Affected_Rows(); // output $this->_outputMessage("done.\n"); $rCount = $this->_countFixed !== false ? $this->_countFixed : $this->_countProblems; // DEBUG : log $msg = "found and removed invalid totals-entries from tf_transfer_totals : " . $rCount . "/" . $this->_countProblems; if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], "database-maintenance : table-maintenance : " . $msg); } // output $this->_outputMessage($msg . "\n"); } else { // output $this->_outputMessage("no problems found.\n"); } // null uid $sql = "SELECT tid FROM tf_transfer_totals WHERE uid = 0"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { $this->_countProblems += $rc; while (list($tid) = $recordset->FetchRow()) { // get uid $tname = getTransferFromHash($tid); if (!empty($tname)) { $uid = (int) getTransferOwnerID($tname); } else { $uid = 0; } // t has no uid, update if ($uid > 0) { $this->_outputMessage("updating tf_transfer_totals which has empty uid : " . $tname . "\n"); $sql = "UPDATE tf_transfer_totals SET uid = {$uid} WHERE tid = " . $db->qstr($tid) . " AND uid=0"; $db->Execute($sql); //if duplicates, delete old uid=0 $sql = "DELETE FROM tf_transfer_totals WHERE tid = " . $db->qstr($tid) . " AND uid=0"; $db->Execute($sql); $this->_countFixed++; // output $this->_outputMessage("done.\n"); } elseif (!empty($tname)) { // output $this->_outputMessage("cannot get uid for " . $tname . ".\n"); } /* else { // old transfers (for global stats) $this->_outputMessage("cannot get uid for hash ".$tid.".\n"); } */ } } //xfer delete TB day values $sql = "SELECT user_id, date FROM tf_xfer WHERE download > '1000000000000' or upload > '1000000000000'"; $recordset = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rc = $recordset->RecordCount(); if ($rc > 0) { $this->_outputMessage("updating xfer which has TeraBytes day count\n"); $this->_countProblems += $rc; while (list($username, $date) = $recordset->FetchRow()) { //if duplicates, delete old uid=0 $sql = "DELETE FROM tf_xfer WHERE user_id = " . $db->qstr($username) . " AND date=" . $db->qstr($date); $db->Execute($sql); $this->_countFixed++; } $this->_outputMessage("done (" . $this->_countFixed . ").\n"); } // prune db $this->_maintenanceDatabasePrune(); /* done */ $this->_outputMessage("database-maintenance done.\n"); }