diff --git a/assets/public/css/styles.css b/assets/public/css/styles.css index 530f6743..52d130ec 100644 --- a/assets/public/css/styles.css +++ b/assets/public/css/styles.css @@ -431,6 +431,23 @@ header form input { background-color: rgba(0, 0, 0, .1); } + +.floating { + position: fixed; + bottom: 1em; + right: 1em; +} + +.floating .action { + background-color: #68EFAD; + color: #306e50; + box-shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .12); +} + +#newfolder i { + transform: rotate(45deg); +} + /* LISTING */ #listing { diff --git a/assets/templates/base.tmpl b/assets/templates/base.tmpl index 40adb3a0..573ef4a1 100644 --- a/assets/templates/base.tmpl +++ b/assets/templates/base.tmpl @@ -1,106 +1,95 @@ - - {{.Name}} - - - - - - - - - - {{ if ne .Config.StyleSheet "" }} - - {{ end }} - - - -
-
- {{ $lnk := .PreviousLink }} - {{ if ne $lnk ""}} - - - - {{ else }} -
+ +{{ end }} - {{ if .IsDir }} -
-
-
- arrow_back -
-

- 0 - selected.

-
-
- {{ template "actions" . }} -
-
- {{ end }} - -
- {{ .Path }} - {{ template "content" .Data }} -
- - + + diff --git a/filemanager.go b/filemanager.go index 9007a39e..98218312 100644 --- a/filemanager.go +++ b/filemanager.go @@ -14,6 +14,7 @@ import ( a "github.com/hacdias/caddy-filemanager/internal/assets" "github.com/hacdias/caddy-filemanager/internal/config" "github.com/hacdias/caddy-filemanager/internal/file" + "github.com/hacdias/caddy-filemanager/internal/vcs" "github.com/mholt/caddy/caddyhttp/httpserver" ) @@ -79,7 +80,11 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err } // Search and git commands if r.Header.Get("Search") == "true" { - // TODO: search and git commands + // TODO: search commands + } + // VCS commands + if r.Header.Get("Command") != "" { + vcs.Handle(w, r, c) } // Creates a new folder // TODO: not implemented on frontend diff --git a/internal/config/config.go b/internal/config/config.go index d52eb6ed..331eeed6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,7 +15,7 @@ type Config struct { Root http.FileSystem BaseURL string StyleSheet string // Costum stylesheet - HugoEnabled bool // This must be only used by Hugo plugin + HugoEnabled bool // Enables the Hugo plugin for File Manager } // Parse parses the configuration set by the user so it can diff --git a/internal/git/git.go b/internal/git/git.go deleted file mode 100644 index 7c103be9..00000000 --- a/internal/git/git.go +++ /dev/null @@ -1,55 +0,0 @@ -package git - -import ( - "bytes" - "encoding/json" - "net/http" - "os/exec" - "strings" - - "github.com/hacdias/caddy-filemanager/internal/config" - "github.com/hacdias/caddy-filemanager/internal/page" -) - -// Handle handles the POST method on GIT page which is only an API. -func Handle(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) { - // Check if git is installed on the computer - if _, err := exec.LookPath("git"); err != nil { - return http.StatusNotImplemented, nil - } - - // Get the JSON information sent using a buffer - buff := new(bytes.Buffer) - buff.ReadFrom(r.Body) - - // Creates the raw file "map" using the JSON - var info map[string]interface{} - json.Unmarshal(buff.Bytes(), &info) - - // Check if command was sent - if _, ok := info["command"]; !ok { - return http.StatusBadRequest, nil - } - - command := info["command"].(string) - args := strings.Split(command, " ") - - if len(args) > 0 && args[0] == "git" { - args = append(args[:0], args[1:]...) - } - - if len(args) == 0 { - return http.StatusBadRequest, nil - } - - cmd := exec.Command("git", args...) - cmd.Dir = c.PathScope - output, err := cmd.CombinedOutput() - - if err != nil { - return http.StatusInternalServerError, err - } - - page := &page.Page{Info: &page.Info{Data: string(output)}} - return page.PrintAsJSON(w) -} diff --git a/internal/vcs/vcs.go b/internal/vcs/vcs.go new file mode 100644 index 00000000..a549e32a --- /dev/null +++ b/internal/vcs/vcs.go @@ -0,0 +1,36 @@ +package vcs + +import ( + "net/http" + "os/exec" + "strings" + + "github.com/hacdias/caddy-filemanager/internal/config" + "github.com/hacdias/caddy-filemanager/internal/page" +) + +// Handle handles the POST method on GIT page which is only an API. +func Handle(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) { + command := strings.Split(r.Header.Get("command"), " ") + + // Check if the command is for git, mercurial or svn + if command[0] != "git" && command[0] != "hg" && command[0] != "svn" { + return http.StatusForbidden, nil + } + + // Check if the program is talled is installed on the computer + if _, err := exec.LookPath(command[0]); err != nil { + return http.StatusNotImplemented, nil + } + + cmd := exec.Command(command[0], command[1:len(command)]...) + cmd.Dir = c.PathScope + output, err := cmd.CombinedOutput() + + if err != nil { + return http.StatusInternalServerError, err + } + + page := &page.Page{Info: &page.Info{Data: string(output)}} + return page.PrintAsJSON(w) +}