Skip to content

Commit

Permalink
new Welcome Page and firstrunWizard (#235)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Rizzitello <crizzitello@ics.com>
  • Loading branch information
crizzitello and Chris Rizzitello committed Nov 14, 2023
1 parent 3e1ba34 commit 26fb82e
Show file tree
Hide file tree
Showing 34 changed files with 1,845 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -64,6 +64,7 @@ find_package(Qt6 6.5.0 REQUIRED COMPONENTS
Network
Sql
Core
Svg
)

add_subdirectory(deploy)
Expand Down
3 changes: 3 additions & 0 deletions src/appconfig.cpp
Expand Up @@ -104,6 +104,9 @@ QString AppConfig::defaultValue(const QString &key)
if (key == CONFIG::APIURL)
return QStringLiteral("http://localhost:8080");

if (key == CONFIG::SHOW_WELCOME_SCREEN)
return QStringLiteral("true");

if (key == CONFIG::SHORTCUT_CAPTURECLIPBOARD) {
if(!get()->appSettings->value(key).isValid())
return QStringLiteral("Meta+Alt+v");
Expand Down
2 changes: 2 additions & 0 deletions src/appconfig.h
Expand Up @@ -21,6 +21,7 @@ struct CONFIG {
inline static const auto COMMAND_CAPTUREWINDOW = QStringLiteral("captureWindowExec");
inline static const auto SHORTCUT_CAPTUREWINDOW = QStringLiteral("captureWindowShortcut");
inline static const auto SHORTCUT_CAPTURECLIPBOARD = QStringLiteral("captureClipboardShortcut");
inline static const auto SHOW_WELCOME_SCREEN = QStringLiteral("showWelcomeScreen");
};

/// AppConfig is a singleton for accessing the application's configuration.
Expand Down Expand Up @@ -102,5 +103,6 @@ class AppConfig : public QObject
CONFIG::COMMAND_CAPTUREWINDOW,
CONFIG::SHORTCUT_CAPTUREWINDOW,
CONFIG::SHORTCUT_CAPTURECLIPBOARD,
CONFIG::SHOW_WELCOME_SCREEN,
};
};
14 changes: 14 additions & 0 deletions src/forms/CMakeLists.txt
Expand Up @@ -9,6 +9,19 @@ add_library (FORMS STATIC
getinfo/getinfo.cpp getinfo/getinfo.h
porting/porting_dialog.cpp porting/porting_dialog.h
settings/settings.cpp settings/settings.h
firstRunWizard/firstTimeWizard.h firstRunWizard/firstTimeWizard.cpp
firstRunWizard/welcomepage.h firstRunWizard/welcomepage.cpp
firstRunWizard/wizardpage.h firstRunWizard/wizardpage.cpp
firstRunWizard/requirementspage.h firstRunWizard/requirementspage.cpp
firstRunWizard/evidencepage.h firstRunWizard/evidencepage.cpp
firstRunWizard/apikeyspage.h firstRunWizard/apikeyspage.cpp
firstRunWizard/hostpathpage.h firstRunWizard/hostpathpage.cpp
firstRunWizard/hosttestpage.h firstRunWizard/hosttestpage.cpp
firstRunWizard/captureareapage.h firstRunWizard/captureareapage.cpp
firstRunWizard/capturewindowpage.h firstRunWizard/capturewindowpage.cpp
firstRunWizard/captureclipboardpage.h firstRunWizard/captureclipboardpage.cpp
firstRunWizard/opspage.h firstRunWizard/opspage.cpp
firstRunWizard/finishedpage.h firstRunWizard/finishedpage.cpp
)

add_library(ASHIRT::FORMS ALIAS FORMS)
Expand All @@ -26,6 +39,7 @@ target_link_libraries ( FORMS
Qt::Gui
Qt::Widgets
Qt::Sql
Qt::Svg
ASHIRT::HELPERS
ASHIRT::MODELS
ASHIRT::COMPONENTS
Expand Down
114 changes: 114 additions & 0 deletions src/forms/firstRunWizard/apikeyspage.cpp
@@ -0,0 +1,114 @@
#include "apikeyspage.h"

#include <QFileDialog>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <appconfig.h>

bool ApiKeysPage::validatePage()
{
if (!field("host.accessKey").isValid())
return false;

if (!field("host.secretKey").isValid())
return false;

return true;
}

void ApiKeysPage::initializePage()
{
QString accessKey = AppConfig::value(CONFIG::ACCESSKEY);
setField("host.accessKey", accessKey);
accessKeyLine->setText(accessKey);

QString secretKey = AppConfig::value(CONFIG::SECRETKEY);
setField("host.secretKey", secretKey);
secretKeyLine->setText(secretKey);
}

ApiKeysPage::ApiKeysPage(QWidget *parent)
: WizardPage{Page_Api, parent}
{

auto f = font();
auto _lblTitleLabel = new QLabel(this);
f.setPointSize(titleFont.first);
f.setWeight(titleFont.second);
_lblTitleLabel->setFont(f);
_lblTitleLabel->setText(tr("API Keys"));

auto _lblSubtitle = new QLabel(this);
f.setPointSize(subTitleFont.first);
f.setWeight(subTitleFont.second);
_lblSubtitle->setFont(f);
_lblSubtitle->setWordWrap(true);
_lblSubtitle->setText(tr("Input Api keys for the server"));

auto _lblBody = new QLabel(this);
f.setPointSize(bodyFont.first);
f.setWeight(bodyFont.second);
_lblBody->setFont(f);
_lblBody->setWordWrap(true);
_lblBody->setText(tr("• Login to the Ashirt server click the profile icon in the top right then select <i>Account Settings</i><br>"));

auto _lblBody2 = new QLabel(this);
_lblBody2->setFont(f);
_lblBody2->setWordWrap(true);
_lblBody2->setText(tr("• Select <i>API Keys</i> on the left, select click <i>Generate New API Key</i><br>"));

auto _lblBody3 = new QLabel(this);
_lblBody3->setFont(f);
_lblBody3->setWordWrap(true);
_lblBody3->setText(tr("• Enter your keys below"));

auto _lblAKey = new QLabel(this);
f.setPointSize(smallFont.first);
f.setWeight(smallFont.second);
_lblAKey->setFont(f);
_lblAKey->setText(tr("Access Key"));

accessKeyLine = new QLineEdit(this);
accessKeyLine->setMaxLength(24);
accessKeyLine->setTextMargins(3,0,3,0);
accessKeyLine->setMaximumWidth(fontMetrics().averageCharWidth() * 27);
registerField("host.accessKey*", accessKeyLine);

auto t1 = new QVBoxLayout();
t1->setSpacing(1);
t1->addWidget(_lblAKey);
t1->addWidget(accessKeyLine);

auto _lblBKey = new QLabel(this);
f.setPointSize(smallFont.first);
f.setWeight(smallFont.second);
_lblBKey->setFont(f);
_lblBKey->setText(tr("Secret Key"));

secretKeyLine = new QLineEdit(this);
secretKeyLine->setTextMargins(3,0,3,0);
registerField("host.secretKey*", secretKeyLine);

auto t2 = new QVBoxLayout();
t2->setSpacing(1);
t2->addWidget(_lblBKey);
t2->addWidget(secretKeyLine);

auto tLayout = new QHBoxLayout();
tLayout->addLayout(t1);
tLayout->addLayout(t2);

auto layout = new QVBoxLayout();
layout->addWidget(_lblTitleLabel);
layout->addWidget(_lblSubtitle);
layout->addSpacerItem(new QSpacerItem(0,30,QSizePolicy::Minimum, QSizePolicy::Fixed));
layout->addWidget(_lblBody);
layout->addWidget(_lblBody2);
layout->addWidget(_lblBody3);
layout->addSpacerItem(new QSpacerItem(0,30,QSizePolicy::Minimum, QSizePolicy::Fixed));
layout->addLayout(tLayout);
layout->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Minimum, QSizePolicy::Expanding));
setLayout(layout);
}
17 changes: 17 additions & 0 deletions src/forms/firstRunWizard/apikeyspage.h
@@ -0,0 +1,17 @@
#pragma once

#include "wizardpage.h"
#include <QObject>

class QLineEdit;
class ApiKeysPage : public WizardPage
{
Q_OBJECT
public:
bool validatePage() override;
void initializePage() override;
ApiKeysPage(QWidget *parent = nullptr);
private:
QLineEdit * accessKeyLine = nullptr;
QLineEdit * secretKeyLine = nullptr;
};
115 changes: 115 additions & 0 deletions src/forms/firstRunWizard/captureareapage.cpp
@@ -0,0 +1,115 @@
#include "captureareapage.h"

#include <QFileDialog>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <appconfig.h>

#include "hotkeymanager.h"
#include "components/custom_keyseq_edit/singlestrokekeysequenceedit.h"

bool CaptureAreaPage::validatePage()
{
if(!field("command.area").isValid())
return false;
AppConfig::setValue(CONFIG::COMMAND_SCREENSHOT, field("command.area").toString());

if(!field("keySequence.area").isValid())
return false;
auto keyCombo = QKeySequence::fromString(field("keySequence.area").toString(), QKeySequence::NativeText);
AppConfig::setValue(CONFIG::SHORTCUT_SCREENSHOT, keyCombo.toString(QKeySequence::PortableText));
HotkeyManager::updateHotkeys();
return true;
}

void CaptureAreaPage::initializePage()
{
HotkeyManager::unregisterKey(HotkeyManager::ACTION_CAPTURE_AREA);
QString captureAreaCommand = AppConfig::value(CONFIG::COMMAND_SCREENSHOT);
if(!captureAreaCommand.isEmpty()) {
setField("command.area", captureAreaCommand);
captureAreaLine->setText(captureAreaCommand);
}

QString sequence = AppConfig::value(CONFIG::SHORTCUT_SCREENSHOT);
if(!sequence.isEmpty()) {
setField("keySequence.area", sequence);
captureAreaKeySequenceEdit->setKeySequence(QKeySequence::fromString(sequence));
}
}

void CaptureAreaPage::cleanupPage()
{
HotkeyManager::updateHotkeys();
}

CaptureAreaPage::CaptureAreaPage(QWidget *parent)
: WizardPage{Page_CaptureArea, parent}
{
auto f = font();
auto _lblTitleLabel = new QLabel(this);
f.setPointSize(titleFont.first);
f.setWeight(titleFont.second);
_lblTitleLabel->setFont(f);
_lblTitleLabel->setText(tr("Capture Area"));

auto _lblSubtitle = new QLabel(this);
f.setPointSize(subTitleFont.first);
f.setWeight(subTitleFont.second);
_lblSubtitle->setFont(f);
_lblSubtitle->setWordWrap(true);
_lblSubtitle->setText(tr("Set the capture area command and shortcut."));

auto _lblB1 = new QLabel(this);
f.setPointSize(bodyFont.first);
f.setWeight(bodyFont.second);
_lblB1->setFont(f);
_lblB1->setText(tr("<html><br><br>• Enter the command ashirt will use to capture area screenshots<br><br>• Enter a key combination that will trigger the capture area command<html>"));

auto hLayout = new QHBoxLayout();
hLayout->addWidget(_lblB1, 0, Qt::AlignHCenter);

auto _lblAKey = new QLabel(this);
f.setPointSize(smallFont.first);
f.setWeight(smallFont.second);
_lblAKey->setFont(f);
_lblAKey->setText(tr("Capture Area Command"));

captureAreaLine = new QLineEdit(this);
captureAreaLine->setTextMargins(3,0,3,0);
registerField("command.area*", captureAreaLine);

auto t1 = new QVBoxLayout();
t1->setSpacing(1);
t1->addWidget(_lblAKey);
t1->addWidget(captureAreaLine);

auto _lblBKey = new QLabel(this);
f.setPointSize(smallFont.first);
f.setWeight(smallFont.second);
_lblBKey->setFont(f);
_lblBKey->setText(tr("Shortcut"));

captureAreaKeySequenceEdit = new SingleStrokeKeySequenceEdit(this);
registerField("keySequence.area*", captureAreaKeySequenceEdit, "keySequence", SIGNAL(keySequenceChanged(const QKeySequence &)));

auto t2 = new QVBoxLayout();
t2->setSpacing(1);
t2->addWidget(_lblBKey);
t2->addWidget(captureAreaKeySequenceEdit);

auto tLayout = new QHBoxLayout();
tLayout->addLayout(t1, 8);
tLayout->addLayout(t2, 2);

auto layout = new QVBoxLayout();
layout->addWidget(_lblTitleLabel);
layout->addWidget(_lblSubtitle);
layout->addLayout(hLayout);
layout->addSpacerItem(new QSpacerItem(0,60,QSizePolicy::Minimum, QSizePolicy::Fixed));
layout->addLayout(tLayout);
layout->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Minimum, QSizePolicy::Expanding));
setLayout(layout);
}
19 changes: 19 additions & 0 deletions src/forms/firstRunWizard/captureareapage.h
@@ -0,0 +1,19 @@
#pragma once

#include "wizardpage.h"
#include <QObject>

class QLineEdit;
class SingleStrokeKeySequenceEdit;
class CaptureAreaPage : public WizardPage
{
Q_OBJECT
public:
bool validatePage() override;
void initializePage() override;
void cleanupPage() override;
CaptureAreaPage(QWidget *parent = nullptr);
private:
QLineEdit *captureAreaLine = nullptr;
SingleStrokeKeySequenceEdit *captureAreaKeySequenceEdit = nullptr;
};

0 comments on commit 26fb82e

Please sign in to comment.