Read the partner's identity out of master.conf instead of asking for it again
This commit is contained in:
@@ -38,6 +38,38 @@
|
|||||||
// master.conf pull (for partner servers) lives in the checklist, not here.
|
// master.conf pull (for partner servers) lives in the checklist, not here.
|
||||||
|
|
||||||
$detectedHostname = vv_get_hostname();
|
$detectedHostname = vv_get_hostname();
|
||||||
|
|
||||||
|
// ── Identity already on disk? ────────────────────────────────────────────────────────────────
|
||||||
|
// A partner that has been sent the owner's master.conf already knows everything this step asks
|
||||||
|
// for: the conf names the primary, and it names this machine in one of the HOSTn slots. Asking
|
||||||
|
// for it again invites a typo in the one field the form itself warns is case-sensitive, and the
|
||||||
|
// answer is sitting in a file two lines away.
|
||||||
|
//
|
||||||
|
// Only a *populated* conf counts. The installer seeds master.conf from the template, where every
|
||||||
|
// HOSTn is empty — that is a fresh node with no identity, not a detected one.
|
||||||
|
//
|
||||||
|
// Matching is exact and case-insensitive, never a prefix: two hosts called Tower and Tower2 must
|
||||||
|
// not resolve to each other, and there is no ambiguity to tolerate when the value was written by
|
||||||
|
// the very host it names.
|
||||||
|
$vvDetected = ['slot' => '', 'primary' => '', 'role' => ''];
|
||||||
|
$vvMasterRaw = vv_read_conf_raw('master.conf');
|
||||||
|
if ($vvMasterRaw !== '' && $detectedHostname !== '') {
|
||||||
|
preg_match_all('/^\s*(HOST\d+)\s*=\s*"([^"]*)"/m', $vvMasterRaw, $vvHm, PREG_SET_ORDER);
|
||||||
|
$vvSlots = [];
|
||||||
|
foreach ($vvHm as $m) {
|
||||||
|
$val = trim($m[2]);
|
||||||
|
if ($val !== '') $vvSlots[strtolower($m[1])] = $val;
|
||||||
|
}
|
||||||
|
foreach ($vvSlots as $slot => $name) {
|
||||||
|
if (strcasecmp($name, $detectedHostname) === 0) {
|
||||||
|
$vvDetected['slot'] = $slot;
|
||||||
|
$vvDetected['role'] = ($slot === 'host1') ? 'primary' : 'partner';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The primary is whatever HOST1 says, and it is only useful to a host that is not HOST1.
|
||||||
|
if ($vvDetected['role'] === 'partner') $vvDetected['primary'] = $vvSlots['host1'] ?? '';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<link rel="stylesheet" href="/plugins/varaverk/css/varaverk.css">
|
<link rel="stylesheet" href="/plugins/varaverk/css/varaverk.css">
|
||||||
<style>
|
<style>
|
||||||
@@ -251,8 +283,14 @@ function vvSetStorage(mode) {
|
|||||||
vvSetStorage(d.mode);
|
vvSetStorage(d.mode);
|
||||||
const hf = document.getElementById('vv-hostname');
|
const hf = document.getElementById('vv-hostname');
|
||||||
if (hf && !hf.value.trim()) hf.value = d.hostname;
|
if (hf && !hf.value.trim()) hf.value = d.hostname;
|
||||||
|
// After the banner is rebuilt, never before — this appends to it, and the line above
|
||||||
|
// replaces its innerHTML wholesale.
|
||||||
|
vvApplyDetectedIdentity();
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
document.getElementById('vv-detect-banner').innerHTML = '<span style="color:#444">Detection unavailable</span>';
|
document.getElementById('vv-detect-banner').innerHTML = '<span style="color:#444">Detection unavailable</span>';
|
||||||
|
// Identity comes off the local conf, not from the probe, so it still applies when the
|
||||||
|
// environment probe is the thing that failed.
|
||||||
|
vvApplyDetectedIdentity();
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -266,6 +304,38 @@ function vvSetRole(role) {
|
|||||||
document.getElementById('vv-cond-partner')?.classList.toggle('show', role === 'partner');
|
document.getElementById('vv-cond-partner')?.classList.toggle('show', role === 'partner');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Identity detected from master.conf ────────────────────────────────────────
|
||||||
|
// Applied, not enforced. Every field stays editable: the conf is evidence of what the owner
|
||||||
|
// intended, and if it is wrong the person standing at the machine is the one who can say so.
|
||||||
|
// What this removes is the need to retype three values that are already known — including the
|
||||||
|
// hostname field whose own hint warns it is case-sensitive.
|
||||||
|
const vvDetectedIdentity = <?= json_encode($vvDetected) ?>;
|
||||||
|
|
||||||
|
function vvApplyDetectedIdentity() {
|
||||||
|
const d = vvDetectedIdentity;
|
||||||
|
if (!d || !d.slot) return;
|
||||||
|
|
||||||
|
vvSetRole(d.role);
|
||||||
|
if (d.role === 'partner') {
|
||||||
|
const pn = document.getElementById('vv-primary-hostname');
|
||||||
|
if (pn && d.primary) pn.value = d.primary;
|
||||||
|
const sel = document.getElementById('vv-partner-slot');
|
||||||
|
if (sel && [...sel.options].some(o => o.value === d.slot)) sel.value = d.slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
const banner = document.getElementById('vv-detect-banner');
|
||||||
|
if (banner) {
|
||||||
|
const note = document.createElement('div');
|
||||||
|
note.style.cssText = 'margin-top:8px;padding:7px 10px;border-radius:3px;background:#0d1f0d;'
|
||||||
|
+ 'border:1px solid #1a3a1a;color:#4caf50;font-size:11px;line-height:1.5;';
|
||||||
|
note.textContent = d.role === 'partner'
|
||||||
|
? `Identity read from master.conf — this server is ${d.slot.toUpperCase()}, joining `
|
||||||
|
+ `${d.primary}. Change anything below if that is wrong.`
|
||||||
|
: 'Identity read from master.conf — this server is HOST1, the primary.';
|
||||||
|
banner.appendChild(note);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||||
function vvSetStatus(msg, cls) {
|
function vvSetStatus(msg, cls) {
|
||||||
const s = document.getElementById('vv-status');
|
const s = document.getElementById('vv-status');
|
||||||
|
|||||||
Reference in New Issue
Block a user