File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -194,3 +194,17 @@ func GetContainersList() []string {
194194
195195 return names
196196}
197+
198+ func GetContainerImageNameByContainerID (containerID string ) string {
199+ body := string (makeSocketRequest ("containers/" + containerID + "/json" ))
200+ body = strings .Split (body , "\r \n \r \n " )[1 ]
201+ var result map [string ]any
202+ json .Unmarshal ([]byte (body ), & result )
203+
204+ if result ["Config" ] == nil {
205+ return ""
206+ }
207+
208+ imageName := fmt .Sprintf ("%v" , result ["Config" ].(map [string ]any )["Image" ])
209+ return imageName
210+ }
Original file line number Diff line number Diff line change @@ -713,9 +713,14 @@ func DeleteContainer(w http.ResponseWriter, req *http.Request) {
713713 decoder := json .NewDecoder (req .Body )
714714 decoder .Decode (& logItem )
715715
716- if (logItem .Host == "" || logItem .Host == util .GetHost ()) && strings .Contains (logItem .Service , "onlogs" ) {
717- w .WriteHeader (http .StatusForbidden )
718- json .NewEncoder (w ).Encode (map [string ]interface {}{"error" : "Can't delete myself!" })
716+ if logItem .Host == "" || logItem .Host == util .GetHost () {
717+ dockerContainerID := util .GetDockerContainerID (logItem .Host , logItem .Service )
718+ dockerImage := daemon .GetContainerImageNameByContainerID (dockerContainerID )
719+ if strings .Contains (dockerImage , "devforth/onlogs" ) {
720+ w .WriteHeader (http .StatusForbidden )
721+ json .NewEncoder (w ).Encode (map [string ]interface {}{"error" : "Can't delete logs of OnLogs container!" })
722+ return
723+ }
719724 }
720725
721726 go containerdb .DeleteContainer (logItem .Host , logItem .Service , true )
You can’t perform that action at this time.
0 commit comments