1
1
xquery version "3.1" ;
2
2
3
+ import module namespace config="http://exist-db.org/xquery/apps/config" at "modules/config.xqm" ;
3
4
import module namespace login="http://exist-db.org/xquery/login" at "resource:org/exist/xquery/modules/persistentlogin/login.xql" ;
4
5
6
+ declare namespace sm="http://exist-db.org/xquery/securitymanager" ;
7
+
5
8
declare variable $exist:path external ;
6
9
declare variable $exist:resource external ;
7
10
declare variable $exist:controller external ;
8
11
declare variable $exist:prefix external ;
9
12
declare variable $exist:root external ;
10
13
11
14
declare variable $app-root-absolute-url :=
12
- (request:get-header ("X-Forwarded-Proto" ), request:get-scheme ())[1 ]
13
- || "://"
14
- || (request:get-header ("X-Forwarded-Server" ), request:get-server-name ())[1 ]
15
- || request:get-context-path ()
15
+ request:get-context-path ()
16
16
|| $exist:prefix
17
17
|| $exist:controller
18
18
;
@@ -30,33 +30,21 @@ else if ($exist:path eq "/") then
30
30
<redirect url = "index.html" />
31
31
</dispatch>
32
32
33
- else if ($exist:path eq "/public/apps.xml" ) then (
34
- response:set-header ('Content-Type' , 'application/xml' ),
33
+ else if ($exist:path eq "/public/apps.xml" ) then
35
34
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
36
- <forward url = "{$exist:controller} /modules/list.xql " />
35
+ <forward url = "{$exist:controller} /modules/list.xq " />
37
36
</dispatch>
38
- )
39
- else if ($exist:resource eq "update.xql" ) then
40
- <dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
41
- <forward url = "{$exist:controller} /modules/update.xql" />
42
- <view>
43
- <forward url = "{$exist:controller} /index.html" />
44
- <forward url = "{$exist:controller} /modules/view.xql" >
45
- <set-header name = "Cache-Control" value = "no-cache" />
46
- </forward>
47
- </view>
48
- </dispatch>
49
-
37
+
50
38
(: Protected resource: user is required to log in with valid credentials.
51
39
If the login fails or no credentials were provided, the request is redirected
52
40
to the login.html page. :)
53
41
else if ($exist:path eq "/admin.html" ) then
54
42
let $user := request:get-attribute ("org.exist.public-repo.login.user" )
55
43
return
56
- if ($user and ( sm:is-dba ($user) or "repo" = sm:get-user-groups ($user)) ) then
44
+ if (exists ( $user) and sm:get-user-groups ($user) = config:repo-permissions ()? group ) then
57
45
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
58
46
<view>
59
- <forward url = "{$exist:controller} /modules/view.xql " >
47
+ <forward url = "{$exist:controller} /modules/view.xq " >
60
48
<set-header name = "Cache-Control" value = "no-cache" />
61
49
</forward>
62
50
</view>
@@ -65,47 +53,62 @@ else if ($exist:path eq "/admin.html") then
65
53
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
66
54
<forward url = "login.html" />
67
55
<view>
68
- <forward url = "{$exist:controller} /modules/view.xql " >
56
+ <forward url = "{$exist:controller} /modules/view.xq " >
69
57
<set-header name = "Cache-Control" value = "no-cache" />
70
58
</forward>
71
59
</view>
72
60
</dispatch>
73
61
62
+ (: Protected resource :)
63
+ else if ($exist:path eq "/put-package" ) then
64
+ <dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
65
+ <forward url = "{$exist:controller} /modules/put-package.xq" />
66
+ </dispatch>
67
+
74
68
else if (ends-with ($exist:resource, ".html" ) and starts-with ($exist:path, "/packages" )) then
75
69
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
76
70
<forward url = "{concat ($exist:controller, '/packages.html' )} " />
77
71
<view>
78
- <forward url = "{concat ($exist:controller, '/modules/view.xql ' )} " >
72
+ <forward url = "{concat ($exist:controller, '/modules/view.xq ' )} " >
79
73
<add-parameter name = "abbrev" value = "{substring-before ($exist:resource, '.html' )} " />
80
74
</forward>
81
75
</view>
82
76
</dispatch>
83
77
84
78
else if (ends-with ($exist:resource, ".html" )) then
85
- (: the html page is run through view.xql to expand templates :)
79
+ (: the html page is run through view.xq to expand templates :)
86
80
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
87
81
<view>
88
- <forward url = "modules/view.xql " >
82
+ <forward url = "modules/view.xq " >
89
83
<set-header name = "Cache-Control" value = "no-cache" />
90
84
</forward>
91
85
</view>
92
86
</dispatch>
93
87
94
- else if (contains ($exist:path, "/public/" ) and ends-with ($exist:resource, ".zip" )) then
88
+ else if (contains ($exist:path, "/public/" ) and ends-with ($exist:resource, ".xar" ) or ends-with ($exist:resource, ".zip" )) then
89
+ <dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
90
+ <forward url = "{$exist:controller} /modules/get-package.xq" >
91
+ <add-parameter name = "filename" value = "{$exist:resource} " />
92
+ </forward>
93
+ </dispatch>
94
+
95
+ else if (contains ($exist:path, "/public/" ) and (ends-with ($exist:resource, ".png" ) or ends-with ($exist:resource, ".svg" ))) then
95
96
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
96
- <forward url = "../modules/download-xar-zip.xq" />
97
+ <forward url = "{$exist:controller} /modules/get-icon.xq" >
98
+ <add-parameter name = "filename" value = "{$exist:resource} " />
99
+ </forward>
97
100
</dispatch>
98
101
99
- else if ($exist:path eq "/find" or ends-with ($exist:resource, ".zip" ) ) then
102
+ else if ($exist:path eq "/find" ) then
100
103
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
101
- <forward url = "modules/find.xql " >
104
+ <forward url = "modules/find.xq " >
102
105
<add-parameter name = "app-root-absolute-url" value = "{$app-root-absolute-url} " />
103
106
</forward>
104
107
</dispatch>
105
108
106
109
else if ($exist:resource eq "feed.xml" ) then
107
110
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
108
- <forward url = "modules/feed.xql " />
111
+ <forward url = "modules/feed.xq " />
109
112
</dispatch>
110
113
111
114
else if (contains ($exist:path, "/$shared/" )) then
@@ -117,16 +120,9 @@ else if (contains($exist:path, "/$shared/")) then
117
120
118
121
else if (contains ($exist:path, "/resources/" )) then
119
122
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
120
- <forward url = "{$exist:controller} /resources/{substring-after ($exist:path, '/resources/' )} " >
121
- <set-header name = "Cache-Control" value = "max-age=3600, must-revalidate" />
122
- </forward>
123
+ <set-header name = "Cache-Control" value = "max-age=3600, must-revalidate" />
123
124
</dispatch>
124
125
125
- else if (ends-with ($exist:path, ".xml" )) then
126
- <dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
127
- <set-header name = "Cache-Control" value = "no-cache" />
128
- </dispatch>
129
-
130
126
else
131
127
(: everything else is passed through :)
132
128
<dispatch xmlns = "http://exist.sourceforge.net/NS/exist" >
0 commit comments