
######################################################################
# Advanced Settings

puts -nonewline "
	<h4>Advanced Settings</h4>
	<div>
	<fieldset style=\"display: inline\">
	<legend> Advanced Settings </legend>
	<table>
"

setting_toggle "Show development and advanced packages?" "pkgdev" $pkgdev

if {[system nuggeted]} {
	setting_toggle "Real-time scheduling?" "rtschedule" $rtschedule
}

setting_toggle "Automatically remove unneeded dependent packages?" \
    "noautoremove" $(!$noautoremove) 1

puts -nonewline "
	<tr>
		<th class=key>Rotate logs when they exceed</th>
		<td>
		<form class=auto id=logsize method=get action=$env(SCRIPT_NAME)>
		<select name=logsize
		    class=\"text ui-widget-content ui-corner-all\">
"
set sizes { 102400 262144 524288 1048576 1572864 2097152 }
foreach size $sizes {
	puts -nonewline "<option value=$size"
	if {$logsize == $size} { puts -nonewline " selected" }
	puts ">[pretty_size $size]"
}
puts "
		</select>
		<small><input value=\"set\" type=submit></small>
		<div id=logsize_output></div>
		</form>
		</td>
	</tr>
"

setting_number logkeep "How many rotated logs to keep" $logkeep \
    1 100

setting_number logage "Delete old logs after X days" $logage \
    0 365

setting_number backupsage "Delete schedule backups after X days" \
    $backupsage 7 56

if {[system modversion 1] >= 214} {
	setting_toggle "Disable telnet menu?" "xtelnet" \
	    [file exists /mod/boot/xtelnet] 0 1
}

puts "
	</table>
	</fieldset>
	<fieldset style=\"display: inline\">
	<legend> Encryption Key </legend>
	<table>
	<tr><th class=key>
		Native encryption key
	</th><td><span id=nativekey>[system encryptionkey]</span></td></tr>
	<tr>
		<th class=key>Custom encryption key</th>
		<td>
		<form class=auto id=cryptokey method=post action=$env(SCRIPT_NAME)>
		<input type=hidden name=act value=cryptokey>
		<input name=cryptokey size=40 maxlength=32
		    class=\"text ui-widget-content ui-corner-all\"
		    value=\"$cryptokey\">
		<small><input value=\"set\" type=submit></small>
		<div id=cryptokey_output></div>
		</form>
		</td>"
# Script that clears the custom key input field when the native key 
# is restored by entering its full value (as shown in #nativekey).
# We rely on magical knowledge that the form holding this <input> is
# submitted with an Ajax call, and so we hook all successful Ajax calls,
# but filter by the text returned (init.hook) to avoid unnecessary updates. 
puts {
	<script>
	$(document).ajaxSuccess(
		function(ev, jqXHR) {
		        var ip;
		        if ((jqXHR.responseText.indexOf("ative ") >= 0) &&
			    ($("#nativekey").html() == (ip = $("input[name=cryptokey]")).prop("value"))) {
				 ip.prop("value", "");
			}
		}
	);
	</script>
}
puts "
	</tr><tr>
		<td></td>
		<td class=blood>
			NB: For fastest direct decryption, set the second half
			<br>
			of the key to the same as the first half.
		</td>
	</tr>
"

puts "
	</table>
	</fieldset>
	</div>
"

