Files
ironic/tools/vnc-container/extension/Supermicro.js
Steve Baker e6e842b228 Replace Chrome/Selenium console with Firefox extension
The current containerised graphical console approach has a Selenium
script managing a Chrome browser session. This change replaces that with
firefox and a custom extension to perform the required actions to login
and load the BMC console. This supports the same vendors as the previous
approach (iDRAC, iLO, Supermicro).

This change is required by Red Hat as Chrome is not packaged in RHEL.
However switching to firefox has allowed a more robust and featureful
implementation so it is presented here on its own merits.

This is implemented with bash, calling out to dedicated python scripts
for these specific tasks:
- Detecting which vendor specific javascript to use for the
  redfish-graphical driver
- Building the required certificate fingerprint when app_info.verify_ca
  is false, which is written to the profile's cert_override.txt
- Building a custom policy.json which is specific to the BMC and vendor
  implementation.

Functional differences with the chrome/selenium version
- Firefox kiosk mode has a more locked-down environment, including
  disabling context menus. This means the brittle workaround to disable
  them is no longer required.
- Firefox global policy allows the environment to be locked down
  further, including limiting accessing to all URLs except the BMC.
- There is now a dedicated loading page which can show status updates
  until the first BMC page loads. This page shows error messages if any
  of the early redfish calls fail.
- VNC client sessions are now shared with multiple clients, and firefox
  will be started on the first connection, and stopped when the last
  connection ends.
- Starting Xvfb is now deferred until the first VNC client connection.
  This results in a never-connected container using 5MB vs 30MB
  once Xvfb is started. Starting Xvfb has ~1sec time penality on first
  connection.
- The browser now runs in a dedicated non-root user
- All redfish consoles now hide toolbar elements with a CSS overlay rather than
  simulating other methods such as clicking the "Full Screen" button.
- ilo6/ilo5 detection is now done by a redfish call and the ilo5 path
  has less moving parts.

Change-Id: Ib42704a016dc891833a0ddbeae8054cac2c57d4d
Signed-off-by: Steve Baker <sbaker@redhat.com>
Assisted-By: gemini
2025-11-05 11:07:07 +13:00

73 lines
2.8 KiB
JavaScript

window.addEventListener("load", function () {
if (window.location.protocol === "file:" && window.location.pathname.endsWith("/drivers/launch/index.html")) {
console.log("supermicro-graphical driver launch page loaded");
window.location.replace(bmc_url("/"));
}
else if (window.location.pathname.endsWith("/")) {
console.log("supermicro-graphical logging in");
login();
}
else if (window.location.search.includes("url_name=mainmenu")) {
console.log("supermicro-graphical waiting for console to be ready");
waitForConsoleSnapshot();
}
else if (window.location.search.includes("url_name=man_ikvm_html5_bootstrap")) {
console.log("supermicro-graphical console page loaded");
}
});
/**
* Fills in the username and password fields and clicks the login button.
*/
function login() {
const username_field = document.querySelector('input[name="name"]');
const password_field = document.getElementById('pwd');
const login_button = document.getElementById('login_word');
if (username_field && password_field && login_button) {
username_field.value = config.app_info.username;
password_field.value = config.app_info.password;
login_button.click();
} else {
console.error("Login elements not found.", username_field, password_field, login_button);
}
}
/**
* Waits for the console snapshot image to load and then clicks it to launch the HTML5 KVM console.
*/
function waitForConsoleSnapshot() {
const checkExist = setInterval(() => {
const topMenuFrame = document.getElementById("TOPMENU");
const topMenuDoc = topMenuFrame.contentDocument || topMenuFrame.contentWindow.document;
if (! topMenuDoc){
console.log('waiting for topMenuDoc...');
return;
}
const mainFrame = topMenuDoc.getElementById("frame_main");
const mainDoc = mainFrame.contentDocument || mainFrame.contentWindow.document;
if (! mainDoc){
console.log('waiting for mainDoc...');
return;
}
const img1 = mainDoc.getElementById("img1");
if (! img1){
console.log('waiting for img1');
return;
}
console.log('waiting for img1 to load')
if (img1 && img1.src.includes("Snapshot") && img1.complete) {
console.log("supermicro-graphical snapshot ready, clicking");
clearInterval(checkExist);
// override onclick to open as a tab instead of a popup
img1.onclick = () => {
window.open(bmc_url("/cgi/url_redirect.cgi?url_name=man_ikvm_html5_bootstrap"));
}
// open by clicking so that window.opener is set on the console page
img1.click();
}
}, 1000);
}