Files
webgui/plugins/dynamix/Syslinux.page
2018-05-05 14:45:45 +02:00

186 lines
7.3 KiB
Plaintext

Menu="Flash"
Title="Syslinux Configuration"
Tag="edit"
---
<?PHP
/* Copyright 2005-2018, Lime Technology
* Copyright 2012-2018, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
> Use this page to make changes to your `syslinux.cfg` file.
> You will need to reboot your server for these changes to take effect.
<?
function strip($area) {
return preg_replace(["/\r\n/","/\r/","/^ /","/\n /","/\n\n/","/\n$/"],["\n","\n","","\n","\n",""],$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.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.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.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) {
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.text2.disabled = true;
}
function setDefault(form) {
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);
var checked = start ? ' checked':'';
if (i) title += "<span style='float:right'><input type='checkbox' id='checkbox-"+i+"' title='Set default boot menu' onchange='changeMenu(this.form,this.id)'"+checked+"></span>";
$('#header-'+i).html(title).attr('class',start ? 'array':'system');
if (start) field.shift();
$(this).val(field.join('\n')).trigger('change');
} else {
$('#header-'+i).remove();
$(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(){
var i = $(this).prop('id');
var header = $('#'+i.replace('checkbox','header'));
if (i == id) {
header.attr('class','array');
$(this).prop('checked',true);
} else {
header.attr('class','system');
$(this).prop('checked',false);
}
});
}
$(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):
$field = explode("\n", $area);
$title = ($i) ? array_shift($field):$global;
$start = in_array($boot,$field);
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 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'?>
Permit UEFI boot mode <input type="checkbox" name="boot" <?=is_dir('/boot/EFI')?'checked':''?>>
: *Boot system in UEFI mode. Please check your system settings to support UEFI boot mode.*
<input type="button" value="Default" onclick="setDefault(this.form)">
: <input type="submit" value="Apply"><input type="button" value="Done" onclick="done()">
> Click the **Default** button to initialize the edit box with the
> factory-default contents. You still need to click **Apply** in order to
>commit the change.
>
> Click the **Apply** button to commit the current edits. Click **Reset** to
> undo any changes you make (before Saving). Click **Done** to exit this page.
</form>