move.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /* $Id: move.php 3082 2007-06-09 13:51:43Z danez $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // common functions
  23. require_once('inc/functions/functions.common.php');
  24. // dir functions
  25. require_once('inc/functions/functions.dir.php');
  26. // is enabled ?
  27. if ($cfg["enable_move"] != 1) {
  28. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to use move");
  29. @error("move is disabled. Action has been logged.", "", "");
  30. }
  31. // init template-instance
  32. tmplInitializeInstance($cfg["theme"], "page.move.tmpl");
  33. // set vars
  34. if((isset($_REQUEST['start'])) && ($_REQUEST['start'] == true)) {
  35. $path = stripslashes($_REQUEST['path']);
  36. $dir = tfb_getRequestVar('path');
  37. $source = $cfg["path"].$dir;
  38. // only valid paths + entries with permission
  39. if (!((tfb_isValidPath($source)) &&
  40. (isValidEntry(basename($source))) &&
  41. (hasPermission($dir, $cfg["user"], 'w')))) {
  42. AuditAction($cfg["constants"]["error"], "ILLEGAL MOVE: ".$cfg["user"]." tried to move ".$dir);
  43. @error("Illegal move. Action has been logged.", "", "");
  44. }
  45. //
  46. $tmpl->setvar('is_start', 1);
  47. $tmpl->setvar('path', $path);
  48. $tmpl->setvar('_MOVE_STRING', $cfg['_MOVE_STRING']);
  49. $tmpl->setvar('_MOVE_FILE', $cfg['_MOVE_FILE']);
  50. if ((isset($cfg["move_paths"])) && (strlen($cfg["move_paths"]) > 0)) {
  51. $tmpl->setvar('move_start', 1);
  52. $dirs = explode(":", trim($cfg["move_paths"]));
  53. $dir_list = array();
  54. foreach ($dirs as $dir) {
  55. $target = trim($dir);
  56. if ((strlen($target) > 0) && ((substr($target, 0, 1)) != ";"))
  57. array_push($dir_list, array('target' => $target));
  58. }
  59. $tmpl->setloop('dir_list', $dir_list);
  60. } else {
  61. $tmpl->setvar('move_start', 0);
  62. }
  63. } else {
  64. $file = $_POST['file'];
  65. $targetDir = "";
  66. if (isset($_POST['dest'])) {
  67. $tempDir = trim(rawurldecode($_POST['dest']));
  68. if (strlen($tempDir) > 0) {
  69. $targetDir = $tempDir;
  70. } else {
  71. if (isset($_POST['selector']))
  72. $targetDir = trim(urldecode($_POST['selector']));
  73. }
  74. }
  75. // only valid dirs + entries with permission
  76. if (!((tfb_isValidPath($cfg["path"].$file)) &&
  77. (tfb_isValidPath($targetDir)) &&
  78. (isValidEntry(basename($cfg["path"].$file))) &&
  79. (hasPermission($file, $cfg["user"], 'w')))) {
  80. AuditAction($cfg["constants"]["error"], "ILLEGAL MOVE: ".$cfg["user"]." tried to move ".$file." to ".$targetDir);
  81. @error("Illegal move. Action has been logged.", "", "");
  82. }
  83. // we need absolute paths or stuff will end up in docroot
  84. // inform user .. don't move it into a fallback-dir which may be a hassle
  85. $dirValid = true;
  86. if (strlen($targetDir) <= 0) {
  87. $dirValid = false;
  88. } else {
  89. if ($targetDir{0} != '/') {
  90. $tmpl->setvar('not_absolute', 1);
  91. $dirValid = false;
  92. } else {
  93. $tmpl->setvar('not_absolute', 0);
  94. }
  95. }
  96. $tmpl->setvar('is_start', 0);
  97. $tmpl->setvar('targetDir', $targetDir);
  98. // check dir
  99. if (($dirValid) && (checkDirectory($targetDir, 0777))) {
  100. $tmpl->setvar('is_valid', 1);
  101. $targetDir = checkDirPathString($targetDir);
  102. // Add slashes if magic_quotes off:
  103. if (get_magic_quotes_gpc() !== 1)
  104. $targetDir = addslashes($targetDir);
  105. // Use single quote to escape mv args:
  106. $cmd = "mv '".$cfg["path"].$file."' '".$targetDir."'";
  107. $cmd .= ' 2>&1';
  108. $handle = popen($cmd, 'r');
  109. // get the output and print it.
  110. $gotError = -1;
  111. $buff= "";
  112. while (!feof($handle)) {
  113. $buff .= @fgets($handle,30);
  114. $gotError = $gotError + 1;
  115. }
  116. $tmpl->setvar('messages', nl2br($buff));
  117. pclose($handle);
  118. if ($gotError <= 0) {
  119. $tmpl->setvar('got_no_error', 1);
  120. $tmpl->setvar('file', $file);
  121. } else {
  122. $tmpl->setvar('got_no_error', 0);
  123. }
  124. } else {
  125. $tmpl->setvar('is_valid', 1);
  126. }
  127. }
  128. //
  129. tmplSetTitleBar($cfg["pagetitle"]." - ".$cfg['_MOVE_FILE_TITLE'], false);
  130. tmplSetIidVars();
  131. // parse template
  132. $tmpl->pparse();
  133. ?>