feat(web): mask real file paths when working with TFM database

This commit is contained in:
Masahiko AMANO 2023-01-28 21:51:56 +03:00
parent 94b55c8a87
commit f5eb8dac06

View File

@ -11,15 +11,17 @@ import (
"os" "os"
"path" "path"
"strconv" "strconv"
"strings"
"time" "time"
) )
type JSON struct { type JSON struct {
Status bool `json:"status,omitempty"` Status bool `json:"status"`
Token string `json:"token,omitempty"` Token string `json:"token,omitempty"`
TRC uint8 `json:"trc,omitempty"` TRC uint8 `json:"trc,omitempty"`
TRDB string `json:"trdb,omitempty"` TRDB string `json:"trdb,omitempty"`
TRB string `json:"trb,omitempty"` TRB string `json:"trb,omitempty"`
Data []map[string]interface{} `json:"data,omitempty"`
} }
var tdbms TDBMSConnection var tdbms TDBMSConnection
@ -128,6 +130,19 @@ func HandlerTDBMS(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Failed to execute request", http.StatusInternalServerError) http.Error(w, "Failed to execute request", http.StatusInternalServerError)
return return
} }
if request.TRDB == "$TFM" && (request.TRC == 0b10000 || request.TRC == 0b101000) {
var json_response JSON
err = json.Unmarshal(response, &json_response)
if err != nil {
http.Error(w, "TDBMS error", http.StatusInternalServerError)
return
}
for index, element := range json_response.Data {
json_response.Data[index]["path"] =
strings.ReplaceAll(element["path"].(string), "/srv/data/tfm/", "")
}
response, err = json.Marshal(json_response)
}
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
_, err = w.Write(response) _, err = w.Write(response)
if err != nil { if err != nil {