- {{ if .IsDir}}
-
-
-
view_headline
+
+ arrow_back
+
+
0 selected.
-
- file_upload
-
- {{ else }}
+
{{ template "actions" . }}
- {{ end }}
+
+
+{{ end }}
- {{ if .Config.HugoEnabled }}
-
-
-
- settings
-
-
+
+{{ template "content" .Data }}
+
- {{ end }}
-
-
exit_to_app
+{{ if .IsDir }}
+
-
+
+{{ end }}
- {{ if .IsDir }}
-
- {{ 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)
+}