/**
 * gets size of data of a torrent
 *
 * @param $transfer name of the torrent
 * @return int with size of data of torrent.
 *		   -1 if error
 *		   4096 if dir (lol ~)
 */
function getTorrentDataSize($transfer)
{
    global $cfg;
    $datapath = getTransferDatapath($transfer);
    return $datapath != "" && $datapath != "." ? file_size(getTransferSavepath($transfer) . $datapath) : -1;
}
 /**
  * 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;
 }
 /**
  * _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");
 }
 /**
  * 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 = $cfg["max_upload_rate"];
     $this->drate = $cfg["max_download_rate"];
     $this->maxuploads = $cfg["max_uploads"];
     $this->superseeder = $cfg["superseeder"];
     $this->runtime = $cfg["die_when_done"];
     $this->sharekill = $cfg["sharekill"];
     $this->minport = $cfg["minport"];
     $this->maxport = $cfg["maxport"];
     $this->maxcons = $cfg["maxcons"];
     $this->rerequest = $cfg["rerequest_interval"];
 }
Пример #5
0
        $handle = opendir($cfg['transfer_file_path']);
        $tDirPs = array();
        while (false !== ($entry = readdir($handle))) {
            if (substr($entry, -3) == 'pid') {
                $tDirPs[] = $entry;
            }
        }
    }
} else {
    $dir = "";
}
foreach ($tDirPs as $value) {
    $value = $cfg['transfer_file_path'] . '/' . preg_replace('#(.*\\.torrent)\\.pid#', '\\1', $value);
    $stats = explode("\n", @file_get_contents($value . ".stat"));
    $value = preg_replace('#.*\\.transfers/([^ ]+\\.torrent)#', '\\1', $value);
    $path = getTransferDatapath($value);
    if ((int) @$stats[1] < 100) {
        $tRunning[$path] = $value;
    } else {
        $tSeeding[$path] = $value;
    }
}
unset($tDirPs);
// dir-name
$dirName = $cfg["path"] . $dir;
// dir-check
if (!@is_dir($dirName)) {
    // our dir is no dir but a file. use parent-directory.
    if (preg_match("/^(.+)\\/.+\$/", $dir, $matches) == 1) {
        header("Location: index.php?iid=dir&dir=" . UrlHTMLSlashesEncode($matches[1]));
    } else {
Пример #6
0
 /**
  * sets fields from default-vals
  *
  * @param $transfer
  */
 function settingsDefault($transfer = "")
 {
     global $cfg;
     // transfer vars
     if (empty($transfer) && !empty($this->transfer)) {
         $transfer = $this->transfer;
     }
     if (!empty($transfer)) {
         $this->_setVarsForTransfer($transfer);
         // common vars
         $this->hash = getTransferHash($this->transfer);
         $this->datapath = getTransferDatapath($this->transfer);
         $this->savepath = getTransferSavepath($this->transfer, "");
         // default profile
     } elseif ($cfg['debuglevel'] > 0) {
         AuditAction($cfg["constants"]["debug"], $this->client . " settingsDefault with empty transfer");
     }
     $this->running = 0;
     $this->rate = $cfg["max_upload_rate"];
     $this->drate = $cfg["max_download_rate"];
     $this->maxuploads = $cfg["max_uploads"];
     $this->superseeder = $cfg["superseeder"];
     $this->runtime = $cfg["die_when_done"];
     $this->sharekill = $cfg["sharekill"];
     $this->minport = $cfg["minport"];
     $this->maxport = $cfg["maxport"];
     $this->maxcons = $cfg["maxcons"];
     $this->rerequest = $cfg["rerequest_interval"];
     $this->skip_hash_check = true;
     $this->encryption = false;
     $this->file_priority = false;
 }
Пример #7
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");
 }
Пример #8
0
             $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));
             }
         }
     }
     $settingsAry['hash'] = "";
     $settingsAry["savepath"] = getTransferSavepath($transfer);
     $settingsAry['datapath'] = getTransferDatapath($transfer);
 }
 // cache running-flag in local var. we will access that often
 $transferRunning = $sf->running;
 // cache percent-done in local var. ...
 $percentDone = $sf->percent_done;
 // hide seeding - we do it asap to keep things as fast as possible
 if ($_SESSION['settings']['index_show_seeding'] == 0 && $percentDone >= 100 && $transferRunning == 1) {
     $cfg["total_upload"] = $cfg["total_upload"] + GetSpeedValue($sf->up_speed);
     continue;
 }
 // status-image
 $hd = getStatusImage($sf);
 // ---------------------------------------------------------------------
 //XFER: update1: add upload/download stats to the xfer array
 if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) {