blob: 4060556767c47824a99ccf49136f6584ec275c2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HTCd/1.2 Server (H. Rydberg, 2001)
% Supports methods HEAD, GET, PUT, POST, DELETE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Useragent setting
%
\if(count \req.accept.lang){\setlang{\req.accept.lang}}
\const{FRAMES}(int(\req.useragent past "Mozilla/")>=2);
\if{\FRAMES}{
\redef{target}{x}{
\if(
(\1 cnt "//") ||
( (\sub{\1}{0}{1} eq "/") && ("HEAD BODY FOOT" which (\1 past "/" left "/"))==0)
){ target=_top}
}
}
\const{killframes}{
\if(int(\req.useragent past "Mozilla/")>2){
if(self!=top) top.location.replace(self.location)}{
if(self!=top) top.location=self.location}}
%
% Set userid and other cookies
% Handle errors directly
%
[userok:=1;];
\def{statlog}{x}{\resp.status{\HTTP.[\1]}}
\for(i:=0)(i<\ncookie)(i+=1){
\switch{\cookie[i].name}
{LANG}{
\setlang{\cookie[i].val}
}
{FRAMES}{
\reconst{FRAMES}(int \cookie[i].val);
}
{AUTH}{
%MIGRATION to HTCd/1.1
%Just silently remove the cookie and continue
\resp.cookie{AUTH}{deleted}{path=/; expires=\time2http{1}}
}
{ID}{
[uid:=\cookie[i].val left ".";pin:=\cookie[i].val past "."];
\setuser(uid);
[MAXFAIL:=\on.clear{EXPERT}{1}{3}];
\if(\user.id && \user.pin eq pin){
\if(\user.fail>0){
\if(\user.fail>=MAXFAIL){
\statlog{409}[userok=0;];
\resp.cont.type.charset{};
\output{
\body{
\h3{Login \lang{Failure}{fel}}
\lang{
There has been too many bad logins.
Please contact the \href{mailto:\ADMIN}{Server Administrator}.
}{
F{\"o}r m{\aa}nga login-fel har gjorts.
Var v{\"a}nlig kontakta \href{mailto:\ADMIN}{Serveradministrat{\"o}ren}.
}
}
}
\setcookie{ID}{deleted}{1}
}{
\mail.user{LOGIN ALERT}{
\lang{
There has been (\user.fail) PIN failures
}{
Ett antal (\user.fail) PIN fel har gjorts.
}
\user.lastin; (\gethost{\user.lastin})
\time2htc{\user.last}
}
\user.fail.set{0}\user.update;
}
}{
\if(\user.lastin ne \remote.address){
\on.clear{EXPERT}{
\mail.user{HOST ALERT}{
\lang{
A change of access address has occured.
}{
Ett byte av access-adress har intr{\"a}ffat.
}
\lang{Current access:}{Nuvarande access:}
\remote.address; (\remote.name)
\time2htc{\now}
\lang{Last access:}{Senaste access:}
\user.lastin; (\gethost{\user.lastin})
\time2htc{\user.last}
}
}{
\log{HOST ALERT \user.lastin -> \remote.address}
}
}
}
}{
\if{\user.id}{
\user.fail.set(\user.fail+1)\user.update;
\if(\user.fail==MAXFAIL){
\mail.root{PIN failure}{
PIN failure (\user.fail) for \user.id: \user.name <\user.email>
From: \remote.address:\remote.port; (\remote.name)
}
}
}
\statlog{409}[userok=0;];
\resp.cont.type.charset{};
\output{
\body{
\h3{\lang{Bad User}{Felaktig anv{\"a}ndare}}
\lang{
Please check your user credentials and press the Back button.
}{
Var v{\"a}nlig kontrollera din anv{\"a}ndarinformation
och tryck p{\aa} Tillbaka-knappen.
}
}
}
\setcookie{ID}{deleted}{1}
}
}
}
%
% At this point, user is set.
%
\if(\user.id){\user.last.set{\now}\user.lastin.set{\remote.address}\user.update}
%
% userok tells whether we should continue or not.
%
\if(userok){
%
% Start by checking special URIs
%
[muri:=\req.uri;sroute:=muri past "/" left "/"];
\if(sroute eq "POST")(muri=muri past "/" past sroute;sroute=muri past "/" left "/");
\const{this}(muri);
\if("LOGIN LOGOUT" which sroute)(muri=muri past "/" past sroute)(sroute="");
\const{referer}{\server;[muri]\andarg}
[route:=muri past "/" left "/";];
\if("SRC RAW HEAD FOOT BODY" which route)(muri=muri past "/" past route)(route="");
\seturi(muri);
[lroute:=muri past "/" left "/";];
\if("en sv" which lroute){[muri=muri past "/" past lroute]\setlang(lroute)}(lroute="");
\const{andlang}{/\lang{en}{sv}}
%
% sroute -> LOGIN|LOGOUT|none
% route -> SRC|RAW|HEAD|FOOT|BODY|none
% lroute -> en|sv|none
% this -> req.uri without POST
% referer -> complete URL (without POST|LOGIN|LOGOUT)
% uri -> directory URI (without SRC|RAW|HEAD|FOOT|BODY)
% andlang -> /[lang]
% muri -> mappable uri (without en|sv)
%
% Check method and dispatch
%
\if(\req.method eq "PUT" || \req.method eq "DELETE"){
%
% PUT and DELETE treated together
%
[wclear:=\upload.clear(muri)];
\if((count sroute)||(count lroute)|| !("SRC RAW" which route)||(wclear eq "ROOT")){
\statlog{405};
\resp.cont.type.charset{};
\output{
\body{
\h3{\lang{Method not allowed}{Metoden ej till{\aa}ten}}
\lang{
\req.method is not allowed here.
}{
\req.method; {\"a}r ej till{\aa}ten h{\"a}r.
}
<p>
\href{\server}{\lang{Home}{Hem}}
}
}
}{
\if{\user.allow(wclear){\now}}{
\statlog{200};
\if(\req.method eq "DELETE"){\upload.delete(muri)}{\upload.put(muri)}
}{
\statlog{409}
\resp.cont.type.charset{};
\output{
\body{
\h3{\lang{Conflict}{Konflikt}}
\lang{
The request could not be granted.
}{
Kommandot kunde ej utf{\"o}ras.
}
<p>
\href{\server}{\lang{Home}{Hem}}
}
}
}
}
}{
%
% HEAD, GET and POST treated together
%
[fallow:=0;uallow:=0;rallow:=0;callow:=0];
\switch(sroute){LOGIN}{\page.login}{LOGOUT}{\page.logout}{
\staturi(muri){
\if(stat.URI ne muri){
[canonized:={\server\andlang;[stat.URI]\andarg}];
\resp.status{\HTTP.301};
\resp.location(canonized);
\resp.cont.type.charset{};
\output{\href(canonized)(canonized)}
}{
\if(count stat.ALIAS){\db{TREE}(@<-stat.)};
\setgroup(first stat.X.CLEAR);
[
fallow=1;
ttime:=\if(stat.MOD&36){\now}(stat.LASTMOD);
uallow=\user.allow(stat.X.CLEAR)(ttime);
rallow=\remote.allow(stat.X.DOMAIN);
callow=\cookie.allow(stat.X.COOKIE);
];
\nif((count stat.REFER) && uallow && rallow && callow)(userok=0){
\statlog{200}[cacheok:=0];
\if("text/x-htc text/x-htx text/html" which stat.MIME){
\if(\req.method eq "POST"){
\show.page;
}{
\switch(route)
{SRC}{
\show.srcpage
}
{RAW}{
\show.rawpage
}
{HEAD}{
\page.header
}
{FOOT}{
\page.footer
}
{BODY}{
\show.page;
[cacheok=(first \resp.getstatus == 200);]
}
{
\if(count lroute){\layout}{
[canonized:={\server\andlang\uri\andarg}];
\resp.status{\HTTP.301};
\resp.location(canonized);
\resp.cont.type.charset{};
\output{\href(canonized)(canonized)}
}
}
}
}{
\resp.cont.type(stat.MIME);
\output{\load(stat.REFER)}[cacheok=1;]
}
\if(cacheok&&(count stat.X.CACHE)){
\resp.pragma{}
\if(stat.X.CACHE){
\resp.lastmod{\time2http(stat.LASTMOD)}
[expire:=\now+stat.X.CACHE;
\if(expire<=stat.LASTMOD)(expire=stat.LASTMOD+1)];
\resp.expires{\time2http(expire)}
}
}
}
}
}(userok=0)
}
\nif(userok){
\statlog{404};
\resp.cont.type.charset{};
\output{
\body{
\h3{\lang{Not Found}{Ej hittad}}
\lang{
The requested uri (\req.uri) could not be found.
}{
Den beg{\"a}rda sidan (\req.uri) kunde inte hittas.
}
\nif{\user.id}{
\if(\req.useragent cnt "Mozilla"){
<p>
\lang
{The reason \it{may} be that you need need to }
{Andledningen \it{kan} vara att du beh{\"o}ver }
\href{/LOGIN\req.uri\andarg}{\lang{login}{logga in}} \lang{first}{f{\"o}rst}.
}{
<p>
\lang{
The reason \it{may} be that your user credentials were improperly set.
}{
Anledningen \it{kan} vara att din anv{\"a}ndar information {\"a}r felaktigt satt.
}
<p>
\lang{
Please go back try again.
}{
G{\aa} tillbaka och f{\"o}rs{\"o}k igen.
}
}
}{
\if(fallow){
<p>
\lang{Reason:}{Orsak:}
\nif(uallow){\lang{Bad clearance}{Fel r{\"a}ttigheter}}
\nif(rallow){\lang{Bad access address}{Felaktig access-adress}}
\nif(callow){\lang{Bad cookie}{Felaktig 'cookie'}}
}
}
<p>
\href{\server}{\lang{Home}{Hem}}
}
}
}
}
}
|