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