moved stuff around
This commit is contained in:
@@ -591,36 +591,6 @@ func (con Connection) AttachServer(ctx *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (con Connection) serverAuthorized(permissions models.Permission) func(*gin.Context) bool {
|
||||
return func(ctx *gin.Context) bool {
|
||||
claims, exists := ctx.Get("claims")
|
||||
if !exists {
|
||||
return false
|
||||
}
|
||||
|
||||
server_id := ctx.Param("server_id")
|
||||
if server_id == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
var serverData models.ServerData
|
||||
|
||||
con.databaseConnection.Database("Backend").Collection("Servers").FindOne(context.TODO(), bson.D{{Key: "Id", Value: server_id}}).Decode(&serverData)
|
||||
|
||||
if serverData.OwnerId == claims.(*auth.AuthClaims).Username {
|
||||
return true
|
||||
}
|
||||
|
||||
userPermissions := serverData.UserPermissions[claims.(*auth.AuthClaims).Username]
|
||||
|
||||
if userPermissions&permissions == permissions || userPermissions&models.Admin == models.Admin {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type UpdateServerRequest struct {
|
||||
DefaultPorts []models.Port `json:"DefaultPorts"`
|
||||
DefaultCommand string `json:"DefaultCommand"`
|
||||
@@ -669,17 +639,21 @@ func (con Connection) BrowseServer(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
}
|
||||
|
||||
labelId := serverInfo.Id[:12]
|
||||
browserLabels := make(map[string]string)
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.tls.domains[0].main", serverInfo.Id)] = fmt.Sprintf("%s.%s", "browsers", DOMAIN)
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.tls.domains[0].sans", serverInfo.Id)] = fmt.Sprintf("*.%s.%s", "browsers", DOMAIN)
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.tls.certresolver", serverInfo.Id)] = "myresolver"
|
||||
browserLabels["traefik.enable"] = "true"
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.rule", labelId)] = fmt.Sprintf("Host(`%s.{service_type}.{DOMAIN}`)", labelId)
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.entrypoints", labelId)] = "websecure"
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.middlewares", labelId)] = "games@docker"
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.tls.domains[0].main", labelId)] = fmt.Sprintf("%s.%s", "browsers", DOMAIN)
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.tls.domains[0].sans", labelId)] = fmt.Sprintf("*.%s.%s", "browsers", DOMAIN)
|
||||
browserLabels[fmt.Sprintf("traefik.http.routers.%s.tls.certresolver", labelId)] = "myresolver"
|
||||
|
||||
containerLabels := ContainerLabels{
|
||||
OwnerId: claims.(*auth.AuthClaims).Username,
|
||||
ImageId: FILE_BROWSER_IMAGE,
|
||||
VolumeId: serverInfo.Id,
|
||||
Type: "FILE-BROWSER",
|
||||
Type: "FILE_BROWSER",
|
||||
}
|
||||
jsonLabels, err := json.Marshal(containerLabels)
|
||||
if err != nil {
|
||||
@@ -706,17 +680,16 @@ func (con Connection) BrowseServer(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
if len(images) == 0 {
|
||||
ctx.AbortWithError(500, fmt.Errorf("Image %s no longer exists", imageRef))
|
||||
ctx.AbortWithError(500, fmt.Errorf("image %s no longer exists", imageRef))
|
||||
return
|
||||
}
|
||||
|
||||
ContainerResponse, err := con.dockerClient.ContainerCreate(
|
||||
context.TODO(),
|
||||
&container.Config{
|
||||
Cmd: command,
|
||||
Image: FILE_BROWSER_IMAGE,
|
||||
Labels: browserLabels,
|
||||
ExposedPorts: nat.PortSet{"80/tcp": struct{}{}},
|
||||
Cmd: command,
|
||||
Image: FILE_BROWSER_IMAGE,
|
||||
Labels: browserLabels,
|
||||
},
|
||||
&container.HostConfig{
|
||||
Mounts: []mount.Mount{{Source: serverInfo.Id, Target: "/tmp/data", Type: "volume"}},
|
||||
@@ -745,7 +718,37 @@ func (con Connection) BrowseServer(ctx *gin.Context) {
|
||||
ctx.JSON(200, "OK")
|
||||
}
|
||||
|
||||
func LoadGroup(group *gin.RouterGroup, mongo_client *mongo.Client) {
|
||||
func (con Connection) serverAuthorized(permissions models.Permission) func(*gin.Context) bool {
|
||||
return func(ctx *gin.Context) bool {
|
||||
claims, exists := ctx.Get("claims")
|
||||
if !exists {
|
||||
return false
|
||||
}
|
||||
|
||||
server_id := ctx.Param("server_id")
|
||||
if server_id == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
var serverData models.ServerData
|
||||
|
||||
con.databaseConnection.Database("Backend").Collection("Servers").FindOne(context.TODO(), bson.D{{Key: "Id", Value: server_id}}).Decode(&serverData)
|
||||
|
||||
if serverData.OwnerId == claims.(*auth.AuthClaims).Username {
|
||||
return true
|
||||
}
|
||||
|
||||
userPermissions := serverData.UserPermissions[claims.(*auth.AuthClaims).Username]
|
||||
|
||||
if userPermissions&permissions == permissions || userPermissions&models.Admin == models.Admin {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func LoadGroup(group *gin.RouterGroup, mongo_client *mongo.Client, config models.GlobalConfig) {
|
||||
apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Reference in New Issue
Block a user