PUT THIS FILE IN A DIRECTORY ON YOUR WEB SERVER (maybe a directory called w3btorrent) AND VISIT IT
*/
/*
w3btorrent (keep it simple) - simple web fronted torrent client
Copyright (C) 2005, 2007 Vegard Hammerseth (http://thewulong.com)
w3btorrent is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
*/
/* DON'T EDIT ANYTHING BELOW, UNLESS YOU KNOW WHAT YOU'RE DOING */
if (phpversion() < 4)
{
exit("Sorry, you need PHP4+ to be able to use w3btorrent.");
}
error_reporting(E_ALL);
class install
{
var $title = "w3btorrent web installer v1.3";
var $logo = "http://w3btorrent.sourceforge.net/pix/w3btorrent.jpg";
var $url = "http://kent.dl.sourceforge.net/sourceforge/w3btorrent/w3btorrent_0.1.3.tar.gz";
var $steps = array("Writeable dir","Download","Extract archive","Binary check","Finish");
function is_installed()
{
if (isset($_SESSION['step']))
{
return;
}
if (is_file("inc/class/w3btorrent.class.php"))
{
return true;
}
}
function initial()
{
if (isset($_SESSION['step']))
{
return;
}
$_SESSION['webuser'] = trim($this->safe_exec("whoami"));
$_SESSION['realdirpath'] = dirname($_SERVER['SCRIPT_FILENAME'])."/";
$_SESSION['step'] = 2;
}
/* valid url */
function valid_url($arg_url)
{
if (preg_match("/(http(s?)|ftp):\/\//i",$arg_url) && @fopen($arg_url,"r"))
{
return true;
}
}
function get_real_location($arg_url,$arg_max_redirects = 5)
{
$headers = array_reverse(get_headers($arg_url));
foreach ($headers as $value)
{
if (preg_match("/^location:(.*)/i",$value,$m))
{
return trim($m['1']);
}
}
}
/* find executable path for program */
function exec_path($arg_cmd)
{
$paths = array("/usr/bin","/bin","/usr/local/bin","/usr/sbin","/sbin");
$paths = array_merge($paths,explode(":",$_SERVER['PATH']));
$paths = array_unique($paths);
/* find and execute path */
foreach ($paths as $path)
{
if (is_executable($path."/".$arg_cmd))
{
return $path."/".$arg_cmd;
}
}
}
/* be able to execute files even with safe_exec on! */
function safe_exec($arg_cmd)
{
$cmdlist = explode(" ",$arg_cmd);
$cmd = $cmdlist['0'];
$args = implode(" ",array_slice($cmdlist,1));
if (!is_executable($cmd) && !$path = $this->exec_path($cmd))
{
return;
}
/* execute command with arguments and return result */
if (!$popen = popen("$cmd $args","r"))
{
return;
}
$return = "";
while (!feof($popen))
{
$return .= fgets($popen,4096);
}
pclose($popen);
return $return;
}
function download_archive($arg_url)
{
if (!isset($arg_url))
{
return "Write a URL to a w3torrent archive.";
}
elseif (!$fdata = file_get_contents($arg_url))
{
return "Problems with URL, check it that it works.";
}
$filename = basename($arg_url);
/* save file this way, supporting PHP4 users */
if (!$f = fopen($filename,"w"))
{
return "Can't create new files in this directory.";
}
if (!fwrite($f,$fdata))
{
fclose($f);
return "Unable to write to system.";
}
fclose($f);
}
/* move contents within directory to another directory */
function move_dir_content($argdir,$argtodir)
{
if (!is_dir($argdir) || !$d = dir($argdir))
{
return;
}
while ($entry = $d->read())
{
if ($entry == "." || $entry == "..")
{
continue;
}
rename("$argdir/$entry","$argtodir/$entry");
}
$d->close();
rmdir($argdir);
return true;
}
/* use a valid directory */
function valid_dir($arg_dir)
{
if (is_dir($arg_dir) && is_readable($arg_dir) && is_executable($arg_dir) && is_writeable($arg_dir))
{
return true;
}
}
function decompress_archive($arg_file)
{
$file = escapeshellarg($arg_file);
$this->safe_exec("tar xf $file");
/* did the execute work? */
if (!is_dir("w3btorrent"))
{
unset($_SESSION['filename']);
return "We were unable to decompress '$arg_file'. Make sure it is a tar archive. Go back and download a new one.";
}
/* try move the directory's content's to curren dir */
if (!$this->move_dir_content("w3btorrent/",$_SESSION['realdirpath']))
{
return "Unable to move the folder within 'w3btorrent/' to current directory, check permissions.";
}
}
function binary_works()
{
$exec = $this->safe_exec("system/wctorrent -h 2>&1");
if (strlen($exec) > 1000)
{
return true;
}
}
function configure($arg_dir)
{
$olddir = getcwd();
chdir($arg_dir);
$exec = $this->safe_exec("bash configure --prefix=".escapeshellarg($arg_dir));
$exec = str_replace("... yes\n","... yes\n",$exec);
$exec = str_replace("... no\n","... no\n",$exec);
chdir($olddir);
return $exec;
}
function compile($arg_dir)
{
$olddir = getcwd();
chdir($arg_dir);
$exec = $this->safe_exec("make install");
if (substr($exec,0,7) == "cd . &&" && preg_match("/missing --run (.*)/",$exec,$m))
{
$exec = "WARNING: `".$m['1']."' is needed, and you do not seem to have it handy on your\nsystem. You might have modified some files without having the\nproper tools for further handling them. Check the `README' file,\nit often tells you about the needed prerequirements for installing\nthis package. You may also peek at any GNU archive site, in case\nsome other package would contain this missing `".$m['1']."' program.";
}
chdir($olddir);
return $exec;
}
}
/* session */
$install = new install;
session_name("w3btorrent".getcwd());
session_start();
ob_start();
/* if it's already installed hightlight this file so everyone can get it */
if ($install->is_installed())
{
echo file_get_contents($_SERVER['SCRIPT_FILENAME']);
exit();
}
/* set values */
$install->initial();
/* highlight progress */
$install->steps[$_SESSION['step']-($install->valid_dir($_SESSION['realdirpath'])?1:2)] = "".$install->steps[$_SESSION['step']-($install->valid_dir($_SESSION['realdirpath'])?1:2)]."";
/* for download, extract and compiling */
ini_set("max_execution_time",1600); // 30 min
?>
title; ?>