assa
This commit is contained in:
@@ -12,14 +12,12 @@
|
|||||||
const passInput = form.querySelector('input[name="password"]');
|
const passInput = form.querySelector('input[name="password"]');
|
||||||
const imageInput = form.querySelector('input[name="image_url"]');
|
const imageInput = form.querySelector('input[name="image_url"]');
|
||||||
const submitBtn = form.querySelector('[data-host-submit]');
|
const submitBtn = form.querySelector('[data-host-submit]');
|
||||||
const cancelBtn = form.querySelector('[data-host-cancel]');
|
|
||||||
const modal = document.querySelector('[data-host-modal]');
|
const modal = document.querySelector('[data-host-modal]');
|
||||||
const modalTitle = document.querySelector('[data-host-modal-title]');
|
const modalTitle = document.querySelector('[data-host-modal-title]');
|
||||||
const closeBtn = document.querySelector('[data-host-close]');
|
const closeBtn = document.querySelector('[data-host-close]');
|
||||||
const newBtn = document.querySelector('[data-host-new]');
|
const newBtn = document.querySelector('[data-host-new]');
|
||||||
const checkAllBtn = document.querySelector('[data-host-check-all]');
|
const checkAllBtn = document.querySelector('[data-host-check-all]');
|
||||||
const unsavedBar = document.querySelector('[data-host-unsaved]');
|
const cancelBtn = form.querySelector('[data-host-cancel]');
|
||||||
const discardBtn = document.querySelector('[data-host-discard]');
|
|
||||||
|
|
||||||
let initialSnapshot = '';
|
let initialSnapshot = '';
|
||||||
|
|
||||||
@@ -34,7 +32,9 @@
|
|||||||
if (passInput) passInput.value = '';
|
if (passInput) passInput.value = '';
|
||||||
if (imageInput) imageInput.value = '';
|
if (imageInput) imageInput.value = '';
|
||||||
if (submitBtn) submitBtn.textContent = 'Speichern';
|
if (submitBtn) submitBtn.textContent = 'Speichern';
|
||||||
if (unsavedBar) unsavedBar.style.display = 'none';
|
if (modal && modal.classList.contains('is-open')) {
|
||||||
|
initialSnapshot = snapshot();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const snapshot = () => {
|
const snapshot = () => {
|
||||||
@@ -63,12 +63,11 @@
|
|||||||
const closeModal = (force = false) => {
|
const closeModal = (force = false) => {
|
||||||
if (!modal) return;
|
if (!modal) return;
|
||||||
if (!force && isDirty()) {
|
if (!force && isDirty()) {
|
||||||
if (unsavedBar) unsavedBar.style.display = 'flex';
|
const ok = window.confirm('Änderungen nicht gespeichert. Ohne Speichern schließen?');
|
||||||
return;
|
if (!ok) return;
|
||||||
}
|
}
|
||||||
modal.classList.remove('is-open');
|
modal.classList.remove('is-open');
|
||||||
modal.setAttribute('aria-hidden', 'true');
|
modal.setAttribute('aria-hidden', 'true');
|
||||||
if (unsavedBar) unsavedBar.style.display = 'none';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
document.querySelectorAll('[data-host-edit]').forEach((btn) => {
|
document.querySelectorAll('[data-host-edit]').forEach((btn) => {
|
||||||
@@ -92,13 +91,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (cancelBtn) {
|
|
||||||
cancelBtn.addEventListener('click', (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
resetForm();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newBtn) {
|
if (newBtn) {
|
||||||
newBtn.addEventListener('click', () => {
|
newBtn.addEventListener('click', () => {
|
||||||
resetForm();
|
resetForm();
|
||||||
@@ -111,19 +103,13 @@
|
|||||||
closeBtn.addEventListener('click', () => closeModal(false));
|
closeBtn.addEventListener('click', () => closeModal(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (discardBtn) {
|
if (cancelBtn) {
|
||||||
discardBtn.addEventListener('click', () => {
|
cancelBtn.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
resetForm();
|
resetForm();
|
||||||
closeModal(true);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
form.addEventListener('input', () => {
|
|
||||||
if (unsavedBar && isDirty()) {
|
|
||||||
unsavedBar.style.display = 'flex';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const updateStatus = (card, status) => {
|
const updateStatus = (card, status) => {
|
||||||
const dot = card.querySelector('[data-host-status]');
|
const dot = card.querySelector('[data-host-status]');
|
||||||
if (!dot) return;
|
if (!dot) return;
|
||||||
@@ -155,6 +141,7 @@
|
|||||||
const upg = card.querySelector('[data-upgrade-badge]');
|
const upg = card.querySelector('[data-upgrade-badge]');
|
||||||
const time = card.querySelector('[data-update-time]');
|
const time = card.querySelector('[data-update-time]');
|
||||||
if (upd) {
|
if (upd) {
|
||||||
|
upd.classList.remove('badge-warn', 'badge-ok', 'badge-error');
|
||||||
if (data.updates && typeof data.updates.count === 'number') {
|
if (data.updates && typeof data.updates.count === 'number') {
|
||||||
upd.textContent = `Updates: ${data.updates.count}`;
|
upd.textContent = `Updates: ${data.updates.count}`;
|
||||||
upd.classList.toggle('badge-warn', data.updates.count > 0);
|
upd.classList.toggle('badge-warn', data.updates.count > 0);
|
||||||
@@ -171,6 +158,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (upg) {
|
if (upg) {
|
||||||
|
upg.classList.remove('badge-warn', 'badge-ok', 'badge-error');
|
||||||
if (data.os && typeof data.os.available === 'boolean') {
|
if (data.os && typeof data.os.available === 'boolean') {
|
||||||
upg.textContent = data.os.available ? 'OS: Upgrade verfügbar' : 'OS: OK';
|
upg.textContent = data.os.available ? 'OS: Upgrade verfügbar' : 'OS: OK';
|
||||||
upg.classList.toggle('badge-warn', data.os.available);
|
upg.classList.toggle('badge-warn', data.os.available);
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
.form-card { padding: 14px; }
|
.form-card { padding: 14px; }
|
||||||
|
|
||||||
|
.notice-card {
|
||||||
|
padding: 12px 14px;
|
||||||
|
line-height: 1.45;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
.form-grid { display: grid; gap: 12px; }
|
.form-grid { display: grid; gap: 12px; }
|
||||||
.form-field { display: grid; gap: 6px; }
|
.form-field { display: grid; gap: 6px; }
|
||||||
.form-field input,
|
.form-field input,
|
||||||
@@ -82,7 +88,7 @@
|
|||||||
background: var(--panel);
|
background: var(--panel);
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
overflow: hidden;
|
overflow: visible;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-rows: 120px 1fr;
|
grid-template-rows: 120px 1fr;
|
||||||
box-shadow: var(--shadow);
|
box-shadow: var(--shadow);
|
||||||
@@ -94,6 +100,8 @@
|
|||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
border-top-left-radius: 16px;
|
||||||
|
border-top-right-radius: 16px;
|
||||||
}
|
}
|
||||||
.host-card-overlay {
|
.host-card-overlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -88,11 +88,11 @@ $commands = $pdo->query('SELECT * FROM ' . $table('commands') . ' ORDER BY COALE
|
|||||||
<p class="muted">Verwalte vordefinierte SSH-Befehle.</p>
|
<p class="muted">Verwalte vordefinierte SSH-Befehle.</p>
|
||||||
|
|
||||||
<?php if ($error): ?>
|
<?php if ($error): ?>
|
||||||
<div class="card" style="margin-top:1rem; border-color:#ffb4a8; background:#fff5f3; color:#7a2114;">
|
<div class="card notice-card" style="margin-top:1rem; border-color:#ffb4a8; background:#fff5f3; color:#7a2114;">
|
||||||
<?= e($error) ?>
|
<?= e($error) ?>
|
||||||
</div>
|
</div>
|
||||||
<?php elseif ($notice): ?>
|
<?php elseif ($notice): ?>
|
||||||
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
|
<div class="card notice-card" style="margin-top:1rem; border-color:var(--accent-2);">
|
||||||
<?= e($notice) ?>
|
<?= e($notice) ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -424,11 +424,11 @@ function sendToActiveConsole(array $host, string $command, bool $strictHostKey):
|
|||||||
<p class="muted">Wähle einen Host und führe einen Befehl aus.</p>
|
<p class="muted">Wähle einen Host und führe einen Befehl aus.</p>
|
||||||
|
|
||||||
<?php if ($error): ?>
|
<?php if ($error): ?>
|
||||||
<div class="card" style="margin-top:1rem; border-color:#ffb4a8; background:#fff5f3; color:#7a2114;">
|
<div class="card notice-card" style="margin-top:1rem; border-color:#ffb4a8; background:#fff5f3; color:#7a2114;">
|
||||||
<?= e($error) ?>
|
<?= e($error) ?>
|
||||||
</div>
|
</div>
|
||||||
<?php elseif ($notice): ?>
|
<?php elseif ($notice): ?>
|
||||||
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
|
<div class="card notice-card" style="margin-top:1rem; border-color:var(--accent-2);">
|
||||||
<?= e($notice) ?>
|
<?= e($notice) ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -46,26 +46,36 @@ if (isset($_GET['update_json'])) {
|
|||||||
$settings = modules()->settings('pi_control');
|
$settings = modules()->settings('pi_control');
|
||||||
$strictHostKey = !empty($settings['terminal_strict_hostkey']);
|
$strictHostKey = !empty($settings['terminal_strict_hostkey']);
|
||||||
|
|
||||||
$updateCmd = "apt-get -s upgrade | grep '^Inst'";
|
$updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; apt-get -s upgrade 2>/dev/null | grep \"^Inst \" || true'";
|
||||||
$upgradeCmd = 'current="$(. /etc/os-release && echo "$VERSION_CODENAME")"; latest="$(curl -fsSL https://deb.debian.org/debian/dists/stable/Release | awk -F\': \' \'/^Codename:/{print $2}\')"; echo "Installed: $current"; echo "Latest stable: $latest"; [ "$current" != "$latest" ] && echo "OS UPGRADE AVAILABLE" || echo "NO OS UPGRADE AVAILABLE"';
|
$upgradeCmd = "sh -lc 'current=\"$(. /etc/os-release 2>/dev/null && echo \"$VERSION_CODENAME\")\"; if [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2; exit}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; echo \"__CURRENT__=$current\"; echo \"__LATEST__=$latest\"; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'";
|
||||||
|
|
||||||
[$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20);
|
[$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20);
|
||||||
$lines = array_values(array_filter(preg_split('/\r?\n/', (string)$updOut)));
|
$updOutStr = (string)$updOut;
|
||||||
$updateCount = $updExit === 0 ? count($lines) : null;
|
$updErrStr = (string)$updErr;
|
||||||
|
$updateCount = null;
|
||||||
|
$updatePreview = '';
|
||||||
|
if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) {
|
||||||
|
$lines = array_values(array_filter(preg_split('/\r?\n/', $updOutStr)));
|
||||||
|
$updateCount = count($lines);
|
||||||
$updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : '';
|
$updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : '';
|
||||||
|
}
|
||||||
|
|
||||||
[$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25);
|
[$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25);
|
||||||
|
$upgOutStr = (string)$upgOut;
|
||||||
|
$upgErrStr = (string)$upgErr;
|
||||||
$upgradeAvailable = null;
|
$upgradeAvailable = null;
|
||||||
if ($upgExit === 0) {
|
if ($upgExit === 0 && !str_contains($upgOutStr, '__ERR__')) {
|
||||||
$upgradeAvailable = str_contains($upgOut, 'OS UPGRADE AVAILABLE');
|
if (preg_match('/^__UPGRADE__=(0|1)$/m', $upgOutStr, $m)) {
|
||||||
|
$upgradeAvailable = $m[1] === '1';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
|
$driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||||
$nowExpr = $driver === 'pgsql' ? 'NOW()' : "DATETIME('now')";
|
$nowExpr = $driver === 'pgsql' ? 'NOW()' : "DATETIME('now')";
|
||||||
$updCountVal = $updateCount;
|
$updCountVal = $updateCount;
|
||||||
$updErrVal = $updExit === 0 ? null : trim($updErr ?: $updOut);
|
$updErrVal = $updExit === 0 && !str_contains($updOutStr, '__ERR__') ? null : trim($updErrStr ?: $updOutStr);
|
||||||
$upgAvailVal = $upgradeAvailable;
|
$upgAvailVal = $upgradeAvailable;
|
||||||
$upgErrVal = $upgExit === 0 ? null : trim($upgErr ?: $upgOut);
|
$upgErrVal = $upgExit === 0 && !str_contains($upgOutStr, '__ERR__') ? null : trim($upgErrStr ?: $upgOutStr);
|
||||||
$stmt = $pdo->prepare(
|
$stmt = $pdo->prepare(
|
||||||
'UPDATE ' . $table('hosts') . ' SET update_checked_at = ' . $nowExpr . ',
|
'UPDATE ' . $table('hosts') . ' SET update_checked_at = ' . $nowExpr . ',
|
||||||
update_count = :update_count,
|
update_count = :update_count,
|
||||||
@@ -81,7 +91,7 @@ if (isset($_GET['update_json'])) {
|
|||||||
'update_preview' => $updatePreview !== '' ? $updatePreview : null,
|
'update_preview' => $updatePreview !== '' ? $updatePreview : null,
|
||||||
'update_error' => $updErrVal,
|
'update_error' => $updErrVal,
|
||||||
'upgrade_available' => $upgAvailVal === null ? null : ($upgAvailVal ? 1 : 0),
|
'upgrade_available' => $upgAvailVal === null ? null : ($upgAvailVal ? 1 : 0),
|
||||||
'upgrade_raw' => $upgExit === 0 ? trim($upgOut) : null,
|
'upgrade_raw' => $upgExit === 0 ? trim($upgOutStr) : null,
|
||||||
'upgrade_error' => $upgErrVal,
|
'upgrade_error' => $upgErrVal,
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
]);
|
]);
|
||||||
@@ -92,12 +102,12 @@ if (isset($_GET['update_json'])) {
|
|||||||
'updates' => [
|
'updates' => [
|
||||||
'count' => $updateCount,
|
'count' => $updateCount,
|
||||||
'preview' => $updatePreview,
|
'preview' => $updatePreview,
|
||||||
'error' => $updExit === 0 ? '' : trim($updErr ?: $updOut),
|
'error' => $updExit === 0 && !str_contains($updOutStr, '__ERR__') ? '' : trim($updErrStr ?: $updOutStr),
|
||||||
],
|
],
|
||||||
'os' => [
|
'os' => [
|
||||||
'available' => $upgradeAvailable,
|
'available' => $upgradeAvailable,
|
||||||
'raw' => $upgExit === 0 ? trim($upgOut) : '',
|
'raw' => $upgExit === 0 ? trim($upgOutStr) : '',
|
||||||
'error' => $upgExit === 0 ? '' : trim($upgErr ?: $upgOut),
|
'error' => $upgExit === 0 && !str_contains($upgOutStr, '__ERR__') ? '' : trim($upgErrStr ?: $upgOutStr),
|
||||||
],
|
],
|
||||||
'checked_at' => date('c'),
|
'checked_at' => date('c'),
|
||||||
]);
|
]);
|
||||||
@@ -317,11 +327,11 @@ function hostAuthOk(array $host, bool $strictHostKey): bool
|
|||||||
<p class="muted">Verwalte die Raspberry Pis, die du steuern möchtest.</p>
|
<p class="muted">Verwalte die Raspberry Pis, die du steuern möchtest.</p>
|
||||||
|
|
||||||
<?php if ($error): ?>
|
<?php if ($error): ?>
|
||||||
<div class="card" style="margin-top:1rem; border-color:#ffb4a8; background:#fff5f3; color:#7a2114;">
|
<div class="card notice-card" style="margin-top:1rem; border-color:#ffb4a8; background:#fff5f3; color:#7a2114;">
|
||||||
<?= e($error) ?>
|
<?= e($error) ?>
|
||||||
</div>
|
</div>
|
||||||
<?php elseif ($notice): ?>
|
<?php elseif ($notice): ?>
|
||||||
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
|
<div class="card notice-card" style="margin-top:1rem; border-color:var(--accent-2);">
|
||||||
<?= e($notice) ?>
|
<?= e($notice) ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
@@ -431,13 +441,6 @@ function hostAuthOk(array $host, bool $strictHostKey): bool
|
|||||||
<span class="muted">Bild-URL (optional)</span>
|
<span class="muted">Bild-URL (optional)</span>
|
||||||
<input type="text" name="image_url" placeholder="https://..." title="Optionales Bild für die Host-Karte.">
|
<input type="text" name="image_url" placeholder="https://..." title="Optionales Bild für die Host-Karte.">
|
||||||
</label>
|
</label>
|
||||||
<div class="host-unsaved" data-host-unsaved style="display:none;">
|
|
||||||
<span class="muted">Änderungen nicht gespeichert.</span>
|
|
||||||
<div style="display:flex; gap:10px; flex-wrap:wrap;">
|
|
||||||
<button class="cta-button" type="submit" data-host-submit>Speichern</button>
|
|
||||||
<button class="nav-link" type="button" data-host-discard>Änderungen verwerfen</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div style="display:flex; gap:10px; flex-wrap:wrap;">
|
<div style="display:flex; gap:10px; flex-wrap:wrap;">
|
||||||
<button class="cta-button" type="submit" data-host-submit>Speichern</button>
|
<button class="cta-button" type="submit" data-host-submit>Speichern</button>
|
||||||
<button class="nav-link" type="button" data-host-cancel>Zurücksetzen</button>
|
<button class="nav-link" type="button" data-host-cancel>Zurücksetzen</button>
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ $table = fn(string $name) => module_fn($module, 'table', $name);
|
|||||||
$settings = modules()->settings($module);
|
$settings = modules()->settings($module);
|
||||||
$strictHostKey = !empty($settings['terminal_strict_hostkey']);
|
$strictHostKey = !empty($settings['terminal_strict_hostkey']);
|
||||||
|
|
||||||
$updateCmd = "apt-get -s upgrade | grep '^Inst'";
|
$updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; apt-get -s upgrade 2>/dev/null | grep \"^Inst \" || true'";
|
||||||
$upgradeCmd = 'current="$(. /etc/os-release && echo "$VERSION_CODENAME")"; latest="$(curl -fsSL https://deb.debian.org/debian/dists/stable/Release | awk -F\': \' \'/^Codename:/{print $2}\')"; echo "Installed: $current"; echo "Latest stable: $latest"; [ "$current" != "$latest" ] && echo "OS UPGRADE AVAILABLE" || echo "NO OS UPGRADE AVAILABLE"';
|
$upgradeCmd = "sh -lc 'current=\"$(. /etc/os-release 2>/dev/null && echo \"$VERSION_CODENAME\")\"; if [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2; exit}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; echo \"__CURRENT__=$current\"; echo \"__LATEST__=$latest\"; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'";
|
||||||
|
|
||||||
$driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
|
$driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||||
$nowExpr = $driver === 'pgsql' ? 'NOW()' : "DATETIME('now')";
|
$nowExpr = $driver === 'pgsql' ? 'NOW()' : "DATETIME('now')";
|
||||||
@@ -26,18 +26,28 @@ foreach ($hosts as $host) {
|
|||||||
if ($id <= 0) continue;
|
if ($id <= 0) continue;
|
||||||
|
|
||||||
[$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20);
|
[$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20);
|
||||||
$lines = array_values(array_filter(preg_split('/\r?\n/', (string)$updOut)));
|
$updOutStr = (string)$updOut;
|
||||||
$updateCount = $updExit === 0 ? count($lines) : null;
|
$updErrStr = (string)$updErr;
|
||||||
|
$updateCount = null;
|
||||||
|
$updatePreview = '';
|
||||||
|
if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) {
|
||||||
|
$lines = array_values(array_filter(preg_split('/\r?\n/', $updOutStr)));
|
||||||
|
$updateCount = count($lines);
|
||||||
$updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : '';
|
$updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : '';
|
||||||
|
|
||||||
[$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25);
|
|
||||||
$upgradeAvailable = null;
|
|
||||||
if ($upgExit === 0) {
|
|
||||||
$upgradeAvailable = str_contains($upgOut, 'OS UPGRADE AVAILABLE');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$updErrVal = $updExit === 0 ? null : trim($updErr ?: $updOut);
|
[$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25);
|
||||||
$upgErrVal = $upgExit === 0 ? null : trim($upgErr ?: $upgOut);
|
$upgOutStr = (string)$upgOut;
|
||||||
|
$upgErrStr = (string)$upgErr;
|
||||||
|
$upgradeAvailable = null;
|
||||||
|
if ($upgExit === 0 && !str_contains($upgOutStr, '__ERR__')) {
|
||||||
|
if (preg_match('/^__UPGRADE__=(0|1)$/m', $upgOutStr, $m)) {
|
||||||
|
$upgradeAvailable = $m[1] === '1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$updErrVal = $updExit === 0 && !str_contains($updOutStr, '__ERR__') ? null : trim($updErrStr ?: $updOutStr);
|
||||||
|
$upgErrVal = $upgExit === 0 && !str_contains($upgOutStr, '__ERR__') ? null : trim($upgErrStr ?: $upgOutStr);
|
||||||
|
|
||||||
$stmt = $pdo->prepare(
|
$stmt = $pdo->prepare(
|
||||||
'UPDATE ' . $table('hosts') . ' SET update_checked_at = ' . $nowExpr . ',
|
'UPDATE ' . $table('hosts') . ' SET update_checked_at = ' . $nowExpr . ',
|
||||||
@@ -54,7 +64,7 @@ foreach ($hosts as $host) {
|
|||||||
'update_preview' => $updatePreview !== '' ? $updatePreview : null,
|
'update_preview' => $updatePreview !== '' ? $updatePreview : null,
|
||||||
'update_error' => $updErrVal,
|
'update_error' => $updErrVal,
|
||||||
'upgrade_available' => $upgradeAvailable === null ? null : ($upgradeAvailable ? 1 : 0),
|
'upgrade_available' => $upgradeAvailable === null ? null : ($upgradeAvailable ? 1 : 0),
|
||||||
'upgrade_raw' => $upgExit === 0 ? trim($upgOut) : null,
|
'upgrade_raw' => $upgExit === 0 ? trim($upgOutStr) : null,
|
||||||
'upgrade_error' => $upgErrVal,
|
'upgrade_error' => $upgErrVal,
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user