瀏覽代碼

Added csrf token requirement to file system new item API

TC pushbot 5 4 年之前
父節點
當前提交
157b5d3845

+ 7 - 0
file_system.go

@@ -956,6 +956,13 @@ func system_fs_handleNewObjects(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	//Validate the token
+	tokenValid := CSRFTokenManager.HandleTokenValidation(w, r)
+	if !tokenValid {
+		http.Error(w, "Invalid CSRF token", 401)
+		return
+	}
+
 	fileType, _ := mv(r, "type", true)     //File creation type, {file, folder}
 	vsrc, _ := mv(r, "src", true)          //Virtual file source folder, do not include filename
 	filename, _ := mv(r, "filename", true) //Filename for the new file

+ 2 - 2
web/FFmpeg Factory/backend/convert.js

@@ -36,7 +36,7 @@ if (filelib.fileExists(targetFilepath)){
     var actualCommand = decodeURIComponent(command);
     actualCommand = actualCommand.replace('{filepath}',srcReal);
     actualCommand = actualCommand.replace('{filename}',dir(srcReal) + "/" + base(srcReal))
-    
+
     //Register this task in on-going task list
     newDBTableIfNotExists("FFmpeg Factory")
     var ts = Math.round((new Date()).getTime() / 1000);
@@ -47,7 +47,7 @@ if (filelib.fileExists(targetFilepath)){
     var results = execpkg("ffmpeg",actualCommand);
 
     //Deregister this task from on-going task list
-
+    deleteDBItem("FFmpeg Factory",taskKey,targetFilepath);
 
     sendJSONResp(JSON.stringify({
         status: "ok",

+ 9 - 9
web/FFmpeg Factory/config/i2i.json

@@ -1,11 +1,11 @@
 {
-    "PNG(Default)": "-i \"{filepath}\" \"{filename}.png\"",
-    "PNG(High Quality)": "-i \"{filepath}\" -compression_level 0 \"{filename}.png\"",
-    "PNG(Low Quality)": "-i \"{filepath}\" -compression_level 200 \"{filename}.png\"",
-    "JPG(Default)": "-i \"{filepath}\" \"{filename}.jpg\"",
-    "JPG(High Quality)": "-i \"{filepath}\" -compression_level 0 \"{filename}.jpg\"",
-    "JPG(Low Quality)": "-i \"{filepath}\" -compression_level 200 \"{filename}.jpg\"",
-    "GIF": "-i \"{filepath}\" \"{filename}.gif\"",
-    "BMP": "-i \"{filepath}\" \"{filename}.bmp\"",
-    "TIF(TIFF)": "-i \"{filepath}\" \"{filename}.tif\""
+    "PNG(Default)": "-y -i \"{filepath}\" \"{filename}.png\"",
+    "PNG(High Quality)": "-y -i \"{filepath}\" -compression_level 0 \"{filename}.png\"",
+    "PNG(Low Quality)": "-y -i \"{filepath}\" -compression_level 200 \"{filename}.png\"",
+    "JPG(Default)": "-y -i \"{filepath}\" \"{filename}.jpg\"",
+    "JPG(High Quality)": "-y -i \"{filepath}\" -compression_level 0 \"{filename}.jpg\"",
+    "JPG(Low Quality)": "-y -i \"{filepath}\" -compression_level 200 \"{filename}.jpg\"",
+    "GIF": "-y -i \"{filepath}\" \"{filename}.gif\"",
+    "BMP": "-y -i \"{filepath}\" \"{filename}.bmp\"",
+    "TIF(TIFF)": "-y -i \"{filepath}\" \"{filename}.tif\""
 }

+ 4 - 4
web/FFmpeg Factory/config/other.json

@@ -1,6 +1,6 @@
 {
-	"MP4 to GIF": "-i \"{filepath}\" -f gif \"{filename}.gif\"",
-	"GIF to MP4": "-i \"{filepath}\" -f mp4 -pix_fmt yuv420p \"{filename}.mp4\"",
-	"SRT to ASS": "-i \"{filepath}\" \"{filename}.ass\"",
-	"ASS to SRT": "-i \"{filepath}\" -c:s srt \"{filename}.srt\""
+	"MP4 to GIF": "-y -i \"{filepath}\" -f gif \"{filename}.gif\"",
+	"GIF to MP4": "-y -i \"{filepath}\" -f mp4 -pix_fmt yuv420p \"{filename}.mp4\"",
+	"SRT to ASS": "-y -i \"{filepath}\" \"{filename}.ass\"",
+	"ASS to SRT": "-y -i \"{filepath}\" -c:s srt \"{filename}.srt\""
 }

+ 9 - 9
web/FFmpeg Factory/config/v2a.json

@@ -1,12 +1,12 @@
 {
-    "MP3(Default)": "-i \"{filepath}\" \"{filename}.mp3\"",
-    "MP3(320 Kbps)": "-i \"{filepath}\" -b:a 320k \"{filename}.mp3\"",
-    "MP3(256 Kbps)": "-i \"{filepath}\" -b:a 256k \"{filename}.mp3\"",
-    "MP3(192 Kbps)": "-i \"{filepath}\" -b:a 192k \"{filename}.mp3\"",
-    "MP3(128 Kbps)": "-i \"{filepath}\" -b:a 128k \"{filename}.mp3\"",
-    "AAC(Default)": "-i \"{filepath}\" -strict experimental \"{filename}.aac\"",
+    "MP3(Default)": "-y -i \"{filepath}\" \"{filename}.mp3\"",
+    "MP3(320 Kbps)": "-y -i \"{filepath}\" -b:a 320k \"{filename}.mp3\"",
+    "MP3(256 Kbps)": "-y -i \"{filepath}\" -b:a 256k \"{filename}.mp3\"",
+    "MP3(192 Kbps)": "-y -i \"{filepath}\" -b:a 192k \"{filename}.mp3\"",
+    "MP3(128 Kbps)": "-y -i \"{filepath}\" -b:a 128k \"{filename}.mp3\"",
+    "AAC(Default)": "-y -i \"{filepath}\" -strict experimental \"{filename}.aac\"",
     "AAC(codec copy)": "-i \"{filepath}\" -vn -acodec copy \"{filename}.aac\"",
-    "FLAC": "-i \"{filepath}\" \"{filename}.flac\"",
-    "OGG": "-i \"{filepath}\" \"{filename}.ogg\"",
-    "WAV": "-i \"{filepath}\" \"{filename}.wav\""
+    "FLAC": "-y -i \"{filepath}\" \"{filename}.flac\"",
+    "OGG": "-y -i \"{filepath}\" \"{filename}.ogg\"",
+    "WAV": "-y -i \"{filepath}\" \"{filename}.wav\""
 }

+ 14 - 14
web/FFmpeg Factory/config/v2v.json

@@ -1,16 +1,16 @@
 {
-    "MP4(Default)": "-i \"{filepath}\" \"{filename}.mp4\"",
-    "MP4(1080p)": "-i \"{filepath}\" -s hd1080 -c:v libx264 -crf 23 -c:a aac -strict -2 \"{filename}.mp4\"",
-    "MP4(720p)": "-i \"{filepath}\" -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 \"{filename}.mp4\"",
-    "MP4(480p)": "-i \"{filepath}\" -s hd480 -c:v libx264 -crf 23 -c:a aac -strict -2 \"{filename}.mp4\"",
-    "AVI(Default)": "-i \"{filepath}\" -q:v 2 \"{filename}.avi\"",
-    "AVI(Low Quality)": "-i \"{filepath}\" -q:v 6 \"{filename}.avi\"",
-    "AVI(High Quality)": "-i \"{filepath}\" -q:v 0 \"{filename}.avi\"",
-    "AVI(codec copy)": "-i \"{filepath}\" -vcodec copy -acodec copy \"{filename}.avi\"",
-    "WebM": "-i \"{filepath}\" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis \"{filename}.webm\"",
-    "WMV": "-i \"{filepath}\" \"{filename}.wmv\"",
-    "FLV": "-i \"{filepath}\" \"{filename}.flv\"",
-    "MKV(Default)": "-i \"{filepath}\" \"{filename}.mkv\"",
-    "MKV(codec copy)": "-i \"{filepath}\" -vcodec copy -acodec copy \"{filename}.mkv\"",
-    "MOV": "-i \"{filepath}\" \"{filename}.mov\""
+    "MP4(Default)": "-y -i \"{filepath}\" \"{filename}.mp4\"",
+    "MP4(1080p)": "-y -i \"{filepath}\" -s hd1080 -c:v libx264 -crf 23 -c:a aac -strict -2 \"{filename}.mp4\"",
+    "MP4(720p)": "-y -i \"{filepath}\" -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 \"{filename}.mp4\"",
+    "MP4(480p)": "-y -i \"{filepath}\" -s hd480 -c:v libx264 -crf 23 -c:a aac -strict -2 \"{filename}.mp4\"",
+    "AVI(Default)": "-y -i \"{filepath}\" -q:v 2 \"{filename}.avi\"",
+    "AVI(Low Quality)": "-y -i \"{filepath}\" -q:v 6 \"{filename}.avi\"",
+    "AVI(High Quality)": "-y -i \"{filepath}\" -q:v 0 \"{filename}.avi\"",
+    "AVI(codec copy)": "-y -i \"{filepath}\" -vcodec copy -acodec copy \"{filename}.avi\"",
+    "WebM": "-y -i \"{filepath}\" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis \"{filename}.webm\"",
+    "WMV": "-y -i \"{filepath}\" \"{filename}.wmv\"",
+    "FLV": "-y -i \"{filepath}\" \"{filename}.flv\"",
+    "MKV(Default)": "-y -i \"{filepath}\" \"{filename}.mkv\"",
+    "MKV(codec copy)": "-y -i \"{filepath}\" -vcodec copy -acodec copy \"{filename}.mkv\"",
+    "MOV": "-y -i \"{filepath}\" \"{filename}.mov\""
 }

+ 68 - 58
web/SystemAO/file_system/file_explorer.html

@@ -2950,35 +2950,21 @@
                 $("#createNewFileName").parent().removeClass("error");
                 //Update the newfile list
                 $("#newFile").find(".newfilelist").html("");
-                $.ajax({
-                    url: "../../system/file_system/newItem",
-                    success: function(data){
-                        if (data.error !== undefined){
-                            return;
-                        }
-                        for (var i =0; i < data.length; i++){
-                            var desc = data[i].Desc;
-                            var ext = data[i].Ext;
-                            var icon = ao_module_utils.getIconFromExt(ext);
-                            $("#newFile").find(".newfilelist").append(`<div class="item newFileFormat" ext="${ext}"><i class="${icon} icon" style="margin-right:12px;"></i> ${desc}</div>`);
-                        }
-                        //Initialize the new file as txt
-                        var filename = "newfile";
-                        var finalFilename = filename; 
-                        var i = 0;
-                        while (currentFilelist.includes(finalFilename)){
-                            finalFilename = finalFilename + "(" + i + ")";
-                            i++;
-                        }  
-                        $("#createNewFileName").val(finalFilename + ".txt");
-
-                        //Hook events for on click
-                        $(".newFileFormat").off("click").on("click",function(data){
-                            $(".newFileFormat").removeClass("selected");
-                            $(this).addClass("selected");
-
-                            //Parse the newfilename
-                            var selectedExt = $(this).attr("ext");
+                requestCSRFToken(function(token){
+                    $.ajax({
+                        url: "../../system/file_system/newItem",
+                        data: {csrft: token},
+                        success: function(data){
+                            if (data.error !== undefined){
+                                return;
+                            }
+                            for (var i =0; i < data.length; i++){
+                                var desc = data[i].Desc;
+                                var ext = data[i].Ext;
+                                var icon = ao_module_utils.getIconFromExt(ext);
+                                $("#newFile").find(".newfilelist").append(`<div class="item newFileFormat" ext="${ext}"><i class="${icon} icon" style="margin-right:12px;"></i> ${desc}</div>`);
+                            }
+                            //Initialize the new file as txt
                             var filename = "newfile";
                             var finalFilename = filename; 
                             var i = 0;
@@ -2986,9 +2972,26 @@
                                 finalFilename = finalFilename + "(" + i + ")";
                                 i++;
                             }  
-                            $("#createNewFileName").val(filename + "." + selectedExt);
-                        });
-                    }
+                            $("#createNewFileName").val(finalFilename + ".txt");
+
+                            //Hook events for on click
+                            $(".newFileFormat").off("click").on("click",function(data){
+                                $(".newFileFormat").removeClass("selected");
+                                $(this).addClass("selected");
+
+                                //Parse the newfilename
+                                var selectedExt = $(this).attr("ext");
+                                var filename = "newfile";
+                                var finalFilename = filename; 
+                                var i = 0;
+                                while (currentFilelist.includes(finalFilename)){
+                                    finalFilename = finalFilename + "(" + i + ")";
+                                    i++;
+                                }  
+                                $("#createNewFileName").val(filename + "." + selectedExt);
+                            });
+                        }
+                    });
                 });
             }
 
@@ -3039,27 +3042,31 @@
                     //OK to proceed.
                     $("#createNewFolder").parent().removeClass("error").addClass("success");
                     $("#newFolder").find(".duplicateWarning").hide();
-                    $.ajax({
-                        url: "../../system/file_system/newItem",
-                        data: {type: "folder", src: currentPath, filename: newFoldername},
-                        success: function(data){
-                            if (data.error !== undefined){
-                                msgbox("remove", data.error);
-                            }else{
-                                msgbox("checkmark","New folder created.");
-                                refreshList();
-                            }
-                            $("#newFolder").fadeOut('fast');
-                            hideAllPopupWindows();
-                            if (currentPath == "user:/"){
-                                //Reload the User root folder list
-                                initRootDirs();
+                    requestCSRFToken(function(token){
+                        $.ajax({
+                            url: "../../system/file_system/newItem",
+                            data: {type: "folder", src: currentPath, filename: newFoldername, csrft: token},
+                            success: function(data){
+                                if (data.error !== undefined){
+                                    msgbox("remove", data.error);
+                                }else{
+                                    msgbox("checkmark","New folder created.");
+                                    refreshList();
+                                }
+                                $("#newFolder").fadeOut('fast');
+                                hideAllPopupWindows();
+                                if (currentPath == "user:/"){
+                                    //Reload the User root folder list
+                                    initRootDirs();
+                                }
                             }
-                        }
+                        });
                     });
+                    
                 }
             }
 
+
             function confirmNewFile(){
                 var filename = $("#createNewFileName").val();
                 if (filename == ""){
@@ -3074,18 +3081,21 @@
                 }
                 $("#createNewFileName").parent().removeClass("error");
                 //Ok to proceed
-                $.ajax({
-                    url: "../../system/file_system/newItem",
-                    data: {type: "file", src: currentPath, filename:filename},
-                    success: function(data){
-                        if (data.error !== undefined){
-                            msgbox("remove",data.error);
-                        }else{
-                            msgbox("checkmark",filename + " created.");
-                            refreshList();
+                requestCSRFToken(function(token){
+                    $.ajax({
+                        url: "../../system/file_system/newItem",
+                        data: {type: "file", src: currentPath, filename:filename,csrft: token},
+                        success: function(data){
+                            if (data.error !== undefined){
+                                msgbox("remove",data.error);
+                            }else{
+                                msgbox("checkmark",filename + " created.");
+                                refreshList();
+                            }
                         }
-                    }
+                    });
                 });
+                
                 hideAllPopupWindows();
                 $("#newFile").fadeOut('fast');
             }

+ 77 - 3
web/SystemAO/file_system/file_selector.html

@@ -72,9 +72,10 @@
     <body>
         <div class="navi">
             <button id="sidebarToggleBtn" class="ts icon tiny button" onclick="ts('.sidebar').sidebar('toggle');"><i class="content icon"></i></button>
-            <button class="ts icon tiny button" onclick="backDir();"><i class="arrow left icon"></i></button>
-            <button class="ts icon tiny button" onclick="parentDir();"><i class="arrow up icon"></i></button>
-            <button class="ts icon tiny button" onclick="refresh();"><i class="refresh icon"></i></button>
+            <button title="Back" class="ts icon tiny button" onclick="backDir();"><i class="arrow left icon"></i></button>
+            <button title="Parent" class="ts icon tiny button" onclick="parentDir();"><i class="arrow up icon"></i></button>
+            <button title="Refresh" class="ts icon tiny button" onclick="refresh();"><i class="refresh icon"></i></button>
+            <button title="New Folder" class="ts icon tiny button" onclick="newFolder();"><i class="folder icon"></i></button>
             <div  class="ts action fluid tiny input" style="width: calc(100% - 180px); float: right;">
                 <input id="addressbar" type="text" placeholder="" onchange="updatePath();">
                 <button class="ts positive icon button" onclick="confirmSelection();"><i class="checkmark icon"></i></button>
@@ -85,6 +86,13 @@
                     <input id="filename" type="text" placeholder="New Filename">
                 </div>
             </div>
+
+            <div id="newFolderInput" style="width:100%; margin-top:12px; display:none;" align="right">
+                <div  class="ts fluid action tiny input" style="width: calc(100% - 180px); float: right;">
+                    <input id="foldername" type="text" placeholder="New Folder" value="">
+                    <button class="ts icon button" onclick="createFolder()"><i class="add icon"></i></button>
+                </div>
+            </div>
         </div>
         <div id="sidebar" class="ts left static visible overlapped sidebar" style="background-color:#f5f5f5 !important;z-index:90 !important; width:200px;">
             <div id="sidebarPadder" style="height:46px;"></div>
@@ -130,6 +138,7 @@
             var multiSelect = false;
             var type = "file";
             var currentDir = "user:/";
+            var currentFileList = [];
             var pathHistory = [];
             var ctrlDown = false;
             var shiftDown = false;
@@ -266,6 +275,61 @@
                 listDir(currentDir);
             }
 
+            function newFolder(){
+                $("#newFolderInput").toggle();
+                if($("#newFolderInput").is(":visible")){
+                    $("#sidebarPadder").css("height", "90px");
+                    $(".fileListWrapper").css("padding-top", "50px");
+                }else{
+                    $("#sidebarPadder").css("height", "46px");
+                    $(".fileListWrapper").css("padding-top", "0px");
+                }
+            }
+
+            function hideFolderNameInput(){
+                $("#newFolderInput").hide();
+                $("#sidebarPadder").css("height", "46px");
+                $(".fileListWrapper").css("padding-top", "0px");
+            }
+
+            function createFolder(){
+                var folderName = $("#foldername").val();
+                if (folderName == ""){
+                    folderName = "New Folder"
+                    $("#foldername").val("New Folder");
+                }
+                folderName = folderName.replace(/[<>:"/\\|?*]/g, "_");
+                
+                //Check if folder exists
+                var nameAlreadyExists = false;
+                currentFileList.forEach(fileObject => {
+                    if (fileObject.IsDir && fileObject.Filename == folderName){
+                        nameAlreadyExists = true;   
+                    }
+                });
+
+                if (nameAlreadyExists){
+                    alert("Folder already exists")
+                    return
+                }
+
+                //Create the new folder request
+                requestCSRFToken(function(token){
+                    $.ajax({
+                        url: "../../system/file_system/newItem",
+                        data: {type: "folder", src: currentDir, filename: folderName, csrft: token},
+                        success: function(data){
+                            if (data.error !== undefined){
+                                alert(data.error);
+                            }else{
+                                refresh()
+                            }
+                            hideFolderNameInput();
+                        }
+                    });
+                });
+            }
+
             function loadSelectorInfoFromHash(){
                 if (window.location.hash.length == 0){
                     return {
@@ -309,6 +373,7 @@
                         //Load the index instead
                         listDir("user:/");
                     }else{
+                        currentFileList = data;
                         var folders = [];
                         var files = [];
                         for (var i =0; i < data.length; i++){
@@ -375,6 +440,15 @@
                 });
             }
 
+            function requestCSRFToken(callback){
+                $.ajax({
+                    url: "../../system/csrf/new",
+                    success: function(token){
+                        callback(token);
+                    }
+                })
+            }
+
             //Open folder
             function openFolder(event, object){
                 event.preventDefault();

+ 10 - 7
web/SystemAO/file_system/newFolder.html

@@ -96,14 +96,17 @@
             function createFolder(){
                 var foldername = $("#fname").val().trim();
                 //Create a folder via file system api
-                $.post("../../system/file_system/newItem",{type: "folder", src: vsrc, filename: foldername}).done(function(data){
-                    if (data.error !== undefined){
-                        console.log(data.error);
-                    }else{
-                        parent.refresh();
-                        ao_module_close();
-                    }
+                requestCSRFToken(function(token){
+                    $.post("../../system/file_system/newItem",{type: "folder", src: vsrc, filename: foldername, csrft: token}).done(function(data){
+                        if (data.error !== undefined){
+                            console.log(data.error);
+                        }else{
+                            parent.refresh();
+                            ao_module_close();
+                        }
+                    });
                 });
+                
             }
 
         </script>

+ 38 - 30
web/desktop.system

@@ -4827,26 +4827,29 @@
             }
 
             //Create the folder
-            $.post("system/file_system/newItem", {
-                type: "folder",
-                src: "user:/Desktop/",
-                filename: newFolderName
-            }).done(function(data) {
-                if (data.error !== undefined) {
-                    console.log(data.error);
-                } else {
-                    if (createObjectLocation) {
-                        setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
-                            //After set Desktop icon, refresh the page 
-                            refresh(function() {
-                                //After refresh the page, highlight the new folder and set it to rename mode
-                                var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
-                                console.log(targetFolderObject);
-                                enableRenameOnLaunchIconObject(targetFolderObject);
+            requestCSRFToken(function(token){
+                $.post("system/file_system/newItem", {
+                    type: "folder",
+                    src: "user:/Desktop/",
+                    filename: newFolderName,
+                    csrft: token
+                }).done(function(data) {
+                    if (data.error !== undefined) {
+                        alert(data.error);
+                    } else {
+                        if (createObjectLocation) {
+                            setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
+                                //After set Desktop icon, refresh the page 
+                                refresh(function() {
+                                    //After refresh the page, highlight the new folder and set it to rename mode
+                                    var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
+                                    console.log(targetFolderObject);
+                                    enableRenameOnLaunchIconObject(targetFolderObject);
+                                });
                             });
-                        });
+                        }
                     }
-                }
+                });
             });
 
             /*
@@ -4942,6 +4945,7 @@
                                     success: function(data){
                                         if (data.error !== undefined){
                                             //Cancel the operation
+                                            alert(data.error);
                                             console.log("*ERROR* " + data.error);
                                             currentInputTextArea.remove();
                                         }else{
@@ -5042,17 +5046,21 @@
             addContextMenuItem($("#subcontextmenu"), 'Folder', "<i class='folder icon'></i>", "newfolder", true);
             addContextMenuItem($("#subcontextmenu"), 'Shortcut', "<i class='external icon'></i>", "newshortcut", true);
             addContextMenuSeperator($("#subcontextmenu"));
-            $.get("system/file_system/newItem", function(data) {
-                for (var i = 0; i < data.length; i++) {
-                    var thisNewFile = data[i];
-                    var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
-                    addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
-                }
-                //Show sub-context menu
-                showSubContextMenu(target);
+            requestCSRFToken(function(token){
+                $.ajax({
+                    url: "system/file_system/newItem",
+                    data: {csrft: token},
+                    success: function(data){
+                        for (var i = 0; i < data.length; i++) {
+                            var thisNewFile = data[i];
+                            var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
+                            addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
+                        }
+                        //Show sub-context menu
+                        showSubContextMenu(target);
+                    }
+                })
             });
-
-            
         }
 
         function showSubContextMenu(target) {
@@ -5089,7 +5097,7 @@
             //Request backend to generate the new file
             $.ajax({
                 url: "system/file_system/newItem",
-                data: {type: "file",src: "user:/Desktop/",filename: newfn},
+                data: {type: "file",src: "user:/Desktop/",filename: newfn, csrft: token},
                 success: function(data){
                     if (data.error !== undefined){
                         alert(data.error);
@@ -5793,7 +5801,7 @@
                     desktopFileHash = hash;
                 }else if (desktopFileHash != hash){
                     //Changed on desktop files. Refresh
-                    refresh();
+                    refresh(undefined, true);
                     desktopFileHash = hash;
                 }