ljw 1 год назад
Родитель
Сommit
fcce10c695

+ 2 - 1
cmd/apimain.go

@@ -200,7 +200,7 @@ func getTranslatorForLang(lang string) ut.Translator {
200 200
 	}
201 201
 }
202 202
 func DatabaseAutoUpdate() {
203
-	version := 233
203
+	version := 235
204 204
 
205 205
 	db := global.DB
206 206
 
@@ -263,6 +263,7 @@ func Migrate(version uint) {
263 263
 		&model.LoginLog{},
264 264
 		&model.ShareRecord{},
265 265
 		&model.AuditConn{},
266
+		&model.AuditFile{},
266 267
 	)
267 268
 	if err != nil {
268 269
 		fmt.Println("migrate err :=>", err)

+ 76 - 9
docs/admin/admin_docs.go

@@ -387,7 +387,7 @@ const docTemplateadmin = `{
387 387
                         "token": []
388 388
                     }
389 389
                 ],
390
-                "description": "链接日志删除",
390
+                "description": "文件日志删除",
391 391
                 "consumes": [
392 392
                     "application/json"
393 393
                 ],
@@ -395,17 +395,17 @@ const docTemplateadmin = `{
395 395
                     "application/json"
396 396
                 ],
397 397
                 "tags": [
398
-                    "链接日志"
398
+                    "文件日志"
399 399
                 ],
400
-                "summary": "链接日志删除",
400
+                "summary": "文件日志删除",
401 401
                 "parameters": [
402 402
                     {
403
-                        "description": "链接日志信息",
403
+                        "description": "文件日志信息",
404 404
                         "name": "body",
405 405
                         "in": "body",
406 406
                         "required": true,
407 407
                         "schema": {
408
-                            "$ref": "#/definitions/model.AuditConn"
408
+                            "$ref": "#/definitions/model.AuditFile"
409 409
                         }
410 410
                     }
411 411
                 ],
@@ -432,7 +432,7 @@ const docTemplateadmin = `{
432 432
                         "token": []
433 433
                     }
434 434
                 ],
435
-                "description": "链接日志列表",
435
+                "description": "文件日志列表",
436 436
                 "consumes": [
437 437
                     "application/json"
438 438
                 ],
@@ -440,9 +440,9 @@ const docTemplateadmin = `{
440 440
                     "application/json"
441 441
                 ],
442 442
                 "tags": [
443
-                    "链接日志"
443
+                    "文件日志"
444 444
                 ],
445
-                "summary": "链接日志列表",
445
+                "summary": "文件日志列表",
446 446
                 "parameters": [
447 447
                     {
448 448
                         "type": "integer",
@@ -481,7 +481,7 @@ const docTemplateadmin = `{
481 481
                                     "type": "object",
482 482
                                     "properties": {
483 483
                                         "data": {
484
-                                            "$ref": "#/definitions/model.AuditConnList"
484
+                                            "$ref": "#/definitions/model.AuditFileList"
485 485
                                         }
486 486
                                     }
487 487
                                 }
@@ -2566,6 +2566,9 @@ const docTemplateadmin = `{
2566 2566
                 },
2567 2567
                 "name": {
2568 2568
                     "type": "string"
2569
+                },
2570
+                "type": {
2571
+                    "type": "integer"
2569 2572
                 }
2570 2573
             }
2571 2574
         },
@@ -2925,6 +2928,70 @@ const docTemplateadmin = `{
2925 2928
                 }
2926 2929
             }
2927 2930
         },
2931
+        "model.AuditFile": {
2932
+            "type": "object",
2933
+            "properties": {
2934
+                "created_at": {
2935
+                    "type": "string"
2936
+                },
2937
+                "from_name": {
2938
+                    "type": "string"
2939
+                },
2940
+                "from_peer": {
2941
+                    "type": "string"
2942
+                },
2943
+                "id": {
2944
+                    "type": "integer"
2945
+                },
2946
+                "info": {
2947
+                    "type": "string"
2948
+                },
2949
+                "ip": {
2950
+                    "type": "string"
2951
+                },
2952
+                "is_file": {
2953
+                    "type": "boolean"
2954
+                },
2955
+                "num": {
2956
+                    "type": "integer"
2957
+                },
2958
+                "path": {
2959
+                    "type": "string"
2960
+                },
2961
+                "peer_id": {
2962
+                    "type": "string"
2963
+                },
2964
+                "type": {
2965
+                    "type": "integer"
2966
+                },
2967
+                "updated_at": {
2968
+                    "type": "string"
2969
+                },
2970
+                "uuid": {
2971
+                    "type": "string"
2972
+                }
2973
+            }
2974
+        },
2975
+        "model.AuditFileList": {
2976
+            "type": "object",
2977
+            "properties": {
2978
+                "list": {
2979
+                    "type": "array",
2980
+                    "items": {
2981
+                        "$ref": "#/definitions/model.AuditFile"
2982
+                    }
2983
+                },
2984
+                "page": {
2985
+                    "type": "integer"
2986
+                },
2987
+                "page_size": {
2988
+                    "type": "integer"
2989
+                },
2990
+                "total": {
2991
+                    "type": "integer"
2992
+                }
2993
+            }
2994
+        },
2928 2995
         "model.Group": {
2929 2996
             "type": "object",
2930 2997
             "properties": {

+ 76 - 9
docs/admin/admin_swagger.json

@@ -380,7 +380,7 @@
380 380
                         "token": []
381 381
                     }
382 382
                 ],
383
-                "description": "链接日志删除",
383
+                "description": "文件日志删除",
384 384
                 "consumes": [
385 385
                     "application/json"
386 386
                 ],
@@ -388,17 +388,17 @@
388 388
                     "application/json"
389 389
                 ],
390 390
                 "tags": [
391
-                    "链接日志"
391
+                    "文件日志"
392 392
                 ],
393
-                "summary": "链接日志删除",
393
+                "summary": "文件日志删除",
394 394
                 "parameters": [
395 395
                     {
396
-                        "description": "链接日志信息",
396
+                        "description": "文件日志信息",
397 397
                         "name": "body",
398 398
                         "in": "body",
399 399
                         "required": true,
400 400
                         "schema": {
401
-                            "$ref": "#/definitions/model.AuditConn"
401
+                            "$ref": "#/definitions/model.AuditFile"
402 402
                         }
403 403
                     }
404 404
                 ],
@@ -425,7 +425,7 @@
425 425
                         "token": []
426 426
                     }
427 427
                 ],
428
-                "description": "链接日志列表",
428
+                "description": "文件日志列表",
429 429
                 "consumes": [
430 430
                     "application/json"
431 431
                 ],
@@ -433,9 +433,9 @@
433 433
                     "application/json"
434 434
                 ],
435 435
                 "tags": [
436
-                    "链接日志"
436
+                    "文件日志"
437 437
                 ],
438
-                "summary": "链接日志列表",
438
+                "summary": "文件日志列表",
439 439
                 "parameters": [
440 440
                     {
441 441
                         "type": "integer",
@@ -474,7 +474,7 @@
474 474
                                     "type": "object",
475 475
                                     "properties": {
476 476
                                         "data": {
477
-                                            "$ref": "#/definitions/model.AuditConnList"
477
+                                            "$ref": "#/definitions/model.AuditFileList"
478 478
                                         }
479 479
                                     }
480 480
                                 }
@@ -2559,6 +2559,9 @@
2559 2559
                 },
2560 2560
                 "name": {
2561 2561
                     "type": "string"
2562
+                },
2563
+                "type": {
2564
+                    "type": "integer"
2562 2565
                 }
2563 2566
             }
2564 2567
         },
@@ -2918,6 +2921,70 @@
2918 2921
                 }
2919 2922
             }
2920 2923
         },
2924
+        "model.AuditFile": {
2925
+            "type": "object",
2926
+            "properties": {
2927
+                "created_at": {
2928
+                    "type": "string"
2929
+                },
2930
+                "from_name": {
2931
+                    "type": "string"
2932
+                },
2933
+                "from_peer": {
2934
+                    "type": "string"
2935
+                },
2936
+                "id": {
2937
+                    "type": "integer"
2938
+                },
2939
+                "info": {
2940
+                    "type": "string"
2941
+                },
2942
+                "ip": {
2943
+                    "type": "string"
2944
+                },
2945
+                "is_file": {
2946
+                    "type": "boolean"
2947
+                },
2948
+                "num": {
2949
+                    "type": "integer"
2950
+                },
2951
+                "path": {
2952
+                    "type": "string"
2953
+                },
2954
+                "peer_id": {
2955
+                    "type": "string"
2956
+                },
2957
+                "type": {
2958
+                    "type": "integer"
2959
+                },
2960
+                "updated_at": {
2961
+                    "type": "string"
2962
+                },
2963
+                "uuid": {
2964
+                    "type": "string"
2965
+                }
2966
+            }
2967
+        },
2968
+        "model.AuditFileList": {
2969
+            "type": "object",
2970
+            "properties": {
2971
+                "list": {
2972
+                    "type": "array",
2973
+                    "items": {
2974
+                        "$ref": "#/definitions/model.AuditFile"
2975
+                    }
2976
+                },
2977
+                "page": {
2978
+                    "type": "integer"
2979
+                },
2980
+                "page_size": {
2981
+                    "type": "integer"
2982
+                },
2983
+                "total": {
2984
+                    "type": "integer"
2985
+                }
2986
+            }
2987
+        },
2921 2988
         "model.Group": {
2922 2989
             "type": "object",
2923 2990
             "properties": {

+ 53 - 9
docs/admin/admin_swagger.yaml

@@ -75,6 +75,8 @@ definitions:
75 75
         type: integer
76 76
       name:
77 77
         type: string
78
+      type:
79
+        type: integer
78 80
     required:
79 81
     - name
80 82
     type: object
@@ -315,6 +317,48 @@ definitions:
315 317
       total:
316 318
         type: integer
317 319
     type: object
320
+  model.AuditFile:
321
+    properties:
322
+      created_at:
323
+        type: string
324
+      from_name:
325
+        type: string
326
+      from_peer:
327
+        type: string
328
+      id:
329
+        type: integer
330
+      info:
331
+        type: string
332
+      ip:
333
+        type: string
334
+      is_file:
335
+        type: boolean
336
+      num:
337
+        type: integer
338
+      path:
339
+        type: string
340
+      peer_id:
341
+        type: string
342
+      type:
343
+        type: integer
344
+      updated_at:
345
+        type: string
346
+      uuid:
347
+        type: string
348
+    type: object
349
+  model.AuditFileList:
350
+    properties:
351
+      list:
352
+        items:
353
+          $ref: '#/definitions/model.AuditFile'
354
+        type: array
355
+      page:
356
+        type: integer
357
+      page_size:
358
+        type: integer
359
+      total:
360
+        type: integer
361
+    type: object
318 362
   model.Group:
319 363
     properties:
320 364
       created_at:
@@ -765,14 +809,14 @@ paths:
765 809
     post:
766 810
       consumes:
767 811
       - application/json
768
-      description: 链接日志删除
812
+      description: 文件日志删除
769 813
       parameters:
770
-      - description: 链接日志信息
814
+      - description: 文件日志信息
771 815
         in: body
772 816
         name: body
773 817
         required: true
774 818
         schema:
775
-          $ref: '#/definitions/model.AuditConn'
819
+          $ref: '#/definitions/model.AuditFile'
776 820
       produces:
777 821
       - application/json
778 822
       responses:
@@ -786,14 +830,14 @@ paths:
786 830
             $ref: '#/definitions/response.Response'
787 831
       security:
788 832
       - token: []
789
-      summary: 链接日志删除
833
+      summary: 文件日志删除
790 834
       tags:
791
-      - 链接日志
835
+      - 文件日志
792 836
   /admin/audit_conn/list:
793 837
     get:
794 838
       consumes:
795 839
       - application/json
796
-      description: 链接日志列表
840
+      description: 文件日志列表
797 841
       parameters:
798 842
       - description: 页码
799 843
         in: query
@@ -821,7 +865,7 @@ paths:
821 865
             - $ref: '#/definitions/response.Response'
822 866
             - properties:
823 867
                 data:
824
-                  $ref: '#/definitions/model.AuditConnList'
868
+                  $ref: '#/definitions/model.AuditFileList'
825 869
               type: object
826 870
         "500":
827 871
           description: Internal Server Error
@@ -829,9 +873,9 @@ paths:
829 873
             $ref: '#/definitions/response.Response'
830 874
       security:
831 875
       - token: []
832
-      summary: 链接日志列表
876
+      summary: 文件日志列表
833 877
       tags:
834
-      - 链接日志
878
+      - 文件日志
835 879
   /admin/file/oss_token:
836 880
     get:
837 881
       consumes:

+ 66 - 0
docs/api/api_docs.go

@@ -727,6 +727,46 @@ const docTemplateapi = `{
727 727
                 }
728 728
             }
729 729
         },
730
+        "/audit/file": {
731
+            "post": {
732
+                "description": "审计文件",
733
+                "consumes": [
734
+                    "application/json"
735
+                ],
736
+                "produces": [
737
+                    "application/json"
738
+                ],
739
+                "tags": [
740
+                    "审计"
741
+                ],
742
+                "summary": "审计文件",
743
+                "parameters": [
744
+                    {
745
+                        "description": "审计文件",
746
+                        "name": "body",
747
+                        "in": "body",
748
+                        "required": true,
749
+                        "schema": {
750
+                            "$ref": "#/definitions/api.AuditFileForm"
751
+                        }
752
+                    }
753
+                ],
754
+                "responses": {
755
+                    "200": {
756
+                        "description": "OK",
757
+                        "schema": {
758
+                            "type": "string"
759
+                        }
760
+                    },
761
+                    "500": {
762
+                        "description": "Internal Server Error",
763
+                        "schema": {
764
+                            "$ref": "#/definitions/response.Response"
765
+                        }
766
+                    }
767
+                }
768
+            }
769
+        },
730 770
         "/heartbeat": {
731 771
             "post": {
732 772
                 "description": "心跳",
@@ -1259,6 +1299,32 @@ const docTemplateapi = `{
1259 1299
                 }
1260 1300
             }
1261 1301
         },
1302
+        "api.AuditFileForm": {
1303
+            "type": "object",
1304
+            "properties": {
1305
+                "id": {
1306
+                    "type": "string"
1307
+                },
1308
+                "info": {
1309
+                    "type": "string"
1310
+                },
1311
+                "is_file": {
1312
+                    "type": "boolean"
1313
+                },
1314
+                "path": {
1315
+                    "type": "string"
1316
+                },
1317
+                "peer_id": {
1318
+                    "type": "string"
1319
+                },
1320
+                "type": {
1321
+                    "type": "integer"
1322
+                },
1323
+                "uuid": {
1324
+                    "type": "string"
1325
+                }
1326
+            }
1327
+        },
1262 1328
         "api.DeviceInfoInLogin": {
1263 1329
             "type": "object",
1264 1330
             "properties": {

+ 66 - 0
docs/api/api_swagger.json

@@ -720,6 +720,46 @@
720 720
                 }
721 721
             }
722 722
         },
723
+        "/audit/file": {
724
+            "post": {
725
+                "description": "审计文件",
726
+                "consumes": [
727
+                    "application/json"
728
+                ],
729
+                "produces": [
730
+                    "application/json"
731
+                ],
732
+                "tags": [
733
+                    "审计"
734
+                ],
735
+                "summary": "审计文件",
736
+                "parameters": [
737
+                    {
738
+                        "description": "审计文件",
739
+                        "name": "body",
740
+                        "in": "body",
741
+                        "required": true,
742
+                        "schema": {
743
+                            "$ref": "#/definitions/api.AuditFileForm"
744
+                        }
745
+                    }
746
+                ],
747
+                "responses": {
748
+                    "200": {
749
+                        "description": "OK",
750
+                        "schema": {
751
+                            "type": "string"
752
+                        }
753
+                    },
754
+                    "500": {
755
+                        "description": "Internal Server Error",
756
+                        "schema": {
757
+                            "$ref": "#/definitions/response.Response"
758
+                        }
759
+                    }
760
+                }
761
+            }
762
+        },
723 763
         "/heartbeat": {
724 764
             "post": {
725 765
                 "description": "心跳",
@@ -1252,6 +1292,32 @@
1252 1292
                 }
1253 1293
             }
1254 1294
         },
1295
+        "api.AuditFileForm": {
1296
+            "type": "object",
1297
+            "properties": {
1298
+                "id": {
1299
+                    "type": "string"
1300
+                },
1301
+                "info": {
1302
+                    "type": "string"
1303
+                },
1304
+                "is_file": {
1305
+                    "type": "boolean"
1306
+                },
1307
+                "path": {
1308
+                    "type": "string"
1309
+                },
1310
+                "peer_id": {
1311
+                    "type": "string"
1312
+                },
1313
+                "type": {
1314
+                    "type": "integer"
1315
+                },
1316
+                "uuid": {
1317
+                    "type": "string"
1318
+                }
1319
+            }
1320
+        },
1255 1321
         "api.DeviceInfoInLogin": {
1256 1322
             "type": "object",
1257 1323
             "properties": {

+ 43 - 0
docs/api/api_swagger.yaml

@@ -27,6 +27,23 @@ definitions:
27 27
       uuid:
28 28
         type: string
29 29
     type: object
30
+  api.AuditFileForm:
31
+    properties:
32
+      id:
33
+        type: string
34
+      info:
35
+        type: string
36
+      is_file:
37
+        type: boolean
38
+      path:
39
+        type: string
40
+      peer_id:
41
+        type: string
42
+      type:
43
+        type: integer
44
+      uuid:
45
+        type: string
46
+    type: object
30 47
   api.DeviceInfoInLogin:
31 48
     properties:
32 49
       name:
@@ -609,6 +626,32 @@ paths:
609 626
       summary: 审计连接
610 627
       tags:
611 628
       - 审计
629
+  /audit/file:
630
+    post:
631
+      consumes:
632
+      - application/json
633
+      description: 审计文件
634
+      parameters:
635
+      - description: 审计文件
636
+        in: body
637
+        name: body
638
+        required: true
639
+        schema:
640
+          $ref: '#/definitions/api.AuditFileForm'
641
+      produces:
642
+      - application/json
643
+      responses:
644
+        "200":
645
+          description: OK
646
+          schema:
647
+            type: string
648
+        "500":
649
+          description: Internal Server Error
650
+          schema:
651
+            $ref: '#/definitions/response.Response'
652
+      summary: 审计文件
653
+      tags:
654
+      - 审计
612 655
   /heartbeat:
613 656
     post:
614 657
       consumes:

+ 68 - 1
http/controller/admin/audit.go

@@ -67,7 +67,7 @@ func (a *Audit) ConnDelete(c *gin.Context) {
67 67
 		response.Fail(c, 101, errList[0])
68 68
 		return
69 69
 	}
70
-	l := service.AllService.AuditService.InfoById(f.Id)
70
+	l := service.AllService.AuditService.ConnInfoById(f.Id)
71 71
 	if l.Id > 0 {
72 72
 		err := service.AllService.AuditService.DeleteAuditConn(l)
73 73
 		if err == nil {
@@ -79,3 +79,70 @@ func (a *Audit) ConnDelete(c *gin.Context) {
79 79
 	}
80 80
 	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
81 81
 }
82
+
83
+// FileList 列表
84
+// @Tags 文件日志
85
+// @Summary 文件日志列表
86
+// @Description 文件日志列表
87
+// @Accept  json
88
+// @Produce  json
89
+// @Param page query int false "页码"
90
+// @Param page_size query int false "页大小"
91
+// @Param peer_id query int false "目标设备"
92
+// @Param from_peer query int false "来源设备"
93
+// @Success 200 {object} response.Response{data=model.AuditFileList}
94
+// @Failure 500 {object} response.Response
95
+// @Router /admin/audit_conn/list [get]
96
+// @Security token
97
+func (a *Audit) FileList(c *gin.Context) {
98
+	query := &admin.AuditQuery{}
99
+	if err := c.ShouldBindQuery(query); err != nil {
100
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
101
+		return
102
+	}
103
+	res := service.AllService.AuditService.AuditFileList(query.Page, query.PageSize, func(tx *gorm.DB) {
104
+		if query.PeerId != "" {
105
+			tx.Where("peer_id like ?", "%"+query.PeerId+"%")
106
+		}
107
+		if query.FromPeer != "" {
108
+			tx.Where("from_peer like ?", "%"+query.FromPeer+"%")
109
+		}
110
+	})
111
+	response.Success(c, res)
112
+}
113
+
114
+// FileDelete 删除
115
+// @Tags 文件日志
116
+// @Summary 文件日志删除
117
+// @Description 文件日志删除
118
+// @Accept  json
119
+// @Produce  json
120
+// @Param body body model.AuditFile true "文件日志信息"
121
+// @Success 200 {object} response.Response
122
+// @Failure 500 {object} response.Response
123
+// @Router /admin/audit_conn/delete [post]
124
+// @Security token
125
+func (a *Audit) FileDelete(c *gin.Context) {
126
+	f := &model.AuditFile{}
127
+	if err := c.ShouldBindJSON(f); err != nil {
128
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
129
+		return
130
+	}
131
+	id := f.Id
132
+	errList := global.Validator.ValidVar(c, id, "required,gt=0")
133
+	if len(errList) > 0 {
134
+		response.Fail(c, 101, errList[0])
135
+		return
136
+	}
137
+	l := service.AllService.AuditService.FileInfoById(f.Id)
138
+	if l.Id > 0 {
139
+		err := service.AllService.AuditService.DeleteAuditFile(l)
140
+		if err == nil {
141
+			response.Success(c, nil)
142
+			return
143
+		}
144
+		response.Fail(c, 101, err.Error())
145
+		return
146
+	}
147
+	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
148
+}

+ 29 - 1
http/controller/api/audit.go

@@ -30,7 +30,9 @@ func (a *Audit) AuditConn(c *gin.Context) {
30 30
 		response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
31 31
 		return
32 32
 	}
33
-	//fmt.Println(af)
33
+	/*ttt := &gin.H{}
34
+	c.ShouldBindBodyWith(ttt, binding.JSON)
35
+	fmt.Println(ttt)*/
34 36
 	ac := af.ToAuditConn()
35 37
 	if af.Action == model.AuditActionNew {
36 38
 		service.AllService.AuditService.CreateAuditConn(ac)
@@ -48,9 +50,35 @@ func (a *Audit) AuditConn(c *gin.Context) {
48 50
 				FromPeer:  ac.FromPeer,
49 51
 				FromName:  ac.FromName,
50 52
 				SessionId: ac.SessionId,
53
+				Type:      ac.Type,
51 54
 			}
52 55
 			service.AllService.AuditService.UpdateAuditConn(up)
53 56
 		}
54 57
 	}
55 58
 	response.Success(c, "")
56 59
 }
60
+
61
+// AuditFile
62
+// @Tags 审计
63
+// @Summary 审计文件
64
+// @Description 审计文件
65
+// @Accept  json
66
+// @Produce  json
67
+// @Param body body request.AuditFileForm true "审计文件"
68
+// @Success 200 {string} string ""
69
+// @Failure 500 {object} response.Response
70
+// @Router /audit/file [post]
71
+func (a *Audit) AuditFile(c *gin.Context) {
72
+	aff := &request.AuditFileForm{}
73
+	err := c.ShouldBindBodyWith(aff, binding.JSON)
74
+	if err != nil {
75
+		response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
76
+		return
77
+	}
78
+	//ttt := &gin.H{}
79
+	//c.ShouldBindBodyWith(ttt, binding.JSON)
80
+	//fmt.Println(ttt)
81
+	af := aff.ToAuditFile()
82
+	service.AllService.AuditService.CreateAuditFile(af)
83
+	response.Success(c, "")
84
+}

+ 38 - 0
http/request/api/audit.go

@@ -1,7 +1,9 @@
1 1
 package api
2 2
 
3 3
 import (
4
+	"Gwen/global"
4 5
 	"Gwen/model"
6
+	"encoding/json"
5 7
 	"strconv"
6 8
 )
7 9
 
@@ -38,3 +40,39 @@ func (a *AuditConnForm) ToAuditConn() *model.AuditConn {
38 40
 		Uuid:      a.Uuid,
39 41
 	}
40 42
 }
43
+
44
+type AuditFileForm struct {
45
+	Id     string `json:"id"`
46
+	Info   string `json:"info"`
47
+	IsFile bool   `json:"is_file"`
48
+	Path   string `json:"path"`
49
+	PeerId string `json:"peer_id"`
50
+	Type   int    `json:"type"`
51
+	Uuid   string `json:"uuid"`
52
+}
53
+type AuditFileInfo struct {
54
+	Ip   string `json:"ip"`
55
+	Name string `json:"name"`
56
+	Num  int    `json:"num"`
57
+}
58
+
59
+func (a *AuditFileForm) ToAuditFile() *model.AuditFile {
60
+	fi := &AuditFileInfo{}
61
+	err := json.Unmarshal([]byte(a.Info), fi)
62
+	if err != nil {
63
+		global.Logger.Warn("ToAuditFile", err)
64
+	}
65
+
66
+	return &model.AuditFile{
67
+		PeerId:   a.Id,
68
+		Info:     a.Info,
69
+		IsFile:   a.IsFile,
70
+		FromPeer: a.PeerId,
71
+		Path:     a.Path,
72
+		Type:     a.Type,
73
+		Uuid:     a.Uuid,
74
+		FromName: fi.Name,
75
+		Ip:       fi.Ip,
76
+		Num:      fi.Num,
77
+	}
78
+}

+ 3 - 0
http/router/admin.go

@@ -148,6 +148,9 @@ func AuditBind(rg *gin.RouterGroup) {
148 148
 	aR := rg.Group("/audit_conn").Use(middleware.AdminPrivilege())
149 149
 	aR.GET("/list", cont.ConnList)
150 150
 	aR.POST("/delete", cont.ConnDelete)
151
+	afR := rg.Group("/audit_file").Use(middleware.AdminPrivilege())
152
+	afR.GET("/list", cont.FileList)
153
+	afR.POST("/delete", cont.FileDelete)
151 154
 }
152 155
 
153 156
 /*

+ 2 - 0
http/router/api.go

@@ -53,6 +53,8 @@ func ApiInit(g *gin.Engine) {
53 53
 	au := &api.Audit{}
54 54
 	//[method:POST] [uri:/api/audit/conn]
55 55
 	frg.POST("/audit/conn", au.AuditConn)
56
+	//[method:POST] [uri:/api/audit/file]
57
+	frg.POST("/audit/file", au.AuditFile)
56 58
 	frg.Use(middleware.RustAuth())
57 59
 	{
58 60
 		u := &api.User{}

+ 20 - 0
model/audit.go

@@ -24,3 +24,23 @@ type AuditConnList struct {
24 24
 	AuditConns []*AuditConn `json:"list"`
25 25
 	Pagination
26 26
 }
27
+
28
+type AuditFile struct {
29
+	IdModel
30
+	FromPeer string `json:"from_peer" gorm:"default:'';not null;index"`
31
+	Info     string `json:"info" gorm:"default:'';not null;"`
32
+	IsFile   bool   `json:"is_file" gorm:"default:0;not null;"`
33
+	Path     string `json:"path" gorm:"default:'';not null;"`
34
+	PeerId   string `json:"peer_id" gorm:"default:'';not null;index"`
35
+	Type     int    `json:"type" gorm:"default:0;not null;"`
36
+	Uuid     string `json:"uuid" gorm:"default:'';not null;"`
37
+	Ip       string `json:"ip" gorm:"default:'';not null;"`
38
+	Num      int    `json:"num" gorm:"default:0;not null;"`
39
+	FromName string `json:"from_name" gorm:"default:'';not null;"`
40
+	TimeModel
41
+}
42
+
43
+type AuditFileList struct {
44
+	AuditFiles []*AuditFile `json:"list"`
45
+	Pagination
46
+}

+ 37 - 2
service/audit.go

@@ -44,9 +44,44 @@ func (as *AuditService) InfoByPeerIdAndConnId(peerId string, connId int64) (res
44 44
 	return
45 45
 }
46 46
 
47
-// InfoById
48
-func (as *AuditService) InfoById(id uint) (res *model.AuditConn) {
47
+// ConnInfoById
48
+func (as *AuditService) ConnInfoById(id uint) (res *model.AuditConn) {
49 49
 	res = &model.AuditConn{}
50 50
 	global.DB.Where("id = ?", id).First(res)
51 51
 	return
52 52
 }
53
+
54
+// FileInfoById
55
+func (as *AuditService) FileInfoById(id uint) (res *model.AuditFile) {
56
+	res = &model.AuditFile{}
57
+	global.DB.Where("id = ?", id).First(res)
58
+	return
59
+}
60
+
61
+func (as *AuditService) AuditFileList(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AuditFileList) {
62
+	res = &model.AuditFileList{}
63
+	res.Page = int64(page)
64
+	res.PageSize = int64(pageSize)
65
+	tx := global.DB.Model(&model.AuditFile{})
66
+	if where != nil {
67
+		where(tx)
68
+	}
69
+	tx.Count(&res.Total)
70
+	tx.Scopes(Paginate(page, pageSize))
71
+	tx.Find(&res.AuditFiles)
72
+	return
73
+}
74
+
75
+// CreateAuditFile
76
+func (as *AuditService) CreateAuditFile(u *model.AuditFile) error {
77
+	res := global.DB.Create(u).Error
78
+	return res
79
+}
80
+func (as *AuditService) DeleteAuditFile(u *model.AuditFile) error {
81
+	return global.DB.Delete(u).Error
82
+}
83
+
84
+// Update 更新
85
+func (as *AuditService) UpdateAuditFile(u *model.AuditFile) error {
86
+	return global.DB.Model(u).Updates(u).Error
87
+}