forked from unraid/webgui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyslinux.page
More file actions
245 lines (234 loc) · 9.49 KB
/
Syslinux.page
File metadata and controls
245 lines (234 loc) · 9.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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.
*/
?>
<?
$top = $themes1 ? -58 : -44;
function strip($area) {
return preg_replace(["/^|(\n) /","/\n$/"],["$1",""],$area);
}
$file = '/boot/syslinux/syslinux.cfg';
$current = file_get_contents($file);
$default = @file_get_contents("$file-") ?: $current;
$current = preg_replace(["/\r\n/","/\r/","/\n$/"],["\n","\n",""],$current);
$default = preg_replace(["/\r\n/","/\r/","/\n$/"],["\n","\n",""],$default);
$title = 'Global Configuration';
$menu = 'menu default';
$mark = 'label ';
?>
<link type="text/css" rel="stylesheet" href="<?autov('/webGui/styles/jquery.switchbutton.css')?>">
<style>
div.basic{display:block}
div.advanced{display:none}
textarea.raw{resize:none;font-family:bitstream;width:65.5%}
<?
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;padding:4px 10px;font-family:bitstream;border-top:none}\n";
break;
case 'white':
echo "span.array,span.system{margin-left:33.33%;width:65.5%;padding:2px 10px;font-weight:bold;border:solid 1px #1c1c1c;border-bottom:none}\n";
echo "textarea.menu{margin-left:33.33%;width:65.5%;margin-bottom:12px;padding:4px 10px;font-family:bitstream;border:1px solid #1c1b1b;border-top:none}\n";
break;
case 'black':
echo "span.array,span.system{margin-left:33.33%;width:65.5%;padding:2px 10px;font-weight:bold;border:solid 1px #f2f2f2;border-bottom:none}\n";
echo "textarea.menu{margin-left:33.33%;width:65.5%;margin-bottom:12px;padding:4px 10px;font-family:bitstream;border:1px solid #f2f2f2;border-top:none}\n";
break;
}
?>
</style>
<script src="<?autov('/webGui/javascript/jquery.switchbutton.js')?>"></script>
<script>
const menu = '<?=$menu?>';
const title = '<?=$title?>';
const mark = '<?=$mark?>';
Array.prototype.indent = function(o) {
if (o) for (var i=0; i < this.length; i++) this[i] = ' '+this[i];
return this;
};
Array.prototype.spliceArray = function(i,n,a) {
return Array.prototype.splice.apply(this,[i,n].concat(a));
};
function prepareMenu(form) {
$('input[name="#arg[1]"]').val(form.boot.checked?1:0);
if ($('div.basic').is(':visible')) {
var label = [], area = [];
$(form).find('span[id^=label]').each(function(){
label.push($(this).text());
});
$(form).find('textarea.menu').each(function(i){
var start = $('#input-'+i).prop('checked') ? menu+'\n' : '';
area.push(start+$(this).val());
});
var text = [];
for (var i=0; i < label.length; i++) {
if (i==0) {
text.push(area[i]);
} else {
text.push(mark+label[i]);
text.push(area[i].replace(/^|(\n)/g,'$1 '));
}
}
// menu view
form.text.value = text.join('\n')+'\n';
} else {
// raw view
form.text.value = form.raw.value+'\n';
}
form.raw.disabled = true;
}
function setDefault(form) {
var text = <?=json_encode(array_map('strip',explode($mark,$default)))?>;
$(form).find('textarea.menu').each(function(i){
if (i < text.length) {
var area = text[i].split('\n');
var label = (i) ? area.shift():title;
var start = (area[0]==menu);
var checked = start ? ' checked':'';
if (i) label += "<span style='float:right'><input type='radio' id='input-"+i+"' title='Set default boot menu' onchange='changeMenu(this.form,this.id,true)'"+checked+"></span>";
$('#label-'+i).html(label).prop('class',start ? 'array':'system');
if (start) area.shift();
$(this).val(area.join('\n')).prop('rows',area.length).trigger('change');
} else {
$('#label-'+i).remove();
$(this).remove();
}
});
$(form).find('textarea.raw').val(<?=json_encode($default)?>).prop('rows',$(this).val().match(/\n/g).length+1).trigger('change');
}
function changeMenu(form,id,update) {
$(form).find('input.menu').each(function(){
// highlight default boot menu
var i = $(this).prop('id');
var label = $('#'+i.replace('input','label'));
if (i == id) {
label.prop('class','array');
$(this).prop('checked',true);
} else {
label.prop('class','system');
$(this).prop('checked',false);
}
});
if (update) {
// menu view -> update raw view
var n = 0, o = null;
var x = id.split('-')[1];
var text = form.raw.value.split('\n');
for (var i=0; i < text.length; i++) {
if (text[i].indexOf(mark) >= 0) if (++n == x) o = i + 1;
if (text[i].indexOf(menu) >= 0) text.splice(i,1);
}
if (o) text.splice(o,0,' '+menu);
$(form).find('textarea.raw').val(text.join('\n')).prop('rows',text.length);
}
}
$(function(){
$('form').find('textarea').each(function(){$(this).on('input change',function(event){
$(this).prop('rows',($(this).val().match(/\n/g)||[]).length+1);
if (event.type == 'input') return;
// propogate changes to 'other' view mode
var form = $(this).closest('form');
if ($(this).prop('class')=='menu') {
// menu view -> update raw view
var n = 0, o = 0, x = null;
var id = $(this).prop('id').split('-')[1];
var area = $(this).val().split('\n');
var raw = form.find('textarea.raw');
var text = raw.val().split('\n');
for (var i=0; i < text.length; i++) {
if (text[i].indexOf(mark) >= 0) {
if (n++ == id) x = i; else o = i + 1;
}
if (text[i].indexOf(menu) >= 0) o++;
if (x) break;
}
text.spliceArray(o,(x||text.length)-o,area.indent(o));
raw.val(text.join('\n')).prop('rows',text.length);
} else {
// raw view -> update menu view
var n = 0, id = null, area = [];
var text = $(this).val().split('\n');
for (var i=0; i < text.length; i++) {
if (text[i].indexOf(mark) >= 0) {
$('#menu-'+(n++)).val(area.join('\n')).prop('rows',area.length);
var label = $('#label-'+n);
label.html(label.html().replace(/^.*(<span.*)/,text[i].replace(mark,'')+'$1'));
area = [];
} else {
if (text[i].indexOf(menu) >= 0) id = 'input-'+n; else if (text[i].length) area.push(text[i].replace(/^ /,''));
}
}
$('#menu-'+n).val(area.join('\n')).prop('rows',area.length);
if (id) changeMenu(form,id,false);
}
});});
if ($.cookie('syslinux_viewmode')=='advanced') {
$('.advanced').show();
$('.basic').hide();
}
$('.advancedview').switchButton({
labels_placement: 'left',
off_label: 'Menu View',
on_label: 'Raw View',
checked: $.cookie('syslinux_viewmode')=='advanced'
});
$('.advancedview').change(function() {
$('.advanced').toggle('slow');
$('.basic').toggle('slow');
$.cookie('syslinux_viewmode', $('.advancedview').is(':checked') ? 'advanced':'basic', {expires:3650});
});
});
</script>
<span class="status" style="margin-top:<?=$top?>px"><input type="checkbox" class="advancedview"></span>
> Use this page to make changes to your `syslinux.cfg` file.
> You will need to reboot your server for these changes to take effect.
<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:
: <?$i=0;
foreach (array_map('strip',explode($mark,$current)) as $area):
$area = explode("\n", $area);
$label = ($i) ? array_shift($area):$title;
$start = in_array($menu,$area);
if ($start) unset($area[array_search($menu,$area)]);
?><span id="label-<?=$i?>" class="<?=$start?'array':'system'?>"><?=$label?>
<?if ($i):?><span style="float:right"><input type="radio" id="input-<?=$i?>" class="menu" <?=$start?'checked':''?> title="Set default boot menu" onchange="changeMenu(this.form,this.id,true)"></span><?endif;?></span>
<textarea class="menu" id="menu-<?=$i++?>" spellcheck="false" cols="80" rows="<?=count($area)?>" maxlength="2048"><?=implode("\n",$area)?></textarea>
<?endforeach;?>
</div>
<div markdown="1" class="advanced">
Syslinux configuration:
: <textarea class="raw" name="raw" spellcheck="false" cols="80" rows="<?=substr_count($current,"\n")+1?>" maxlength="2048"><?=$current?></textarea>
</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>