| 1 |
/* |
| 2 |
* Copyright (C) 2017 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
import '../lib/patternfly/patternfly-6-cockpit.scss'; |
| 6 |
import 'polyfills'; // once per application |
| 7 |
import 'cockpit-dark-theme'; // once per page |
| 8 |
|
| 9 |
import cockpit from "cockpit"; |
| 10 |
import React from "react"; |
| 11 |
import { createRoot } from 'react-dom/client'; |
| 12 |
|
| 13 |
import { Badge } from "@patternfly/react-core/dist/esm/components/Badge/index.js"; |
| 14 |
import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js"; |
| 15 |
import { CodeBlock, CodeBlockCode } from "@patternfly/react-core/dist/esm/components/CodeBlock/index.js"; |
| 16 |
import { Gallery } from "@patternfly/react-core/dist/esm/layouts/Gallery/index.js"; |
| 17 |
import { Popover } from "@patternfly/react-core/dist/esm/components/Popover/index.js"; |
| 18 |
import { Tooltip } from "@patternfly/react-core/dist/esm/components/Tooltip/index.js"; |
| 19 |
import { Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core/dist/esm/components/Card/index.js'; |
| 20 |
import { DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; |
| 21 |
import { ExpandableSection } from "@patternfly/react-core/dist/esm/components/ExpandableSection/index.js"; |
| 22 |
import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js"; |
| 23 |
import { Grid, GridItem } from "@patternfly/react-core/dist/esm/layouts/Grid/index.js"; |
| 24 |
import { LabelGroup } from "@patternfly/react-core/dist/esm/components/Label/index.js"; |
| 25 |
import { Page, PageSection, } from "@patternfly/react-core/dist/esm/components/Page/index.js"; |
| 26 |
import { Progress, ProgressSize } from "@patternfly/react-core/dist/esm/components/Progress/index.js"; |
| 27 |
import { Spinner } from "@patternfly/react-core/dist/esm/components/Spinner/index.js"; |
| 28 |
import { Stack, StackItem } from "@patternfly/react-core/dist/esm/layouts/Stack/index.js"; |
| 29 |
import { Switch } from "@patternfly/react-core/dist/esm/components/Switch/index.js"; |
| 30 |
import { Content, ContentVariants } from "@patternfly/react-core/dist/esm/components/Content/index.js"; |
| 31 |
|
| 32 |
import { |
| 33 |
BugIcon, |
| 34 |
CheckIcon, |
| 35 |
EnhancementIcon, |
| 36 |
ExclamationCircleIcon, |
| 37 |
ExclamationTriangleIcon, |
| 38 |
RebootingIcon, |
| 39 |
RedoIcon, |
| 40 |
ProcessAutomationIcon, |
| 41 |
SecurityIcon, |
| 42 |
} from "@patternfly/react-icons"; |
| 43 |
import { TableText } from "@patternfly/react-table"; |
| 44 |
import { Remarkable } from "remarkable"; |
| 45 |
|
| 46 |
import { AutoUpdates, getBackend } from "./autoupdates.jsx"; |
| 47 |
import { KpatchSettings, KpatchStatus } from "./kpatch"; |
| 48 |
import { History, PackageList } from "./history"; |
| 49 |
import { RestartServicesDialog } from './restartservices-dialog'; |
| 50 |
import { TwoColumnContent, TwoColumnTitle } from "./two-column"; |
| 51 |
import { page_status } from "notifications"; |
| 52 |
import { EmptyStatePanel } from "cockpit-components-empty-state.jsx"; |
| 53 |
import { ListingTable } from 'cockpit-components-table.jsx'; |
| 54 |
import { ShutdownModal } from 'cockpit-components-shutdown.jsx'; |
| 55 |
import { WithDialogs } from "dialogs.jsx"; |
| 56 |
|
| 57 |
import { superuser } from 'superuser'; |
| 58 |
import * as PK from "packagekit.js"; |
| 59 |
import * as python from "python.js"; |
| 60 |
import * as timeformat from "timeformat"; |
| 61 |
|
| 62 |
import { debug, watchRedHatSubscription } from './utils'; |
| 63 |
import { read_os_release } from "os-release.js"; |
| 64 |
import callTracerScript from './callTracer.py'; |
| 65 |
|
| 66 |
import "./updates.scss"; |
| 67 |
import { Truncate } from '@patternfly/react-core/dist/esm/components/Truncate/index.js'; |
| 68 |
import { Severity } from '_internal/packagemanager-abstract'; |
| 69 |
import { getPackageManager } from 'packagemanager'; |
| 70 |
import { Icon } from '@patternfly/react-core/dist/esm/components/Icon/index.js'; |
| 71 |
|
| 72 |
const _ = cockpit.gettext; |
| 73 |
|
| 74 |
// "available" heading is built dynamically |
| 75 |
const STATE_HEADINGS = {}; |
| 76 |
const PK_STATUS_STRINGS = {}; |
| 77 |
const PK_STATUS_LOG_STRINGS = {}; |
| 78 |
|
| 79 |
const UPDATES = { |
| 80 |
ALL: 0, |
| 81 |
SECURITY: 1, |
| 82 |
KPATCHES: 2, |
| 83 |
}; |
| 84 |
|
| 85 |
function init() { |
| 86 |
STATE_HEADINGS.loading = _("Loading available updates, please wait..."); |
| 87 |
STATE_HEADINGS.locked = _("Some other program is currently using the package manager, please wait..."); |
| 88 |
STATE_HEADINGS.refreshing = _("Refreshing package information"); |
| 89 |
STATE_HEADINGS.uptodate = _("System is up to date"); |
| 90 |
STATE_HEADINGS.applying = _("Applying updates"); |
| 91 |
STATE_HEADINGS.updateError = _("Applying updates failed"); |
| 92 |
STATE_HEADINGS.loadError = _("Loading available updates failed"); |
| 93 |
|
| 94 |
PK_STATUS_STRINGS[PK.Enum.STATUS_DOWNLOAD] = _("Downloading"); |
| 95 |
PK_STATUS_STRINGS[PK.Enum.STATUS_INSTALL] = _("Installing"); |
| 96 |
PK_STATUS_STRINGS[PK.Enum.STATUS_UPDATE] = _("Updating"); |
| 97 |
PK_STATUS_STRINGS[PK.Enum.STATUS_CLEANUP] = _("Setting up"); |
| 98 |
PK_STATUS_STRINGS[PK.Enum.STATUS_SIGCHECK] = _("Verifying"); |
| 99 |
|
| 100 |
PK_STATUS_LOG_STRINGS[PK.Enum.STATUS_DOWNLOAD] = _("Downloaded"); |
| 101 |
PK_STATUS_LOG_STRINGS[PK.Enum.STATUS_INSTALL] = _("Installed"); |
| 102 |
PK_STATUS_LOG_STRINGS[PK.Enum.STATUS_UPDATE] = _("Updated"); |
| 103 |
PK_STATUS_LOG_STRINGS[PK.Enum.STATUS_CLEANUP] = _("Set up"); |
| 104 |
PK_STATUS_LOG_STRINGS[PK.Enum.STATUS_SIGCHECK] = _("Verified"); |
| 105 |
} |
| 106 |
|
| 107 |
function deduplicate(list) { |
| 108 |
return [...new Set(list)].sort(); |
| 109 |
} |
| 110 |
|
| 111 |
// Insert comma strings in between elements of the list. Unlike list.join(",") |
| 112 |
// this does not stringify the elements, which we need to keep as JSX objects. |
| 113 |
function insertCommas(list) { |
| 114 |
if (list.length <= 1) |
| 115 |
return list; |
| 116 |
return list.reduce((prev, cur) => [prev, ", ", cur]); |
| 117 |
} |
| 118 |
|
| 119 |
// Fedora changelogs are a wild mix of enumerations or not, headings, etc. |
| 120 |
// Remove that formatting to avoid an untidy updates overview list |
| 121 |
function cleanupChangelogLine(text) { |
| 122 |
if (!text) |
| 123 |
return text; |
| 124 |
|
| 125 |
// enumerations |
| 126 |
text = text.replace(/^[-* ]*/, ""); |
| 127 |
|
| 128 |
// headings |
| 129 |
text = text.replace(/^=+\s+/, "").replace(/=+\s*$/, ""); |
| 130 |
|
| 131 |
return text.trim(); |
| 132 |
} |
| 133 |
|
| 134 |
// Replace cockpit-wsinstance-https@[long_id] with a shorter string |
| 135 |
function shortenCockpitWsInstance(list) { |
| 136 |
return list.map(item => item.startsWith('cockpit-wsinstance-https') ? 'cockpit-wsinstance-https@.' : item); |
| 137 |
} |
| 138 |
|
| 139 |
function count_security_updates(updates) { |
| 140 |
let num_security = 0; |
| 141 |
for (const u of updates) |
| 142 |
if (u.severity === Severity.CRITICAL) |
| 143 |
++num_security; |
| 144 |
return num_security; |
| 145 |
} |
| 146 |
|
| 147 |
function isKpatchPackage(name) { |
| 148 |
return name.startsWith("kpatch-patch"); |
| 149 |
} |
| 150 |
|
| 151 |
function count_kpatch_updates(updates) { |
| 152 |
let num_kpatches = 0; |
| 153 |
for (const u of updates) |
| 154 |
if (isKpatchPackage(u.name)) |
| 155 |
++num_kpatches; |
| 156 |
return num_kpatches; |
| 157 |
} |
| 158 |
|
| 159 |
function find_highest_severity(updates) { |
| 160 |
let max = Severity.LOW; |
| 161 |
for (const u of updates) |
| 162 |
if (u.severity > max) |
| 163 |
max = u.severity; |
| 164 |
return max; |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Get appropriate icon for an update severity |
| 169 |
* |
| 170 |
* info: An Severity level |
| 171 |
* secSeverity: If given, further classification of the severity of Severity.CRITICAL from the vendor_urls; |
| 172 |
* e. g. "critical", see https://access.redhat.com/security/updates/classification |
| 173 |
* Returns: Icon JSX object |
| 174 |
* |
| 175 |
*/ |
| 176 |
function getSeverityIcon(info, secSeverity) { |
| 177 |
let classes = "severity-icon"; |
| 178 |
if (secSeverity) |
| 179 |
classes += " severity-" + secSeverity; |
| 180 |
if (info == Severity.CRITICAL) |
| 181 |
return <Icon isInline status="danger"><SecurityIcon aria-label={secSeverity || _("security")} className={classes} /></Icon>; |
| 182 |
else if (info >= Severity.IMPORTANT) |
| 183 |
return <Icon isInline className='pf-m-important'><BugIcon className={classes} aria-label={_("bug fix")} /></Icon>; |
| 184 |
else |
| 185 |
return <Icon isInline status="custom"><EnhancementIcon className={classes} aria-label={_("enhancement")} /></Icon>; |
| 186 |
} |
| 187 |
|
| 188 |
function getPageStatusSeverityIcon(severity) { |
| 189 |
if (severity == Severity.CRITICAL) |
| 190 |
return "security"; |
| 191 |
else if (severity >= Severity.IMPORTANT) |
| 192 |
return "bug"; |
| 193 |
else |
| 194 |
return "enhancement"; |
| 195 |
} |
| 196 |
|
| 197 |
function getSeverityURL(urls) { |
| 198 |
if (urls.length === 0) |
| 199 |
return null; |
| 200 |
|
| 201 |
// in ascending severity |
| 202 |
const knownLevels = ["low", "moderate", "important", "critical"]; |
| 203 |
let highestIndex = -1; |
| 204 |
let highestURL = null; |
| 205 |
|
| 206 |
// search URLs for highest valid severity; by all means we expect an update to have at most one, but for paranoia.. |
| 207 |
urls.forEach(value => { |
| 208 |
if (value.startsWith("https://access.redhat.com/security/updates/classification/#")) { |
| 209 |
const i = knownLevels.indexOf(value.slice(value.indexOf("#") + 1)); |
| 210 |
if (i > highestIndex) { |
| 211 |
highestIndex = i; |
| 212 |
highestURL = value; |
| 213 |
} |
| 214 |
} |
| 215 |
}); |
| 216 |
return highestURL; |
| 217 |
} |
| 218 |
|
| 219 |
function isSafeUrl(href) { |
| 220 |
try { |
| 221 |
const url = new URL(href); |
| 222 |
return ["https:", "http:"].includes(url.protocol); |
| 223 |
} catch { |
| 224 |
return false; |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
// Overrides the link_open function to apply our required HTML attributes |
| 229 |
function customRemarkable() { |
| 230 |
const remarkable = new Remarkable(); |
| 231 |
|
| 232 |
remarkable.renderer.rules.link_open = function(tokens, idx) { |
| 233 |
try { |
| 234 |
const url = tokens[idx].href; |
| 235 |
if (!isSafeUrl(url)) |
| 236 |
return "<a>"; |
| 237 |
|
| 238 |
const a = document.createElement("a"); |
| 239 |
a.setAttribute("href", url); |
| 240 |
a.rel = "noopener noreferrer"; |
| 241 |
a.target = "_blank"; |
| 242 |
return a.outerHTML.replace("</a>", ""); |
| 243 |
} catch { |
| 244 |
return "<a>"; |
| 245 |
} |
| 246 |
}; |
| 247 |
return remarkable; |
| 248 |
} |
| 249 |
|
| 250 |
function updateItem(remarkable, info, pkgNames, key) { |
| 251 |
const bug_urls = (info.bug_urls || []).filter(isSafeUrl); |
| 252 |
const cve_urls = (info.cve_urls || []).filter(isSafeUrl); |
| 253 |
const vendor_urls = (info.vendor_urls || []).filter(isSafeUrl); |
| 254 |
|
| 255 |
let bugs = null; |
| 256 |
if (bug_urls.length > 0) { |
| 257 |
// we assume a bug URL ends with a number; if not, show the complete URL |
| 258 |
bugs = insertCommas(bug_urls.map(url => ( |
| 259 |
<a key={url} rel="noopener noreferrer" target="_blank" href={url}> |
| 260 |
{url.match(/[0-9]+$/) || url} |
| 261 |
</a>) |
| 262 |
)); |
| 263 |
} |
| 264 |
|
| 265 |
let cves = null; |
| 266 |
if (cve_urls.length > 0) { |
| 267 |
cves = insertCommas(cve_urls.map(url => ( |
| 268 |
<a key={url} href={url} rel="noopener noreferrer" target="_blank"> |
| 269 |
{url.match(/[^/=]+$/)} |
| 270 |
</a>) |
| 271 |
)); |
| 272 |
} |
| 273 |
|
| 274 |
let errata = null; |
| 275 |
if (vendor_urls.length > 0) { |
| 276 |
errata = insertCommas(vendor_urls.filter(url => url.indexOf("/errata/") > 0).map(url => ( |
| 277 |
<a key={url} href={url} rel="noopener noreferrer" target="_blank"> |
| 278 |
{url.match(/[^/=]+$/)} |
| 279 |
</a>) |
| 280 |
)); |
| 281 |
if (!errata.length) |
| 282 |
errata = null; // simpler testing below |
| 283 |
} |
| 284 |
|
| 285 |
let secSeverityURL = getSeverityURL(vendor_urls); |
| 286 |
const secSeverity = secSeverityURL ? secSeverityURL.slice(secSeverityURL.indexOf("#") + 1) : null; |
| 287 |
const icon = getSeverityIcon(info.severity, secSeverity); |
| 288 |
let type; |
| 289 |
if (info.severity === Severity.CRITICAL) { |
| 290 |
if (secSeverityURL) |
| 291 |
secSeverityURL = <a rel="noopener noreferrer" target="_blank" href={secSeverityURL}>{secSeverity}</a>; |
| 292 |
type = ( |
| 293 |
<Tooltip id="tip-severity" content={ secSeverity || _("security") }> |
| 294 |
<span> |
| 295 |
{icon} |
| 296 |
{ cve_urls.length > 0 && cve_urls.length} |
| 297 |
</span> |
| 298 |
</Tooltip> |
| 299 |
); |
| 300 |
} else { |
| 301 |
const tip = (info.severity >= Severity.IMPORTANT) ? _("bug fix") : _("enhancement"); |
| 302 |
type = ( |
| 303 |
<Tooltip id="tip-severity" content={tip}> |
| 304 |
<span> |
| 305 |
{icon} |
| 306 |
{ bug_urls.length > 0 && bug_urls.length } |
| 307 |
</span> |
| 308 |
</Tooltip> |
| 309 |
); |
| 310 |
} |
| 311 |
|
| 312 |
const pkgList = pkgNames.map((n, index) => ( |
| 313 |
<Tooltip key={n.name + n.arch} id="tip-summary" content={n.summary + " (" + n.arch + ")"}> |
| 314 |
<span>{n.name + (index !== (pkgNames.length - 1) ? ", " : "")}</span> |
| 315 |
</Tooltip>) |
| 316 |
); |
| 317 |
const pkgs = pkgList; |
| 318 |
const pkgsTruncated = pkgList.slice(0, 4); |
| 319 |
|
| 320 |
if (pkgList.length > 4) |
| 321 |
pkgsTruncated.push(<span key="more">…</span>); |
| 322 |
|
| 323 |
if (pkgNames.some(pkg => isKpatchPackage(pkg.name))) |
| 324 |
pkgsTruncated.push( |
| 325 |
<LabelGroup key={`${key}-kpatches-labelgroup`} className="kpatches-labelgroup"> |
| 326 |
{" "}<Badge color="blue">{_("patches")}</Badge> |
| 327 |
</LabelGroup> |
| 328 |
); |
| 329 |
|
| 330 |
let descriptionFirstLine = (info.description || "").trim(); |
| 331 |
if (descriptionFirstLine.indexOf("\n") >= 0) |
| 332 |
descriptionFirstLine = descriptionFirstLine.slice(0, descriptionFirstLine.indexOf("\n")); |
| 333 |
descriptionFirstLine = cleanupChangelogLine(descriptionFirstLine); |
| 334 |
let description; |
| 335 |
if (info.markdown) { |
| 336 |
descriptionFirstLine = <span dangerouslySetInnerHTML={{ __html: remarkable.render(descriptionFirstLine) }} />; |
| 337 |
description = <div dangerouslySetInnerHTML={{ __html: remarkable.render(info.description) }} />; |
| 338 |
} else { |
| 339 |
description = <div className="changelog">{info.description}</div>; |
| 340 |
} |
| 341 |
|
| 342 |
const expandedContent = ( |
| 343 |
<Flex justifyContent={{ default: 'justifyContentSpaceBetween' }}> |
| 344 |
<DescriptionList> |
| 345 |
<DescriptionListGroup> |
| 346 |
<DescriptionListTerm>{_("Packages")}</DescriptionListTerm> |
| 347 |
<DescriptionListDescription>{pkgs}</DescriptionListDescription> |
| 348 |
</DescriptionListGroup> |
| 349 |
{ cves |
| 350 |
? <DescriptionListGroup> |
| 351 |
<DescriptionListTerm>{_("CVE")}</DescriptionListTerm> |
| 352 |
<DescriptionListDescription>{cves}</DescriptionListDescription> |
| 353 |
</DescriptionListGroup> |
| 354 |
: null } |
| 355 |
{ secSeverityURL |
| 356 |
? <DescriptionListGroup> |
| 357 |
<DescriptionListTerm>{_("Severity")}</DescriptionListTerm> |
| 358 |
<DescriptionListDescription className="severity">{secSeverityURL}</DescriptionListDescription> |
| 359 |
</DescriptionListGroup> |
| 360 |
: null } |
| 361 |
{ errata |
| 362 |
? <DescriptionListGroup> |
| 363 |
<DescriptionListTerm>{_("Errata")}</DescriptionListTerm> |
| 364 |
<DescriptionListDescription>{errata}</DescriptionListDescription> |
| 365 |
</DescriptionListGroup> |
| 366 |
: null } |
| 367 |
{ bugs |
| 368 |
? <DescriptionListGroup> |
| 369 |
<DescriptionListTerm>{_("Bugs")}</DescriptionListTerm> |
| 370 |
<DescriptionListDescription>{bugs}</DescriptionListDescription> |
| 371 |
</DescriptionListGroup> |
| 372 |
: null } |
| 373 |
</DescriptionList> |
| 374 |
<Content>{description}</Content> |
| 375 |
</Flex> |
| 376 |
); |
| 377 |
|
| 378 |
return { |
| 379 |
columns: [ |
| 380 |
{ title: pkgsTruncated }, |
| 381 |
{ title: <TableText wrapModifier="truncate">{info.version}</TableText>, props: { className: "version" } }, |
| 382 |
{ title: <TableText wrapModifier="nowrap">{type}</TableText>, props: { className: "type" } }, |
| 383 |
{ title: descriptionFirstLine, props: { className: "changelog" } }, |
| 384 |
], |
| 385 |
props: { |
| 386 |
key, |
| 387 |
className: info.severity === Severity.CRITICAL ? ["error"] : [], |
| 388 |
}, |
| 389 |
hasPadding: true, |
| 390 |
expandedContent, |
| 391 |
}; |
| 392 |
} |
| 393 |
|
| 394 |
const UpdatesList = ({ updates }) => { |
| 395 |
const remarkable = customRemarkable(); |
| 396 |
const combined_updates = []; |
| 397 |
|
| 398 |
// PackageKit doesn"t expose source package names, so group packages with the same version and changelog |
| 399 |
// create a reverse version+changes → [id] map on iteration |
| 400 |
const sameUpdate = {}; |
| 401 |
const packageNames = {}; |
| 402 |
for (const u of updates) { |
| 403 |
// did we already see the same version and description? then merge |
| 404 |
const hash = u.version + u.description; |
| 405 |
const seenId = sameUpdate[hash]; |
| 406 |
if (seenId) { |
| 407 |
packageNames[seenId].push({ name: u.name, arch: u.arch, summary: u.summary }); |
| 408 |
} else { |
| 409 |
// this is a new update |
| 410 |
sameUpdate[hash] = u.id; |
| 411 |
packageNames[u.id] = [{ name: u.name, arch: u.arch, summary: u.summary }]; |
| 412 |
combined_updates.push(u); |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
// sort security first |
| 417 |
combined_updates.sort((a, b) => { |
| 418 |
if (a.severity === Severity.CRITICAL && b.severity !== Severity.CRITICAL) |
| 419 |
return -1; |
| 420 |
if (a.severity !== Severity.CRITICAL && b.severity === Severity.CRITICAL) |
| 421 |
return 1; |
| 422 |
return a.name.localeCompare(b.name); |
| 423 |
}); |
| 424 |
|
| 425 |
return ( |
| 426 |
<ListingTable aria-label={_("Available updates")} |
| 427 |
gridBreakPoint='grid-lg' |
| 428 |
columns={[ |
| 429 |
{ title: _("Name"), props: { width: 40 } }, |
| 430 |
{ title: _("Version"), props: { width: 15 } }, |
| 431 |
{ title: _("Severity"), props: { width: 15 } }, |
| 432 |
{ title: _("Details"), props: { width: 30 } }, |
| 433 |
]} |
| 434 |
rows={combined_updates.map(update => updateItem(remarkable, update, packageNames[update.id].sort((a, b) => a.name > b.name), update.id))} /> |
| 435 |
); |
| 436 |
}; |
| 437 |
|
| 438 |
const formatPackageId = packageId => { |
| 439 |
const pfields = packageId.split(";"); |
| 440 |
return pfields[0] + " " + pfields[1] + " (" + pfields[2] + ")"; |
| 441 |
}; |
| 442 |
|
| 443 |
// actions is a chronological list of { status, packageId } events that happen during applying updates |
| 444 |
// status: see PK_STATUS_* at https://github.com/PackageKit/PackageKit/blob/main/lib/packagekit-glib2/pk-enum.h |
| 445 |
const ApplyUpdates = ({ transactionProps, actions, onCancel, rebootAfter, setRebootAfter }) => { |
| 446 |
const remain = transactionProps.RemainingTime |
| 447 |
? timeformat.distanceToNow(new Date().valueOf() + transactionProps.RemainingTime * 1000) |
| 448 |
: null; |
| 449 |
|
| 450 |
let percentage = transactionProps.Percentage || 0; |
| 451 |
// PackageKit sets this to 101 initially |
| 452 |
if (percentage > 100) |
| 453 |
percentage = 0; |
| 454 |
|
| 455 |
// scroll update log to the bottom, if it already is (almost) at the bottom |
| 456 |
const log = document.getElementById("update-log"); |
| 457 |
if (log) { |
| 458 |
if (log.scrollHeight - log.clientHeight <= log.scrollTop + 2) |
| 459 |
log.scrollTop = log.scrollHeight; |
| 460 |
} |
| 461 |
|
| 462 |
const cancelButton = transactionProps.AllowCancel |
| 463 |
? <Button variant="secondary" onClick={onCancel} size="sm">{_("Cancel")}</Button> |
| 464 |
: null; |
| 465 |
|
| 466 |
if (actions.length === 0 && percentage === 0) { |
| 467 |
return <EmptyStatePanel title={ _("Initializing...") } |
| 468 |
headingLevel="h5" |
| 469 |
secondary={cancelButton} |
| 470 |
loading |
| 471 |
/>; |
| 472 |
} |
| 473 |
|
| 474 |
const lastAction = actions[actions.length - 1]; |
| 475 |
// when resuming an upgrade, we did not get any Package signal yet; fall back to LastPackage |
| 476 |
const curPackage = formatPackageId(lastAction?.packageId || transactionProps.LastPackage || ""); |
| 477 |
return ( |
| 478 |
<div className="progress-main-view"> |
| 479 |
<Grid hasGutter> |
| 480 |
<GridItem span={12}> |
| 481 |
<div className="progress-description pf-v6-u-display-flex"> |
| 482 |
<Spinner size="md" isInline /> |
| 483 |
<strong>{PK_STATUS_STRINGS[lastAction?.status] || PK_STATUS_STRINGS[PK.Enum.STATUS_UPDATE]}</strong> |
| 484 |
|
| 485 |
<Truncate content={curPackage} /> |
| 486 |
</div> |
| 487 |
<Progress title={remain} |
| 488 |
aria-label={remain ? _("Time remaining: ") : _("Update progress")} |
| 489 |
value={percentage} |
| 490 |
size={ProgressSize.sm} |
| 491 |
className="pf-v6-u-mb-xs" /> |
| 492 |
</GridItem> |
| 493 |
|
| 494 |
<GridItem span={3}>{cancelButton}</GridItem> |
| 495 |
|
| 496 |
<GridItem span={12}> |
| 497 |
<Switch id="reboot-after" isChecked={rebootAfter} |
| 498 |
label={ _("Reboot after completion") } |
| 499 |
onChange={setRebootAfter} /> |
| 500 |
</GridItem> |
| 501 |
|
| 502 |
<GridItem span={12} className="update-log"> |
| 503 |
<ExpandableSection toggleText={_("View update log")} onToggle={() => { |
| 504 |
// always scroll down on expansion |
| 505 |
const log = document.getElementById("update-log"); |
| 506 |
log.scrollTop = log.scrollHeight; |
| 507 |
}}> |
| 508 |
<div id="update-log" className="update-log-content"> |
| 509 |
<table> |
| 510 |
<tbody> |
| 511 |
{ actions.slice(0, -1).map((action, i) => ( |
| 512 |
<tr key={action.packageId + i}> |
| 513 |
<th>{PK_STATUS_LOG_STRINGS[action.status] || PK_STATUS_LOG_STRINGS[PK.Enum.STATUS_UPDATE]}</th> |
| 514 |
<td>{formatPackageId(action.packageId)}</td> |
| 515 |
</tr>)) } |
| 516 |
</tbody> |
| 517 |
</table> |
| 518 |
</div> |
| 519 |
</ExpandableSection> |
| 520 |
</GridItem> |
| 521 |
</Grid> |
| 522 |
</div> |
| 523 |
); |
| 524 |
}; |
| 525 |
|
| 526 |
const UpdateSuccess = ({ onIgnore, openServiceRestartDialog, openRebootDialog, restart, manual, reboot, checkRestartAvailable, history }) => { |
| 527 |
if (!checkRestartAvailable) { |
| 528 |
/* tracer is not available any more in RHEL 10; as a special case, if only kpatch and kernel were |
| 529 |
* updated, don't reboot (as that's their whole raison d'être) */ |
| 530 |
const pkgs = Object.keys(history[0]?.packages ?? {}); |
| 531 |
const only_kpatch = pkgs.filter(p => p.startsWith("kpatch")).length > 0 && |
| 532 |
pkgs.filter(p => !p.startsWith("kernel") && !p.startsWith("kpatch")).length == 0; |
| 533 |
|
| 534 |
const paragraph = only_kpatch ? null : _("Updated packages may require a reboot to take effect."); |
| 535 |
const actions = only_kpatch |
| 536 |
? <Button id="ignore" variant="primary" onClick={onIgnore}>{_("Continue")}</Button> |
| 537 |
: <> |
| 538 |
<Button id="reboot-system" variant="primary" onClick={openRebootDialog}>{_("Reboot system...")}</Button> |
| 539 |
<Button id="ignore" variant="link" onClick={onIgnore}>{_("Ignore")}</Button> |
| 540 |
</>; |
| 541 |
|
| 542 |
return (<> |
| 543 |
<EmptyStatePanel icon={RebootingIcon} |
| 544 |
title={ _("Update was successful") } |
| 545 |
headingLevel="h5" |
| 546 |
paragraph={paragraph} |
| 547 |
secondary={actions} /> |
| 548 |
{ history[0]?.packages && |
| 549 |
<div className="flow-list-blank-slate"> |
| 550 |
<ExpandableSection toggleText={_("Package information")}> |
| 551 |
<PackageList packages={history[0].packages} /> |
| 552 |
</ExpandableSection> |
| 553 |
</div> |
| 554 |
} |
| 555 |
</>); |
| 556 |
} |
| 557 |
|
| 558 |
const entries = []; |
| 559 |
if (reboot.length > 0) { |
| 560 |
entries.push({ |
| 561 |
columns: [ |
| 562 |
{ |
| 563 |
title: <TwoColumnTitle icon={<RebootingIcon />} |
| 564 |
str={cockpit.format(cockpit.ngettext("$0 package needs a system reboot", |
| 565 |
"$0 packages need a system reboot", |
| 566 |
reboot.length), |
| 567 |
reboot.length)} /> |
| 568 |
}, |
| 569 |
], |
| 570 |
props: { key: "reboot", id: "reboot-row" }, |
| 571 |
hasPadding: true, |
| 572 |
expandedContent: <TwoColumnContent list={reboot} />, |
| 573 |
}); |
| 574 |
} |
| 575 |
|
| 576 |
if (restart.length > 0) { |
| 577 |
entries.push({ |
| 578 |
columns: [ |
| 579 |
{ |
| 580 |
title: <TwoColumnTitle icon={<ProcessAutomationIcon />} |
| 581 |
str={cockpit.format(cockpit.ngettext("$0 service needs to be restarted", |
| 582 |
"$0 services need to be restarted", |
| 583 |
restart.length), |
| 584 |
restart.length)} /> |
| 585 |
}, |
| 586 |
], |
| 587 |
props: { key: "service", id: "service-row" }, |
| 588 |
hasPadding: true, |
| 589 |
expandedContent: <TwoColumnContent list={restart} />, |
| 590 |
}); |
| 591 |
} |
| 592 |
|
| 593 |
if (manual.length > 0) { |
| 594 |
entries.push({ |
| 595 |
columns: [ |
| 596 |
{ |
| 597 |
title: <TwoColumnTitle icon={<ProcessAutomationIcon />} |
| 598 |
str={_("Some software needs to be restarted manually")} /> |
| 599 |
} |
| 600 |
], |
| 601 |
props: { key: "manual", id: "manual-row" }, |
| 602 |
hasPadding: true, |
| 603 |
expandedContent: <TwoColumnContent list={manual} />, |
| 604 |
}); |
| 605 |
} |
| 606 |
|
| 607 |
const showReboot = reboot.length > 0 || manual.length > 0; |
| 608 |
|
| 609 |
return (<> |
| 610 |
<EmptyStatePanel title={ _("Update was successful") } |
| 611 |
headingLevel="h5" |
| 612 |
secondary={ |
| 613 |
<> |
| 614 |
{ entries.length > 0 && <ListingTable aria-label={_("Update Success Table")} |
| 615 |
columns={[{ title: _("Info") }]} |
| 616 |
showHeader={false} |
| 617 |
className="updates-success-table" |
| 618 |
rows={entries} /> } |
| 619 |
<div className="update-success-actions"> |
| 620 |
{ showReboot && <Button id="reboot-system" variant="primary" onClick={openRebootDialog}>{_("Reboot system...")}</Button> } |
| 621 |
{ restart.length > 0 && <Button id="choose-service" variant={showReboot ? "secondary" : "primary"} onClick={openServiceRestartDialog}>{_("Restart services...")}</Button> } |
| 622 |
{ reboot.length > 0 || restart.length > 0 || manual.length > 0 |
| 623 |
? <Button id="ignore" variant="link" onClick={onIgnore}>{_("Ignore")}</Button> |
| 624 |
: <Button id="ignore" variant="primary" onClick={onIgnore}>{_("Continue")}</Button> } |
| 625 |
</div> |
| 626 |
</> |
| 627 |
} /> |
| 628 |
{ history[0]?.packages && |
| 629 |
<div className="flow-list-blank-slate"> |
| 630 |
<ExpandableSection toggleText={_("Package information")}> |
| 631 |
<PackageList packages={history[0].packages} /> |
| 632 |
</ExpandableSection> |
| 633 |
</div> |
| 634 |
} |
| 635 |
</>); |
| 636 |
}; |
| 637 |
|
| 638 |
const UpdatesStatus = ({ updates, highestSeverity, timeSinceRefresh, restartPackages, onValueChanged }) => { |
| 639 |
const numUpdates = updates.length; |
| 640 |
const numSecurity = count_security_updates(updates); |
| 641 |
const numRestartServices = restartPackages.daemons.length; |
| 642 |
const numManualSoftware = restartPackages.manual.length; |
| 643 |
const numRebootPackages = restartPackages.reboot.length; |
| 644 |
let lastChecked; |
| 645 |
// PackageKit returns G_MAXUINT if the db was never checked. |
| 646 |
if (timeSinceRefresh !== null && timeSinceRefresh !== 2 ** 32 - 1) |
| 647 |
lastChecked = cockpit.format(_("Last checked: $0"), timeformat.distanceToNow(new Date().valueOf() - timeSinceRefresh * 1000)); |
| 648 |
|
| 649 |
const notifications = []; |
| 650 |
if (numUpdates > 0) { |
| 651 |
if (numUpdates == numSecurity) { |
| 652 |
const stateStr = cockpit.ngettext("$0 security fix available", "$0 security fixes available", numSecurity); |
| 653 |
notifications.push({ |
| 654 |
id: "security-updates-available", |
| 655 |
stateStr: cockpit.format(stateStr, numSecurity), |
| 656 |
icon: getSeverityIcon(highestSeverity), |
| 657 |
secondary: <Content id="last-checked" component={ContentVariants.small}>{lastChecked}</Content> |
| 658 |
}); |
| 659 |
} else { |
| 660 |
let stateStr = cockpit.ngettext("$0 update available", "$0 updates available", numUpdates); |
| 661 |
if (numSecurity > 0) |
| 662 |
stateStr += cockpit.ngettext(", including $1 security fix", ", including $1 security fixes", numSecurity); |
| 663 |
notifications.push({ |
| 664 |
id: "updates-available", |
| 665 |
stateStr: cockpit.format(stateStr, numUpdates, numSecurity), |
| 666 |
icon: getSeverityIcon(highestSeverity), |
| 667 |
secondary: <Content id="last-checked" component={ContentVariants.small}>{lastChecked}</Content> |
| 668 |
}); |
| 669 |
} |
| 670 |
} else if (!numRestartServices && !numRebootPackages && !numManualSoftware) { |
| 671 |
notifications.push({ |
| 672 |
id: "system-up-to-date", |
| 673 |
stateStr: STATE_HEADINGS.uptodate, |
| 674 |
icon: <CheckIcon color="green" />, |
| 675 |
secondary: <Content id="last-checked" component={ContentVariants.small}>{lastChecked}</Content> |
| 676 |
}); |
| 677 |
} |
| 678 |
|
| 679 |
if (numRebootPackages > 0) { |
| 680 |
const stateStr = cockpit.ngettext("$0 package needs a system reboot", "$0 packages need a system reboot", numRebootPackages); |
| 681 |
notifications.push({ |
| 682 |
id: "packages-need-reboot", |
| 683 |
stateStr: cockpit.format(stateStr, numRebootPackages), |
| 684 |
icon: <RebootingIcon />, |
| 685 |
secondary: <Button variant="danger" onClick={() => onValueChanged("showRebootSystemDialog", true)}> |
| 686 |
{_("Reboot system...")} |
| 687 |
</Button> |
| 688 |
}); |
| 689 |
} |
| 690 |
|
| 691 |
if (numRestartServices > 0) { |
| 692 |
const stateStr = cockpit.ngettext("$0 service needs to be restarted", "$0 services need to be restarted", numRestartServices); |
| 693 |
notifications.push({ |
| 694 |
id: "services-need-restart", |
| 695 |
stateStr: cockpit.format(stateStr, numRestartServices), |
| 696 |
icon: <ProcessAutomationIcon />, |
| 697 |
secondary: <Button variant="primary" onClick={() => onValueChanged("showRestartServicesDialog", true)}> |
| 698 |
{_("Restart services...")} |
| 699 |
</Button> |
| 700 |
}); |
| 701 |
} |
| 702 |
|
| 703 |
if (numManualSoftware > 0) { |
| 704 |
notifications.push({ |
| 705 |
id: "processes-need-restart", |
| 706 |
stateStr: _("Some software needs to be restarted manually"), |
| 707 |
icon: <ProcessAutomationIcon />, |
| 708 |
secondary: <Content component={ContentVariants.small}>{restartPackages.manual.join(", ")}</Content> |
| 709 |
}); |
| 710 |
} |
| 711 |
|
| 712 |
return (<Stack hasGutter> |
| 713 |
{ notifications.map(notification => ( |
| 714 |
<StackItem key={notification.id}> |
| 715 |
<Flex flexWrap={{ default: 'nowrap' }} id={notification.id}> |
| 716 |
<FlexItem> |
| 717 |
{notification.icon} |
| 718 |
</FlexItem> |
| 719 |
<FlexItem> |
| 720 |
<Stack> |
| 721 |
<StackItem> |
| 722 |
<Content component={ContentVariants.p}>{notification.stateStr}</Content> |
| 723 |
</StackItem> |
| 724 |
<StackItem> |
| 725 |
{ notification.secondary } |
| 726 |
</StackItem> |
| 727 |
</Stack> |
| 728 |
</FlexItem> |
| 729 |
</Flex> |
| 730 |
</StackItem> |
| 731 |
))} |
| 732 |
</Stack>); |
| 733 |
}; |
| 734 |
|
| 735 |
class CardsPage extends React.Component { |
| 736 |
constructor() { |
| 737 |
super(); |
| 738 |
this.state = { |
| 739 |
autoupdates_backend: undefined, |
| 740 |
}; |
| 741 |
} |
| 742 |
|
| 743 |
componentDidMount() { |
| 744 |
getBackend(this.props.backend).then(b => { this.setState({ autoupdates_backend: b }) }); |
| 745 |
} |
| 746 |
|
| 747 |
render() { |
| 748 |
const cardContents = []; |
| 749 |
let settingsContent = null; |
| 750 |
const statusContent = <Stack hasGutter> |
| 751 |
<UpdatesStatus key="updates-status" |
| 752 |
updates={this.props.updates} |
| 753 |
onValueChanged={this.props.onValueChanged} |
| 754 |
restartPackages={this.props.restartPackages} |
| 755 |
highestSeverity={this.props.highestSeverity} |
| 756 |
timeSinceRefresh={this.props.timeSinceRefresh} /> |
| 757 |
<KpatchStatus /> |
| 758 |
</Stack>; |
| 759 |
|
| 760 |
if (this.state.autoupdates_backend) { |
| 761 |
settingsContent = <Stack hasGutter> |
| 762 |
<AutoUpdates privileged={this.props.privileged} packagekit_backend={this.props.backend} initial_backend={this.state.autoupdates_backend} /> |
| 763 |
{cockpit.info.os_release && cockpit.info.os_release?.ID === "rhel" && |
| 764 |
<KpatchSettings privileged={this.props.privileged} /> |
| 765 |
} |
| 766 |
</Stack>; |
| 767 |
} |
| 768 |
|
| 769 |
cardContents.push({ |
| 770 |
id: "status", |
| 771 |
className: settingsContent !== null ? "ct-card-info" : "", |
| 772 |
title: _("Status"), |
| 773 |
actions: (<Tooltip content={_("Check for updates")}> |
| 774 |
<Button icon={<RedoIcon />} variant="secondary" onClick={this.props.handleRefresh} /> |
| 775 |
</Tooltip>), |
| 776 |
body: statusContent, |
| 777 |
}); |
| 778 |
|
| 779 |
if (settingsContent !== null) { |
| 780 |
cardContents.push({ |
| 781 |
id: "settings", |
| 782 |
className: "ct-card-info", |
| 783 |
title: _("Settings"), |
| 784 |
body: settingsContent, |
| 785 |
}); |
| 786 |
} |
| 787 |
|
| 788 |
if (this.props.state === "available") { // automatic updates are not tracked by PackageKit, hide history when they are enabled |
| 789 |
cardContents.push({ |
| 790 |
id: "available-updates", |
| 791 |
title: _("Available updates"), |
| 792 |
actions: (<div className="pk-updates--header--actions"> |
| 793 |
{this.props.cockpitUpdate && |
| 794 |
<Flex flex={{ default: 'inlineFlex' }} className="cockpit-update-warning"> |
| 795 |
<FlexItem> |
| 796 |
<ExclamationTriangleIcon className="ct-icon-exclamation-triangle cockpit-update-warning-icon" /> |
| 797 |
<strong className="cockpit-update-warning-text"> |
| 798 |
<span className="pf-screen-reader">{_("Danger alert:")}</span> |
| 799 |
{_("Web Console will restart")} |
| 800 |
</strong> |
| 801 |
</FlexItem> |
| 802 |
<FlexItem> |
| 803 |
<Popover aria-label="More information popover" |
| 804 |
bodyContent={_("When the Web Console is restarted, you will no longer see progress information. However, the update process will continue in the background. Reconnect to continue watching the update process.")}> |
| 805 |
<Button variant="link" isInline>{_("More info...")}</Button> |
| 806 |
</Popover> |
| 807 |
</FlexItem> |
| 808 |
</Flex>} |
| 809 |
{this.props.applyKpatches} |
| 810 |
{this.props.applySecurity} |
| 811 |
{this.props.applyAll} |
| 812 |
</div>), |
| 813 |
containsList: true, |
| 814 |
body: <UpdatesList updates={this.props.updates} /> |
| 815 |
}); |
| 816 |
} |
| 817 |
|
| 818 |
if ((!this.state.autoupdates_backend || !this.state.autoupdates_backend.enabled) && this.props.history.length > 0) { // automatic updates are not tracked by PackageKit, hide history when they are enabled |
| 819 |
cardContents.push({ |
| 820 |
id: "update-history", |
| 821 |
title: _("Update history"), |
| 822 |
containsList: true, |
| 823 |
body: <History packagekit={this.props.history} /> |
| 824 |
}); |
| 825 |
} |
| 826 |
|
| 827 |
return cardContents.map(card => { |
| 828 |
return ( |
| 829 |
<Card key={card.id} className={card.className} id={card.id}> |
| 830 |
<CardHeader actions={{ actions: card.actions }}> |
| 831 |
<CardTitle component="h2">{card.title}</CardTitle> |
| 832 |
</CardHeader> |
| 833 |
<CardBody className={card.containsList ? "contains-list" : null}> |
| 834 |
{card.body} |
| 835 |
</CardBody> |
| 836 |
</Card> |
| 837 |
); |
| 838 |
}); |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
class OsUpdates extends React.Component { |
| 843 |
constructor() { |
| 844 |
super(); |
| 845 |
this.state = { |
| 846 |
state: "loading", |
| 847 |
errorMessages: [], |
| 848 |
updates: [], |
| 849 |
timeSinceRefresh: null, |
| 850 |
loadPercent: null, |
| 851 |
cockpitUpdate: false, |
| 852 |
haveOsRepo: null, |
| 853 |
applyTransaction: null, |
| 854 |
applyTransactionProps: {}, |
| 855 |
applyActions: [], |
| 856 |
history: [], |
| 857 |
unregistered: false, |
| 858 |
privileged: false, |
| 859 |
autoUpdatesEnabled: undefined, |
| 860 |
restartPackages: { daemons: [], manual: [], reboot: [] }, |
| 861 |
checkRestartAvailable: false, |
| 862 |
checkRestartRunning: false, |
| 863 |
showRestartServicesDialog: false, |
| 864 |
showRebootSystemDialog: false, |
| 865 |
backend: "", |
| 866 |
rebootAfterSuccess: false, |
| 867 |
packageManager: null, |
| 868 |
}; |
| 869 |
this.handleLoadError = this.handleLoadError.bind(this); |
| 870 |
this.handleRefresh = this.handleRefresh.bind(this); |
| 871 |
this.loadUpdates = this.loadUpdates.bind(this); |
| 872 |
this.onValueChanged = this.onValueChanged.bind(this); |
| 873 |
this.checkNeedsRestart = this.checkNeedsRestart.bind(this); |
| 874 |
} |
| 875 |
|
| 876 |
onValueChanged(key, value) { |
| 877 |
this.setState({ [key]: value }); |
| 878 |
} |
| 879 |
|
| 880 |
async componentDidMount() { |
| 881 |
this._mounted = true; |
| 882 |
this.checkNeedsRestart(); |
| 883 |
|
| 884 |
superuser.addEventListener("changed", this.handleSuperUserChange); |
| 885 |
|
| 886 |
// HACK: force usage of PackageKit backend |
| 887 |
const packageManager = await getPackageManager(true); |
| 888 |
const backend = await packageManager.get_backend(); |
| 889 |
this.setState({ packageManager, backend }); |
| 890 |
|
| 891 |
// check if there is an upgrade in progress already; if so, switch to "applying" state right away |
| 892 |
PK.call("/org/freedesktop/PackageKit", "org.freedesktop.PackageKit", "GetTransactionList", []) |
| 893 |
.then(([transactions]) => { |
| 894 |
if (!this._mounted) |
| 895 |
return; |
| 896 |
|
| 897 |
const promises = transactions.map(transactionPath => PK.call( |
| 898 |
transactionPath, "org.freedesktop.DBus.Properties", "Get", [PK.transactionInterface, "Role"])); |
| 899 |
|
| 900 |
Promise.all(promises) |
| 901 |
.then(roles => { |
| 902 |
// any transaction with UPDATE_PACKAGES role? |
| 903 |
for (let idx = 0; idx < roles.length; ++idx) { |
| 904 |
if (roles[idx][0].v === PK.Enum.ROLE_UPDATE_PACKAGES) { |
| 905 |
this.watchUpdates(transactions[idx]); |
| 906 |
return; |
| 907 |
} |
| 908 |
} |
| 909 |
|
| 910 |
// no running updates found, proceed to showing available updates |
| 911 |
this.initialLoadOrRefresh(); |
| 912 |
}) |
| 913 |
.catch(ex => { |
| 914 |
console.warn("GetTransactionList: failed to read PackageKit transaction roles:", ex.message); |
| 915 |
// be robust, try to continue with loading updates anyway |
| 916 |
this.initialLoadOrRefresh(); |
| 917 |
}); |
| 918 |
}) |
| 919 |
.catch(this.handleLoadError); |
| 920 |
} |
| 921 |
|
| 922 |
componentWillUnmount() { |
| 923 |
this._mounted = false; |
| 924 |
superuser.removeEventListener("changed", this.handleSuperUserChange); |
| 925 |
} |
| 926 |
|
| 927 |
handleSuperUserChange = () => { |
| 928 |
this.setState({ privileged: superuser.allowed }); |
| 929 |
// get out of error state when switching from unprivileged to privileged |
| 930 |
if (superuser.allowed && this.state.state.indexOf("Error") >= 0) |
| 931 |
this.loadUpdates(); |
| 932 |
}; |
| 933 |
|
| 934 |
checkNeedsRestart() { |
| 935 |
this.setState({ checkRestartRunning: true }); |
| 936 |
return python.spawn(callTracerScript, undefined, { err: "message", superuser: "require" }) |
| 937 |
.then(output => { |
| 938 |
debug("tracer succeeded, output:", output); |
| 939 |
const restartPackages = JSON.parse(output); |
| 940 |
// Filter out duplicates |
| 941 |
restartPackages.reboot = deduplicate(shortenCockpitWsInstance(restartPackages.reboot)); |
| 942 |
restartPackages.daemons = deduplicate(shortenCockpitWsInstance(restartPackages.daemons)); |
| 943 |
restartPackages.manual = deduplicate(shortenCockpitWsInstance(restartPackages.manual)); |
| 944 |
debug("tracer parsed restartPackages:", JSON.stringify(restartPackages)); |
| 945 |
this.setState({ checkRestartAvailable: true, checkRestartRunning: false, restartPackages }); |
| 946 |
}) |
| 947 |
.catch((exception, data) => { |
| 948 |
// tracer not installed or supported (like on Arch)? then fall back to dnf needs-restarting |
| 949 |
if (exception.message?.includes("ModuleNotFoundError") || |
| 950 |
exception.message?.includes("UnsupportedDistribution")) { |
| 951 |
debug('tracer not installed:', JSON.stringify(exception), "trying dnf needs-restarting"); |
| 952 |
return this.checkDnfNeedsRestarting(); |
| 953 |
} |
| 954 |
|
| 955 |
// log the error except for some common cases: polkit does not allow it |
| 956 |
if (exception.problem !== "access-denied" && |
| 957 |
// or unprivileged session |
| 958 |
exception.problem !== "authentication-failed" && |
| 959 |
// or the session goes away while checking |
| 960 |
exception.problem !== "terminated") |
| 961 |
console.error(`Tracer failed: "${JSON.stringify(exception)}", data: "${JSON.stringify(data)}"`); |
| 962 |
else |
| 963 |
debug('tracer failed for uninteresting reason:', JSON.stringify(exception)); |
| 964 |
|
| 965 |
// When tracer fails, act like it's not available (demand reboot after every update) |
| 966 |
this.setState({ |
| 967 |
checkRestartAvailable: false, |
| 968 |
checkRestartRunning: false, |
| 969 |
restartPackages: { reboot: [], daemons: [], manual: [] }, |
| 970 |
}); |
| 971 |
}); |
| 972 |
} |
| 973 |
|
| 974 |
checkDnfNeedsRestarting() { |
| 975 |
const restartPackages = { reboot: [], daemons: [], manual: [] }; |
| 976 |
|
| 977 |
// needs-restarting has no machine-readable API: https://issues.redhat.com/browse/RHEL-56139 |
| 978 |
// dnf5 needs-restarting also has no machine-readable API: https://github.com/rpm-software-management/dnf5/issues/2341 |
| 979 |
// --exclude-services was added much later, so check that first |
| 980 |
return cockpit.spawn(["dnf", "needs-restarting", "--exclude-services"], { err: "message", superuser: "require" }) |
| 981 |
.then(outManual => { |
| 982 |
debug("dnf needs-restarting --exclude-services succeeded:", outManual); |
| 983 |
// format: "pid : argv", e.g. "1234 : mydaemon 3600" |
| 984 |
outManual.trim() |
| 985 |
.split("\n") |
| 986 |
// HACK: https://issues.redhat.com/browse/RHEL-84657 |
| 987 |
.filter(line => line.match(/^\d+ : /)) |
| 988 |
.forEach(line => !line || restartPackages.manual.push(line)); |
| 989 |
|
| 990 |
return Promise.allSettled([ |
| 991 |
cockpit.spawn(["dnf", "needs-restarting", "--services"], { err: "message", superuser: "require" }), |
| 992 |
// we can't get stdout for a failing process, thus needs script |
| 993 |
cockpit.script("! dnf needs-restarting --reboothint", undefined, { err: "message", superuser: "require" }), |
| 994 |
]) |
| 995 |
.then(([serviceResult, rebootResult]) => { |
| 996 |
// --services format: one unit name per line |
| 997 |
if (serviceResult.status == 'fulfilled') { |
| 998 |
debug("dnf needs-restarting --services succeeded:", serviceResult.value); |
| 999 |
serviceResult.value.trim() |
| 1000 |
.split("\n") |
| 1001 |
// HACK: https://issues.redhat.com/browse/RHEL-84657 |
| 1002 |
.filter(line => line.endsWith(".service")) |
| 1003 |
.forEach(line => restartPackages.daemons.push(line)); |
| 1004 |
} else { |
| 1005 |
console.error("dnf needs-restarting --services failed:", JSON.stringify(serviceResult.reason)); |
| 1006 |
} |
| 1007 |
|
| 1008 |
// --reboothint format: " * kernel-rt" plus header/footer; exit nonzero iff reboot required, inverted above |
| 1009 |
if (rebootResult.status == 'fulfilled') { |
| 1010 |
debug("dnf needs-restarting --reboothint exited nonzero, wants reboot:", rebootResult.value); |
| 1011 |
rebootResult.value.split("\n").forEach(line => { |
| 1012 |
if (line.startsWith(" * ")) |
| 1013 |
restartPackages.reboot.push(line.substring(4)); |
| 1014 |
}); |
| 1015 |
} else { |
| 1016 |
debug("dnf needs-restarting --reboothint exited zero, no reboot"); |
| 1017 |
} |
| 1018 |
|
| 1019 |
debug("dnf needs-restarting parsed packages:", JSON.stringify(restartPackages)); |
| 1020 |
this.setState({ checkRestartAvailable: true, checkRestartRunning: false, restartPackages }); |
| 1021 |
}); |
| 1022 |
}) |
| 1023 |
.catch(ex => { |
| 1024 |
// log the error except for some common cases: no dnf |
| 1025 |
if (ex.problem !== "not-found" && |
| 1026 |
// plugin does not support --exclude-services |
| 1027 |
!ex.message.includes("usage:") && |
| 1028 |
// polkit does not allow it |
| 1029 |
ex.problem !== "access-denied" && |
| 1030 |
// or unprivileged session |
| 1031 |
ex.problem !== "authentication-failed" && |
| 1032 |
// or the session goes away while checking |
| 1033 |
ex.problem !== "terminated") |
| 1034 |
console.error("dnf needs-restarting failed:", ex.toString()); |
| 1035 |
|
| 1036 |
// act like it's not available (demand reboot after every update) |
| 1037 |
this.setState({ checkRestartAvailable: false, checkRestartRunning: false, restartPackages }); |
| 1038 |
}); |
| 1039 |
} |
| 1040 |
|
| 1041 |
handleLoadError(ex) { |
| 1042 |
console.warn("loading available updates failed:", JSON.stringify(ex)); |
| 1043 |
|
| 1044 |
if (!this._mounted) |
| 1045 |
return; |
| 1046 |
|
| 1047 |
if (ex.problem === "not-found" || ex.name?.includes("DBus.Error.ServiceUnknown")) |
| 1048 |
ex = _("PackageKit is not installed"); |
| 1049 |
this.setState(prevState => ({ errorMessages: [...prevState.errorMessages, ex.detail || ex.message || ex], state: "loadError" })); |
| 1050 |
} |
| 1051 |
|
| 1052 |
loadUpdates() { |
| 1053 |
let cockpitUpdate = false; |
| 1054 |
|
| 1055 |
this.setState({ state: "loading" }); |
| 1056 |
|
| 1057 |
// check if there is an available version of coreutils; this is a heuristics for unregistered RHEL |
| 1058 |
// systems to see if they need a subscription to get "proper" OS updates |
| 1059 |
this.state.packageManager.is_available(["coreutils"]) |
| 1060 |
.then((have_coreutils) => this.setState({ haveOsRepo: have_coreutils }), |
| 1061 |
ex => console.warn("Resolving coreutils failed:", JSON.stringify(ex))) |
| 1062 |
.then(() => this.state.packageManager.get_updates(true, null).then(updates => { |
| 1063 |
debug("GetUpdates result:", updates); |
| 1064 |
if (updates.length) { |
| 1065 |
for (const update of updates) { |
| 1066 |
if (update.name === 'cockpit-ws') { |
| 1067 |
cockpitUpdate = true; |
| 1068 |
// Arch Linux has no cockpit-ws package |
| 1069 |
} else if (update.name === 'cockpit' && this.state.backend === "alpm") { |
| 1070 |
cockpitUpdate = true; |
| 1071 |
} |
| 1072 |
} |
| 1073 |
this.setState({ updates, cockpitUpdate, state: "available" }); |
| 1074 |
} else { |
| 1075 |
this.setState({ updates: [], state: "uptodate" }); |
| 1076 |
} |
| 1077 |
this.loadHistory(); |
| 1078 |
})) |
| 1079 |
.catch(this.handleLoadError); |
| 1080 |
} |
| 1081 |
|
| 1082 |
async loadHistory() { |
| 1083 |
try { |
| 1084 |
const history = await this.state.packageManager.get_history(); |
| 1085 |
this.setState({ history }); |
| 1086 |
} catch (exc) { |
| 1087 |
console.warn("Failed to load old transactions (history):", exc); |
| 1088 |
} |
| 1089 |
} |
| 1090 |
|
| 1091 |
initialLoadOrRefresh() { |
| 1092 |
watchRedHatSubscription(registered => this.setState({ unregistered: !registered })); |
| 1093 |
|
| 1094 |
cockpit.addEventListener("visibilitychange", () => { |
| 1095 |
if (!cockpit.hidden) |
| 1096 |
this.loadOrRefresh(false); |
| 1097 |
}); |
| 1098 |
|
| 1099 |
if (!cockpit.hidden) |
| 1100 |
this.loadOrRefresh(true); |
| 1101 |
else |
| 1102 |
this.loadUpdates(); |
| 1103 |
} |
| 1104 |
|
| 1105 |
async loadOrRefresh(always_load) { |
| 1106 |
try { |
| 1107 |
const seconds = await this.state.packageManager.get_last_refresh_time(); |
| 1108 |
this.setState({ timeSinceRefresh: seconds }); |
| 1109 |
|
| 1110 |
// automatically trigger refresh for ≥ 1 day or if never refreshed |
| 1111 |
if (seconds >= 24 * 3600 || seconds < 0) |
| 1112 |
this.handleRefresh(); |
| 1113 |
else if (always_load) |
| 1114 |
this.loadUpdates(); |
| 1115 |
} catch (exc) { |
| 1116 |
this.handleLoadError(exc); |
| 1117 |
} |
| 1118 |
} |
| 1119 |
|
| 1120 |
watchUpdates(transactionPath) { |
| 1121 |
this.setState({ state: "applying", applyTransaction: transactionPath, applyTransactionProps: {}, applyActions: [] }); |
| 1122 |
|
| 1123 |
return PK.watchTransaction(transactionPath, |
| 1124 |
{ |
| 1125 |
ErrorCode: (code, details) => this.setState(prevState => ({ errorMessages: [...prevState.errorMessages, details] })), |
| 1126 |
|
| 1127 |
Finished: exit => { |
| 1128 |
this.setState({ applyTransaction: null, applyTransactionProps: {}, applyActions: [] }); |
| 1129 |
|
| 1130 |
if (exit === PK.Enum.EXIT_SUCCESS) { |
| 1131 |
this.setState({ state: "loading", loadPercent: null }); |
| 1132 |
this.loadHistory().then(() => { |
| 1133 |
if (this.state.checkRestartAvailable) { |
| 1134 |
this.checkNeedsRestart() |
| 1135 |
.finally(() => this.setState({ state: "updateSuccess" })); |
| 1136 |
} else { |
| 1137 |
this.setState({ state: "updateSuccess", loadPercent: null }); |
| 1138 |
} |
| 1139 |
}); |
| 1140 |
} else if (exit === PK.Enum.EXIT_CANCELLED) { |
| 1141 |
if (this.state.checkRestartAvailable) { |
| 1142 |
this.setState({ state: "loading", loadPercent: null }); |
| 1143 |
this.checkNeedsRestart(); |
| 1144 |
} |
| 1145 |
this.loadUpdates(); |
| 1146 |
} else { |
| 1147 |
// normally we get FAILED here with ErrorCodes; handle unexpected errors to allow for some debugging |
| 1148 |
if (exit !== PK.Enum.EXIT_FAILED) |
| 1149 |
this.setState(prevState => ({ errorMessages: [...prevState.errorMessages, cockpit.format(_("PackageKit reported error code $0"), exit)] })); |
| 1150 |
this.setState({ state: "updateError" }); |
| 1151 |
} |
| 1152 |
}, |
| 1153 |
|
| 1154 |
// not working/being used in at least Fedora |
| 1155 |
RequireRestart: (type, packageId) => console.log("update RequireRestart", type, packageId), |
| 1156 |
|
| 1157 |
Package: (status, packageId) => this.setState(old => |
| 1158 |
({ applyActions: [...old.applyActions, { status, packageId }] }) |
| 1159 |
), |
| 1160 |
}, |
| 1161 |
|
| 1162 |
notify => this.setState(old => |
| 1163 |
({ applyTransactionProps: { ...old.applyTransactionProps, ...notify } }) |
| 1164 |
) |
| 1165 |
) |
| 1166 |
.catch(ex => { |
| 1167 |
this.setState(prevState => ({ errorMessages: [...prevState.errorMessages, ex], state: "updateError" })); |
| 1168 |
}); |
| 1169 |
} |
| 1170 |
|
| 1171 |
applyUpdates(type) { |
| 1172 |
let updates = [...this.state.updates]; |
| 1173 |
if (type === UPDATES.SECURITY) |
| 1174 |
updates = updates.filter(update => update.severity === Severity.CRITICAL); |
| 1175 |
if (type === UPDATES.KPATCHES) { |
| 1176 |
updates = updates.filter(update => isKpatchPackage(update.name)); |
| 1177 |
} |
| 1178 |
|
| 1179 |
PK.transaction() |
| 1180 |
.then(transactionPath => { |
| 1181 |
this.watchUpdates(transactionPath) |
| 1182 |
.then(() => { |
| 1183 |
PK.update_packages(updates, null, transactionPath) |
| 1184 |
.catch(ex => { |
| 1185 |
// We get more useful error messages through ErrorCode or "PackageKit has crashed", so only |
| 1186 |
// show this if we don't have anything else |
| 1187 |
this.setState(prevState => ({ |
| 1188 |
errorMessages: prevState.errorMessages.length === 0 ? [ex.message] : prevState.errorMessages, |
| 1189 |
state: "updateError", |
| 1190 |
})); |
| 1191 |
}); |
| 1192 |
}); |
| 1193 |
}) |
| 1194 |
.catch(ex => { |
| 1195 |
this.setState(prevState => ({ errorMessages: [...prevState.errorMessages, ex.message], state: "updateError" })); |
| 1196 |
}); |
| 1197 |
} |
| 1198 |
|
| 1199 |
renderContent() { |
| 1200 |
let applySecurity; |
| 1201 |
let applyKpatches; |
| 1202 |
let applyAll; |
| 1203 |
|
| 1204 |
/* On unregistered RHEL systems we need some heuristics: If the "main" OS repos (which provide coreutils) require |
| 1205 |
* a subscription, then point this out and don't show available updates, even if there are some auxiliary |
| 1206 |
* repositories enabled which don't require subscriptions. But there are a lot of cases (cloud repos, nightly internal |
| 1207 |
* repos) which don't need a subscription, there it would just be confusing */ |
| 1208 |
if (this.state.unregistered && this.state.haveOsRepo === false) { |
| 1209 |
page_status.set_own({ |
| 1210 |
type: "warning", |
| 1211 |
title: _("Not registered"), |
| 1212 |
details: { |
| 1213 |
link: "subscriptions", |
| 1214 |
} |
| 1215 |
}); |
| 1216 |
|
| 1217 |
return <EmptyStatePanel |
| 1218 |
title={_("This system is not registered")} |
| 1219 |
headingLevel="h5" |
| 1220 |
paragraph={ _("To get software updates, this system needs to be registered with Red Hat, either using the Red Hat Customer Portal or a local subscription server.") } |
| 1221 |
icon={ExclamationCircleIcon} |
| 1222 |
action={ _("Register…") } |
| 1223 |
onAction={ () => cockpit.jump("/subscriptions", cockpit.transport.host) } |
| 1224 |
/>; |
| 1225 |
} |
| 1226 |
|
| 1227 |
switch (this.state.state) { |
| 1228 |
case "loading": |
| 1229 |
case "refreshing": |
| 1230 |
case "locked": |
| 1231 |
page_status.set_own({ |
| 1232 |
type: null, |
| 1233 |
title: _("Checking for package updates..."), |
| 1234 |
details: { |
| 1235 |
link: false, |
| 1236 |
pficon: "spinner", |
| 1237 |
} |
| 1238 |
}); |
| 1239 |
|
| 1240 |
if (this.state.loadPercent) |
| 1241 |
return <Progress value={this.state.loadPercent} title={STATE_HEADINGS[this.state.state]} />; |
| 1242 |
else |
| 1243 |
return <EmptyStatePanel loading title={ _("Checking software status")} |
| 1244 |
headingLevel="h5" |
| 1245 |
paragraph={STATE_HEADINGS[this.state.state]} |
| 1246 |
/>; |
| 1247 |
|
| 1248 |
case "available": |
| 1249 |
{ |
| 1250 |
const num_updates = this.state.updates.length; |
| 1251 |
const num_security_updates = count_security_updates(this.state.updates); |
| 1252 |
const num_kpatches = count_kpatch_updates(this.state.updates); |
| 1253 |
const highest_severity = find_highest_severity(this.state.updates); |
| 1254 |
|
| 1255 |
applyAll = ( |
| 1256 |
<Button id={num_updates == num_security_updates ? "install-security" : "install-all"} variant="primary" onClick={ () => this.applyUpdates(UPDATES.ALL) }> |
| 1257 |
{ num_updates == num_security_updates |
| 1258 |
? _("Install security updates") |
| 1259 |
: _("Install all updates") } |
| 1260 |
</Button>); |
| 1261 |
|
| 1262 |
if (num_security_updates > 0 && num_updates > num_security_updates) { |
| 1263 |
applySecurity = ( |
| 1264 |
<Button id="install-security" variant="secondary" onClick={ () => this.applyUpdates(UPDATES.SECURITY) }> |
| 1265 |
{_("Install security updates")} |
| 1266 |
</Button>); |
| 1267 |
} |
| 1268 |
|
| 1269 |
if (num_kpatches > 0) { |
| 1270 |
applyKpatches = ( |
| 1271 |
<Button id="install-kpatches" variant="secondary" onClick={ () => this.applyUpdates(UPDATES.KPATCHES) }> |
| 1272 |
{_("Install kpatch updates")} |
| 1273 |
</Button>); |
| 1274 |
} |
| 1275 |
|
| 1276 |
let text; |
| 1277 |
if (highest_severity == Severity.CRITICAL) |
| 1278 |
text = _("Security updates available"); |
| 1279 |
else if (highest_severity >= Severity.IMPORTANT) |
| 1280 |
text = _("Bug fix updates available"); |
| 1281 |
else if (highest_severity >= Severity.LOW) |
| 1282 |
text = _("Enhancement updates available"); |
| 1283 |
else |
| 1284 |
text = _("Updates available"); |
| 1285 |
|
| 1286 |
page_status.set_own({ |
| 1287 |
type: num_security_updates > 0 ? "warning" : "info", |
| 1288 |
title: text, |
| 1289 |
details: { |
| 1290 |
pficon: getPageStatusSeverityIcon(highest_severity) |
| 1291 |
} |
| 1292 |
}); |
| 1293 |
|
| 1294 |
return ( |
| 1295 |
<> |
| 1296 |
<PageSection hasBodyWrapper={false}> |
| 1297 |
<Gallery className='ct-cards-grid' hasGutter> |
| 1298 |
<CardsPage handleRefresh={this.handleRefresh} |
| 1299 |
applySecurity={applySecurity} |
| 1300 |
applyAll={applyAll} |
| 1301 |
applyKpatches={applyKpatches} |
| 1302 |
highestSeverity={highest_severity} |
| 1303 |
onValueChanged={this.onValueChanged} |
| 1304 |
{...this.state} /> |
| 1305 |
</Gallery> |
| 1306 |
</PageSection> |
| 1307 |
{ this.state.showRestartServicesDialog && |
| 1308 |
<RestartServicesDialog |
| 1309 |
restartPackages={this.state.restartPackages} |
| 1310 |
close={() => this.setState({ showRestartServicesDialog: false })} |
| 1311 |
state={this.state.state} |
| 1312 |
checkNeedsRestart={this.checkNeedsRestart} |
| 1313 |
onValueChanged={delta => this.setState(delta)} |
| 1314 |
loadUpdates={this.loadUpdates} /> |
| 1315 |
} |
| 1316 |
{ this.state.showRebootSystemDialog && |
| 1317 |
<ShutdownModal onClose={() => this.setState({ showRebootSystemDialog: false })} /> |
| 1318 |
} |
| 1319 |
</> |
| 1320 |
); |
| 1321 |
} |
| 1322 |
|
| 1323 |
case "loadError": |
| 1324 |
case "updateError": |
| 1325 |
page_status.set_own({ |
| 1326 |
type: "error", |
| 1327 |
title: STATE_HEADINGS[this.state.state], |
| 1328 |
}); |
| 1329 |
return ( |
| 1330 |
<Stack> |
| 1331 |
<EmptyStatePanel title={ STATE_HEADINGS[this.state.state] } |
| 1332 |
icon={ ExclamationCircleIcon } |
| 1333 |
paragraph={ |
| 1334 |
<Content component={ContentVariants.p}> |
| 1335 |
{_("Please resolve the issue and reload this page.")} |
| 1336 |
</Content> |
| 1337 |
} |
| 1338 |
/> |
| 1339 |
<CodeBlock className='pf-v6-u-mx-auto error-log'> |
| 1340 |
<CodeBlockCode> |
| 1341 |
{this.state.errorMessages |
| 1342 |
.filter((m, index) => index == 0 || m != this.state.errorMessages[index - 1]) |
| 1343 |
.map(m => <span key={m}>{m}</span>)} |
| 1344 |
</CodeBlockCode> |
| 1345 |
</CodeBlock> |
| 1346 |
</Stack> |
| 1347 |
); |
| 1348 |
|
| 1349 |
case "applying": |
| 1350 |
page_status.set_own(null); |
| 1351 |
return <ApplyUpdates transactionProps={this.state.applyTransactionProps} |
| 1352 |
actions={this.state.applyActions} |
| 1353 |
onCancel={ () => PK.call(this.state.applyTransaction, PK.transactionInterface, "Cancel", []) } |
| 1354 |
rebootAfter={this.state.rebootAfterSuccess} |
| 1355 |
setRebootAfter={ (_event, enabled) => this.setState({ rebootAfterSuccess: enabled }) } |
| 1356 |
/>; |
| 1357 |
|
| 1358 |
case "updateSuccess": { |
| 1359 |
if (this.state.rebootAfterSuccess) { |
| 1360 |
this.setState({ state: "restart" }); |
| 1361 |
cockpit.spawn(["shutdown", "--reboot", "now"], { superuser: "require" }); |
| 1362 |
return null; |
| 1363 |
} |
| 1364 |
|
| 1365 |
let warningTitle; |
| 1366 |
if (!this.state.checkRestartAvailable) { |
| 1367 |
warningTitle = _("Reboot recommended"); |
| 1368 |
} else { |
| 1369 |
if (this.state.restartPackages.reboot.length > 0) |
| 1370 |
warningTitle = cockpit.ngettext("A package needs a system reboot for the updates to take effect:", |
| 1371 |
"Some packages need a system reboot for the updates to take effect:", |
| 1372 |
this.state.restartPackages.reboot.length); |
| 1373 |
else if (this.state.restartPackages.daemons.length > 0) |
| 1374 |
warningTitle = cockpit.ngettext("A service needs to be restarted for the updates to take effect:", |
| 1375 |
"Some services need to be restarted for the updates to take effect:", |
| 1376 |
this.state.restartPackages.daemons.length); |
| 1377 |
else if (this.state.restartPackages.manual.length > 0) |
| 1378 |
warningTitle = _("Some software needs to be restarted manually"); |
| 1379 |
} |
| 1380 |
|
| 1381 |
if (warningTitle) { |
| 1382 |
page_status.set_own({ |
| 1383 |
type: "warning", |
| 1384 |
title: warningTitle |
| 1385 |
}); |
| 1386 |
} |
| 1387 |
|
| 1388 |
return ( |
| 1389 |
<> |
| 1390 |
<UpdateSuccess onIgnore={this.loadUpdates} |
| 1391 |
openServiceRestartDialog={() => this.setState({ showRestartServicesDialog: true })} |
| 1392 |
openRebootDialog={() => this.setState({ showRebootSystemDialog: true })} |
| 1393 |
restart={this.state.restartPackages.daemons} |
| 1394 |
manual={this.state.restartPackages.manual} |
| 1395 |
reboot={this.state.restartPackages.reboot} |
| 1396 |
checkRestartAvailable={this.state.checkRestartAvailable} |
| 1397 |
history={this.state.history} /> |
| 1398 |
{ this.state.showRebootSystemDialog && |
| 1399 |
<ShutdownModal onClose={() => this.setState({ showRebootSystemDialog: false })} /> |
| 1400 |
} |
| 1401 |
{ this.state.showRestartServicesDialog && |
| 1402 |
<RestartServicesDialog restartPackages={this.state.restartPackages} |
| 1403 |
close={() => this.setState({ showRestartServicesDialog: false })} |
| 1404 |
state={this.state.state} |
| 1405 |
checkNeedsRestart={this.checkNeedsRestart} |
| 1406 |
onValueChanged={delta => this.setState(delta)} |
| 1407 |
loadUpdates={this.loadUpdates} /> |
| 1408 |
} |
| 1409 |
</> |
| 1410 |
); |
| 1411 |
} |
| 1412 |
|
| 1413 |
case "restart": |
| 1414 |
page_status.set_own(null); |
| 1415 |
return <EmptyStatePanel loading title={ _("Restarting") } |
| 1416 |
headingLevel="h5" |
| 1417 |
paragraph={ _("Your server will close the connection soon. You can reconnect after it has restarted.") } |
| 1418 |
/>; |
| 1419 |
|
| 1420 |
case "uptodate": |
| 1421 |
{ |
| 1422 |
page_status.set_own({ |
| 1423 |
title: STATE_HEADINGS[this.state.state], |
| 1424 |
details: { |
| 1425 |
link: false, |
| 1426 |
pficon: "check", |
| 1427 |
} |
| 1428 |
}); |
| 1429 |
|
| 1430 |
return ( |
| 1431 |
<PageSection hasBodyWrapper={false}> |
| 1432 |
<Gallery className='ct-cards-grid' hasGutter> |
| 1433 |
<CardsPage onValueChanged={this.onValueChanged} handleRefresh={this.handleRefresh} {...this.state} /> |
| 1434 |
</Gallery> |
| 1435 |
{ this.state.showRestartServicesDialog && |
| 1436 |
<RestartServicesDialog restartPackages={this.state.restartPackages} |
| 1437 |
close={() => this.setState({ showRestartServicesDialog: false })} |
| 1438 |
state={this.state.state} |
| 1439 |
checkNeedsRestart={this.checkNeedsRestart} |
| 1440 |
onValueChanged={delta => this.setState(delta)} |
| 1441 |
loadUpdates={this.loadUpdates} /> |
| 1442 |
} |
| 1443 |
{ this.state.showRebootSystemDialog && |
| 1444 |
<ShutdownModal onClose={() => this.setState({ showRebootSystemDialog: false })} /> |
| 1445 |
} |
| 1446 |
</PageSection> |
| 1447 |
); |
| 1448 |
} |
| 1449 |
|
| 1450 |
default: |
| 1451 |
page_status.set_own(null); |
| 1452 |
return null; |
| 1453 |
} |
| 1454 |
} |
| 1455 |
|
| 1456 |
handleRefresh() { |
| 1457 |
this.setState({ state: "refreshing", loadPercent: null }); |
| 1458 |
this.state.packageManager.refresh(true, data => this.setState({ loadPercent: data.percentage })) |
| 1459 |
.then(() => { |
| 1460 |
if (this._mounted === false) |
| 1461 |
return; |
| 1462 |
|
| 1463 |
this.setState({ timeSinceRefresh: 0 }); |
| 1464 |
this.loadUpdates(); |
| 1465 |
}) |
| 1466 |
.catch(this.handleLoadError); |
| 1467 |
} |
| 1468 |
|
| 1469 |
render() { |
| 1470 |
let content = this.renderContent(); |
| 1471 |
if (!["available", "uptodate"].includes(this.state.state)) |
| 1472 |
content = <PageSection hasBodyWrapper={false}>{content}</PageSection>; |
| 1473 |
|
| 1474 |
return ( |
| 1475 |
<WithDialogs> |
| 1476 |
<Page className="pf-m-no-sidebar"> |
| 1477 |
{content} |
| 1478 |
</Page> |
| 1479 |
</WithDialogs> |
| 1480 |
); |
| 1481 |
} |
| 1482 |
} |
| 1483 |
|
| 1484 |
document.addEventListener("DOMContentLoaded", async () => { |
| 1485 |
init(); |
| 1486 |
|
| 1487 |
try { |
| 1488 |
await cockpit.init(); |
| 1489 |
} catch (exp) { |
| 1490 |
/* Remove this when every beiboot scenario has Cockpit 336 */ |
| 1491 |
if (exp.problem === 'not-supported') { |
| 1492 |
const os_release = await read_os_release(); |
| 1493 |
cockpit.info.os_release = os_release; |
| 1494 |
} |
| 1495 |
} |
| 1496 |
|
| 1497 |
const root = createRoot(document.getElementById('app')); |
| 1498 |
root.render(<OsUpdates />); |
| 1499 |
}); |