diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-04-25 13:23:37 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-04-25 13:23:37 -0700 |
commit | 099d000119447708d7d0d0482758d352438fa7e5 (patch) | |
tree | f4386ae2ff25a5b6b15c2e6442d4c56705e8271e /system/system.go | |
parent | 7092fb8979869f3c09b364d454d8d8081bb7c0bc (diff) |
adding support for file upload type and API handler to fetch file info
Diffstat (limited to 'system/system.go')
-rw-r--r-- | system/system.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/system/system.go b/system/system.go new file mode 100644 index 0000000..8b12ab5 --- /dev/null +++ b/system/system.go @@ -0,0 +1,37 @@ +// Package system contains a collection of packages that make up the internal +// Ponzu system, which handles addons, administration, the Admin server, the API +// server, analytics, databases, search, TLS, and various internal types. +package system + +import ( + "net/http" + + "github.com/ponzu-cms/ponzu/system/db" +) + +// BasicAuth adds HTTP Basic Auth check for requests that should implement it +func BasicAuth(next http.HandlerFunc) http.HandlerFunc { + return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + u := db.ConfigCache("backup_basic_auth_user").(string) + p := db.ConfigCache("backup_basic_auth_password").(string) + + if u == "" || p == "" { + res.WriteHeader(http.StatusForbidden) + return + } + + user, password, ok := req.BasicAuth() + + if !ok { + res.WriteHeader(http.StatusForbidden) + return + } + + if u != user || p != password { + res.WriteHeader(http.StatusUnauthorized) + return + } + + next.ServeHTTP(res, req) + }) +} |