@@ -10,6 +10,7 @@ import (
1010 "net/http"
1111
1212 "github.com/jmpsec/osctrl/cmd/admin/sessions"
13+ "github.com/jmpsec/osctrl/pkg/auditlog"
1314 "github.com/jmpsec/osctrl/pkg/handlers"
1415 "github.com/jmpsec/osctrl/pkg/nodes"
1516 "github.com/jmpsec/osctrl/pkg/queries"
@@ -45,7 +46,7 @@ func (h *HandlersAdmin) LoginPOSTHandler(w http.ResponseWriter, r *http.Request)
4546 return
4647 }
4748 // Serialize and send response
48- log . Debug (). Msg ( "Login response sent" )
49+ h . AuditLog . NewLogin ( user . Username , strings . Split ( r . RemoteAddr , ":" )[ 0 ] )
4950 adminOKResponse (w , "/dashboard" )
5051}
5152
@@ -74,7 +75,7 @@ func (h *HandlersAdmin) LogoutPOSTHandler(w http.ResponseWriter, r *http.Request
7475 return
7576 }
7677 // Serialize and send response
77- log . Debug (). Msg ( "Logout response sent" )
78+ h . AuditLog . NewLogout ( ctx [ sessions . CtxUser ], strings . Split ( r . RemoteAddr , ":" )[ 0 ] )
7879 adminOKResponse (w , "OK" )
7980}
8081
@@ -172,7 +173,7 @@ func (h *HandlersAdmin) QueryRunPOSTHandler(w http.ResponseWriter, r *http.Reque
172173 }
173174 }
174175 // Serialize and send response
175- log . Debug (). Msg ( " Query run response sent" )
176+ h . AuditLog . NewQuery ( ctx [ sessions . CtxUser ], q . Query , strings . Split ( r . RemoteAddr , ":" )[ 0 ], env . ID )
176177 adminOKResponse (w , "OK" )
177178}
178179
@@ -262,7 +263,7 @@ func (h *HandlersAdmin) CarvesRunPOSTHandler(w http.ResponseWriter, r *http.Requ
262263 return
263264 }
264265 // Serialize and send response
265- log . Debug (). Msg ( "Carve run response sent" )
266+ h . AuditLog . NewCarve ( ctx [ sessions . CtxUser ], c . Path , strings . Split ( r . RemoteAddr , ":" )[ 0 ], env . ID )
266267 adminOKResponse (w , "OK" )
267268}
268269
@@ -345,8 +346,7 @@ func (h *HandlersAdmin) QueryActionsPOSTHandler(w http.ResponseWriter, r *http.R
345346 }
346347 adminOKResponse (w , "queries delete successfully" )
347348 }
348- // Serialize and send response
349- log .Debug ().Msg ("Query run response sent" )
349+ h .AuditLog .QueryAction (ctx [sessions .CtxUser ], q .Action , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
350350}
351351
352352// CarvesActionsPOSTHandler - Handler for POST requests to carves
@@ -402,8 +402,7 @@ func (h *HandlersAdmin) CarvesActionsPOSTHandler(w http.ResponseWriter, r *http.
402402 log .Debug ().Msg ("testing action" )
403403 adminOKResponse (w , "test successful" )
404404 }
405- // Serialize and send response
406- log .Debug ().Msg ("Carves action response sent" )
405+ h .AuditLog .CarveAction (ctx [sessions .CtxUser ], q .Action , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
407406}
408407
409408// ConfPOSTHandler for POST requests for saving configuration
@@ -466,8 +465,8 @@ func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request)
466465 adminErrorResponse (w , "error saving configuration parts" , http .StatusInternalServerError , err )
467466 return
468467 }
468+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], "update configuration" , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
469469 // Send response
470- log .Debug ().Msg ("Configuration response sent" )
471470 adminOKResponse (w , "configuration saved successfully" )
472471 return
473472 }
@@ -489,8 +488,8 @@ func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request)
489488 adminErrorResponse (w , "error updating configuration" , http .StatusInternalServerError , err )
490489 return
491490 }
491+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], "update options" , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
492492 // Send response
493- log .Debug ().Msg ("Options response sent" )
494493 adminOKResponse (w , "options saved successfully" )
495494 return
496495 }
@@ -512,8 +511,8 @@ func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request)
512511 adminErrorResponse (w , "error updating configuration" , http .StatusInternalServerError , err )
513512 return
514513 }
514+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], "update schedule" , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
515515 // Send response
516- log .Debug ().Msg ("Schedule response sent" )
517516 adminOKResponse (w , "schedule saved successfully" )
518517 return
519518 }
@@ -535,8 +534,8 @@ func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request)
535534 adminErrorResponse (w , "error updating configuration" , http .StatusInternalServerError , err )
536535 return
537536 }
537+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], "update packs" , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
538538 // Send response
539- log .Debug ().Msg ("Packs response sent" )
540539 adminOKResponse (w , "packs saved successfully" )
541540 return
542541 }
@@ -558,8 +557,8 @@ func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request)
558557 adminErrorResponse (w , "error updating configuration" , http .StatusInternalServerError , err )
559558 return
560559 }
560+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], "update decorators" , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
561561 // Send response
562- log .Debug ().Msg ("Decorators response sent" )
563562 adminOKResponse (w , "decorators saved successfully" )
564563 return
565564 }
@@ -581,8 +580,8 @@ func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request)
581580 adminErrorResponse (w , "error updating configuration" , http .StatusInternalServerError , err )
582581 return
583582 }
583+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], "update ATC" , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
584584 // Send response
585- log .Debug ().Msg ("ATC response sent" )
586585 adminOKResponse (w , "ATC saved successfully" )
587586 return
588587 }
@@ -644,8 +643,8 @@ func (h *HandlersAdmin) IntervalsPOSTHandler(w http.ResponseWriter, r *http.Requ
644643 adminErrorResponse (w , "error updating flags" , http .StatusInternalServerError , err )
645644 return
646645 }
646+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], "update intervals" , strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
647647 // Serialize and send response
648- log .Debug ().Msg ("Intervals response sent" )
649648 adminOKResponse (w , "intervals saved successfully" )
650649}
651650
@@ -741,8 +740,7 @@ func (h *HandlersAdmin) ExpirationPOSTHandler(w http.ResponseWriter, r *http.Req
741740 adminOKResponse (w , "link set to not expire successfully" )
742741 }
743742 }
744- // Serialize and send response
745- log .Debug ().Msg ("Expiration response sent" )
743+ h .AuditLog .ConfAction (ctx [sessions .CtxUser ], fmt .Sprintf ("%s:%s" , e .Type , e .Action ), strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
746744}
747745
748746// NodeActionsPOSTHandler for POST requests for multi node action
@@ -787,8 +785,7 @@ func (h *HandlersAdmin) NodeActionsPOSTHandler(w http.ResponseWriter, r *http.Re
787785 return
788786 }
789787 }
790- // Serialize and send response
791- log .Debug ().Msg ("Multi-node action response sent" )
788+ h .AuditLog .NodeAction (ctx [sessions .CtxUser ], m .Action , strings .Split (r .RemoteAddr , ":" )[0 ], auditlog .NoEnvironment )
792789}
793790
794791// EnvsPOSTHandler for POST request for /environments
@@ -878,8 +875,7 @@ func (h *HandlersAdmin) EnvsPOSTHandler(w http.ResponseWriter, r *http.Request)
878875 }
879876 adminOKResponse (w , "debug changed successfully" )
880877 }
881- // Serialize and send response
882- log .Debug ().Msg ("Environments response sent" )
878+ h .AuditLog .EnvAction (ctx [sessions .CtxUser ], fmt .Sprintf ("%s - %s" , c .Action , c .Name ), strings .Split (r .RemoteAddr , ":" )[0 ], auditlog .NoEnvironment )
883879}
884880
885881// SettingsPOSTHandler for POST request for /settings
@@ -963,8 +959,7 @@ func (h *HandlersAdmin) SettingsPOSTHandler(w http.ResponseWriter, r *http.Reque
963959 }
964960 adminOKResponse (w , "setting deleted successfully" )
965961 }
966- // Serialize and send response
967- log .Debug ().Msg ("Settings response sent" )
962+ h .AuditLog .SettingsAction (ctx [sessions .CtxUser ], fmt .Sprintf ("%s - %s" , s .Action , s .Name ), strings .Split (r .RemoteAddr , ":" )[0 ])
968963}
969964
970965// UsersPOSTHandler for POST request for /users
@@ -1112,8 +1107,7 @@ func (h *HandlersAdmin) UsersPOSTHandler(w http.ResponseWriter, r *http.Request)
11121107 adminOKResponse (w , "service changed successfully" )
11131108 }
11141109 }
1115- // Serialize and send response
1116- log .Debug ().Msg ("Users response sent" )
1110+ h .AuditLog .UserAction (ctx [sessions .CtxUser ], fmt .Sprintf ("%s - %s" , u .Action , u .Username ), strings .Split (r .RemoteAddr , ":" )[0 ])
11171111}
11181112
11191113// TagsPOSTHandler for POST request for /tags
@@ -1205,8 +1199,7 @@ func (h *HandlersAdmin) TagsPOSTHandler(w http.ResponseWriter, r *http.Request)
12051199 }
12061200 adminOKResponse (w , "tag removed successfully" )
12071201 }
1208- // Serialize and send response
1209- log .Debug ().Msg ("Tags response sent" )
1202+ h .AuditLog .TagAction (ctx [sessions .CtxUser ], fmt .Sprintf ("%s - %s" , t .Action , t .Name ), strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
12101203}
12111204
12121205// TagNodesPOSTHandler for POST request for /tags/nodes
@@ -1263,8 +1256,9 @@ func (h *HandlersAdmin) TagNodesPOSTHandler(w http.ResponseWriter, r *http.Reque
12631256 return
12641257 }
12651258 }
1259+ aMsg := fmt .Sprintf ("tags processed: add %d, remove %d" , len (t .TagsAdd ), len (t .TagsRemove ))
1260+ h .AuditLog .TagAction (ctx [sessions .CtxUser ], aMsg , strings .Split (r .RemoteAddr , ":" )[0 ], toBeProcessed [0 ].EnvironmentID )
12661261 // Serialize and send response
1267- log .Debug ().Msg ("Tags response sent" )
12681262 adminOKResponse (w , "tags processed successfully" )
12691263}
12701264
@@ -1322,8 +1316,8 @@ func (h *HandlersAdmin) PermissionsPOSTHandler(w http.ResponseWriter, r *http.Re
13221316 return
13231317 }
13241318 }
1319+ h .AuditLog .UserAction (ctx [sessions .CtxUser ], fmt .Sprintf ("permissions - %s" , usernameVar ), strings .Split (r .RemoteAddr , ":" )[0 ])
13251320 // Serialize and send response
1326- log .Debug ().Msg ("Users response sent" )
13271321 adminOKResponse (w , "permissions updated successfully" )
13281322}
13291323
@@ -1423,8 +1417,8 @@ func (h *HandlersAdmin) EnrollPOSTHandler(w http.ResponseWriter, r *http.Request
14231417 }
14241418 }
14251419 }
1420+ h .AuditLog .EnvAction (ctx [sessions .CtxUser ], fmt .Sprintf ("%s - %s" , e .Action , env .Name ), strings .Split (r .RemoteAddr , ":" )[0 ], env .ID )
14261421 // Serialize and send response
1427- log .Debug ().Msg ("Configuration response sent" )
14281422 adminOKResponse (w , "enroll data saved" )
14291423}
14301424
@@ -1491,8 +1485,7 @@ func (h *HandlersAdmin) EditProfilePOSTHandler(w http.ResponseWriter, r *http.Re
14911485 }
14921486 adminOKResponse (w , "profiled updated successfully" )
14931487 }
1494- // Serialize and send response
1495- log .Debug ().Msg ("Edit profile response sent" )
1488+ h .AuditLog .UserAction (ctx [sessions .CtxUser ], fmt .Sprintf ("%s - %s" , u .Action , u .Username ), strings .Split (r .RemoteAddr , ":" )[0 ])
14961489}
14971490
14981491// SavedQueriesPOSTHandler for POST requests to save queries
@@ -1520,6 +1513,4 @@ func (h *HandlersAdmin) SavedQueriesPOSTHandler(w http.ResponseWriter, r *http.R
15201513 case "edit" :
15211514 adminOKResponse (w , "query saved successfully" )
15221515 }
1523- // Serialize and send response
1524- log .Debug ().Msg ("Saved query response sent" )
15251516}
0 commit comments