2017-09-02 08:07:07 +00:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtQuick.Controls 2.2
|
2017-09-02 10:17:51 +00:00
|
|
|
import com.fortfirewall 1.0
|
2017-09-02 08:07:07 +00:00
|
|
|
|
|
|
|
BasePage {
|
|
|
|
|
2017-09-04 11:39:15 +00:00
|
|
|
readonly property DriverManager driverManager: fortManager.driverManager
|
|
|
|
|
2017-09-04 11:54:07 +00:00
|
|
|
property alias enableLogReading: cbShowBlockedApps.checked
|
2017-09-04 11:39:15 +00:00
|
|
|
|
|
|
|
property var appPaths: []
|
2017-09-05 13:56:11 +00:00
|
|
|
property var appPathIpMap: ({})
|
|
|
|
property var appPathIpArray: ({})
|
|
|
|
|
|
|
|
property var hostNames: ({})
|
2017-09-04 11:39:15 +00:00
|
|
|
|
|
|
|
function readLogAsync() {
|
|
|
|
driverManager.readLogAsync(logBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelDeviceIo() {
|
|
|
|
driverManager.cancelDeviceIo();
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchLogReading(enable) {
|
|
|
|
enableLogReading = enable;
|
|
|
|
|
|
|
|
fortManager.setAppLogBlocked(enable);
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
readLogAsync();
|
|
|
|
} else {
|
|
|
|
cancelDeviceIo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearAppPaths() {
|
2017-09-05 13:56:11 +00:00
|
|
|
appPaths = [];
|
|
|
|
appPathIpMap = ({});
|
|
|
|
appPathIpArray = ({});
|
|
|
|
|
|
|
|
hostNames = ({});
|
|
|
|
hostInfo.abortHostLookups();
|
2017-09-05 11:06:21 +00:00
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
refreshListViews();
|
2017-09-04 11:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function processLogBuffer() {
|
|
|
|
while (logBuffer.read(logEntry)) {
|
2017-09-05 11:06:21 +00:00
|
|
|
var path = getEntryPath(logEntry);
|
|
|
|
var ipText = netUtil.ip4ToText(logEntry.ip);
|
2017-09-04 11:39:15 +00:00
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
var ipTextsMap = appPathIpMap[path];
|
2017-09-04 11:39:15 +00:00
|
|
|
if (!ipTextsMap) {
|
|
|
|
ipTextsMap = ({});
|
2017-09-05 13:56:11 +00:00
|
|
|
appPathIpMap[path] = ipTextsMap;
|
|
|
|
appPathIpArray[path] = [];
|
2017-09-05 11:06:21 +00:00
|
|
|
appPaths.push(path);
|
2017-09-04 11:39:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
var ipCount = ipTextsMap[ipText];
|
|
|
|
ipTextsMap[ipText] = (ipCount || 0) + 1;
|
|
|
|
|
|
|
|
var ipTextsArray = appPathIpArray[path];
|
|
|
|
if (!ipCount) {
|
|
|
|
ipTextsArray.push(ipText);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Host name
|
|
|
|
if (hostNames[ipText] === undefined) {
|
|
|
|
hostNames[ipText] = false;
|
|
|
|
hostInfo.lookupHost(ipText);
|
|
|
|
}
|
2017-09-04 11:39:15 +00:00
|
|
|
}
|
2017-09-05 11:06:21 +00:00
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
refreshListViews();
|
2017-09-05 11:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEntryPath(logEntry) {
|
|
|
|
var dosPath = logEntry.dosPath;
|
|
|
|
if (!dosPath) {
|
|
|
|
dosPath = osUtil.pidToDosPath(logEntry.pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fileUtil.dosPathToPath(dosPath);
|
2017-09-04 11:39:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
function refreshListViews() {
|
|
|
|
const curIndex = appListView.currentIndex;
|
|
|
|
appListView.model = undefined;
|
|
|
|
|
|
|
|
appListView.model = appPaths;
|
|
|
|
appListView.currentIndex = curIndex;
|
|
|
|
}
|
|
|
|
|
2017-09-04 11:39:15 +00:00
|
|
|
Connections {
|
|
|
|
target: mainPage
|
|
|
|
onClosed: switchLogReading(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: driverManager
|
|
|
|
onReadLogResult: {
|
|
|
|
if (success) {
|
|
|
|
processLogBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enableLogReading) {
|
|
|
|
readLogAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
HostInfo {
|
|
|
|
id: hostInfo
|
|
|
|
onHostLookedup: {
|
|
|
|
if (success) {
|
|
|
|
hostNames[name] = hostName;
|
|
|
|
refreshListViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-04 11:39:15 +00:00
|
|
|
LogBuffer {
|
|
|
|
id: logBuffer
|
|
|
|
}
|
|
|
|
LogEntry {
|
|
|
|
id: logEntry
|
|
|
|
}
|
|
|
|
|
2017-09-02 13:48:33 +00:00
|
|
|
ColumnLayout {
|
2017-09-02 14:36:38 +00:00
|
|
|
anchors.fill: parent
|
2017-09-05 11:06:21 +00:00
|
|
|
spacing: 10
|
2017-09-02 14:36:38 +00:00
|
|
|
|
2017-09-04 11:39:15 +00:00
|
|
|
RowLayout {
|
|
|
|
Button {
|
2017-09-05 11:06:21 +00:00
|
|
|
enabled: btCopy.enabled
|
2017-09-04 11:39:15 +00:00
|
|
|
text: QT_TRANSLATE_NOOP("qml", "Clear")
|
|
|
|
onClicked: clearAppPaths()
|
|
|
|
}
|
2017-09-05 11:06:21 +00:00
|
|
|
Button {
|
|
|
|
id: btCopy
|
|
|
|
enabled: currentItem
|
2017-09-05 13:56:11 +00:00
|
|
|
text: QT_TRANSLATE_NOOP("qml", "Copy Path")
|
|
|
|
readonly property Item currentItem: appListView.currentItem
|
2017-09-05 11:06:21 +00:00
|
|
|
onClicked: {
|
|
|
|
osUtil.setClipboardData(currentItem.text);
|
|
|
|
}
|
|
|
|
}
|
2017-09-04 11:39:15 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
Switch {
|
2017-09-04 11:54:07 +00:00
|
|
|
id: cbShowBlockedApps
|
2017-09-05 14:32:11 +00:00
|
|
|
text: QT_TRANSLATE_NOOP("qml", "Log Blocked Applications")
|
2017-09-04 11:39:15 +00:00
|
|
|
onToggled: switchLogReading(checked)
|
2017-09-02 13:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-02 14:36:38 +00:00
|
|
|
|
2017-09-05 11:06:21 +00:00
|
|
|
Frame {
|
2017-09-02 14:36:38 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2017-09-05 11:06:21 +00:00
|
|
|
clip: true
|
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
RowLayout {
|
2017-09-05 11:06:21 +00:00
|
|
|
anchors.fill: parent
|
2017-09-05 13:56:11 +00:00
|
|
|
spacing: 20
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: appListView
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
spacing: 10
|
|
|
|
|
|
|
|
highlightRangeMode: ListView.ApplyRange
|
|
|
|
highlightResizeDuration: 0
|
|
|
|
highlightMoveDuration: 200
|
|
|
|
|
|
|
|
highlight: Item {
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: -7
|
|
|
|
radius: 2
|
|
|
|
border.width: 3
|
|
|
|
border.color: "black"
|
|
|
|
color: "transparent"
|
|
|
|
}
|
|
|
|
}
|
2017-09-05 11:06:21 +00:00
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
delegate: Label {
|
|
|
|
width: appListView.width
|
|
|
|
font.pixelSize: 20
|
|
|
|
elide: Text.ElideRight
|
|
|
|
text: modelData
|
|
|
|
}
|
2017-09-05 11:06:21 +00:00
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
MouseArea {
|
2017-09-05 11:06:21 +00:00
|
|
|
anchors.fill: parent
|
2017-09-05 13:56:11 +00:00
|
|
|
onClicked: {
|
|
|
|
const index = appListView.indexAt(mouse.x, mouse.y);
|
|
|
|
if (index >= 0) {
|
|
|
|
appListView.currentIndex = index;
|
|
|
|
}
|
|
|
|
}
|
2017-09-05 11:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
ListView {
|
|
|
|
id: ipListView
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
spacing: 4
|
2017-09-05 11:06:21 +00:00
|
|
|
|
2017-09-05 13:56:11 +00:00
|
|
|
model: {
|
|
|
|
const curIndex = appListView.currentIndex;
|
|
|
|
if (curIndex < 0)
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
const path = appPaths[curIndex];
|
|
|
|
return appPathIpArray[path];
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: Label {
|
|
|
|
width: ipListView.width
|
|
|
|
elide: Text.ElideRight
|
|
|
|
text: hostNames[ipText] || ipText
|
|
|
|
readonly property string ipText: modelData
|
2017-09-05 11:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-02 14:36:38 +00:00
|
|
|
}
|
2017-09-02 13:48:33 +00:00
|
|
|
}
|
2017-09-02 08:07:07 +00:00
|
|
|
}
|