diff options
author | Maxim Devaev <[email protected]> | 2022-05-24 15:07:31 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-05-24 15:07:31 +0300 |
commit | dab806eaecf2be1d4ba4efbfa161f8a02de73307 (patch) | |
tree | be4fad0765e94e0197641272993e2385acae3b05 | |
parent | 1c730a4dcfda4ebd8f2e56f7dbabd7e92c28ba72 (diff) |
pikvm/pikvm#725: sysrq confirmation
-rw-r--r-- | web/kvm/index.html | 32 | ||||
-rw-r--r-- | web/kvm/navbar-shortcuts.pug | 6 | ||||
-rw-r--r-- | web/share/js/kvm/hid.js | 21 |
3 files changed, 46 insertions, 13 deletions
diff --git a/web/kvm/index.html b/web/kvm/index.html index 579b0f94..596deec3 100644 --- a/web/kvm/index.html +++ b/web/kvm/index.html @@ -653,21 +653,33 @@ <hr> <div class="buttons"> <div class="buttons-row"> - <button class="row25" data-shortcut="AltLeft PrintScreen KeyF" title="Call the OOM killer to kill a memory hog process">F</button> - <button class="row25" data-shortcut="AltLeft PrintScreen KeyM" title="Dump current memory info to the console">M</button> - <button class="row25" data-shortcut="AltLeft PrintScreen KeyD" title="Show all locks that are held">D</button> - <button class="row25" data-shortcut="AltLeft PrintScreen KeyT" title="Dump a list of current tasks and their information to the console">T</button> + <button class="row25" data-shortcut="AltLeft PrintScreen KeyF" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Call the OOM killer to kill a memory hog process">F</button> + <button class="row25" data-shortcut="AltLeft PrintScreen KeyM" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Dump current memory info to the console">M</button> + <button class="row25" data-shortcut="AltLeft PrintScreen KeyD" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Show all locks that are held">D</button> + <button class="row25" data-shortcut="AltLeft PrintScreen KeyT" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Dump a list of current tasks and their information to the console">T</button> </div> <hr> <div class="buttons-row"> - <button class="row16" data-shortcut="AltLeft PrintScreen KeyR" title="Turn off keyboard raw mode, set it to XLATE">R</button> - <button class="row16" data-shortcut="AltLeft PrintScreen KeyE" title="Send a SIGTERM to all processes, except for init">E</button> - <button class="row16" data-shortcut="AltLeft PrintScreen KeyI" title="Send a SIGKILL to all processes, except for init">I</button> - <button class="row16" data-shortcut="AltLeft PrintScreen KeyS" title="Attempt to sync all mounted filesystems">S</button> - <button class="row16" data-shortcut="AltLeft PrintScreen KeyU" title="Attempt to remount all mounted filesystems read-only">U</button> - <button class="row16" data-shortcut="AltLeft PrintScreen KeyB" title="Immediately reboot the system without syncing or unmounting disks">B</button> + <button class="row16" data-shortcut="AltLeft PrintScreen KeyR" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Turn off keyboard raw mode, set it to XLATE">R</button> + <button class="row16" data-shortcut="AltLeft PrintScreen KeyE" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Send a SIGTERM to all processes, except for init">E</button> + <button class="row16" data-shortcut="AltLeft PrintScreen KeyI" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Send a SIGKILL to all processes, except for init">I</button> + <button class="row16" data-shortcut="AltLeft PrintScreen KeyS" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Attempt to sync all mounted filesystems">S</button> + <button class="row16" data-shortcut="AltLeft PrintScreen KeyU" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Attempt to remount all mounted filesystems read-only">U</button> + <button class="row16" data-shortcut="AltLeft PrintScreen KeyB" data-shortcut-confirm="hid-sysrq-ask-switch" style="text-align: center;" title="Immediately reboot the system without syncing or unmounting disks">B</button> </div> </div> + <hr> + <table class="kv"> + <tr> + <td>Ask the magic confirmation:</td> + <td align="right"> + <div class="switch-box"> + <input checked type="checkbox" id="hid-sysrq-ask-switch"> + <label for="hid-sysrq-ask-switch"><span class="switch-inner"></span><span class="switch"></span></label> + </div> + </td> + </tr> + </table> </div> </li> <li class="right feature-disabled" id="gpio-dropdown"><a class="menu-button" id="gpio-menu-button" href="#">GPIO</a> diff --git a/web/kvm/navbar-shortcuts.pug b/web/kvm/navbar-shortcuts.pug index 0b56d611..b3463d63 100644 --- a/web/kvm/navbar-shortcuts.pug +++ b/web/kvm/navbar-shortcuts.pug @@ -42,7 +42,7 @@ li(class="right") "T": "Dump a list of current tasks and their information to the console", } each title, key in sysrq - button(data-shortcut=`AltLeft PrintScreen Key${key}` class="row25" title=`${title}`) #{key} + button(data-shortcut=`AltLeft PrintScreen Key${key}` data-shortcut-confirm="hid-sysrq-ask-switch" class="row25" style="text-align: center;" title=`${title}`) #{key} hr div(class="buttons-row") - @@ -55,4 +55,6 @@ li(class="right") "B": "Immediately reboot the system without syncing or unmounting disks", } each title, key in sysrq - button(data-shortcut=`AltLeft PrintScreen Key${key}` class="row16" title=`${title}`) #{key} + button(data-shortcut=`AltLeft PrintScreen Key${key}` data-shortcut-confirm="hid-sysrq-ask-switch" class="row16" style="text-align: center;" title=`${title}`) #{key} + hr + +menu_switch("hid-sysrq-ask-switch", "Ask the magic confirmation", true, true) diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js index 1d7a4ff3..91300fd9 100644 --- a/web/share/js/kvm/hid.js +++ b/web/share/js/kvm/hid.js @@ -90,8 +90,27 @@ export function Hid(__getGeometry, __recorder) { tools.el.setOnClick($("hid-reset-button"), __clickResetButton); for (let el_shortcut of $$$("[data-shortcut]")) { - tools.el.setOnClick(el_shortcut, () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" "))); + tools.el.setOnClick(el_shortcut, function() { + let ask = false; + let confirm_id = el_shortcut.getAttribute("data-shortcut-confirm"); + if (confirm_id) { + ask = $(confirm_id).checked; + } + let codes = el_shortcut.getAttribute("data-shortcut").split(" "); + if (ask) { + let confirm_msg = `Do you want to press <b>${codes.join(" + ")}</b>?`; + wm.confirm(confirm_msg).then(function(ok) { + if (ok) { + __emitShortcut(codes); + } + }); + } else { + __emitShortcut(codes); + } + }); } + + tools.storage.bindSimpleSwitch($("hid-sysrq-ask-switch"), "hid.sysrq.ask", true); }; /************************************************************************/ |