|
|
@ -17,25 +17,80 @@ |
|
|
|
package webuiapi |
|
|
|
package webuiapi |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
|
|
|
|
"path" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/mux" |
|
|
|
"github.com/gorilla/mux" |
|
|
|
|
|
|
|
"github.com/minio-io/minio/pkg/utils/config" |
|
|
|
|
|
|
|
"github.com/minio-io/minio/pkg/utils/crypto/keys" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
DEFAULT_WEB = "polygon" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type webUiApi struct { |
|
|
|
type webUiApi struct { |
|
|
|
|
|
|
|
conf config.Config |
|
|
|
|
|
|
|
webPath string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func HttpHandler() http.Handler { |
|
|
|
func HttpHandler() http.Handler { |
|
|
|
mux := mux.NewRouter() |
|
|
|
mux := mux.NewRouter() |
|
|
|
var api = webUiApi{} |
|
|
|
var api = webUiApi{} |
|
|
|
|
|
|
|
|
|
|
|
mux.StrictSlash(true) |
|
|
|
if err := api.conf.SetupConfig(); err != nil { |
|
|
|
mux.HandleFunc("/", api.homeHandler).Methods("GET") |
|
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api.webPath = path.Join(api.conf.GetConfigPath(), DEFAULT_WEB) |
|
|
|
|
|
|
|
mux.Handle("/{polygon:.*}", http.FileServer(http.Dir(api.webPath))).Methods("GET") |
|
|
|
|
|
|
|
mux.HandleFunc("/access", api.accessHandler).Methods("POST") |
|
|
|
return mux |
|
|
|
return mux |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (web *webUiApi) homeHandler(w http.ResponseWriter, req *http.Request) { |
|
|
|
func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) { |
|
|
|
w.Header().Set("Server", "Minio Management Console") |
|
|
|
var err error |
|
|
|
fmt.Fprintln(w, "Welcome!") |
|
|
|
var accesskey, secretkey []byte |
|
|
|
|
|
|
|
username := req.FormValue("username") |
|
|
|
|
|
|
|
if len(username) <= 0 { |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusBadRequest) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var user = config.User{} |
|
|
|
|
|
|
|
user.Name = username |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accesskey, err = keys.GetRandomAlphaNumeric(keys.MINIO_ACCESS_ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
|
|
|
w.Write([]byte(err.Error())) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
user.AccessKey = string(accesskey) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
secretkey, err = keys.GetRandomBase64(keys.MINIO_SECRET_ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
|
|
|
w.Write([]byte(err.Error())) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
user.SecretKey = string(secretkey) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web.conf.AddUser(user) |
|
|
|
|
|
|
|
err = web.conf.WriteConfig() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
|
|
|
w.Write([]byte(err.Error())) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = web.conf.ReadConfig() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|
|
|
|
|
w.Write([]byte(err.Error())) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.Println("Config:", web.conf.Users) |
|
|
|
} |
|
|
|
} |
|
|
|