Skip to content

Commit

Permalink
新增镜像删除功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxxbxxxxx committed Jul 1, 2020
1 parent a69f326 commit 70b3ed5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 16 deletions.
6 changes: 5 additions & 1 deletion vulfocus-api/dockerapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Meta:
class ContainerVulSerializer(serializers.ModelSerializer):
rank = serializers.SerializerMethodField('ranktocon')
name = serializers.SerializerMethodField('conname')
image_id = serializers.SerializerMethodField("get_image_id")
user_name = serializers.SerializerMethodField('get_user_name')
vul_name = serializers.SerializerMethodField('get_vul_name')
vul_desc = serializers.SerializerMethodField('get_vul_desc')
Expand All @@ -112,7 +113,7 @@ class ContainerVulSerializer(serializers.ModelSerializer):
class Meta:
model = ContainerVul
fields = ['name', 'container_id', 'container_status', 'vul_host', 'create_date', 'is_check', 'is_check_date',
'rank', 'user_name', 'vul_name', 'vul_desc']
'rank', 'user_name', 'vul_name', 'vul_desc', "image_id"]

def get_vul_name(self,obj):
return obj.image_id.image_vul_name
Expand Down Expand Up @@ -140,6 +141,9 @@ def get_user_name(self, obj):
user_info = UserProfile.objects.get(id=user_id)
return user_info.username

def get_image_id(self, obj):
return str(obj.image_id.image_id)


class SysLogSerializer(serializers.ModelSerializer):

Expand Down
4 changes: 3 additions & 1 deletion vulfocus-api/dockerapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,13 @@ def delete_image(self, request, pk=None):
sys_log.save()
image_id = img_info.image_id
container_vul = ContainerVul.objects.filter(image_id=image_id)
data_json = ContainerVulSerializer(container_vul, many=True)
print(data_json.data)
if container_vul.count() == 0:
img_info.delete()
return JsonResponse(R.ok())
else:
return JsonResponse(R.build(msg="镜像正在使用,无法删除!"))
return JsonResponse(R.build(msg="镜像正在使用,无法删除!", data=data_json.data))

@action(methods=["post", "get"], detail=True, url_path="start")
def start_container(self, request, pk=None):
Expand Down
4 changes: 2 additions & 2 deletions vulfocus-frontend/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ENV = 'development'

# base api
#VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://127.0.0.1:8000'
#VUE_APP_BASE_API = 'http://10.10.10.172:8000'
#VUE_APP_BASE_API = 'http://127.0.0.1:8000'
VUE_APP_BASE_API = 'http://10.10.10.172:8000'
# vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable,
# to control whether the babel-plugin-dynamic-import-node plugin is enabled.
# It only does one thing by converting all import() to require().
Expand Down
82 changes: 70 additions & 12 deletions vulfocus-frontend/src/views/image/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@
</el-row>
</div>
</el-dialog>
<el-dialog :visible.sync="deleteShow" title="删除" width="80%">
<el-table
:data="deleteContainerList" border stripe style="width: 100%">
<el-table-column type="index" width="50"></el-table-column>
<el-table-column prop="vul_name" width="150" :show-overflow-tooltip=true label="漏洞名称"></el-table-column>
<el-table-column :show-overflow-tooltip=true prop="user_name" width="100" label="用户名"></el-table-column>
<el-table-column prop="vul_host" width="200" :show-overflow-tooltip=true label="访问地址"></el-table-column>
<el-table-column label="状态" width="85">
<template slot-scope="{row}">
<el-tag>{{row.container_status}}</el-tag>
</template>
</el-table-column>
<el-table-column prop="vul_desc" :show-overflow-tooltip=true width="300" label="漏洞描述"></el-table-column>
<el-table-column prop="combination_desc" label="操作" :show-overflow-tooltip=true>
<template slot-scope="{row}">
<el-button size="mini" type="danger" icon="el-icon-delete" v-if="row.container_status === 'running' || row.container_status === 'stop'"
@click="delContainer(row)" >删除</el-button>
</template>
</el-table-column>
</el-table>
</el-dialog>
<div class="filter-container">
<el-input v-model="search" style="width: 230px;" size="medium"></el-input>
<el-button class="filter-item" size="medium" style="margin-left: 10px;margin-bottom: 10px" type="primary" icon="el-icon-search" @click="handleQuery(1)">
Expand Down Expand Up @@ -156,6 +177,7 @@
import { ImgList } from "@/api/docker"
import { search } from "@/api/utils"
import { ImageAdd, ImageDelete,ImageLocal,ImageLocalAdd,ImageShare } from "@/api/image"
import { containerDel } from '@/api/container'
import { getTask,batchTask,progressTask } from '@/api/tasks'
export default {
Expand Down Expand Up @@ -185,6 +207,8 @@
selectLocalImages: [],
progressShow: false,
progressLoading: false,
deleteShow: false,
deleteContainerList: [],
progress:{
"title":"",
"layer":[],
Expand Down Expand Up @@ -397,14 +421,16 @@
ImageDelete(row.image_id).then(response => {
let data = response.data
if(data.status === 200){
this.$notify({
this.$message({
title: '成功',
message: '删除成功!',
type: 'success'
});
this.initTableData()
}else{
this.$notify({
this.deleteShow = true
this.deleteContainerList = data.data
this.$message({
title: '失败',
message: data.msg,
type: 'error'
Expand Down Expand Up @@ -561,33 +587,65 @@
message: msg,
type: 'success'
});
// this.$message({message: msg,type: "success",duration: 1.5 * 1000})
}
this.centerDialogVisible = false
this.initTableData()
}else if(status === 201){
// this.$message({
// message: rsp["msg"],
// type: "info",
// })
this.$notify({
title: '失败',
message: rsp["msg"],
type: 'info'
});
}else{
// this.$message({
// message: rsp["msg"],
// type: "error",
// duration: 3 * 1000
// })
this.$notify({
title: '失败',
message: rsp["msg"],
type: 'error'
});
}
})
},
delContainer(row){
containerDel(row.container_id).then(response => {
let taskId = response.data["data"]
let tmpDeleteContainerInterval = window.setInterval(() => {
setTimeout(()=>{
getTask(taskId).then(response=>{
let responseStatus = response.data["status"]
let responseData = response.data
if (responseStatus === 1001){
// 一直轮训
}else{
clearInterval(tmpDeleteContainerInterval)
if (responseStatus === 200) {
this.$message({
type: 'success',
message: '删除成功'
});
ImageDelete(row.image_id).then(response => {
let data = response.data
if(data.status !== 200){
this.deleteContainerList = data.data
}else{
this.$message({
type: 'success',
message: '删除成功'
});
this.deleteShow = false
this.initTableData()
}
})
}else{
this.$message({
message: responseData["msg"],
type: "error",
})
}
}
})
},1)
},1000)
})
}
}
}
Expand Down

0 comments on commit 70b3ed5

Please sign in to comment.