#!/mod/bin/jimsh

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

jqplugin enadis
jscss script.js style.css
header

pkg loaddiagmeta
eval_plugins diagmeta

set model [system model]
set smv [system modversion 1]

puts {
<div class=cleft>
<fieldset>
<legend>Diagnostics</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>
</table>
</fieldset>
}

######################################################################
# Utilities

proc util {icon id text {link "#"} {extra ""}} {{col 0}} {
	if {[incr col] > 3} {
		puts "</tr><tr>"
		set col 1
	}
	if {![string match "*/*" $icon]} {
		set icon "/img/$icon.png"
	}
	puts "
<td>
	<a href=$link id=$id>
		<img class=button src=$icon>
		<br>
		<span class=label>$text</span>$extra
	</a>
</td>
"
}

puts {
<fieldset>
<legend>Utilities</legend>
<table class=button>
<tr>
}

util "editor" "editor" "File Editor" "/edit/edit.jim"
util "db" "dbinfo" "Database Browser" "/db/"
util "aerials" "muxinfo" "Mux Info" "/diag/mux.jim"

util "disc" "disk" "Disk Diagnostics" "/diag/disk.jim"
util "dspace" "diskspace" "Disk Space" "/diag/dspace/"

if {$model eq "HDR"} {
	util "dlna_large" "dlna" "DLNA Reset" "/dlna/dlna.jim"
}

if {$smv >= 310} {
	util "safe" "safe" "Safe Mode" "#" "<br><span id=saferesult></span>"
}

util "reset" "reset" "CFW Reset" "#" "<br><span id=resetresult></span>"
util "shredder" "rma" "RMA" "#" "<br><span id=rmaresult></span>"

util "bluering" "reboot" "Reboot System" "/restart/"
util "maint" "maint" "Maintenance Mode" "#" "<br><span id=maintresult></span>"
util "queuep" "queue" "Queued Tasks" "/diag/queue/"

eval_plugins diag

puts {
</tr>
</table>
</fieldset>

<fieldset>
<legend>System Information</legend>
}

source /mod/webif/include/modversion.jim

puts "</fieldset>"

######################################################################
# Second column
puts "</div><div class=left>"

######################################################################
# Log Files

puts {
<fieldset>
<legend>View Log Files</legend>
}

source /mod/webif/html/log/_lib.jim
foreach file [lsort -command logsort $loglist] {
	puts "
	    <img border=0 height=14 src=/images/421_1_00_CH_Title_2R_Arrow.png>
	    <a href=\"../log/?log=[cgi_quote_url $file]\">
	    	[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>
}

source /mod/webif/html/diag/assets.jim

footer

