Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions emhttp/plugins/dynamix/BootMode.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Menu="Flash:999"
Title="Boot Mode"
Tag="edit"
---
<?PHP
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, 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.
*/
?>

<script>
function prepareBootMode(form) {
form['#arg[1]'].value = form.boot.checked ? 1 : 0;
}
</script>
Comment on lines +18 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add defensive null checks in JavaScript function.

The function accesses form.boot and form['#arg[1]'] without verifying they exist, which could cause runtime errors if the form structure changes.

🔎 Proposed fix with defensive checks
 function prepareBootMode(form) {
+  if (!form.boot || !form['#arg[1]']) {
+    console.error('Required form elements not found');
+    return false;
+  }
   form['#arg[1]'].value = form.boot.checked ? 1 : 0;
+  return true;
 }

Also update the form's onsubmit to return the validation result:

-<form markdown="1" method="POST" action="/update.php" target="progressFrame" onsubmit="prepareBootMode(this)">
+<form markdown="1" method="POST" action="/update.php" target="progressFrame" onsubmit="return prepareBootMode(this)">

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In emhttp/plugins/dynamix/BootMode.page around lines 18 to 22, the
prepareBootMode(form) function assumes form.boot and form['#arg[1]'] exist which
can throw if the form structure changes; add defensive checks that verify both
elements exist (and are of expected types) before reading or setting values, and
ensure the function returns a boolean indicating success so the caller can
decide to submit; also update the form's onsubmit to return the result of
prepareBootMode(this) so submission is prevented when validation fails.

<form markdown="1" method="POST" action="/update.php" target="progressFrame" onsubmit="prepareBootMode(this)">
<input type="hidden" name="#include" value="/webGui/include/update.file.php">
<input type="hidden" name="#command" value="/webGui/scripts/bootmode">
<input type="hidden" name="#arg[1]" value="">

_(Server boot mode)_:
: <?=is_dir('/sys/firmware/efi') ? 'UEFI' : 'Legacy'?>

_(Boot system in UEFI mode)_:
: <label>
<input type="checkbox" name="boot" <?=is_dir('/boot/EFI')?'checked':''?>>
_(Permit UEFI boot mode)_
</label>
*_(Please check your system settings to support UEFI boot mode)_.*

&nbsp;
: <span class="inline-block">
<input type="submit" value="_(Apply)_">
<input type="button" value="_(Done)_" onclick="done()">
</span>

</form>

13 changes: 0 additions & 13 deletions emhttp/plugins/dynamix/Syslinux.page
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ 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('label[id^=label]').each(function(){
Expand Down Expand Up @@ -186,8 +185,6 @@ $(function(){
<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">
Expand Down Expand Up @@ -215,16 +212,6 @@ _(Syslinux configuration)_:
: <textarea class="raw config-raw" name="raw" spellcheck="false" cols="80" rows="<?=substr_count($current,"\n")+1?>" maxlength="2048"><?=htmlspecialchars($current)?></textarea>

</div>
_(Server boot mode)_:
: <?=is_dir('/sys/firmware/efi') ? 'UEFI' : 'Legacy'?>

_(Boot system in UEFI mode)_:
: <label>
<input type="checkbox" name="boot" <?=is_dir('/boot/EFI')?'checked':''?>>
_(Permit UEFI boot mode)_
</label>
*_(Please check your system settings to support UEFI boot mode)_.*

<input type="button" value="_(Default)_" onclick="setDefault(this.form)">
: <span class="inline-block">
<input type="submit" value="_(Apply)_">
Expand Down
Loading