123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- package main
- import (
- "io/ioutil"
- "net/http"
- module "imuslab.com/arozos/mod/modules"
- )
- /*
- MODULE UTIL HANDLER
- This is a util module for doing basic registry works and < 20 line server side handling.
- DO NOT USE THIS TO WRITE A NEW MODULE
- >> Updates v1.112
- This util functions will be deprecated before v1.120.
- Please migrate all of the modules out as WebApps using agi interface
- */
- //Register the utilities here
- func util_init() {
- //PDF Viewer
- /*
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "PDF Reader",
- Desc: "The browser build in PDF Reader",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/pdfReader.png",
- Version: "1.2",
- SupportFW: false,
- SupportEmb: true,
- LaunchEmb: "SystemAO/utilities/pdfReader.html",
- InitEmbSize: []int{1080, 580},
- SupportedExt: []string{".pdf"},
- })
- */
- //Open Documents Viewer
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "OpenOffice Reader",
- Desc: "Open OpenOffice files",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/odfReader.png",
- Version: "0.8",
- SupportFW: false,
- SupportEmb: true,
- LaunchEmb: "SystemAO/utilities/odfReader.html",
- InitEmbSize: []int{1080, 580},
- SupportedExt: []string{".odt", ".odp", ".ods"},
- })
- /*
- Notebook - The build in basic text editor
- */
- //Open Documents Viewer
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "Notebook",
- Desc: "Basic Text Editor",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/notebook.png",
- Version: "1.0",
- SupportFW: false,
- SupportEmb: true,
- LaunchEmb: "SystemAO/utilities/notebook.html",
- InitEmbSize: []int{1080, 580},
- SupportedExt: []string{".txt", ".md"},
- })
- http.HandleFunc("/system/utils/notebook/save", system_util_handleNotebookSave)
- /*
- ArOZ Media Player - The basic video player
- */
- //Open Documents Viewer
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "ArOZ Media Player",
- Desc: "Basic Video Player",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/mediaPlayer.png",
- Version: "1.0",
- SupportFW: false,
- SupportEmb: true,
- LaunchEmb: "SystemAO/utilities/mediaPlayer.html",
- InitEmbSize: []int{720, 480},
- SupportedExt: []string{".mp4", ".webm", ".ogv"},
- })
- /*
- ArOZ Audio Player - Basic Audio File Player
- */
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "Audio Player",
- Desc: "Basic Audio Player",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/audio.png",
- Version: "1.0",
- SupportFW: false,
- SupportEmb: true,
- LaunchEmb: "SystemAO/utilities/audio.html",
- InitEmbSize: []int{600, 175},
- SupportedExt: []string{".mp3", ".wav", ".ogg", ".flac"},
- })
- /*
- STL File Viewer - Plotted from ArOZ Online Beta
- */
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "STL Viewer",
- Desc: "3D Model Viewer for STL Files",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/stlViewer.png",
- Version: "1.0",
- SupportFW: false,
- SupportEmb: true,
- LaunchEmb: "SystemAO/utilities/stlViewer.html",
- InitEmbSize: []int{720, 480},
- SupportedExt: []string{".stl"},
- })
- /*
- Gcode File Viewer - Plotted from ArOZ Online Beta
- */
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "Gcode Viewer",
- Desc: "Gcode Toolpath Viewer",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/gcodeViewer.png",
- Version: "1.0",
- SupportFW: false,
- SupportEmb: true,
- LaunchEmb: "SystemAO/utilities/gcodeViewer.html",
- InitEmbSize: []int{720, 480},
- SupportedExt: []string{".gcode", ".gco"},
- })
- /*
- Basic Timer
- */
- moduleHandler.RegisterModule(module.ModuleInfo{
- Name: "Timer",
- Desc: "Basic Timer Utility",
- Group: "Utilities",
- IconPath: "SystemAO/utilities/img/timer.png",
- StartDir: "SystemAO/utilities/timer.html",
- Version: "1.0",
- SupportFW: true,
- SupportEmb: false,
- LaunchFWDir: "SystemAO/utilities/timer.html",
- InitFWSize: []int{380, 190},
- })
- }
- /*
- Util functions
- Please put the functions in the space below
- */
- /*
- Notebook function handlers
- Handle save of new notebook text file
- */
- func system_util_handleNotebookSave(w http.ResponseWriter, r *http.Request) {
- username, err := authAgent.GetUserName(w, r)
- if err != nil {
- sendErrorResponse(w, "User not logged in")
- return
- }
- userinfo, _ := userHandler.GetUserInfoFromUsername(username)
- filepath, _ := mv(r, "filepath", true)
- newcontent, _ := mv(r, "content", true)
- if filepath == "" {
- sendErrorResponse(w, "Undefined filepath given.")
- return
- }
- //Check if user can write
- if !userinfo.CanWrite(filepath) {
- sendErrorResponse(w, "Write request denied")
- return
- }
- //Get real path of file
- realpath, _ := userinfo.VirtualPathToRealPath(filepath)
- //Check if file exists. If yes, remove its ownership and size allocation
- if fileExists(realpath) {
- userinfo.RemoveOwnershipFromFile(realpath)
- }
- if userinfo.StorageQuota.HaveSpace(int64(len(newcontent))) {
- //have space. Set this file to the owner's
- userinfo.RemoveOwnershipFromFile(realpath)
- } else {
- //Out of space. Add this file back to the user ownership
- userinfo.SetOwnerOfFile(realpath)
- sendErrorResponse(w, "Storage Quota Fulled")
- return
- }
- err = ioutil.WriteFile(realpath, []byte(newcontent), 0755)
- if err != nil {
- sendErrorResponse(w, err.Error())
- return
- }
- userinfo.SetOwnerOfFile(realpath)
- sendOK(w)
- }
|