#!/usr/bin/tclsh.docsrc #### Import of wapp.tcl INCLUDE wapp.tcl #### End of wapp.tcl # Generate all header content for the output document # proc search_header {} { wapp-trim { DOCHEAD {Search SQLite Stats} {../} } } proc wapp-default {} { # When running using the built-in webserver in Wapp (in other words, # when not running as CGI) any filename that contains a "." loads # directly from the filesystem. if {[string match *//127.0.0.1:* [wapp-param BASE_URL]] && [string match *.* [wapp-param PATH_INFO]] } { set altfile [file dir [wapp-param SCRIPT_FILENAME]]/../[wapp-param PATH_INFO] set fd [open $altfile rb] fconfigure $fd -translation binary wapp-unsafe [read $fd] close $fd switch -glob -- $altfile { *.html { wapp-mimetype text/html } *.css { wapp-mimetype text/css } *.gif { wapp-mimetype image/gif } } return } wapp-page-admin } proc wapp-page-admin {} { wapp-allow-xorigin-params wapp-content-security-policy off sqlite3 db2 [file dir [wapp-param SCRIPT_FILENAME]]/searchlog.db set where "" set res "" set ipfilter "" set ipaddr [wapp-param ip] if {$ipaddr!=""} { set where {WHERE ip = $ipaddr} set ipfilter $ipaddr } set checked "" set isUnique [expr {[wapp-param unique 0]+0}] if {$isUnique} { set checked "checked" } set limit [wapp-param limit 10] set s10 "" set s100 "" set s1000 "" if {$limit==10} {set s10 selected} if {$limit==100} {set s100 selected} if {$limit==1000} {set s1000 selected} search_header set self [wapp-param PATH_HEAD] wapp-trim {
Results: IP: Unique:
IP Query Results Timestamp } set i 0 db2 eval " SELECT rowid, ip, query, nres, timestamp FROM log $where ORDER BY rowid DESC " { if {$isUnique} { if {[info exists seen($query)]} continue set seen($query) 1 } wapp-trim {
%html($rowid) %html($ip) %html($query) %html($nres)%html($timestamp) } incr i if {$i >= $limit} break } wapp-subst {