66 "mjpclab.dev/ghfs/src/serverLog"
77 "mjpclab.dev/ghfs/src/tpl/theme"
88 "mjpclab.dev/ghfs/src/user"
9+ "mjpclab.dev/ghfs/src/util"
910 "net/http"
1011 "regexp"
1112 "strconv"
@@ -14,8 +15,6 @@ import (
1415
1516var defaultHandler = http .NotFoundHandler ()
1617
17- type prefixFilter func (whole , prefix string ) bool
18-
1918type aliasHandler struct {
2019 alias
2120
@@ -45,10 +44,9 @@ type aliasHandler struct {
4544 authUrls []string
4645 authDirs []string
4746
48- restrictAccess bool
4947 globalRestrictAccess []string
50- restrictAccessUrls [] pathStrings
51- restrictAccessDirs [] pathStrings
48+ restrictAccessUrls pathStringsList
49+ restrictAccessDirs pathStringsList
5250
5351 globalHeaders [][2 ]string
5452 headersUrls []pathHeaders
@@ -114,7 +112,7 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
114112
115113 if ! session .allowAccess {
116114 if ! h .applyMiddlewares (h .postMiddlewares , w , r , session , data ) {
117- h .page (w , r , data )
115+ h .page (w , r , session , data )
118116 }
119117 return
120118 }
@@ -174,7 +172,7 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
174172 } else if shouldServeAsContent (session .file , data .Item ) {
175173 h .content (w , r , session , data )
176174 } else {
177- h .page (w , r , data )
175+ h .page (w , r , session , data )
178176 }
179177}
180178
@@ -186,6 +184,11 @@ func newAliasHandler(
186184) * aliasHandler {
187185 emptyRoot := p .EmptyRoot && currentAlias .url == "/"
188186
187+ globalRestrictAccess := p .GlobalRestrictAccess
188+ globalRestrictAccess = vhostCtx .restrictAccessUrls .mergePrefixMatched (globalRestrictAccess , util .HasUrlPrefixDir , currentAlias .url )
189+ globalRestrictAccess = vhostCtx .restrictAccessDirs .mergePrefixMatched (globalRestrictAccess , util .HasFsPrefixDir , currentAlias .fs )
190+ globalRestrictAccess = util .InPlaceDedup (globalRestrictAccess )
191+
189192 h := & aliasHandler {
190193 alias : currentAlias ,
191194 emptyRoot : emptyRoot ,
@@ -207,10 +210,9 @@ func newAliasHandler(
207210 authUrls : p .AuthUrls ,
208211 authDirs : p .AuthDirs ,
209212
210- restrictAccess : vhostCtx .restrictAccess ,
211- globalRestrictAccess : p .GlobalRestrictAccess ,
212- restrictAccessUrls : vhostCtx .restrictAccessUrls ,
213- restrictAccessDirs : vhostCtx .restrictAccessDirs ,
213+ globalRestrictAccess : globalRestrictAccess ,
214+ restrictAccessUrls : vhostCtx .restrictAccessUrls .filterSuccessor (util .HasUrlPrefixDir , currentAlias .url ),
215+ restrictAccessDirs : vhostCtx .restrictAccessDirs .filterSuccessor (util .HasFsPrefixDir , currentAlias .fs ),
214216
215217 globalHeaders : p .GlobalHeaders ,
216218 headersUrls : vhostCtx .headersUrls ,
0 commit comments