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

feat: Command line export by condition #206

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
3 changes: 0 additions & 3 deletions application/cliapplicationhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,9 @@ bool CliApplicationHelper::setSingleInstance(const QString &key, CliApplicationH
if (!_d_singleServer->listen(socket_key)) {
qCWarning(dgAppHelper) << "listen failed:" << _d_singleServer->errorString();
return false;
} else {
qCDebug(dgAppHelper) << "===> listen <===" << _d_singleServer->serverName() << getpid();
}

if (new_server) {
qCDebug(dgAppHelper) << "===> new server <===" << _d_singleServer->serverName() << getpid();
QObject::connect(_d_singleServer, &QLocalServer::newConnection, qApp, [] {
QLocalSocket *instance = _d_singleServer->nextPendingConnection();
// 先发送数据告诉新的实例自己收到了它的请求
Expand Down
2 changes: 1 addition & 1 deletion application/dbusproxy/dldbushandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DLDBusHandler::DLDBusHandler(QObject *parent)
if (!m_dbus->isValid() && !m_dbus->lastError().message().isEmpty()) {
qCCritical(logDBusHandler) << "dbus com.deepin.logviewer isValid false error:" << m_dbus->lastError() << m_dbus->lastError().message();
}
qCInfo(logDBusHandler) << "dbus com.deepin.logviewer isValid true";
qCDebug(logDBusHandler) << "dbus com.deepin.logviewer isValid true";
}

/*!
Expand Down
17 changes: 3 additions & 14 deletions application/displaycontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,22 +1157,11 @@ void DisplayContent::insertJournalTable(QList<LOG_MSG_JOURNAL> logList, int star
*/
QString DisplayContent::getAppName(const QString &filePath)
{
QString ret;
if (filePath.isEmpty())
return ret;

QStringList strList = filePath.split("/");
if (strList.count() < 2) {
if (filePath.contains("."))
ret = filePath.section(".", 0, 0);
else {
ret = filePath;
}
return LogApplicationHelper::instance()->transName(ret);
}
QString ret = Utils::appName(filePath);
if (ret.isEmpty())
return ret;

QString desStr = filePath.section("/", -1);
ret = desStr.mid(0, desStr.lastIndexOf("."));
return LogApplicationHelper::instance()->transName(ret);
}

Expand Down
19 changes: 16 additions & 3 deletions application/journalwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,23 @@ void journalWork::doWork()
//获取进程名
r = sd_journal_get_data(j, "SYSLOG_IDENTIFIER", reinterpret_cast<const void **>(&d), &l);
if (r < 0) {
logMsg.daemonName = "unknown";
qCWarning(logJournal) << logMsg.daemonId << "error code" << r;
r = sd_journal_get_data(j, "_EXE", reinterpret_cast<const void **>(&d), &l);
if (r >= 0) {
QStringList strList = getReplaceColorStr(d).split("=");
strList.removeFirst();
QFileInfo fi(strList.first());
if (fi.exists())
logMsg.daemonName = fi.fileName();
else {
qCWarning(logJournal) << "unknown progressname, exe path: " << strList.first();
logMsg.daemonName = "unknown";
}
} else {
qCWarning(logJournal) << logMsg.daemonId << "error code" << r;
logMsg.daemonName = "unknown";
}
} else {
QStringList strList = getReplaceColorStr(d).split("=");
QStringList strList = getReplaceColorStr(d).split("=");
strList.removeFirst();
logMsg.daemonName = strList.join("=");
}
Expand Down
181 changes: 103 additions & 78 deletions application/logauththread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@
m_isStopProccess = true;
//停止获取线程执行,标记量置false
m_canRun = false;
//共享内存数据结构,用于和获取进程共享内存,数据为是否可执行进程,用于控制数据获取进程停止,因为这里会出现需要提权执行的进程,主进程没有权限停止提权进程,所以使用共享内存变量标记量控制提权进程停止
ShareMemoryInfo shareInfo ;
//设置进程为不可执行
shareInfo.isStart = false;
//把数据付给共享内存中对应的变量
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
if (!Utils::runInCmd) {
//共享内存数据结构,用于和获取进程共享内存,数据为是否可执行进程,用于控制数据获取进程停止,因为这里会出现需要提权执行的进程,主进程没有权限停止提权进程,所以使用共享内存变量标记量控制提权进程停止
ShareMemoryInfo shareInfo ;
//设置进程为不可执行
shareInfo.isStart = false;
//把数据付给共享内存中对应的变量
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
}
if (m_process) {
m_process->kill();
}
}
}

void LogAuthThread::setFilePath(const QStringList &filePath)
Expand Down Expand Up @@ -206,20 +208,24 @@
if (!m_canRun) {
return;
}
initProccess();
m_process->setProcessChannelMode(QProcess::MergedChannels);
//共享内存对应变量置true,允许进程内部逻辑运行
ShareMemoryInfo shareInfo;
shareInfo.isStart = true;
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
//启动日志需要提权获取,运行的时候把对应共享内存的名称传进去,方便获取进程拿标记量判断是否继续运行
m_process->start("pkexec", QStringList() << "logViewerAuth"
<< m_FilePath.at(i) << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
if (m_process->exitCode() != 0) {
emit bootFinished(m_threadCount);
return;

if (!Utils::runInCmd) {
initProccess();
m_process->setProcessChannelMode(QProcess::MergedChannels);
//共享内存对应变量置true,允许进程内部逻辑运行
ShareMemoryInfo shareInfo;
shareInfo.isStart = true;
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
//启动日志需要提权获取,运行的时候把对应共享内存的名称传进去,方便获取进程拿标记量判断是否继续运行
m_process->start("pkexec", QStringList() << "logViewerAuth"
<< m_FilePath.at(i) << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
if (m_process->exitCode() != 0) {
emit bootFinished(m_threadCount);
return;
}
}

QString byte = DLDBusHandler::instance(this)->readLog(m_FilePath.at(i));
byte.replace('\u0000', "").replace("\x01", "");
QStringList strList = byte.split('\n', QString::SkipEmptyParts);
Expand Down Expand Up @@ -284,27 +290,31 @@
if (!m_canRun) {
return;
}
initProccess();
if (!m_canRun) {
return;
}
m_process->setProcessChannelMode(QProcess::MergedChannels);
if (!m_canRun) {
return;
}
//共享内存对应变量置true,允许进程内部逻辑运行
ShareMemoryInfo shareInfo;
shareInfo.isStart = true;
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
//启动日志需要提权获取,运行的时候把对应共享内存的名称传进去,方便获取进程拿标记量判断是否继续运行
m_process->start("pkexec", QStringList() << "logViewerAuth"
<< m_FilePath.at(i) << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
//有错则传出空数据
if (m_process->exitCode() != 0) {
emit kernFinished(m_threadCount);
return;

if (!Utils::runInCmd) {
initProccess();
if (!m_canRun) {
return;
}
m_process->setProcessChannelMode(QProcess::MergedChannels);
if (!m_canRun) {

Check warning on line 300 in application/logauththread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition '!m_canRun' is always false
return;
}
//共享内存对应变量置true,允许进程内部逻辑运行
ShareMemoryInfo shareInfo;
shareInfo.isStart = true;
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
//启动日志需要提权获取,运行的时候把对应共享内存的名称传进去,方便获取进程拿标记量判断是否继续运行
m_process->start("pkexec", QStringList() << "logViewerAuth"
<< m_FilePath.at(i) << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
//有错则传出空数据
if (m_process->exitCode() != 0) {
emit kernFinished(m_threadCount);
return;
}
}

if (!m_canRun) {
return;
}
Expand Down Expand Up @@ -924,40 +934,43 @@
if (!m_canRun) {
return;
}
initProccess();
if (!m_canRun) {
return;
}
m_process->setProcessChannelMode(QProcess::MergedChannels);
if (!m_canRun) {
return;
}

if (DBusManager::isSEOepn()) {
if (DBusManager::isAuditAdmin()) {
// 是审计管理员,需要鉴权,有错则传出空数据
if (!Utils::checkAuthorization("com.deepin.pkexec.logViewerAuth.self", QCoreApplication::instance()->applicationPid())) {
emit auditFinished(m_threadCount);
return;
}
} else {
// 不是审计管理员,给出提示
emit auditFinished(m_threadCount, true);
if (!Utils::runInCmd) {
initProccess();
if (!m_canRun) {
return;
}
} else {
// 未开启等保四,鉴权逻辑同内核日志
ShareMemoryInfo shareInfo;
shareInfo.isStart = true;
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
//启动日志需要提权获取,运行的时候把对应共享内存的名称传进去,方便获取进程拿标记量判断是否继续运行
m_process->start("pkexec", QStringList() << "logViewerAuth"
<< m_FilePath.at(i) << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
if (m_process->exitCode() != 0) {
emit auditFinished(m_threadCount);
m_process->setProcessChannelMode(QProcess::MergedChannels);
if (!m_canRun) {

Check warning on line 944 in application/logauththread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition '!m_canRun' is always false
return;
}

if (DBusManager::isSEOepn()) {
if (DBusManager::isAuditAdmin()) {
// 是审计管理员,需要鉴权,有错则传出空数据
if (!Utils::checkAuthorization("com.deepin.pkexec.logViewerAuth.self", QCoreApplication::instance()->applicationPid())) {
emit auditFinished(m_threadCount);
return;
}
} else {
// 不是审计管理员,给出提示
emit auditFinished(m_threadCount, true);
return;
}
} else {
// 未开启等保四,鉴权逻辑同内核日志
ShareMemoryInfo shareInfo;
shareInfo.isStart = true;
SharedMemoryManager::instance()->setRunnableTag(shareInfo);
//启动日志需要提权获取,运行的时候把对应共享内存的名称传进去,方便获取进程拿标记量判断是否继续运行
m_process->start("pkexec", QStringList() << "logViewerAuth"
<< m_FilePath.at(i) << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
if (m_process->exitCode() != 0) {
emit auditFinished(m_threadCount);
return;
}
}
}

if (!m_canRun) {
Expand Down Expand Up @@ -1149,13 +1162,20 @@
}
QList<LOG_MSG_COREDUMP> coredumpList;

QString byte;
initProccess();
m_process->start("pkexec", QStringList() << "logViewerAuth" <<
QStringList() << "coredumpctl-list" << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
if (Utils::runInCmd) {
byte = DLDBusHandler::instance()->readLog("coredump");
byte = byte.replace('\u0000', "").replace("\x01", "");
} else {
m_process->start("pkexec", QStringList() << "logViewerAuth" <<
QStringList() << "coredumpctl-list" << SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
QByteArray outByte = m_process->readAllStandardOutput();
byte = Utils::replaceEmptyByteArray(outByte);
}

QByteArray outByte = m_process->readAllStandardOutput();
QStringList strList = QString(Utils::replaceEmptyByteArray(outByte)).split('\n', QString::SkipEmptyParts);
QStringList strList = QString(byte).split('\n', QString::SkipEmptyParts);

QRegExp re("(Storage: )\\S+");
for (int i = strList.size() - 1; i >= 0 ; --i) {
Expand Down Expand Up @@ -1194,11 +1214,16 @@
// 解析coredump文件保存位置
if (coredumpMsg.coreFile != "missing") {
// 若coreFile状态为missing,表示文件已丢失,不继续解析文件位置
m_process->start("pkexec", QStringList() << "logViewerAuth" << QStringList() << "coredumpctl-info"
<< coredumpMsg.pid <<SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
QByteArray outInfoByte = m_process->readAllStandardOutput();
QString outInfoByte;
if (Utils::runInCmd) {
outInfoByte = DLDBusHandler::instance()->readLog(QString("coredumpctl info %1").arg(coredumpMsg.pid));
} else {
m_process->start("pkexec", QStringList() << "logViewerAuth" << QStringList() << "coredumpctl-info"
<< coredumpMsg.pid <<SharedMemoryManager::instance()->getRunnableKey());
m_process->waitForFinished(-1);
outInfoByte = m_process->readAllStandardOutput();
}
re.indexIn(outInfoByte);

Check warning on line 1226 in application/logauththread.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Return value of function re.indexIn() is not used.
coredumpMsg.storagePath = re.cap(0).replace("Storage: ", "");
} else {
coredumpMsg.storagePath = QString("coredump file is missing");
Expand Down
Loading