Mercurial > trustbridge
diff ui/administratorwindow.cpp @ 562:ccdc4c6b97ce
Log diff between initial certificate list and saved list to a logfile.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 22 May 2014 15:29:59 +0200 |
parents | d7ab9e734317 |
children | 9db7034b2d6c |
line wrap: on
line diff
--- a/ui/administratorwindow.cpp Thu May 22 13:23:07 2014 +0000 +++ b/ui/administratorwindow.cpp Thu May 22 15:29:59 2014 +0200 @@ -215,3 +215,62 @@ removeButton->setEnabled(true); } } + +void AdministratorWindow::logChanges(const QString ¤tCerts) +{ + QDir logDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); + QString logFilePath = logDir.filePath("log.txt"); + QFile logFile(logFilePath); + + if (!logFile.open(QIODevice::Append)) { + qDebug() << "Failed to open log file: " << logFilePath; + return; + } + + CertificateList newCertList; + newCertList.readList(currentCerts.toLocal8Bit()); + QByteArray entries = createLogEntries(newCertList); + if(logFile.write(entries) != entries.size()) { + qDebug() << "Failed to write log file: " << logFilePath; + return; + } + logFile.close(); +} + +QByteArray AdministratorWindow::createLogEntries(const CertificateList &list) +{ + QByteArray entries; + QByteArray removeListEntries; + + QDateTime currentDate = QDateTime::currentDateTime(); + QDateTime newListDate = list.date(); + QDateTime listDate = mCertList.date(); + + entries.append("##### " + + currentDate.toString("yyyy-MM-dd hh:mm") + + tr(" new certificatelist ") + + newListDate.toString(Qt::ISODate) + + tr(" based on list from ") + + listDate.toString(Qt::ISODate) + + "#####\r\n"); + entries.append(tr("signing certificate: \r\n")); + entries.append(tr("new certificates:\r\n")); + + foreach (const Certificate& cert, list.getCertificates()) { + if (!mCertList.getCertificates().contains(cert)) { + QString certEntry(cert.subjectCN() + ": " + cert.base64Line() + "\r\n"); + if (cert.isInstallCert()) { + entries.append(certEntry); + } + else { + removeListEntries.append(certEntry); + } + } + } + + entries.append(tr("certificates marked to remove:\r\n")); + entries.append(removeListEntries); + entries.append("\r\n"); + + return entries; +}