webif/var/mongoose/cgi-bin/settings.jim
hummypkg 8949bfaa02 update pkg management and add update-all, add reset firmware button
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@443 2a923420-c742-0410-a762-8d5b09965624
2011-10-05 22:07:22 +00:00

250 lines
5.3 KiB
Plaintext
Executable File

#!/mod/bin/jimsh
package require cgi
source /mod/var/mongoose/lib/setup
require settings.class
require plugin
puts "Content-Type: text/html"
puts ""
cgi_input
#cgi_dump
set settings [settings new]
set hostname [$settings hostname]
set smtp_server [$settings smtp_server]
set channel_group [$settings channel_group]
set epg_style [$settings epg_style]
set pkgdev [$settings pkgdev]
# Handle updates
if {![dict exists $env REQUEST_URI]} { set env(REQUEST_URI) "" }
proc _handle_update {class var old text} {
global _cgi
global settings
if {[dict exists $_cgi $var]} {
set new [string trim [dict get $_cgi $var]]
if {$new == $old} {
puts "$text unchanged."
} elseif [string is $class -strict $new] {
$settings $var $new
puts "$text updated."
} else {
puts "Invalid value for $var."
}
exit
}
}
proc handle_int_update {var old {text "Value"}} {
_handle_update digit $var $old $text
}
proc handle_str_update {var old {text "Value"}} {
_handle_update alnum $var $old $text
}
handle_str_update hostname $hostname Hostname
_handle_update ascii smtp_server $smtp_server "SMTP Server"
handle_int_update channel_group $channel_group "Channel Group"
handle_str_update epg_style $epg_style "EPG Type"
if {[dict exists $_cgi pkgdevoff] && ![dict exists $_cgi pkgdev]} {
set _cgi(pkgdev) 0
}
handle_int_update pkgdev $pkgdev "Development Package Display"
header
puts {
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/jconfirmaction.jquery.js"></script>
<link href=/css/jconfirmaction.jquery.css rel=stylesheet type=text/css />
<script type="text/javascript" src="/js/iphone-style-checkboxes.js"></script>
<link href=/css/iphone-style-checkboxes.css rel=stylesheet type=text/css />
}
puts {
<script type=text/javascript>
$(document).ready(function () {
$(":submit").button();
$('form.auto').each(function(i, el) {
var id = $(this).attr('id');
var output = '#' + id + '_output'
$(this).ajaxForm({
target: output,
success: function() {
$(output).css('font-style', 'italic');
$(output).show('slow');
$(output).delay(2000).fadeOut('slow');
}
});
});
});
</script>
}
puts "
<fieldset style=\"display: inline\">
<legend>
General Settings
</legend>
<table>
"
puts "
<tr>
<form class=auto id=hostname method=get action=$env(REQUEST_URI)>
<th class=key>Hostname</th>
<td><input name=hostname value=\"$hostname\"
class=\"text ui-widget-content ui-corner-all\"
length=20 maxlength=50>
<small>
<input id=hostname_submit value=\"change\" type=submit>
</small>
<div id=hostname_output></div>
</td>
</form>
</tr>
"
puts "
<tr>
<form class=auto id=epg_style method=get action=$env(REQUEST_URI)>
<th class=key>Default Now/Next style</th>
<td><select id=epg_style name=epg_style
class=\"text ui-widget-content ui-corner-all\">
"
puts "<option value=standard"
if {$epg_style ne "grid"} { puts " selected" }
puts ">Standard\n"
puts "<option value=grid"
if {$epg_style eq "grid"} { puts " selected" }
puts ">Grid\n"
puts "
</select>
<small>
<input name=epg_style value=\"set\" type=submit>
</small>
<div id=epg_style_output></div>
</td>
</form>
</tr>
"
puts "
<tr>
<form class=auto id=channel_group method=get action=$env(REQUEST_URI)>
<th class=key>Channel Group for EPG</th>
<td><select id=channel_group name=channel_group
class=\"text ui-widget-content ui-corner-all\">
"
set i 0
puts "<option value=0>-- None --"
foreach grp [$settings channel_groups] {
incr i
puts -nonewline "<option value=$i"
if {$channel_group == $i} {
puts -nonewline " selected"
}
puts ">$grp"
}
puts "
</select>
<small>
<input name=channel_group value=\"set\" type=submit>
</small>
<div id=channel_group_output></div>
</td>
</form>
</tr>
"
puts "
</table>
</fieldset>
<br><br>
<fieldset style=\"display: inline\">
<legend> Email Settings </legend>
<table>
"
puts "
<tr>
<form class=auto id=smtp_server method=get action=$env(REQUEST_URI)>
<th class=key>SMTP Server for outbound email</th>
<td><input name=smtp_server value=\"$smtp_server\"
class=\"text ui-widget-content ui-corner-all\"
length=20 maxlength=50>
<small>
<input id=smtp_server_submit value=\"change\" type=submit>
</small>
<div id=smtp_server_output></div>
</td>
</form>
</tr>
"
puts "
</table>
</fieldset>
<br><br>
<fieldset style=\"display: inline\">
<legend> Advanced Settings </legend>
<table>
"
puts "
<tr>
<form class=auto id=pkgdev method=get action=$env(REQUEST_URI)>
<th class=key>Show development and advanced packages?</th>
<td><input name=pkgdevoff value=0 type=hidden>
<input name=pkgdev id=pkgdev value=1 type=checkbox
"
if {$pkgdev} { puts " checked" }
puts {
>
<small>
<input id=pkgdev_submit value="save" type=submit>
</small>
<div id=pkgdev_output></div>
</td>
</form>
</tr>
}
puts "
</table>
</fieldset>
"
eval_plugins settings
puts {
<br><br>
<fieldset style="display: inline">
<legend> Reset Custom Firmware </legend>
<button id=cfwreset>
Click to remove all packages and settings installed by the custom firmware.
</button>
</fieldset>
<script type=text/javascript>
$('#cfwreset').jConfirmAction({
yesAnswer: "Delete"
}, function(el) {
$('html').html('Restart the Humax using the remote control.');
$.get('/cgi-bin/cfwreset');
});
</script>
}
footer