#!/mod/bin/jimsh

package require cgi
source /mod/webif/lib/setup
require pretty_size system.class pkg.class

jqplugin enadis
jscss script.js style.css
header

pkg loaddiagmeta

set smv [system modversion 1]


puts {
<fieldset class=cleft>
<legend>Utilities</legend>
<table>

<tr>
<td>Run Diagnostic:</td>
<td class=va><span class=cleft>
<select name=diagsel id=diagsel class="text ui-widget-content ui-corner-all">
<option value=0>-- Select diag or type name in box below --
}

catch {
	foreach diag [array names ::diagmeta] {
		puts "<option value=\"$diag\">$diag\n"
	}
}

puts {
</select><br>
<input name=seq id=seq autocorrect=off autocapitalize=off
    value="general" size=30 maxlength=50
    class="text ui-widget-content ui-corner-all">
</span>
<span class="left va">
<button id=rundiag>Run Diagnostic</button>
</span>
</td>
</tr>

<tr>
<td>Package:</td>
<td><input name=fopkg id=fopkg autocorrect=off autocapitalize=off
    value='' size=30 maxlength=50
    class="text ui-widget-content ui-corner-all">
<button id=runfopkg>Force re-install</button>
</td>
</tr>

<tr><td colspan=2 style="height: 10px"></td></tr>

<tr>
<td colspan=2 align=center>
<button id=runedit class=half>File Editor</button>
<button id=dbinfo class=half>Database Browser</button>
</td>
</tr>

<tr>
<td colspan=2 align=center>
}
if {[system model] eq "HDR"} {
	puts { <button id=diskdiag class=half>Hard Disk</button> }
}
puts {
<button id=channelinfo class=half>Channel Information</button>
</td>
</tr>

<tr>
<td colspan=2 align=center>
<button id=dspace class=half>Disk Space</button>
}

if {[system model] eq "HDR"} {
	puts { <button id=dlna class=half>DLNA Server</button> }
}

puts {
</td>
</tr>

<tr><td colspan=2 style="height: 10px"></td></tr>

<tr>
<td colspan=2>
<button id=reboot style="width: 100%">Reboot System</button>
</td>
</tr>

<tr>
<td colspan=2>
<button id=runreset style="width: 100%"
}

if {$smv < 200} {
	puts -nonewline " disabled class=ui-state-disabled"
}

puts {
>
Remove all custom firmware packages and settings 
</button>
}

if {$smv < 200} {
	puts {
<div class=footnote style="text-align: center">
(Install custom firmware v2.00 to enable this option)
</div>
	}
}

puts {

<div id=resetdone class="hidden blood">
Restart your Humax with the remote control.<br>
Allow it to turn off completely before restarting.<br>
</div>

</td>
</tr>

<tr>
<td colspan=2>
<button id=runrma style="width: 100%"
}

if {$smv < 213} {
	puts -nonewline " disabled class=ui-state-disabled"
}

puts {
>
Set Return-to-manufacturer (RMA) Mode
</button>
}

if {$smv < 213} {
	puts {
<div class=footnote style="text-align: center">
(Install custom firmware v2.13 to enable this option)
</div>
	}
}

puts {

</td>
</tr>

</table>
<span class=also style="padding-left: 5px">
View:
<a href=/jim/ref.html target=_blank>Jim Reference Manual</a> |
<a href=/jim/oo.html target=_blank>OO</a> |
<a href=/jim/sqlite.html target=_blank>Sqlite</a>
</span>
</fieldset>

<fieldset class=left>
<legend>View Log Files</legend>
}

foreach file [lsort [concat \
    [glob -nocomplain /var/log/*.log] \
    [glob -nocomplain /mod/tmp/*.log] \
    [glob -nocomplain /mnt/hd3/*.log] \
]] {
	puts "<a href=# class=log file=\"$file\">
	    <img border=0 height=14 src=/images/421_1_00_CH_Title_2R_Arrow.png>
	    [file tail $file]</a>
	    (<span class=lsize>[pretty_size [file size $file]]</span>)
	    <a class=\"va footnote logclear\" href=# file=\"$file\">
	    <img class=va border=0 src=/img/close.png width=20>Clear</a>
	    <br>"
}

puts {
</fieldset>

<div style="margin-top: 2em; display: none; float: left; clear: left"
    id=results></div>

}

footer

