mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-03 23:55:44 +00:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			v4.0.1-bet
			...
			feat/app-l
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					e22d181de7 | ||
| 
						 | 
					c9b609b69c | ||
| 
						 | 
					4e6372ea97 | 
@@ -7,7 +7,7 @@ export const Layout = () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div
 | 
					    <div
 | 
				
			||||||
      className="relative flex flex-col justify-center items-center min-h-svh"
 | 
					      className="relative flex flex-col justify-center items-center min-h-dvh"
 | 
				
			||||||
      style={{
 | 
					      style={{
 | 
				
			||||||
        backgroundImage: `url(${backgroundImage})`,
 | 
					        backgroundImage: `url(${backgroundImage})`,
 | 
				
			||||||
        backgroundSize: "cover",
 | 
					        backgroundSize: "cover",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -74,7 +74,7 @@ func (docker *Docker) DockerConnected() bool {
 | 
				
			|||||||
	return err == nil
 | 
						return err == nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (docker *Docker) GetLabels(appId string) (types.Labels, error) {
 | 
					func (docker *Docker) GetLabels(id string, domain string) (types.Labels, error) {
 | 
				
			||||||
	// Check if we have access to the Docker API
 | 
						// Check if we have access to the Docker API
 | 
				
			||||||
	isConnected := docker.DockerConnected()
 | 
						isConnected := docker.DockerConnected()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -85,15 +85,16 @@ func (docker *Docker) GetLabels(appId string) (types.Labels, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get the containers
 | 
						// Get the containers
 | 
				
			||||||
 | 
						log.Debug().Msg("Getting containers")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	containers, err := docker.GetContainers()
 | 
						containers, err := docker.GetContainers()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If there is an error, return false
 | 
						// If there is an error, return false
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Error().Err(err).Msg("Error getting containers")
 | 
				
			||||||
		return types.Labels{}, err
 | 
							return types.Labels{}, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Debug().Msg("Got containers")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Loop through the containers
 | 
						// Loop through the containers
 | 
				
			||||||
	for _, container := range containers {
 | 
						for _, container := range containers {
 | 
				
			||||||
		// Inspect the container
 | 
							// Inspect the container
 | 
				
			||||||
@@ -105,28 +106,22 @@ func (docker *Docker) GetLabels(appId string) (types.Labels, error) {
 | 
				
			|||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get the container name (for some reason it is /name)
 | 
							// Get the labels
 | 
				
			||||||
		containerName := strings.TrimPrefix(inspect.Name, "/")
 | 
							log.Debug().Str("id", inspect.ID).Msg("Getting labels for container")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// There is a container with the same name as the app ID
 | 
					 | 
				
			||||||
		if containerName == appId {
 | 
					 | 
				
			||||||
			log.Debug().Str("container", containerName).Msg("Found container")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			// Get only the tinyauth labels in a struct
 | 
					 | 
				
			||||||
		labels, err := utils.GetLabels(inspect.Config.Labels)
 | 
							labels, err := utils.GetLabels(inspect.Config.Labels)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Check if there was an error
 | 
							// Check if there was an error
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
				log.Error().Err(err).Msg("Error parsing labels")
 | 
								log.Warn().Str("id", container.ID).Err(err).Msg("Error getting container labels, skipping")
 | 
				
			||||||
				return types.Labels{}, err
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			log.Debug().Msg("Got labels")
 | 
							// Check if the labels match the id or the domain
 | 
				
			||||||
 | 
							if strings.TrimPrefix(inspect.Name, "/") == id || labels.Domain == domain {
 | 
				
			||||||
			// Return labels
 | 
								log.Debug().Str("id", inspect.ID).Msg("Found matching container")
 | 
				
			||||||
			return labels, nil
 | 
								return labels, nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Debug().Msg("No matching container found, returning empty labels")
 | 
						log.Debug().Msg("No matching container found, returning empty labels")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,11 +69,14 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
 | 
				
			|||||||
	proto := c.Request.Header.Get("X-Forwarded-Proto")
 | 
						proto := c.Request.Header.Get("X-Forwarded-Proto")
 | 
				
			||||||
	host := c.Request.Header.Get("X-Forwarded-Host")
 | 
						host := c.Request.Header.Get("X-Forwarded-Host")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get the app id
 | 
						// Remove the port from the host if it exists
 | 
				
			||||||
	appId := strings.Split(host, ".")[0]
 | 
						hostPortless := strings.Split(host, ":")[0] // *lol*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get the id
 | 
				
			||||||
 | 
						id := strings.Split(hostPortless, ".")[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get the container labels
 | 
						// Get the container labels
 | 
				
			||||||
	labels, err := h.Docker.GetLabels(appId)
 | 
						labels, err := h.Docker.GetLabels(id, hostPortless)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Debug().Interface("labels", labels).Msg("Got labels")
 | 
						log.Debug().Interface("labels", labels).Msg("Got labels")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -104,5 +104,6 @@ type Labels struct {
 | 
				
			|||||||
	Users   string
 | 
						Users   string
 | 
				
			||||||
	Allowed string
 | 
						Allowed string
 | 
				
			||||||
	Headers []string
 | 
						Headers []string
 | 
				
			||||||
 | 
						Domain  string
 | 
				
			||||||
	OAuth   OAuthLabels
 | 
						OAuth   OAuthLabels
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -201,7 +201,7 @@ func GetLabels(labels map[string]string) (types.Labels, error) {
 | 
				
			|||||||
	var labelsParsed types.Labels
 | 
						var labelsParsed types.Labels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Decode the labels into the labels struct
 | 
						// Decode the labels into the labels struct
 | 
				
			||||||
	err := parser.Decode(labels, &labelsParsed, "tinyauth", "tinyauth.users", "tinyauth.allowed", "tinyauth.headers", "tinyauth.oauth")
 | 
						err := parser.Decode(labels, &labelsParsed, "tinyauth", "tinyauth.users", "tinyauth.allowed", "tinyauth.headers", "tinyauth.domain", "tinyauth.oauth")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if there was an error
 | 
						// Check if there was an error
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user