| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
function brouteur_extract($file, $dest="./") |
|---|
| 10 |
{ |
|---|
| 11 |
static $i=0, $ret; |
|---|
| 12 |
$file = addslashes($file); |
|---|
| 13 |
$dest = addslashes($dest); |
|---|
| 14 |
if ($i == 0) { |
|---|
| 15 |
|
|---|
| 16 |
# need to specify the compression format |
|---|
| 17 |
exec("tar -xzf '$file' -C '$dest'", $void, $ret); |
|---|
| 18 |
} else if ($i == 1) { |
|---|
| 19 |
exec("tar -xjf '$file' -C '$dest'", $void, $ret); |
|---|
| 20 |
} else if ($i == 2) { |
|---|
| 21 |
exec("unzip '$file' -d '$dest'", $void, $ret); |
|---|
| 22 |
} else if ($i == 3) { |
|---|
| 23 |
|
|---|
| 24 |
# but I think unrar just sucks <TM> |
|---|
| 25 |
$rarfile = ereg_replace('[a-z0-9]+', '..', $dest)."/$file"; |
|---|
| 26 |
exec("mkdir -p '$dest'"); |
|---|
| 27 |
exec("cd '$dest' && unrar x -o+ '$rarfile'", $void, $ret); |
|---|
| 28 |
} else { |
|---|
| 29 |
return $ret; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
if ($ret) { |
|---|
| 33 |
$i++; |
|---|
| 34 |
brouteur_extract($file, $dest); |
|---|
| 35 |
} |
|---|
| 36 |
return $ret; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
function brouteur_copy($name, $src, $dest) |
|---|
| 50 |
{ |
|---|
| 51 |
global $error, $db; |
|---|
| 52 |
|
|---|
| 53 |
$ok = false; |
|---|
| 54 |
@mkdir($dest, 0777); |
|---|
| 55 |
@chmod($dest, 0777); |
|---|
| 56 |
$f = @fopen("$dest/test.php", 'w'); |
|---|
| 57 |
if ($f) { |
|---|
| 58 |
@fputs($f, '<?php $ok = true; ?>'); |
|---|
| 59 |
@fclose($f); |
|---|
| 60 |
@chmod("$dest/test.php", 0777); |
|---|
| 61 |
include("$dest/test.php"); |
|---|
| 62 |
} |
|---|
| 63 |
@unlink("$dest/test.php"); |
|---|
| 64 |
@rmdir("$dest"); |
|---|
| 65 |
if (!$ok) { |
|---|
| 66 |
$error = _("No write permissions in the destination directory"); |
|---|
| 67 |
return false; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
if (substr($src, 0, 7) == "http://") { |
|---|
| 71 |
$filename = basename($src); |
|---|
| 72 |
$extractdir = tempnam("/tmp", "brouteur"); |
|---|
| 73 |
unlink($extractdir); |
|---|
| 74 |
mkdir($extractdir); |
|---|
| 75 |
|
|---|
| 76 |
if (!$http = @fopen($src, "rb")) { |
|---|
| 77 |
|
|---|
| 78 |
ereg('^http://([^/]+)(/.*)$', $src, $eregs); |
|---|
| 79 |
$hostname = $eregs[1]; |
|---|
| 80 |
$path = $eregs[2]; |
|---|
| 81 |
$http = @fsockopen($hostname, 80); |
|---|
| 82 |
@fputs($http, "GET $path HTTP/1.1\nHost: $hostname\n\n"); |
|---|
| 83 |
} |
|---|
| 84 |
if ($http) { |
|---|
| 85 |
|
|---|
| 86 |
$f = fopen("$extractdir/$filename", "wb"); |
|---|
| 87 |
while (!feof($http)) { |
|---|
| 88 |
$bin = fgets($http, 16384); |
|---|
| 89 |
fwrite($f, $bin); |
|---|
| 90 |
|
|---|
| 91 |
} |
|---|
| 92 |
fclose($f); |
|---|
| 93 |
fclose($http); |
|---|
| 94 |
} else { |
|---|
| 95 |
|
|---|
| 96 |
exec("wget -q '$src' -O '$extractdir/$filename'", $void, $ret); |
|---|
| 97 |
if ($ret) { |
|---|
| 98 |
$error = _("Unable to download the web application's package."); |
|---|
| 99 |
return false; |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
if (!brouteur_extract("$extractdir/$filename", $extractdir)) { |
|---|
| 105 |
$error = _("Unable to extract the files"); |
|---|
| 106 |
return false; |
|---|
| 107 |
} |
|---|
| 108 |
unlink("$extractdir/$filename"); |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
$hd = opendir($extractdir); |
|---|
| 112 |
while ($file = readdir($hd)) { |
|---|
| 113 |
if ($file != "." && $file != "..") { |
|---|
| 114 |
$src = "$extractdir/$file"; |
|---|
| 115 |
break; |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
$src = addslashes($src); |
|---|
| 122 |
$dest = addslashes($dest); |
|---|
| 123 |
$array = explode('/', $dest); |
|---|
| 124 |
$dir = ""; |
|---|
| 125 |
foreach ($array as $v) { |
|---|
| 126 |
$dir .= "$v/"; |
|---|
| 127 |
@mkdir($dest); |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
exec("cp -Rf '$src'/* '$dest'", $void, $ret); |
|---|
| 131 |
if ($ret) { |
|---|
| 132 |
$error = _("Errors happened while copying the source to destination."); |
|---|
| 133 |
return false; |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
$error = _("The web application has been successfully installed."); |
|---|
| 137 |
return true; |
|---|
| 138 |
} |
|---|
| 139 |
?> |
|---|
| 140 |
|
|---|