shrub/arvo/eyre.hoon

938 lines
33 KiB
Plaintext
Raw Normal View History

!: :: %eyre, http servant
2014-03-12 23:50:39 +04:00
!? 164
::::
2013-12-15 09:42:27 +04:00
|= pit=vase
2013-09-29 00:21:18 +04:00
=> =~
2014-06-07 22:36:31 +04:00
|% :: interfaces
2014-06-08 06:45:00 +04:00
++ chop ,[p=@ud q=@da] :: see
2014-06-03 09:07:32 +04:00
++ gift :: out result <-$
2014-07-15 06:45:04 +04:00
$% [%thou p=httr] :: raw http response
2014-06-04 14:40:09 +04:00
[%thus p=@ud q=(unit hiss)] :: http request/cancel
2014-10-04 02:32:10 +04:00
[%veer p=@ta q=path r=@t] :: drop-through
[%vega p=path] :: drop-through
2015-02-10 04:52:29 +03:00
== ::
2015-02-20 02:33:39 +03:00
++ gram :: inter-ship message
$? [[%lon ~] p=hole] :: login request
[[%aut ~] p=hole] :: login reply
[[%hat ~] p=hole q=hart] :: login redirect
== ::
2014-09-11 03:35:03 +04:00
++ hasp ,[p=ship q=term] :: don't see %gall
++ hapt ,[p=ship q=path] :: do see %gall
2014-06-03 09:07:32 +04:00
++ kiss :: in request ->$
2014-06-04 14:40:09 +04:00
$% [%born ~] :: new unix process
[%crud p=@tas q=(list tank)] :: XX rethink
2014-06-04 14:40:09 +04:00
[%init p=@p] :: report install
2015-02-06 08:00:35 +03:00
:: [%them p=(unit hiss)] :: outbound request
:: [%they p=@ud q=httr] :: inbound response
2014-06-04 14:40:09 +04:00
[%this p=? q=clip r=httq] :: inbound request
[%thud ~] :: inbound cancel
2015-03-09 23:06:00 +03:00
[%wart p=sack q=@tas r=_`[path *]`*gram] :: urbit message
2014-06-04 14:40:09 +04:00
== ::
2014-06-22 09:49:10 +04:00
++ move ,[p=duct q=(mold note gift)] :: local move
2014-06-03 09:07:32 +04:00
++ note :: out request $->
2015-03-09 23:06:00 +03:00
$% $: %a :: to %ames
$% [%want p=sock q=[path *]] ::
== == ::
2014-06-22 06:51:12 +04:00
$: %d :: to %dill
$% [%flog p=[%crud p=@tas q=(list tank)]] ::
== == ::
$: %f :: to %ford
$% [%exec p=@p q=(unit silk)] ::
2015-02-19 00:35:22 +03:00
[%wasp p=@p q=@uvH] ::
2015-03-12 02:51:04 +03:00
== == ::
$: %g :: to %gall
$% [%mess p=hapt q=ship r=cage] ::
[%nuke p=hapt q=ship] ::
[%show p=hapt q=ship r=path] ::
[%took p=hapt q=ship] ::
2015-02-27 00:17:29 +03:00
== == == ::
2014-06-11 18:06:36 +04:00
++ rave :: see %clay
2015-02-10 04:52:29 +03:00
$% [& p=mood] ::
2014-06-11 18:06:36 +04:00
== ::
++ riff ,[p=desk q=(unit rave)] :: see %clay
2014-07-12 22:24:52 +04:00
++ silk :: see %ford
$& [p=silk q=silk] ::
$% [%boil p=mark q=beam r=path] ::
2014-07-27 14:26:17 +04:00
[%cast p=mark q=silk] ::
2014-07-12 22:24:52 +04:00
[%done p=(set beam) q=cage] ::
== ::
2014-10-04 02:32:10 +04:00
++ sine ::
$? sign ::
$: %g ::
$% [%veer p=@ta q=path r=@t] ::
[%vega p=path] ::
== == == ::
2014-06-22 09:49:10 +04:00
++ sign :: in result $<-
2015-03-03 04:52:55 +03:00
$? $: %f :: by %ford
2015-02-19 00:35:22 +03:00
$% [%made p=@uvH q=(each cage tang)] ::
[%news ~] ::
2015-03-12 02:51:04 +03:00
== == ::
$: %g :: by %gall
$% [%dumb ~] ::
[%mean p=ares] ::
[%nice ~] ::
[%rush p=mark q=*] ::
[%rust p=mark q=*] ::
2015-02-19 00:35:22 +03:00
== == ::
2014-06-22 06:51:12 +04:00
$: @tas :: by any
$% [%crud p=@tas q=(list tank)] ::
== == == ::
2015-03-12 02:51:04 +03:00
++ whir $| ~ :: wire subset
$% [%at p=hole q=whir] ::
[%to p=span:ship q=term r=span:ship ~] ::
== ::
2014-06-22 06:51:12 +04:00
-- ::
2014-06-07 22:36:31 +04:00
|% :: models
2013-09-29 00:21:18 +04:00
++ bolo :: eyre state
2014-05-31 02:10:39 +04:00
$: %0 :: version
gub=@t :: random identity
2014-06-10 00:09:14 +04:00
hov=(unit ship) :: master for remote
2014-03-12 23:50:39 +04:00
ged=duct :: client interface
ney=@uvI :: rolling entropy
dop=(map host ship) :: host aliasing
2015-02-17 01:06:58 +03:00
liz=(jug beam (each duct oryx)) :: clay subscriptions
2015-02-26 04:20:45 +03:00
wup=(map hole cyst) :: secure sessions
2015-03-09 23:06:00 +03:00
sop=(map hole ,[ship ?]) :: foreign session names
2014-06-10 00:09:14 +04:00
== ::
2015-03-03 04:52:55 +03:00
::
2015-02-18 00:05:28 +03:00
++ cyst :: client session
$: ced=cred :: credential
2015-03-04 05:22:02 +03:00
[him=ship aut=(set ship)] :: authenticated
2015-02-18 00:05:28 +03:00
cug=(list ,@t) :: unacked cookies
lax=@da :: last used
2015-03-09 23:06:00 +03:00
way=(map ship ,[purl duct]) :: waiting auth
2015-03-04 05:22:02 +03:00
vew=(set oryx) :: open views XX expire
2015-02-18 00:05:28 +03:00
== ::
2015-03-03 04:52:55 +03:00
::
++ perk :: parsed request
$% [%spur p=spur]
[%beam p=beam]
[%poll p=@uvH]
[%auth perk-auth]
2015-03-09 23:55:54 +03:00
[%away ~]
2015-03-12 02:51:04 +03:00
[%bugs %as ~]
[%mess p=hasp q=mark r=json]
2015-03-03 04:52:55 +03:00
==
::
++ perk-auth :: parsed auth
$% [%get him=ship rem=pork]
2015-03-09 23:06:00 +03:00
[%xen ses=hole rem=pork]
2015-03-04 05:22:02 +03:00
[%at p=pork] :: inject auth
2015-03-03 04:52:55 +03:00
[%js ~]
2015-03-04 05:22:02 +03:00
[%json ~]
2015-03-03 04:52:55 +03:00
[%try him=ship cod=cord]
[%del p=(unit ship)]
==
2015-03-04 05:22:02 +03:00
::
++ pest :: result
$% [%for p=whir q=beam r=term s=cred] :: %f block
2015-03-12 02:51:04 +03:00
[%fot p=whir q=mark r=cage] :: %f translate
2015-03-04 05:22:02 +03:00
[%fow p=@uvH] :: %f deps
[%fin $|(~ pest-fin)] :: done
2015-03-12 02:51:04 +03:00
[%mez p=hapt q=ship r=cage] :: %g message
2015-03-13 03:17:00 +03:00
[%red %html] :: redirect
2015-03-04 05:22:02 +03:00
[%zap p=@ud q=(list tank)] :: err
==
::
++ pest-fin :: response
2015-03-09 23:06:00 +03:00
$% [%code p=@ud q=pest-fin]
[%json p=json]
2015-03-04 05:22:02 +03:00
[%html p=manx]
[%js p=@t]
[%$ p=httr]
==
2014-03-12 23:50:39 +04:00
-- ::
|%
2015-03-09 23:55:54 +03:00
++ session-from-cookies
2015-03-03 04:52:55 +03:00
|= [nam=@t maf=math]
2015-02-18 00:05:28 +03:00
^- (unit hole)
=+ ^= cok ^- (list ,@t)
2015-03-03 04:52:55 +03:00
=+ cok=(~(get by maf) 'cookie')
2015-02-18 00:05:28 +03:00
?~(cok ~ u.cok)
|- ^- (unit hole)
?~ cok ~
=+ mar=`(unit (list ,[p=@t q=@t]))`(rush i.cok cock:epur)
?~ mar $(cok t.cok)
|- ^- (unit hole)
?~ u.mar ^$(cok t.cok)
2015-03-09 23:55:54 +03:00
?: &(=(nam p.i.u.mar) !=('~' q.i.u.mar))
[~ q.i.u.mar]
$(u.mar t.u.mar)
2015-02-27 00:23:46 +03:00
::
2015-02-27 03:04:12 +03:00
++ heat :: eat headers
2015-02-06 08:00:35 +03:00
|= hed=(list ,[p=@t q=@t]) ^- math
%+ roll hed
|= [a=[p=cord cord] b=math]
=. p.a (cass (trip p.a))
(~(add ja b) a)
2015-02-27 00:23:46 +03:00
::
2015-03-12 02:51:04 +03:00
++ wush
|= [wid=@u tan=tang]
^- tape
=+ rolt=|=(a=wall `tape`?~(a ~ :(weld i.a "\0a" $(a t.a))))
(rolt (turn tan |=(a=tank (rolt (wash 0^wid a)))))
::
2015-02-27 03:04:12 +03:00
++ tanx :: tanks to manx
2015-03-12 02:51:04 +03:00
|= tan=tang
2015-02-17 02:19:58 +03:00
^- manx
;html
;head
;meta(charset "utf-8");
;title: server error
==
2015-03-12 02:51:04 +03:00
;body:pre:code:"{(wush 160 tan)}"
2015-02-17 02:19:58 +03:00
==
::
2015-02-27 03:04:12 +03:00
++ depo :: inject dependency
2015-02-19 00:35:22 +03:00
|= [dep=@uvH max=manx]
2015-02-17 02:19:58 +03:00
^- manx
?> ?=([[%html ~] [[%head ~] *] [[%body ~] ^] ~] max) :: XX static
?~ dep max
2015-02-19 00:35:22 +03:00
max(c.i.c :_(c.i.c.max ;script@"/~/on/{<dep>}.js";))
2015-02-17 02:19:58 +03:00
::
2015-03-04 05:22:02 +03:00
++ jass :: inject window.urb
|= [urb=json jaz=cord] ^- cord
%^ cat 3
(crip "window.urb = {(pojo urb)}\0a")
jaz
::
2015-02-11 22:26:42 +03:00
++ js :: static javascript
|%
2015-02-27 03:04:12 +03:00
++ poll :: dependency long-poll
2015-02-11 22:26:42 +03:00
'''
2015-02-14 06:43:17 +03:00
urb.tries = 0
2015-02-11 22:26:42 +03:00
urb.call = function() {
2015-02-14 06:43:17 +03:00
xhr = new XMLHttpRequest()
xhr.open('GET', urb.poll, true)
2015-02-11 22:26:42 +03:00
xhr.addEventListener('load', function() {
2015-02-17 02:19:58 +03:00
// if(~~(this.status / 100) == 4)
// return document.write(xhr.responseText)
if(this.status !== 205) {
2015-02-14 06:43:17 +03:00
return urb.keep()
2015-02-11 22:26:42 +03:00
}
2015-02-14 06:43:17 +03:00
document.location.reload()
})
xhr.addEventListener('error', urb.keep)
xhr.addEventListener('abort', urb.keep)
xhr.send()
2015-02-11 22:26:42 +03:00
}
urb.keep = function() {
2015-02-14 06:43:17 +03:00
setTimeout(urb.call,1000*urb.tries)
urb.tries++
2015-02-11 22:26:42 +03:00
}
2015-02-14 06:43:17 +03:00
urb.call()
2015-02-11 22:26:42 +03:00
'''
2015-03-03 04:52:55 +03:00
::
++ auth
'''
2015-03-09 23:55:54 +03:00
var req = function(url,dat,cb){
var xhr = new XMLHttpRequest()
xhr.open('POST', url, true)
dat.oryx = urb.oryx
xhr.send(JSON.stringify(dat))
xhr.addEventListener('load', function(ev){
if(this.status !== 200)
2015-03-12 02:51:04 +03:00
return err.innerHTML = ":( " + Date.now() + "\n" + xhr.responseText
2015-03-09 23:55:54 +03:00
else if(cb) return cb(xhr.responseText,ev)
})
}
2015-03-04 05:22:02 +03:00
ship.innerText = urb.ship
2015-03-09 23:06:00 +03:00
urb.foreign = /^\/~\/am/.test(window.location.pathname)
urb.submit = function(){
2015-03-09 23:55:54 +03:00
req(
"/~/auth.json?PUT",
{ship: ship.innerText, code: pass.value},
function(){
if(urb.foreign) document.location =
2015-03-09 23:06:00 +03:00
document.location.hash.match(/#[^?]+/)[0].slice(1) +
document.location.pathname.replace(
/^\/~\/am\/[^/]+/,
'/~/as/~' + urb.ship) +
document.location.search
else document.location.reload()
2015-03-09 23:55:54 +03:00
})
2015-03-03 04:52:55 +03:00
}
2015-03-09 23:55:54 +03:00
urb.away = function(){req("/~/auth.json?DELETE", {},
function(){document.write("success!")})}
2015-03-03 04:52:55 +03:00
'''
--
++ xml
|%
++ login-page
;html
2015-03-09 23:55:54 +03:00
;head:title:'Log in'
2015-03-03 04:52:55 +03:00
;body
2015-03-04 05:22:02 +03:00
;p: Identify yourself, ~;{span#ship(contenteditable "")}?
;style:'#ship {background: lightgray} #ship br {display: none}'
2015-03-03 04:52:55 +03:00
;input#pass(onchange "urb.submit()");
;pre:code#err;
2015-03-04 05:22:02 +03:00
;script@"/~/at/~/auth.js";
2015-03-03 04:52:55 +03:00
==
==
2015-03-09 23:55:54 +03:00
::
++ logout-page
;html
;head:title:'Log out'
;body
;p: Goodbye ~;{span#ship}.
;button#act(onclick "urb.away()"): Log out
;pre:code#err;
;script@"/~/at/~/auth.js";
==
==
2015-02-11 22:26:42 +03:00
--
2013-09-29 00:21:18 +04:00
--
2014-03-12 23:50:39 +04:00
|% :: functions
++ ye :: per event
2014-06-04 14:40:09 +04:00
=| $: $: hen=duct :: event floor
2014-03-12 23:50:39 +04:00
$: now=@da :: event date
eny=@ :: unique entropy
2015-02-11 22:26:42 +03:00
our=ship :: current ship
2014-03-12 23:50:39 +04:00
sky=$+(* (unit)) :: system namespace
== ::
2014-03-12 23:50:39 +04:00
mow=(list move) :: pending actions
== ::
bolo :: all vane state
== ::
=* bol ->
|%
2015-02-27 03:04:12 +03:00
++ abet :: resolve moves
2014-03-12 23:50:39 +04:00
^- [(list move) bolo]
[(flop mow) bol]
2013-09-29 00:21:18 +04:00
::
2015-02-27 03:04:12 +03:00
++ adit .(ney (mix eny ney)) :: flip entropy
2013-09-29 00:21:18 +04:00
::
2015-03-03 04:52:55 +03:00
++ anon `@p`(add our ^~((bex 64))) :: pseudo-sub
2015-02-27 03:04:12 +03:00
++ axon :: accept response
2014-06-22 09:49:10 +04:00
|= [tea=wire typ=type sih=sign]
2014-06-04 14:40:09 +04:00
^+ +>
2015-03-09 23:06:00 +03:00
=. our ?~(hov our u.hov) :: XX
2014-06-22 06:51:12 +04:00
?- -.+.sih
2014-06-04 14:40:09 +04:00
%crud
2014-06-22 06:51:12 +04:00
+>.$(mow [[hen %slip %d %flog +.sih] mow])
2015-02-10 04:52:29 +03:00
::
2015-03-12 02:51:04 +03:00
?(%dumb %rush %rust) ~|(%gall-stub !!)
%nice ?>(?=(~ tea) nice-json) :: XX subscriptions
%mean ?>(?=(~ tea) (mean-json 500 p.sih))
2015-02-10 04:52:29 +03:00
%made
2015-03-09 23:06:00 +03:00
=+ tee=((soft whir) tea)
?~ tee ~& e/ford/lost/hen +>.$
=. our (need hov) :: XX
|- ^+ ..axon
?- u.tee
2015-03-12 02:51:04 +03:00
[%to ^]
?: ?=(%| -.q.sih)
(mean-json 500 ~ %cast-fail p.q.sih)
~| u.tee
=+ [her app him]=(raid +.u.tee %p %tas %p ~)
(pass-note ~ %g [%mess [her app ~] him p.q.sih])
2015-03-09 23:06:00 +03:00
[%at ^]
?. ?=([%& %js ^] q.sih)
~& e/at-lost/p.u.tee
$(u.tee q.u.tee)
=* cag p.q.sih
?> ?=(@ q.q.cag)
=+ cyz=(~(got by wup) p.u.tee)
=^ jon ..ya ~(stat-json ya p.u.tee cyz)
$(u.tee q.u.tee, q.q.p.q.sih (jass jon q.q.cag))
~
2015-02-10 04:52:29 +03:00
:: ~& e/ford/hen
2015-02-12 00:10:07 +03:00
?- -.q.sih
2015-02-17 01:06:58 +03:00
| (fail 404 p.sih p.q.sih)
& =* cag p.q.sih
2015-02-14 06:43:17 +03:00
?+ p.cag (back ~ p.sih cag)
%hipo :: hacks!
?> ?=(@tas -.q.q.cag)
$(p.q.sih [-.q.q.cag (slot 3 q.cag)])
::
%mime
~| q.q.cag
=+ ((hard ,[mit=mite rez=octs]) q.q.cag) :: XX
2015-03-03 04:52:55 +03:00
(give-gift %thou 200 [content-type/(moon mit)]~ ~ rez)
2015-02-14 06:43:17 +03:00
==
2015-02-10 04:52:29 +03:00
==
==
::
2015-03-03 04:52:55 +03:00
%news (give-json 205 ~ %b &) :: dependency updated
2014-06-04 14:40:09 +04:00
==
::
2015-02-27 03:04:12 +03:00
++ apex :: accept request
2014-06-04 14:40:09 +04:00
|= kyz=kiss
^+ +>
2015-03-09 23:06:00 +03:00
=. our ?~(hov our u.hov) :: XX
2014-06-04 14:40:09 +04:00
?- -.kyz
%born +>.$(ged hen) :: register external
%crud
+>.$(mow [[hen %slip %d %flog kyz] mow])
2014-03-23 23:42:18 +04:00
%init :: register ownership
2014-06-04 14:40:09 +04:00
%_ +>.$
hov ?~(hov [~ p.kyz] [~ (min u.hov p.kyz)])
2014-03-23 23:42:18 +04:00
==
2015-02-18 00:05:28 +03:00
::
2014-03-12 23:50:39 +04:00
%this :: inbound request
2014-06-04 14:40:09 +04:00
=* sec p.kyz :: ? :: https bit
=* heq r.kyz :: httq :: request content
2014-03-12 23:50:39 +04:00
=+ ryp=`quri`(rash q.heq zest:epur)
2015-03-03 04:52:55 +03:00
=+ maf=(heat r.heq)
2014-03-12 23:50:39 +04:00
=+ ^= pul ^- purl
?- -.ryp
& ?>(=(sec p.p.p.ryp) p.ryp)
2015-03-03 04:52:55 +03:00
| =+ hot=(~(get ja maf) %host)
2015-02-11 22:26:42 +03:00
?> ?=([@ ~] hot)
[[sec (rash i.hot thor:epur)] p.ryp q.ryp]
2014-03-12 23:50:39 +04:00
==
2015-01-15 04:47:51 +03:00
=. p.p.pul |(p.p.pul ?=(hoke r.p.pul))
2015-03-12 02:51:04 +03:00
abet:~(handle rq pul [anon q.+.kyz] [p.heq maf s.heq])
::
%thud :: cancel request
2015-02-06 08:00:35 +03:00
~& e/gone/hen
+>.$
2015-02-20 02:33:39 +03:00
::
%wart :: remote request
=+ mez=((soft gram) r.kyz)
?~ mez
~& [%strange-wart p.kyz q.kyz]
+>.$
2015-03-09 23:06:00 +03:00
?- -<.u.mez
%aut abet:(logon:(ses-ya p.u.mez) q.p.kyz)
%hat (foreign-hat:(ses-ya p.u.mez) q.p.kyz q.u.mez)
%lon
~& ses-ask/[p.u.mez sop (~(run by wup) ,~)]
?: (ses-authed p.u.mez)
(ames-gram q.p.kyz aut/~ p.u.mez)
=. sop (~(put by sop) p.u.mez q.p.kyz |)
(ames-gram q.p.kyz hat/~ p.u.mez our-host)
2015-02-20 02:33:39 +03:00
==
2014-03-12 23:50:39 +04:00
==
2013-09-29 00:21:18 +04:00
::
2015-03-09 23:06:00 +03:00
++ ses-authed
|= ses=hole
=+ sap=(~(get by sop) ses)
?: ?=([~ @ %&] sap) &
=+ cyz=(~(get by wup) ses)
?~ cyz |
(~(has in aut.u.cyz) our)
::
++ ses-ya |=(ses=hole ~(. ya ses (~(got by wup) ses)))
++ our-host `hart`[| [~ 8.445] `/localhost] :: XX testing
2015-03-03 04:52:55 +03:00
++ fail :: request failed
|= [sas=@ud dep=@uvH mez=tang]
^+ +>
:: (back ~ dep %tang !>(mez)) :: XX broken tang->mime door in ford
2015-03-09 23:06:00 +03:00
(give-html sas ~ (depo dep (tanx mez)))
2015-03-03 04:52:55 +03:00
::
++ give-html :: request failed
2015-03-09 23:06:00 +03:00
|= [sas=@ud cug=(list ,@t) max=manx]
%- give-gift
%+ add-cookies cug
(make-resp-gift sas text//html (crip (poxo max)))
2015-03-03 04:52:55 +03:00
::
++ give-json :: success json
|= [sas=@uG cug=(list ,@t) jon=json]
%- give-gift
2015-03-09 23:06:00 +03:00
%+ add-cookies cug
(make-resp-gift sas application//json (crip (pojo jon)))
::
2015-03-12 02:51:04 +03:00
++ nice-json (give-json 200 ~ (joba %ok %b &))
++ mean-json
|= [sas=@uG are=ares]
=- (give-json sas ~ (jobe fail/s/typ mess/(jape err) ~))
^- [typ=term err=tape]
?~ are [%fail "Unknown Error"]
[p.u.are (wush 160 q.u.are)]
::
2015-03-09 23:06:00 +03:00
++ add-cookies
|= [cug=(list ,@t) git=[%thou httr]]
2015-03-03 04:52:55 +03:00
?~ cug git
=+ cuh=(turn `(list ,@t)`cug |=(a=@t set-cookie/a))
git(q (weld cuh q.git))
::
++ give-gift :: done card
|= gef=gift
+>(mow :_(mow [hen %give gef]))
::
++ resp :: mime response
2015-03-04 05:22:02 +03:00
|= [sas=@uG mit=mite bod=cord]
2015-03-09 23:06:00 +03:00
(give-gift (make-resp-gift sas mit bod))
::
++ pass-note |=(noe=[whir note] +>(mow :_(mow [hen %pass noe])))
++ ames-gram
|=([him=ship gam=gram] (pass-note ~ %a %want [our him] [%e -.gam] +.gam))
2015-03-03 04:52:55 +03:00
::
++ ford-req
2015-03-04 05:22:02 +03:00
|= [tea=whir our=ship kas=silk]
2015-03-03 04:52:55 +03:00
:: ~& [%ford-req our num ses -.kas]
(pass-note tea %f [%exec our `kas])
::
2015-02-06 08:00:35 +03:00
++ back :: %ford bounce
2015-03-04 05:22:02 +03:00
|= [tea=whir dep=@uvH cag=cage]
2015-03-03 04:52:55 +03:00
(ford-req tea our [%cast %mime %done ~ cag]) :: XX deps
::
2015-03-09 23:06:00 +03:00
++ make-resp-gift :: mimed response
2015-03-03 04:52:55 +03:00
|= [sas=@uG mit=mite rez=@]
:: (weld (turn cug |=(a=@t ['set-cookie' a]))
[%thou `httr`[sas ~[content-type/(moon mit)] [~ (taco rez)]]]
2015-02-11 22:26:42 +03:00
::
2015-03-03 04:52:55 +03:00
++ host-to-ship :: host to ship
2014-03-12 23:50:39 +04:00
|= hot=host
^- (unit ship)
=+ gow=(~(get by dop) hot)
?^ gow gow
2015-02-27 03:04:12 +03:00
?. ?=(& -.hot) ~
=+ dom=(flop p.hot) :: domain name
?~ dom ~
(rush i.dom fed:ag)
2013-09-29 00:21:18 +04:00
::
2015-03-03 04:52:55 +03:00
++ rq
|_ $: [hat=hart pok=pork quy=quay] :: purl, parsed url
2015-03-12 02:51:04 +03:00
[him=ship cip=clip] :: client ip
2015-03-03 04:52:55 +03:00
[mef=meth maf=math bod=(unit octs)] :: method/headers/body
2015-02-27 03:04:12 +03:00
==
2015-03-03 04:52:55 +03:00
++ done .
++ abet ..rq
++ teba |*(a=$+(* ..rq) |*(b=* %_(done ..rq (a b))))
++ fail (teba ^fail)
++ resp (teba ^resp)
++ give-html (teba ^give-html)
++ give-gift (teba ^give-gift)
++ give-json (teba ^give-json)
2015-03-12 02:51:04 +03:00
++ nice-json (teba ^nice-json)
2015-03-03 04:52:55 +03:00
++ pass-note (teba ^pass-note)
++ ford-req (teba ^ford-req)
++ back (teba ^back)
2015-02-19 02:25:55 +03:00
::
2015-03-03 04:52:55 +03:00
++ ford-kill (pass-note ~ %f [%exec our ~]) :: XX unused
++ beam-into-ford
2015-03-04 05:22:02 +03:00
|= [tea=whir bem=beam ext=term ced=cred]
2015-03-03 04:52:55 +03:00
=: s.bem [%web ~(rent co (flux:ya quy ced)) s.bem]
r.bem ?+(r.bem r.bem [%ud %0] da/now)
2015-02-18 00:05:28 +03:00
==
2015-03-09 23:06:00 +03:00
(ford-req tea our [%boil ext bem ~])
2015-02-06 08:00:35 +03:00
::
2015-03-03 04:52:55 +03:00
::
++ as-beam
^- (unit beam)
|-
?~ q.pok
$(q.pok /index)
?. ((sane %tas) i.q.pok)
(tome q.pok)
`[[our i.q.pok da/now] (flop t.q.pok)]
::
++ as-magic-filename
^- (unit gift)
?+ [(fall p.pok %$) q.pok] ~
[?(%ico %png) %favicon ~]
:- ~
2015-03-09 23:06:00 +03:00
%^ make-resp-gift 200 image//png
2015-03-03 04:52:55 +03:00
0w89wg.GV4jA.l9000.00dPb.YzBT6.giO00.o100d.wZcqc.a9tg-.VTG0b.
AUIvE.HBM3g.cK4SE.0aagi.l090p.I1P5g.Y-80r.y1YS9.1xE~Y.qgpFY.
vKN1V.905y0.2UwvL.43TUw.uL406.0-31h.xwoJF.Ul454.ilk00.00Yps.
BNumh.xpl9B.pS5Ji.i1BoC.ZAgg1.BsC5T.t6pLk.Thohn.gp000.0ov~P.
7M000.0o840.00010.0001i.h4x93.g0000.Eq2wR.7jB29
::
[%txt %robots ~]
:- ~
2015-03-09 23:06:00 +03:00
%^ make-resp-gift 200 text//plain
2015-03-03 04:52:55 +03:00
%- role
:~ 'User-agent: *'
'Disallow: /'
==
2015-02-06 08:00:35 +03:00
==
2015-03-03 04:52:55 +03:00
::
++ as-aux-request :: /~/... req parser
^- (unit perk)
|-
?: ?=([%'~~' *] q.pok) :: auth shortcut
$(q.pok ['~' %as %own t.q.pok])
?. ?=([%'~' @ *] q.pok) ~
2015-03-12 02:51:04 +03:00
:- ~ ^- perk
2015-03-03 04:52:55 +03:00
=* pef i.t.q.pok
=+ but=t.t.q.pok :: XX =*
?+ pef ~|(pfix-lost/`path`/~/[pef] !!)
%on
~| on/bad-path/but
2015-03-12 02:51:04 +03:00
[%poll (raid but %uv ~)]
::
2015-03-03 04:52:55 +03:00
%as
:+ %auth %get
~| bad-ship/?~(but ~ i.but)
?~ but !!
:_ pok(q t.but)
?+ i.but (slav %p i.but)
%anon anon
%own our
2015-02-18 00:05:28 +03:00
==
2015-03-12 02:51:04 +03:00
::
2015-03-09 23:06:00 +03:00
%am ?~(but !! [%auth %xen i.but pok(q t.but)])
2015-03-04 05:22:02 +03:00
%at [%auth %at pok(q but)]
2015-03-09 23:55:54 +03:00
%away [%away ~]
2015-03-12 02:51:04 +03:00
%debug ;;(perk [%bugs but])
2015-03-03 04:52:55 +03:00
%auth
:- %auth
2015-03-09 23:55:54 +03:00
|- ^- perk-auth
2015-03-03 04:52:55 +03:00
?+ p.pok !!
~ $(p.pok [~ %json])
[~ %js] [%js ~]
[~ %json]
?+ mef ~|(%bad-meth !!)
2015-03-04 05:22:02 +03:00
%get [%json ~]
2015-03-03 04:52:55 +03:00
%post
?+ quy ~|(bad-quy/'"PUT" or "DELETE"' !!)
[[%'PUT' ~] ~]
=+ paz=(ot ship/(su fed:ag) code/so ~):jo
~| parsing/bod
2015-03-12 02:51:04 +03:00
[%try (grab-body paz)]
2015-03-03 04:52:55 +03:00
::
[[%'DELETE' ~] ~]
2015-03-09 23:55:54 +03:00
~| parsing/bod
=+ jon=(need (poja q:(need bod)))
?> ?=(%o -.jon)
=+ sip=(~(get by p.jon) %ship)
[%del ?~(sip ~ [~ (need ((su:jo fed:ag) u.sip))])]
2015-03-12 02:51:04 +03:00
==
2015-03-03 04:52:55 +03:00
== ==
2015-03-12 02:51:04 +03:00
::
%to
=- [%mess [- +<]:dir +>.dir (grab-body (ot:jo xyro/some ~))]
^= dir
=+ ful=(read but %p %tas %tas ~)
?^ ful u.ful
~| bad-mess/but
[our (raid but %tas %tas ~)]
==
::
++ grab-body
|* a=fist:jo ^+ (need *a)
~| parse-fail/bod
?> &(?=(%post mef) ?=(^ bod))
(need %.(q.u.bod ;~(biff poja a)))
2015-02-18 00:05:28 +03:00
::
2015-03-03 04:52:55 +03:00
++ handle
^+ done
2015-03-09 23:06:00 +03:00
=+ oar=(host-to-ship r.hat)
=. our ?~(oar our u.oar) :: XX
2015-03-04 05:22:02 +03:00
=+ pez=process
?: ?=(%| -.pez) p.pez :: XX transitional
2015-03-09 23:06:00 +03:00
=+ status=200
2015-03-04 05:22:02 +03:00
|- ^+ done
?- -.p.pez
2015-03-13 03:17:00 +03:00
%for (beam-into-ford +.p.pez)
%fot (ford-req p.p.pez our [%cast q.p.pez %done ~ r.p.pez])
%fow (pass-note ~ %f [%wasp our p.p.pez])
%mez (pass-note ~ %g [%mess +.p.pez])
%zap (fail p.p.pez 0v0 q.p.pez)
%red
=+ url=(earn hat pok(p [~ %html]) quy)
?+ p.pok (fail 404 0v0 leaf/"bad redirect" leaf/<p.pok> leaf/url ~)
[~ %js]
$(p.pez [%fin %js (crip "document.location = '{url}'")])
[~ %json]
$(p.pez [%fin %json (jobe ok/b/| red/(jape url) ~)])
==
::
%fin
?~ +.p.pez done
?- &2.p.pez
~ (give-gift %thou p.p.pez)
%js (resp status text//javascript p.p.pez)
%html (give-html status ~ p.p.pez)
%json (give-json status ~ p.p.pez)
%code $(+.p.pez q.p.pez, status p.p.pez)
==
==
2015-03-04 05:22:02 +03:00
::
++ process
^- (each pest ,_done)
=+ git=as-magic-filename
?^ git [%| (give-gift u.git)]
%- |= a=(each (each pest ,_done) tang)
?~(-.a p.a [%& %zap 404 >%exit< p.a])
%- mule |. ^- (each pest ,_done)
~| [mef maf bod]
2015-03-03 04:52:55 +03:00
=+ bem=as-beam
2015-03-04 05:22:02 +03:00
?^ bem (process-parsed %beam u.bem)
2015-03-03 04:52:55 +03:00
?> check-oryx
=+ hem=as-aux-request
2015-03-04 05:22:02 +03:00
?^ hem (process-parsed u.hem)
2015-03-03 04:52:55 +03:00
~|(strange-path/q.pok !!)
2015-02-18 00:05:28 +03:00
::
2015-03-03 04:52:55 +03:00
++ check-oryx :: | if json with bad oryx
^- ?
?. &(?=([~ %json] p.pok) ?=(%post mef) ?=(^ bod)) &
=+ oxe=(parse-to-oryx q.u.bod)
?~ oxe |
2015-03-04 05:22:02 +03:00
& ::(~(has in vew.cyz:for-client) u.oxe) ::XX
2015-02-18 00:05:28 +03:00
::
2015-03-03 04:52:55 +03:00
++ parse-to-oryx ;~(biff poja (ot oryx/so ~):jo)
2015-03-04 05:22:02 +03:00
++ root-beak `beak`[our %main ud/0] :: XX
++ process-parsed
2015-03-03 04:52:55 +03:00
|= hem=perk
2015-03-04 05:22:02 +03:00
^- (each pest ,_done)
2015-03-03 04:52:55 +03:00
?- -.hem
2015-03-04 05:22:02 +03:00
?(%spur %beam)
=+ ext=(fall p.pok %urb)
=+ bem=?-(-.hem %beam p.hem, %spur [root-beak p.hem])
[%& %for ~ bem ext ced.cyz:for-client]
2015-03-03 04:52:55 +03:00
%poll
2015-03-04 05:22:02 +03:00
?: ?=([~ %js] p.pok) :: XX treat non-json cases?
2015-03-09 23:55:54 +03:00
=+ polling-url=['/' (apex:earn %| pok(u.p %json) quy)]
2015-03-04 05:22:02 +03:00
:^ %& %fin %js
2015-03-09 23:06:00 +03:00
(jass (joba %poll (jape polling-url)) poll:js)
2015-03-04 05:22:02 +03:00
?~ p.hem [%| done]
[%& %fow p.hem]
2015-03-09 23:55:54 +03:00
%away [%& %fin %html logout-page:xml]
2015-03-12 02:51:04 +03:00
%bugs (show-login-page)
%mess =+ cay=[%json !>(`json`r.hem)]
?: ?=(%json q.hem)
[%& %mez [- + ~]:p.hem him cay]
=+ wir=to//(scot %p p.p.hem)/[q.p.hem]/(scot %p him)
[%& %fot wir q.hem cay]
2015-03-04 05:22:02 +03:00
%auth
=+ yac=for-client
2015-03-03 04:52:55 +03:00
?- &2.hem
2015-03-04 05:22:02 +03:00
%json
:- %|
=^ jon ..ya stat-json.yac
(give-json 200 ~ jon)
%js [%& %fin %js auth:js]
%at
=. ..ya abet.yac
=+ pez=process(pok p.hem)
?. ?=(%& -.pez) ~|(no-inject/p.hem !!)
2015-03-12 02:51:04 +03:00
?+ -.p.pez ~&(bad-inject/p.pez !!)
?(%zap %red) pez
2015-03-04 05:22:02 +03:00
%for pez(p.p [%at ses.yac p.p.pez])
%fin
~| %not-script
?> ?=(%js &2.p.pez)
=^ jon ..ya stat-json:for-client :: XX state lost
pez(p.p (jass jon p.p.pez))
==
::
2015-03-03 04:52:55 +03:00
%try
2015-03-09 23:06:00 +03:00
~& ses-try/ses.yac
2015-03-04 05:22:02 +03:00
:- %|
2015-03-03 04:52:55 +03:00
?. =(our him.hem)
~|(stub-foreign/him.hem !!)
?. =(load-secret cod.hem)
~|(try/`@t`load-secret !!)
2015-03-04 05:22:02 +03:00
=^ jon ..ya stat-json:(logon:yac him.hem)
(give-json 200 cug.yac jon)
2015-03-03 04:52:55 +03:00
::
2015-03-09 23:55:54 +03:00
%del
=. ..ya (logoff:yac p.hem)
=+ cug=[(cat 3 cookie-prefix '=~; Path=/')]~
[%| (give-json 200 cug (joba %ok %b &))]
2015-03-03 04:52:55 +03:00
%get
~| aute/+.hem
2015-03-04 05:22:02 +03:00
?: |(=(anon him.hem) (~(has in aut.yac) him.hem))
2015-03-12 02:51:04 +03:00
=. him him.hem
2015-03-04 05:22:02 +03:00
=+ pez=process(pok rem.hem)
?. ?=([%& %for ^] pez)
pez
pez(aut.s.p (~(put ju aut.s.p.pez) %$ (scot %p him.hem)))
2015-03-03 04:52:55 +03:00
?. =(our him.hem)
2015-03-09 23:06:00 +03:00
[%| ((teba foreign-auth:for-client) him.hem hat rem.hem quy)]
(show-login-page ~)
%xen
(show-login-page ~ ses.hem)
2015-03-03 04:52:55 +03:00
==
==
2015-03-09 23:06:00 +03:00
++ show-login-page
|= ses=(unit hole) ^- (each pest ,_done)
2015-03-13 03:17:00 +03:00
?. ?=($|(~ [~ %html]) p.pok)
[%& %red %html]
2015-03-09 23:06:00 +03:00
?~ ses
[%& %fin %code 401 %html login-page:xml]
=+ yac=~(. ya u.ses (ses-cyst u.ses))
=. ..ya abet.yac
[%| (give-html 401 cug.yac login-page:xml)]
::
2015-03-03 04:52:55 +03:00
++ load-secret
^- @ta
=+ pax=/(scot %p our)/code/(scot %da now)/(scot %p our)
%^ rsh 3 1
(scot %p (,@ (need (sky %a pax))))
::
2015-03-09 23:06:00 +03:00
++ cookie-prefix (rsh 3 1 (scot %p our))
2015-03-04 05:22:02 +03:00
++ for-client :: stateful per-session engine
^+ ya
2015-03-09 23:06:00 +03:00
=+ pef=cookie-prefix
2015-03-09 23:55:54 +03:00
=+ lig=(session-from-cookies pef maf)
2015-03-03 04:52:55 +03:00
?^ lig
2015-03-09 23:06:00 +03:00
=+ cyz=(~(got by wup) u.lig)
~(. ya u.lig cyz(cug ~))
2015-03-03 04:52:55 +03:00
=+ ses=(rsh 3 1 (scot %p (end 6 1 ney)))
2015-03-09 23:06:00 +03:00
~(. ya ses (ses-cyst ses))
::
++ ses-cyst
|= ses=hole
=* sec p.hat
=+ pef=cookie-prefix
2015-03-03 04:52:55 +03:00
^- cyst
:* ^- cred
:* hat(p sec)
~
2015-03-09 23:06:00 +03:00
'not-yet-implemented' ::(rsh 3 1 (scot %p (end 6 1 (shaf %oryx ses))))
2015-03-03 04:52:55 +03:00
::
=+ lag=(~(get by maf) %accept-language)
?~(lag ~ ?~(u.lag ~ [~ i.u.lag]))
::
cip
~
==
[anon ~]
::
:_ ~
%^ cat 3
(cat 3 (cat 3 pef '=') ses)
:: (cat 3 '; HttpOnly' ?.(sec '' '; Secure'))
'; Path=/; HttpOnly'
::
now
~
2015-03-09 23:06:00 +03:00
~
2015-03-03 04:52:55 +03:00
:: [1 ~]
==
--
2014-03-12 23:50:39 +04:00
++ ya :: session engine
2015-03-04 05:22:02 +03:00
=| [ses=hole cyst]
=* cyz ->
2014-03-12 23:50:39 +04:00
|%
2015-03-04 05:22:02 +03:00
++ abet ..ya(wup (~(put by wup) ses cyz))
++ abut ..ya(wup (~(del by wup) ses))
2015-03-09 23:06:00 +03:00
++ logon
|= her=ship
%_ +>
him her
aut (~(put in aut) her)
..ya
~& logon/[our her ses]
?. =(our her)
..ya
=+ sap=(~(get by sop) ses)
~& sap
?. ?=([~ @ %|] sap)
..ya
(ames-gram -.u.sap aut/~ ses)
==
2015-03-04 05:22:02 +03:00
++ logoff
|= her=(unit ship) ^+ ..ya
?~ her abut
=. aut (~(del in aut) u.her)
?~ aut abut
abet(him ?.(=(her him) him n.aut))
::
2015-03-09 23:06:00 +03:00
++ foreign-auth
|= [him=ship pul=purl] ^+ ..ya
=. way (~(put by way) him pul hen)
(ames-gram:abet him [lon/~ ses])
::
++ foreign-hat
|= [him=ship hat=hart] ^+ ..ya
~| way
=^ pul hen (~(got by way) him)
=. way (~(del by way) him)
=. q.q.pul ['~' %am ses q.q.pul]
=+ url=(welp (earn pul(p hat)) '#' (head:earn p.pul))
%- give-gift
%+ add-cookies cug
:+ %thou 307
[[location/(crip url)]~ ~]
::
2015-03-04 05:22:02 +03:00
++ stat-json
^+ [*json ..ya]
=+ orx=(rsh 3 1 (scot %p (shaf %orx eny)))
=. vew (~(put in vew) orx)
:_ abet
%- jobe :~
oryx/s/orx
ship/(jape +:<our>)
user/(jape +:<him>)
auth/a/(turn (~(tap in aut)) |=(a=@p (jape +:<a>)))
==
::
2015-02-10 04:52:29 +03:00
++ flux :: credential caboose
2015-02-27 03:04:12 +03:00
|= [quy=quay ced=cred] ^- coin
2015-02-10 04:52:29 +03:00
:* %many
[%$ %ta ~]
2015-02-26 04:20:45 +03:00
[%blob ced]
2015-02-10 04:52:29 +03:00
|- ^- (list coin)
?~ quy ~
[[%$ %t p.i.quy] [%$ %t q.i.quy] $(quy t.quy)]
==
2015-02-20 02:33:39 +03:00
++ inte
^- (unit $&([%lon purl] gram))
~
2014-03-12 23:50:39 +04:00
--
--
--
. ==
=| bolo
=* bol -
2014-05-31 23:40:02 +04:00
|= [now=@da eny=@ ski=sled] :: activate
2014-03-12 23:50:39 +04:00
^? :: opaque core
|% ::
2014-06-04 14:40:09 +04:00
++ call :: handle request
|= $: hen=duct
2014-06-04 21:56:30 +04:00
hic=(hypo (hobo kiss))
2014-06-04 14:40:09 +04:00
==
2014-06-06 03:00:19 +04:00
=> %= . :: XX temporary
q.hic
^- kiss
?: ?=(%soft -.q.hic)
((hard kiss) p.q.hic)
?: (~(nest ut -:!>(*kiss)) | p.hic) q.hic
~& [%eyre-call-flub (,@tas `*`-.q.hic)]
((hard kiss) q.hic)
==
2014-05-31 23:40:02 +04:00
^- [p=(list move) q=_..^$]
2015-02-27 00:23:46 +03:00
=+ our=`@p`0x100 :: XX sentinel
2014-05-31 23:40:02 +04:00
=+ ska=(slod ski)
2014-05-02 03:33:15 +04:00
=+ sky=|=(* `(unit)`=+(a=(ska +<) ?~(a ~ ?~(u.a ~ [~ u.u.a]))))
=. ney (shax :(mix (shax now) +(eny) ney)) :: XX!! shd not need
2014-05-31 23:40:02 +04:00
^- [p=(list move) q=_..^$]
2014-03-20 05:05:42 +04:00
=. gub ?.(=(0 gub) gub (cat 3 (rsh 3 1 (scot %p (end 6 1 eny))) '-'))
=^ mos bol
2015-02-11 22:26:42 +03:00
abet:(apex:~(adit ye [hen [now eny our sky] ~] bol) q.hic)
2014-03-12 23:50:39 +04:00
[mos ..^$]
2013-09-29 00:21:18 +04:00
::
2015-02-27 03:04:12 +03:00
++ doze :: require no timer
2013-12-15 09:42:27 +04:00
|= [now=@da hen=duct]
2013-09-29 00:21:18 +04:00
^- (unit ,@da)
~
::
2015-02-27 03:04:12 +03:00
++ load :: clam previous state
2015-03-09 23:06:00 +03:00
|= old=_[%0 gub hov ged ney dop liz wup=wup sop=sop]
2014-05-31 23:40:02 +04:00
^+ ..^$
2015-02-10 04:52:29 +03:00
..^$(+>- (bolo old))
2013-09-29 00:21:18 +04:00
::
++ scry
2014-05-27 00:43:40 +04:00
|= [our=(unit (set monk)) ren=@tas who=ship syd=desk lot=coin tyl=path]
^- (unit (unit (pair mark ,*)))
2013-09-29 00:21:18 +04:00
~
::
2014-05-31 23:40:02 +04:00
++ stay `bolo`+>-.$
2014-06-04 14:40:09 +04:00
++ take :: accept response
2014-10-04 02:32:10 +04:00
|= [tea=wire hen=duct hin=(hypo sine)]
2014-06-04 14:40:09 +04:00
^- [p=(list move) q=_..^$]
2014-10-04 02:32:10 +04:00
?: ?=(%veer +<.q.hin) :: vomit
[[hen %give +.q.hin]~ ..^$]
?: ?=(%vega +<.q.hin) :: vomit
[[hen %give +.q.hin]~ ..^$]
2015-02-27 00:23:46 +03:00
=+ our=`@p`0x100 :: XX sentinel
2014-06-04 14:40:09 +04:00
=+ ska=(slod ski)
=+ sky=|=(* `(unit)`=+(a=(ska +<) ?~(a ~ ?~(u.a ~ [~ u.u.a]))))
=. ney (shax :(mix (shax now) +(eny) ney)) :: XX!! shd not need
^- [p=(list move) q=_..^$]
=. gub ?.(=(0 gub) gub (cat 3 (rsh 3 1 (scot %p (end 6 1 eny))) '-'))
=^ mos bol
=< abet
2015-02-11 22:26:42 +03:00
%^ axon:~(adit ye [hen [now eny our sky] ~] bol) tea
2014-06-24 21:32:59 +04:00
(~(peek ut p.hin) %free 3)
2014-06-22 06:51:12 +04:00
q.hin
2014-06-04 14:40:09 +04:00
[mos ..^$]
2013-09-29 00:21:18 +04:00
--