Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions cmd/admin/handlers/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"github.com/jmpsec/osctrl/cmd/admin/sessions"
"github.com/jmpsec/osctrl/pkg/carves"
"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/users"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/rs/zerolog/log"
)

// FaviconHandler for the favicon
func (h *HandlersAdmin) FaviconHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
w.Header().Set(utils.ContentType, "image/png")
http.ServeFile(w, r, "/static/favicon.png")
}
Expand All @@ -36,20 +35,20 @@ func (h *HandlersAdmin) ErrorHandler(w http.ResponseWriter, r *http.Request) {
// ForbiddenHandler for forbidden error requests
func (h *HandlersAdmin) ForbiddenHandler(w http.ResponseWriter, r *http.Request) {
// Debug HTTP for environment
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Send response
utils.HTTPResponse(w, "", http.StatusForbidden, errorContent)
}

// RootHandler - Handler for the root path
func (h *HandlersAdmin) RootHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
http.Redirect(w, r, "/dashboard", http.StatusFound)
}

// PermissionsGETHandler for platform/environment stats in JSON
func (h *HandlersAdmin) PermissionsGETHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Extract username and verify
usernameVar := r.PathValue("username")
if usernameVar == "" || !h.Users.Exists(usernameVar) {
Expand All @@ -76,7 +75,7 @@ func (h *HandlersAdmin) PermissionsGETHandler(w http.ResponseWriter, r *http.Req

// CarvesDownloadHandler for GET requests to download carves
func (h *HandlersAdmin) CarvesDownloadHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
// Extract environment
Expand Down
4 changes: 1 addition & 3 deletions cmd/admin/handlers/json-carves.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (

"github.com/jmpsec/osctrl/cmd/admin/sessions"
"github.com/jmpsec/osctrl/pkg/carves"
"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/queries"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/users"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -53,7 +51,7 @@ type CarveTarget struct {

// JSONCarvesHandler for JSON carves by target
func (h *HandlersAdmin) JSONCarvesHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
// Check permissions
Expand Down
5 changes: 2 additions & 3 deletions cmd/admin/handlers/json-logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/jmpsec/osctrl/cmd/admin/sessions"
"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/types"
"github.com/jmpsec/osctrl/pkg/users"
"github.com/jmpsec/osctrl/pkg/utils"
Expand Down Expand Up @@ -60,7 +59,7 @@ type QueryLogJSON struct {

// JSONLogsHandler GET requests for JSON status/result logs by node and environment
func (h *HandlersAdmin) JSONLogsHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Extract type
logType := r.PathValue("type")
if logType == "" {
Expand Down Expand Up @@ -167,7 +166,7 @@ func (h *HandlersAdmin) JSONLogsHandler(w http.ResponseWriter, r *http.Request)

// JSONQueryLogsHandler for JSON query logs by query name
func (h *HandlersAdmin) JSONQueryLogsHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
// Check permissions
Expand Down
5 changes: 2 additions & 3 deletions cmd/admin/handlers/json-nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"net/http"

"github.com/jmpsec/osctrl/cmd/admin/sessions"
"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/users"
"github.com/jmpsec/osctrl/pkg/utils"
Expand Down Expand Up @@ -41,7 +40,7 @@ type NodeJSON struct {

// JSONEnvironmentHandler - Handler for JSON endpoints by environment
func (h *HandlersAdmin) JSONEnvironmentHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Extract environment
envVar := r.PathValue("env")
if envVar == "" {
Expand Down Expand Up @@ -113,7 +112,7 @@ func (h *HandlersAdmin) JSONEnvironmentHandler(w http.ResponseWriter, r *http.Re

// JSONPlatformHandler - Handler for JSON endpoints by platform
func (h *HandlersAdmin) JSONPlatformHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
// Check permissions
Expand Down
4 changes: 1 addition & 3 deletions cmd/admin/handlers/json-queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"net/http"

"github.com/jmpsec/osctrl/cmd/admin/sessions"
"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/queries"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/users"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -125,7 +123,7 @@ func (h *HandlersAdmin) JSONSavedJSON(q queries.SavedQuery) SavedJSON {

// JSONQueryHandler - Handler for JSON queries by target
func (h *HandlersAdmin) JSONQueryHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
// Check permissions
Expand Down
3 changes: 1 addition & 2 deletions cmd/admin/handlers/json-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"net/http"

"github.com/jmpsec/osctrl/cmd/admin/sessions"
"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/nodes"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/users"
Expand All @@ -22,7 +21,7 @@ var (

// JSONStatsHandler for platform/environment stats in JSON
func (h *HandlersAdmin) JSONStatsHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
// Extract stats target
Expand Down
4 changes: 1 addition & 3 deletions cmd/admin/handlers/json-tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import (
"net/http"

"github.com/jmpsec/osctrl/cmd/admin/sessions"
"github.com/jmpsec/osctrl/pkg/config"
"github.com/jmpsec/osctrl/pkg/settings"
"github.com/jmpsec/osctrl/pkg/users"
"github.com/jmpsec/osctrl/pkg/utils"
"github.com/rs/zerolog/log"
)

// JSONTagsHandler for platform/environment stats in JSON
func (h *HandlersAdmin) JSONTagsHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
// Check permissions
Expand Down
38 changes: 19 additions & 19 deletions cmd/admin/handlers/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// LoginPOSTHandler for login page for POST requests
func (h *HandlersAdmin) LoginPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
var l LoginRequest
// Parse request JSON body
if h.Settings.DebugService(config.ServiceAdmin) {
Expand Down Expand Up @@ -52,7 +52,7 @@ func (h *HandlersAdmin) LoginPOSTHandler(w http.ResponseWriter, r *http.Request)

// LogoutPOSTHandler for POST requests to logout
func (h *HandlersAdmin) LogoutPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
var l LogoutRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -83,7 +83,7 @@ func (h *HandlersAdmin) LogoutPOSTHandler(w http.ResponseWriter, r *http.Request

// QueryRunPOSTHandler for POST requests to run queries
func (h *HandlersAdmin) QueryRunPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract environment
envVar := r.PathValue("env")
if envVar == "" {
Expand Down Expand Up @@ -241,7 +241,7 @@ func (h *HandlersAdmin) QueryRunPOSTHandler(w http.ResponseWriter, r *http.Reque

// CarvesRunPOSTHandler for POST requests to run file carves
func (h *HandlersAdmin) CarvesRunPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract environment
envVar := r.PathValue("env")
if envVar == "" {
Expand Down Expand Up @@ -388,7 +388,7 @@ func (h *HandlersAdmin) CarvesRunPOSTHandler(w http.ResponseWriter, r *http.Requ

// QueryActionsPOSTHandler for POST requests to queries
func (h *HandlersAdmin) QueryActionsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract environment
envVar := r.PathValue("env")
if envVar == "" {
Expand Down Expand Up @@ -464,7 +464,7 @@ func (h *HandlersAdmin) QueryActionsPOSTHandler(w http.ResponseWriter, r *http.R

// CarvesActionsPOSTHandler - Handler for POST requests to carves
func (h *HandlersAdmin) CarvesActionsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
var q DistributedCarvesActionRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -509,7 +509,7 @@ func (h *HandlersAdmin) CarvesActionsPOSTHandler(w http.ResponseWriter, r *http.

// ConfPOSTHandler for POST requests for saving configuration
func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract environment
envVar := r.PathValue("env")
if envVar == "" {
Expand Down Expand Up @@ -709,7 +709,7 @@ func (h *HandlersAdmin) ConfPOSTHandler(w http.ResponseWriter, r *http.Request)

// IntervalsPOSTHandler for POST requests for saving intervals
func (h *HandlersAdmin) IntervalsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract environment and verify
envVar := r.PathValue("env")
if envVar == "" || !h.Envs.Exists(envVar) {
Expand Down Expand Up @@ -768,7 +768,7 @@ func (h *HandlersAdmin) IntervalsPOSTHandler(w http.ResponseWriter, r *http.Requ

// ExpirationPOSTHandler for POST requests for expiring enroll links
func (h *HandlersAdmin) ExpirationPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract environment
envVar := r.PathValue("env")
if envVar == "" {
Expand Down Expand Up @@ -866,7 +866,7 @@ func (h *HandlersAdmin) ExpirationPOSTHandler(w http.ResponseWriter, r *http.Req

// NodeActionsPOSTHandler for POST requests for multi node action
func (h *HandlersAdmin) NodeActionsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
var m NodeMultiActionRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -914,7 +914,7 @@ func (h *HandlersAdmin) NodeActionsPOSTHandler(w http.ResponseWriter, r *http.Re

// EnvsPOSTHandler for POST request for /environments
func (h *HandlersAdmin) EnvsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
var c EnvironmentsRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -1015,7 +1015,7 @@ func (h *HandlersAdmin) EnvsPOSTHandler(w http.ResponseWriter, r *http.Request)

// SettingsPOSTHandler for POST request for /settings
func (h *HandlersAdmin) SettingsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract service
serviceVar := r.PathValue("service")
if serviceVar == "" {
Expand Down Expand Up @@ -1102,7 +1102,7 @@ func (h *HandlersAdmin) SettingsPOSTHandler(w http.ResponseWriter, r *http.Reque

// UsersPOSTHandler for POST request for /users
func (h *HandlersAdmin) UsersPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
var u UsersRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ func (h *HandlersAdmin) UsersPOSTHandler(w http.ResponseWriter, r *http.Request)

// TagsPOSTHandler for POST request for /tags
func (h *HandlersAdmin) TagsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
var t TagsRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -1323,7 +1323,7 @@ func (h *HandlersAdmin) TagsPOSTHandler(w http.ResponseWriter, r *http.Request)

// TagNodesPOSTHandler for POST request for /tags/nodes
func (h *HandlersAdmin) TagNodesPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
var t TagNodesRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -1384,7 +1384,7 @@ func (h *HandlersAdmin) TagNodesPOSTHandler(w http.ResponseWriter, r *http.Reque

// PermissionsPOSTHandler for POST request for /users/permissions
func (h *HandlersAdmin) PermissionsPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract username and verify
usernameVar := r.PathValue("username")
if usernameVar == "" || !h.Users.Exists(usernameVar) {
Expand Down Expand Up @@ -1445,7 +1445,7 @@ func (h *HandlersAdmin) PermissionsPOSTHandler(w http.ResponseWriter, r *http.Re

// EnrollPOSTHandler for POST requests enroll data
func (h *HandlersAdmin) EnrollPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), true)
utils.DebugHTTPDump(r, true)
// Extract environment
envVar := r.PathValue("env")
if envVar == "" {
Expand Down Expand Up @@ -1548,7 +1548,7 @@ func (h *HandlersAdmin) EnrollPOSTHandler(w http.ResponseWriter, r *http.Request

// EditProfilePOSTHandler for POST requests to edit profile
func (h *HandlersAdmin) EditProfilePOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
var u UsersRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down Expand Up @@ -1617,7 +1617,7 @@ func (h *HandlersAdmin) EditProfilePOSTHandler(w http.ResponseWriter, r *http.Re

// SavedQueriesPOSTHandler for POST requests to save queries
func (h *HandlersAdmin) SavedQueriesPOSTHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, h.Settings.DebugHTTP(config.ServiceAdmin, settings.NoEnvironmentID), false)
utils.DebugHTTPDump(r, false)
var s SavedQueryRequest
// Get context data
ctx := r.Context().Value(sessions.ContextKey(sessions.CtxSession)).(sessions.ContextValue)
Expand Down
Loading