function rpc_error($errorstr, $dummy = "", $dummy = "", $response = "") { global $cfg; AuditAction($cfg["constants"]["error"], "Transmission RPC : {$errorstr} - {$response}"); @error($errorstr . "\n" . $response, "", "", $response, $response); addGrowlMessage('transmission-rpc', $errorstr . $response); //dbError($errorstr); }
/** * starts a transfer * * @param $transfer name of the transfer * @param $interactive (boolean) : is this a interactive startup with dialog ? * @param $enqueue (boolean) : enqueue ? */ function start($transfer, $interactive = false, $enqueue = false) { global $cfg, $db; // set vars $this->_setVarsForTransfer($transfer); addGrowlMessage($this->client . "-start", $transfer); if (!Transmission::isRunning()) { $msg = "Transmission RPC not reacheable, cannot start transfer " . $transfer; $this->logMessage($this->client . "-start : " . $msg . "\n", true); AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); addGrowlMessage($this->client . "-start", $msg); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error: RPC down'; $sf->write(); // return return false; } // init properties $this->_init($interactive, $enqueue, true, false); /* if (!is_dir($cfg["path"].'.config/transmissionrpc/torrents')) { if (!is_dir($cfg["path"].'.config')) mkdir($cfg["path"].'.config',0775); if (!is_dir($cfg["path"].'.config/transmissionrpc')) mkdir($cfg["path"].'.config/transmissionrpc',0775); mkdir($cfg["path"].'.config/transmissionrpc/torrents',0775); } */ if (!is_dir($cfg['path'] . $cfg['user'])) { mkdir($cfg['path'] . $cfg['user'], 0777); } $this->command = ""; if (getOwner($transfer) != $cfg['user']) { //directory must be changed for different users ? changeOwner($transfer, $cfg['user']); $this->owner = $cfg['user']; // change savepath $this->savepath = $cfg["enable_home_dirs"] != 0 ? $cfg['path'] . $this->owner . "/" : $cfg['path'] . $cfg["path_incoming"] . "/"; $this->command = "re-downloading to " . $this->savepath; } else { $this->command = "downloading to " . $this->savepath; } // no client needed $this->state = CLIENTHANDLER_STATE_READY; // ClientHandler _start() $this->_start(); $hash = getTransferHash($transfer); if (empty($hash) || !isTransmissionTransfer($hash)) { $hash = addTransmissionTransfer($cfg['uid'], $cfg['transfer_file_path'] . $transfer, $cfg['path'] . $cfg['user']); if (is_array($hash) && $hash["result"] == "duplicate torrent") { $this->command = 'torrent-add skipped, already exists ' . $transfer; //log purpose $hash = ""; $sql = "SELECT hash FROM tf_transfers WHERE transfer = " . $db->qstr($transfer); $result = $db->Execute($sql); $row = $result->FetchRow(); if (!empty($row)) { $hash = $row['hash']; } } else { $this->command .= "\n" . 'torrent-add ' . $transfer . ' ' . $hash; //log purpose } } else { $this->command .= "\n" . 'torrent-start ' . $transfer . ' ' . $hash; //log purpose } if (!empty($hash)) { if ($this->sharekill > 100) { // bad sharekill, must be 2.5 for 250% $this->sharekill = round((double) $this->sharekill / 100.0, 2); } $params = array('downloadLimit' => intval($this->drate), 'downloadLimited' => intval($this->drate > 0), 'uploadLimit' => intval($this->rate), 'uploadLimited' => intval($this->rate > 0), 'seedRatioLimit' => (double) $this->sharekill, 'seedRatioMode' => intval($this->sharekill > 0.1)); $res = (int) startTransmissionTransfer($hash, $enqueue, $params); } if (!$res) { $this->command .= "\n" . $rpc->LastError; } $this->updateStatFiles($transfer); // log (for the torrent stats window) $this->logMessage($this->client . "-start : hash={$hash}\ndownload rate=" . $this->drate . ", res={$res}\n", true); }
/** * Audit Action * * @param $action * @param $file */ function AuditAction($action, $file = "") { global $cfg, $db; // add entry to the log $db->Execute("INSERT INTO tf_log (user_id,file,action,ip,ip_resolved,user_agent,time)" . " VALUES (" . $db->qstr($cfg["user"]) . "," . $db->qstr($file) . "," . $db->qstr($action != "" ? $action : "unset") . "," . $db->qstr($cfg['ip']) . "," . $db->qstr($cfg['ip_resolved']) . "," . $db->qstr($cfg['user_agent']) . "," . $db->qstr(time()) . ")"); if ($action != 'HIT') { addGrowlMessage('Audit', "{$action} {$file}"); } }
$displayname = $transfer; // may need a special config panel to clean names... $displayname = str_replace('.', "_", $displayname); $displayname = preg_replace('#([^_]+_(com|org|net|info)_)#i', "", $displayname); $displayname = preg_replace('#(_torrent)$#i', "", $displayname); $arToClean = array("http_", "_www_", "isohunt"); $displayname = str_ireplace($arToClean, "", $displayname); $displayname = str_replace('_', ".", $displayname); $displayname = str_replace('..', ".", $displayname); $displayname = trim($displayname, '.'); $displayname = strlen($displayname) > 53 ? substr($displayname, 0, 50) . "..." : $displayname; if ($displayname == 'download.php') { //must fix $transfer torrent filename before... //$name = getTransferFromHash($hash); $displayname = 'dup:' . $mtimecrc; addGrowlMessage('[dup]', 'This torrent has already been downloaded'); } // owner $transferowner = getOwner($transfer); $owner = IsOwner($cfg["user"], $transferowner); // stat $sf = new StatFile($transfer, $transferowner); // settings if (isset($transfers['settings'][$transfer])) { $settingsAry = $transfers['settings'][$transfer]; } else { $settingsAry = array(); if (substr($transfer, -8) == ".torrent") { // this is a t-client $settingsAry['type'] = "torrent"; $settingsAry['client'] = $cfg["btclient"];
/** * output error * * @param $message */ function _outputError($message) { // in cli-mode if ($this->_mode == MAINTENANCEANDREPAIR_MODE_CLI) { printError($this->name, $message); } else { addGrowlMessage($this->name, $message); } }