UI: OptionsPage: Show driver's state; allow to install/remove the driver.

This commit is contained in:
Nodir Temirkhodjaev 2019-04-04 13:53:59 +05:00
parent 3cbc330568
commit dd521ba81b
22 changed files with 399 additions and 164 deletions

View File

@ -17,6 +17,11 @@
"${ROOT}/src/ui/i18n | *.qm |"
]
},
"${TARGET}/driver": {
"fort": [
"${ROOT}/src/driver/scripts | *.bat *.lnk |"
]
},
"${TARGET}/imports": {
"common": [
"${QTPATH}/qml/QtQuick.2 | *.dll *.qmltypes qmldir | *d.dll"

View File

@ -6,7 +6,7 @@
md %TARGET_PATH%
cd %TARGET_PATH%
del /Q /F qt*.* FortFirewall.exe
rd /Q /S i18n imports plugins scripts
rd /Q /S driver\scripts i18n imports plugins scripts
cd ..
powershell.exe -executionpolicy remotesigned -file setup-deployment.ps1 %TARGET_PATH% %*

View File

@ -0,0 +1,11 @@
@rem Execute the command
@cd %~dp0
@echo off
set "SystemPath=%SystemRoot%\System32"
if defined PROGRAMFILES(X86) (
if exist %SystemRoot%\Sysnative\* set "SystemPath=%SystemRoot%\Sysnative"
)
%SystemPath%\cmd.exe /C start /W %1

View File

@ -0,0 +1,53 @@
@rem Install driver
@set DISPNAME=Fort Firewall
@set ARCH=32
@if defined PROGRAMFILES(X86) @set ARCH=64
@set BASENAME=fortfw
@set FILENAME=%BASENAME%%ARCH%.sys
@set SRCPATH=%~dp0..\%FILENAME%
@set DSTPATH=%SystemRoot%\System32\drivers\%BASENAME%.sys
@rem Copy driver to system storage
@if exist "%DSTPATH%" (
@echo Error: Driver already installed. Uninstall it first
@set RCODE=1
@goto EXIT
)
copy "%SRCPATH%" "%DSTPATH%"
@if ERRORLEVEL 1 (
@echo Error: Cannot copy driver to system
@set RCODE=%ERRORLEVEL%
@goto EXIT
)
@rem Create service
sc create %BASENAME% binPath= "%DSTPATH%" type= kernel start= auto depend= BFE DisplayName= "%DISPNAME%"
@if ERRORLEVEL 1 (
@echo Error: Cannot create a service
@set RCODE=%ERRORLEVEL%
@goto EXIT
)
sc start %BASENAME%
@if ERRORLEVEL 1 (
@echo Error: Cannot start the service
@set RCODE=%ERRORLEVEL%
@goto EXIT
)
@set RCODE=0
@goto EXIT
:EXIT
@echo End execution... Error Code = %RCODE%
@if %RCODE% neq 0 (
@pause
)
@exit /b %RCODE%

View File

@ -0,0 +1,8 @@
@rem Re-install driver
@cd %~dp0
@echo off
%COMSPEC% /C uninstall.bat
install.bat

Binary file not shown.

View File

@ -0,0 +1,33 @@
@rem Uninstall driver
@set DISPNAME=Fort Firewall
@set BASENAME=fortfw
@set DSTPATH=%SystemRoot%\System32\drivers\%BASENAME%.sys
@rem Close the "Services" list window
taskkill /F /IM mmc.exe
@rem Stop the service
net stop %BASENAME%
@rem Remove the service
sc delete %BASENAME%
@if ERRORLEVEL 1 (
@echo Error: Cannot delete the service
@set RCODE=%ERRORLEVEL%
@rem @goto EXIT
)
@rem Remove driver from system storage
Del "%DSTPATH%"
@set RCODE=0
@goto EXIT
:EXIT
@echo End execution... Error Code = %RCODE%
@exit /b %RCODE%

Binary file not shown.

View File

@ -50,17 +50,23 @@ bool DriverManager::isDeviceOpened() const
bool DriverManager::openDevice()
{
if (!m_device->open(FortCommon::deviceName())) {
const bool res = m_device->open(FortCommon::deviceName());
if (!res) {
setErrorMessage(OsUtil::lastErrorMessage());
return false;
}
return true;
emit isDeviceOpenedChanged();
return res;
}
bool DriverManager::closeDevice()
{
return m_device->close();
const bool res = m_device->close();
emit isDeviceOpenedChanged();
return res;
}
bool DriverManager::validate()
@ -121,12 +127,22 @@ bool DriverManager::writeData(quint32 code, QByteArray &buf, int size)
}
void DriverManager::reinstallDriver()
{
executeCommand("reinstall.lnk");
}
void DriverManager::uninstallDriver()
{
executeCommand("uninstall.lnk");
}
void DriverManager::executeCommand(const QString &fileName)
{
const QString binPath = FileUtil::toNativeSeparators(
FileUtil::appBinLocation());
const QString cmdPath = qEnvironmentVariable("COMSPEC");
const QString scriptPath = binPath + "\\driver\\scripts\\reinstall-lnk.bat";
const QString scriptPath = binPath + "\\driver\\scripts\\execute-cmd.bat";
QProcess::execute(cmdPath, QStringList() << "/C" << scriptPath);
QProcess::execute(cmdPath, QStringList() << "/C" << scriptPath << fileName);
}

View File

@ -11,6 +11,7 @@ class DriverManager : public QObject
{
Q_OBJECT
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
Q_PROPERTY(bool isDeviceOpened READ isDeviceOpened NOTIFY isDeviceOpenedChanged)
public:
explicit DriverManager(QObject *parent = nullptr);
@ -23,9 +24,11 @@ public:
bool isDeviceOpened() const;
static void reinstallDriver();
static void uninstallDriver();
signals:
void errorMessageChanged();
void isDeviceOpenedChanged();
public slots:
bool openDevice();
@ -44,6 +47,8 @@ private:
bool writeData(quint32 code, QByteArray &buf, int size);
static void executeCommand(const QString &fileName);
private:
Device *m_device;
DriverWorker *m_driverWorker;

View File

@ -21,6 +21,9 @@
<file>images/link.png</file>
<file>images/page_copy.png</file>
<file>images/page_paste.png</file>
<file>images/plugin.png</file>
<file>images/plugin_disabled.png</file>
<file>images/plugin_error.png</file>
<file>images/resultset_next.png</file>
<file>images/resultset_previous.png</file>
<file>images/run.png</file>

View File

@ -2,6 +2,7 @@
<qresource prefix="/">
<file>qml/controls/ButtonMenu.qml</file>
<file>qml/controls/ButtonPopup.qml</file>
<file>qml/controls/DelayButtonControl.qml</file>
<file>qml/controls/HSeparator.qml</file>
<file>qml/controls/LabelColorRow.qml</file>
<file>qml/controls/LabelSpinRow.qml</file>

View File

@ -62,6 +62,7 @@ FortManager::FortManager(FortSettings *fortSettings,
{
setupLogger();
setupDatabaseManager();
setupLogManager();
setupDriver();
@ -80,6 +81,7 @@ FortManager::~FortManager()
removeHotKeys();
closeDriver();
closeLogManager();
}
void FortManager::registerQmlTypes()
@ -119,28 +121,35 @@ void FortManager::registerQmlTypes()
qmlRegisterType<StringUtil>("com.fortfirewall", 1, 0, "StringUtil");
}
void FortManager::installDriver()
{
closeDriver();
m_driverManager->reinstallDriver();
if (setupDriver()) {
updateDriverConf(m_firewallConf);
}
}
void FortManager::removeDriver()
{
closeDriver();
m_driverManager->uninstallDriver();
}
bool FortManager::setupDriver()
{
bool opened = m_driverManager->openDevice();
// Try to (re)install the driver in portable mode
if (m_fortSettings->isPortable()
&& !(opened && m_driverManager->validate())) {
if (opened) {
if (!m_driverManager->validate()) {
m_driverManager->closeDevice();
opened = false;
}
m_driverManager->reinstallDriver();
opened = m_driverManager->openDevice();
}
if (!opened) {
showErrorBox("Setup Driver: " + m_driverManager->errorMessage());
return false;
}
return true;
return opened;
}
void FortManager::closeDriver()
@ -148,6 +157,15 @@ void FortManager::closeDriver()
updateLogManager(false);
m_driverManager->closeDevice();
}
void FortManager::setupLogManager()
{
m_logManager->initialize();
}
void FortManager::closeLogManager()
{
m_logManager->close();
}
@ -169,11 +187,6 @@ void FortManager::setupLogger()
updateLogger();
}
void FortManager::setupLogManager()
{
m_logManager->initialize();
}
void FortManager::setupTranslationManager()
{
TranslationManager::instance()->switchLanguageByName(
@ -201,6 +214,7 @@ bool FortManager::setupEngine()
QQmlContext *context = m_engine->rootContext();
context->setContextProperty("fortManager", this);
context->setContextProperty("driverManager", m_driverManager);
context->setContextProperty("translationManager", TranslationManager::instance());
m_engine->load(QUrl("qrc:/qml/main.qml"));
@ -486,8 +500,6 @@ bool FortManager::updateDriverConf(FirewallConf *conf, bool onlyFlags)
if (res) {
updateDatabaseManager(conf);
} else {
showErrorBox("Update Driver Conf: " + m_driverManager->errorMessage());
}
updateLogManager(true);

View File

@ -47,6 +47,9 @@ signals:
void firewallConfToEditChanged();
public slots:
void installDriver();
void removeDriver();
void launch();
void showTrayIcon();
@ -90,10 +93,12 @@ private:
bool setupDriver();
void closeDriver();
void setupLogManager();
void closeLogManager();
void setupDatabaseManager();
void setupLogger();
void setupLogManager();
void setupTranslationManager();

Binary file not shown.

View File

@ -50,42 +50,42 @@
<context>
<name>FortManager</name>
<message>
<location filename="../fortmanager.cpp" line="369"/>
<location filename="../fortmanager.cpp" line="383"/>
<source>Password input</source>
<translation>Ввод пароля</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="369"/>
<location filename="../fortmanager.cpp" line="383"/>
<source>Please enter the password</source>
<translation>Наберите пароль пожалуйста</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="596"/>
<location filename="../fortmanager.cpp" line="608"/>
<source>Options</source>
<translation>Опции</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="601"/>
<location filename="../fortmanager.cpp" line="613"/>
<source>Traffic Graph</source>
<translation>График трафика</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="611"/>
<location filename="../fortmanager.cpp" line="623"/>
<source>Filter Enabled</source>
<translation>Фильтр включен</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="618"/>
<location filename="../fortmanager.cpp" line="630"/>
<source>Stop Traffic</source>
<translation>Остановить трафик</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="625"/>
<location filename="../fortmanager.cpp" line="637"/>
<source>Stop Internet Traffic</source>
<translation>Остановить Интернет трафик</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="653"/>
<location filename="../fortmanager.cpp" line="665"/>
<source>Quit</source>
<translation>Выйти</translation>
</message>
@ -371,7 +371,7 @@
<translation>Статистика</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="132"/>
<location filename="../qml/pages/OptionsPage.qml" line="135"/>
<source>Password:</source>
<translation>Пароль:</translation>
</message>
@ -396,55 +396,72 @@
<translation>Выйти</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="46"/>
<location filename="../qml/pages/OptionsPage.qml" line="49"/>
<source>Start with Windows</source>
<translation>Запускать вместе с Windows</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="53"/>
<location filename="../qml/pages/OptionsPage.qml" line="56"/>
<source>Stop traffic when Fort Firewall is not running</source>
<translation>Остановить трафик, когда Fort Firewall не запущен</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="69"/>
<location filename="../qml/pages/OptionsPage.qml" line="72"/>
<source>Filter Enabled</source>
<translation>Фильтр включен</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="80"/>
<location filename="../qml/pages/OptionsPage.qml" line="83"/>
<source>Filter Local Addresses</source>
<translation>Фильтр локальных адресов</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="97"/>
<location filename="../qml/pages/OptionsPage.qml" line="100"/>
<source>Stop Traffic</source>
<translation>Остановить трафик</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="108"/>
<location filename="../qml/pages/OptionsPage.qml" line="111"/>
<source>Stop Internet Traffic</source>
<translation>Остановить Интернет трафик</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="121"/>
<location filename="../qml/pages/OptionsPage.qml" line="124"/>
<source>Hot Keys</source>
<translation>Горячие клавиши</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="153"/>
<location filename="../qml/pages/OptionsPage.qml" line="156"/>
<location filename="../qml/pages/OptionsPage.qml" line="209"/>
<source>Installed</source>
<translation>Установлен</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="154"/>
<location filename="../qml/pages/OptionsPage.qml" line="157"/>
<location filename="../qml/pages/OptionsPage.qml" line="210"/>
<source>Not Installed</source>
<translation>Не установлен</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="164"/>
<location filename="../qml/pages/OptionsPage.qml" line="167"/>
<source>Language:</source>
<translation>Язык:</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="201"/>
<source>Driver:</source>
<translation>Драйвер:</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="219"/>
<source>Install</source>
<translation>Установить</translation>
</message>
<message>
<location filename="../qml/pages/OptionsPage.qml" line="224"/>
<source>Remove</source>
<translation>Удалить</translation>
</message>
<message>
<location filename="../qml/pages/MainPage.qml" line="132"/>
<source>Logs</source>

BIN
src/ui/images/plugin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 B

View File

@ -11,8 +11,7 @@
#include "util/osutil.h"
#define FORT_ERROR_INSTANCE 1
#define FORT_ERROR_DEVICE 2
#define FORT_ERROR_CONTROL 3
#define FORT_ERROR_CONTROL 2
int main(int argc, char *argv[])
{
@ -52,14 +51,6 @@ int main(int argc, char *argv[])
}
FortManager fortManager(&fortSettings);
// Error: Cannot open the driver device
if (!fortManager.driverManager()->isDeviceOpened()) {
QMessageBox::critical(nullptr, QString(),
"Cannot open the driver device!");
return FORT_ERROR_DEVICE;
}
fortManager.launch();
// Process control requests from clients

View File

@ -0,0 +1,22 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
DelayButton {
signal delayClicked()
property bool isActivated: false
onPressed: {
isActivated = false;
}
onActivated: {
isActivated = true;
}
onReleased: {
if (isActivated) {
delayClicked();
checked = false;
}
}
}

View File

@ -36,8 +36,11 @@ BasePage {
Frame {
anchors.fill: parent
ColumnLayout {
RowLayout {
anchors.fill: parent
ColumnLayout {
Layout.alignment: Qt.AlignTop
spacing: 10
CheckBox {
@ -171,9 +174,59 @@ BasePage {
onActivated: fortManager.setLanguage(index)
}
}
}
Item {
Layout.fillHeight: true
ColumnLayout {
Layout.alignment: Qt.AlignTop
spacing: 10
Frame {
Layout.alignment: Qt.AlignHCenter
ColumnLayout {
spacing: 10
Row {
Layout.alignment: Qt.AlignHCenter
spacing: 5
Image {
source: driverManager.isDeviceOpened
? (!driverManager.errorMessage
? "qrc:/images/plugin.png"
: "qrc:/images/plugin_error.png")
: "qrc:/images/plugin_disabled.png"
}
Label {
text: translationManager.trTrigger
&& qsTranslate("qml", "Driver:")
}
Label {
width: Math.min(implicitWidth, 300)
wrapMode: Text.Wrap
text: translationManager.trTrigger
&& (driverManager.isDeviceOpened
? (driverManager.errorMessage
|| qsTranslate("qml", "Installed"))
: qsTranslate("qml", "Not Installed"))
}
}
Row {
Layout.alignment: Qt.AlignHCenter
spacing: 10
DelayButtonControl {
text: translationManager.trTrigger
&& qsTranslate("qml", "Install")
onDelayClicked: fortManager.installDriver()
}
DelayButtonControl {
text: translationManager.trTrigger
&& qsTranslate("qml", "Remove")
onDelayClicked: fortManager.removeDriver()
}
}
}
}
}
}
}