@@ -270,6 +270,22 @@ func Connect(c *gin.Context) {
270
270
}
271
271
}
272
272
273
+ var con models.Connection
274
+ con .UserID = userID .(uint )
275
+ con .ServerID = server .ID
276
+ con .ServerCountry = server .Country
277
+ if err := con .Create (); err != nil {
278
+ logger .Log (logger.Fields {
279
+ Loc : "/server/connect/:id - Connect()" ,
280
+ Code : errors .InternalServerError .Code ,
281
+ Extra : map [string ]interface {}{
282
+ "UserID" : con .UserID ,
283
+ "Detail" : "Could not add connection request to db" ,
284
+ },
285
+ Err : err .Error (),
286
+ })
287
+ }
288
+
273
289
c .JSON (http .StatusOK , gin.H {
274
290
"status" : 200 ,
275
291
"data" : gin.H {
@@ -282,6 +298,66 @@ func Connect(c *gin.Context) {
282
298
283
299
}
284
300
301
+ // FreeConnect returns a username and password for the server
302
+ func FreeConnect (c * gin.Context ) {
303
+ serverID , _ := strconv .ParseUint (c .Param ("id" ), 10 , 64 )
304
+ var server models.Server
305
+ server .ID = uint (serverID )
306
+ if err := server .Find (); err != nil {
307
+ logger .Log (logger.Fields {
308
+ Loc : "/server/:id - Server()" ,
309
+ Code : errors .ServerNotFound .Code ,
310
+ Extra : map [string ]interface {}{"ConnID" : c .Param ("id" )},
311
+ Err : err .Error (),
312
+ })
313
+ c .AbortWithStatusJSON (errors .ServerNotFound .Status , errors .ServerNotFound )
314
+ return
315
+ }
316
+
317
+ c .JSON (http .StatusOK , gin.H {
318
+ "status" : 200 ,
319
+ "data" : gin.H {
320
+ "username" : server .Username ,
321
+ "password" : server .Password ,
322
+ "port" : server .Port ,
323
+ "ip" : server .IP ,
324
+ },
325
+ })
326
+
327
+ }
328
+
329
+ // Connections returns an array of all server connections
330
+ func Connections (c * gin.Context ) {
331
+ offset , _ := strconv .Atoi (c .Query ("offset" ))
332
+ var connections models.AllConnections
333
+ if err := connections .FindAll (offset ); err != nil {
334
+ logger .Log (logger.Fields {
335
+ Loc : "/servers - Connections()" ,
336
+ Code : errors .InternalServerError .Code ,
337
+ Err : err .Error (),
338
+ })
339
+ c .AbortWithStatusJSON (errors .InternalServerError .Status , errors .InternalServerError )
340
+ }
341
+
342
+ count , err := connections .Count ()
343
+ if err != nil {
344
+ logger .Log (logger.Fields {
345
+ Loc : "/servers - Connections()" ,
346
+ Code : errors .InternalServerError .Code ,
347
+ Err : err .Error (),
348
+ })
349
+ c .AbortWithStatusJSON (errors .InternalServerError .Status , errors .InternalServerError )
350
+ }
351
+
352
+ c .JSON (http .StatusOK , gin.H {
353
+ "status" : 200 ,
354
+ "data" : gin.H {
355
+ "count" : count ,
356
+ "connections" : connections ,
357
+ },
358
+ })
359
+ }
360
+
285
361
// AllServers returns an array of all available servers
286
362
func AllServers (c * gin.Context ) {
287
363
var servers models.AllServers
0 commit comments