|
@@ -13,6 +13,8 @@ import (
|
|
|
|
|
|
"imuslab.com/arozos/mod/common"
|
|
|
fs "imuslab.com/arozos/mod/filesystem"
|
|
|
+ "imuslab.com/arozos/mod/filesystem/arozfs"
|
|
|
+ "imuslab.com/arozos/mod/filesystem/shortcut"
|
|
|
module "imuslab.com/arozos/mod/modules"
|
|
|
prout "imuslab.com/arozos/mod/prouter"
|
|
|
)
|
|
@@ -610,16 +612,13 @@ func desktop_preference_handler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
func desktop_shortcutHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
- username, err := authAgent.GetUserName(w, r)
|
|
|
-
|
|
|
+ userinfo, err := userHandler.GetUserInfoFromRequest(w, r)
|
|
|
if err != nil {
|
|
|
//user not logged in. Redirect to login page.
|
|
|
common.SendErrorResponse(w, "User not logged in")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- userinfo, _ := userHandler.GetUserInfoFromUsername(username)
|
|
|
-
|
|
|
shortcutType, err := common.Mv(r, "stype", true)
|
|
|
if err != nil {
|
|
|
common.SendErrorResponse(w, err.Error())
|
|
@@ -644,31 +643,50 @@ func desktop_shortcutHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //OK to proceed. Generate a shortcut on the user desktop
|
|
|
- fsh, subpath, _ := GetFSHandlerSubpathFromVpath("user:/Desktop/")
|
|
|
- fshAbs := fsh.FileSystemAbstraction
|
|
|
+ shortcutCreationDest, err := common.Mv(r, "sdest", true)
|
|
|
+ if err != nil {
|
|
|
+ //Default create on desktop
|
|
|
+ shortcutCreationDest = "user:/Desktop/"
|
|
|
+ }
|
|
|
+
|
|
|
+ if !userinfo.CanWrite(shortcutCreationDest) {
|
|
|
+ common.SendErrorResponse(w, "Permission denied")
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- userDesktopPath, _ := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
|
|
|
- if !fs.FileExists(userDesktopPath) {
|
|
|
- os.MkdirAll(userDesktopPath, 0755)
|
|
|
+ //Resolve vpath to fsh and subpath
|
|
|
+ fsh, subpath, err := GetFSHandlerSubpathFromVpath(shortcutCreationDest)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
+ fshAbs := fsh.FileSystemAbstraction
|
|
|
|
|
|
- //Check if there are desktop icon. If yes, override icon on module
|
|
|
- if shortcutType == "module" && fs.FileExists("./web/"+filepath.ToSlash(filepath.Dir(shortcutIcon)+"/desktop_icon.png")) {
|
|
|
- shortcutIcon = filepath.ToSlash(filepath.Join(filepath.Dir(shortcutIcon), "/desktop_icon.png"))
|
|
|
+ shorcutRealDest, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
|
|
|
+ if err != nil {
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- shortcutText = strings.ReplaceAll(shortcutText, "/", "")
|
|
|
- for strings.Contains(shortcutText, "../") {
|
|
|
- shortcutText = strings.ReplaceAll(shortcutText, "../", "")
|
|
|
+ //Filter illegal characters in the shortcut filename
|
|
|
+ shortcutText = arozfs.FilterIllegalCharInFilename(shortcutText, " ")
|
|
|
+
|
|
|
+ //If dest not exists, create it
|
|
|
+ if !fshAbs.FileExists(shorcutRealDest) {
|
|
|
+ fshAbs.MkdirAll(shorcutRealDest, 0755)
|
|
|
}
|
|
|
- shortcutFilename := userDesktopPath + "/" + shortcutText + ".shortcut"
|
|
|
+
|
|
|
+ //Generate a filename for the shortcut
|
|
|
+ shortcutFilename := shorcutRealDest + "/" + shortcutText + ".shortcut"
|
|
|
counter := 1
|
|
|
- for fs.FileExists(shortcutFilename) {
|
|
|
- shortcutFilename = userDesktopPath + "/" + shortcutText + "(" + strconv.Itoa(counter) + ")" + ".shortcut"
|
|
|
+ for fshAbs.FileExists(shortcutFilename) {
|
|
|
+ shortcutFilename = shorcutRealDest + "/" + shortcutText + "(" + strconv.Itoa(counter) + ")" + ".shortcut"
|
|
|
counter++
|
|
|
}
|
|
|
- err = ioutil.WriteFile(shortcutFilename, []byte(shortcutType+"\n"+shortcutText+"\n"+shortcutPath+"\n"+shortcutIcon), 0755)
|
|
|
+
|
|
|
+ //Write the shortcut to file
|
|
|
+ shortcutContent := shortcut.GenerateShortcutBytes(shortcutPath, shortcutType, shortcutText, shortcutIcon)
|
|
|
+ err = fshAbs.WriteFile(shortcutFilename, shortcutContent, 0775)
|
|
|
if err != nil {
|
|
|
common.SendErrorResponse(w, err.Error())
|
|
|
return
|