From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- htc/server.htc | 321 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 htc/server.htc (limited to 'htc/server.htc') 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 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 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. + } +

+ \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. + } +

+ \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"){ +

+ \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}. + }{ +

+ \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. + } +

+ \lang{ + Please go back try again. + }{ + G{\aa} tillbaka och f{\"o}rs{\"o}k igen. + } + } + }{ + \if(fallow){ +

+ \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'}} + } + } +

+ \href{\server}{\lang{Home}{Hem}} + } + } + } + } +} -- cgit v1.2.3