diff --git a/Daemon.ico b/Daemon.ico
new file mode 100644
index 0000000..c426844
Binary files /dev/null and b/Daemon.ico differ
diff --git a/DaemonService.pro.user b/DaemonService.pro.user
index b8fea51..d6aca7d 100644
--- a/DaemonService.pro.user
+++ b/DaemonService.pro.user
@@ -1,14 +1,14 @@
-
+
EnvironmentId
- {6a2adf44-d351-4499-8d66-24024cfa2d9d}
+ {2d03fc4c-541a-4fa5-8f5c-ae92a1998dce}
ProjectExplorer.Project.ActiveTarget
- 0
+ 1
ProjectExplorer.Project.EditorSettings
@@ -64,14 +64,14 @@
ProjectExplorer.Project.Target.0
- Desktop Qt 5.6.2 MinGW 32bit
- Desktop Qt 5.6.2 MinGW 32bit
- qt.56.win32_mingw49_kit
- 1
+ Desktop Qt 5.11.2 MinGW 32bit
+ Desktop Qt 5.11.2 MinGW 32bit
+ qt.qt5.5112.win32_mingw53_kit
+ 0
0
0
- F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Debug
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Debug
true
@@ -89,11 +89,10 @@
Make
Qt4ProjectManager.MakeStep
-
+
false
- false
2
Build
@@ -106,11 +105,10 @@
Make
Qt4ProjectManager.MakeStep
-
+
true
clean
- false
1
Clean
@@ -127,7 +125,7 @@
true
- F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Release
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Release
true
@@ -138,18 +136,17 @@
false
false
- false
+ true
true
Make
Qt4ProjectManager.MakeStep
-
+
false
- false
2
Build
@@ -162,11 +159,10 @@
Make
Qt4ProjectManager.MakeStep
-
+
true
clean
- false
1
Clean
@@ -183,7 +179,7 @@
true
- F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Profile
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Profile
true
@@ -194,18 +190,17 @@
false
true
- false
+ true
true
Make
Qt4ProjectManager.MakeStep
-
+
false
- false
2
Build
@@ -218,11 +213,10 @@
Make
Qt4ProjectManager.MakeStep
-
+
true
clean
- false
1
Clean
@@ -297,32 +291,278 @@
DaemonService
- Qt4ProjectManager.Qt4RunConfiguration:F:/Qt/DaemonService/DaemonService.pro
+ Qt4ProjectManager.Qt4RunConfiguration:E:/C++/Qt/DaemonService/DaemonService.pro
+ true
+
DaemonService.pro
-
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Debug
+ 3768
+ false
+ true
+ false
+ false
+ true
+
+ 1
+
+
+
+ ProjectExplorer.Project.Target.1
+
+ Desktop Qt 5.6.2 MinGW 32bit2
+ Desktop Qt 5.6.2 MinGW 32bit2
+ qt.56.win32_mingw49_kit
+ 1
+ 0
+ 0
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit2-Debug
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ false
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Debug
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+ true
+
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit2-Release
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ false
+
+ false
+ false
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Release
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit2-Profile
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ true
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Profile
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+ 3
+
+
+ 0
+ 閮ㄧ讲
+
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ Deploy Configuration
+
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+
+ false
+ false
+ 1000
+
+ true
+
+ false
+ false
+ false
+ false
+ true
+ 0.01
+ 10
+ true
+ 1
+ 25
+
+ 1
+ true
+ false
+ true
+ valgrind
+
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+
+ 2
+
+ DaemonService
+
+ Qt4ProjectManager.Qt4RunConfiguration:E:/C++/Qt/DaemonService/DaemonService.pro
+ true
+
+ DaemonService.pro
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit2-Release
3768
false
true
- true
false
false
true
-
- F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Release
1
ProjectExplorer.Project.TargetCount
- 1
+ 2
ProjectExplorer.Project.Updater.FileVersion
- 20
+ 18
Version
- 20
+ 18
diff --git a/DaemonService.pro.user.6a2adf4.20 b/DaemonService.pro.user.6a2adf4.20
new file mode 100644
index 0000000..bf619a6
--- /dev/null
+++ b/DaemonService.pro.user.6a2adf4.20
@@ -0,0 +1,328 @@
+
+
+
+
+
+ EnvironmentId
+ {6a2adf44-d351-4499-8d66-24024cfa2d9d}
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+ 2
+ UTF-8
+ false
+ 4
+ false
+ 80
+ true
+ true
+ 1
+ true
+ false
+ 0
+ true
+ true
+ 0
+ 8
+ true
+ 1
+ true
+ true
+ true
+ false
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+ -fno-delayed-template-parsing
+
+ true
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop Qt 5.6.2 MinGW 32bit
+ Desktop Qt 5.6.2 MinGW 32bit
+ qt.56.win32_mingw49_kit
+ 1
+ 0
+ 0
+
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Debug
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ false
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Debug
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+ true
+
+
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Release
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ false
+
+ false
+ false
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Release
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Profile
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ true
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Profile
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+ 3
+
+
+ 0
+ 閮ㄧ讲
+
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ Deploy Configuration
+
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+
+ false
+ false
+ 1000
+
+ true
+
+ false
+ false
+ false
+ false
+ true
+ 0.01
+ 10
+ true
+ 1
+ 25
+
+ 1
+ true
+ false
+ true
+ valgrind
+
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+
+ 2
+
+ DaemonService
+
+ Qt4ProjectManager.Qt4RunConfiguration:F:/Qt/DaemonService/DaemonService.pro
+ DaemonService.pro
+
+ 3768
+ false
+ true
+ true
+ false
+ false
+ true
+
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Release
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 20
+
+
+ Version
+ 20
+
+
diff --git a/README.md b/README.md
index bbc6bd1..3ebd5f9 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,38 @@
# DaemonService
-emmmmmmmmmmmmmm
+
+数据库操作类
+dal.cpp
+dal.h
+
+策略组操作类
+ipsechelper.cpp
+ipsechelper.h
+
+工作者线程类
+worker.cpp
+worker.h
+
+日志类
+log.cpp
+log.h
+
+md5计算类(未使用)
+md5.cpp
+md5.h
+
+连接池、线程分配、服务主类
+daemonservice.cpp
+daemonservice.h
+
+守护服务初始化脚本
+DaemonServiceInitializer.bat
+
+Qt项目文件
+DaemonService.pro
+
+资源文件
+res.qrc
+uac.rc
+
+图标文件
+Daemon.ico
\ No newline at end of file
diff --git a/ReadMe.png b/ReadMe.png
new file mode 100644
index 0000000..93935e9
Binary files /dev/null and b/ReadMe.png differ
diff --git a/dal.cpp b/dal.cpp
index b5ff252..64bf092 100644
--- a/dal.cpp
+++ b/dal.cpp
@@ -88,6 +88,16 @@ QList DAL::getWhiteList(QString ip)
return whitelist;
}
+void DAL::removeFromWhiteList(QString ip)
+{
+ QString sql = QString("DELETE FROM whitelist WHERE IP=?");
+ QSqlQuery query;
+ query.prepare(sql);
+ query.addBindValue(ip);
+ if(!query.exec())
+ qCritical()< ports)
{
QString portStr = QString("%1").arg(ports[0]);
@@ -130,7 +140,10 @@ bool DAL::addItemToBlackList(int port)
{
return addItemToBlackList("any", port);
}
-
+bool DAL::addItemToBlackList(QString ip)
+{
+ return addItemToBlackList(ip, -1);
+}
bool DAL::addItemToBlackList(QString ip, int port)
{
QSqlQuery query;
@@ -145,6 +158,16 @@ bool DAL::addItemToBlackList(QString ip, int port)
return true;
}
+void DAL::removeFromBlackList(QString ip)
+{
+ QString sql = QString("DELETE FROM blacklist WHERE IP=?");
+ QSqlQuery query;
+ query.prepare(sql);
+ query.addBindValue(ip);
+ if(!query.exec())
+ qCritical()< portList);
QList getWhiteList(QString ip);
+ void removeFromWhiteList(QString ip);
void removeFromWhiteList(QString ip, QList ports);
bool isExistsBlackList(int port);
bool isExistsBlackList(QString ip);
bool addItemToBlackList(int port);
+ bool addItemToBlackList(QString ip);
bool addItemToBlackList(QString ip, int port);
+ void removeFromBlackList(QString ip);
QString getPortList();
void setPortList(QString portList);
diff --git a/ipsechelper.cpp b/ipsechelper.cpp
index 0261eb0..5489d36 100644
--- a/ipsechelper.cpp
+++ b/ipsechelper.cpp
@@ -16,12 +16,18 @@ void IpsecHelper::addItemToBlackList(QString ip, int port)
{
ExeCmd("add", "blacklist", ip, port);
}
-
+void IpsecHelper::addItemToBlackList(QString ip)
+{
+ ExeCmd("add", "blacklist", ip);
+}
void IpsecHelper::removeItemFromBlackList(QString ip, int port)
{
ExeCmd("delete", "blacklist", ip, port);
}
-
+void IpsecHelper::removeItemFromBlackList(QString ip)
+{
+ ExeCmd("delete", "blacklist", ip);
+}
void IpsecHelper::addItemToBlackList(int port)
{
ExeCmd("add", "blacklist", "any", port);
@@ -45,3 +51,22 @@ void IpsecHelper::ExeCmd(QString cmd, QString filterlist, QString srcaddr, int p
p.waitForStarted();
p.waitForFinished();
}
+
+void IpsecHelper::ExeCmd(QString cmd, QString filterlist, QString srcaddr)
+{
+ QProcess p(nullptr);
+ p.start("netsh",
+ QStringList() << "ipsec"
+ << "static"
+ << cmd
+ << "filter"
+ << ("filterlist=" + filterlist)
+ << ("srcaddr=" + srcaddr)
+ << "dstaddr=me"
+ << "protocol=tcp"
+ << "mirrored=yes"
+ << "dstport=any"
+ );
+ p.waitForStarted();
+ p.waitForFinished();
+}
diff --git a/ipsechelper.h b/ipsechelper.h
index bb3722b..280e15d 100644
--- a/ipsechelper.h
+++ b/ipsechelper.h
@@ -15,11 +15,14 @@ public:
static void removeItemFromWhiteList(QString ip, int port);
static void addItemToBlackList(QString ip, int port);
+ static void addItemToBlackList(QString ip);
static void removeItemFromBlackList(QString ip, int port);
+ static void removeItemFromBlackList(QString ip);
static void addItemToBlackList(int port);
private:
static void ExeCmd(QString cmd, QString filterlist, QString srcaddr, int port);
+ static void ExeCmd(QString cmd, QString filterlist, QString srcaddr);
};
#endif // IPSECHELPER_H
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 4380e1d..275c5ba 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -195,3 +195,51 @@ void MainWindow::on_btnRemoveIP_clicked()
qDebug("IP:%s 宸茬Щ鍑烘寚瀹氱鍙g櫧鍚嶅崟", ip.toStdString().data());
}
}
+
+void MainWindow::on_btnAddBlackIP_clicked()
+{
+ QString ip = ui->txtBlackIP->text();
+ if (ip.isEmpty())
+ {
+ log_append("璇疯緭鍏ヨ鍔犲叆榛戝悕鍗曠殑IP");
+ return;
+ }
+ if (DAL::instance().isExistsBlackList(ip))
+ {
+ log_append("璇P宸插瓨鍦ㄩ粦鍚嶅崟");
+ return;
+ }
+
+ auto list = DAL::instance().getWhiteList(ip);
+ if (list.length() > 0)
+ {
+ log_append("姝e湪灏嗚ip浠庣櫧鍚嶅崟涓Щ鍑...");
+ for (int i = 0; i < list.length(); ++i)
+ IpsecHelper::removeItemFromWhiteList(ip, list[i].Port);
+ DAL::instance().removeFromWhiteList(ip);
+ log_append("绉诲嚭鐧藉悕鍗曞畬鎴");
+ }
+
+ IpsecHelper::addItemToBlackList(ip);
+ DAL::instance().addItemToBlackList(ip);
+ log_append("榛戝悕鍗曟坊鍔犲畬鎴");
+}
+
+void MainWindow::on_btnRemoveBlackIP_clicked()
+{
+ QString ip = ui->txtBlackIP->text();
+ if (ip.isEmpty())
+ {
+ log_append("璇疯緭鍏ヨ绉诲嚭榛戝悕鍗曠殑IP");
+ return;
+ }
+ if (!DAL::instance().isExistsBlackList(ip))
+ {
+ log_append("璇P涓嶅瓨鍦ㄤ簬榛戝悕鍗");
+ return;
+ }
+
+ IpsecHelper::addItemToBlackList(ip);
+ DAL::instance().removeFromBlackList(ip);
+ log_append("榛戝悕鍗曠Щ鍑哄畬鎴");
+}
diff --git a/mainwindow.h b/mainwindow.h
index 6275805..3248035 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -29,6 +29,10 @@ private slots:
void on_btnRemoveIP_clicked();
+ void on_btnAddBlackIP_clicked();
+
+ void on_btnRemoveBlackIP_clicked();
+
private:
Ui::MainWindow *ui;
};
diff --git a/mainwindow.ui b/mainwindow.ui
index a1f8650..5e8a7b3 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -7,19 +7,19 @@
0
0
700
- 320
+ 400
700
- 320
+ 400
700
- 320
+ 400
@@ -32,7 +32,7 @@
130
30
561
- 281
+ 361
@@ -60,7 +60,7 @@ p, li { white-space: pre-wrap; }
10
- 270
+ 350
111
41
@@ -170,6 +170,55 @@ p, li { white-space: pre-wrap; }
鐧藉悕鍗旾P:
+
+
+
+ 10
+ 250
+ 54
+ 12
+
+
+
+ 榛戝悕鍗旾P:
+
+
+
+
+
+ 10
+ 290
+ 51
+ 23
+
+
+
+ +
+
+
+
+
+
+ 10
+ 270
+ 111
+ 20
+
+
+
+
+
+
+ 70
+ 290
+ 51
+ 23
+
+
+
+ -
+
+
diff --git a/worker.cpp b/worker.cpp
index 71cf41f..e8ed537 100644
--- a/worker.cpp
+++ b/worker.cpp
@@ -49,10 +49,7 @@ void Worker::run()
// 涓轰簡闃叉鐭椂闂村唴澶氭杩炴帴锛屾鏌ユ渶鍚庝竴娆¤繛鎺ョ殑鏃堕棿璺濈鐜板湪鏈夊涔
// 濡傛灉涓嶈秴杩30绉掞紝鍒欏皢鍏朵粠鐧藉悕鍗曚腑绉婚櫎
-
-
-
- for (int i = this->m_portList.length(); i >= 0; --i)
+ for (int i = this->m_portList.length() - 1; i >= 0; --i)
{
int port = this->m_portList[i];
int index;
@@ -75,7 +72,7 @@ void Worker::run()
// 濡傛灉鍊掗鍗佸勾锛屾椂闂磋繕娌″埌锛岃鏄庣姝㈡椂闂存湭缁撴潫锛岀洿鎺ョ粨鏉熸湰娆″鐞
if (list[index].LastUpdateTime.addYears(-10) > QDateTime::currentDateTime())
{
- qDebug("IP:%s 宸叉嫆缁", ip.toStdString().data(), port);
+ qDebug("IP:%s 宸叉嫆缁", ip.toStdString().data());
goto end;
}
else