@@ -27,12 +27,15 @@ import (
27
27
// * "dbname" is the name of the database
28
28
func branchesHandler (w http.ResponseWriter , r * http.Request ) {
29
29
// Do auth check, grab request info
30
- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
30
+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
31
31
if err != nil {
32
32
jsonErr (w , err .Error (), httpStatus )
33
33
return
34
34
}
35
35
36
+ // Record the api call in our backend database
37
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "branches" , r .Header .Get ("User-Agent" ))
38
+
36
39
// If the database is a live database, we return an error message
37
40
isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
38
41
if err != nil {
@@ -102,6 +105,9 @@ func columnsHandler(w http.ResponseWriter, r *http.Request) {
102
105
return
103
106
}
104
107
108
+ // Record the api call in our backend database
109
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "columns" , r .Header .Get ("User-Agent" ))
110
+
105
111
// Extract the table name
106
112
table , err := com .GetFormTable (r , false )
107
113
if err != nil {
@@ -221,12 +227,15 @@ func columnsHandler(w http.ResponseWriter, r *http.Request) {
221
227
// * "dbname" is the name of the database
222
228
func commitsHandler (w http.ResponseWriter , r * http.Request ) {
223
229
// Do auth check, grab request info
224
- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
230
+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
225
231
if err != nil {
226
232
jsonErr (w , err .Error (), httpStatus )
227
233
return
228
234
}
229
235
236
+ // Record the api call in our backend database
237
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "commits" , r .Header .Get ("User-Agent" ))
238
+
230
239
// If the database is a live database, we return an error message
231
240
isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
232
241
if err != nil {
@@ -271,6 +280,9 @@ func databasesHandler(w http.ResponseWriter, r *http.Request) {
271
280
return
272
281
}
273
282
283
+ // Record the api call in our backend database
284
+ com .ApiCallLog (loggedInUser , "" , "" , "databases" , r .Header .Get ("User-Agent" ))
285
+
274
286
// Get "live" boolean value, if provided by the caller
275
287
var live bool
276
288
live , err = com .GetFormLive (r )
@@ -336,6 +348,9 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
336
348
}
337
349
dbOwner := loggedInUser
338
350
351
+ // Record the api call in our backend database
352
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "delete" , r .Header .Get ("User-Agent" ))
353
+
339
354
// Check if the database exists
340
355
exists , err := com .CheckDBPermissions (loggedInUser , dbOwner , dbName , false )
341
356
if err != nil {
@@ -517,6 +532,10 @@ func diffHandler(w http.ResponseWriter, r *http.Request) {
517
532
return
518
533
}
519
534
535
+ // Record the api call in our backend database
536
+ // Note - Lets not bother adding additional api logging fields just for the diff function at this stage
537
+ com .ApiCallLog (loggedInUser , dbOwnerA , dbNameA , "diff" , r .Header .Get ("User-Agent" ))
538
+
520
539
// Check permissions of the first database
521
540
var allowed bool
522
541
allowed , err = com .CheckDBPermissions (loggedInUser , dbOwnerA , dbNameA , false )
@@ -593,6 +612,9 @@ func downloadHandler(w http.ResponseWriter, r *http.Request) {
593
612
return
594
613
}
595
614
615
+ // Record the api call in our backend database
616
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "download" , r .Header .Get ("User-Agent" ))
617
+
596
618
// Return the requested database to the user
597
619
_ , err = com .DownloadDatabase (w , r , dbOwner , dbName , commitID , loggedInUser , "api" )
598
620
if err != nil {
@@ -630,6 +652,9 @@ func executeHandler(w http.ResponseWriter, r *http.Request) {
630
652
return
631
653
}
632
654
655
+ // Record the api call in our backend database
656
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "execute" , r .Header .Get ("User-Agent" ))
657
+
633
658
// Grab the incoming SQLite query
634
659
rawInput := r .FormValue ("sql" )
635
660
var sql string
@@ -709,6 +734,9 @@ func indexesHandler(w http.ResponseWriter, r *http.Request) {
709
734
return
710
735
}
711
736
737
+ // Record the api call in our backend database
738
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "indexes" , r .Header .Get ("User-Agent" ))
739
+
712
740
// Check if the database is a live database, and get the node/queue to send the request to
713
741
isLive , liveNode , err := com .CheckDBLive (dbOwner , dbName )
714
742
if err != nil {
@@ -826,12 +854,15 @@ func indexesHandler(w http.ResponseWriter, r *http.Request) {
826
854
// * "dbname" is the name of the database
827
855
func metadataHandler (w http.ResponseWriter , r * http.Request ) {
828
856
// Do auth check, grab request info
829
- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
857
+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
830
858
if err != nil {
831
859
jsonErr (w , err .Error (), httpStatus )
832
860
return
833
861
}
834
862
863
+ // Record the api call in our backend database
864
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "metadata" , r .Header .Get ("User-Agent" ))
865
+
835
866
// If the database is a live database, we return an error message
836
867
isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
837
868
if err != nil {
@@ -886,6 +917,9 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
886
917
return
887
918
}
888
919
920
+ // Record the api call in our backend database
921
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "query" , r .Header .Get ("User-Agent" ))
922
+
889
923
// Grab the incoming SQLite query
890
924
rawInput := r .FormValue ("sql" )
891
925
query , err := com .CheckUnicode (rawInput )
@@ -958,12 +992,15 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
958
992
// * "dbname" is the name of the database
959
993
func releasesHandler (w http.ResponseWriter , r * http.Request ) {
960
994
// Do auth check, grab request info
961
- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
995
+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
962
996
if err != nil {
963
997
jsonErr (w , err .Error (), httpStatus )
964
998
return
965
999
}
966
1000
1001
+ // Record the api call in our backend database
1002
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "releases" , r .Header .Get ("User-Agent" ))
1003
+
967
1004
// If the database is a live database, we return an error message
968
1005
isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
969
1006
if err != nil {
@@ -1033,6 +1070,9 @@ func tablesHandler(w http.ResponseWriter, r *http.Request) {
1033
1070
return
1034
1071
}
1035
1072
1073
+ // Record the api call in our backend database
1074
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "tables" , r .Header .Get ("User-Agent" ))
1075
+
1036
1076
// Check if the database is a live database, and get the node/queue to send the request to
1037
1077
isLive , liveNode , err := com .CheckDBLive (dbOwner , dbName )
1038
1078
if err != nil {
@@ -1108,12 +1148,15 @@ func tablesHandler(w http.ResponseWriter, r *http.Request) {
1108
1148
// * "dbname" is the name of the database
1109
1149
func tagsHandler (w http.ResponseWriter , r * http.Request ) {
1110
1150
// Do auth check, grab request info
1111
- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
1151
+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
1112
1152
if err != nil {
1113
1153
jsonErr (w , err .Error (), httpStatus )
1114
1154
return
1115
1155
}
1116
1156
1157
+ // Record the api call in our backend database
1158
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "tags" , r .Header .Get ("User-Agent" ))
1159
+
1117
1160
// If the database is a live database, we return an error message
1118
1161
isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
1119
1162
if err != nil {
@@ -1263,6 +1306,9 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
1263
1306
return
1264
1307
}
1265
1308
1309
+ // Record the api call in our backend database
1310
+ com .ApiCallLog (loggedInUser , loggedInUser , dbName , "upload" , r .Header .Get ("User-Agent" ))
1311
+
1266
1312
// Check if the database exists already
1267
1313
exists , err := com .CheckDBExists (loggedInUser , dbName )
1268
1314
if err != nil {
@@ -1366,6 +1412,9 @@ func viewsHandler(w http.ResponseWriter, r *http.Request) {
1366
1412
return
1367
1413
}
1368
1414
1415
+ // Record the api call in our backend database
1416
+ com .ApiCallLog (loggedInUser , loggedInUser , dbName , "views" , r .Header .Get ("User-Agent" ))
1417
+
1369
1418
// Check if the database is a live database, and get the node/queue to send the request to
1370
1419
isLive , liveNode , err := com .CheckDBLive (dbOwner , dbName )
1371
1420
if err != nil {
@@ -1441,12 +1490,15 @@ func viewsHandler(w http.ResponseWriter, r *http.Request) {
1441
1490
// * "dbname" is the name of the database being queried
1442
1491
func webpageHandler (w http.ResponseWriter , r * http.Request ) {
1443
1492
// Authenticate user and collect requested database details
1444
- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
1493
+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
1445
1494
if err != nil {
1446
1495
jsonErr (w , err .Error (), httpStatus )
1447
1496
return
1448
1497
}
1449
1498
1499
+ // Record the api call in our backend database
1500
+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "views" , r .Header .Get ("User-Agent" ))
1501
+
1450
1502
// Return the database webUI URL to the user
1451
1503
var z com.WebpageResponseContainer
1452
1504
z .WebPage = "https://" + com .Conf .Web .ServerName + "/" + dbOwner + "/" + dbName
0 commit comments