• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

squinky86 / STIGQter / 5238656917

pending completion
5238656917

push

github

squinky86
prepping for 1.2.5 release

1 of 1 new or added line in 1 file covered. (100.0%)

3420 of 8337 relevant lines covered (41.02%)

6938.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/stigedit.cpp
1
/*
2
 * STIGQter - STIG fun with Qt
3
 *
4
 * Copyright © 2020–2023 Jon Hood, http://www.hoodsecurity.com/
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "stig.h"
21
#include "stigcheck.h"
22
#include "stigedit.h"
23
#include "supplement.h"
24

25
#include <iostream>
26

27
#include "ui_stigedit.h"
28

29
/**
30
 * @brief STIGEdit::STIGEdit
31
 * @param stig
32
 * @param parent
33
 *
34
 * Main Constructor
35
 */
36
STIGEdit::STIGEdit(STIG &stig, QWidget *parent) : TabViewWidget (parent),
×
37
    ui(new Ui::STIGEdit),
×
38
    _s(stig)
×
39
{
40
    ui->setupUi(this);
×
41

42
    ui->txtTitle->setText(_s.title);
×
43
    ui->txtDescription->setText(_s.description);
×
44
    ui->txtVersion->setText(QString::number(_s.version));
×
45
    QString tmpRelease = _s.release;
×
46
    if (tmpRelease.contains(QStringLiteral("Release: ")))
×
47
    {
48
        tmpRelease = tmpRelease.right(tmpRelease.size() - 9);
×
49
        if (tmpRelease.contains(QStringLiteral(" ")))
×
50
        {
51
            ui->txtRelease->setText(tmpRelease.left(tmpRelease.indexOf(QStringLiteral(" "))));
×
52
        }
53
    }
54
    if (tmpRelease.contains(QStringLiteral("Date: ")))
×
55
    {
56
        tmpRelease = tmpRelease.right(tmpRelease.size() - tmpRelease.indexOf(QStringLiteral("Date: ")) - 6);
×
57

58
        QDate d = QDate::fromString(tmpRelease, QStringLiteral("dd MMM yyyy"));
×
59
        ui->date->setDate(d);
×
60
    }
61

62
    UpdateChecks();
×
63
    UpdateSupplements();
×
64

65
    DbManager db;
×
66
    Q_FOREACH(auto cci, db.GetCCIs())
×
67
    {
68
        ui->cbCCIs->addItem(QString::number(cci.cci), QVariant::fromValue(cci));
×
69
    }
×
70
}
×
71

72
/**
73
 * @brief STIGEdit::DisableInput
74
 *
75
 * Disable all button input
76
 */
77
void STIGEdit::DisableInput()
×
78
{
79
    ui->btnSave->setEnabled(false);
×
80
    ui->txtTitle->setEnabled(false);
×
81
    ui->txtRelease->setEnabled(false);
×
82
    ui->txtVersion->setEnabled(false);
×
83
    ui->txtDescription->setEnabled(false);
×
84
}
×
85

86
/**
87
 * @brief STIGEdit::EnableInput
88
 *
89
 * Enable all button input
90
 */
91
void STIGEdit::EnableInput()
×
92
{
93
    ui->btnSave->setEnabled(true);
×
94
    ui->txtTitle->setEnabled(true);
×
95
    ui->txtRelease->setEnabled(true);
×
96
    ui->txtVersion->setEnabled(true);
×
97
    ui->txtDescription->setEnabled(true);
×
98
}
×
99

100
/**
101
 * @brief STIGEdit::GetTabType
102
 * @return Indication that this is a STIG editing tab
103
 */
104
TabType STIGEdit::GetTabType()
×
105
{
106
    return TabType::stig;
×
107
}
108

109
#ifdef USE_TESTS
110
/**
111
 * @brief STIGEdit::RunTests
112
 *
113
 * Run interface tests.
114
 */
115
void STIGEdit::RunTests()
×
116
{
117
    int onTest = 0;
×
118

119
    //select each of the STIGChecks
120
    std::cout << "\t\t\tTest " << onTest++ << ": Select STIGChecks" << std::endl;
×
121
    for (int i = 0; (i < ui->lstChecks->count()) && (i < 10); ++i)
×
122
    {
123
        ui->lstChecks->item(i)->setSelected(true);
×
124
        ProcEvents();
×
125

126
        //change something about STIGCheck
127
        std::cout << "\t\t\t\tTest " << onTest++ << ": Change STIGCheck" << std::endl;
×
128
        ui->txtFix->setText(QStringLiteral("FIX IT"));
×
129
        ProcEvents();
×
130

131
        //add CCI
132
        std::cout << "\t\t\t\tTest " << onTest++ << ": Add CCI" << std::endl;
×
133
        AddCCI();
×
134
        ProcEvents();
×
135
    }
136

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

142
    //close the tab
143
    Q_EMIT CloseTab(_tabIndex);
×
144
}
×
145
#endif
146

147
/**
148
 * @brief STIGEdit::UpdateChecks
149
 *
150
 * Update the list of STIGChecks
151
 */
152
void STIGEdit::UpdateChecks()
×
153
{
154
    ui->lstChecks->clear();
×
155
    Q_FOREACH(auto sc, _s.GetSTIGChecks())
×
156
    {
157
        auto *tmpItem = new QListWidgetItem(); //memory managed by ui->lstChecks container
×
158
        tmpItem->setData(Qt::UserRole, QVariant::fromValue<STIGCheck>(sc));
×
159
        tmpItem->setText(PrintSTIGCheck(sc));
×
160
        ui->lstChecks->addItem(tmpItem);
×
161
    }
×
162
}
×
163

164
/**
165
 * @brief STIGEdit::UpdateSupplements
166
 *
167
 * Update the list of STIG supplementary material
168
 */
169
void STIGEdit::UpdateSupplements()
×
170
{
171
    ui->lstSupplements->clear();
×
172
    Q_FOREACH(auto s, _s.GetSupplements())
×
173
    {
174
        auto *tmpItem = new QListWidgetItem(); //memory managed by ui->lstChecks container
×
175
        tmpItem->setData(Qt::UserRole, QVariant::fromValue<Supplement>(s));
×
176
        tmpItem->setText(PrintSupplement(s));
×
177
        ui->lstSupplements->addItem(tmpItem);
×
178
    }
×
179
}
×
180

181
/**
182
 * @brief STIGEdit::AddCCI
183
 *
184
 * Adds the selected CCI to the STIGCheck's mapping
185
 */
186
void STIGEdit::AddCCI()
×
187
{
188
    CCI toAdd = ui->cbCCIs->currentData().value<CCI>();
×
189
    for (int i = 0; i < ui->lstCCIs->count(); ++i)
×
190
    {
191
        QListWidgetItem *cciItem = ui->lstCCIs->item(i);
×
192
        if (cciItem)
×
193
        {
194
            CCI cci = cciItem->data(Qt::UserRole).value<CCI>();
×
195
            if (cci == toAdd)
×
196
                return;
×
197
        }
×
198
    }
199
    auto *tmpItem = new QListWidgetItem(); //memory managed by ui->lstCCIs container
×
200
    tmpItem->setData(Qt::UserRole, QVariant::fromValue<CCI>(toAdd));
×
201
    tmpItem->setText(PrintCCI(toAdd));
×
202
    ui->lstCCIs->addItem(tmpItem);
×
203
    QApplication::processEvents();
×
204
    UpdateCheck();
×
205
}
×
206

207
/**
208
 * @brief STIGEdit::SelectCheck
209
 *
210
 * A new STIGCheck has been selected
211
 */
212
void STIGEdit::SelectCheck()
×
213
{
214
    Q_FOREACH(QListWidgetItem *i, ui->lstChecks->selectedItems())
×
215
    {
216
        auto sc = i->data(Qt::UserRole).value<STIGCheck>();
×
217
        ui->txtCheckRule->setText(sc.rule);
×
218
        ui->txtCheckRuleVersion->setText(sc.ruleVersion);
×
219
        ui->txtCheckTitle->setText(sc.title);
×
220
        ui->txtDiscussion->setText(sc.vulnDiscussion);
×
221
        ui->txtFalsePositives->setText(sc.falsePositives);
×
222
        ui->txtFalseNegatives->setText(sc.falseNegatives);
×
223
        ui->txtFix->setText(sc.fix);
×
224
        ui->txtCheck->setText(sc.check);
×
225
        ui->lstCCIs->clear();
×
226
        Q_FOREACH(auto cci, sc.GetCCIs())
×
227
        {
228
            auto *tmpItem = new QListWidgetItem(); //memory managed by ui->lstCCIs container
×
229
            tmpItem->setData(Qt::UserRole, QVariant::fromValue<CCI>(cci));
×
230
            tmpItem->setText(PrintCCI(cci));
×
231
            ui->lstCCIs->addItem(tmpItem);
×
232
        }
×
233
    }
×
234
}
×
235

236
/**
237
 * @brief STIGEdit::UpdateSTIG
238
 *
239
 * Update the database with the new STIG values
240
 */
241
void STIGEdit::UpdateSTIG()
×
242
{
243
    DbManager db;
×
244
    _s.title = ui->txtTitle->text();
×
245
    _s.release = "Release: " + ui->txtRelease->text() + " Benchmark Date: " + ui->date->date().toString(QStringLiteral("dd MMM yyyy"));
×
246
    _s.version = ui->txtVersion->text().toInt();
×
247
    db.UpdateSTIG(_s);
×
248

249
    Q_EMIT RenameTab(_tabIndex, PrintSTIG(_s));
×
250

251
    if (_parent)
×
252
    {
253
        _parent->Display();
×
254
    }
255
}
×
256

257
/**
258
 * @brief STIGEdit::UpdateCheck
259
 *
260
 * Update the database with the new STIGCheck values
261
 */
262
void STIGEdit::UpdateCheck()
×
263
{
264
    DbManager db;
×
265
    Q_FOREACH(QListWidgetItem *i, ui->lstChecks->selectedItems())
×
266
    {
267
        auto sc = i->data(Qt::UserRole).value<STIGCheck>();
×
268
        sc.rule = ui->txtCheckRule->text();
×
269
        sc.ruleVersion = ui->txtCheckRuleVersion->text();
×
270
        sc.title = ui->txtCheckTitle->text();
×
271
        sc.vulnDiscussion = ui->txtDiscussion->toPlainText();
×
272
        sc.falsePositives = ui->txtFalsePositives->toPlainText();
×
273
        sc.falseNegatives = ui->txtFalseNegatives->toPlainText();
×
274
        sc.fix = ui->txtFix->toPlainText();
×
275
        sc.check = ui->txtCheck->toPlainText();
×
276

277
        sc.cciIds.clear();
×
278
        for (int j = 0; j < ui->lstCCIs->count(); ++j)
×
279
        {
280
            QListWidgetItem *tmpCCIItem = ui->lstCCIs->item(j);
×
281
            auto cci = tmpCCIItem->data(Qt::UserRole).value<CCI>();
×
282
            sc.cciIds.append(cci.id);
×
283
        }
×
284

285
        db.UpdateSTIGCheck(sc);
×
286
    }
×
287

288
    if (_parent)
×
289
        _parent->Display();
×
290
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc