mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-10-28 16:42:30 +00:00
refactor code
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
VERSION=$(cat ./version.txt)
|
||||
docker build --progress=plain -t securitybunker/databunker:$VERSION .
|
||||
BUILDKIT_PROGRESS=plain docker build -t securitybunker/databunker:$VERSION .
|
||||
docker tag securitybunker/databunker:$VERSION securitybunker/databunker:latest
|
||||
|
||||
40
src/userlist_api.go
Normal file
40
src/userlist_api.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/securitybunker/databunker/src/utils"
|
||||
)
|
||||
|
||||
func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if e.EnforceAdmin(w, r, nil) == "" {
|
||||
return
|
||||
}
|
||||
if e.conf.Generic.ListUsers == false {
|
||||
utils.ReturnError(w, r, "access denied", 403, nil, nil)
|
||||
return
|
||||
}
|
||||
var offset int32 = 0
|
||||
var limit int32 = 10
|
||||
args := r.URL.Query()
|
||||
if value, ok := args["offset"]; ok {
|
||||
offset = utils.Atoi(value[0])
|
||||
}
|
||||
if value, ok := args["limit"]; ok {
|
||||
limit = utils.Atoi(value[0])
|
||||
}
|
||||
resultJSON, counter, _ := e.db.getUsers(offset, limit)
|
||||
log.Printf("Total count of events: %d\n", counter)
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(200)
|
||||
if counter == 0 {
|
||||
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":[]}`, counter)
|
||||
w.Write([]byte(str))
|
||||
} else {
|
||||
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, counter, resultJSON)
|
||||
w.Write([]byte(str))
|
||||
}
|
||||
}
|
||||
@@ -167,36 +167,6 @@ func (e mainEnv) userGet(w http.ResponseWriter, r *http.Request, ps httprouter.P
|
||||
w.Write([]byte(finalJSON))
|
||||
}
|
||||
|
||||
func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if e.EnforceAdmin(w, r, nil) == "" {
|
||||
return
|
||||
}
|
||||
if e.conf.Generic.ListUsers == false {
|
||||
utils.ReturnError(w, r, "access denied", 403, nil, nil)
|
||||
return
|
||||
}
|
||||
var offset int32 = 0
|
||||
var limit int32 = 10
|
||||
args := r.URL.Query()
|
||||
if value, ok := args["offset"]; ok {
|
||||
offset = utils.Atoi(value[0])
|
||||
}
|
||||
if value, ok := args["limit"]; ok {
|
||||
limit = utils.Atoi(value[0])
|
||||
}
|
||||
resultJSON, counter, _ := e.db.getUsers(offset, limit)
|
||||
log.Printf("Total count of events: %d\n", counter)
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(200)
|
||||
if counter == 0 {
|
||||
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":[]}`, counter)
|
||||
w.Write([]byte(str))
|
||||
} else {
|
||||
str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, counter, resultJSON)
|
||||
w.Write([]byte(str))
|
||||
}
|
||||
}
|
||||
|
||||
func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
identity := ps.ByName("identity")
|
||||
mode := ps.ByName("mode")
|
||||
|
||||
Reference in New Issue
Block a user