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

+ 2 - 1
cmd/apimain.go

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

+ 76 - 9
docs/admin/admin_docs.go

@@ -387,7 +387,7 @@ const docTemplateadmin = `{
387
                         "token": []
387
                         "token": []
388
                     }
388
                     }
389
                 ],
389
                 ],
390
-                "description": "链接日志删除",
390
+                "description": "文件日志删除",
391
                 "consumes": [
391
                 "consumes": [
392
                     "application/json"
392
                     "application/json"
393
                 ],
393
                 ],
@@ -395,17 +395,17 @@ const docTemplateadmin = `{
395
                     "application/json"
395
                     "application/json"
396
                 ],
396
                 ],
397
                 "tags": [
397
                 "tags": [
398
-                    "链接日志"
398
+                    "文件日志"
399
                 ],
399
                 ],
400
-                "summary": "链接日志删除",
400
+                "summary": "文件日志删除",
401
                 "parameters": [
401
                 "parameters": [
402
                     {
402
                     {
403
-                        "description": "链接日志信息",
403
+                        "description": "文件日志信息",
404
                         "name": "body",
404
                         "name": "body",
405
                         "in": "body",
405
                         "in": "body",
406
                         "required": true,
406
                         "required": true,
407
                         "schema": {
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
                         "token": []
432
                         "token": []
433
                     }
433
                     }
434
                 ],
434
                 ],
435
-                "description": "链接日志列表",
435
+                "description": "文件日志列表",
436
                 "consumes": [
436
                 "consumes": [
437
                     "application/json"
437
                     "application/json"
438
                 ],
438
                 ],
@@ -440,9 +440,9 @@ const docTemplateadmin = `{
440
                     "application/json"
440
                     "application/json"
441
                 ],
441
                 ],
442
                 "tags": [
442
                 "tags": [
443
-                    "链接日志"
443
+                    "文件日志"
444
                 ],
444
                 ],
445
-                "summary": "链接日志列表",
445
+                "summary": "文件日志列表",
446
                 "parameters": [
446
                 "parameters": [
447
                     {
447
                     {
448
                         "type": "integer",
448
                         "type": "integer",
@@ -481,7 +481,7 @@ const docTemplateadmin = `{
481
                                     "type": "object",
481
                                     "type": "object",
482
                                     "properties": {
482
                                     "properties": {
483
                                         "data": {
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
                 "name": {
2567
                 "name": {
2568
                     "type": "string"
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
         "model.Group": {
2995
         "model.Group": {
2929
             "type": "object",
2996
             "type": "object",
2930
             "properties": {
2997
             "properties": {

+ 76 - 9
docs/admin/admin_swagger.json

@@ -380,7 +380,7 @@
380
                         "token": []
380
                         "token": []
381
                     }
381
                     }
382
                 ],
382
                 ],
383
-                "description": "链接日志删除",
383
+                "description": "文件日志删除",
384
                 "consumes": [
384
                 "consumes": [
385
                     "application/json"
385
                     "application/json"
386
                 ],
386
                 ],
@@ -388,17 +388,17 @@
388
                     "application/json"
388
                     "application/json"
389
                 ],
389
                 ],
390
                 "tags": [
390
                 "tags": [
391
-                    "链接日志"
391
+                    "文件日志"
392
                 ],
392
                 ],
393
-                "summary": "链接日志删除",
393
+                "summary": "文件日志删除",
394
                 "parameters": [
394
                 "parameters": [
395
                     {
395
                     {
396
-                        "description": "链接日志信息",
396
+                        "description": "文件日志信息",
397
                         "name": "body",
397
                         "name": "body",
398
                         "in": "body",
398
                         "in": "body",
399
                         "required": true,
399
                         "required": true,
400
                         "schema": {
400
                         "schema": {
401
-                            "$ref": "#/definitions/model.AuditConn"
401
+                            "$ref": "#/definitions/model.AuditFile"
402
                         }
402
                         }
403
                     }
403
                     }
404
                 ],
404
                 ],
@@ -425,7 +425,7 @@
425
                         "token": []
425
                         "token": []
426
                     }
426
                     }
427
                 ],
427
                 ],
428
-                "description": "链接日志列表",
428
+                "description": "文件日志列表",
429
                 "consumes": [
429
                 "consumes": [
430
                     "application/json"
430
                     "application/json"
431
                 ],
431
                 ],
@@ -433,9 +433,9 @@
433
                     "application/json"
433
                     "application/json"
434
                 ],
434
                 ],
435
                 "tags": [
435
                 "tags": [
436
-                    "链接日志"
436
+                    "文件日志"
437
                 ],
437
                 ],
438
-                "summary": "链接日志列表",
438
+                "summary": "文件日志列表",
439
                 "parameters": [
439
                 "parameters": [
440
                     {
440
                     {
441
                         "type": "integer",
441
                         "type": "integer",
@@ -474,7 +474,7 @@
474
                                     "type": "object",
474
                                     "type": "object",
475
                                     "properties": {
475
                                     "properties": {
476
                                         "data": {
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
                 "name": {
2560
                 "name": {
2561
                     "type": "string"
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
         "model.Group": {
2988
         "model.Group": {
2922
             "type": "object",
2989
             "type": "object",
2923
             "properties": {
2990
             "properties": {

+ 53 - 9
docs/admin/admin_swagger.yaml

@@ -75,6 +75,8 @@ definitions:
75
         type: integer
75
         type: integer
76
       name:
76
       name:
77
         type: string
77
         type: string
78
+      type:
79
+        type: integer
78
     required:
80
     required:
79
     - name
81
     - name
80
     type: object
82
     type: object
@@ -315,6 +317,48 @@ definitions:
315
       total:
317
       total:
316
         type: integer
318
         type: integer
317
     type: object
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
   model.Group:
362
   model.Group:
319
     properties:
363
     properties:
320
       created_at:
364
       created_at:
@@ -765,14 +809,14 @@ paths:
765
     post:
809
     post:
766
       consumes:
810
       consumes:
767
       - application/json
811
       - application/json
768
-      description: 链接日志删除
812
+      description: 文件日志删除
769
       parameters:
813
       parameters:
770
-      - description: 链接日志信息
814
+      - description: 文件日志信息
771
         in: body
815
         in: body
772
         name: body
816
         name: body
773
         required: true
817
         required: true
774
         schema:
818
         schema:
775
-          $ref: '#/definitions/model.AuditConn'
819
+          $ref: '#/definitions/model.AuditFile'
776
       produces:
820
       produces:
777
       - application/json
821
       - application/json
778
       responses:
822
       responses:
@@ -786,14 +830,14 @@ paths:
786
             $ref: '#/definitions/response.Response'
830
             $ref: '#/definitions/response.Response'
787
       security:
831
       security:
788
       - token: []
832
       - token: []
789
-      summary: 链接日志删除
833
+      summary: 文件日志删除
790
       tags:
834
       tags:
791
-      - 链接日志
835
+      - 文件日志
792
   /admin/audit_conn/list:
836
   /admin/audit_conn/list:
793
     get:
837
     get:
794
       consumes:
838
       consumes:
795
       - application/json
839
       - application/json
796
-      description: 链接日志列表
840
+      description: 文件日志列表
797
       parameters:
841
       parameters:
798
       - description: 页码
842
       - description: 页码
799
         in: query
843
         in: query
@@ -821,7 +865,7 @@ paths:
821
             - $ref: '#/definitions/response.Response'
865
             - $ref: '#/definitions/response.Response'
822
             - properties:
866
             - properties:
823
                 data:
867
                 data:
824
-                  $ref: '#/definitions/model.AuditConnList'
868
+                  $ref: '#/definitions/model.AuditFileList'
825
               type: object
869
               type: object
826
         "500":
870
         "500":
827
           description: Internal Server Error
871
           description: Internal Server Error
@@ -829,9 +873,9 @@ paths:
829
             $ref: '#/definitions/response.Response'
873
             $ref: '#/definitions/response.Response'
830
       security:
874
       security:
831
       - token: []
875
       - token: []
832
-      summary: 链接日志列表
876
+      summary: 文件日志列表
833
       tags:
877
       tags:
834
-      - 链接日志
878
+      - 文件日志
835
   /admin/file/oss_token:
879
   /admin/file/oss_token:
836
     get:
880
     get:
837
       consumes:
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
         "/heartbeat": {
770
         "/heartbeat": {
731
             "post": {
771
             "post": {
732
                 "description": "心跳",
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
         "api.DeviceInfoInLogin": {
1328
         "api.DeviceInfoInLogin": {
1263
             "type": "object",
1329
             "type": "object",
1264
             "properties": {
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
         "/heartbeat": {
763
         "/heartbeat": {
724
             "post": {
764
             "post": {
725
                 "description": "心跳",
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
         "api.DeviceInfoInLogin": {
1321
         "api.DeviceInfoInLogin": {
1256
             "type": "object",
1322
             "type": "object",
1257
             "properties": {
1323
             "properties": {

+ 43 - 0
docs/api/api_swagger.yaml

@@ -27,6 +27,23 @@ definitions:
27
       uuid:
27
       uuid:
28
         type: string
28
         type: string
29
     type: object
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
   api.DeviceInfoInLogin:
47
   api.DeviceInfoInLogin:
31
     properties:
48
     properties:
32
       name:
49
       name:
@@ -609,6 +626,32 @@ paths:
609
       summary: 审计连接
626
       summary: 审计连接
610
       tags:
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
   /heartbeat:
655
   /heartbeat:
613
     post:
656
     post:
614
       consumes:
657
       consumes:

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

@@ -67,7 +67,7 @@ func (a *Audit) ConnDelete(c *gin.Context) {
67
 		response.Fail(c, 101, errList[0])
67
 		response.Fail(c, 101, errList[0])
68
 		return
68
 		return
69
 	}
69
 	}
70
-	l := service.AllService.AuditService.InfoById(f.Id)
70
+	l := service.AllService.AuditService.ConnInfoById(f.Id)
71
 	if l.Id > 0 {
71
 	if l.Id > 0 {
72
 		err := service.AllService.AuditService.DeleteAuditConn(l)
72
 		err := service.AllService.AuditService.DeleteAuditConn(l)
73
 		if err == nil {
73
 		if err == nil {
@@ -79,3 +79,70 @@ func (a *Audit) ConnDelete(c *gin.Context) {
79
 	}
79
 	}
80
 	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
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
 		response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
30
 		response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
31
 		return
31
 		return
32
 	}
32
 	}
33
-	//fmt.Println(af)
33
+	/*ttt := &gin.H{}
34
+	c.ShouldBindBodyWith(ttt, binding.JSON)
35
+	fmt.Println(ttt)*/
34
 	ac := af.ToAuditConn()
36
 	ac := af.ToAuditConn()
35
 	if af.Action == model.AuditActionNew {
37
 	if af.Action == model.AuditActionNew {
36
 		service.AllService.AuditService.CreateAuditConn(ac)
38
 		service.AllService.AuditService.CreateAuditConn(ac)
@@ -48,9 +50,35 @@ func (a *Audit) AuditConn(c *gin.Context) {
48
 				FromPeer:  ac.FromPeer,
50
 				FromPeer:  ac.FromPeer,
49
 				FromName:  ac.FromName,
51
 				FromName:  ac.FromName,
50
 				SessionId: ac.SessionId,
52
 				SessionId: ac.SessionId,
53
+				Type:      ac.Type,
51
 			}
54
 			}
52
 			service.AllService.AuditService.UpdateAuditConn(up)
55
 			service.AllService.AuditService.UpdateAuditConn(up)
53
 		}
56
 		}
54
 	}
57
 	}
55
 	response.Success(c, "")
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
 package api
1
 package api
2
 
2
 
3
 import (
3
 import (
4
+	"Gwen/global"
4
 	"Gwen/model"
5
 	"Gwen/model"
6
+	"encoding/json"
5
 	"strconv"
7
 	"strconv"
6
 )
8
 )
7
 
9
 
@@ -38,3 +40,39 @@ func (a *AuditConnForm) ToAuditConn() *model.AuditConn {
38
 		Uuid:      a.Uuid,
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
 	aR := rg.Group("/audit_conn").Use(middleware.AdminPrivilege())
148
 	aR := rg.Group("/audit_conn").Use(middleware.AdminPrivilege())
149
 	aR.GET("/list", cont.ConnList)
149
 	aR.GET("/list", cont.ConnList)
150
 	aR.POST("/delete", cont.ConnDelete)
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
 	au := &api.Audit{}
53
 	au := &api.Audit{}
54
 	//[method:POST] [uri:/api/audit/conn]
54
 	//[method:POST] [uri:/api/audit/conn]
55
 	frg.POST("/audit/conn", au.AuditConn)
55
 	frg.POST("/audit/conn", au.AuditConn)
56
+	//[method:POST] [uri:/api/audit/file]
57
+	frg.POST("/audit/file", au.AuditFile)
56
 	frg.Use(middleware.RustAuth())
58
 	frg.Use(middleware.RustAuth())
57
 	{
59
 	{
58
 		u := &api.User{}
60
 		u := &api.User{}

+ 20 - 0
model/audit.go

@@ -24,3 +24,23 @@ type AuditConnList struct {
24
 	AuditConns []*AuditConn `json:"list"`
24
 	AuditConns []*AuditConn `json:"list"`
25
 	Pagination
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
 	return
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
 	res = &model.AuditConn{}
49
 	res = &model.AuditConn{}
50
 	global.DB.Where("id = ?", id).First(res)
50
 	global.DB.Where("id = ?", id).First(res)
51
 	return
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
+}