Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix cli export kwin log failed problem #211

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 68 additions & 11 deletions application/dbusmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QDBusReply>
#include <QDebug>
#include <QLoggingCategory>
#include <QProcess>

#ifdef QT_DEBUG
Q_LOGGING_CATEGORY(logDBusManager, "org.deepin.log.viewer.dbus.manager")
Expand Down Expand Up @@ -55,6 +56,58 @@ QString DBusManager::getSystemInfo()
return isklusystemName;
}

//根据命令行 dmidecode -s system-product-name|awk '{print SNF}' 返回的结果判断是否是华为电脑
bool DBusManager::isHuaWei()
{
QStringList options;
options << QString(QStringLiteral("-c"));
options << QString(QStringLiteral("dmidecode -s system-product-name|awk '{print $NF}'"));
QProcess process;
process.start(QString(QStringLiteral("bash")), options);
process.waitForFinished();
process.waitForReadyRead();
QByteArray tempArray = process.readAllStandardOutput();
char *charTemp = tempArray.data();
QString str_output = QString(QLatin1String(charTemp));
process.close();
//qInfo() << "system-product-name: " << str_output;
options.clear();
options << QString(QStringLiteral("-c"));
options << QString(QStringLiteral("dmidecode | grep -i \"String 4\""));
process.start(QString(QStringLiteral("bash")), options);
process.waitForFinished();
process.waitForReadyRead();
QString str_output1 = QString(QLatin1String(process.readAllStandardOutput().data()));
//qInfo() << "dmidecode | grep -i \"String 4\": " << str_output1;
if (str_output.contains("KLVV", Qt::CaseInsensitive) ||
str_output.contains("KLVU", Qt::CaseInsensitive) ||
str_output.contains("PGUV", Qt::CaseInsensitive) ||
str_output.contains("PGUW", Qt::CaseInsensitive) ||
str_output1.contains("PWC30", Qt::CaseInsensitive) ||
str_output.contains("L540", Qt::CaseInsensitive) ||
str_output.contains("W585", Qt::CaseInsensitive) ||
isPangu())
return true;
return false;
}

bool DBusManager::isPangu()
{
QDBusInterface systemInfoInterface("com.deepin.daemon.SystemInfo",
"/com/deepin/daemon/SystemInfo",
"org.freedesktop.DBus.Properties",
QDBusConnection::sessionBus());
QDBusMessage replyCpu = systemInfoInterface.call("Get", "com.deepin.daemon.SystemInfo", "CPUHardware");
QList<QVariant> outArgsCPU = replyCpu.arguments();
if (outArgsCPU.count()) {
QString CPUHardware = outArgsCPU.at(0).value<QDBusVariant>().variant().toString();
if (CPUHardware.contains("PANGU")) {
return true;
}
}
return false;
}

bool DBusManager::isSEOepn()
{
bool bIsSEOpen = false;
Expand Down Expand Up @@ -100,24 +153,28 @@ bool DBusManager::isAuditAdmin()
}

bool DBusManager::isSpecialComType(){
qCDebug(logDBusManager) << "Utils::specialComType:" << Utils::specialComType;
bool isSpecialComType = false;
//机器类型未知时,走以前判读机器的类型,有可能是通过DConfig获取失败,导致机器类型未知
if(Utils::specialComType != -1){
isSpecialComType = Utils::specialComType ? true:false;
}else{
QString systemName = getSystemInfo();
qCDebug(logDBusManager) << "systemName:" << systemName;
if (systemName == "klu" ||
systemName == "panguV" ||
systemName == "W515 PGUV-WBY0" ||
systemName == "pangu" ||
systemName.toUpper().contains("PGUV") ||
systemName.toUpper().contains("PANGUV") ||
systemName.toUpper().contains("KLU") ||
systemName.toUpper().contains("PANGU")) {
isSpecialComType = true;
if (!systemName.isEmpty()) {
if (systemName == "klu" ||
systemName == "panguV" ||
systemName == "W515 PGUV-WBY0" ||
systemName == "pangu" ||
systemName.toUpper().contains("PGUV") ||
systemName.toUpper().contains("PANGUV") ||
systemName.toUpper().contains("KLU") ||
systemName.toUpper().contains("PANGU")) {
isSpecialComType = true;
}
}

// 上一dbus服务可能在新版本已失效,使用dmidecode命令再判断一次
if (!isSpecialComType)
isSpecialComType = isHuaWei();
}
return isSpecialComType;
}
3 changes: 2 additions & 1 deletion application/dbusmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class DBusManager : public QObject
public:
explicit DBusManager(QObject *parent = nullptr);
static QString getSystemInfo();
static bool isHuaWei();
static bool isPangu();
// 是否开启等保四
static bool isSEOepn();
// 开启等保四情况下,判断是否为审计管理员身份
Expand All @@ -27,7 +29,6 @@ class DBusManager : public QObject
static bool isSpecialComType();
static bool isGetedKlu ;
static QString isklusystemName ;

signals:

public slots:
Expand Down
4 changes: 4 additions & 0 deletions application/displaycontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,10 @@ void DisplayContent::slot_BtnSelected(int btnId, int lId, QModelIndex idx)
generateDnfFile(BUTTONID(m_curBtnId), m_curDnfLevel);
} else if (treeData.contains(DMESG_TREE_DATA, Qt::CaseInsensitive)) {
generateDmesgFile(BUTTONID(m_curBtnId), PRIORITY(m_curLevel));
} else if (treeData.contains(KWIN_TREE_DATA, Qt::CaseInsensitive)) {
KWIN_FILTERS filter;
filter.msg = "";
generateKwinFile(filter);
} else if (treeData.contains(AUDIT_TREE_DATA, Qt::CaseInsensitive)) {
generateAuditFile(BUTTONID(m_curBtnId), AUDITTYPE(m_curLevel));
} else if(treeData.contains(COREDUMP_TREE_DATA, Qt::CaseInsensitive)) {
Expand Down
2 changes: 1 addition & 1 deletion application/logbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ BUTTONID LogBackend::period2Enum(const QString &period)
BUTTONID id = INVALID;
if (period == "all")
id = ALL;
else if (period == "today" || period == "1d")
else if (period == "today")
id = ONE_DAY;
else if (period == "3d")
id = THREE_DAYS;
Expand Down
8 changes: 7 additions & 1 deletion application/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ int main(int argc, char *argv[])
else
bRet = LogBackend::instance(&a)->exportTypeLogsByCondition(outDir, type, period, event, keyword);
} else if (TYPE_XORG == type || TYPE_OTHER == type || TYPE_CUSTOM == type || TYPE_KWIN == type) {
// Xorg、其他、自定义日志 不能按条件导出
// Xorg、Kwin 只能按关键字导出
if (!period.isEmpty() || !level.isEmpty() || !status.isEmpty() || !event.isEmpty())
qCWarning(logAppMain) << QString("Export logs by %1, can only be filtered using 'keyword' parameters.").arg(type);
else
bRet = LogBackend::instance(&a)->exportTypeLogsByCondition(outDir, type, period, event, keyword);
} else if (TYPE_OTHER == type || TYPE_CUSTOM == type) {
// 其他、自定义日志 不能按条件导出
if (!period.isEmpty() || !level.isEmpty() || !status.isEmpty() || !event.isEmpty())
qCWarning(logAppMain) << QString("Export logs by %1, cannot be filtered by any parameters.").arg(type);
} else {
Expand Down