mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-10-31 22:25:43 +00:00 
			
		
		
		
	feat: allow customizability of resources dir
This commit is contained in:
		| @@ -113,6 +113,7 @@ func init() { | |||||||
| 		{"ldap-base-dn", "", "LDAP base DN (e.g. dc=example,dc=com)."}, | 		{"ldap-base-dn", "", "LDAP base DN (e.g. dc=example,dc=com)."}, | ||||||
| 		{"ldap-insecure", false, "Skip certificate verification for the LDAP server."}, | 		{"ldap-insecure", false, "Skip certificate verification for the LDAP server."}, | ||||||
| 		{"ldap-search-filter", "(uid=%s)", "LDAP search filter for user lookup."}, | 		{"ldap-search-filter", "(uid=%s)", "LDAP search filter for user lookup."}, | ||||||
|  | 		{"resources-dir", "/data/resources", "Path to a directory containing custom resources (e.g. background image)."}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, opt := range configOptions { | 	for _, opt := range configOptions { | ||||||
|   | |||||||
| @@ -151,7 +151,9 @@ func (app *BootstrapApp) Setup() error { | |||||||
| 		Domain: domain, | 		Domain: domain, | ||||||
| 	}, authService, oauthBrokerService) | 	}, authService, oauthBrokerService) | ||||||
|  |  | ||||||
| 	uiMiddleware := middleware.NewUIMiddleware() | 	uiMiddleware := middleware.NewUIMiddleware(middleware.UIMiddlewareConfig{ | ||||||
|  | 		ResourcesDir: app.Config.ResourcesDir, | ||||||
|  | 	}) | ||||||
| 	zerologMiddleware := middleware.NewZerologMiddleware() | 	zerologMiddleware := middleware.NewZerologMiddleware() | ||||||
|  |  | ||||||
| 	middlewares = append(middlewares, contextMiddleware, uiMiddleware, zerologMiddleware) | 	middlewares = append(middlewares, contextMiddleware, uiMiddleware, zerologMiddleware) | ||||||
|   | |||||||
| @@ -55,6 +55,7 @@ type Config struct { | |||||||
| 	LdapBaseDN              string `mapstructure:"ldap-base-dn"` | 	LdapBaseDN              string `mapstructure:"ldap-base-dn"` | ||||||
| 	LdapInsecure            bool   `mapstructure:"ldap-insecure"` | 	LdapInsecure            bool   `mapstructure:"ldap-insecure"` | ||||||
| 	LdapSearchFilter        string `mapstructure:"ldap-search-filter"` | 	LdapSearchFilter        string `mapstructure:"ldap-search-filter"` | ||||||
|  | 	ResourcesDir            string `mapstructure:"resources-dir"` | ||||||
| } | } | ||||||
|  |  | ||||||
| type OAuthLabels struct { | type OAuthLabels struct { | ||||||
|   | |||||||
| @@ -10,14 +10,21 @@ import ( | |||||||
| 	"github.com/gin-gonic/gin" | 	"github.com/gin-gonic/gin" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | type UIMiddlewareConfig struct { | ||||||
|  | 	ResourcesDir string | ||||||
|  | } | ||||||
|  |  | ||||||
| type UIMiddleware struct { | type UIMiddleware struct { | ||||||
|  | 	Config              UIMiddlewareConfig | ||||||
| 	UIFS                fs.FS | 	UIFS                fs.FS | ||||||
| 	UIFileServer        http.Handler | 	UIFileServer        http.Handler | ||||||
| 	ResourcesFileServer http.Handler | 	ResourcesFileServer http.Handler | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewUIMiddleware() *UIMiddleware { | func NewUIMiddleware(config UIMiddlewareConfig) *UIMiddleware { | ||||||
| 	return &UIMiddleware{} | 	return &UIMiddleware{ | ||||||
|  | 		Config: config, | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *UIMiddleware) Init() error { | func (m *UIMiddleware) Init() error { | ||||||
| @@ -29,7 +36,7 @@ func (m *UIMiddleware) Init() error { | |||||||
|  |  | ||||||
| 	m.UIFS = ui | 	m.UIFS = ui | ||||||
| 	m.UIFileServer = http.FileServer(http.FS(ui)) | 	m.UIFileServer = http.FileServer(http.FS(ui)) | ||||||
| 	m.ResourcesFileServer = http.FileServer(http.Dir("/data/resources")) | 	m.ResourcesFileServer = http.FileServer(http.Dir(m.Config.ResourcesDir)) | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| @@ -45,7 +52,7 @@ func (m *UIMiddleware) Middleware() gin.HandlerFunc { | |||||||
| 			c.Next() | 			c.Next() | ||||||
| 			return | 			return | ||||||
| 		case "resources": | 		case "resources": | ||||||
| 			_, err := os.Stat("/data/resources/" + strings.TrimPrefix(c.Request.URL.Path, "/resources/")) | 			_, err := os.Stat(m.Config.ResourcesDir + strings.TrimPrefix(c.Request.URL.Path, "/resources/")) | ||||||
|  |  | ||||||
| 			if os.IsNotExist(err) { | 			if os.IsNotExist(err) { | ||||||
| 				c.Status(404) | 				c.Status(404) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Stavros
					Stavros