添加登录和注销判定功能

This commit is contained in:
wangxx1809 2024-03-01 16:33:16 +08:00
parent b17f20b615
commit 0aaf992142
2 changed files with 31 additions and 11 deletions

View File

@ -31,7 +31,8 @@ Packet::Packet()
, m_intervalTime(0)
, m_adhandle(nullptr)
, m_quitFlag(false) //退出标记
, m_isShowToast(false) {
, m_isShowToast(false)
, m_specialPackCount(0){
}
@ -52,7 +53,7 @@ void Packet::Init() {
m_hbPort = 1433; //心跳端口
m_startTime = time(nullptr); //当前时间
m_serverIp = "139.159.230.183"; //服务器ip
m_intervalTime = 900; //时间间隔5分钟
m_intervalTime = 180; //时间间隔5分钟
}
@ -224,11 +225,11 @@ void Packet::PacketHandler(u_char* param, const struct pcap_pkthdr* header, cons
//printf(result);
pthis->CheckTimeOut(sport,dport,result);
pthis->CheckTimeOut(sport,dport,result, header->len);
}
bool IsProcessRunning(const std::wstring& processName) {
bool Packet::IsProcessRunning(const std::wstring& processName) {
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
@ -255,7 +256,7 @@ bool IsProcessRunning(const std::wstring& processName) {
}
void Packet::CheckTimeOut(u_short sport, u_short dport,const std::string& tcpInfoStr) {
void Packet::CheckTimeOut(u_short sport, u_short dport,const std::string& tcpInfoStr,int len) {
bool isRun = IsProcessRunning(L"EdmServer.exe");
if (!isRun) return; //plm进程不存在就不打印日志
@ -263,8 +264,10 @@ void Packet::CheckTimeOut(u_short sport, u_short dport,const std::string& tcpInf
if (dport == m_hbPort || sport == m_hbPort) { //心跳数据
int timeDiff = static_cast<int>(time(nullptr) - GetStartTime());
if (timeDiff > m_intervalTime) { //超时,调用注销脚本
LogoutPLM();
LOG(DEBUG) << "Logout PLM end...";
if (m_specialPackCount > 0) {
LogoutPLM();
LOG(DEBUG) << "Logout PLM end...";
}
UpdateStartTime();
}
else {
@ -275,6 +278,18 @@ void Packet::CheckTimeOut(u_short sport, u_short dport,const std::string& tcpInf
hbCount = 0;
}
}
//1.时间在弹窗前的最后两分钟内 m_intervalTime - timeDiff<120s
//2.服务端 接收端口1433 长度54
if (m_intervalTime - timeDiff <= 120 ) {
if (dport == 1433 && 54 == len) {
++m_specialPackCount;
LOG(DEBUG) << "m_specialPackCount:" << m_specialPackCount;
}
}
else {
m_specialPackCount = 0;
}
}
else {
UpdateStartTime();
@ -345,7 +360,9 @@ void Packet::UserHandleProc(){
m_checkThread = std::thread([this, uiPath]() {
while (!m_quitFlag) {
int timeDiff = static_cast<int>(time(nullptr) - GetStartTime());
if (IsProcessRunning(L"EdmServer.exe") && timeDiff >= m_intervalTime - 10 && timeDiff <= m_intervalTime - 9) { //超时,调用注销脚本
//m_specialPackCount>0表示登录状态超时调用注销脚本
if (m_specialPackCount>0 && IsProcessRunning(L"EdmServer.exe")
&& timeDiff >= m_intervalTime - 10 && timeDiff <= m_intervalTime - 9) {
LOG(DEBUG) << "pop ui begin...";
DWORD exit_code = -1;
if (WaitUserHandle((LPWSTR)uiPath.data(), &exit_code)) {
@ -605,7 +622,7 @@ BOOL Packet::WaitUserHandle(LPWSTR command_line, DWORD* exit_code)
GetExitCodeProcess(pi.hProcess, &exitCode);
*exit_code = *exit_code== CANCEL ? *exit_code:exitCode;
LOG(DEBUG)<<"子进程ui退出码:"<< *exit_code;
LOG(DEBUG)<<"子进程ui退出码(1:确定2:取消):"<< *exit_code;
// 终止子进程
TerminateProcess(pi.hProcess, 0);

View File

@ -89,11 +89,14 @@ public:
private:
bool CheckKeepAlive(u_char* option); //无用
void CheckTimeOut(u_short sport, u_short dport, const std::string& tcpInfoStr); //检测是否超时
void CheckTimeOut(u_short sport, u_short dport, const std::string& tcpInfoStr,int len); //检测是否超时
unsigned long ConvertMaskToULong(const std::string& maskString);
INT64 PopToast();
BOOL WaitUserHandle(LPWSTR command_line, DWORD* exit_code); //创建ui进程
void UserHandleProc();
static bool IsProcessRunning(const std::wstring& processName); //进程是否在运行
static void FtpPacketHandler(const struct pcap_pkthdr* header, const u_char* pkt_data);
static void PacketHandler(u_char* param, const struct pcap_pkthdr* header, const u_char* pkt_data);
@ -112,7 +115,7 @@ private:
std::thread m_checkThread; //检测线程
bool m_isShowToast; //是否弹出了toast;
int m_specialPackCount; //累计特殊包次数弹窗前最后两分钟内注销后为0登录后大于0
};
class MyToastHandler :public WinToastLib::IWinToastHandler {