file_rename.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. James Rose <[email protected]>
  21. */
  22. //disable this feature
  23. exit;
  24. //includes files
  25. require_once dirname(__DIR__, 2) . "/resources/require.php";
  26. require_once "resources/check_auth.php";
  27. //check permissions
  28. if (!permission_exists('edit_save')) {
  29. echo "access denied";
  30. exit;
  31. }
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //set the variables
  36. $folder = $_REQUEST["folder"];
  37. //$folder = str_replace ("\\", "/", $folder);
  38. //if (substr($folder, -1) != "/") { $folder = $folder.'/'; }
  39. $new_file_name = $_REQUEST["new_file_name"];
  40. $fil_ename = $_REQUEST["filename"];
  41. //rename the file or show the html form
  42. if (strlen($folder) > 0 && strlen($newfilename) > 0) {
  43. //compare the tokens
  44. $key_name = '/app/edit/file_new';
  45. $hash = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]);
  46. if (!hash_equals($hash, $_POST['token'])) {
  47. echo "access denied";
  48. exit;
  49. }
  50. //rename the file
  51. //echo "new file: ".$newfilename."<br>";
  52. //echo "folder: ".$folder."<br>";
  53. //echo "orig filename: ".$file_name."<br>";;
  54. rename($folder.$file_name, $folder.$new_file_name);
  55. header("Location: file_options.php");
  56. }
  57. else {
  58. //create the token
  59. $key_name = '/app/edit/file_new';
  60. $_SESSION['keys'][$key_name] = bin2hex(random_bytes(32));
  61. $_SESSION['token'] = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]);
  62. //display the form
  63. require_once "header.php";
  64. echo "<br>";
  65. echo "<div align='left'>";
  66. echo "<form method='POST' action=''>";
  67. echo "<table>";
  68. echo " <tr>";
  69. echo " <td>".$text['label-path']."</td>";
  70. echo " </tr>";
  71. echo " <tr>";
  72. echo " <td>".escape($folder.$file_name)."</td>";
  73. echo " </tr>";
  74. echo " <tr>";
  75. echo " <td><br></td>";
  76. echo " </tr>";
  77. echo " <tr>";
  78. echo " <td>".$text['label-file-name-orig']."</td>";
  79. echo " </tr>";
  80. echo " <tr>";
  81. echo " <td>".escape($file_name)."</td>";
  82. echo " </tr>";
  83. echo "</table>";
  84. echo "<br />";
  85. echo "<table>";
  86. echo " <tr>";
  87. echo " <td>".$text['label-rename-file-to']."</td>";
  88. echo " </tr>";
  89. echo " <tr>";
  90. echo " <td><input type='text' name='newfilename' value=''></td>";
  91. echo " </tr>";
  92. echo " <tr>";
  93. echo " <td colspan='1' align='right'>";
  94. echo " <input type='hidden' name='folder' value='".escape($folder)."'>";
  95. echo " <input type='hidden' name='filename' value='".escape($file_name)."'>";
  96. echo " <input type='hidden' name='token' id='token' value='". $_SESSION['token']. "'>";
  97. echo " <input type='button' value='".$text['button-back']."' onclick='history.back()'><input type='submit' value='".$text['button-rename-file']."'>";
  98. echo " </td>";
  99. echo " </tr>";
  100. echo "</table>";
  101. echo "</form>";
  102. echo "</div>";
  103. require_once "footer.php";
  104. }