17 include_once (
"FDL/import_tar.php");
24 $dirid = GetHttpVars(
"dirid");
25 $famid = GetHttpVars(
"famid");
26 $onlycsv = (GetHttpVars(
"onlycsv") !=
"");
27 $analyze = (GetHttpVars(
"analyze",
"N") ==
"Y");
34 if ($_FILES[
'tar'][
'error'] != UPLOAD_ERR_OK) {
35 switch ($_FILES[
'tar'][
'error']) {
36 case UPLOAD_ERR_INI_SIZE:
37 $err = sprintf(
"The uploaded file exceeds the upload_max_filesize [%s bytes] directive in php.ini", ini_get(
'upload_max_filesize'));
40 case UPLOAD_ERR_FORM_SIZE:
41 $err =
"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
44 case UPLOAD_ERR_PARTIAL:
45 $err =
"The uploaded file was only partially uploaded.";
48 case UPLOAD_ERR_NO_FILE:
49 $err =
"No file was uploaded.";
55 system(
"mkdir -p " . escapeshellarg($uploaddir));
56 $fname = get_magic_quotes_gpc() ? stripslashes($_FILES[
'tar'][
'name']) : $_FILES[
'tar'][
'name'];
57 $uploadfile = $uploaddir . $fname;
58 if (move_uploaded_file($_FILES[
'tar'][
'tmp_name'],
"$uploadfile")) {
59 $report = sprintf(_(
"File %s is valid, and was successfully uploaded.") , $fname);
65 $extract = sprintf(_(
"The file %s has been correctly extracted") , $fname);
67 $extract = sprintf(_(
"The file %s cannot be extracted: %s") , $fname,
$status);
70 $report = _(
"Possible file upload attack! Here's some debugging info:\n");
75 $action->lay->eset(
"filename", $fname);
76 $action->lay->eset(
"report",
$report);
77 $action->lay->eset(
"extract", $extract);
78 $action->lay->eset(
"dirid",
$dirid);
83 $tar = realpath($tar);
84 $mime = trim(shell_exec(sprintf(
"file -b %s", escapeshellarg($tar))));
85 $mime = substr($mime, 0, strpos($mime,
" "));
91 case "application/x-compressed-tar":
92 case "application/x-gzip":
93 exec(sprintf(
"rm -rf %s 2>&1", escapeshellarg($untardir)) , $output,
$status);
95 throw new Exception(sprintf(_(
"Error deleting directory '%s': %s") , $untardir, join(
"\n", $output)));
97 exec(sprintf(
"mkdir -p %s 2>&1", escapeshellarg($untardir)) , $output,
$status);
99 throw new Exception(sprintf(_(
"Error creating directory '%s': %s") , $untardir, join(
"\n", $output)));
101 exec(sprintf(
"tar -C %s -zxf %s 2>&1", escapeshellarg($untardir) , escapeshellarg($tar)) , $output,
$status);
103 throw new Exception(sprintf(_(
"Error extracting archive '%s' in '%s': %s") , $tar, $untardir, join(
"\n", $output)));
108 exec(sprintf(
"rm -rf %s 2>&1", escapeshellarg($untardir)) , $output,
$status);
110 throw new Exception(sprintf(_(
"Error deleting directory '%s': %s") , $untardir, join(
"\n", $output)));
112 exec(sprintf(
"mkdir -p %s 2>&1", escapeshellarg($untardir)) , $output,
$status);
114 throw new Exception(sprintf(_(
"Error creating directory '%s': %s") , $untardir, join(
"\n", $output)));
116 exec(sprintf(
"tar -C %s -jxf %s 2>&1", escapeshellarg($untardir) , escapeshellarg($tar)) , $output,
$status);
118 throw new Exception(sprintf(_(
"Error extracting archive '%s' in '%s': %s") , $tar, $untardir, join(
"\n", $output)));
123 case "application/x-zip-compressed":
124 case "application/x-zip":
125 exec(sprintf(
"rm -rf %s 2>&1", escapeshellarg($untardir)) , $output,
$status);
127 throw new Exception(sprintf(_(
"Error deleting directory '%s': %s") , $untardir, join(
"\n", $output)));
129 exec(sprintf(
"mkdir -p %s 2>&1", escapeshellarg($untardir)) , $output,
$status);
131 throw new Exception(sprintf(_(
"Error creating directory '%s': %s") , $untardir, join(
"\n", $output)));
133 exec(sprintf(
"unzip -d %s %s 2>&1", escapeshellarg($untardir) , escapeshellarg($tar)) , $output,
$status);
135 throw new Exception(sprintf(_(
"Error extracting archive '%s' in '%s': %s") , $tar, $untardir, join(
"\n", $output)));
140 throw new Exception(sprintf(_(
"Unsupported archive format '%s' for archive '%s'.") , $mime, $tar));
143 catch(Exception $e) {
144 $err = $e->getMessage();
getTarExtractDir(Action &$action, $tar)
freedom_import_tar(Action &$action)
exitError($texterr, $exit=true, $code="")
getTarUploadDir(Action &$action)
extractTar($tar, $untardir, $mime="")
if($file) if($subject==""&&$file) if($subject=="") $err