#!/mod/bin/jimsh

package require cgi
source /mod/webif/lib/setup

source _lib.jim

cgi_input
#cgi_dump

httpheader

proc quote {s} {
	return [string map {
		{&} {&amp;}
		{"} {&quot;}
		{<} {&lt;}
		{>} {&gt;}
	    } $s]
}

set file [cgi_get file "-"]
if {$file eq "-"} { set file "/var/log/humaxtv.log" }
if {$file ni $loglist} { exit }

set lines [cgi_get lines 0]

if {$lines} {
	set fp [popen [list tail -n $lines $file]]
} else {
	set fp [open $file r]
}
set l 1
while {![$fp eof]} {
	$fp gets line
	if {[$fp eof]} break
	puts "<tr><td>$l</td><td>[quote $line]</td></tr>"
	incr l
}
$fp close

