2011-07-11 23:29:21 +00:00
|
|
|
#!/mod/bin/jimsh
|
|
|
|
|
2011-07-12 18:57:30 +00:00
|
|
|
package require cgi
|
2011-07-11 23:29:21 +00:00
|
|
|
package require sqlite3
|
|
|
|
source /mod/var/mongoose/lib/setup
|
|
|
|
require altrow
|
|
|
|
|
2011-07-12 18:57:30 +00:00
|
|
|
puts "Content-Type: text/html"
|
|
|
|
puts ""
|
|
|
|
|
2011-09-09 19:38:37 +00:00
|
|
|
set databases {
|
|
|
|
/var/lib/humaxtv/rsvp.db
|
|
|
|
/var/lib/humaxtv/rsv.db
|
|
|
|
/var/lib/humaxtv/setup.db
|
|
|
|
/var/lib/humaxtv/channel.db
|
|
|
|
/mnt/hd2/dms_cds.db
|
|
|
|
}
|
|
|
|
|
2011-07-12 18:57:30 +00:00
|
|
|
header
|
|
|
|
|
|
|
|
cgi_input
|
|
|
|
#cgi_dump
|
|
|
|
|
|
|
|
set ftab [cgi_get tab]
|
|
|
|
set fdb [cgi_get db]
|
|
|
|
|
|
|
|
if {$fdb != 0} {
|
|
|
|
puts "<h1><a href=/cgi-bin/db.jim>Remove filters</a></h1>"
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
proc db_info {db_file} {
|
2011-07-12 18:57:30 +00:00
|
|
|
global _cgi fdb ftab
|
|
|
|
|
|
|
|
if {$fdb != 0 && [file tail $db_file] ne $fdb} { return }
|
2011-07-11 23:29:21 +00:00
|
|
|
if {![file exists $db_file]} { return }
|
2011-07-12 18:57:30 +00:00
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
set db [sqlite3.open $db_file]
|
2011-07-12 18:57:30 +00:00
|
|
|
set tables [$db query {
|
|
|
|
select name from sqlite_master
|
|
|
|
where type='table' order by name
|
|
|
|
}]
|
|
|
|
|
|
|
|
puts "<h1><a href=/cgi-bin/db.jim?db=[file tail $db_file]>
|
|
|
|
$db_file</a></h1>"
|
2011-07-11 23:29:21 +00:00
|
|
|
|
|
|
|
foreach table $tables {
|
2011-07-12 18:57:30 +00:00
|
|
|
set table [lindex $table 1]
|
|
|
|
if {$ftab != 0 && $ftab ne $table} { continue }
|
|
|
|
set columns [$db query "pragma table_info($table)"]
|
|
|
|
set datas [$db query "SELECT * FROM $table order by 1"]
|
2011-07-11 23:29:21 +00:00
|
|
|
|
2011-07-12 18:57:30 +00:00
|
|
|
puts "<h2><a href=/cgi-bin/db.jim?db=[file tail $db_file]&tab=$table>$table</a></h2>"
|
|
|
|
puts "<table class=borders>"
|
2011-07-11 23:29:21 +00:00
|
|
|
puts " <tr>"
|
|
|
|
foreach column $columns {
|
|
|
|
puts " <th>[lindex $column 3]</th>"
|
|
|
|
}
|
|
|
|
puts " </tr>"
|
|
|
|
foreach data $datas {
|
|
|
|
altrow
|
|
|
|
|
|
|
|
for {set i 1} {$i < [llength $data]} {incr i 2} {
|
|
|
|
puts " <td>[lindex $data $i]</td>"
|
|
|
|
}
|
|
|
|
puts " </tr>"
|
|
|
|
}
|
|
|
|
puts "</table>"
|
|
|
|
}
|
|
|
|
|
|
|
|
$db close
|
|
|
|
}
|
|
|
|
|
2011-09-09 19:38:37 +00:00
|
|
|
if {$fdb == 0} {
|
|
|
|
puts "Please choose database to view:<ul>"
|
|
|
|
foreach db $databases {
|
|
|
|
puts "<li><a href=$::env(REQUEST_URI)?db=[file tail $db]>
|
|
|
|
$db</a></li>"
|
|
|
|
}
|
|
|
|
puts "</ul>"
|
|
|
|
} else {
|
|
|
|
foreach db $databases { db_info $db }
|
|
|
|
}
|
2011-07-12 18:57:30 +00:00
|
|
|
|
|
|
|
footer
|
2011-07-11 23:29:21 +00:00
|
|
|
|