diff --git a/src/driver/fortdrv.c b/src/driver/fortdrv.c index b36a72ad..f0224feb 100644 --- a/src/driver/fortdrv.c +++ b/src/driver/fortdrv.c @@ -207,7 +207,8 @@ fort_callout_classify_v4 (const FWPS_INCOMING_VALUES0 *inFixedValues, if (!blocked) { if (ip_included && conf_flags.log_stat) { - fort_stat_flow_associate(inMetaValues->flowHandle); + fort_stat_flow_associate(inMetaValues->flowHandle, + g_device->flow4_id, (UINT32) inMetaValues->processId); } goto permit; } @@ -321,7 +322,7 @@ fort_callout_install (PDEVICE_OBJECT device) /* IPv4 flow callout */ c.calloutKey = FORT_GUID_CALLOUT_FLOW_V4; - c.classifyFn = fort_callout_flow_v4; + c.classifyFn = fort_callout_flow_classify_v4; c.flowDeleteFn = fort_callout_flow_delete_v4; c.flags = FWP_CALLOUT_FLAG_CONDITIONAL_ON_FLOW; diff --git a/src/driver/fortstat.c b/src/driver/fortstat.c index f0c22b89..f90e35d8 100644 --- a/src/driver/fortstat.c +++ b/src/driver/fortstat.c @@ -1,15 +1,19 @@ /* Fort Firewall Usage Statistics */ static void -fort_stat_flow_associate(UINT64 flowId) +fort_stat_flow_associate (UINT64 flowId, + UINT32 calloutId, + UINT32 processId) { - //DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, - // "FORT: Classify V4: %d %d %d\n", FWPS_IS_METADATA_FIELD_PRESENT( - // inMetaValues, FWPS_METADATA_FIELD_FLOW_HANDLE), - // inMetaValues->flowHandle, (UINT32) flowContext); + NTSTATUS status; - //const NTSTATUS status = FwpsFlowAssociateContext0( - // flowId, FWPM_LAYER_STREAM_V4, FORT_GUID_CALLOUT_FLOW_V4, 1); + status = FwpsFlowAssociateContext0( + flowId, FWPS_LAYER_STREAM_V4, calloutId, processId); + + DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, + "FORT: flow +: %d %d\n", flowId, processId); + + //STATUS_OBJECT_NAME_EXISTS } static void @@ -17,14 +21,25 @@ fort_callout_flow_delete_v4 (UINT16 layerId, UINT32 calloutId, UINT64 flowContext) { + UNUSED(layerId); + UNUSED(calloutId); + + DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, + "FORT: flow -: %d\n", (UINT32) flowContext); } static void -fort_callout_flow_v4 (const FWPS_INCOMING_VALUES0 *inFixedValues, - const FWPS_INCOMING_METADATA_VALUES0 *inMetaValues, - void *layerData, - const FWPS_FILTER0 *filter, - UINT64 flowContext, - FWPS_CLASSIFY_OUT0 *classifyOut) +fort_callout_flow_classify_v4 (const FWPS_INCOMING_VALUES0 *inFixedValues, + const FWPS_INCOMING_METADATA_VALUES0 *inMetaValues, + FWPS_STREAM_CALLOUT_IO_PACKET0 *packet, + const FWPS_FILTER0 *filter, + UINT64 flowContext, + FWPS_CLASSIFY_OUT0 *classifyOut) { + FWPS_STREAM_DATA0 *streamData = packet->streamData; + + DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL, + "FORT: flow >: %d %d %d\n", inMetaValues->flowHandle, flowContext, streamData->dataLength); + + classifyOut->actionType = FWP_ACTION_CONTINUE; } diff --git a/src/ui/conf/firewallconf.cpp b/src/ui/conf/firewallconf.cpp index b6787d36..6f5c8805 100644 --- a/src/ui/conf/firewallconf.cpp +++ b/src/ui/conf/firewallconf.cpp @@ -142,6 +142,7 @@ void FirewallConf::copyFlags(const FirewallConf &o) void FirewallConf::copyTempFlags(const FirewallConf &o) { setLogBlocked(o.logBlocked()); + setLogStat(o.logStat()); } QVariant FirewallConf::toVariant() const diff --git a/src/ui/fort_images.qrc b/src/ui/fort_images.qrc index dfd3d081..a9030a63 100644 --- a/src/ui/fort_images.qrc +++ b/src/ui/fort_images.qrc @@ -6,6 +6,7 @@ images/application_double.png images/application_edit.png images/cancel.png + images/chart_line.png images/clock.png images/cog.png images/cross.png diff --git a/src/ui/fort_qml.qrc b/src/ui/fort_qml.qrc index 9dd43d1a..6d9d51ce 100644 --- a/src/ui/fort_qml.qrc +++ b/src/ui/fort_qml.qrc @@ -11,6 +11,7 @@ qml/pages/MainPage.qml qml/pages/OptionsPage.qml qml/pages/SchedulePage.qml + qml/pages/StatisticsPage.qml qml/pages/addresses/AddressesColumn.qml qml/pages/apps/AppsColumn.qml qml/pages/apps/AppsTextColumn.qml diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 46809483..45a70ada 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -306,6 +306,13 @@ void FortManager::setLogBlocked(bool enable) updateDriverConfFlags(m_firewallConf); } +void FortManager::setLogStat(bool enable) +{ + m_firewallConf->setLogStat(enable); + + updateDriverConfFlags(m_firewallConf); +} + void FortManager::setLanguage(int language) { if (!TranslationManager::instance()->switchLanguage(language)) diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index 475487e1..eb3f5595 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -55,6 +55,7 @@ public slots: bool applyConf(bool onlyFlags = false); void setLogBlocked(bool enable); + void setLogStat(bool enable); void setLanguage(int language); diff --git a/src/ui/images/chart_line.png b/src/ui/images/chart_line.png new file mode 100644 index 00000000..85020f32 Binary files /dev/null and b/src/ui/images/chart_line.png differ diff --git a/src/ui/qml/pages/BlockedPage.qml b/src/ui/qml/pages/BlockedPage.qml index 635cc434..216cffac 100644 --- a/src/ui/qml/pages/BlockedPage.qml +++ b/src/ui/qml/pages/BlockedPage.qml @@ -9,18 +9,18 @@ BasePage { readonly property LogManager logManager: fortManager.logManager readonly property AppBlockedModel appBlockedModel: logManager.appBlockedModel - property bool logReadingEnabled: false + property bool logBlockedEnabled: false property bool addressResolvingEnabled: false readonly property string currentAppPath: (appListView.currentIndex >= 0 && appListView.currentItem) ? appListView.currentItem.appPath : "" - function switchLogReading(enable) { - if (logReadingEnabled === enable) + function switchLogBlocked(enable) { + if (logBlockedEnabled === enable) return; - logReadingEnabled = enable; + logBlockedEnabled = enable; fortManager.setLogBlocked(enable); } @@ -42,7 +42,7 @@ BasePage { target: mainPage onClosed: { switchResolveAddresses(false); - switchLogReading(false); + switchLogBlocked(false); } } @@ -77,7 +77,7 @@ BasePage { font.weight: Font.DemiBold text: translationManager.dummyBool && qsTranslate("qml", "Log Blocked Applications") - onToggled: switchLogReading(checked) + onToggled: switchLogBlocked(checked) } } diff --git a/src/ui/qml/pages/MainPage.qml b/src/ui/qml/pages/MainPage.qml index 5c30bb3b..719cfeeb 100644 --- a/src/ui/qml/pages/MainPage.qml +++ b/src/ui/qml/pages/MainPage.qml @@ -67,6 +67,11 @@ Page { text: translationManager.dummyBool && qsTranslate("qml", "Blocked") } + TabButton { + icon.source: "qrc:/images/chart_line.png" + text: translationManager.dummyBool + && qsTranslate("qml", "Statistics") + } } SwipeView { @@ -79,6 +84,7 @@ Page { ApplicationsPage {} SchedulePage {} BlockedPage {} + StatisticsPage {} } footer: Pane { diff --git a/src/ui/qml/pages/StatisticsPage.qml b/src/ui/qml/pages/StatisticsPage.qml new file mode 100644 index 00000000..c7575577 --- /dev/null +++ b/src/ui/qml/pages/StatisticsPage.qml @@ -0,0 +1,53 @@ +import QtQuick 2.9 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 2.2 +import "../controls" +import com.fortfirewall 1.0 + +BasePage { + + readonly property LogManager logManager: fortManager.logManager + + property bool logStatisticsEnabled: false + + function switchLogStatistics(enable) { + if (logStatisticsEnabled === enable) + return; + + logStatisticsEnabled = enable; + + fortManager.setLogStat(enable); + } + + Connections { + target: mainPage + onClosed: { + switchLogStatistics(false); + } + } + + ColumnLayout { + anchors.fill: parent + spacing: 10 + + RowLayout { + Item { + Layout.fillWidth: true + } + + Switch { + id: cbShowBlockedApps + font.weight: Font.DemiBold + text: translationManager.dummyBool + && qsTranslate("qml", "Collect Usage Statistics") + onToggled: switchLogStatistics(checked) + } + } + + Frame { + Layout.fillWidth: true + Layout.fillHeight: true + clip: true + } + } +}