Update filesave.php

This commit is contained in:
FusionPBX
2019-07-08 22:37:37 -06:00
committed by GitHub
parent ae299d00f5
commit e91ca958a4
+39 -26
View File
@@ -17,54 +17,67 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
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. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
James Rose <james.o.rose@gmail.com> James Rose <james.o.rose@gmail.com>
*/ */
include "root.php";
require_once "resources/require.php"; //includes
require_once "resources/check_auth.php"; include "root.php";
if (permission_exists('script_editor_save')) { require_once "resources/require.php";
//access granted require_once "resources/check_auth.php";
}
else { //check permissions
echo "access denied"; if (permission_exists('script_editor_save')) {
exit; //access granted
} }
else {
echo "access denied";
exit;
}
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
$filepath = $_POST["filepath"]; //compare the tokens
if ($filepath != '') { $key_name = '/app/edit/'.$_POST['mode'];
$hash = hash_hmac('sha256', $key_name, $_SESSION['keys'][$key_name]);
if (!hash_equals($hash, $_POST['token'])) {
echo "access denied";
exit;
}
//run the code if file path exists
$file_path = $_POST["filepath"];
if ($file_path != '') {
try { try {
//save file content //save file content
$filepath = realpath($filepath); //filepath $file_path = realpath($file_path);
$filepath = str_replace ('//', '/', $filepath); $file_path = str_replace ('//', '/', $file_path);
$filepath = str_replace ("\\", "/", $filepath); $file_path = str_replace ("\\", "/", $file_path);
$content = $_POST["content"]; if (file_exists($file_path)) {
$handle = fopen($file_path, 'wb');
$handle = fopen($filepath, 'wb'); if (!$handle) {
if (!$handle) { throw new Exception('Write Failed - Check File Owner & Permissions');
throw new Exception('Write Failed - Check File Owner & Permissions'); }
fwrite($handle, $_POST["content"]);
fclose($handle);
} }
fwrite($handle, $content);
fclose($handle);
//set the reload_xml value to true //set the reload_xml value to true
$_SESSION["reload_xml"] = true; $_SESSION["reload_xml"] = true;
//alert user of success //alert user of success
echo "<script>alert('Changes Saved'); parent.focus_editor();</script>"; echo "Changes Saved";
} }
catch(Exception $e) { catch(Exception $e) {
//alert error //alert error
echo "<script>alert('".$e->getMessage()."'); parent.focus_editor();</script>"; echo $e->getMessage();
} }
} }