/**
 * waits until transfer is up/down
 *
 * @param $transfer name of the transfer
 * @param $state : true = start, false = stop
 * @param $maxWait in seconds
 * @return boolean
 */
function waitForTransfer($transfer, $state, $maxWait = 15)
{
    $maxLoops = $maxWait * 5;
    $loopCtr = 0;
    for (;;) {
        @clearstatcache();
        if (isTransferRunning($transfer) === $state) {
            return true;
        } else {
            $loopCtr++;
            if ($loopCtr > $maxLoops) {
                return false;
            } else {
                usleep(200000);
            }
            // wait for 0.2 seconds
        }
    }
    return true;
}
/**
 * multi
 *
 * @param $action
 */
function dispatcher_multi($action)
{
    global $cfg;
    // is enabled ?
    if ($cfg["enable_multiops"] != 1) {
        AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use multi-op " . $action);
        @error("multiops are disabled", "", "");
    }
    // messages-ary
    $dispatcherMessages = array();
    // loop
    if (empty($_POST['transfer'])) {
        return;
    }
    foreach ($_POST['transfer'] as $key => $element) {
        // url-decode
        $transfer = urldecode($element);
        // is valid transfer ? + check permissions
        $invalid = true;
        if (tfb_isValidTransfer($transfer) === true) {
            if (substr($transfer, -8) == ".torrent") {
                // this is a torrent-client
                $invalid = false;
            } else {
                if (substr($transfer, -5) == ".wget") {
                    // this is wget.
                    $invalid = false;
                    // is enabled ?
                    if ($cfg["enable_wget"] == 0) {
                        $invalid = true;
                        AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use wget");
                        array_push($dispatcherMessages, "wget is disabled : " . $transfer);
                    } else {
                        if ($cfg["enable_wget"] == 1) {
                            if (!$cfg['isAdmin']) {
                                $invalid = true;
                                AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use wget");
                                array_push($dispatcherMessages, "wget is disabled for users : " . $transfer);
                            }
                        }
                    }
                } else {
                    if (substr($transfer, -4) == ".nzb") {
                        // This is nzbperl.
                        $invalid = false;
                        if ($cfg["enable_nzbperl"] == 0) {
                            $invalid = true;
                            AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use nzbperl");
                            array_push($dispatcherMessages, "nzbperl is disabled : " . $transfer);
                        } else {
                            if ($cfg["enable_nzbperl"] == 1) {
                                if (!$cfg['isAdmin']) {
                                    $invalid = true;
                                    AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use nzbperl");
                                    array_push($dispatcherMessages, "nzbperl is disabled for users : " . $transfer);
                                }
                            }
                        }
                    }
                }
            }
        }
        if ($invalid) {
            AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $cfg["user"] . " tried to " . $action . " " . $transfer);
            array_push($dispatcherMessages, "Invalid Transfer : " . $transfer);
            continue;
        }
        // client
        $client = getTransferClient($transfer);
        // is transfer running ?
        $tRunningFlag = isTransferRunning($transfer);
        // action switch
        switch ($action) {
            case "transferStart":
                /* transferStart */
                if (!$tRunningFlag) {
                    $ch = ClientHandler::getInstance($client);
                    $ch->start($transfer, false, FluxdQmgr::isRunning());
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                }
                break;
            case "transferStop":
                /* transferStop */
                if ($tRunningFlag) {
                    $ch = ClientHandler::getInstance($client);
                    $ch->stop($transfer);
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                }
                break;
            case "transferEnQueue":
                /* transferEnQueue */
                if (!$tRunningFlag) {
                    // enqueue it
                    $ch = ClientHandler::getInstance($client);
                    $ch->start($transfer, false, true);
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                }
                break;
            case "transferDeQueue":
                /* transferDeQueue */
                if (!$tRunningFlag) {
                    // dequeue it
                    FluxdQmgr::dequeueTransfer($transfer, $cfg['user']);
                }
                break;
            case "transferResetTotals":
                /* transferResetTotals */
                $msgs = resetTransferTotals($transfer, false);
                if (count($msgs) > 0) {
                    $dispatcherMessages = array_merge($dispatcherMessages, $msgs);
                }
                break;
            default:
                if ($tRunningFlag) {
                    // stop first
                    $ch = ClientHandler::getInstance($client);
                    $ch->stop($transfer);
                    if (count($ch->messages) > 0) {
                        $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                    }
                    // is transfer running ?
                    $tRunningFlag = isTransferRunning($transfer);
                }
                // if it was running... hope the thing is down...
                // only continue if it is
                if (!$tRunningFlag) {
                    switch ($action) {
                        case "transferWipe":
                            /* transferWipe */
                            $msgsDelete = deleteTransferData($transfer);
                            if (count($msgsDelete) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $msgsDelete);
                            }
                            $msgsReset = resetTransferTotals($transfer, true);
                            if (count($msgsReset) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $msgsReset);
                            }
                            break;
                        case "transferData":
                            /* transferData */
                            $msgsDelete = deleteTransferData($transfer);
                            if (count($msgsDelete) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $msgsDelete);
                            }
                        case "transfer":
                            /* transfer */
                            $ch = ClientHandler::getInstance($client);
                            $ch->delete($transfer);
                            if (count($ch->messages) > 0) {
                                $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages);
                            }
                    }
                }
        }
        // end switch
    }
    // end loop
    // error if messages
    if (count($dispatcherMessages) > 0) {
        @error("There were Problems", "", "", $dispatcherMessages);
    }
}
 /**
  * _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");
 }
Пример #4
0
 /**
  * set transfer setting
  *
  * @param $transfer
  * @param $key
  * @param $val
  * @param $options
  * @return mixed
  */
 function _tset($transfer, $key, $val, $options)
 {
     global $cfg;
     // check transfer
     if (!transferExists($transfer)) {
         $this->_outputError("transfer does not exist.\n");
         return false;
     }
     // check params
     $settingsKeys = array('uprate' => 'NUMBER', 'downrate' => 'NUMBER', 'completion' => 'BOOL', 'sharekill' => 'NUMBER');
     if (!array_key_exists($key, $settingsKeys)) {
         $this->_outputError("invalid settings-key: " . $key . "\n");
         return false;
     }
     if (strlen($val) < 1) {
         $this->_outputError("value for " . $key . " invalid.\n");
         return false;
     }
     switch ($settingsKeys[$key]) {
         case 'NUMBER':
             if (!preg_match('/^[0-9\\-]+$/D', $val)) {
                 $this->_outputError("value for " . $key . " must be a number: " . $val . "\n");
                 return false;
             }
             break;
         case 'BOOL':
             $val = strtolower($val);
             if ($val != 'true' && $val != 'false') {
                 $this->_outputError("value for " . $key . " must be true or false: " . $val . "\n");
                 return false;
             }
             break;
     }
     // set user
     $cfg["user"] = getOwner($transfer);
     // output
     $this->_outputMessage("Setting " . $key . " to " . $val . " for " . $transfer . " for user " . $cfg["user"] . "...\n");
     // init ch-instance
     $ch = ClientHandler::getInstance(getTransferClient($transfer));
     // load settings, default if settings could not be loaded (fresh transfer)
     if ($ch->settingsLoad($transfer) !== true) {
         $ch->settingsDefault();
     }
     // autosend
     $send = strpos($options, 's') !== false && isTransferRunning($transfer);
     // set setting
     switch ($key) {
         case 'uprate':
             if ($ch->rate != $val) {
                 $ch->setRateUpload($transfer, $val, $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
         case 'downrate':
             if ($ch->drate != $val) {
                 $ch->setRateDownload($transfer, $val, $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
         case 'completion':
             if (strtolower($ch->runtime) != $val) {
                 $ch->setRuntime($transfer, $val == 'true' ? 'True' : 'False', $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
         case 'sharekill':
             if ($ch->sharekill != $val) {
                 $ch->setSharekill($transfer, $val, $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
     }
     // save
     $ch->settingsSave();
     // output + return
     if ($send) {
         $this->_outputMessage("settings saved + changes sent to client.\n");
     } else {
         $this->_outputMessage("settings saved.\n");
     }
     return true;
 }
/**
 * transfers
 *
 * @param $action
 */
function sa_transfers($action = "")
{
    global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain;
    if ($action == "") {
        return;
    }
    buildPage("t");
    switch ($action) {
        case "0":
            // Transfers-main
            $htmlTitle = "Transfer Bulk Operations";
            $htmlMain .= '<br><div align="left">';
            $htmlMain .= '<p>Select action to perform on all items in the transfer list:</p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?t=1"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Stop All Transfers" border="0"> Stop All Transfers</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?t=2"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Start All Transfers" border="0"> Start All Transfers</a>';
            $htmlMain .= '<p>';
            $htmlMain .= '<a href="' . _FILE_THIS . '?t=3"><img src="themes/' . $cfg["theme"] . '/images/arrow.gif" width="9" height="9" title="Resume All Transfers" border="0"> Resume All Transfers</a>';
            $htmlMain .= '<br><br><strong>Note:</strong><br>\'Start All Transfers\' will start all transfers in the transfer list, regardless of whether they have been started previously or not.<br><br>\'Resume All Transfers\' will only start those transfers that have previously been started and are currently in the \'stopped\' state';
            $htmlMain .= '</div><br><br>';
            break;
        case "1":
            // Transfers-Stop
            $htmlTitle = "Transfers - Stop";
            $htmlMain .= '<br><strong>Transfers Stopped:</strong><br>';
            $htmlMain .= '<pre>';
            $transferList = getTransferArray();
            foreach ($transferList as $transfer) {
                if (isTransferRunning($transfer)) {
                    $ch = ClientHandler::getInstance(getTransferClient($transfer));
                    $ch->stop($transfer);
                    $htmlMain .= ' - ' . $transfer . "";
                    $htmlMain .= "\n";
                }
            }
            $htmlMain .= '</pre>';
            $htmlMain .= '<hr><br>';
            break;
        case "2":
            // Transfers-Start
            $htmlTitle = "Transfers - Start";
            $htmlMain .= '<br><strong>Transfers Started:</strong><br>';
            $htmlMain .= '<pre>';
            $transferList = getTransferArray();
            foreach ($transferList as $transfer) {
                if (!isTransferRunning($transfer)) {
                    $ch = ClientHandler::getInstance(getTransferClient($transfer));
                    $ch->start($transfer, false, false);
                    $htmlMain .= ' - ' . $transfer . "";
                    $htmlMain .= "\n";
                }
            }
            $htmlMain .= '</pre>';
            $htmlMain .= '<hr><br>';
            break;
        case "3":
            // Transfers-Resume
            $htmlTitle = "Transfers - Resume";
            $htmlMain .= '<br><strong>Transfers Resumed:</strong><br>';
            $htmlMain .= '<pre>';
            $transferList = getTransferArray();
            $sf = new StatFile("");
            foreach ($transferList as $transfer) {
                $sf->init($transfer);
                if (trim($sf->running) == 0 && !isTransferRunning($transfer)) {
                    $ch = ClientHandler::getInstance(getTransferClient($transfer));
                    $ch->start($transfer, false, false);
                    $htmlMain .= ' - ' . $transfer . "";
                    $htmlMain .= "\n";
                }
            }
            $htmlMain .= '</pre>';
            $htmlMain .= '<hr><br>';
            break;
    }
    $htmlMain .= '<br><strong>Transfers:</strong><br>';
    $htmlMain .= '<pre>';
    $transferList = getTransferArray();
    foreach ($transferList as $transfer) {
        $htmlMain .= ' - ' . $transfer . "";
        if (isTransferRunning($transfer)) {
            $htmlMain .= " (running)";
        }
        $htmlMain .= "\n";
    }
    $htmlMain .= '</pre>';
    printPage();
    exit;
}
 /**
  * instance_dequeue
  *
  * @param $transfer
  * @param $user
  */
 function instance_dequeueTransfer($transfer, $user)
 {
     global $cfg;
     if ($this->modstate == FLUXDMOD_STATE_RUNNING) {
         if (isTransferRunning($transfer)) {
             // transfer has been started...log
             AuditAction($cfg["constants"]["unqueued_transfer"], $transfer . "has been already started.");
         } else {
             // send command
             $result = Fluxd::sendServiceCommand($this->moduleName, 'dequeue;' . $transfer . ';' . $user, 1);
             // flag the transfer as stopped (in db)
             stopTransferSettings($transfer);
             // update the stat file.
             $this->_updateStatFile($transfer);
             // log
             AuditAction($cfg["constants"]["fluxd"], $result);
             // log
             AuditAction($cfg["constants"]["unqueued_transfer"], $transfer);
             // just 2 sec... dont stress fluxd
             sleep(2);
         }
     }
 }
// init transfer
transfer_init();
// request-vars
$saveop = tfb_getRequestVar('save');
$client = tfb_getRequestVar('client');
$isSave = $saveop == 1 ? true : false;
// init ch-instance
$ch = $client == "" ? ClientHandler::getInstance(getTransferClient($transfer)) : ClientHandler::getInstance($client);
// customize-vars
transfer_setCustomizeVars();
// load settings, default if settings could not be loaded (fresh transfer)
if ($ch->settingsLoad($transfer) !== true) {
    $ch->settingsDefault();
}
// set running-field
$ch->running = isTransferRunning($transfer) ? 1 : 0;
// save/display
if ($isSave) {
    /* save */
    // set save-var
    $tmpl->setvar('isSave', 1);
    // send to client
    $doSend = isset($_REQUEST['sendbox']) && $ch->running == 1 ? true : false;
    // settings-keys
    $settingsKeys = array('savepath', 'max_upload_rate', 'max_download_rate', 'max_uploads', 'superseeder', 'die_when_done', 'sharekill', 'minport', 'maxport', 'maxcons', 'rerequest');
    // settings-labels
    $settingsLabels = array('savepath' => 'Savepath', 'max_upload_rate' => 'Max Upload Rate', 'max_download_rate' => 'Max Download Rate', 'max_uploads' => 'Max Upload Connections', 'superseeder' => 'Superseeder', 'die_when_done' => 'Torrent Completion Activity', 'sharekill' => 'Percentage When Seeding should Stop', 'minport' => 'Min-Port', 'maxport' => 'Max-Port', 'maxcons' => 'Max Cons', 'rerequest' => 'Rerequest Interval');
    // current settings
    $settingsCurrent = array();
    $settingsCurrent['savepath'] = $ch->savepath;
    $settingsCurrent['max_upload_rate'] = $ch->rate;
if (!isset($cfg['user']) || isset($_REQUEST['cfg'])) {
    @ob_end_clean();
    @header("location: ../../index.php");
    exit;
}
/******************************************************************************/
// transfer functions
require_once 'inc/functions/functions.transfer.php';
// init template-instance
tmplInitializeInstance($cfg["theme"], "page.transferFiles.tmpl");
// init transfer
transfer_init();
// init ch-instance
$ch = ClientHandler::getInstance(getTransferClient($transfer));
// set file vars
transfer_setFileVars();
// file-prio
if ($cfg["enable_file_priority"] == 1 && $cfg["supportMap"][$ch->client]['file_priority'] == 1 && !isTransferRunning($transfer)) {
    require_once "inc/functions/functions.fileprio.php";
    $tmpl->setvar('filePrio', getFilePrioForm($transfer, true));
    $tmpl->setvar('file_priority_enabled', 1);
} else {
    $tmpl->setvar('file_priority_enabled', 0);
}
// title + foot
tmplSetFoot(false);
tmplSetTitleBar($transferLabel . " - Files", false);
// iid
tmplSetIidVars();
// parse template
$tmpl->pparse();
Пример #9
0
 /**
  * _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");
 }