pikvm/pikvm#725: sysrq confirmation

This commit is contained in:
Maxim Devaev 2022-05-24 15:07:31 +03:00
parent 1c730a4dcf
commit dab806eaec
3 changed files with 46 additions and 13 deletions

View File

@ -653,21 +653,33 @@
<hr> <hr>
<div class="buttons"> <div class="buttons">
<div class="buttons-row"> <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 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" title="Dump current memory info to the console">M</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" title="Show all locks that are held">D</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" title="Dump a list of current tasks and their information to the console">T</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> </div>
<hr> <hr>
<div class="buttons-row"> <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 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" title="Send a SIGTERM to all processes, except for init">E</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" title="Send a SIGKILL to all processes, except for init">I</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" title="Attempt to sync all mounted filesystems">S</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" title="Attempt to remount all mounted filesystems read-only">U</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" title="Immediately reboot the system without syncing or unmounting disks">B</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>
</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> </div>
</li> </li>
<li class="right feature-disabled" id="gpio-dropdown"><a class="menu-button" id="gpio-menu-button" href="#">GPIO</a> <li class="right feature-disabled" id="gpio-dropdown"><a class="menu-button" id="gpio-menu-button" href="#">GPIO</a>

View File

@ -42,7 +42,7 @@ li(class="right")
"T": "Dump a list of current tasks and their information to the console", "T": "Dump a list of current tasks and their information to the console",
} }
each title, key in sysrq 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 hr
div(class="buttons-row") div(class="buttons-row")
- -
@ -55,4 +55,6 @@ li(class="right")
"B": "Immediately reboot the system without syncing or unmounting disks", "B": "Immediately reboot the system without syncing or unmounting disks",
} }
each title, key in sysrq 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)

View File

@ -90,8 +90,27 @@ export function Hid(__getGeometry, __recorder) {
tools.el.setOnClick($("hid-reset-button"), __clickResetButton); tools.el.setOnClick($("hid-reset-button"), __clickResetButton);
for (let el_shortcut of $$$("[data-shortcut]")) { 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);
}; };
/************************************************************************/ /************************************************************************/