Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
freedom_import_tar.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Import document descriptions
9  *
10  * @author Anakeen 2000
11  * @version $Id: freedom_import_tar.php,v 1.3 2006/01/16 16:11:39 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage GED
15  */
16 /**
17  */
18 
19 include_once ("FDL/import_tar.php");
20 
22 {
23 
24  global $_FILES;
25 
26  $dirid = GetHttpVars("dirid"); // directory to place imported doc
27  $famid = GetHttpVars("famid"); // default import family
28  $onlycsv = (GetHttpVars("onlycsv") != ""); // only files described in fdl.csv files
29  $analyze = (GetHttpVars("analyze", "N") == "Y"); // just analyze
30  $uploaddir = getTarUploadDir($action);
31 
32  $dbaccess = $action->GetParam("FREEDOM_DB");
33  if ($_FILES['tar']['error'] != UPLOAD_ERR_OK) {
34  switch ($_FILES['tar']['error']) {
35  case UPLOAD_ERR_INI_SIZE:
36  $err = sprintf("The uploaded file exceeds the upload_max_filesize [%s bytes] directive in php.ini", ini_get('upload_max_filesize'));
37  break;
38 
39  case UPLOAD_ERR_FORM_SIZE:
40  $err = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
41  break;
42 
43  case UPLOAD_ERR_PARTIAL:
44  $err = "The uploaded file was only partially uploaded.";
45  break;
46 
47  case UPLOAD_ERR_NO_FILE:
48  $err = "No file was uploaded.";
49  break;
50  }
51  if ($err != "") $action->exitError($err);
52  } else {
53 
54  system("mkdir -p " . escapeshellarg($uploaddir));
55  $fname = get_magic_quotes_gpc() ? stripslashes($_FILES['tar']['name']) : $_FILES['tar']['name'];
56  $uploadfile = $uploaddir . $fname;
57  if (move_uploaded_file($_FILES['tar']['tmp_name'], "$uploadfile")) {
58  $report = sprintf(_("File %s is valid, and was successfully uploaded.") , $fname);
59 
60  $untardir = getTarExtractDir($action, $fname);
61 
62  $status = extractTar($uploadfile, $untardir, $_FILES['tar']['type']);
63  if ($status == 0) $extract = sprintf(_("The file %s has been correctly extracted") , $fname);
64  else $extract = sprintf(_("The file %s cannot be extracted") , $fname);
65  } else {
66  $report = _("Possible file upload attack! Here's some debugging info:\n");
67  print_r2($_FILES);
68  }
69  }
70 
71  $action->lay->set("filename", $fname);
72  $action->lay->set("report", $report);
73  $action->lay->set("extract", $extract);
74  $action->lay->set("dirid", $dirid);
75 }
76 
77 function extractTar($tar, $untardir, $mime = "")
78 {
79 
80  $mime = trim(shell_exec(sprintf("file -ib %s", escapeshellarg($tar))));
81  $mime = trim(shell_exec(sprintf("file -b %s", escapeshellarg($tar))));
82  $mime = substr($mime, 0, strpos($mime, " "));
83 
84  if ($status == 0) {
85  switch ($mime) {
86  case "gzip":
87  case "application/x-compressed-tar":
88  case "application/x-gzip":
89  system("/bin/rm -fr " . escapeshellarg($untardir) . "; mkdir -p " . escapeshellarg($untardir) , $status);
90  system("cd " . escapeshellarg($untardir) . " && tar xfz " . escapeshellarg($tar) . " >/dev/null", $status);
91 
92  break;
93 
94  case "bzip2":
95  system("/bin/rm -fr " . escapeshellarg($untardir) . "; mkdir -p " . escapeshellarg($untardir) , $status);
96  system("cd " . escapeshellarg($untardir) . " && tar xf " . escapeshellarg($tar) . " --use-compress-program bzip2 >/dev/null", $status);
97 
98  break;
99 
100  case "Zip":
101  case "application/x-zip-compressed":
102  case "application/x-zip":
103  system("/bin/rm -fr " . escapeshellarg($untardir) . "; mkdir -p " . escapeshellarg($untardir) , $status);
104  system("cd " . escapeshellarg($untardir) . " && unzip " . escapeshellarg($tar) . " >/dev/null", $status);
105 
106  WNGBDirRename($untardir);
107  break;
108 
109  default:
110  $status = - 2;
111  }
112  }
113  return $status;
114 }
115 ?>
← centre documentaire © anakeen - published under CC License - Dynacase