changeset 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 4433f9d57f6d
children aee3eb10bbba
files ui/administratorwindow.cpp ui/administratorwindow.h ui/createcertlistdialog.cpp
diffstat 3 files changed, 68 insertions(+), 0 deletions(-) [+]
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 &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;
+}
--- 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;
 
--- 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();
 }

http://wald.intevation.org/projects/trustbridge/