# CETK epic HTTP server script 0.0 load cetk.functions # Erase something from 2.8script which just gets in the way. on ^dcc_raw -"% % D %" alias.t serve.http (port default 8080, root default "serve.http.root", ...) { if (!isnumber(b10 $port)) { xecho -banner -- $port is not a number. xecho -banner -- Requires [] [] } elsif (0 > port) { ^on -dcc_raw -"% % N ${0-port}" ^dcc close raw_listen ${0-port} xecho -banner -- HTTP service on port ${0-port} closed } elsif (!aliasctl(alias pmatch ${root}*)) { xecho -banner -- No such alias structure ${root} xecho -banner -- Requires [] [] } elsif (!listen($port)) { xecho -banner -- Error: Port $port already in use? } else { ^on -dcc_raw "% % N $port" serve.http.connect $root \$* xecho -banner -- HTTP service on port $port serving alias structure $root } } alias.t serve.http.connect (root, ...) { ^on +dcc_raw "$0 % *" serve.http.connection $root \$* } alias.t serve.http.connection (root, ...) { switch ($2) { (e)(n)(c) { defer purge http[$0] defer ^dcc close raw $0 defer ^on dcc_raw -"$0 % *" } (d) { @:line=strip("$chr(13 10)" $3-) switch ($line) { (get % http/?.?) { @ http[$0][req] = before(? $word(1 $line)?) @ http[$0][alias] = unsplit(. $root $remws(/ $split(/ $http[$0][req]))) @ http[$0][args] = after(? $word(1 $line)) fe ($split(& $http[$0][args])) arg { @ http[$0][args][$before(= $arg=)] = urldecode($split(+ $after(= $arg))) } } (%:*) { push http[$0][head][$encode($before(: $line))] $after(: $line) } () { if (findw($http[$0][alias] $aliasctl(alias match $http[$0][alias]))) { serve.http.index $0-1 } else { $http[$0][alias] $0-1 } shook dcc_raw $0-1 c } (*) { echo Bad HTTP message? $line shook dcc_raw $0-1 c } } } } } alias.t serve.http.resphead (fd, hdrs default "\"Content-Type: text/html\"") { msg =$fd HTTP/1.0 200 OK$chr(13) fe ($hdrs) hdr { msg =$fd $hdr$chr(13) } msg =$fd $chr(13 10) } alias.t serve.http.page (fd,args) { serve.http.resphead $fd msg =$fd $html.head($shift(args)) $args msg =$fd } alias.t serve.http.prepage (fd,args) { serve.http.page $fd "$shift(args)" eval msg =$fd
\;$args\;msg =$fd 
} alias.t serve.http.index (fd,...) { serve.http.prepage $fd $http[$fd][req] foreach -$http[$fd][alias] foo { msg =$fd $foo } } alias.t serve.http.captureredirect { @ :redir = [cmdredir]##rand(${10**9}) ^alias $redir @setitem\($redir \$numitems\($redir\) \$*\) redirect /$redir $* @ function_return = listarray($redir "$chr(13 10)") ## chr(13 10) @ delarray($redir) ^alias -$redir } alias.t serve.http.dumparray (dcc,arrays) fe arrays array {@array=getarrays($array)};fe arrays array {for foo from 0 to ${numitems($array)-1} {msg =$dcc $getitem($array $foo)}} alias.t serve.http.dumpfd (dcc,fds) fe fds fd {until (eof($fd)){msg =$dcc $read($fd)}} alias.t serve.http.dumpfile (dcc,files) fe files file {@file=glob($file)};fe files file {@fd=open($file r),serve.http.dumpfd($dcc $fd),close($fd)} alias.t html.html return $* alias.t html.head return $* alias.t html.body return $* alias.t html.form (args) return
$args
alias.t html.input.submit return alias.t html.input.text (args) return alias.t html.pre return
$*
alias.t html.page (args) return $html.html($html.head($shift(args))$html.body($args)) alias.t serve.http.rediralias (cmd,...) alias serve.http.root.$cmd serve.http.prepage \$0 \$http[\$0][req] redirect =\$0 \{msg =\$fd \$html.form\(GET "\$http[\$fd][req]" \$html.input.text\(in \$http[\$fd][args][in]\)\$html.input.submit(rerun)\)\;$*\} serve.http.rediralias history.chan.chan list.chan $http[$fd][args][in] serve.http.rediralias history.chan.list list.chan.list $http[$fd][args][in] serve.http.rediralias history.chan.nuh list.chan.nuh $http[$fd][args][in] serve.http.rediralias history.chan.onuh list.chan.onuh $http[$fd][args][in] serve.http.rediralias history.nuh list.nuh $http[$fd][args][in] serve.http.rediralias history.onuh list.onuh $http[$fd][args][in] serve.http.rediralias queries.links allservs wait for links $http[$fd][args][in] serve.http.rediralias queries.list allservs wait for list $http[$fd][args][in] serve.http.rediralias queries.map allservs wait for map $http[$fd][args][in] serve.http.rediralias queries.motd allservs wait for motd $http[$fd][args][in] serve.http.rediralias queries.names allservs wait for names $http[$fd][args][in] serve.http.rediralias queries.stats allservs wait for stats $http[$fd][args][in] serve.http.rediralias queries.time allservs wait for time $http[$fd][args][in] serve.http.rediralias queries.trace allservs wait for trace $http[$fd][args][in] serve.http.rediralias queries.who allservs wait for who $http[$fd][args][in] serve.http.rediralias queries.whois allservs wait for whois $http[$fd][args][in] serve.http.rediralias queries.whowas allservs wait for whowas $http[$fd][args][in] serve.http.rediralias status.channel channel serve.http.rediralias status.cps cps $http[$fd][args][in] serve.http.rediralias status.dcc dcc $http[$fd][args][in] serve.http.rediralias status.screendump @:foo=[htsd.$fd];snapw $foo $http[$fd][args][in];@perlxcall(attr2html $foo $foo 0);serve.http.dumparray $fd $foo;@delarray($foo) serve.http.rediralias status.scrolldump @:foo=[htsd.$fd];snapl $foo $http[$fd][args][in];@perlxcall(attr2html $foo $foo 0);serve.http.dumparray $fd $foo;@delarray($foo) serve.http.rediralias test0.test1.test echo $*;assign.dump http.$fd.* #serve.http.rediralias test0.test1.file serve.http.dumpfile $fd $http[$fd][args][in] #serve.http 4444