mirror of
https://github.com/unraid/webgui.git
synced 2026-01-13 21:20:01 -06:00
Syslinux config: basic and advanced mode
This commit is contained in:
@@ -24,61 +24,71 @@ function strip($area) {
|
||||
$file = '/boot/syslinux/syslinux.cfg';
|
||||
$menu = file_get_contents($file);
|
||||
$default = @file_get_contents("$file-") ?: $menu;
|
||||
$text = preg_replace(["/\r\n/","/\r/"],"\n",$menu);
|
||||
$text2 = preg_replace(["/\r\n/","/\r/"],"\n",$default);
|
||||
$menu = array_map('strip',explode('label ',$menu));
|
||||
$default = array_map('strip',explode('label ',$default));
|
||||
|
||||
$global = 'Global Configuration';
|
||||
$boot = 'menu default';
|
||||
?>
|
||||
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.switchbutton.css">
|
||||
<style>
|
||||
.basic{display:block}
|
||||
.advanced{display:none;white-space:nowrap}
|
||||
<?
|
||||
switch ($display['theme']) {
|
||||
case 'gray':
|
||||
case 'azure':
|
||||
echo "span.array,span.system{margin-left:33.33%;width:65.5%;padding:2px 10px;font-weight:bold;border:solid 1px #606E7F;border-bottom:none}\n";
|
||||
echo "textarea{margin-left:33.33%;width:65.5%;margin-bottom:12px;font-family:bitstream;resize:none;border-top:none}\n";
|
||||
echo "textarea.menu{margin-left:33.33%;width:65.5%;margin-bottom:12px;font-family:bitstream;resize:none;border-top:none}\n";
|
||||
break;
|
||||
case 'white':
|
||||
echo "span.array,span.system{margin-left:33.33%;width:65.66%;padding:1px 8px;font-weight:bold;border:solid 1px #E0E0E0;border-bottom:none}\n";
|
||||
echo "textarea{margin-left:33.33%;width:65.66%;margin-bottom:12px;font-family:bitstream;resize:none;border-top:none;border-radius:0}\n";
|
||||
echo "textarea.menu{margin-left:33.33%;width:65.66%;margin-bottom:12px;font-family:bitstream;resize:none;border-top:none;border-radius:0}\n";
|
||||
break;
|
||||
case 'black':
|
||||
echo "span.array,span.system{margin-left:33.33%;width:65.66%;padding:1px 8px;font-weight:bold;border:solid 1px #404040;border-bottom:none}\n";
|
||||
echo "textarea{margin-left:33.33%;width:65.66%;margin-bottom:12px;font-family:bitstream;resize:none;border-top:none;border-radius:0}\n";
|
||||
echo "textarea.menu{margin-left:33.33%;width:65.66%;margin-bottom:12px;font-family:bitstream;resize:none;border-top:none;border-radius:0}\n";
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</style>
|
||||
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
|
||||
<script>
|
||||
const boot = '<?=$boot?>';
|
||||
const global = '<?=$global?>';
|
||||
|
||||
function prepareMenu(form) {
|
||||
$('input[name="#arg[1]"]').val(form.boot.checked?1:0);
|
||||
var header = [], area = [];
|
||||
$(form).find('span[id^=header]').each(function(){
|
||||
header.push($(this).text());
|
||||
});
|
||||
$(form).find('textarea').each(function(i){
|
||||
var start = $('#checkbox-'+i).prop('checked') ? boot+'\n' : '';
|
||||
area.push(start+$(this).val());
|
||||
});
|
||||
var menu = '';
|
||||
for (var i=0; i < header.length; i++) {
|
||||
if (i==0) {
|
||||
menu += area[i]+'\n';
|
||||
} else {
|
||||
menu += 'label '+header[i]+'\n';
|
||||
menu += area[i].replace(/^/,' ').replace(/\n/g,'\n ')+'\n';
|
||||
if ($.cookie('syslinux_view_mode')!='advanced') {
|
||||
form.text.value = form.text2.value;
|
||||
} else {
|
||||
$('input[name="#arg[1]"]').val(form.boot.checked?1:0);
|
||||
var header = [], area = [];
|
||||
$(form).find('span[id^=header]').each(function(){
|
||||
header.push($(this).text());
|
||||
});
|
||||
$(form).find('textarea.menu').each(function(i){
|
||||
var start = $('#checkbox-'+i).prop('checked') ? boot+'\n' : '';
|
||||
area.push(start+$(this).val());
|
||||
});
|
||||
var menu = '';
|
||||
for (var i=0; i < header.length; i++) {
|
||||
if (i==0) {
|
||||
menu += area[i]+'\n';
|
||||
} else {
|
||||
menu += 'label '+header[i]+'\n';
|
||||
menu += area[i].replace(/^/,' ').replace(/\n/g,'\n ')+'\n';
|
||||
}
|
||||
}
|
||||
form.text.value = menu;
|
||||
}
|
||||
form.text.value = menu;
|
||||
form.text2.disabled = true;
|
||||
}
|
||||
function setDefault(form) {
|
||||
var menu = [<?foreach ($default as $field) echo '"'.str_replace("\n",'|',$field).'",'?>];
|
||||
var max = menu.length;
|
||||
$(form).find('textarea').each(function(i){
|
||||
if (i < max) {
|
||||
var menu = [<?foreach ($default as $area) echo '"'.str_replace("\n",'|',$area).'",'?>];
|
||||
$(form).find('textarea.menu').each(function(i){
|
||||
if (i < menu.length) {
|
||||
var field = menu[i].split('|');
|
||||
var title = (i) ? field.shift():global;
|
||||
var start = (field[0]==boot);
|
||||
@@ -92,6 +102,8 @@ function setDefault(form) {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
form.text2.value = <?=json_encode($text2)?>;
|
||||
$(form).find('textarea.text').trigger('change');
|
||||
}
|
||||
function changeMenu(form,id) {
|
||||
$(form).find('input[type=checkbox]').each(function(){
|
||||
@@ -110,14 +122,37 @@ $(function(){
|
||||
$('form').find('textarea').each(function(){$(this).on('input change',function(){
|
||||
$(this).attr('rows',($(this).val().match(/\n/g)||[]).length+1);
|
||||
});});
|
||||
if ($.cookie('syslinux_view_mode')=='advanced') {
|
||||
$('.advanced').show();
|
||||
$('.basic').hide();
|
||||
}
|
||||
$('.advancedview').switchButton({
|
||||
labels_placement: 'left',
|
||||
on_label: 'Advanced View',
|
||||
off_label: 'Basic View',
|
||||
checked: $.cookie('syslinux_view_mode')=='advanced'
|
||||
});
|
||||
$('.advancedview').change(function() {
|
||||
$('.advanced').toggle('slow');
|
||||
$('.basic').toggle('slow');
|
||||
$.cookie('syslinux_view_mode', $('.advancedview').is(':checked') ? 'advanced':'basic', {expires:3650});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<span class="status" style="margin-top:-44px"><input type="checkbox" class="advancedview"></span>
|
||||
|
||||
<form markdown="1" method="POST" action="/update.php" target="progressFrame" onsubmit="prepareMenu(this)">
|
||||
<input type="hidden" name="#include" value="/webGui/include/update.file.php">
|
||||
<input type="hidden" name="#file" value="<?=$file;?>">
|
||||
<input type="hidden" name="#command" value="/webGui/scripts/bootmode">
|
||||
<input type="hidden" name="#arg[1]" value="">
|
||||
<input type="hidden" name="text" value="">
|
||||
<div markdown="1" class="basic">
|
||||
Syslinux configuration:
|
||||
: <textarea class="text" name="text2" spellcheck="false" cols="80" rows="<?=substr_count($text,"\n")+1?>" maxlength="2048" style="resize:none;font-family:bitstream;width:65.5%"><?=$text?></textarea>
|
||||
|
||||
</div>
|
||||
<div markdown="1" class="advanced" style="display:none">
|
||||
Syslinux configuration:
|
||||
: <?$i=0;
|
||||
foreach ($menu as $area):
|
||||
@@ -127,9 +162,10 @@ Syslinux configuration:
|
||||
if ($start) unset($field[array_search($boot,$field)]);
|
||||
?><span id="header-<?=$i?>" class="<?=$start?'array':'system'?>"><?=$title?>
|
||||
<?if ($i):?><span style="float:right"><input type="checkbox" id="checkbox-<?=$i?>" <?=$start?'checked':''?> title="Set default boot menu" onchange="changeMenu(this.form,this.id)"></span><?endif;?></span>
|
||||
<textarea spellcheck="false" cols="80" rows="<?=count($field)?>" maxlength="2048"><?=implode("\n",$field)?></textarea><?$i++?>
|
||||
<textarea class="menu" spellcheck="false" cols="80" rows="<?=count($field)?>" maxlength="2048"><?=implode("\n",$field)?></textarea><?$i++?>
|
||||
<?endforeach;?>
|
||||
|
||||
</div>
|
||||
Server boot mode:
|
||||
: <?=is_dir('/sys/firmware/efi') ? 'UEFI' : 'Legacy'?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user