comparison 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
comparison
equal deleted inserted replaced
561:4433f9d57f6d 562:ccdc4c6b97ce
213 } 213 }
214 else { 214 else {
215 removeButton->setEnabled(true); 215 removeButton->setEnabled(true);
216 } 216 }
217 } 217 }
218
219 void AdministratorWindow::logChanges(const QString &currentCerts)
220 {
221 QDir logDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
222 QString logFilePath = logDir.filePath("log.txt");
223 QFile logFile(logFilePath);
224
225 if (!logFile.open(QIODevice::Append)) {
226 qDebug() << "Failed to open log file: " << logFilePath;
227 return;
228 }
229
230 CertificateList newCertList;
231 newCertList.readList(currentCerts.toLocal8Bit());
232 QByteArray entries = createLogEntries(newCertList);
233 if(logFile.write(entries) != entries.size()) {
234 qDebug() << "Failed to write log file: " << logFilePath;
235 return;
236 }
237 logFile.close();
238 }
239
240 QByteArray AdministratorWindow::createLogEntries(const CertificateList &list)
241 {
242 QByteArray entries;
243 QByteArray removeListEntries;
244
245 QDateTime currentDate = QDateTime::currentDateTime();
246 QDateTime newListDate = list.date();
247 QDateTime listDate = mCertList.date();
248
249 entries.append("##### " +
250 currentDate.toString("yyyy-MM-dd hh:mm") +
251 tr(" new certificatelist ") +
252 newListDate.toString(Qt::ISODate) +
253 tr(" based on list from ") +
254 listDate.toString(Qt::ISODate) +
255 "#####\r\n");
256 entries.append(tr("signing certificate: \r\n"));
257 entries.append(tr("new certificates:\r\n"));
258
259 foreach (const Certificate& cert, list.getCertificates()) {
260 if (!mCertList.getCertificates().contains(cert)) {
261 QString certEntry(cert.subjectCN() + ": " + cert.base64Line() + "\r\n");
262 if (cert.isInstallCert()) {
263 entries.append(certEntry);
264 }
265 else {
266 removeListEntries.append(certEntry);
267 }
268 }
269 }
270
271 entries.append(tr("certificates marked to remove:\r\n"));
272 entries.append(removeListEntries);
273 entries.append("\r\n");
274
275 return entries;
276 }

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