rename.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /* $Id: rename.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_rename"] != 1) {
  28. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to use rename");
  29. @error("rename is disabled. Action has been logged.", "", "");
  30. }
  31. // init template-instance
  32. tmplInitializeInstance($cfg["theme"], "page.rename.tmpl");
  33. // process move and set vars
  34. if ((isset($_REQUEST['start'])) && ($_REQUEST['start'] == true)) {
  35. $file = UrlHTMLSlashesDecode($_REQUEST['file']);
  36. $dir = UrlHTMLSlashesDecode($_REQUEST['dir']);
  37. $sourceDir = $cfg["path"].$dir;
  38. // only valid dirs + entries with permission
  39. if (!((tfb_isValidPath($sourceDir)) &&
  40. (tfb_isValidPath($sourceDir.$file)) &&
  41. (isValidEntry($file)) &&
  42. (hasPermission($dir, $cfg["user"], 'w')))) {
  43. AuditAction($cfg["constants"]["error"], "ILLEGAL RENAME: ".$cfg["user"]." tried to rename ".$file." in ".$dir);
  44. @error("Illegal rename. Action has been logged.", "", "");
  45. }
  46. // template
  47. $tmpl->setvar('is_start', 1);
  48. $tmpl->setvar('file', $file);
  49. $tmpl->setvar('dir', $dir);
  50. $tmpl->setvar('_REN_FILE', $cfg['_REN_FILE']);
  51. $tmpl->setvar('_REN_STRING', $cfg['_REN_STRING']);
  52. } else {
  53. $file = tfb_getRequestVar('fileFrom');
  54. $fileTo = tfb_getRequestVar('fileTo');
  55. $dir = tfb_getRequestVar('dir');
  56. $sourceDir = $cfg["path"].$dir;
  57. $targetDir = $cfg["path"].$dir.$fileTo;
  58. // Add slashes if magic_quotes off:
  59. if (get_magic_quotes_gpc() !== 1) {
  60. $targetDir = addslashes($targetDir);
  61. $sourceDir = addslashes($sourceDir);
  62. }
  63. // only valid dirs + entries with permission
  64. if (!((tfb_isValidPath($sourceDir)) &&
  65. (tfb_isValidPath($sourceDir.$file)) &&
  66. (tfb_isValidPath($targetDir)) &&
  67. (isValidEntry($file)) &&
  68. (isValidEntry($fileTo)) &&
  69. (hasPermission($dir, $cfg["user"], 'w')))) {
  70. AuditAction($cfg["constants"]["error"], "ILLEGAL RENAME: ".$cfg["user"]." tried to rename ".$file." in ".$dir." to ".$fileTo);
  71. @error("Illegal rename. Action has been logged.", "", "");
  72. }
  73. // Use single quote to escape mv args:
  74. $cmd = "mv '".$sourceDir.$file."' '".$targetDir."'";
  75. $cmd .= ' 2>&1';
  76. $handle = popen($cmd, 'r' );
  77. $gotError = -1;
  78. $buff = fgets($handle);
  79. $gotError = $gotError + 1;
  80. pclose($handle);
  81. // template
  82. $tmpl->setvar('is_start', 0);
  83. $tmpl->setvar('messages', nl2br($buff));
  84. if ($gotError <= 0) {
  85. $tmpl->setvar('no_error', 1);
  86. $tmpl->setvar('fileFrom', $file);
  87. $tmpl->setvar('fileTo', $fileTo);
  88. $tmpl->setvar('_REN_DONE', $cfg['_REN_DONE']);
  89. } else {
  90. $tmpl->setvar('no_error', 0);
  91. $tmpl->setvar('_REN_ERROR', $cfg['_REN_ERROR']);
  92. }
  93. }
  94. //
  95. tmplSetTitleBar($cfg["pagetitle"]." - ".$cfg['_REN_TITLE'], false);
  96. tmplSetIidVars();
  97. // parse template
  98. $tmpl->pparse();
  99. ?>