[PATCH] Log diff between initial certificate list and saved list to a logfile

Wald Commits scm-commit at wald.intevation.org
Thu May 22 15:30:48 CEST 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1400765399 -7200
# Node ID ccdc4c6b97ce868cbb3bbb7a3030cf522035ccbf
# Parent  4433f9d57f6dd7a9ff1250a247925f01bebbafc9
Log diff between initial certificate list and saved list to a logfile.

diff -r 4433f9d57f6d -r ccdc4c6b97ce ui/administratorwindow.cpp
--- 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 &currentCerts)
+{
+    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;
+}
diff -r 4433f9d57f6d -r ccdc4c6b97ce ui/administratorwindow.h
--- a/ui/administratorwindow.h	Thu May 22 13:23:07 2014 +0000
+++ b/ui/administratorwindow.h	Thu May 22 15:29:59 2014 +0200
@@ -44,6 +44,13 @@
      */
     QSettings* settings() {return &mSettings;}
 
+    /** @brief log the diff between the initial certificate list and the list
+     * saved as current.
+     *
+     * @param currentCerts  Path to the current certificate list file.
+     */
+    void logChanges(const QString &currentCerts);
+
 private slots:
     void createInstaller();
     void showAbout();
@@ -59,6 +66,7 @@
     void createContent();
     void loadCertificateTable();
     void addToCertificateTable(const QList<Certificate> &certs);
+    QByteArray createLogEntries(const CertificateList &list);
 
     QSettings mSettings;
 
diff -r 4433f9d57f6d -r ccdc4c6b97ce ui/createcertlistdialog.cpp
--- a/ui/createcertlistdialog.cpp	Thu May 22 13:23:07 2014 +0000
+++ b/ui/createcertlistdialog.cpp	Thu May 22 15:29:59 2014 +0200
@@ -273,5 +273,6 @@
     }
 
     QMessageBox::information(this, "", tr("Saved certificate list:\n%1").arg(fileName));
+    mAdminWindow->logChanges(curCerts);
     close();
 }


More information about the Trustbridge-commits mailing list