From 0dec060543e33be3fad29d6edc54bb98ad24b19d Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Mon, 8 Jul 2019 22:32:50 -0600 Subject: [PATCH] Update filenew.php --- app/edit/filenew.php | 135 +++++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 56 deletions(-) diff --git a/app/edit/filenew.php b/app/edit/filenew.php index 6f93a3a8c2..5b151ac2ae 100644 --- a/app/edit/filenew.php +++ b/app/edit/filenew.php @@ -17,78 +17,101 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2012 + Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane James Rose */ -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; -if (permission_exists('script_editor_save')) { - //access granted -} -else { - echo "access denied"; - exit; -} + +//includes + include "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('script_editor_save')) { + //access granted + } + else { + echo "access denied"; + exit; + } //add multi-lingual support $language = new text; $text = $language->get(); -$folder = $_GET["folder"]; -$folder = str_replace ("\\", "/", $folder); -if (substr($folder, -1) != "/") { $folder = $folder.'/'; } -$file = $_GET["file"]; +//handle the directory and file + $folder = $_REQUEST["folder"]; + $folder = str_replace ("\\", "/", $folder); + if (substr($folder, -1) != "/") { $folder = $folder.'/'; } + $file = $_REQUEST["file"]; -if (strlen($folder) > 0 && strlen($file) > 0) { - //create new file - $handle = fopen($folder.$file, 'wb') or die("Error!!"); - $content = ""; - fwrite($handle, $content); - fclose($handle); - header("Location: fileoptions.php"); -} -else { - require_once "header.php"; +//write the file or show the html form + if (strlen($folder) > 0 && strlen($file) > 0) { + //compare the tokens + $key_name = '/app/edit/file_new'; + $hash = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]); + if (!hash_equals($hash, $_POST['token'])) { + echo "access denied"; + exit; + } - echo "
"; - echo "
"; - echo "
"; - echo ""; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo "
Path:
".$folder.$file."
"; + //create new file + $handle = fopen($folder.$file, 'wb') or die("Error!!"); + $content = ""; + fwrite($handle, $content); + fclose($handle); + header("Location: fileoptions.php"); + } + else { - echo "
"; + //create a token + $key_name = '/app/edit/file_new'; + $_SESSION['keys'][$key_name] = bin2hex(random_bytes(32)); + $_SESSION['token'] = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]); - echo ""; - echo " "; - echo " "; - echo " "; + //include the header + require_once "header.php"; - echo " "; - echo " "; - echo " "; + //show the content + echo "
"; + echo "
"; + echo ""; + echo "
".$text['label-file-name']."
"; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo "
Path:
".$folder.$file."
"; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo ""; - echo "
"; - echo "
"; + echo "
"; - require_once "footer.php"; -} + echo ""; + echo " "; + echo " "; + echo " "; -?> \ No newline at end of file + echo " "; + echo " "; + echo " "; + + echo " "; + echo " "; + echo " "; + echo "
".$text['label-file-name']."
"; + echo " "; + echo " "; + echo " "; + echo "
"; + echo ""; + echo ""; + + require_once "footer.php"; + } + +?>