file_new.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. //access granted
  30. }
  31. else {
  32. echo "access denied";
  33. exit;
  34. }
  35. //add multi-lingual support
  36. $language = new text;
  37. $text = $language->get();
  38. //handle the directory and file
  39. $folder = $_REQUEST["folder"];
  40. $folder = str_replace ("\\", "/", $folder);
  41. if (substr($folder, -1) != "/") { $folder = $folder.'/'; }
  42. $file = $_REQUEST["file"];
  43. //write the file or show the html form
  44. if (strlen($folder) > 0 && strlen($file) > 0) {
  45. //compare the tokens
  46. $key_name = '/app/edit/file_new';
  47. $hash = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]);
  48. if (!hash_equals($hash, $_POST['token'])) {
  49. echo "access denied";
  50. exit;
  51. }
  52. //create new file
  53. $handle = fopen($folder.$file, 'wb') or die("Error!!");
  54. $content = "<?php\n\n?>";
  55. fwrite($handle, $content);
  56. fclose($handle);
  57. header("Location: file_options.php");
  58. }
  59. else {
  60. //create a token
  61. $key_name = '/app/edit/file_new';
  62. $_SESSION['keys'][$key_name] = bin2hex(random_bytes(32));
  63. $_SESSION['token'] = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]);
  64. //include the header
  65. require_once "header.php";
  66. //show the content
  67. echo "<br>";
  68. echo "<div align='left'>";
  69. echo "<form method='POST' action=''>";
  70. echo "<table>";
  71. echo " <tr>";
  72. echo " <td>Path:</td>";
  73. echo " </tr>";
  74. echo " <tr>";
  75. echo " <td>".$folder.$file."</td>";
  76. echo " </tr>";
  77. echo "</table>";
  78. echo "<br />";
  79. echo "<table>";
  80. echo " <tr>";
  81. echo " <td>".$text['label-file-name']."</td>";
  82. echo " </tr>";
  83. echo " <tr>";
  84. echo " <td><input type='text' name='file' value=''></td>";
  85. echo " </tr>";
  86. echo " <tr>";
  87. echo " <td colspan='1' align='right'>";
  88. echo " <input type='hidden' name='folder' value='$folder'>";
  89. echo " <input type='hidden' name='token' id='token' value='". $_SESSION['token']. "'>";
  90. echo " <input type='button' value='".$text['button-back']."' onclick='history.back()'><input type='submit' value='".$text['button-new-file']."'>";
  91. echo " </td>";
  92. echo " </tr>";
  93. echo "</table>";
  94. echo "</form>";
  95. echo "</div>";
  96. require_once "footer.php";
  97. }