@@ -27,12 +27,15 @@ import (
2727// * "dbname" is the name of the database
2828func branchesHandler (w http.ResponseWriter , r * http.Request ) {
2929 // Do auth check, grab request info
30- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
30+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
3131 if err != nil {
3232 jsonErr (w , err .Error (), httpStatus )
3333 return
3434 }
3535
36+ // Record the api call in our backend database
37+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "branches" , r .Header .Get ("User-Agent" ))
38+ 3639 // If the database is a live database, we return an error message
3740 isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
3841 if err != nil {
@@ -102,6 +105,9 @@ func columnsHandler(w http.ResponseWriter, r *http.Request) {
102105 return
103106 }
104107
108+ // Record the api call in our backend database
109+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "columns" , r .Header .Get ("User-Agent" ))
110+ 105111 // Extract the table name
106112 table , err := com .GetFormTable (r , false )
107113 if err != nil {
@@ -221,12 +227,15 @@ func columnsHandler(w http.ResponseWriter, r *http.Request) {
221227// * "dbname" is the name of the database
222228func commitsHandler (w http.ResponseWriter , r * http.Request ) {
223229 // Do auth check, grab request info
224- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
230+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
225231 if err != nil {
226232 jsonErr (w , err .Error (), httpStatus )
227233 return
228234 }
229235
236+ // Record the api call in our backend database
237+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "commits" , r .Header .Get ("User-Agent" ))
238+ 230239 // If the database is a live database, we return an error message
231240 isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
232241 if err != nil {
@@ -271,6 +280,9 @@ func databasesHandler(w http.ResponseWriter, r *http.Request) {
271280 return
272281 }
273282
283+ // Record the api call in our backend database
284+ com .ApiCallLog (loggedInUser , "" , "" , "databases" , r .Header .Get ("User-Agent" ))
285+ 274286 // Get "live" boolean value, if provided by the caller
275287 var live bool
276288 live , err = com .GetFormLive (r )
@@ -336,6 +348,9 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
336348 }
337349 dbOwner := loggedInUser
338350
351+ // Record the api call in our backend database
352+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "delete" , r .Header .Get ("User-Agent" ))
353+ 339354 // Check if the database exists
340355 exists , err := com .CheckDBPermissions (loggedInUser , dbOwner , dbName , false )
341356 if err != nil {
@@ -517,6 +532,10 @@ func diffHandler(w http.ResponseWriter, r *http.Request) {
517532 return
518533 }
519534
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+ 520539 // Check permissions of the first database
521540 var allowed bool
522541 allowed , err = com .CheckDBPermissions (loggedInUser , dbOwnerA , dbNameA , false )
@@ -593,6 +612,9 @@ func downloadHandler(w http.ResponseWriter, r *http.Request) {
593612 return
594613 }
595614
615+ // Record the api call in our backend database
616+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "download" , r .Header .Get ("User-Agent" ))
617+ 596618 // Return the requested database to the user
597619 _ , err = com .DownloadDatabase (w , r , dbOwner , dbName , commitID , loggedInUser , "api" )
598620 if err != nil {
@@ -630,6 +652,9 @@ func executeHandler(w http.ResponseWriter, r *http.Request) {
630652 return
631653 }
632654
655+ // Record the api call in our backend database
656+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "execute" , r .Header .Get ("User-Agent" ))
657+ 633658 // Grab the incoming SQLite query
634659 rawInput := r .FormValue ("sql" )
635660 var sql string
@@ -709,6 +734,9 @@ func indexesHandler(w http.ResponseWriter, r *http.Request) {
709734 return
710735 }
711736
737+ // Record the api call in our backend database
738+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "indexes" , r .Header .Get ("User-Agent" ))
739+ 712740 // Check if the database is a live database, and get the node/queue to send the request to
713741 isLive , liveNode , err := com .CheckDBLive (dbOwner , dbName )
714742 if err != nil {
@@ -826,12 +854,15 @@ func indexesHandler(w http.ResponseWriter, r *http.Request) {
826854// * "dbname" is the name of the database
827855func metadataHandler (w http.ResponseWriter , r * http.Request ) {
828856 // Do auth check, grab request info
829- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
857+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
830858 if err != nil {
831859 jsonErr (w , err .Error (), httpStatus )
832860 return
833861 }
834862
863+ // Record the api call in our backend database
864+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "metadata" , r .Header .Get ("User-Agent" ))
865+ 835866 // If the database is a live database, we return an error message
836867 isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
837868 if err != nil {
@@ -886,6 +917,9 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
886917 return
887918 }
888919
920+ // Record the api call in our backend database
921+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "query" , r .Header .Get ("User-Agent" ))
922+ 889923 // Grab the incoming SQLite query
890924 rawInput := r .FormValue ("sql" )
891925 query , err := com .CheckUnicode (rawInput )
@@ -958,12 +992,15 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
958992// * "dbname" is the name of the database
959993func releasesHandler (w http.ResponseWriter , r * http.Request ) {
960994 // Do auth check, grab request info
961- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
995+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
962996 if err != nil {
963997 jsonErr (w , err .Error (), httpStatus )
964998 return
965999 }
9661000
1001+ // Record the api call in our backend database
1002+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "releases" , r .Header .Get ("User-Agent" ))
1003+ 9671004 // If the database is a live database, we return an error message
9681005 isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
9691006 if err != nil {
@@ -1033,6 +1070,9 @@ func tablesHandler(w http.ResponseWriter, r *http.Request) {
10331070 return
10341071 }
10351072
1073+ // Record the api call in our backend database
1074+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "tables" , r .Header .Get ("User-Agent" ))
1075+ 10361076 // Check if the database is a live database, and get the node/queue to send the request to
10371077 isLive , liveNode , err := com .CheckDBLive (dbOwner , dbName )
10381078 if err != nil {
@@ -1108,12 +1148,15 @@ func tablesHandler(w http.ResponseWriter, r *http.Request) {
11081148// * "dbname" is the name of the database
11091149func tagsHandler (w http.ResponseWriter , r * http.Request ) {
11101150 // Do auth check, grab request info
1111- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
1151+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
11121152 if err != nil {
11131153 jsonErr (w , err .Error (), httpStatus )
11141154 return
11151155 }
11161156
1157+ // Record the api call in our backend database
1158+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "tags" , r .Header .Get ("User-Agent" ))
1159+ 11171160 // If the database is a live database, we return an error message
11181161 isLive , _ , err := com .CheckDBLive (dbOwner , dbName )
11191162 if err != nil {
@@ -1263,6 +1306,9 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
12631306 return
12641307 }
12651308
1309+ // Record the api call in our backend database
1310+ com .ApiCallLog (loggedInUser , loggedInUser , dbName , "upload" , r .Header .Get ("User-Agent" ))
1311+ 12661312 // Check if the database exists already
12671313 exists , err := com .CheckDBExists (loggedInUser , dbName )
12681314 if err != nil {
@@ -1366,6 +1412,9 @@ func viewsHandler(w http.ResponseWriter, r *http.Request) {
13661412 return
13671413 }
13681414
1415+ // Record the api call in our backend database
1416+ com .ApiCallLog (loggedInUser , loggedInUser , dbName , "views" , r .Header .Get ("User-Agent" ))
1417+ 13691418 // Check if the database is a live database, and get the node/queue to send the request to
13701419 isLive , liveNode , err := com .CheckDBLive (dbOwner , dbName )
13711420 if err != nil {
@@ -1441,12 +1490,15 @@ func viewsHandler(w http.ResponseWriter, r *http.Request) {
14411490// * "dbname" is the name of the database being queried
14421491func webpageHandler (w http.ResponseWriter , r * http.Request ) {
14431492 // Authenticate user and collect requested database details
1444- _ , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
1493+ loggedInUser , dbOwner , dbName , _ , httpStatus , err := collectInfo (w , r )
14451494 if err != nil {
14461495 jsonErr (w , err .Error (), httpStatus )
14471496 return
14481497 }
14491498
1499+ // Record the api call in our backend database
1500+ com .ApiCallLog (loggedInUser , dbOwner , dbName , "views" , r .Header .Get ("User-Agent" ))
1501+ 14501502 // Return the database webUI URL to the user
14511503 var z com.WebpageResponseContainer
14521504 z .WebPage = "https://" + com .Conf .Web .ServerName + "/" + dbOwner + "/" + dbName
0 commit comments