Skip to content

Commit f43481f

Browse files
committed
feat: add secure boot and driver verification reporting
1 parent 2807d42 commit f43481f

2 files changed

Lines changed: 144 additions & 160 deletions

File tree

src/backend/nvidia/detector.cpp

Lines changed: 101 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,146 +2,132 @@
22
#include "system/commandrunner.h"
33

44
#include <QFile>
5-
#include <QTextStream>
65
#include <QRegularExpression>
6+
#include <QTextStream>
77

8-
NvidiaDetector::NvidiaDetector(QObject *parent)
9-
: QObject(parent)
10-
{}
8+
NvidiaDetector::NvidiaDetector(QObject *parent) : QObject(parent) {}
119

12-
NvidiaDetector::GpuInfo NvidiaDetector::detect() const
13-
{
14-
GpuInfo info;
10+
NvidiaDetector::GpuInfo NvidiaDetector::detect() const {
11+
GpuInfo info;
1512

16-
info.name = detectGpuName();
17-
info.found = !info.name.isEmpty();
18-
info.driverVersion = detectDriverVersion();
19-
info.driverLoaded = isModuleLoaded(QStringLiteral("nvidia"));
20-
info.nouveauActive = isModuleLoaded(QStringLiteral("nouveau"));
21-
info.secureBootEnabled = detectSecureBoot();
13+
info.name = detectGpuName();
14+
info.found = !info.name.isEmpty();
15+
info.driverVersion = detectDriverVersion();
16+
info.driverLoaded = isModuleLoaded(QStringLiteral("nvidia"));
17+
info.nouveauActive = isModuleLoaded(QStringLiteral("nouveau"));
18+
info.secureBootEnabled = detectSecureBoot();
2219

23-
return info;
20+
return info;
2421
}
2522

26-
bool NvidiaDetector::hasNvidiaGpu() const
27-
{
28-
return !detectGpuName().isEmpty();
23+
bool NvidiaDetector::hasNvidiaGpu() const { return !detectGpuName().isEmpty(); }
24+
25+
bool NvidiaDetector::isDriverInstalled() const {
26+
return !detectDriverVersion().isEmpty();
2927
}
3028

31-
bool NvidiaDetector::isDriverInstalled() const
32-
{
33-
return !detectDriverVersion().isEmpty();
29+
QString NvidiaDetector::installedDriverVersion() const {
30+
return detectDriverVersion();
3431
}
3532

36-
QString NvidiaDetector::installedDriverVersion() const
37-
{
38-
return detectDriverVersion();
33+
QString NvidiaDetector::verificationReport() const {
34+
const QString gpuText = m_info.found ? m_info.name : QStringLiteral("Yok");
35+
const QString driverText =
36+
m_info.driverVersion.isEmpty() ? QStringLiteral("Yok") : m_info.driverVersion;
37+
const QString secureBootText = m_info.secureBootEnabled ? QStringLiteral("Acik")
38+
: QStringLiteral("Kapali/Bilinmiyor");
39+
40+
return QStringLiteral("GPU: %1\nSurucu Versiyonu: %2\nSecure Boot: %3\nNVIDIA Modulu: %4\nNouveau: %5")
41+
.arg(gpuText, driverText, secureBootText,
42+
m_info.driverLoaded ? QStringLiteral("Yuklu") : QStringLiteral("Yuklu degil"),
43+
m_info.nouveauActive ? QStringLiteral("Aktif") : QStringLiteral("Aktif degil"));
3944
}
4045

41-
QString NvidiaDetector::detectGpuName() const
42-
{
43-
CommandRunner runner;
44-
45-
// lspci ile PCI cihazlarını listele, NVIDIA olanı filtrele
46-
const auto result = runner.run(
47-
QStringLiteral("lspci"),
48-
{ QStringLiteral("-mm") }
49-
);
50-
51-
if (!result.success())
52-
return {};
53-
54-
// lspci -mm çıktısında NVIDIA GPU satırını ara
55-
const QStringList lines = result.stdout.split(QLatin1Char('\n'));
56-
for (const QString &line : lines) {
57-
if (line.contains(QStringLiteral("NVIDIA"), Qt::CaseInsensitive) &&
58-
line.contains(QStringLiteral("VGA"), Qt::CaseInsensitive))
59-
{
60-
// Tırnak işaretleri arasındaki model adını çıkar
61-
static const QRegularExpression re(QStringLiteral("\"([^\"]+)\""));
62-
auto it = re.globalMatch(line);
63-
QStringList parts;
64-
while (it.hasNext())
65-
parts << it.next().captured(1);
66-
67-
if (parts.size() >= 3)
68-
return parts[2]; // Model adı 3. tırnak grubunda
69-
}
70-
}
46+
QString NvidiaDetector::detectGpuName() const {
47+
CommandRunner runner;
48+
49+
// lspci ile PCI cihazlarını listele, NVIDIA olanı filtrele
50+
const auto result =
51+
runner.run(QStringLiteral("lspci"), {QStringLiteral("-mm")});
7152

53+
if (!result.success())
7254
return {};
73-
}
7455

75-
QString NvidiaDetector::detectDriverVersion() const
76-
{
77-
CommandRunner runner;
78-
79-
// nvidia-smi varsa sürücü versiyonunu döner
80-
const auto result = runner.run(
81-
QStringLiteral("nvidia-smi"),
82-
{ QStringLiteral("--query-gpu=driver_version"),
83-
QStringLiteral("--format=csv,noheader") }
84-
);
85-
86-
if (result.success())
87-
return result.stdout.trimmed();
88-
89-
// nvidia-smi yoksa modinfo'dan dene
90-
const auto modinfo = runner.run(
91-
QStringLiteral("modinfo"),
92-
{ QStringLiteral("nvidia") }
93-
);
94-
95-
if (modinfo.success()) {
96-
static const QRegularExpression re(QStringLiteral("^version:\\s+(.+)$"),
97-
QRegularExpression::MultilineOption);
98-
const auto match = re.match(modinfo.stdout);
99-
if (match.hasMatch())
100-
return match.captured(1).trimmed();
56+
// lspci -mm çıktısında NVIDIA GPU satırını ara
57+
const QStringList lines = result.stdout.split(QLatin1Char('\n'));
58+
for (const QString &line : lines) {
59+
if (line.contains(QStringLiteral("NVIDIA"), Qt::CaseInsensitive) &&
60+
line.contains(QStringLiteral("VGA"), Qt::CaseInsensitive)) {
61+
// Tırnak işaretleri arasındaki model adını çıkar
62+
static const QRegularExpression re(QStringLiteral("\"([^\"]+)\""));
63+
auto it = re.globalMatch(line);
64+
QStringList parts;
65+
while (it.hasNext())
66+
parts << it.next().captured(1);
67+
68+
if (parts.size() >= 3)
69+
return parts[2]; // Model adı 3. tırnak grubunda
10170
}
71+
}
10272

103-
return {};
73+
return {};
10474
}
10575

106-
bool NvidiaDetector::isModuleLoaded(const QString &moduleName) const
107-
{
108-
// /proc/modules dosyasını oku — yüklü kernel modüllerini listeler
109-
QFile modules(QStringLiteral("/proc/modules"));
110-
if (!modules.open(QIODevice::ReadOnly | QIODevice::Text))
111-
return false;
112-
113-
QTextStream stream(&modules);
114-
while (!stream.atEnd()) {
115-
const QString line = stream.readLine();
116-
if (line.startsWith(moduleName + QLatin1Char(' ')))
117-
return true;
118-
}
76+
QString NvidiaDetector::detectDriverVersion() const {
77+
CommandRunner runner;
78+
79+
// nvidia-smi varsa sürücü versiyonunu döner
80+
const auto result = runner.run(QStringLiteral("nvidia-smi"),
81+
{QStringLiteral("--query-gpu=driver_version"),
82+
QStringLiteral("--format=csv,noheader")});
83+
84+
if (result.success())
85+
return result.stdout.trimmed();
11986

87+
// nvidia-smi yoksa modinfo'dan dene
88+
const auto modinfo =
89+
runner.run(QStringLiteral("modinfo"), {QStringLiteral("nvidia")});
90+
91+
if (modinfo.success()) {
92+
static const QRegularExpression re(QStringLiteral("^version:\\s+(.+)$"),
93+
QRegularExpression::MultilineOption);
94+
const auto match = re.match(modinfo.stdout);
95+
if (match.hasMatch())
96+
return match.captured(1).trimmed();
97+
}
98+
99+
return {};
100+
}
101+
102+
bool NvidiaDetector::isModuleLoaded(const QString &moduleName) const {
103+
// /proc/modules dosyasını oku — yüklü kernel modüllerini listeler
104+
QFile modules(QStringLiteral("/proc/modules"));
105+
if (!modules.open(QIODevice::ReadOnly | QIODevice::Text))
120106
return false;
107+
108+
QTextStream stream(&modules);
109+
while (!stream.atEnd()) {
110+
const QString line = stream.readLine();
111+
if (line.startsWith(moduleName + QLatin1Char(' ')))
112+
return true;
113+
}
114+
115+
return false;
121116
}
122117

123-
bool NvidiaDetector::detectSecureBoot() const
124-
{
125-
// mokutil --sb-state: Secure Boot durumunu raporlar
126-
// "SecureBoot enabled" veya "SecureBoot disabled" döner
127-
CommandRunner runner;
128-
const auto result = runner.run(
129-
QStringLiteral("mokutil"),
130-
{ QStringLiteral("--sb-state") }
131-
);
132-
133-
if (result.success() || result.exitCode == 1) {
134-
// mokutil çıktısı "enabled" içeriyorsa Secure Boot açık
135-
return result.stdout.contains(QStringLiteral("enabled"),
136-
Qt::CaseInsensitive);
137-
}
118+
bool NvidiaDetector::detectSecureBoot() const {
119+
CommandRunner runner;
120+
const auto result =
121+
runner.run(QStringLiteral("mokutil"), {QStringLiteral("--sb-state")});
138122

139-
// mokutil yoksa durum bilinmez — kullanıcıyı uyarmayız
140-
return false;
123+
if (result.success() || result.exitCode == 1) {
124+
return result.stdout.contains(QStringLiteral("enabled"), Qt::CaseInsensitive);
125+
}
126+
127+
return false;
141128
}
142129

143-
void NvidiaDetector::refresh()
144-
{
145-
m_info = detect();
146-
emit infoChanged();
130+
void NvidiaDetector::refresh() {
131+
m_info = detect();
132+
emit infoChanged();
147133
}

src/backend/nvidia/detector.h

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,63 @@
55

66
// NvidiaDetector: Sistemdeki NVIDIA GPU ve sürücü durumunu tespit eder.
77
// Hiçbir kurulum yapmaz — sadece okur ve raporlar.
8-
class NvidiaDetector : public QObject
9-
{
10-
Q_OBJECT
8+
class NvidiaDetector : public QObject {
9+
Q_OBJECT
1110

12-
Q_PROPERTY(bool gpuFound READ gpuFound NOTIFY infoChanged)
13-
Q_PROPERTY(QString gpuName READ gpuName NOTIFY infoChanged)
14-
Q_PROPERTY(QString driverVersion READ driverVersion NOTIFY infoChanged)
15-
Q_PROPERTY(bool driverLoaded READ driverLoaded NOTIFY infoChanged)
16-
Q_PROPERTY(bool nouveauActive READ nouveauActive NOTIFY infoChanged)
17-
Q_PROPERTY(bool secureBootEnabled READ secureBootEnabled NOTIFY infoChanged)
11+
Q_PROPERTY(bool gpuFound READ gpuFound NOTIFY infoChanged)
12+
Q_PROPERTY(QString gpuName READ gpuName NOTIFY infoChanged)
13+
Q_PROPERTY(QString driverVersion READ driverVersion NOTIFY infoChanged)
14+
Q_PROPERTY(bool driverLoaded READ driverLoaded NOTIFY infoChanged)
15+
Q_PROPERTY(bool nouveauActive READ nouveauActive NOTIFY infoChanged)
16+
Q_PROPERTY(bool secureBootEnabled READ secureBootEnabled NOTIFY infoChanged)
17+
Q_PROPERTY(QString verificationReport READ verificationReport NOTIFY infoChanged)
1818

1919
public:
20-
struct GpuInfo {
21-
bool found = false; // NVIDIA GPU var mı?
22-
QString name; // GPU adı (ör: "NVIDIA GeForce RTX 3060")
23-
QString driverVersion; // Kurulu sürücü versiyonu (ör: "535.154.05")
24-
QString vbiosVersion; // VBIOS versiyonu
25-
bool driverLoaded = false; // nvidia.ko kernel modülü yüklü mü?
26-
bool nouveauActive = false; // Nouveau (açık kaynak) sürücü aktif mi?
27-
bool secureBootEnabled = false; // UEFI Secure Boot açık mı?
28-
};
20+
struct GpuInfo {
21+
bool found = false; // NVIDIA GPU var mı?
22+
QString name; // GPU adı (ör: "NVIDIA GeForce RTX 3060")
23+
QString driverVersion; // Kurulu sürücü versiyonu (ör: "535.154.05")
24+
QString vbiosVersion; // VBIOS versiyonu
25+
bool driverLoaded = false; // nvidia.ko kernel modülü yüklü mü?
26+
bool nouveauActive = false; // Nouveau (açık kaynak) sürücü aktif mi?
27+
bool secureBootEnabled = false; // UEFI Secure Boot açık mı?
28+
};
2929

30-
explicit NvidiaDetector(QObject *parent = nullptr);
30+
explicit NvidiaDetector(QObject *parent = nullptr);
3131

32-
// QML property getters
33-
bool gpuFound() const { return m_info.found; }
34-
QString gpuName() const { return m_info.name; }
35-
QString driverVersion() const { return m_info.driverVersion; }
36-
bool driverLoaded() const { return m_info.driverLoaded; }
37-
bool nouveauActive() const { return m_info.nouveauActive; }
38-
bool secureBootEnabled() const { return m_info.secureBootEnabled; }
32+
bool gpuFound() const { return m_info.found; }
33+
QString gpuName() const { return m_info.name; }
34+
QString driverVersion() const { return m_info.driverVersion; }
35+
bool driverLoaded() const { return m_info.driverLoaded; }
36+
bool nouveauActive() const { return m_info.nouveauActive; }
37+
bool secureBootEnabled() const { return m_info.secureBootEnabled; }
38+
QString verificationReport() const;
3939

40-
// GPU bilgisini yeniden tara — QML'den çağrılabilir
41-
Q_INVOKABLE void refresh();
40+
Q_INVOKABLE void refresh();
4241

43-
// Tüm GPU bilgisini toplar ve döner
44-
GpuInfo detect() const;
42+
// Tüm GPU bilgisini toplar ve döner
43+
GpuInfo detect() const;
4544

46-
// Hızlı kontroller
47-
bool hasNvidiaGpu() const;
48-
bool isDriverInstalled() const;
49-
QString installedDriverVersion() const;
45+
// Hızlı kontroller
46+
bool hasNvidiaGpu() const;
47+
bool isDriverInstalled() const;
48+
QString installedDriverVersion() const;
5049

5150
signals:
52-
void infoChanged();
51+
void infoChanged();
5352

5453
private:
55-
// lspci çıktısından GPU adını çıkar
56-
QString detectGpuName() const;
54+
// lspci çıktısından GPU adını çıkar
55+
QString detectGpuName() const;
5756

58-
// nvidia-smi'den sürücü versiyonunu çıkar
59-
QString detectDriverVersion() const;
57+
// nvidia-smi'den sürücü versiyonunu çıkar
58+
QString detectDriverVersion() const;
6059

61-
// /proc/modules'dan modül durumunu kontrol et
62-
bool isModuleLoaded(const QString &moduleName) const;
60+
// /proc/modules'dan modül durumunu kontrol et
61+
bool isModuleLoaded(const QString &moduleName) const;
6362

64-
// mokutil ile Secure Boot durumunu kontrol et
65-
bool detectSecureBoot() const;
63+
// mokutil ile Secure Boot durumunu kontrol et
64+
bool detectSecureBoot() const;
6665

67-
GpuInfo m_info;
66+
GpuInfo m_info;
6867
};
69-

0 commit comments

Comments
 (0)