Skip to content
Permalink
Browse files

initial round of STIG editing basic functionality

  • Loading branch information
squinky86 committed Mar 17, 2020
1 parent 55a18cb commit 75d343294cf24c4d50f258db035310fcc444c86e
Showing with 271 additions and 3 deletions.
  1. +34 −0 src/dbmanager.cpp
  2. +1 −0 src/dbmanager.h
  3. +70 −1 src/stigedit.cpp
  4. +2 −0 src/stigedit.h
  5. +163 −1 src/stigedit.ui
  6. +1 −1 src/stigqter.h
@@ -2394,6 +2394,40 @@ bool DbManager::UpdateCKLCheck(const CKLCheck &check)
return ret;
}

/**
* @brief DbManager::UpdateSTIG
* @param stig
* @return @c True when the STIG is updated with the provided @a STIG.
* Otherwise, @c false.
*/
bool DbManager::UpdateSTIG(const STIG &stig)
{
STIG tmpSTIG = GetSTIG(stig);
bool ret = false;

if (tmpSTIG.id > 0)
{
QSqlDatabase db;
ret = true;
if (CheckDatabase(db))
{
QSqlQuery q(db);
q.prepare(QStringLiteral("UPDATE STIG SET title = :title, description = :description, release = :release, version = :version, benchmarkId = :benchmarkId, fileName = :fileName WHERE id = :id"));
q.bindValue(QStringLiteral(":title"), stig.title);
q.bindValue(QStringLiteral(":description"), stig.description);
q.bindValue(QStringLiteral(":release"), stig.release);
q.bindValue(QStringLiteral(":version"), stig.version);
q.bindValue(QStringLiteral(":benchmarkId"), stig.benchmarkId);
q.bindValue(QStringLiteral(":fileName"), stig.fileName);
q.bindValue(QStringLiteral(":id"), stig.id);
ret = q.exec();
Log(6, QStringLiteral("UpdateSTIG"), q);
}
}

return ret;
}

/**
* @brief DbManager::UpdateSTIGCheck
* @param check
@@ -115,6 +115,7 @@ class DbManager
bool UpdateAsset(const Asset &asset);
bool UpdateCCI(const CCI &cci);
bool UpdateCKLCheck(const CKLCheck &check);
bool UpdateSTIG(const STIG &stig);
bool UpdateSTIGCheck(const STIGCheck &check);
bool UpdateVariable(const QString &name, const QString &value);

@@ -22,6 +22,8 @@
#include "stigedit.h"
#include "supplement.h"

#include <iostream>

#include "ui_stigedit.h"

/**
@@ -112,13 +114,26 @@ TabType STIGEdit::GetTabType()
*/
void STIGEdit::RunTests()
{
int onTest = 0;

//select each of the STIGChecks
std::cout << "\t\t\tTest " << onTest++ << ": Select STIGChecks" << std::endl;
for (int i = 0; i < ui->lstChecks->count(); ++i)
{
ui->lstChecks->item(i)->setSelected(true);
ProcEvents();

//change something about STIG
std::cout << "\t\t\t\tTest " << onTest++ << ": Change STIGCheck" << std::endl;
ui->txtFix->setText(QStringLiteral("FIX IT"));
ProcEvents();
}

//change STIG name
std::cout << "\t\tTest " << onTest++ << ": Edit STIG" << std::endl;
ui->txtTitle->setText(ui->txtTitle->text() + " (edited)");
ProcEvents();

//close the tab
Q_EMIT CloseTab(_tabIndex);
}
@@ -179,7 +194,61 @@ void STIGEdit::SelectCheck()
ui->lstCCIs->clear();
Q_FOREACH(auto cci, sc.GetCCIs())
{
ui->lstCCIs->addItem(PrintCCI(cci));
auto *tmpItem = new QListWidgetItem(); //memory managed by ui->lstCCIs container
tmpItem->setData(Qt::UserRole, QVariant::fromValue<CCI>(cci));
tmpItem->setText(PrintCCI(cci));
ui->lstCCIs->addItem(tmpItem);
}
}
}

/**
* @brief STIGEdit::UpdateSTIG
*
* Update the database with the new STIG values
*/
void STIGEdit::UpdateSTIG()
{
DbManager db;
_s.title = ui->txtTitle->text();
_s.release = "Release: " + ui->txtRelease->text() + " Benchmark Date: " + ui->date->date().toString(QStringLiteral("dd MMM yyyy"));
_s.version = ui->txtVersion->text().toInt();
db.UpdateSTIG(_s);
if (_parent)
_parent->UpdateSTIGs();
}

/**
* @brief STIGEdit::UpdateCheck
*
* Update the database with the new STIGCheck values
*/
void STIGEdit::UpdateCheck()
{
DbManager db;
Q_FOREACH(QListWidgetItem *i, ui->lstChecks->selectedItems())
{
auto sc = i->data(Qt::UserRole).value<STIGCheck>();
sc.rule = ui->txtCheckRule->text();
sc.ruleVersion = ui->txtCheckRuleVersion->text();
sc.title = ui->txtCheckTitle->text();
sc.vulnDiscussion = ui->txtDiscussion->toPlainText();
sc.falsePositives = ui->txtFalsePositives->toPlainText();
sc.falseNegatives = ui->txtFalseNegatives->toPlainText();
sc.fix = ui->txtFix->toPlainText();
sc.check = ui->txtCheck->toPlainText();

sc.cciIds.clear();
for (int j = 0; j < ui->lstCCIs->count(); ++j)
{
QListWidgetItem *tmpCCIItem = ui->lstCCIs->item(j);
auto cci = tmpCCIItem->data(Qt::UserRole).value<CCI>();
sc.cciIds.append(cci.id);
}

db.UpdateSTIGCheck(sc);
}

if (_parent)
_parent->UpdateSTIGs();
}
@@ -52,6 +52,8 @@ class STIGEdit : public TabViewWidget

private Q_SLOTS:
void SelectCheck();
void UpdateSTIG();
void UpdateCheck();
};

#endif // STIGEDIT_H
@@ -205,7 +205,7 @@
<string>STIG Details</string>
</property>
<property name="currentIndex">
<number>5</number>
<number>0</number>
</property>
<widget class="QWidget" name="Discussion">
<property name="geometry">
@@ -570,8 +570,170 @@
</hint>
</hints>
</connection>
<connection>
<sender>txtTitle</sender>
<signal>editingFinished()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateSTIG()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtDescription</sender>
<signal>editingFinished()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateSTIG()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtVersion</sender>
<signal>editingFinished()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateSTIG()</slot>
<hints>
<hint type="sourcelabel">
<x>135</x>
<y>72</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtRelease</sender>
<signal>editingFinished()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateSTIG()</slot>
<hints>
<hint type="sourcelabel">
<x>347</x>
<y>72</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>date</sender>
<signal>userDateChanged(QDate)</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateSTIG()</slot>
<hints>
<hint type="sourcelabel">
<x>506</x>
<y>72</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtDiscussion</sender>
<signal>textChanged()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateCheck()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>299</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtFalseNegatives</sender>
<signal>textChanged()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateCheck()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>353</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtFalsePositives</sender>
<signal>textChanged()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateCheck()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>326</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtFix</sender>
<signal>textChanged()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateCheck()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>380</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtCheck</sender>
<signal>textChanged()</signal>
<receiver>STIGEdit</receiver>
<slot>UpdateCheck()</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>407</y>
</hint>
<hint type="destinationlabel">
<x>278</x>
<y>248</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>SelectCheck()</slot>
<slot>UpdateSTIG()</slot>
<slot>UpdateCheck()</slot>
</slots>
</ui>
@@ -41,6 +41,7 @@ class STIGQter : public QMainWindow
~STIGQter();
bool isProcessingEnabled();
QThread* ConnectThreads(Worker *worker);
void UpdateSTIGs();
#ifdef USE_TESTS
void ProcEvents();
void RunTests();
@@ -99,7 +100,6 @@ private Q_SLOTS:
void DisplayCCIs();
void DisplaySTIGs(const QString &search = QString());
void EnableInput();
void UpdateSTIGs();
bool _isFiltered;
};

0 comments on commit 75d3432

Please sign in to comment.
You can’t perform that action at this time.