Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Liiuliu committed Nov 5, 2021
1 parent 86eb082 commit 6ac9efe
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3
LABEL maintainer="Prometheus <[email protected]>" version="0.3.2.10" description="Vulfocus for Docker"
LABEL maintainer="Prometheus <[email protected]>" version="0.3.2.11" description="Vulfocus for Docker"
EXPOSE 80
RUN mkdir /vulfocus-api/
WORKDIR /vulfocus-api/
Expand Down
Binary file removed vulfocus-api/db.sqlite3
Binary file not shown.
48 changes: 24 additions & 24 deletions vulfocus-api/dockerapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,18 +1751,18 @@ def get_operation_image_api(req):
if username:
user = UserProfile.objects.filter(username=username).first()
if not user:
return JsonResponse(R.err(msg="信息认证未通过"))
return HttpResponse(json.dumps(R.err(msg="认证信息错误"), ensure_ascii=False))
else:
return JsonResponse(R.err(msg="信息认证未通过"))
return HttpResponse(json.dumps(R.err(msg="认证信息错误"), ensure_ascii=False))
# 判断licence是否匹配用户,符合则返回所有已下载的镜像数据
if licence and licence == user.licence:
imgs = ImageInfo.objects.filter(is_ok=True).all().values("image_name", "image_vul_name", "image_desc")
imglist = list()
for i in imgs:
imglist.append(i)
return JsonResponse(R.ok(data=imglist, msg="镜像信息"))
return HttpResponse(json.dumps(R.ok(data=imglist), ensure_ascii=False), content_type='application/json')
else:
return JsonResponse(R.err(msg="信息认证未通过"))
return HttpResponse(json.dumps(R.err(msg="认证信息错误"), ensure_ascii=False))

# 启动镜像
if req.method == "POST":
Expand All @@ -1775,26 +1775,26 @@ def get_operation_image_api(req):
if username:
user = UserProfile.objects.filter(username=username).first()
if not user:
return JsonResponse(R.err(msg="认证信息错误"))
return HttpResponse(json.dumps(R.err(msg="认证信息错误"), ensure_ascii=False))
else:
return JsonResponse(R.err(msg="认证信息错误"))
return HttpResponse(json.dumps(R.err(msg="认证信息错误"), ensure_ascii=False))
# 判断licence是否匹配用户
if licence and licence == user.licence:
pass
else:
return JsonResponse(R.err(msg="认证信息错误"))
return HttpResponse(json.dumps(R.err(msg="认证信息错误"), ensure_ascii=False))
# 判断镜像是否存在
if image_name:
image = ImageInfo.objects.filter(image_name=image_name, is_ok=True).first()
if not image:
return JsonResponse(R.err(msg="镜像不存在"))
return HttpResponse(json.dumps(R.err(msg="镜像不存在"), ensure_ascii=False))
else:
return JsonResponse(R.err(msg="镜像名称不能为空"))
return HttpResponse(json.dumps(R.err(msg="镜像名称不能为空"), ensure_ascii=False))
if not requisition:
return JsonResponse(R.err(msg="错误的请求"))
return HttpResponse(json.dumps(R.err(msg="错误的请求"), ensure_ascii=False))
if requisition and requisition not in ['start', 'stop', 'delete']:
return JsonResponse(R.err(msg="错误的请求"))
# 启动镜像的请求
return HttpResponse(json.dumps(R.err(msg="错误的请求"), ensure_ascii=False))
# 启动惊喜那个的请求
if requisition == "start":
data_count = ContainerVul.objects.filter(user_id=user.id, container_status='running').all().count()
data_start = ContainerVul.objects.filter(user_id=user.id, image_id=image.image_id, container_status='running').first()
Expand All @@ -1813,9 +1813,9 @@ def get_operation_image_api(req):
except:
status["host"] = data_start.vul_host
status["port"] = data_start.vul_port
return JsonResponse(R.ok(data=status, msg="镜像已启动"))
return HttpResponse(json.dumps(R.ok(data=status, msg="镜像已启动"), ensure_ascii=False))
if data_count > 3:
return JsonResponse(R.err(msg="同时启动容器数量达到上线"))
return HttpResponse(json.dumps(R.err(msg="同时启动容器数量达到上线"), ensure_ascii=False))
img_info = image
# 当前用户id
image_id = img_info.image_id
Expand Down Expand Up @@ -1870,30 +1870,30 @@ def get_operation_image_api(req):
except:
status["host"] = data.vul_host
status["port"] = data.vul_port
return JsonResponse(R.ok(data=status, msg="启动成功"))
return HttpResponse(json.dumps(R.ok(data=status, msg="启动成功"), ensure_ascii=False))
else:
if num == 3:
break
return JsonResponse(R.err(msg="启动失败"))
return HttpResponse(json.dumps(R.err(msg="启动失败"), ensure_ascii=False))
# 停止镜像的请求
if requisition == "stop":
container_vul = ContainerVul.objects.filter(image_id=image.image_id, user_id=user.id,
container_status="running").first()
if not container_vul:
return JsonResponse(R.err(msg="镜像已经停止"))
return HttpResponse(json.dumps(R.err(msg="镜像已经停止"), ensure_ascii=False))
if image.is_docker_compose == True:
original_container = ContainerVul.objects.filter(
Q(user_id=user.id) & Q(image_id=image.image_id) &
Q(container_status="running") & ~Q(docker_compose_path="")).first()
if not original_container:
return JsonResponse(R.err(msg="镜像已经停止"))
return HttpResponse(json.dumps(R.err(msg="镜像已经停止"), ensure_ascii=False))
task_id = tasks.stop_container_task(container_vul=original_container, user_info=user,
request_ip=get_request_ip(req))
return JsonResponse(R.ok(msg="停止成功"))
return HttpResponse(json.dumps(R.ok(msg="停止成功"), ensure_ascii=False))
else:
task_id = tasks.stop_container_task(container_vul=container_vul, user_info=user,
request_ip=get_request_ip(req))
return JsonResponse(R.ok(msg="停止成功"))
return HttpResponse(json.dumps(R.ok(msg="停止成功"), ensure_ascii=False))
# 删除镜像的请求
if requisition == "delete":
container_status_q = Q()
Expand All @@ -1902,17 +1902,17 @@ def get_operation_image_api(req):
container_status_q.children.append(('container_status', "stop"))
container_vul = ContainerVul.objects.filter(Q(image_id=image.image_id) & Q(user_id=user.id) & Q(container_status_q)).first()
if not container_vul:
return JsonResponse(R.err(msg="镜像已经删除"))
return HttpResponse(json.dumps(R.err(msg="镜像已经删除"), ensure_ascii=False))
if image.is_docker_compose == True:
original_container = ContainerVul.objects.filter(
Q(user_id=user.id) & Q(image_id=image.image_id) & ~Q(docker_compose_path="") & Q(container_status_q)).first()
if not original_container:
return JsonResponse(R.err(msg="镜像已经删除"))
return HttpResponse(json.dumps(R.err(msg="镜像已经删除"), ensure_ascii=False))
task_id = tasks.delete_container_task(container_vul=original_container, user_info=user,
request_ip=get_request_ip(req))
return JsonResponse(R.ok(msg='删除成功'))
return HttpResponse(json.dumps(R.ok(msg="删除成功"), ensure_ascii=False))
else:
task_id = tasks.delete_container_task(container_vul=container_vul, user_info=user,
request_ip=get_request_ip(req))

return JsonResponse(R.ok(msg="删除成功"))
return HttpResponse(json.dumps(R.ok(msg="删除成功"), ensure_ascii=False))
1 change: 1 addition & 0 deletions vulfocus-api/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ http {
keepalive_timeout 650;
types_hash_max_size 2048;
client_max_body_size 4096M;
fastcgi_buffers 8 128k;
# server_tokens off;
client_body_buffer_size 128M;
fastcgi_intercept_errors on;
Expand Down
3 changes: 2 additions & 1 deletion vulfocus-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"dependencies": {
"@toast-ui/editor-plugin-code-syntax-highlight": "^3.0.0",
"axios": ">=0.21.1",
"element-ui": "^2.15.3",
"clipboard": "^2.0.8",
"driver.js": "^0.9.8",
"element-ui": "^2.15.3",
"font-awesome": "^4.7.0",
"js-cookie": "2.2.0",
"normalize.css": "7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion vulfocus-frontend/src/views/dashboard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export default {
listData() {
ImgDashboard().then(response => {
this.listdata = response.data.results
this.page.total = response.data.count
this.page.total1 = response.data.count
this.degreeList = [{value:"全部"}]
this.languageList = [{value:"全部"}]
this.databaseList = [{value:"全部"}]
Expand Down
23 changes: 22 additions & 1 deletion vulfocus-frontend/src/views/profile/components/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<el-input v-model.trim="user.email" :disabled="true" />
</el-form-item>
<el-form-item label="Licence">
<el-input v-model.trim="user.licence" :disabled="true" />
<el-input v-model.trim="user.licence" class="copy-code-button" :disabled="true">
<el-button slot="append" icon="el-icon-document-copy" class="copy-code-button" :data-clipboard-text="user.licence" @click="copy">
</el-button>
</el-input>
</el-form-item>
<el-form-item label="旧密码" v-if="updatePwd === true">
<el-input v-model.trim="ruleForm.oldPassword" />
Expand All @@ -28,6 +31,7 @@

<script>
import { updatePassword } from "@/api/user"
import Clipboard from 'clipboard'
export default {
data(){
Expand Down Expand Up @@ -90,6 +94,23 @@ export default {
closeHandlerPwd(){
this.updatePwd = false
},
copy () {
let clipboard = new Clipboard('.copy-code-button') // 这里可以理解为选择器,选择上面的复制按钮
clipboard.on('success', e => {
clipboard.destroy()
this.$message({
message: '复制成功',
type: "success",
})
})
clipboard.on('error', e => {
clipboard.destroy()
this.$message({
message: '复制失败',
type: "error",
})
})
},
handleUpdatePwd(){
this.$refs.ruleForm.validate(valid => {
if(valid){
Expand Down

0 comments on commit 6ac9efe

Please sign in to comment.