Commit cc61d347 authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈 Committed by Nate Graham
Browse files

new module firmware security

uses html as output because the CLI output is most useful with color

uses a new tool called aha to convert the ansi output to html
parent 533f8e75
Pipeline #145117 passed with stage
in 1 minute and 44 seconds
......@@ -9,6 +9,7 @@ add_subdirectory(xserver)
add_subdirectory(egl)
add_subdirectory(glx)
add_subdirectory(pci)
add_subdirectory(firmware_security)
add_subdirectory( samba )
add_subdirectory( nics )
......
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
find_package(fwupdmgr)
set_package_properties(fwupdmgr PROPERTIES TYPE RUNTIME)
find_package(aha)
set_package_properties(aha PROPERTIES TYPE RUNTIME)
add_definitions(-DTRANSLATION_DOMAIN=\"kcm_firmware_security\")
add_library(kcm_firmware_security MODULE main.cpp)
target_link_libraries(kcm_firmware_security KF5::CoreAddons KF5::QuickAddons KF5::I18n KF5::Package KInfoCenterInternal)
install(TARGETS kcm_firmware_security DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/kcms/kinfocenter)
kpackage_install_package(package kcm_firmware_security kcms)
#!/bin/sh
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-FileCopyrightText: 2020-2022 Harald Sitter <sitter@kde.org>
$XGETTEXT `find . -name \*.cpp -o -name \*.h` -o $podir/kcm_firmware_security.pot
# Extract JavaScripty files as what they are, otherwise for example template literals won't work correctly (by default we extract as C++).
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
$XGETTEXT --join-existing --language=JavaScript `find . -name \*.qml -o -name \*.js` -o $podir/kcm_firmware_security.pot
{
"Categories": "Qt;KDE;X-KDE-information;",
"KPlugin": {
"Description": "Firmware Security Information",
"Icon": "preferences-security",
"Name": "Firmware Security"
},
"TryExec": "fwupdmgr",
"X-KDE-KInfoCenter-Category": "device_information",
"X-KDE-Keywords": "firmware,security,hsi,secureboot,fwupd,bootguard,lockdown"
}
SPDX-FileCopyrightText: None
SPDX-License-Identifier: CC0-1.0
/*
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
*/
#include <KAboutData>
#include <KLocalizedString>
#include <KPackage/PackageLoader>
#include <KPluginFactory>
#include <KQuickAddons/ConfigModule>
#include <CommandOutputContext.h>
class KCMFirmwareSecurity : public KQuickAddons::ConfigModule
{
Q_OBJECT
public:
explicit KCMFirmwareSecurity(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: ConfigModule(parent, data, args)
{
auto *about = new KAboutData(QStringLiteral("kcm_firmware_security"),
i18nc("@label kcm name", "Firmware Security"),
QStringLiteral("1.0"),
QString(),
KAboutLicense::GPL);
about->addAuthor(i18n("Harald Sitter"), QString(), QStringLiteral("sitter@kde.org"));
setAboutData(about);
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML"));
package.setDefaultPackageRoot(QStringLiteral("kpackage/kcms"));
package.setPath(about->componentName());
auto outputContext = new CommandOutputContext({QStringLiteral("fwupdmgr"), QStringLiteral("aha")},
QStringLiteral("/bin/sh"),
{package.path() + QStringLiteral("contents/code/fwupdmgr.sh")},
parent);
qmlRegisterSingletonInstance("org.kde.kinfocenter.firmware_security.private", 1, 0, "InfoOutputContext", outputContext);
}
};
K_PLUGIN_CLASS_WITH_JSON(KCMFirmwareSecurity, "kcm_firmware_security.json")
#include "main.moc"
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
set -e
# For sed testing please use --posix on GNU sed so you don't end up using gnu-isms.
fwupdmgr security --force | aha | sed -E 's@(https:[^[:space:]]+)@<a href="\1">\1</a>@g'
/*
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
*/
import QtQuick 2.5
import org.kde.kcm 1.4 as KCM
import org.kde.kinfocenter.private 1.0 as KInfoCenter
import org.kde.kinfocenter.firmware_security.private 1.0
KInfoCenter.CommandOutputKCM {
KCM.ConfigModule.quickHelp: i18nc("@info:whatsthis", "Firmware Security Information")
output: InfoOutputContext
textFormat: TextEdit.RichText
}
# This module defines the following variables:
#
# aha_FOUND - true if found
# aha_PATH - path to the bin (only when found)
#
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
include(ProgramFinder)
program_finder(aha)
# This module defines the following variables:
#
# fwupdmgr_FOUND - true if found
# fwupdmgr_PATH - path to the bin (only when found)
#
# SPDX-License-Identifier: BSD-2-Clause
# SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
include(ProgramFinder)
program_finder(fwupdmgr)
/*
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
*/
#include "CommandOutputContext.h"
......@@ -13,7 +13,7 @@
#include <KLocalizedString>
CommandOutputContext::CommandOutputContext(const QString &executable, const QStringList &arguments, QObject *parent)
CommandOutputContext::CommandOutputContext(const QStringList &findExecutables, const QString &executable, const QStringList &arguments, QObject *parent)
: QObject(parent)
, m_executableName(executable)
, m_executablePath(QStandardPaths::findExecutable(m_executableName))
......@@ -25,9 +25,19 @@ CommandOutputContext::CommandOutputContext(const QString &executable, const QStr
QStandardPaths::findExecutable(m_executableName, {QStringLiteral("/usr/local/sbin"), QStringLiteral("/usr/sbin"), QStringLiteral("/sbin")});
}
m_foundExecutablePaths[executable] = m_executablePath;
for (const QString &findExecutable : findExecutables) {
m_foundExecutablePaths[findExecutable] = QStandardPaths::findExecutable(findExecutable);
}
metaObject()->invokeMethod(this, &CommandOutputContext::load);
}
CommandOutputContext::CommandOutputContext(const QString &executable, const QStringList &arguments, QObject *parent)
: CommandOutputContext({/* executable is by default always searched for */}, executable, arguments, parent)
{
}
QString CommandOutputContext::executableName() const
{
return m_executableName;
......@@ -79,9 +89,11 @@ void CommandOutputContext::load()
{
reset();
if (m_executablePath.isEmpty()) {
setError(xi18nc("@info", "The executable <command>%1</command> could not be found in $PATH.", m_executableName));
return;
for (auto it = m_foundExecutablePaths.cbegin(); it != m_foundExecutablePaths.cend(); ++it) {
if (it.value().isEmpty()) {
setError(xi18nc("@info", "The executable <command>%1</command> could not be found in $PATH.", it.key()));
return;
}
}
auto proc = new QProcess(this);
......
/*
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
*/
#pragma once
#include <QMap>
#include <QObject>
// Somewhat general-purpose command executor. This class runs the executable with arguments, collecting all its output
......@@ -23,7 +24,8 @@ class CommandOutputContext : public QObject
// Potential error description. Empty when there is no error to report.
Q_PROPERTY(QString error MEMBER m_error NOTIFY errorChanged)
public:
explicit CommandOutputContext(const QString &executable, const QStringList &arguments, QObject *parent = nullptr);
CommandOutputContext(const QStringList &findExecutables, const QString &executable, const QStringList &arguments, QObject *parent = nullptr);
CommandOutputContext(const QString &executable, const QStringList &arguments, QObject *parent = nullptr);
QString executableName() const;
QStringList arguments() const;
......@@ -45,6 +47,7 @@ private:
const QString m_executableName;
QString m_executablePath;
QMap<QString, QString> m_foundExecutablePaths;
const QStringList m_arguments;
QStringList m_originalLines;
......
/*
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2021-2022 Harald Sitter <sitter@kde.org>
*/
import QtQuick 2.5
......@@ -25,6 +25,7 @@ KCM.SimpleKCM {
// The CommandOutputContext object.
required property QtObject output
property int wrapMode: TextEdit.NoWrap
property var textFormat: TextEdit.PlainText
Component {
id: dataComponent
......@@ -33,9 +34,12 @@ KCM.SimpleKCM {
text: output.text
font.family: "monospace"
wrapMode: root.wrapMode
textFormat: TextEdit.PlainText
textFormat: root.textFormat
onLinkActivated: Qt.openUrlExternally(link)
onLinkHovered: labelsMouseArea.cursorShape = link === "" ? undefined : Qt.PointingHandCursor
MouseArea {
id: labelsMouseArea
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: contextMenu.popup()
......@@ -99,7 +103,7 @@ KCM.SimpleKCM {
}
footer: QQC2.ToolBar {
visible: root.state !== "loading"
visible: root.state !== "loading" && root.textFormat === TextEdit.PlainText
Kirigami.SearchField {
id: filterField
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment