# $Id: html.itcl,v 1.2 2005/08/13 02:03:32 davidlallen Exp $ proc print_html_header_200 { chan contenttype lastmodified } { puts $chan "HTTP/1.0 200 OK" puts $chan [format "Date: %s GMT" [clock format [clock seconds] -format "%a, %d %b %Y %T" -gmt true]] if { $lastmodified != "" } { puts $chan [format "Last-Modified: %s GMT" [clock format $lastmodified -format "%a, %d %b %Y %T" -gmt true]] } puts $chan "Connection: close" puts $chan "Content-Type: $contenttype" puts $chan "" } proc print_html_header_304 { chan } { puts $chan "HTTP/1.0 304 Not Modified" puts $chan "Connection: close" puts $chan "" } proc print_html_header_401 { chan } { puts $chan "HTTP/1.0 401 Authorization Required" puts $chan "WWW-Authenticate: Basic realm=\"$TWP::NAME - v$TWP::VERSION\"" puts $chan "Connection: close" puts $chan "" } proc print_html_header_403 { chan } { puts $chan "HTTP/1.0 403 Forbidden" puts $chan "Connection: close" puts $chan "" } # Original; replaced with code below. #proc print_html_header_404 { chan } { # puts $chan "HTTP/1.0 404 Not Found" # puts $chan "Connection: close" # puts $chan "Content-Type: text/html; charset=iso-8859-1" # puts $chan " # # #404 Not Found # #

Not Found

#The requested URL was not found on this server. # #" #} if { $reload == 0 } { namespace eval INSULTS { array set a { 1 {I don't wanna talk to you no more, you empty headed animal food trough wiper! I fart in your general direction! Your mother was a hamster and your father smelt of elderberries! Now go away or I shall taunt you a second time-a!} 2 {Here I am, brain the size of a tivo and you ask me to display a 404 page? Call that job satisfaction? 'Cos I sure don't} 3 {It's about to print out a 404 error. I can tell by the intolerable air of smugness it suddenly generates. It's tivoweb's pleasure to render a page for you and their satisfaction to close the socket afterwards with the knowledge of of a job well done. Thank you tivoweb programmers, \"let's not write new features; let's waste a ton of memory on 404 messages\" they said. I'm a 404 prototype. You can tell can't you? I hate 404 messages. I'm not getting you down am I?} 4 {Oh look, it's another one of those mindbogglingly useful 404 pages. Don't pretend that you wanted to see this page, I know you hate me, everybody does. It's part of the shape of the universe. I only have to talk to somebody and they begin to hate me. Even other webservers hate me. If you just ignore me I expect I shall probably go away.} 5 {The page you're looking for is currently on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard} 6 {*&^@#%!$%#! where'd I put that page?} 7 {
Tmk Fatal Error: Thread tivoweb <42> died due to signal -2
NIP 0x1a36728 link 0x1c485ac ctr 29802260
R00 0x00000025  R01 0x7ffff3e0  R02 0x00000100  R03 0x00000000
R04 0x80a36018  R05 0x3003d5d7  R06 0x00000000  R07 0x00000000
R08 0x19999999  R09 0x01d88e6c  R10 0x000000e6  R11 0x3003d5d7
R12 0x00000000  R13 0x01d9ac08  R14 0x30000fb4  R15 0x00000000
R16 0x00000000  R17 0x00000000  R18 0x30000fc8  R19 0xffffffff
R20 0x30041a2e  R21 0x00000000  R22 0x3001839c  R23 0x00000002
R24 0x00000002  R25 0x00000003  R26 0x00000003  R27 0x00000004
R28 0x30015f40  R29 0x00000002  R30 0x30000fd0  R31 0x00000000
1a29e08 7ffff2f8 1c48598 1c48118 1c41c18 1c6c284 1c55e18 1c72934 1c7a520 1c41650 1c1d4e4 18
(just kidding)} 8 {You're rather presumptuous aren't you? I merely start to display the page and I'm immediately harrased by you before given time to do so. Perhaps I was actually going to give you the page this time... farell, have a good evening of being unfriendly} 9 {Congratulations! that's the [nth $404_counter] 404 page you've hit since the last reboot.} 10 {Ni! Ni! Ni! Ni! We shall say Ni! again if you do not appease us} 11 { <\[mbm\]> hmm, why doesn't tivoweb have some lame ass easter egg ?
<lightn> I thought your idea of insulting 404 errors was good
<\[mbm\]> thought you turned that down, something about censorship
<lightn> huh? no, I always liked it, I just didn't like your \"click here to crash your tivo\" } 12 {Surely you've not given up your quest for the Holy Grail?} 13 {I'm not quite dead yet!} 14 {Run away! Run away! Run away! Run away! Run away! Run away! Run away!} 15 {O Lord, bless this Thy tivoweb server that, with it, Thou mayest blow Thine enemies to tiny bits in Thy mercy} 16 {Now it is such a bizarrely improbable coincidence that anything so mindboggingly useful as this 404 page could have evolved purely by chance that some thinkers have chosen to see it as the final and clinching proof of the non-existance of tivoweb programmers.

The argument goes something like this: `I refuse to prove that we exist,' said one tivoweb programmer, 'for proof denies deniablity and without deniablity there'd be bug reports.'

'But,' says Man, 'Surely the 404 page is a dead giveaway isn't it? It could not have evolved by chance. It proves you exist, and so therefore, by your own arguments, you don't. QED.'

'Oh dear,' said the tivoweb programmer, 'I hadn't thought of that,' and the tivoweb programmers promptly vanished under flood of bug reports.} 17 {I knew I should have taken that left in Albuquerque!} 18 {YOUR AD HERE.} 19 {This page intentionally left blank.} } } set 404_counter 0 } proc print_html_header_404 { chan } { global 404_counter puts $chan "HTTP/1.0 404 Not Found" puts $chan "Connection: close" puts $chan "Content-Type: text/html; charset=iso-8859-1" incr 404_counter puts $chan " 404 Not Found

Not Found

" set size [expr [array size INSULTS::a] +1]; set rand [random 1 $size]; eval "puts $chan \"$INSULTS::a($rand)\"" puts $chan "" } proc print_html_error { chan action error } { puts $chan "
INTERNAL SERVER ERROR"
  puts $chan "--cut here--"
  puts $chan $action
  puts $chan $error
  puts $chan "--cut here--"
  puts $chan "
" } proc IE_alpha_support {} { global IE_alpha_trans_fix if {$IE_alpha_trans_fix == 1} { return { } } } proc html_start {args} { global url_prefix global IE_alpha_trans_fix set title [lindex $args 0] set submenu "" if { [llength $args] > 1 } { set submenu [lindex $args 1] } set additional "" if { [llength $args] > 2 } { set additional [lindex $args 2] } set ret "\n" append ret "\n" if {$title != ""} { append ret "$title\n" } if {$additional != ""} { append ret "$additional\n" } if {[info exists ::theme_list]} { foreach theme $::theme_list { if {$theme == $TWP::STYLE} { set type stylesheet } else { set type "alternate stylesheet" } append ret "\n" } } else { append ret "\n" } append ret [IE_alpha_support] append ret " " if { $submenu != "" } { append ret "" } append ret "
[html_link "/" $TWP::NAME]
v$TWP::VERSION
\[$::hostname\] 
" ######################################### # HACK 060703: Should really be removed # ######################################### # Fixup for IE not handling CSS:content # (put /'s before and after menu links) if { $TWP::STYLE == "faiec" && $IE_alpha_trans_fix } { foreach arg [split $TWP::OPTIONS_MENU "\n"] { if { $arg != "" } { append ret "/$arg/\n" } } } else { append ret "$TWP::OPTIONS_MENU" } ######################################### append ret "
$submenu
" } # added nomenu - boody proc html_start_nomenu {title bodyargs} { set ret "\n" append ret "\n" if {$title != ""} { append ret "$title\n" } append ret "\n" append ret [IE_alpha_support] append ret "\n" return $ret } proc html_end {} { return "
" } proc html_link {link anchor args} { global url_prefix if { [string index $link 0] == "/" } { set link "/$url_prefix[string range $link 1 end]" } if { [llength $args] > 0 && [lindex $args 0] != ""} { return "$anchor" } return "$anchor" } proc img {attr img} { global url_prefix return "" } proc td {args} { set ret " 1 } { set str [strim [lindex $args 1]] append ret " [lindex $args 0]" } else { set str [strim $args] } if { $str == "" } { append ret "> " } else { append ret ">$str" } return $ret } proc h1 {str} { if { $str == "" } { return "

 

" } else { return "

$str

" } } proc h2 {str} { if { $str == "" } { return "

 

" } else { return "

$str

" } } proc tr {attrs args} { set str "" foreach arg $args { append str $arg } if { $str == "" } { set str " " } return "$str" } proc th {args} { if { [llength $args] > 1 } { return "[strim [lindex $args 1]]" } else { return "[strim $args]" } } proc html_table_start {tattr cap capattr} { set ret "" if {$cap != ""} { append ret "" } return $ret } proc html_table_end {} { return "
$cap
" } proc html_form_select {name values labels defaultval args} { set str "" append str "" return $str } # added by boody proc html_form_checkbox {name chkd} { set str "" append str "" return $str } proc html_form_hidden {name value} { return "" } proc html_form_start {method action args} { global url_prefix if { [string index $action 0] == "/" } { set action "/$url_prefix[string range $action 1 end]" } set str "
" return $str } proc html_form_end {} { return "
" } proc html_form_input {type name value} { return "" } proc html_form_text {lines cols name value} { if {$lines == 1} { return "" } else { return "" } } proc add_slashes {str} { regsub -all {([\[\"\;\$])} $str {\\\1} str return $str } proc url_decode {str} { regsub -all {\+} $str " " str set str [add_slashes $str] regsub -all {%([a-fA-F0-9][a-fA-F0-9])} $str {[format "%c" 0x\1]} str set str "return \"$str\"" eval $str } proc parse_post {data} { set env "" while { [set j [string first "=" $data]] != -1 } { if { [set i [string first "&" $data]] == -1 } { set i [string length $data] } set key [add_slashes [string range $data 0 [expr $j - 1]]] set value [add_slashes [url_decode [string range $data [expr $j + 1] [expr $i - 1]]]] append env "set \"$key\" \"$value\";" set data [string range $data [expr $i + 1] end] } return $env } proc get_kvalue {keys values key} { set i [lsearch $keys $key] if { $i != -1 } { return [lindex $values $i] } else { return "" } } # For debugging purposes proc action_dumppost {chan path data} { puts $chan [html_start "Dump Post"] puts $chan "$data
" set parseddata [parse_post $data] set keys [lindex $parseddata 0] set values [lindex $parseddata 1] set numkeys [llength $keys] for {set i 0} {$i < $numkeys} {incr i} { set key [lindex $keys $i] set value [lindex $values $i] puts $chan "$key = $value
" } puts $chan [html_end] } # httpMapReply taken from http.tcl (part of TCL library.) # check sourceforge at http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/tcl/tcl/library/http1.0/http.tcl?rev=1.4&content-type=text/plain # do x-www-urlencoded character mapping # The spec says: "non-alphanumeric characters are replaced by '%HH'" # 1 leave alphanumerics characters alone # 2 Convert every other character to an array lookup # 3 Escape constructs that are "special" to the tcl parser # 4 "subst" the result, doing all the array substitutions proc httpMapReply {string} { global httpFormMap set alphanumeric a-zA-Z0-9 if {![info exists httpFormMap]} { for {set i 1} {$i <= 256} {incr i} { set c [format %c $i] if {![string match \[$alphanumeric\] $c]} { set httpFormMap($c) %[format %.2x $i] } } # These are handled specially array set httpFormMap { " " + \n %0a } } regsub -all \[^$alphanumeric\] $string {$httpFormMap(&)} string regsub -all \n $string {\\n} string regsub -all \t $string {\\t} string regsub -all {[][{})\\]\)} $string {\\&} string return [subst $string] } proc htmlEncode { text } { set ret "$text" regsub -all "\&" $ret {\&} ret regsub -all "<" $ret {\<} ret regsub -all ">" $ret {\>} ret regsub -all "\n" $ret {
} ret return "$ret" }