/** * start a stream * * @param $file * @param $vidc * @param $vbit * @param $audc * @param $abit */ function instance_start($file, $vidc, $vbit, $audc, $abit) { global $cfg; // build command $this->_command = "nohup"; $this->_command .= " " . $cfg['bin_vlc']; $this->_command .= " --rc-fake-tty"; if ($vidc == 'direct') { $this->_command .= " --play-and-stop --intf telnet -vvv \"" . str_replace("'", "\\'", $file) . "\""; $this->_command .= " --sout '#standard{access=http,mux=ogg,dst=" . $this->addr . ":" . $this->port . "}'"; } else { $this->_command .= " --sout " . tfb_shellencode("#transcode{vcodec=" . $vidc . ",vb=" . $vbit . ",scale=1,acodec=" . $audc . ",ab=" . $abit . ",channels=2}:std{access=mmsh,mux=asfh,dst=" . $this->addr . ":" . $this->port . "}"); $this->_command .= " " . tfb_shellencode($file); } $this->_command = str_replace('//', '/', $this->_command); $this->_command .= " > /dev/null &"; //2>>/var/log/vlc_tfberr &"; // DEBUG : log the command if ($cfg['debuglevel'] > 1) { AuditAction($cfg["constants"]["debug"], "vlcStart : " . $this->_command); } // exec command exec($this->_command); }
/** * Returns file size... overcomes PHP limit of 2.0GB * * @param $file * @return int */ function file_size($file) { $size = @filesize($file); if ($size == 0) { return exec("ls -l " . tfb_shellencode($file) . " 2>/dev/null | awk '{print \$5}'"); } return $size; }
/** * instance_start * * @return boolean */ function instance_start() { global $cfg; if ($this->state == FLUAZU_STATE_RUNNING) { AuditAction($cfg["constants"]["error"], "fluazu already started"); return false; } else { // check the needed bins // python if (@file_exists($cfg['pythonCmd']) !== true) { $msg = "cannot start fluazu, specified python-binary does not exist: " . $cfg['pythonCmd']; AuditAction($cfg["constants"]["error"], $msg); array_push($this->messages, $msg); // Set the state $this->state = FLUAZU_STATE_ERROR; // return return false; } // start it $startCommand = "cd " . tfb_shellencode($cfg["docroot"] . "bin/clients/fluazu/") . "; HOME=" . tfb_shellencode($cfg["path"]) . ";"; $startCommand .= " export HOME;"; $startCommand .= " nohup"; $startCommand .= " " . $cfg["pythonCmd"] . " -OO"; $startCommand .= " fluazu.py"; $startCommand .= " " . tfb_shellencode($cfg["path"]); $startCommand .= " " . tfb_shellencode($cfg["fluazu_host"]); $startCommand .= " " . tfb_shellencode($cfg["fluazu_port"]); $startCommand .= " " . tfb_shellencode($cfg["fluazu_secure"]); $startCommand .= $cfg["fluazu_user"] == "" ? ' ""' : " " . tfb_shellencode($cfg["fluazu_user"]); $startCommand .= $cfg["fluazu_pw"] == "" ? ' ""' : " " . tfb_shellencode($cfg["fluazu_pw"]); $startCommand .= " 1>> " . tfb_shellencode($this->_pathLogFile); $startCommand .= " 2>> " . tfb_shellencode($this->_pathLogFile); $startCommand .= " &"; // log the command $this->instance_logMessage("executing command : \n" . $startCommand . "\n", true); // exec $result = exec($startCommand); // check if fluazu could be started $loop = true; $maxLoops = 125; $loopCtr = 0; $started = false; while ($loop) { @clearstatcache(); if (file_exists($this->_pathStatFile)) { $started = true; $loop = false; } else { $loopCtr++; if ($loopCtr > $maxLoops) { $loop = false; } else { usleep(200000); } // wait for 0.2 seconds } } // check if started if ($started) { AuditAction($cfg["constants"]["admin"], "fluazu started"); // Set the state $this->state = FLUAZU_STATE_RUNNING; // return return true; } else { AuditAction($cfg["constants"]["error"], "errors starting fluazu"); // Set the state $this->state = FLUAZU_STATE_ERROR; // return return false; } } }
/** * backup of flux-installation * * @param $talk: boolean if function should talk * @param $compression: 0 = none | 1 = gzip | 2 = bzip2 * @return string with name of backup-archive, string with "" in error-case. */ function backupCreate($talk = false, $compression = 0) { global $cfg, $error; // backup-dir $dirBackup = $cfg["path"] . _DIR_BACKUP; if (!checkDirectory($dirBackup)) { $error = "Errors when checking/creating backup-dir: " . tfb_htmlencodekeepspaces($dirBackup); return ""; } // files and more strings $backupName = "backup_" . _VERSION . "_" . date("YmdHis"); $fileArchiveName = $backupName . ".tar"; $tarSwitch = "-cf"; switch ($compression) { case 1: $fileArchiveName .= ".gz"; $tarSwitch = "-zcf"; break; case 2: $fileArchiveName .= ".bz2"; $tarSwitch = "-jcf"; break; } // files $files = array(); $files['archive'] = $dirBackup . '/' . $fileArchiveName; $files['db'] = $dirBackup . '/database.sql'; $files['docroot'] = $dirBackup . '/docroot.tar'; $files['transfers'] = $dirBackup . '/transfers.tar'; $files['fluxd'] = $dirBackup . '/fluxd.tar'; $files['mrtg'] = $dirBackup . '/mrtg.tar'; // exec $exec = array(); $exec['transfers'] = @is_dir($cfg["transfer_file_path"]) === true; $exec['fluxd'] = @is_dir($cfg["path"] . '.fluxd') === true; $exec['mrtg'] = @is_dir($cfg["path"] . '.mrtg') === true; // commands $commands = array(); $commands['archive'] = "cd " . tfb_shellencode($dirBackup) . "; tar " . $tarSwitch . " " . $fileArchiveName . " "; $commands['db'] = ""; switch ($cfg["db_type"]) { case "mysql": $commands['db'] = "mysqldump -h " . tfb_shellencode($cfg["db_host"]) . " -u " . tfb_shellencode($cfg["db_user"]) . " --password="******"db_pass"]) . " --all -f " . tfb_shellencode($cfg["db_name"]) . " > " . tfb_shellencode($files['db']); $commands['archive'] .= 'database.sql '; break; case "sqlite": $commands['db'] = "sqlite " . tfb_shellencode($cfg["db_host"]) . " .dump > " . tfb_shellencode($files['db']); $commands['archive'] .= 'database.sql '; break; case "postgres": $commands['db'] = "pg_dump -h " . tfb_shellencode($cfg["db_host"]) . " -D " . tfb_shellencode($cfg["db_name"]) . " -U " . tfb_shellencode($cfg["db_user"]) . " -f " . tfb_shellencode($files['db']); $commands['archive'] .= 'database.sql '; break; } $commands['archive'] .= 'docroot.tar'; if ($exec['transfers'] === true) { $commands['archive'] .= ' transfers.tar'; } if ($exec['fluxd'] === true) { $commands['archive'] .= ' fluxd.tar'; } if ($exec['mrtg'] === true) { $commands['archive'] .= ' mrtg.tar'; } //$commands['docroot'] = "cd ".tfb_shellencode($dirBackup)."; tar -cf docroot.tar ".tfb_shellencode($cfg["docroot"]); // with path of docroot $commands['docroot'] = "cd " . tfb_shellencode($cfg["docroot"]) . "; tar -cf " . tfb_shellencode($files['docroot']) . " ."; // only content of docroot $commands['transfers'] = "cd " . tfb_shellencode($cfg["transfer_file_path"]) . "; tar -cf " . tfb_shellencode($files['transfers']) . " ."; $commands['fluxd'] = "cd " . tfb_shellencode($cfg["path"] . '.fluxd') . "; tar -cf " . tfb_shellencode($files['fluxd']) . " ."; $commands['mrtg'] = "cd " . tfb_shellencode($cfg["path"] . '.mrtg') . "; tar -cf " . tfb_shellencode($files['mrtg']) . " ."; // action if ($talk) { sendLine('<br>'); } // database-command if ($commands['db'] != "") { if ($talk) { sendLine('Backup of Database <em>' . tfb_htmlencodekeepspaces($cfg["db_name"]) . '</em> ...'); } shell_exec($commands['db']); } if ($talk) { sendLine(' <font color="green">Ok</font><br>'); } // docroot-command if ($talk) { sendLine('Backup of Docroot <em>' . tfb_htmlencodekeepspaces($cfg["docroot"]) . '</em> ...'); } shell_exec($commands['docroot']); if ($talk) { sendLine(' <font color="green">Ok</font><br>'); } // transfers-command if ($exec['transfers'] === true) { if ($talk) { sendLine('Backup of transfers <em>' . tfb_htmlencodekeepspaces($cfg["transfer_file_path"]) . '</em> ...'); } shell_exec($commands['transfers']); if ($talk) { sendLine(' <font color="green">Ok</font><br>'); } } // fluxd-command if ($exec['fluxd'] === true) { if ($talk) { sendLine('Backup of fluxd <em>' . tfb_htmlencodekeepspaces($cfg["path"] . '.fluxd') . '</em> ...'); } shell_exec($commands['fluxd']); if ($talk) { sendLine(' <font color="green">Ok</font><br>'); } } // mrtg-command if ($exec['mrtg'] === true) { if ($talk) { sendLine('Backup of mrtg <em>' . tfb_htmlencodekeepspaces($cfg["path"] . '.mrtg') . '</em> ...'); } shell_exec($commands['mrtg']); if ($talk) { sendLine(' <font color="green">Ok</font><br>'); } } // create the archive if ($talk) { sendLine('Creating Archive <em>' . $fileArchiveName . '</em> ...'); } shell_exec($commands['archive']); if ($talk) { sendLine(' <font color="green">Ok</font><br>'); } // delete temp-file(s) if ($talk) { sendLine('Deleting temp-files ...'); } if ($commands['db'] != "") { @unlink($files['db']); } @unlink($files['docroot']); @unlink($files['transfers']); @unlink($files['fluxd']); @unlink($files['mrtg']); if ($talk) { sendLine(' <font color="green">Ok</font><br>'); } // log if ($talk) { sendLine('<font color="green">Backup Complete.</font><br>'); } AuditAction($cfg["constants"]["admin"], "Backup Created: " . $fileArchiveName); return $fileArchiveName; }
/** * starts a client * * @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; // set vars $this->_setVarsForTransfer($transfer); // log $this->logMessage($this->client . "-start : " . $transfer . "\n", true); // do tornado special-pre-start-checks // check to see if the path to the python script is valid if (!is_file($this->tornadoBin)) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "path for tftornado.py is not valid"; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); array_push($this->messages, $msg); array_push($this->messages, "tornadoBin : " . $this->tornadoBin); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error'; $sf->write(); // return return false; } // init starting of client $this->_init($interactive, $enqueue, true, $cfg['enable_sharekill'] == 1); // only continue if init succeeded (skip start / error) if ($this->state != CLIENTHANDLER_STATE_READY) { if ($this->state == CLIENTHANDLER_STATE_ERROR) { $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")"; array_push($this->messages, $msg); $this->logMessage($msg . "\n", true); } // return return false; } // file-prio if ($cfg["enable_file_priority"]) { setFilePriority($transfer); } // pythonCmd $pyCmd = $cfg["pythonCmd"] . " -OO"; // build the command-string $skipHashCheck = ""; if (!empty($this->skip_hash_check) && getTorrentDataSize($transfer) > 0) { $skipHashCheck = " --check_hashes 0"; } $filePrio = ""; if (@file_exists($this->transferFilePath . ".prio")) { $priolist = explode(',', @file_get_contents($this->transferFilePath . ".prio")); $priolist = implode(',', array_slice($priolist, 1, $priolist[0])); $filePrio = " --priority " . tfb_shellencode($priolist); } // build the command-string // note : order of args must not change for ps-parsing-code in // RunningTransferTornado $this->command = ""; // Proxy Hack // $this->command .= 'export http_proxy=127.0.0.1:8118; HTTP_PROXY=$http_proxy;'; $this->command .= "cd " . tfb_shellencode($this->savepath) . ";"; $this->command .= " HOME=" . tfb_shellencode($cfg["path"]); $this->command .= "; export HOME;"; $this->command .= $this->umask; $this->command .= " nohup "; $this->command .= $this->nice; $this->command .= $pyCmd . " " . tfb_shellencode($this->tornadoBin); $this->command .= " " . tfb_shellencode($this->runtime); $this->command .= " " . tfb_shellencode($this->sharekill_param); $this->command .= " " . tfb_shellencode($this->owner); $this->command .= " " . tfb_shellencode($this->transferFilePath); $this->command .= " --responsefile " . tfb_shellencode($this->transferFilePath); $this->command .= " --display_interval 1"; $this->command .= " --max_download_rate " . tfb_shellencode($this->drate); $this->command .= " --max_upload_rate " . tfb_shellencode($this->rate); $this->command .= " --max_uploads " . tfb_shellencode($this->maxuploads); $this->command .= " --minport " . tfb_shellencode($this->port); $this->command .= " --maxport " . tfb_shellencode($this->maxport); $this->command .= " --rerequest_interval " . tfb_shellencode($this->rerequest); $this->command .= " --super_seeder " . tfb_shellencode($this->superseeder); $this->command .= " --max_connections " . tfb_shellencode($this->maxcons); $this->command .= $skipHashCheck; $this->command .= $filePrio; if (strlen($cfg["btclient_tornado_options"]) > 0) { $this->command .= " " . $cfg["btclient_tornado_options"]; } $this->command .= " 1>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " 2>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " &"; // start the client $this->_start(); }
/** * del * * @param $file * @return */ function del($file) { exec("rm -f " . tfb_shellencode($file)); return true; }
$dirS = str_replace($cfg["path"], '', $dir); if (!(tfb_isValidPath($dir) && hasPermission($dirS, $cfg["user"], 'r'))) { AuditAction($cfg["constants"]["error"], "ILLEGAL SFV-ACCESS: " . $cfg["user"] . " tried to check " . $dirS); @error("Illegal access. Action has been logged.", "", ""); } } if (!empty($file)) { $fileS = str_replace($cfg["path"], '', $file); if (!(tfb_isValidPath($file) && isValidEntry(basename($file)) && hasPermission($fileS, $cfg["user"], 'r'))) { AuditAction($cfg["constants"]["error"], "ILLEGAL SFV-ACCESS: " . $cfg["user"] . " tried to check " . $fileS); @error("Illegal access. Action has been logged.", "", ""); } } // init template-instance tmplInitializeInstance($cfg["theme"], "page.checkSFV.tmpl"); // process $cmd = $cfg['bin_cksfv'] . ' -C ' . tfb_shellencode($dir) . ' -f ' . tfb_shellencode($file); $handle = popen($cmd . ' 2>&1', 'r'); $buff = isset($cfg["debuglevel"]) && $cfg["debuglevel"] == 2 ? "<strong>Debug:</strong> Evaluating command:<br/><br/><pre>" . tfb_htmlencode($cmd) . "</pre><br/>Output follows below:<br/>" : ""; $buff .= "<pre>"; while (!feof($handle)) { $buff .= tfb_htmlencode(@fgets($handle, 30)); } $tmpl->setvar('buff', $buff); pclose($handle); $buff .= "</pre>"; // set vars tmplSetTitleBar($cfg["pagetitle"] . ' - checkSFV', false); tmplSetIidVars(); // parse template $tmpl->pparse();
function runningDaemonInfo() { global $cfg; // ps-string $screenStatus = shell_exec("ps x a -o pid -o %cpu -o command | " . $cfg['bin_grep'] . " " . tfb_shellencode($this->binClient) . " | " . $cfg['bin_grep'] . " -v grep"); $arScreen = array(); $tok = strtok($screenStatus, "\n"); while ($tok) { array_push($arScreen, $tok); $tok = strtok("\n"); } $retVal = " --- Running Processes ---\n"; $retVal .= " Daemon : " . count($screenStatus) . "\n"; $retVal .= "\n"; $retVal .= " PID %CPU Command\n"; $retVal .= $screenStatus . "\n"; return $retVal; }
function getDownloadFtpLogUsers($srchFile, $logNumber = "") { global $cfg, $db, $dlLog; $userlist = array(); $userRenamer = array(); //xferlog or xferlog.0 (last month) //$ftplog = '/var/log/proftpd/xferlog'.$logNumber; $ftplog = "/var/log/pure-ftpd/stats_transfer{$logNumber}.log"; if (!is_file($ftplog)) { return array(); } //Search in Log (for old or external log insert, todo) $srchFile = str_replace($cfg["path"], '', $srchFile); //Search in cached db log array foreach ($dlLog as $row) { if ($row->file == $srchFile) { $userlist[$row->user_id] = htmlentities(substr($row->user_id, 0, 3), ENT_QUOTES); } } if (count($userlist) > 0) { return $userlist; } if (!file_exists($ftplog)) { return $userlist; } $userRenamer["root"] = "epsylon3"; $cmdLog = "cat {$ftplog}|" . $cfg["bin_grep"] . ' ' . tfb_shellencode(str_replace(' ', '_', $srchFile)); //.'|'.$cfg["bin_grep"]." -o -E ' r (.*) ftp'" $dlInfos = trim(@shell_exec($cmdLog)); if ($dlInfos) { $ftpusers = explode("\n", $dlInfos); foreach ($ftpusers as $key => $value) { /* PROFTPD $value=substr($value,4); $time=strtotime(substr($value,0,20)); $value=substr($value,21); $lineWords=explode(' ',$value); $hostname=$lineWords[1]; $size=0+($lineWords[2]); $username=$lineWords[count($lineWords)-5]; $complete=$lineWords[count($lineWords)-1]; */ /* pure-ftpd (stats:/var/log/pure-ftpd/stats_transfer.log) */ $lineWords = explode(' ', $value); $time = 0 + $lineWords[0]; $username = $lineWords[2]; $hostname = $lineWords[3]; $complete = str_replace("D", "c", $lineWords[4]); $size = 0.0 + $lineWords[5]; //die( "<pre>$size-$complete-$hostname-$username-$time\n$value\n</pre>"); if ($complete == "c") { //rename user ? if (array_key_exists($username, $userRenamer)) { $username = $userRenamer[$username]; } if (!array_key_exists($username, $userlist)) { $srchAction = "File Download (FTP)"; $db->Execute("INSERT INTO tf_log (user_id,file,action,ip,ip_resolved,user_agent,time)" . " VALUES (" . $db->qstr($username) . "," . $db->qstr($srchFile) . "," . $db->qstr($srchAction) . "," . $db->qstr('FTP') . "," . $db->qstr($hostname) . "," . $db->qstr('FTP') . "," . $time . ")"); if ($db->ErrorNo() != 0) { dbError($sql); } } $userlist[$username] = substr($username, 0, 3); } } } return $userlist; }
/** * Validates existence + exec + valid version of transmissioncli and returns the status image * * @param $the_file * @return string */ function validateTransmissionCli($the_file) { global $cfg; if (!isFile($the_file)) { return validationMsg(false, 'Path is not valid'); } if (!is_executable($the_file)) { return validationMsg(false, 'File exists but is not executable'); } $transmissionHelp = strtolower(shell_exec("HOME=" . tfb_shellencode($cfg["path"]) . "; export HOME; " . $the_file . ' --help')); return strpos($transmissionHelp, 'transmission') === false || strpos($transmissionHelp, 'tfcli') === false && strpos($transmissionHelp, 'torrentflux') === false ? validationMsg(false, 'Executable is not TorrentFlux-bundled transmissioncli') : validationMsg(true); }
/** * starts a client * * @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; // set vars $this->_setVarsForTransfer($transfer); // log $this->logMessage($this->client . "-start : " . $transfer . "\n", true); // do transmission special-pre-start-checks // check to see if the path to the transmission-bin is valid if (!is_executable($cfg["btclient_transmission_bin"])) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "transmissioncli cannot be executed"; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); array_push($this->messages, $msg); array_push($this->messages, "btclient_transmission_bin : " . $cfg["btclient_transmission_bin"]); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error'; $sf->write(); // return return false; } // init starting of client $this->_init($interactive, $enqueue, true, false); // only continue if init succeeded (skip start / error) if ($this->state != CLIENTHANDLER_STATE_READY) { if ($this->state == CLIENTHANDLER_STATE_ERROR) { $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")"; array_push($this->messages, $msg); $this->logMessage($msg . "\n", true); } // return return false; } /* // workaround for bsd-pid-file-problem : touch file first if ((!$this->queue) && ($cfg["_OS"] == 2)) @touch($this->transferFilePath.".pid"); */ // build the command-string // note : order of args must not change for ps-parsing-code in // RunningTransferTransmission $this->command = "cd " . tfb_shellencode($this->savepath) . ";"; $this->command .= " HOME=" . tfb_shellencode($cfg["path"]) . "; export HOME;" . ($this->command .= $this->umask); $this->command .= " nohup "; $this->command .= $this->nice; $this->command .= tfb_shellencode($cfg["btclient_transmission_bin"]); $this->command .= " -d " . tfb_shellencode($this->drate); $this->command .= " -u " . tfb_shellencode($this->rate); $this->command .= " -p " . tfb_shellencode($this->port); $this->command .= " -W " . tfb_shellencode($this->runtime == "True" ? 1 : 0); $this->command .= " -L " . tfb_shellencode($this->sharekill_param); $this->command .= " -E 6"; $this->command .= " -O " . tfb_shellencode($this->owner); if (strlen($cfg["btclient_transmission_options"]) > 0) { $this->command .= " " . $cfg["btclient_transmission_options"]; } $this->command .= " " . tfb_shellencode($this->transferFilePath); $this->command .= " 1>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " 2>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " &"; // start the client $this->_start(); }
// languages $arLang = GetLanguages(); $countLang = count($arLang); $tmpl->setvar('server_lang_total', $countLang); // du switch ($cfg["_OS"]) { case 1: //Linux $duArg = "-D"; break; case 2: //BSD $duArg = "-L"; break; } $du = @shell_exec($cfg['bin_du'] . " -ch " . tfb_shellencode($duArg) . " " . tfb_shellencode($cfg['docroot']) . " | " . $cfg['bin_grep'] . " \"total\""); $tmpl->setvar('server_du_total', substr($du, 0, -7)); // version $tmpl->setvar('server_version', $cfg["version"]); // M: db-settings $tmpl->setvar('db_type', $cfg["db_type"]); $tmpl->setvar('db_host', $cfg["db_host"]); $tmpl->setvar('db_name', $cfg["db_name"]); $tmpl->setvar('db_user', $cfg["db_user"]); $tmpl->setvar('db_pcon', $cfg["db_pcon"] ? "true" : "false"); // R: server-stats $tmpl->setvar('server_os', php_uname('s')); $tmpl->setvar('server_php', PHP_VERSION); $tmpl->setvar('server_php_state', PHP_VERSION < 4.3 ? 0 : 1); $loadedExtensions = get_loaded_extensions(); if (in_array("session", $loadedExtensions)) {
/** * set dir tree vars * * @param $dir * @param $maxdepth */ function tmplSetDirTree($dir, $maxdepth) { global $cfg, $tmpl; $tmpl->setvar('dirtree_dir', $dir); if (is_numeric($maxdepth)) { $retvar_list = array(); $last = $maxdepth == 0 ? exec("find " . tfb_shellencode($dir) . " -type d | sort && echo", $retval) : exec("find " . tfb_shellencode($dir) . " -maxdepth " . tfb_shellencode($maxdepth) . " -type d | sort && echo", $retval); for ($i = 1; $i < count($retval) - 1; $i++) { array_push($retvar_list, array('retval' => $retval[$i])); } $tmpl->setloop('dirtree_retvar_list', $retvar_list); } }
$tmpl->setvar('skip_hash_check_enabled', $cfg["supportMap"][$ch->client]['skip_hash_check']); if ($cfg["supportMap"][$ch->client]['skip_hash_check'] == 1) { $dsize = getTorrentDataSize($transfer); $tmpl->setvar('is_skip', $dsize > 0 && $dsize != 4096 ? $cfg["skiphashcheck"] : 0); } else { $tmpl->setvar('is_skip', 0); } // queue $tmpl->setvar('is_queue', FluxdQmgr::isRunning() ? 1 : 0); // break break; case "rewrite": /* btreannounce*/ $newUrl = tfb_getRequestVar('announceUrl'); if ($newUrl != $announceUrl) { echo shell_exec("cd " . tfb_shellencode($cfg["transfer_file_path"]) . "; " . $cfg["pythonCmd"] . " -OO " . tfb_shellencode($cfg["docroot"] . "bin/clients/tornado/btreannounce.py") . " " . tfb_shellencode($newUrl) . ' ' . tfb_shellencode($transfer)); } break; default: /* default */ @error("Invalid pageop", "", "", array($pageop)); } // title + foot tmplSetFoot(false); tmplSetTitleBar($transferLabel . " - Control", false); // lang vars $tmpl->setvar('_RUNTRANSFER', $cfg['_RUNTRANSFER']); $tmpl->setvar('_STOPTRANSFER', $cfg['_STOPTRANSFER']); $tmpl->setvar('_DELQUEUE', $cfg['_DELQUEUE']); // iid tmplSetIidVars();
/** * starts a client * * @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; // set vars $this->_setVarsForTransfer($transfer); // log $this->logMessage($this->client . "-start : " . $transfer . "\n", true); // do nzbperl special-pre-start-checks // check to see if the path to the nzbperl script is valid if (!is_file($this->nzbbin)) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "path for tfnzbperl.pl is not valid"; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); array_push($this->messages, $msg); array_push($this->messages, "nzbbin : " . $this->nzbbin); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error'; $sf->write(); // return return false; } // init starting of client $this->_init($interactive, $enqueue, false, false); // only continue if init succeeded (skip start / error) if ($this->state != CLIENTHANDLER_STATE_READY) { if ($this->state == CLIENTHANDLER_STATE_ERROR) { $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")"; array_push($this->messages, $msg); $this->logMessage($msg . "\n", true); } // return return false; } // Build Command String (do not change order of last args !) $this->command = "cd " . tfb_shellencode($this->savepath) . ";"; $this->command .= " HOME=" . tfb_shellencode(substr($cfg["path"], 0, -1)); $this->command .= "; export HOME;"; $this->command .= $this->umask; $this->command .= " nohup "; $this->command .= $this->nice; $this->command .= $cfg['perlCmd']; $this->command .= " -I " . tfb_shellencode($cfg["docroot"] . "bin/lib"); $this->command .= " " . tfb_shellencode($this->nzbbin); $this->command .= " --conn " . tfb_shellencode($cfg['nzbperl_conn']); $this->command .= " --uudeview " . tfb_shellencode($cfg["bin_uudeview"]); $this->command .= $cfg['nzbperl_badAction'] ? " --insane --keepbrokenbin" : " --dropbad"; switch ($cfg['nzbperl_create']) { case 1: $this->command .= " --dlcreate"; break; case 2: $this->command .= " --dlcreategrp"; break; } $this->command .= " --dthreadct " . tfb_shellencode($cfg['nzbperl_threads']); $this->command .= " --speed " . tfb_shellencode($this->drate); $this->command .= " --server " . tfb_shellencode($cfg['nzbperl_server']); $this->command .= " --port " . tfb_shellencode($cfg['nzbperl_port']); if ($cfg["nzbperl_ssl"] == 1) { $this->command .= " --ssl"; } if ($cfg['nzbperl_user'] != "") { $this->command .= " --user " . tfb_shellencode($cfg['nzbperl_user']); $this->command .= " --pw " . tfb_shellencode($cfg['nzbperl_pw']); } if (strlen($cfg["nzbperl_options"]) > 0) { $this->command .= " " . $cfg['nzbperl_options']; } // do NOT change anything below (not even order) $this->command .= " --dlpath " . tfb_shellencode($this->savepath); $this->command .= " --tfuser " . tfb_shellencode($this->owner); $this->command .= " " . tfb_shellencode($this->transferFilePath); $this->command .= " 1>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " 2>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " &"; // state $this->state = CLIENTHANDLER_STATE_READY; // Start the client $this->_start(); }
/** * create torrent with Mainline * * @return string $onLoad */ function createTorrentMainline() { global $cfg, $path, $tfile, $comment, $piece, $use_tracker, $tracker_name, $alert; $onLoad = ""; // Clean up old files if (@file_exists($cfg["transfer_file_path"] . $tfile)) { @unlink($cfg["transfer_file_path"] . $tfile); } // build command-string $command = "cd " . tfb_shellencode($cfg["transfer_file_path"]) . ";"; $command .= " HOME=" . tfb_shellencode($cfg["path"]); $command .= "; export HOME;"; $command .= "nohup " . $cfg["pythonCmd"] . " -OO "; $command .= tfb_shellencode($cfg["docroot"] . "bin/clients/mainline/maketorrent-console.py"); $command .= " --no_verbose"; $command .= " --no_debug"; // $command .= " --language en"; // Is there comments to add? if (!empty($comment)) { $command .= " --comment " . tfb_shellencode($comment); } // Set the piece size if (!empty($piece)) { $command .= " --piece_size_pow2 " . tfb_shellencode($piece); } // trackerless / tracker /* if ((isset($use_tracker)) && ($use_tracker == 1)) $command .= " --use_tracker"; else $command .= " --no_use_tracker"; */ $command .= " --use_tracker"; // tracker-name //if ((!empty($tracker_name)) && ($tracker_name != "http://")) $command .= " --tracker_name " . tfb_shellencode($tracker_name); // Set the target torrent field $command .= " --target " . tfb_shellencode($cfg["transfer_file_path"] . $tfile); // tracker (i don't know...) $command .= " " . tfb_shellencode($tracker_name); // input $command .= " " . tfb_shellencode($cfg["path"] . $path); // Set to never timeout for large torrents @set_time_limit(0); // Let's see how long this takes... $time_start = microtime(true); // Execute the command exec($command); // We want to check to make sure the file was successful $success = false; $raw = @file_get_contents($cfg["transfer_file_path"] . $tfile); if (preg_match("/6:pieces([^:]+):/i", $raw, $results)) { // This means it is a valid torrent $success = true; // Make an entry for the owner AuditAction($cfg["constants"]["file_upload"], $tfile); } else { // Something went wrong, clean up if (@file_exists($cfg["transfer_file_path"] . $tfile)) { @unlink($cfg["transfer_file_path"] . $tfile); } } // We are done! how long did we take? $time_end = microtime(true); $diff = duration($time_end - $time_start); // make path URL friendly to support non-standard characters $downpath = urlencode($tfile); // Depending if we were successful, display the required information $onLoad = $success ? "completed('" . $downpath . "'," . $alert . ",'" . $diff . "');" : "failed('" . $downpath . "'," . $alert . ");"; return $onLoad; }
/** * gets metainfo of a torrent as string * * @param $transfer name of the torrent * @return string with torrent-meta-info */ function getTorrentMetaInfo($transfer) { global $cfg; switch ($cfg["metainfoclient"]) { case "transmissioncli": return shell_exec("HOME=" . tfb_shellencode($cfg["path"]) . "; export HOME; " . $cfg["btclient_transmission_bin"] . " -i " . tfb_shellencode($cfg["transfer_file_path"] . $transfer)); case "ttools.pl": return shell_exec($cfg["perlCmd"] . ' -I ' . tfb_shellencode($cfg["docroot"] . 'bin/ttools') . ' ' . tfb_shellencode($cfg["docroot"] . 'bin/ttools/ttools.pl') . ' -i ' . tfb_shellencode($cfg["transfer_file_path"] . $transfer)); case "torrentinfo-console.py": return shell_exec("cd " . tfb_shellencode($cfg["transfer_file_path"]) . "; " . $cfg["pythonCmd"] . " -OO " . tfb_shellencode($cfg["docroot"] . "bin/clients/mainline/torrentinfo-console.py") . " " . tfb_shellencode($transfer)); case "btshowmetainfo.py": default: return shell_exec("cd " . tfb_shellencode($cfg["transfer_file_path"]) . "; " . $cfg["pythonCmd"] . " -OO " . tfb_shellencode($cfg["docroot"] . "bin/clients/tornado/btshowmetainfo.py") . " " . tfb_shellencode($transfer)); } }
/** * starts a client * * @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; // set vars $this->_setVarsForTransfer($transfer); // log $this->logMessage($this->client . "-start : " . $transfer . "\n", true); // do mainline special-pre-start-checks // check to see if the path to the python script is valid if (!is_file($this->mainlineBin)) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "path for tfmainline.py is not valid"; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); array_push($this->messages, $msg); array_push($this->messages, "mainlineBin : " . $this->mainlineBin); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error'; $sf->write(); // return return false; } // init starting of client $this->_init($interactive, $enqueue, true, $cfg['enable_sharekill'] == 1); // only continue if init succeeded (skip start / error) if ($this->state != CLIENTHANDLER_STATE_READY) { if ($this->state == CLIENTHANDLER_STATE_ERROR) { $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")"; array_push($this->messages, $msg); $this->logMessage($msg . "\n", true); } // return return false; } // build the command-string // note : order of args must not change for ps-parsing-code in // RunningTransferMainline $this->command = "cd " . tfb_shellencode($this->savepath) . ";"; $this->command .= " HOME=" . tfb_shellencode($cfg["path"]); $this->command .= "; export HOME;"; $this->command .= $this->umask; $this->command .= " nohup "; $this->command .= $this->nice; $this->command .= $cfg["pythonCmd"] . " -OO" . " " . tfb_shellencode($this->mainlineBin); $this->command .= " --tf_owner " . tfb_shellencode($this->owner); $this->command .= " --display_interval 1"; $this->command .= " --save_incomplete_in " . tfb_shellencode($this->savepath); $this->command .= " --save_in " . tfb_shellencode($this->savepath); $this->command .= " --die_when_done " . tfb_shellencode($this->runtime); $this->command .= " --seed_limit " . tfb_shellencode($this->sharekill_param); $this->command .= $this->drate != 0 ? " --max_download_rate " . tfb_shellencode($this->drate * 1024) : " --max_download_rate 125000000"; // 1 GBit local net = 125MB/s $this->command .= $this->rate != 0 ? " --max_upload_rate " . tfb_shellencode($this->rate * 1024) : " --max_upload_rate 125000000"; // 1 GBit local net = 125MB/s $this->command .= " --max_uploads " . tfb_shellencode($this->maxuploads); $this->command .= " --minport " . tfb_shellencode($this->port); $this->command .= " --maxport " . tfb_shellencode($this->maxport); $this->command .= " --rerequest_interval " . tfb_shellencode($this->rerequest); $this->command .= " --max_initiate " . tfb_shellencode($this->maxcons); if (!empty($this->skip_hash_check) && getTorrentDataSize($this->transfer) > 0) { $this->command .= " --no_check_hashes"; } if (strlen($cfg["btclient_mainline_options"]) > 0) { $this->command .= " " . $cfg["btclient_mainline_options"]; } $this->command .= " " . tfb_shellencode($this->transferFilePath); $this->command .= " 1>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " 2>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " &"; // start the client $this->_start(); }
/** * Get the size in bytes of a directory() * * @param string $path * @return string $size bytes */ function dirsize($path) { global $cfg; if (!is_dir($path)) { return -1; } switch ($cfg["_OS"]) { case 1: // linux $size = shell_exec("du -sb " . tfb_shellencode($path)); $size = (double) preg_replace("/(.+)[\t\\s]*.*/", "\$1", $size); return $size; case 2: // bsd $size = shell_exec("du -sk " . tfb_shellencode($path)); $size = (double) preg_replace("/(.+)[\t\\s]*.*/", "\$1", $size); $size = $size * 1024; return $size; } return -1; }
/** * start a stream * * @param $file * @param $vidc * @param $vbit * @param $audc * @param $abit */ function instance_start($file, $vidc, $vbit, $audc, $abit) { global $cfg; // build command $this->_command = "nohup"; $this->_command .= " " . $cfg['bin_vlc']; $this->_command .= " --rc-fake-tty"; $this->_command .= " --sout " . tfb_shellencode("#transcode{vcodec=" . $vidc . ",vb=" . $vbit . ",scale=1,acodec=" . $audc . ",ab=" . $abit . ",channels=2}:std{access=mmsh,mux=asfh,dst=" . $this->addr . ":" . $this->port . "}"); $this->_command .= " " . tfb_shellencode($file); $this->_command .= " > /dev/null &"; // DEBUG : log the command if ($cfg['debuglevel'] > 1) { AuditAction($cfg["constants"]["debug"], "vlcStart : " . $this->_command); } // exec command exec($this->_command); }
/** * starts a client * * @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; // set vars $this->_setVarsForTransfer($transfer); // log $this->logMessage($this->client . "-start : " . $transfer . "\n", true); // FluAzu require_once "inc/classes/FluAzu.php"; // do azureus special-pre-start-checks // check to see if fluazu is running if (!FluAzu::isRunning()) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "fluazu not running, cannot start transfer " . $transfer; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); array_push($this->messages, $msg); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error: fluazu down'; $sf->write(); // return return false; } // init starting of client $this->_init($interactive, $enqueue, true, false); // only continue if init succeeded (skip start / error) if ($this->state != CLIENTHANDLER_STATE_READY) { if ($this->state == CLIENTHANDLER_STATE_ERROR) { $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")"; array_push($this->messages, $msg); $this->logMessage($msg . "\n", true); } // return return false; } // build the command-string $content = $cfg['user'] . "\n"; $content .= $this->savepath . "\n"; $content .= $this->rate . "\n"; $content .= $this->drate . "\n"; $content .= $this->maxuploads . "\n"; $content .= $this->superseeder . "\n"; $content .= $this->runtime . "\n"; $content .= $this->sharekill_param . "\n"; $content .= $this->minport . "\n"; $content .= $this->maxport . "\n"; $content .= $this->maxcons . "\n"; $content .= $this->rerequest; $this->command = "echo -e " . tfb_shellencode($content) . " > " . tfb_shellencode($cfg["path"] . '.fluazu/run/' . $transfer); $this->command .= " && "; $this->command .= "echo r > " . tfb_shellencode($cfg["path"] . '.fluazu/fluazu.cmd'); // start the client $this->_start(); }
/** * instance_start * * @return boolean */ function instance_start() { global $cfg; if ($this->state == FLUXD_STATE_RUNNING) { AuditAction($cfg["constants"]["error"], "fluxd already started"); return false; } else { // check the needed bins // perl if (@file_exists($cfg['perlCmd']) !== true) { $msg = "cannot start fluxd, specified Perl-binary does not exist: " . $cfg['perlCmd']; AuditAction($cfg["constants"]["error"], $msg); array_push($this->messages, $msg); // Set the state $this->state = FLUXD_STATE_ERROR; // return return false; } // php-cli if (@file_exists($cfg['bin_php']) !== true) { $msg = "cannot start fluxd, specified php-cli-binary does not exist: " . $cfg['bin_php']; AuditAction($cfg["constants"]["error"], $msg); array_push($this->messages, $msg); // Set the state $this->state = FLUXD_STATE_ERROR; // return return false; } // check for sockets $loadedExtensions = get_loaded_extensions(); if (!in_array("sockets", $loadedExtensions)) { $msg = "refusing to start fluxd, PHP does not have support for sockets"; AuditAction($cfg["constants"]["error"], $msg); array_push($this->messages, $msg); // Set the state $this->state = FLUXD_STATE_ERROR; // return return false; } // start it $startCommand = "cd " . tfb_shellencode($cfg["docroot"]) . "; HOME=" . tfb_shellencode($cfg["path"]) . ";"; $startCommand .= " export HOME;"; $startCommand .= " nohup " . $cfg["perlCmd"]; $startCommand .= " -I " . tfb_shellencode($cfg["docroot"] . "bin/fluxd"); $startCommand .= " -I " . tfb_shellencode($cfg["docroot"] . "bin/lib"); $startCommand .= " " . tfb_shellencode($cfg["docroot"] . "bin/fluxd/fluxd.pl"); $startCommand .= " start"; $startCommand .= " " . tfb_shellencode($cfg["docroot"]); $startCommand .= " " . tfb_shellencode($cfg["path"]); $startCommand .= " " . tfb_shellencode($cfg["bin_php"]); $startCommand .= " " . tfb_shellencode($cfg["fluxd_dbmode"]); $startCommand .= " 1>> " . tfb_shellencode($this->_pathLogFile); $startCommand .= " 2>> " . tfb_shellencode($this->_pathLogFileError); $startCommand .= " &"; $this->instance_logMessage("executing command : \n" . $startCommand . "\n", true); // exec $result = exec($startCommand); // check if fluxd could be started $loop = true; $maxLoops = 125; $loopCtr = 0; $started = false; while ($loop) { @clearstatcache(); if ($this->_isRunning()) { $started = true; $loop = false; } else { $loopCtr++; if ($loopCtr > $maxLoops) { $loop = false; } else { usleep(200000); } // wait for 0.2 seconds } } // check if started if ($started) { AuditAction($cfg["constants"]["fluxd"], "fluxd started"); // Set the state $this->state = FLUXD_STATE_RUNNING; // return return true; } else { AuditAction($cfg["constants"]["error"], "errors starting fluxd"); // add startcommand to messages for debug // TODO : set better message array_push($this->messages, $startCommand); // Set the state $this->state = FLUXD_STATE_ERROR; // return return false; } } }
*/ // xmwebui seems to accept only urls and magnet to add torrents // so i've added that to download local torrent file. // edit: fixed in vuze core 4.5.1.1-B30 if (isset($_REQUEST['getUrl'])) { header("Content-type: application/octet-stream\n"); // main.core to get $cfg chdir('../../'); require_once 'inc/main.core.php'; // security replace (dl only local torrent files) $transfer = str_replace('/', '', $_REQUEST['getUrl']); global $cfg; $path = $cfg["transfer_file_path"]; //$data = file_get_contents($path.$transfer); if (is_file($path . $transfer)) { $fp = popen("cat " . tfb_shellencode($path . $transfer), "r"); fpassthru($fp); pclose($fp); exit(0); } } // for static calls, first create will affect this var // next calls will reuse it with VuzeRPC::getInstance() // usefull for curl, to keep connection (no curl_close) $VuzeRPC_instance = NULL; class VuzeRPC { public $DEBUG = false; public $HOST = '127.0.0.1'; public $PORT = '9091'; public $USER = '******';
/** * 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 (is_executable($cfg["btclient_transmission_bin"])) { $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); } } // 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"; }
/** * _maintenanceFluazu * delete leftovers of fluazu (only do this if daemon is not running) */ function _maintenanceFluazu() { global $cfg; // output $this->_outputMessage("fluazu-maintenance...\n"); // files $fdp = $cfg["path"] . '.fluazu/fluazu.pid'; $fds = $cfg["path"] . '.fluazu/fluazu.stat'; $fdc = $cfg["path"] . '.fluazu/fluazu.cmd'; $fdpe = file_exists($fdp); $fdse = file_exists($fds); $fdce = file_exists($fdc); $leftoversFound = false; $fctr = 0; if ($fdpe) { $fctr++; } if ($fdse) { $fctr++; } if ($fdce) { $fctr++; } if ($fctr > 0) { if ("1" != @trim(shell_exec("ps x -o pid='' -o ppid='' -o command='' -ww 2> /dev/null | " . $cfg['bin_grep'] . " -v grep | " . $cfg['bin_grep'] . " 'fluazu.py' | " . $cfg['bin_grep'] . " -c " . tfb_shellencode($cfg["path"])))) { $leftoversFound = true; } } if ($leftoversFound) { // problems $this->_outputMessage("found and removing fluazu-leftovers...\n"); // pid if ($fdpe) { @unlink($fdp); } // stat if ($fdse) { @unlink($fds); } // command if ($fdce) { @unlink($fdc); } // DEBUG : log the repair if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], "fluazu-maintenance : found and removed fluazu-leftovers."); } // output $this->_outputMessage("done.\n"); } else { // no problems $this->_outputMessage("no problems found.\n"); } /* done */ $this->_outputMessage("fluazu-maintenance done.\n"); }
/** * get info of running clients (via call to ps) * * @return string */ function runningProcessInfo() { global $cfg; // ps-string $screenStatus = shell_exec("ps x -o pid='' -o ppid='' -o command='' -ww | " . $cfg['bin_grep'] . " " . tfb_shellencode($this->binClient) . " | " . $cfg['bin_grep'] . " " . tfb_shellencode($cfg["transfer_file_path"]) . " | " . $cfg['bin_grep'] . " -v grep"); $arScreen = array(); $tok = strtok($screenStatus, "\n"); while ($tok) { array_push($arScreen, $tok); $tok = strtok("\n"); } $cProcess = array(); $cpProcess = array(); $pProcess = array(); $ProcessCmd = array(); for ($i = 0; $i < sizeof($arScreen); $i++) { if (strpos($arScreen[$i], $this->binClient) !== false) { $pinfo = new ProcessInfo($arScreen[$i]); if (intval($pinfo->ppid) == 1) { if (!strpos($pinfo->cmdline, "rep " . $this->binSystem) > 0) { if (!strpos($pinfo->cmdline, "ps x") > 0) { array_push($pProcess, $pinfo->pid); $rt = RunningTransfer::getInstance($pinfo->pid . " " . $pinfo->cmdline, $this->client); array_push($ProcessCmd, $rt->transferowner . "\t" . $rt->transferFile); } } } else { if (!strpos($pinfo->cmdline, "rep " . $this->binSystem) > 0) { if (!strpos($pinfo->cmdline, "ps x") > 0) { array_push($cProcess, $pinfo->pid); array_push($cpProcess, $pinfo->ppid); } } } } } $retVal = " --- Running Processes ---\n"; $retVal .= " Parents : " . count($pProcess) . "\n"; $retVal .= " Children : " . count($cProcess) . "\n"; $retVal .= "\n"; $retVal .= " PID \tOwner\tTransfer File\n"; foreach ($pProcess as $key => $value) { $retVal .= " " . $value . "\t" . $ProcessCmd[$key] . "\n"; } $retVal .= "\n"; return $retVal; }
/** * 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"; }
/** * check if client-process is running * * @return boolean */ function _clientIsRunning() { return strpos(exec('ps -p ' . tfb_shellencode($this->_pid)), $this->_pid) !== false; }
$tmpl->setvar('who_free', shell_exec("free -mo")); // drivespace-bar tmplSetDriveSpaceBar(); break; // ps // ps case "ps": // set vars if ($cfg['isAdmin']) { // array with all clients $clients = array('tornado', 'transmission', 'mainline', 'wget', 'nzbperl', 'azureus'); // get informations $process_list = array(); foreach ($clients as $client) { $ch = ClientHandler::getInstance($client); array_push($process_list, array('client' => $client, 'RunningProcessInfo' => $ch->runningProcessInfo(), 'pinfo' => shell_exec("ps auxww | " . $cfg['bin_grep'] . " " . tfb_shellencode($ch->binClient) . " | " . $cfg['bin_grep'] . " -v grep"))); } $tmpl->setloop('process_list', $process_list); } // drivespace-bar tmplSetDriveSpaceBar(); break; // netstat // netstat case "netstat": // set vars if ($cfg['isAdmin']) { // set vars $tmpl->setvar('netstatConnectionsSum', netstatConnectionsSum()); $tmpl->setvar('netstatPortList', netstatPortList()); $tmpl->setvar('netstatHostList', netstatHostList());
/** * starts a client * * @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; // set vars from the wget-file $this->setVarsFromFile($transfer); // log $this->logMessage($this->client . "-start : " . $transfer . "\n", true); // do wget special-pre-start-checks // check to see if the path to the php-bin is valid if (@file_exists($cfg['bin_php']) !== true) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "php-cli binary does not exist"; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); array_push($this->messages, $msg); array_push($this->messages, "bin_php : " . $cfg["bin_php"]); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error'; $sf->write(); // return return false; } // check to see if the wget-bin is executable if (!is_executable($cfg["bin_wget"])) { $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "wget cannot be executed"; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); array_push($this->messages, $msg); array_push($this->messages, "bin_wget : " . $cfg["bin_wget"]); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error'; $sf->write(); // return return false; } // init starting of client $this->_init($interactive, $enqueue, false, false); // only continue if init succeeded (skip start / error) if ($this->state != CLIENTHANDLER_STATE_READY) { if ($this->state == CLIENTHANDLER_STATE_ERROR) { $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")"; array_push($this->messages, $msg); $this->logMessage($msg . "\n", true); } // return return false; } // build the command-string // note : order of args must not change for ps-parsing-code in // RunningTransferWget $this->command = "nohup " . $cfg['bin_php'] . " -f bin/wget.php"; $this->command .= " " . tfb_shellencode($this->transferFilePath); $this->command .= " " . tfb_shellencode($this->owner); $this->command .= " " . tfb_shellencode($this->savepath); $this->command .= " " . tfb_shellencode($this->drate * 1024); $this->command .= " " . tfb_shellencode($cfg["wget_limit_retries"]); $this->command .= " " . tfb_shellencode($cfg["wget_ftp_pasv"]); $this->command .= " 1>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " 2>> " . tfb_shellencode($this->transferFilePath . ".log"); $this->command .= " &"; // state $this->state = CLIENTHANDLER_STATE_READY; // start the client $this->_start(); }