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

+ 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 := 220
203
+	version := 233
204 204
 
205 205
 	db := global.DB
206 206
 
@@ -262,6 +262,7 @@ func Migrate(version uint) {
262 262
 		&model.Oauth{},
263 263
 		&model.LoginLog{},
264 264
 		&model.ShareRecord{},
265
+		&model.AuditConn{},
265 266
 	)
266 267
 	if err != nil {
267 268
 		fmt.Println("migrate err :=>", err)

+ 181 - 0
docs/admin/admin_docs.go

@@ -380,6 +380,123 @@ const docTemplateadmin = `{
380 380
                 }
381 381
             }
382 382
         },
383
+        "/admin/audit_conn/delete": {
384
+            "post": {
385
+                "security": [
386
+                    {
387
+                        "token": []
388
+                    }
389
+                ],
390
+                "description": "链接日志删除",
391
+                "consumes": [
392
+                    "application/json"
393
+                ],
394
+                "produces": [
395
+                    "application/json"
396
+                ],
397
+                "tags": [
398
+                    "链接日志"
399
+                ],
400
+                "summary": "链接日志删除",
401
+                "parameters": [
402
+                    {
403
+                        "description": "链接日志信息",
404
+                        "name": "body",
405
+                        "in": "body",
406
+                        "required": true,
407
+                        "schema": {
408
+                            "$ref": "#/definitions/model.AuditConn"
409
+                        }
410
+                    }
411
+                ],
412
+                "responses": {
413
+                    "200": {
414
+                        "description": "OK",
415
+                        "schema": {
416
+                            "$ref": "#/definitions/response.Response"
417
+                        }
418
+                    },
419
+                    "500": {
420
+                        "description": "Internal Server Error",
421
+                        "schema": {
422
+                            "$ref": "#/definitions/response.Response"
423
+                        }
424
+                    }
425
+                }
426
+            }
427
+        },
428
+        "/admin/audit_conn/list": {
429
+            "get": {
430
+                "security": [
431
+                    {
432
+                        "token": []
433
+                    }
434
+                ],
435
+                "description": "链接日志列表",
436
+                "consumes": [
437
+                    "application/json"
438
+                ],
439
+                "produces": [
440
+                    "application/json"
441
+                ],
442
+                "tags": [
443
+                    "链接日志"
444
+                ],
445
+                "summary": "链接日志列表",
446
+                "parameters": [
447
+                    {
448
+                        "type": "integer",
449
+                        "description": "页码",
450
+                        "name": "page",
451
+                        "in": "query"
452
+                    },
453
+                    {
454
+                        "type": "integer",
455
+                        "description": "页大小",
456
+                        "name": "page_size",
457
+                        "in": "query"
458
+                    },
459
+                    {
460
+                        "type": "integer",
461
+                        "description": "目标设备",
462
+                        "name": "peer_id",
463
+                        "in": "query"
464
+                    },
465
+                    {
466
+                        "type": "integer",
467
+                        "description": "来源设备",
468
+                        "name": "from_peer",
469
+                        "in": "query"
470
+                    }
471
+                ],
472
+                "responses": {
473
+                    "200": {
474
+                        "description": "OK",
475
+                        "schema": {
476
+                            "allOf": [
477
+                                {
478
+                                    "$ref": "#/definitions/response.Response"
479
+                                },
480
+                                {
481
+                                    "type": "object",
482
+                                    "properties": {
483
+                                        "data": {
484
+                                            "$ref": "#/definitions/model.AuditConnList"
485
+                                        }
486
+                                    }
487
+                                }
488
+                            ]
489
+                        }
490
+                    },
491
+                    "500": {
492
+                        "description": "Internal Server Error",
493
+                        "schema": {
494
+                            "$ref": "#/definitions/response.Response"
495
+                        }
496
+                    }
497
+                }
498
+            }
499
+        },
383 500
         "/admin/file/oss_token": {
384 501
             "get": {
385 502
                 "security": [
@@ -2744,6 +2861,70 @@ const docTemplateadmin = `{
2744 2861
                 }
2745 2862
             }
2746 2863
         },
2864
+        "model.AuditConn": {
2865
+            "type": "object",
2866
+            "properties": {
2867
+                "action": {
2868
+                    "type": "string"
2869
+                },
2870
+                "close_time": {
2871
+                    "type": "integer"
2872
+                },
2873
+                "conn_id": {
2874
+                    "type": "integer"
2875
+                },
2876
+                "created_at": {
2877
+                    "type": "string"
2878
+                },
2879
+                "from_name": {
2880
+                    "type": "string"
2881
+                },
2882
+                "from_peer": {
2883
+                    "type": "string"
2884
+                },
2885
+                "id": {
2886
+                    "type": "integer"
2887
+                },
2888
+                "ip": {
2889
+                    "type": "string"
2890
+                },
2891
+                "peer_id": {
2892
+                    "type": "string"
2893
+                },
2894
+                "session_id": {
2895
+                    "type": "string"
2896
+                },
2897
+                "type": {
2898
+                    "type": "integer"
2899
+                },
2900
+                "updated_at": {
2901
+                    "type": "string"
2902
+                },
2903
+                "uuid": {
2904
+                    "type": "string"
2905
+                }
2906
+            }
2907
+        },
2908
+        "model.AuditConnList": {
2909
+            "type": "object",
2910
+            "properties": {
2911
+                "list": {
2912
+                    "type": "array",
2913
+                    "items": {
2914
+                        "$ref": "#/definitions/model.AuditConn"
2915
+                    }
2916
+                },
2917
+                "page": {
2918
+                    "type": "integer"
2919
+                },
2920
+                "page_size": {
2921
+                    "type": "integer"
2922
+                },
2923
+                "total": {
2924
+                    "type": "integer"
2925
+                }
2926
+            }
2927
+        },
2747 2928
         "model.Group": {
2748 2929
             "type": "object",
2749 2930
             "properties": {

+ 181 - 0
docs/admin/admin_swagger.json

@@ -373,6 +373,123 @@
373 373
                 }
374 374
             }
375 375
         },
376
+        "/admin/audit_conn/delete": {
377
+            "post": {
378
+                "security": [
379
+                    {
380
+                        "token": []
381
+                    }
382
+                ],
383
+                "description": "链接日志删除",
384
+                "consumes": [
385
+                    "application/json"
386
+                ],
387
+                "produces": [
388
+                    "application/json"
389
+                ],
390
+                "tags": [
391
+                    "链接日志"
392
+                ],
393
+                "summary": "链接日志删除",
394
+                "parameters": [
395
+                    {
396
+                        "description": "链接日志信息",
397
+                        "name": "body",
398
+                        "in": "body",
399
+                        "required": true,
400
+                        "schema": {
401
+                            "$ref": "#/definitions/model.AuditConn"
402
+                        }
403
+                    }
404
+                ],
405
+                "responses": {
406
+                    "200": {
407
+                        "description": "OK",
408
+                        "schema": {
409
+                            "$ref": "#/definitions/response.Response"
410
+                        }
411
+                    },
412
+                    "500": {
413
+                        "description": "Internal Server Error",
414
+                        "schema": {
415
+                            "$ref": "#/definitions/response.Response"
416
+                        }
417
+                    }
418
+                }
419
+            }
420
+        },
421
+        "/admin/audit_conn/list": {
422
+            "get": {
423
+                "security": [
424
+                    {
425
+                        "token": []
426
+                    }
427
+                ],
428
+                "description": "链接日志列表",
429
+                "consumes": [
430
+                    "application/json"
431
+                ],
432
+                "produces": [
433
+                    "application/json"
434
+                ],
435
+                "tags": [
436
+                    "链接日志"
437
+                ],
438
+                "summary": "链接日志列表",
439
+                "parameters": [
440
+                    {
441
+                        "type": "integer",
442
+                        "description": "页码",
443
+                        "name": "page",
444
+                        "in": "query"
445
+                    },
446
+                    {
447
+                        "type": "integer",
448
+                        "description": "页大小",
449
+                        "name": "page_size",
450
+                        "in": "query"
451
+                    },
452
+                    {
453
+                        "type": "integer",
454
+                        "description": "目标设备",
455
+                        "name": "peer_id",
456
+                        "in": "query"
457
+                    },
458
+                    {
459
+                        "type": "integer",
460
+                        "description": "来源设备",
461
+                        "name": "from_peer",
462
+                        "in": "query"
463
+                    }
464
+                ],
465
+                "responses": {
466
+                    "200": {
467
+                        "description": "OK",
468
+                        "schema": {
469
+                            "allOf": [
470
+                                {
471
+                                    "$ref": "#/definitions/response.Response"
472
+                                },
473
+                                {
474
+                                    "type": "object",
475
+                                    "properties": {
476
+                                        "data": {
477
+                                            "$ref": "#/definitions/model.AuditConnList"
478
+                                        }
479
+                                    }
480
+                                }
481
+                            ]
482
+                        }
483
+                    },
484
+                    "500": {
485
+                        "description": "Internal Server Error",
486
+                        "schema": {
487
+                            "$ref": "#/definitions/response.Response"
488
+                        }
489
+                    }
490
+                }
491
+            }
492
+        },
376 493
         "/admin/file/oss_token": {
377 494
             "get": {
378 495
                 "security": [
@@ -2737,6 +2854,70 @@
2737 2854
                 }
2738 2855
             }
2739 2856
         },
2857
+        "model.AuditConn": {
2858
+            "type": "object",
2859
+            "properties": {
2860
+                "action": {
2861
+                    "type": "string"
2862
+                },
2863
+                "close_time": {
2864
+                    "type": "integer"
2865
+                },
2866
+                "conn_id": {
2867
+                    "type": "integer"
2868
+                },
2869
+                "created_at": {
2870
+                    "type": "string"
2871
+                },
2872
+                "from_name": {
2873
+                    "type": "string"
2874
+                },
2875
+                "from_peer": {
2876
+                    "type": "string"
2877
+                },
2878
+                "id": {
2879
+                    "type": "integer"
2880
+                },
2881
+                "ip": {
2882
+                    "type": "string"
2883
+                },
2884
+                "peer_id": {
2885
+                    "type": "string"
2886
+                },
2887
+                "session_id": {
2888
+                    "type": "string"
2889
+                },
2890
+                "type": {
2891
+                    "type": "integer"
2892
+                },
2893
+                "updated_at": {
2894
+                    "type": "string"
2895
+                },
2896
+                "uuid": {
2897
+                    "type": "string"
2898
+                }
2899
+            }
2900
+        },
2901
+        "model.AuditConnList": {
2902
+            "type": "object",
2903
+            "properties": {
2904
+                "list": {
2905
+                    "type": "array",
2906
+                    "items": {
2907
+                        "$ref": "#/definitions/model.AuditConn"
2908
+                    }
2909
+                },
2910
+                "page": {
2911
+                    "type": "integer"
2912
+                },
2913
+                "page_size": {
2914
+                    "type": "integer"
2915
+                },
2916
+                "total": {
2917
+                    "type": "integer"
2918
+                }
2919
+            }
2920
+        },
2740 2921
         "model.Group": {
2741 2922
             "type": "object",
2742 2923
             "properties": {

+ 113 - 0
docs/admin/admin_swagger.yaml

@@ -273,6 +273,48 @@ definitions:
273 273
       total:
274 274
         type: integer
275 275
     type: object
276
+  model.AuditConn:
277
+    properties:
278
+      action:
279
+        type: string
280
+      close_time:
281
+        type: integer
282
+      conn_id:
283
+        type: integer
284
+      created_at:
285
+        type: string
286
+      from_name:
287
+        type: string
288
+      from_peer:
289
+        type: string
290
+      id:
291
+        type: integer
292
+      ip:
293
+        type: string
294
+      peer_id:
295
+        type: string
296
+      session_id:
297
+        type: string
298
+      type:
299
+        type: integer
300
+      updated_at:
301
+        type: string
302
+      uuid:
303
+        type: string
304
+    type: object
305
+  model.AuditConnList:
306
+    properties:
307
+      list:
308
+        items:
309
+          $ref: '#/definitions/model.AuditConn'
310
+        type: array
311
+      page:
312
+        type: integer
313
+      page_size:
314
+        type: integer
315
+      total:
316
+        type: integer
317
+    type: object
276 318
   model.Group:
277 319
     properties:
278 320
       created_at:
@@ -719,6 +761,77 @@ paths:
719 761
       summary: APP服务配置
720 762
       tags:
721 763
       - ADMIN
764
+  /admin/audit_conn/delete:
765
+    post:
766
+      consumes:
767
+      - application/json
768
+      description: 链接日志删除
769
+      parameters:
770
+      - description: 链接日志信息
771
+        in: body
772
+        name: body
773
+        required: true
774
+        schema:
775
+          $ref: '#/definitions/model.AuditConn'
776
+      produces:
777
+      - application/json
778
+      responses:
779
+        "200":
780
+          description: OK
781
+          schema:
782
+            $ref: '#/definitions/response.Response'
783
+        "500":
784
+          description: Internal Server Error
785
+          schema:
786
+            $ref: '#/definitions/response.Response'
787
+      security:
788
+      - token: []
789
+      summary: 链接日志删除
790
+      tags:
791
+      - 链接日志
792
+  /admin/audit_conn/list:
793
+    get:
794
+      consumes:
795
+      - application/json
796
+      description: 链接日志列表
797
+      parameters:
798
+      - description: 页码
799
+        in: query
800
+        name: page
801
+        type: integer
802
+      - description: 页大小
803
+        in: query
804
+        name: page_size
805
+        type: integer
806
+      - description: 目标设备
807
+        in: query
808
+        name: peer_id
809
+        type: integer
810
+      - description: 来源设备
811
+        in: query
812
+        name: from_peer
813
+        type: integer
814
+      produces:
815
+      - application/json
816
+      responses:
817
+        "200":
818
+          description: OK
819
+          schema:
820
+            allOf:
821
+            - $ref: '#/definitions/response.Response'
822
+            - properties:
823
+                data:
824
+                  $ref: '#/definitions/model.AuditConnList'
825
+              type: object
826
+        "500":
827
+          description: Internal Server Error
828
+          schema:
829
+            $ref: '#/definitions/response.Response'
830
+      security:
831
+      - token: []
832
+      summary: 链接日志列表
833
+      tags:
834
+      - 链接日志
722 835
   /admin/file/oss_token:
723 836
     get:
724 837
       consumes:

+ 176 - 54
docs/api/api_docs.go

@@ -121,40 +121,6 @@ const docTemplateapi = `{
121 121
                 }
122 122
             }
123 123
         },
124
-        "/ab/add": {
125
-            "post": {
126
-                "security": [
127
-                    {
128
-                        "BearerAuth": []
129
-                    }
130
-                ],
131
-                "description": "标签",
132
-                "consumes": [
133
-                    "application/json"
134
-                ],
135
-                "produces": [
136
-                    "application/json"
137
-                ],
138
-                "tags": [
139
-                    "地址[Personal]"
140
-                ],
141
-                "summary": "标签添加",
142
-                "responses": {
143
-                    "200": {
144
-                        "description": "OK",
145
-                        "schema": {
146
-                            "type": "string"
147
-                        }
148
-                    },
149
-                    "500": {
150
-                        "description": "Internal Server Error",
151
-                        "schema": {
152
-                            "$ref": "#/definitions/response.ErrorResponse"
153
-                        }
154
-                    }
155
-                }
156
-            }
157
-        },
158 124
         "/ab/peer/add/{guid}": {
159 125
             "post": {
160 126
                 "security": [
@@ -176,8 +142,8 @@ const docTemplateapi = `{
176 142
                 "parameters": [
177 143
                     {
178 144
                         "type": "string",
179
-                        "description": "id",
180
-                        "name": "id",
145
+                        "description": "guid",
146
+                        "name": "guid",
181 147
                         "in": "path",
182 148
                         "required": true
183 149
                     }
@@ -217,8 +183,8 @@ const docTemplateapi = `{
217 183
                 "parameters": [
218 184
                     {
219 185
                         "type": "string",
220
-                        "description": "id",
221
-                        "name": "id",
186
+                        "description": "guid",
187
+                        "name": "guid",
222 188
                         "in": "path",
223 189
                         "required": true
224 190
                     }
@@ -260,8 +226,8 @@ const docTemplateapi = `{
260 226
                 "parameters": [
261 227
                     {
262 228
                         "type": "string",
263
-                        "description": "id",
264
-                        "name": "id",
229
+                        "description": "guid",
230
+                        "name": "guid",
265 231
                         "in": "path",
266 232
                         "required": true
267 233
                     }
@@ -302,12 +268,22 @@ const docTemplateapi = `{
302 268
                 "summary": "地址列表",
303 269
                 "parameters": [
304 270
                     {
305
-                        "description": "string valid",
306
-                        "name": "string",
307
-                        "in": "body",
308
-                        "schema": {
309
-                            "type": "string"
310
-                        }
271
+                        "type": "integer",
272
+                        "description": "页码",
273
+                        "name": "current",
274
+                        "in": "query"
275
+                    },
276
+                    {
277
+                        "type": "integer",
278
+                        "description": "每页数量",
279
+                        "name": "pageSize",
280
+                        "in": "query"
281
+                    },
282
+                    {
283
+                        "type": "string",
284
+                        "description": "guid",
285
+                        "name": "ab",
286
+                        "in": "query"
311 287
                     }
312 288
                 ],
313 289
                 "responses": {
@@ -434,12 +410,16 @@ const docTemplateapi = `{
434 410
                 "summary": "共享地址簿",
435 411
                 "parameters": [
436 412
                     {
437
-                        "description": "string valid",
438
-                        "name": "string",
439
-                        "in": "body",
440
-                        "schema": {
441
-                            "type": "string"
442
-                        }
413
+                        "type": "integer",
414
+                        "description": "页码",
415
+                        "name": "current",
416
+                        "in": "query"
417
+                    },
418
+                    {
419
+                        "type": "integer",
420
+                        "description": "每页数量",
421
+                        "name": "pageSize",
422
+                        "in": "query"
443 423
                     }
444 424
                 ],
445 425
                 "responses": {
@@ -458,6 +438,49 @@ const docTemplateapi = `{
458 438
                 }
459 439
             }
460 440
         },
441
+        "/ab/tag/add/{guid}": {
442
+            "post": {
443
+                "security": [
444
+                    {
445
+                        "BearerAuth": []
446
+                    }
447
+                ],
448
+                "description": "标签",
449
+                "consumes": [
450
+                    "application/json"
451
+                ],
452
+                "produces": [
453
+                    "application/json"
454
+                ],
455
+                "tags": [
456
+                    "地址[Personal]"
457
+                ],
458
+                "summary": "标签添加",
459
+                "parameters": [
460
+                    {
461
+                        "type": "string",
462
+                        "description": "guid",
463
+                        "name": "guid",
464
+                        "in": "path",
465
+                        "required": true
466
+                    }
467
+                ],
468
+                "responses": {
469
+                    "200": {
470
+                        "description": "OK",
471
+                        "schema": {
472
+                            "type": "string"
473
+                        }
474
+                    },
475
+                    "500": {
476
+                        "description": "Internal Server Error",
477
+                        "schema": {
478
+                            "$ref": "#/definitions/response.ErrorResponse"
479
+                        }
480
+                    }
481
+                }
482
+            }
483
+        },
461 484
         "/ab/tag/rename/{guid}": {
462 485
             "put": {
463 486
                 "security": [
@@ -476,6 +499,15 @@ const docTemplateapi = `{
476 499
                     "地址[Personal]"
477 500
                 ],
478 501
                 "summary": "标签重命名",
502
+                "parameters": [
503
+                    {
504
+                        "type": "string",
505
+                        "description": "guid",
506
+                        "name": "guid",
507
+                        "in": "path",
508
+                        "required": true
509
+                    }
510
+                ],
479 511
                 "responses": {
480 512
                     "200": {
481 513
                         "description": "OK",
@@ -510,6 +542,15 @@ const docTemplateapi = `{
510 542
                     "地址[Personal]"
511 543
                 ],
512 544
                 "summary": "标签修改颜色",
545
+                "parameters": [
546
+                    {
547
+                        "type": "string",
548
+                        "description": "guid",
549
+                        "name": "guid",
550
+                        "in": "path",
551
+                        "required": true
552
+                    }
553
+                ],
513 554
                 "responses": {
514 555
                     "200": {
515 556
                         "description": "OK",
@@ -544,6 +585,15 @@ const docTemplateapi = `{
544 585
                     "地址[Personal]"
545 586
                 ],
546 587
                 "summary": "标签删除",
588
+                "parameters": [
589
+                    {
590
+                        "type": "string",
591
+                        "description": "guid",
592
+                        "name": "guid",
593
+                        "in": "path",
594
+                        "required": true
595
+                    }
596
+                ],
547 597
                 "responses": {
548 598
                     "200": {
549 599
                         "description": "OK",
@@ -581,8 +631,8 @@ const docTemplateapi = `{
581 631
                 "parameters": [
582 632
                     {
583 633
                         "type": "string",
584
-                        "description": "id",
585
-                        "name": "id",
634
+                        "description": "guid",
635
+                        "name": "guid",
586 636
                         "in": "path",
587 637
                         "required": true
588 638
                     }
@@ -637,6 +687,46 @@ const docTemplateapi = `{
637 687
                 }
638 688
             }
639 689
         },
690
+        "/audit/conn": {
691
+            "post": {
692
+                "description": "审计连接",
693
+                "consumes": [
694
+                    "application/json"
695
+                ],
696
+                "produces": [
697
+                    "application/json"
698
+                ],
699
+                "tags": [
700
+                    "审计"
701
+                ],
702
+                "summary": "审计连接",
703
+                "parameters": [
704
+                    {
705
+                        "description": "审计连接",
706
+                        "name": "body",
707
+                        "in": "body",
708
+                        "required": true,
709
+                        "schema": {
710
+                            "$ref": "#/definitions/api.AuditConnForm"
711
+                        }
712
+                    }
713
+                ],
714
+                "responses": {
715
+                    "200": {
716
+                        "description": "OK",
717
+                        "schema": {
718
+                            "type": "string"
719
+                        }
720
+                    },
721
+                    "500": {
722
+                        "description": "Internal Server Error",
723
+                        "schema": {
724
+                            "$ref": "#/definitions/response.Response"
725
+                        }
726
+                    }
727
+                }
728
+            }
729
+        },
640 730
         "/heartbeat": {
641 731
             "post": {
642 732
                 "description": "心跳",
@@ -1137,6 +1227,38 @@ const docTemplateapi = `{
1137 1227
                 }
1138 1228
             }
1139 1229
         },
1230
+        "api.AuditConnForm": {
1231
+            "type": "object",
1232
+            "properties": {
1233
+                "action": {
1234
+                    "type": "string"
1235
+                },
1236
+                "conn_id": {
1237
+                    "type": "integer"
1238
+                },
1239
+                "id": {
1240
+                    "type": "string"
1241
+                },
1242
+                "ip": {
1243
+                    "type": "string"
1244
+                },
1245
+                "peer": {
1246
+                    "type": "array",
1247
+                    "items": {
1248
+                        "type": "string"
1249
+                    }
1250
+                },
1251
+                "session_id": {
1252
+                    "type": "number"
1253
+                },
1254
+                "type": {
1255
+                    "type": "integer"
1256
+                },
1257
+                "uuid": {
1258
+                    "type": "string"
1259
+                }
1260
+            }
1261
+        },
1140 1262
         "api.DeviceInfoInLogin": {
1141 1263
             "type": "object",
1142 1264
             "properties": {

+ 176 - 54
docs/api/api_swagger.json

@@ -114,40 +114,6 @@
114 114
                 }
115 115
             }
116 116
         },
117
-        "/ab/add": {
118
-            "post": {
119
-                "security": [
120
-                    {
121
-                        "BearerAuth": []
122
-                    }
123
-                ],
124
-                "description": "标签",
125
-                "consumes": [
126
-                    "application/json"
127
-                ],
128
-                "produces": [
129
-                    "application/json"
130
-                ],
131
-                "tags": [
132
-                    "地址[Personal]"
133
-                ],
134
-                "summary": "标签添加",
135
-                "responses": {
136
-                    "200": {
137
-                        "description": "OK",
138
-                        "schema": {
139
-                            "type": "string"
140
-                        }
141
-                    },
142
-                    "500": {
143
-                        "description": "Internal Server Error",
144
-                        "schema": {
145
-                            "$ref": "#/definitions/response.ErrorResponse"
146
-                        }
147
-                    }
148
-                }
149
-            }
150
-        },
151 117
         "/ab/peer/add/{guid}": {
152 118
             "post": {
153 119
                 "security": [
@@ -169,8 +135,8 @@
169 135
                 "parameters": [
170 136
                     {
171 137
                         "type": "string",
172
-                        "description": "id",
173
-                        "name": "id",
138
+                        "description": "guid",
139
+                        "name": "guid",
174 140
                         "in": "path",
175 141
                         "required": true
176 142
                     }
@@ -210,8 +176,8 @@
210 176
                 "parameters": [
211 177
                     {
212 178
                         "type": "string",
213
-                        "description": "id",
214
-                        "name": "id",
179
+                        "description": "guid",
180
+                        "name": "guid",
215 181
                         "in": "path",
216 182
                         "required": true
217 183
                     }
@@ -253,8 +219,8 @@
253 219
                 "parameters": [
254 220
                     {
255 221
                         "type": "string",
256
-                        "description": "id",
257
-                        "name": "id",
222
+                        "description": "guid",
223
+                        "name": "guid",
258 224
                         "in": "path",
259 225
                         "required": true
260 226
                     }
@@ -295,12 +261,22 @@
295 261
                 "summary": "地址列表",
296 262
                 "parameters": [
297 263
                     {
298
-                        "description": "string valid",
299
-                        "name": "string",
300
-                        "in": "body",
301
-                        "schema": {
302
-                            "type": "string"
303
-                        }
264
+                        "type": "integer",
265
+                        "description": "页码",
266
+                        "name": "current",
267
+                        "in": "query"
268
+                    },
269
+                    {
270
+                        "type": "integer",
271
+                        "description": "每页数量",
272
+                        "name": "pageSize",
273
+                        "in": "query"
274
+                    },
275
+                    {
276
+                        "type": "string",
277
+                        "description": "guid",
278
+                        "name": "ab",
279
+                        "in": "query"
304 280
                     }
305 281
                 ],
306 282
                 "responses": {
@@ -427,12 +403,16 @@
427 403
                 "summary": "共享地址簿",
428 404
                 "parameters": [
429 405
                     {
430
-                        "description": "string valid",
431
-                        "name": "string",
432
-                        "in": "body",
433
-                        "schema": {
434
-                            "type": "string"
435
-                        }
406
+                        "type": "integer",
407
+                        "description": "页码",
408
+                        "name": "current",
409
+                        "in": "query"
410
+                    },
411
+                    {
412
+                        "type": "integer",
413
+                        "description": "每页数量",
414
+                        "name": "pageSize",
415
+                        "in": "query"
436 416
                     }
437 417
                 ],
438 418
                 "responses": {
@@ -451,6 +431,49 @@
451 431
                 }
452 432
             }
453 433
         },
434
+        "/ab/tag/add/{guid}": {
435
+            "post": {
436
+                "security": [
437
+                    {
438
+                        "BearerAuth": []
439
+                    }
440
+                ],
441
+                "description": "标签",
442
+                "consumes": [
443
+                    "application/json"
444
+                ],
445
+                "produces": [
446
+                    "application/json"
447
+                ],
448
+                "tags": [
449
+                    "地址[Personal]"
450
+                ],
451
+                "summary": "标签添加",
452
+                "parameters": [
453
+                    {
454
+                        "type": "string",
455
+                        "description": "guid",
456
+                        "name": "guid",
457
+                        "in": "path",
458
+                        "required": true
459
+                    }
460
+                ],
461
+                "responses": {
462
+                    "200": {
463
+                        "description": "OK",
464
+                        "schema": {
465
+                            "type": "string"
466
+                        }
467
+                    },
468
+                    "500": {
469
+                        "description": "Internal Server Error",
470
+                        "schema": {
471
+                            "$ref": "#/definitions/response.ErrorResponse"
472
+                        }
473
+                    }
474
+                }
475
+            }
476
+        },
454 477
         "/ab/tag/rename/{guid}": {
455 478
             "put": {
456 479
                 "security": [
@@ -469,6 +492,15 @@
469 492
                     "地址[Personal]"
470 493
                 ],
471 494
                 "summary": "标签重命名",
495
+                "parameters": [
496
+                    {
497
+                        "type": "string",
498
+                        "description": "guid",
499
+                        "name": "guid",
500
+                        "in": "path",
501
+                        "required": true
502
+                    }
503
+                ],
472 504
                 "responses": {
473 505
                     "200": {
474 506
                         "description": "OK",
@@ -503,6 +535,15 @@
503 535
                     "地址[Personal]"
504 536
                 ],
505 537
                 "summary": "标签修改颜色",
538
+                "parameters": [
539
+                    {
540
+                        "type": "string",
541
+                        "description": "guid",
542
+                        "name": "guid",
543
+                        "in": "path",
544
+                        "required": true
545
+                    }
546
+                ],
506 547
                 "responses": {
507 548
                     "200": {
508 549
                         "description": "OK",
@@ -537,6 +578,15 @@
537 578
                     "地址[Personal]"
538 579
                 ],
539 580
                 "summary": "标签删除",
581
+                "parameters": [
582
+                    {
583
+                        "type": "string",
584
+                        "description": "guid",
585
+                        "name": "guid",
586
+                        "in": "path",
587
+                        "required": true
588
+                    }
589
+                ],
540 590
                 "responses": {
541 591
                     "200": {
542 592
                         "description": "OK",
@@ -574,8 +624,8 @@
574 624
                 "parameters": [
575 625
                     {
576 626
                         "type": "string",
577
-                        "description": "id",
578
-                        "name": "id",
627
+                        "description": "guid",
628
+                        "name": "guid",
579 629
                         "in": "path",
580 630
                         "required": true
581 631
                     }
@@ -630,6 +680,46 @@
630 680
                 }
631 681
             }
632 682
         },
683
+        "/audit/conn": {
684
+            "post": {
685
+                "description": "审计连接",
686
+                "consumes": [
687
+                    "application/json"
688
+                ],
689
+                "produces": [
690
+                    "application/json"
691
+                ],
692
+                "tags": [
693
+                    "审计"
694
+                ],
695
+                "summary": "审计连接",
696
+                "parameters": [
697
+                    {
698
+                        "description": "审计连接",
699
+                        "name": "body",
700
+                        "in": "body",
701
+                        "required": true,
702
+                        "schema": {
703
+                            "$ref": "#/definitions/api.AuditConnForm"
704
+                        }
705
+                    }
706
+                ],
707
+                "responses": {
708
+                    "200": {
709
+                        "description": "OK",
710
+                        "schema": {
711
+                            "type": "string"
712
+                        }
713
+                    },
714
+                    "500": {
715
+                        "description": "Internal Server Error",
716
+                        "schema": {
717
+                            "$ref": "#/definitions/response.Response"
718
+                        }
719
+                    }
720
+                }
721
+            }
722
+        },
633 723
         "/heartbeat": {
634 724
             "post": {
635 725
                 "description": "心跳",
@@ -1130,6 +1220,38 @@
1130 1220
                 }
1131 1221
             }
1132 1222
         },
1223
+        "api.AuditConnForm": {
1224
+            "type": "object",
1225
+            "properties": {
1226
+                "action": {
1227
+                    "type": "string"
1228
+                },
1229
+                "conn_id": {
1230
+                    "type": "integer"
1231
+                },
1232
+                "id": {
1233
+                    "type": "string"
1234
+                },
1235
+                "ip": {
1236
+                    "type": "string"
1237
+                },
1238
+                "peer": {
1239
+                    "type": "array",
1240
+                    "items": {
1241
+                        "type": "string"
1242
+                    }
1243
+                },
1244
+                "session_id": {
1245
+                    "type": "number"
1246
+                },
1247
+                "type": {
1248
+                    "type": "integer"
1249
+                },
1250
+                "uuid": {
1251
+                    "type": "string"
1252
+                }
1253
+            }
1254
+        },
1133 1255
         "api.DeviceInfoInLogin": {
1134 1256
             "type": "object",
1135 1257
             "properties": {

+ 120 - 39
docs/api/api_swagger.yaml

@@ -6,6 +6,27 @@ definitions:
6 6
         example: '{"tags":["tag1","tag2","tag3"],"peers":[{"id":"abc","username":"abv-l","hostname":"","platform":"Windows","alias":"","tags":["tag1","tag2"],"hash":"hash"}],"tag_colors":"{\"tag1\":4288585374,\"tag2\":4278238420,\"tag3\":4291681337}"}'
7 7
         type: string
8 8
     type: object
9
+  api.AuditConnForm:
10
+    properties:
11
+      action:
12
+        type: string
13
+      conn_id:
14
+        type: integer
15
+      id:
16
+        type: string
17
+      ip:
18
+        type: string
19
+      peer:
20
+        items:
21
+          type: string
22
+        type: array
23
+      session_id:
24
+        type: number
25
+      type:
26
+        type: integer
27
+      uuid:
28
+        type: string
29
+    type: object
9 30
   api.DeviceInfoInLogin:
10 31
     properties:
11 32
       name:
@@ -208,36 +229,15 @@ paths:
208 229
       summary: 地址更新
209 230
       tags:
210 231
       - 地址
211
-  /ab/add:
212
-    post:
213
-      consumes:
214
-      - application/json
215
-      description: 标签
216
-      produces:
217
-      - application/json
218
-      responses:
219
-        "200":
220
-          description: OK
221
-          schema:
222
-            type: string
223
-        "500":
224
-          description: Internal Server Error
225
-          schema:
226
-            $ref: '#/definitions/response.ErrorResponse'
227
-      security:
228
-      - BearerAuth: []
229
-      summary: 标签添加
230
-      tags:
231
-      - 地址[Personal]
232 232
   /ab/peer/add/{guid}:
233 233
     delete:
234 234
       consumes:
235 235
       - application/json
236 236
       description: 删除地址
237 237
       parameters:
238
-      - description: id
238
+      - description: guid
239 239
         in: path
240
-        name: id
240
+        name: guid
241 241
         required: true
242 242
         type: string
243 243
       produces:
@@ -261,9 +261,9 @@ paths:
261 261
       - application/json
262 262
       description: 添加地址
263 263
       parameters:
264
-      - description: id
264
+      - description: guid
265 265
         in: path
266
-        name: id
266
+        name: guid
267 267
         required: true
268 268
         type: string
269 269
       produces:
@@ -288,9 +288,9 @@ paths:
288 288
       - application/json
289 289
       description: 更新地址
290 290
       parameters:
291
-      - description: id
291
+      - description: guid
292 292
         in: path
293
-        name: id
293
+        name: guid
294 294
         required: true
295 295
         type: string
296 296
       produces:
@@ -315,11 +315,18 @@ paths:
315 315
       - application/json
316 316
       description: 地址
317 317
       parameters:
318
-      - description: string valid
319
-        in: body
320
-        name: string
321
-        schema:
322
-          type: string
318
+      - description: 页码
319
+        in: query
320
+        name: current
321
+        type: integer
322
+      - description: 每页数量
323
+        in: query
324
+        name: pageSize
325
+        type: integer
326
+      - description: guid
327
+        in: query
328
+        name: ab
329
+        type: string
323 330
       produces:
324 331
       - application/json
325 332
       responses:
@@ -396,11 +403,14 @@ paths:
396 403
       - application/json
397 404
       description: 共享
398 405
       parameters:
399
-      - description: string valid
400
-        in: body
401
-        name: string
402
-        schema:
403
-          type: string
406
+      - description: 页码
407
+        in: query
408
+        name: current
409
+        type: integer
410
+      - description: 每页数量
411
+        in: query
412
+        name: pageSize
413
+        type: integer
404 414
       produces:
405 415
       - application/json
406 416
       responses:
@@ -422,6 +432,12 @@ paths:
422 432
       consumes:
423 433
       - application/json
424 434
       description: 标签
435
+      parameters:
436
+      - description: guid
437
+        in: path
438
+        name: guid
439
+        required: true
440
+        type: string
425 441
       produces:
426 442
       - application/json
427 443
       responses:
@@ -438,11 +454,44 @@ paths:
438 454
       summary: 标签删除
439 455
       tags:
440 456
       - 地址[Personal]
457
+  /ab/tag/add/{guid}:
458
+    post:
459
+      consumes:
460
+      - application/json
461
+      description: 标签
462
+      parameters:
463
+      - description: guid
464
+        in: path
465
+        name: guid
466
+        required: true
467
+        type: string
468
+      produces:
469
+      - application/json
470
+      responses:
471
+        "200":
472
+          description: OK
473
+          schema:
474
+            type: string
475
+        "500":
476
+          description: Internal Server Error
477
+          schema:
478
+            $ref: '#/definitions/response.ErrorResponse'
479
+      security:
480
+      - BearerAuth: []
481
+      summary: 标签添加
482
+      tags:
483
+      - 地址[Personal]
441 484
   /ab/tag/rename/{guid}:
442 485
     put:
443 486
       consumes:
444 487
       - application/json
445 488
       description: 标签
489
+      parameters:
490
+      - description: guid
491
+        in: path
492
+        name: guid
493
+        required: true
494
+        type: string
446 495
       produces:
447 496
       - application/json
448 497
       responses:
@@ -464,6 +513,12 @@ paths:
464 513
       consumes:
465 514
       - application/json
466 515
       description: 标签
516
+      parameters:
517
+      - description: guid
518
+        in: path
519
+        name: guid
520
+        required: true
521
+        type: string
467 522
       produces:
468 523
       - application/json
469 524
       responses:
@@ -486,9 +541,9 @@ paths:
486 541
       - application/json
487 542
       description: 标签
488 543
       parameters:
489
-      - description: id
544
+      - description: guid
490 545
         in: path
491
-        name: id
546
+        name: guid
492 547
         required: true
493 548
         type: string
494 549
       produces:
@@ -528,6 +583,32 @@ paths:
528 583
       summary: 用户信息
529 584
       tags:
530 585
       - 用户
586
+  /audit/conn:
587
+    post:
588
+      consumes:
589
+      - application/json
590
+      description: 审计连接
591
+      parameters:
592
+      - description: 审计连接
593
+        in: body
594
+        name: body
595
+        required: true
596
+        schema:
597
+          $ref: '#/definitions/api.AuditConnForm'
598
+      produces:
599
+      - application/json
600
+      responses:
601
+        "200":
602
+          description: OK
603
+          schema:
604
+            type: string
605
+        "500":
606
+          description: Internal Server Error
607
+          schema:
608
+            $ref: '#/definitions/response.Response'
609
+      summary: 审计连接
610
+      tags:
611
+      - 审计
531 612
   /heartbeat:
532 613
     post:
533 614
       consumes:

+ 81 - 0
http/controller/admin/audit.go

@@ -0,0 +1,81 @@
1
+package admin
2
+
3
+import (
4
+	"Gwen/global"
5
+	"Gwen/http/request/admin"
6
+	"Gwen/http/response"
7
+	"Gwen/model"
8
+	"Gwen/service"
9
+	"github.com/gin-gonic/gin"
10
+	"gorm.io/gorm"
11
+)
12
+
13
+type Audit struct {
14
+}
15
+
16
+// ConnList 列表
17
+// @Tags 链接日志
18
+// @Summary 链接日志列表
19
+// @Description 链接日志列表
20
+// @Accept  json
21
+// @Produce  json
22
+// @Param page query int false "页码"
23
+// @Param page_size query int false "页大小"
24
+// @Param peer_id query int false "目标设备"
25
+// @Param from_peer query int false "来源设备"
26
+// @Success 200 {object} response.Response{data=model.AuditConnList}
27
+// @Failure 500 {object} response.Response
28
+// @Router /admin/audit_conn/list [get]
29
+// @Security token
30
+func (a *Audit) ConnList(c *gin.Context) {
31
+	query := &admin.AuditQuery{}
32
+	if err := c.ShouldBindQuery(query); err != nil {
33
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
34
+		return
35
+	}
36
+	res := service.AllService.AuditService.AuditConnList(query.Page, query.PageSize, func(tx *gorm.DB) {
37
+		if query.PeerId != "" {
38
+			tx.Where("peer_id like ?", "%"+query.PeerId+"%")
39
+		}
40
+		if query.FromPeer != "" {
41
+			tx.Where("from_peer like ?", "%"+query.FromPeer+"%")
42
+		}
43
+	})
44
+	response.Success(c, res)
45
+}
46
+
47
+// ConnDelete 删除
48
+// @Tags 链接日志
49
+// @Summary 链接日志删除
50
+// @Description 链接日志删除
51
+// @Accept  json
52
+// @Produce  json
53
+// @Param body body model.AuditConn true "链接日志信息"
54
+// @Success 200 {object} response.Response
55
+// @Failure 500 {object} response.Response
56
+// @Router /admin/audit_conn/delete [post]
57
+// @Security token
58
+func (a *Audit) ConnDelete(c *gin.Context) {
59
+	f := &model.AuditConn{}
60
+	if err := c.ShouldBindJSON(f); err != nil {
61
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
62
+		return
63
+	}
64
+	id := f.Id
65
+	errList := global.Validator.ValidVar(c, id, "required,gt=0")
66
+	if len(errList) > 0 {
67
+		response.Fail(c, 101, errList[0])
68
+		return
69
+	}
70
+	l := service.AllService.AuditService.InfoById(f.Id)
71
+	if l.Id > 0 {
72
+		err := service.AllService.AuditService.DeleteAuditConn(l)
73
+		if err == nil {
74
+			response.Success(c, nil)
75
+			return
76
+		}
77
+		response.Fail(c, 101, err.Error())
78
+		return
79
+	}
80
+	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
81
+}

+ 18 - 10
http/controller/api/ab.go

@@ -118,9 +118,10 @@ func (a *Ab) Tags(c *gin.Context) {
118 118
 // @Description 标签
119 119
 // @Accept  json
120 120
 // @Produce  json
121
+// @Param guid path string true "guid"
121 122
 // @Success 200 {string} string
122 123
 // @Failure 500 {object} response.ErrorResponse
123
-// @Router /ab/add [post]
124
+// @Router /ab/tag/add/{guid} [post]
124 125
 // @Security BearerAuth
125 126
 func (a *Ab) TagAdd(c *gin.Context) {
126 127
 	t := &model.Tag{}
@@ -150,6 +151,7 @@ func (a *Ab) TagAdd(c *gin.Context) {
150 151
 // @Description 标签
151 152
 // @Accept  json
152 153
 // @Produce  json
154
+// @Param guid path string true "guid"
153 155
 // @Success 200 {string} string
154 156
 // @Failure 500 {object} response.ErrorResponse
155 157
 // @Router /ab/tag/rename/{guid} [put]
@@ -187,6 +189,7 @@ func (a *Ab) TagRename(c *gin.Context) {
187 189
 // @Description 标签
188 190
 // @Accept  json
189 191
 // @Produce  json
192
+// @Param guid path string true "guid"
190 193
 // @Success 200 {string} string
191 194
 // @Failure 500 {object} response.ErrorResponse
192 195
 // @Router /ab/tag/update/{guid} [put]
@@ -219,6 +222,7 @@ func (a *Ab) TagUpdate(c *gin.Context) {
219 222
 // @Description 标签
220 223
 // @Accept  json
221 224
 // @Produce  json
225
+// @Param guid path string true "guid"
222 226
 // @Success 200 {string} string
223 227
 // @Failure 500 {object} response.ErrorResponse
224 228
 // @Router /ab/tag/{guid} [delete]
@@ -273,7 +277,7 @@ func (a *Ab) Personal(c *gin.Context) {
273 277
 		c.JSON(http.StatusOK, gin.H{
274 278
 			"guid": guid,
275 279
 			"name": user.Username,
276
-			"rule": 0,
280
+			"rule": 3,
277 281
 		})
278 282
 	} else {
279 283
 		c.JSON(http.StatusOK, nil)
@@ -304,7 +308,8 @@ func (a *Ab) Settings(c *gin.Context) {
304 308
 // @Description 共享
305 309
 // @Accept  json
306 310
 // @Produce  json
307
-// @Param string body string false  "string valid"
311
+// @Param current query int false "页码"
312
+// @Param pageSize query int false "每页数量"
308 313
 // @Success 200 {object} response.Response
309 314
 // @Failure 500 {object} response.Response
310 315
 // @Router /ab/shared/profiles [post]
@@ -322,14 +327,14 @@ func (a *Ab) SharedProfiles(c *gin.Context) {
322 327
 		"name":  "admin",
323 328
 		"owner": "admin",
324 329
 		"note":  "admin11",
325
-		"rule":  0,
330
+		"rule":  3,
326 331
 	}
327 332
 	item2 := map[string]interface{}{
328 333
 		"guid":  "2",
329 334
 		"name":  "admin2",
330 335
 		"owner": "admin2",
331 336
 		"note":  "admin22",
332
-		"rule":  0,
337
+		"rule":  2,
333 338
 	}
334 339
 	c.JSON(http.StatusOK, gin.H{
335 340
 		"total": 2,
@@ -348,7 +353,9 @@ func (a *Ab) SharedProfiles(c *gin.Context) {
348 353
 // @Description 地址
349 354
 // @Accept  json
350 355
 // @Produce  json
351
-// @Param string body string false  "string valid"
356
+// @Param current query int false "页码"
357
+// @Param pageSize query int false "每页数量"
358
+// @Param ab query string false "guid"
352 359
 // @Success 200 {object} response.Response
353 360
 // @Failure 500 {object} response.Response
354 361
 // @Router /ab/peers [post]
@@ -369,7 +376,7 @@ func (a *Ab) Peers(c *gin.Context) {
369 376
 // @Description 标签
370 377
 // @Accept  json
371 378
 // @Produce  json
372
-// @Param id path string true "id"
379
+// @Param guid path string true "guid"
373 380
 // @Success 200 {object} model.TagList
374 381
 // @Failure 500 {object} response.ErrorResponse
375 382
 // @Router /ab/tags/{guid} [post]
@@ -387,7 +394,7 @@ func (a *Ab) PTags(c *gin.Context) {
387 394
 // @Description 添加地址
388 395
 // @Accept  json
389 396
 // @Produce  json
390
-// @Param id path string true "id"
397
+// @Param guid path string true "guid"
391 398
 // @Success 200 {string} string
392 399
 // @Failure 500 {object} response.ErrorResponse
393 400
 // @Router /ab/peer/add/{guid} [post]
@@ -395,6 +402,7 @@ func (a *Ab) PTags(c *gin.Context) {
395 402
 func (a *Ab) PeerAdd(c *gin.Context) {
396 403
 	// forceAlwaysRelay永远是字符串"false"
397 404
 	//f := &gin.H{}
405
+	//guid := c.Param("guid")
398 406
 	f := &requstform.PersonalAddressBookForm{}
399 407
 	err := c.ShouldBindJSON(f)
400 408
 	if err != nil {
@@ -429,7 +437,7 @@ func (a *Ab) PeerAdd(c *gin.Context) {
429 437
 // @Description 删除地址
430 438
 // @Accept  json
431 439
 // @Produce  json
432
-// @Param id path string true "id"
440
+// @Param guid path string true "guid"
433 441
 // @Success 200 {string} string
434 442
 // @Failure 500 {object} response.ErrorResponse
435 443
 // @Router /ab/peer/add/{guid} [delete]
@@ -464,7 +472,7 @@ func (a *Ab) PeerDel(c *gin.Context) {
464 472
 // @Description 更新地址
465 473
 // @Accept  json
466 474
 // @Produce  json
467
-// @Param id path string true "id"
475
+// @Param guid path string true "guid"
468 476
 // @Success 200 {string} string
469 477
 // @Failure 500 {object} response.ErrorResponse
470 478
 // @Router /ab/peer/update/{guid} [put]

+ 56 - 0
http/controller/api/audit.go

@@ -0,0 +1,56 @@
1
+package api
2
+
3
+import (
4
+	request "Gwen/http/request/api"
5
+	"Gwen/http/response"
6
+	"Gwen/model"
7
+	"Gwen/service"
8
+	"github.com/gin-gonic/gin"
9
+	"github.com/gin-gonic/gin/binding"
10
+	"time"
11
+)
12
+
13
+type Audit struct {
14
+}
15
+
16
+// AuditConn
17
+// @Tags 审计
18
+// @Summary 审计连接
19
+// @Description 审计连接
20
+// @Accept  json
21
+// @Produce  json
22
+// @Param body body request.AuditConnForm true "审计连接"
23
+// @Success 200 {string} string ""
24
+// @Failure 500 {object} response.Response
25
+// @Router /audit/conn [post]
26
+func (a *Audit) AuditConn(c *gin.Context) {
27
+	af := &request.AuditConnForm{}
28
+	err := c.ShouldBindBodyWith(af, binding.JSON)
29
+	if err != nil {
30
+		response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
31
+		return
32
+	}
33
+	//fmt.Println(af)
34
+	ac := af.ToAuditConn()
35
+	if af.Action == model.AuditActionNew {
36
+		service.AllService.AuditService.CreateAuditConn(ac)
37
+	} else if af.Action == model.AuditActionClose {
38
+		ex := service.AllService.AuditService.InfoByPeerIdAndConnId(af.Id, af.ConnId)
39
+		if ex.Id != 0 {
40
+			ex.CloseTime = time.Now().Unix()
41
+			service.AllService.AuditService.UpdateAuditConn(ex)
42
+		}
43
+	} else if af.Action == "" {
44
+		ex := service.AllService.AuditService.InfoByPeerIdAndConnId(af.Id, af.ConnId)
45
+		if ex.Id != 0 {
46
+			up := &model.AuditConn{
47
+				IdModel:   model.IdModel{Id: ex.Id},
48
+				FromPeer:  ac.FromPeer,
49
+				FromName:  ac.FromName,
50
+				SessionId: ac.SessionId,
51
+			}
52
+			service.AllService.AuditService.UpdateAuditConn(up)
53
+		}
54
+	}
55
+	response.Success(c, "")
56
+}

+ 1 - 1
http/controller/api/user.go

@@ -22,7 +22,7 @@ type User struct {
22 22
 // @Security token
23 23
 //func (u *User) currentUser(c *gin.Context) {
24 24
 //	user := service.AllService.UserService.CurUser(c)
25
-//	up := (&apiResp.UserPayload{}).FromUser(user)
25
+//	up := (&apiResp.UserPayload{}).FromName(user)
26 26
 //	c.JSON(http.StatusOK, up)
27 27
 //}
28 28
 

+ 7 - 0
http/request/admin/audit.go

@@ -0,0 +1,7 @@
1
+package admin
2
+
3
+type AuditQuery struct {
4
+	PeerId   string `form:"peer_id"`
5
+	FromPeer string `form:"from_peer"`
6
+	PageQuery
7
+}

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

@@ -0,0 +1,40 @@
1
+package api
2
+
3
+import (
4
+	"Gwen/model"
5
+	"strconv"
6
+)
7
+
8
+type AuditConnForm struct {
9
+	Action    string   `json:"action"`
10
+	ConnId    int64    `json:"conn_id"`
11
+	Id        string   `json:"id"`
12
+	Peer      []string `json:"peer"`
13
+	Ip        string   `json:"ip"`
14
+	SessionId float64  `json:"session_id"`
15
+	Type      int      `json:"type"`
16
+	Uuid      string   `json:"uuid"`
17
+}
18
+
19
+func (a *AuditConnForm) ToAuditConn() *model.AuditConn {
20
+	fp := ""
21
+	fn := ""
22
+	if len(a.Peer) >= 1 {
23
+		fp = a.Peer[0]
24
+		if len(a.Peer) == 2 {
25
+			fn = a.Peer[1]
26
+		}
27
+	}
28
+	ssid := strconv.FormatFloat(a.SessionId, 'f', -1, 64)
29
+	return &model.AuditConn{
30
+		Action:    a.Action,
31
+		ConnId:    a.ConnId,
32
+		PeerId:    a.Id,
33
+		FromPeer:  fp,
34
+		FromName:  fn,
35
+		Ip:        a.Ip,
36
+		SessionId: ssid,
37
+		Type:      a.Type,
38
+		Uuid:      a.Uuid,
39
+	}
40
+}

+ 7 - 1
http/router/admin.go

@@ -27,7 +27,7 @@ func Init(g *gin.Engine) {
27 27
 	PeerBind(adg)
28 28
 	OauthBind(adg)
29 29
 	LoginLogBind(adg)
30
-
30
+	AuditBind(adg)
31 31
 	rs := &admin.Rustdesk{}
32 32
 	adg.GET("/server-config", rs.ServerConfig)
33 33
 	adg.GET("/app-config", rs.AppConfig)
@@ -143,6 +143,12 @@ func LoginLogBind(rg *gin.RouterGroup) {
143 143
 	aR.GET("/list", cont.List)
144 144
 	aR.POST("/delete", cont.Delete)
145 145
 }
146
+func AuditBind(rg *gin.RouterGroup) {
147
+	cont := &admin.Audit{}
148
+	aR := rg.Group("/audit_conn").Use(middleware.AdminPrivilege())
149
+	aR.GET("/list", cont.ConnList)
150
+	aR.POST("/delete", cont.ConnDelete)
151
+}
146 152
 
147 153
 /*
148 154
 func FileBind(rg *gin.RouterGroup) {

+ 3 - 1
http/router/api.go

@@ -50,7 +50,9 @@ func ApiInit(g *gin.Engine) {
50 50
 	if global.Config.App.WebClient == 1 {
51 51
 		WebClientRoutes(frg)
52 52
 	}
53
-
53
+	au := &api.Audit{}
54
+	//[method:POST] [uri:/api/audit/conn]
55
+	frg.POST("/audit/conn", au.AuditConn)
54 56
 	frg.Use(middleware.RustAuth())
55 57
 	{
56 58
 		u := &api.User{}

+ 26 - 0
model/audit.go

@@ -0,0 +1,26 @@
1
+package model
2
+
3
+const (
4
+	AuditActionNew   = "new"
5
+	AuditActionClose = "close"
6
+)
7
+
8
+type AuditConn struct {
9
+	IdModel
10
+	Action    string `json:"action" gorm:"default:'';not null;"`
11
+	ConnId    int64  `json:"conn_id" gorm:"default:0;not null;index"`
12
+	PeerId    string `json:"peer_id" gorm:"default:'';not null;index"`
13
+	FromPeer  string `json:"from_peer" gorm:"default:'';not null;"`
14
+	FromName  string `json:"from_name" gorm:"default:'';not null;"`
15
+	Ip        string `json:"ip" gorm:"default:'';not null;"`
16
+	SessionId string `json:"session_id" gorm:"default:'';not null;"`
17
+	Type      int    `json:"type" gorm:"default:0;not null;"`
18
+	Uuid      string `json:"uuid" gorm:"default:'';not null;"`
19
+	CloseTime int64  `json:"close_time" gorm:"default:0;not null;"`
20
+	TimeModel
21
+}
22
+
23
+type AuditConnList struct {
24
+	AuditConns []*AuditConn `json:"list"`
25
+	Pagination
26
+}

+ 52 - 0
service/audit.go

@@ -0,0 +1,52 @@
1
+package service
2
+
3
+import (
4
+	"Gwen/global"
5
+	"Gwen/model"
6
+	"gorm.io/gorm"
7
+)
8
+
9
+type AuditService struct {
10
+}
11
+
12
+func (as *AuditService) AuditConnList(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AuditConnList) {
13
+	res = &model.AuditConnList{}
14
+	res.Page = int64(page)
15
+	res.PageSize = int64(pageSize)
16
+	tx := global.DB.Model(&model.AuditConn{})
17
+	if where != nil {
18
+		where(tx)
19
+	}
20
+	tx.Count(&res.Total)
21
+	tx.Scopes(Paginate(page, pageSize))
22
+	tx.Find(&res.AuditConns)
23
+	return
24
+}
25
+
26
+// Create 创建
27
+func (as *AuditService) CreateAuditConn(u *model.AuditConn) error {
28
+	res := global.DB.Create(u).Error
29
+	return res
30
+}
31
+func (as *AuditService) DeleteAuditConn(u *model.AuditConn) error {
32
+	return global.DB.Delete(u).Error
33
+}
34
+
35
+// Update 更新
36
+func (as *AuditService) UpdateAuditConn(u *model.AuditConn) error {
37
+	return global.DB.Model(u).Updates(u).Error
38
+}
39
+
40
+// InfoByPeerIdAndConnId
41
+func (as *AuditService) InfoByPeerIdAndConnId(peerId string, connId int64) (res *model.AuditConn) {
42
+	res = &model.AuditConn{}
43
+	global.DB.Where("peer_id = ? and conn_id = ?", peerId, connId).First(res)
44
+	return
45
+}
46
+
47
+// InfoById
48
+func (as *AuditService) InfoById(id uint) (res *model.AuditConn) {
49
+	res = &model.AuditConn{}
50
+	global.DB.Where("id = ?", id).First(res)
51
+	return
52
+}

+ 7 - 8
service/oauth.go

@@ -7,7 +7,6 @@ import (
7 7
 	"context"
8 8
 	"encoding/json"
9 9
 	"errors"
10
-	"fmt"
11 10
 	"golang.org/x/oauth2"
12 11
 	"golang.org/x/oauth2/github"
13 12
 	"golang.org/x/oauth2/google"
@@ -174,7 +173,7 @@ func (os *OauthService) GithubCallback(code string) (error error, userData *Gith
174 173
 	}
175 174
 	token, err := oauthConfig.Exchange(context.Background(), code)
176 175
 	if err != nil {
177
-		global.Logger.Warn(fmt.Printf("oauthConfig.Exchange() failed: %s\n", err))
176
+		global.Logger.Warn("oauthConfig.Exchange() failed: ", err)
178 177
 		error = errors.New("GetOauthTokenError")
179 178
 		return
180 179
 	}
@@ -183,20 +182,20 @@ func (os *OauthService) GithubCallback(code string) (error error, userData *Gith
183 182
 	client := oauthConfig.Client(context.Background(), token)
184 183
 	resp, err := client.Get("https://api.github.com/user")
185 184
 	if err != nil {
186
-		global.Logger.Warn("failed getting user info: %s\n", err)
185
+		global.Logger.Warn("failed getting user info: ", err)
187 186
 		error = errors.New("GetOauthUserInfoError")
188 187
 		return
189 188
 	}
190 189
 	defer func(Body io.ReadCloser) {
191 190
 		err := Body.Close()
192 191
 		if err != nil {
193
-			global.Logger.Warn("failed closing response body: %s\n", err)
192
+			global.Logger.Warn("failed closing response body: ", err)
194 193
 		}
195 194
 	}(resp.Body)
196 195
 
197 196
 	// 在这里处理 GitHub 用户信息
198 197
 	if err = json.NewDecoder(resp.Body).Decode(&userData); err != nil {
199
-		global.Logger.Warn("failed decoding user info: %s\n", err)
198
+		global.Logger.Warn("failed decoding user info: ", err)
200 199
 		error = errors.New("DecodeOauthUserInfoError")
201 200
 		return
202 201
 	}
@@ -207,7 +206,7 @@ func (os *OauthService) GoogleCallback(code string) (error error, userData *Goog
207 206
 	err, oauthConfig := os.GetOauthConfig(model.OauthTypeGoogle)
208 207
 	token, err := oauthConfig.Exchange(context.Background(), code)
209 208
 	if err != nil {
210
-		global.Logger.Warn(fmt.Printf("oauthConfig.Exchange() failed: %s\n", err))
209
+		global.Logger.Warn("oauthConfig.Exchange() failed: ", err)
211 210
 		error = errors.New("GetOauthTokenError")
212 211
 		return
213 212
 	}
@@ -215,14 +214,14 @@ func (os *OauthService) GoogleCallback(code string) (error error, userData *Goog
215 214
 	client := oauthConfig.Client(context.Background(), token)
216 215
 	resp, err := client.Get("https://www.googleapis.com/oauth2/v2/userinfo")
217 216
 	if err != nil {
218
-		global.Logger.Warn("failed getting user info: %s\n", err)
217
+		global.Logger.Warn("failed getting user info: ", err)
219 218
 		error = errors.New("GetOauthUserInfoError")
220 219
 		return
221 220
 	}
222 221
 	defer func(Body io.ReadCloser) {
223 222
 		err := Body.Close()
224 223
 		if err != nil {
225
-			global.Logger.Warn("failed closing response body: %s\n", err)
224
+			global.Logger.Warn("failed closing response body: ", err)
226 225
 		}
227 226
 	}(resp.Body)
228 227
 

+ 1 - 0
service/service.go

@@ -15,6 +15,7 @@ type Service struct {
15 15
 	*GroupService
16 16
 	*OauthService
17 17
 	*LoginLogService
18
+	*AuditService
18 19
 }
19 20
 
20 21
 func New() *Service {

+ 5 - 0
service/user.go

@@ -21,6 +21,11 @@ func (us *UserService) InfoById(id uint) *model.User {
21 21
 	global.DB.Where("id = ?", id).First(u)
22 22
 	return u
23 23
 }
24
+func (us *UserService) InfoByUsername(un string) *model.User {
25
+	u := &model.User{}
26
+	global.DB.Where("username = ?", un).First(u)
27
+	return u
28
+}
24 29
 
25 30
 // InfoByOpenid 根据openid取用户信息
26 31
 func (us *UserService) InfoByOpenid(openid string) *model.User {