mirror of
https://github.com/ChronosX88/nesca.git
synced 2024-11-23 10:42:21 +00:00
rqw
This commit is contained in:
parent
6392572f9f
commit
3cdf7c6a10
BIN
.CheckKey_Th.cpp.LOCAL.2427.cpp.swp
Normal file
BIN
.CheckKey_Th.cpp.LOCAL.2427.cpp.swp
Normal file
Binary file not shown.
BIN
.CheckKey_Th.cpp.LOCAL.2593.cpp.swp
Normal file
BIN
.CheckKey_Th.cpp.LOCAL.2593.cpp.swp
Normal file
Binary file not shown.
BIN
.CheckKey_Th.cpp.LOCAL.2715.cpp.swp
Normal file
BIN
.CheckKey_Th.cpp.LOCAL.2715.cpp.swp
Normal file
Binary file not shown.
BIN
.CheckKey_Th.cpp.LOCAL.2915.cpp.swp
Normal file
BIN
.CheckKey_Th.cpp.LOCAL.2915.cpp.swp
Normal file
Binary file not shown.
BIN
.CheckKey_Th.cpp.REMOTE.2427.cpp.swp
Normal file
BIN
.CheckKey_Th.cpp.REMOTE.2427.cpp.swp
Normal file
Binary file not shown.
BIN
.CheckKey_Th.cpp.REMOTE.2915.cpp.swp
Normal file
BIN
.CheckKey_Th.cpp.REMOTE.2915.cpp.swp
Normal file
Binary file not shown.
BIN
.CheckKey_Th.cpp.swo
Normal file
BIN
.CheckKey_Th.cpp.swo
Normal file
Binary file not shown.
BIN
.CheckKey_Th.cpp.swp
Normal file
BIN
.CheckKey_Th.cpp.swp
Normal file
Binary file not shown.
@ -211,16 +211,8 @@ int KeyCheckerMain()
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
{
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
@ -229,20 +221,10 @@ int KeyCheckerMain()
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
{
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
@ -253,21 +235,11 @@ int KeyCheckerMain()
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
{
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
@ -276,21 +248,11 @@ int KeyCheckerMain()
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
return -1;
|
||||
};
|
||||
};
|
||||
|
||||
|
300
CheckKey_Th.cpp.BACKUP.2427.cpp
Normal file
300
CheckKey_Th.cpp.BACKUP.2427.cpp
Normal file
@ -0,0 +1,300 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
300
CheckKey_Th.cpp.BACKUP.2593.cpp
Normal file
300
CheckKey_Th.cpp.BACKUP.2593.cpp
Normal file
@ -0,0 +1,300 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
300
CheckKey_Th.cpp.BACKUP.2715.cpp
Normal file
300
CheckKey_Th.cpp.BACKUP.2715.cpp
Normal file
@ -0,0 +1,300 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
300
CheckKey_Th.cpp.BACKUP.2915.cpp
Normal file
300
CheckKey_Th.cpp.BACKUP.2915.cpp
Normal file
@ -0,0 +1,300 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
0
CheckKey_Th.cpp.BASE.2427.cpp
Normal file
0
CheckKey_Th.cpp.BASE.2427.cpp
Normal file
0
CheckKey_Th.cpp.BASE.2593.cpp
Normal file
0
CheckKey_Th.cpp.BASE.2593.cpp
Normal file
0
CheckKey_Th.cpp.BASE.2715.cpp
Normal file
0
CheckKey_Th.cpp.BASE.2715.cpp
Normal file
0
CheckKey_Th.cpp.BASE.2915.cpp
Normal file
0
CheckKey_Th.cpp.BASE.2915.cpp
Normal file
270
CheckKey_Th.cpp.LOCAL.2427.cpp
Normal file
270
CheckKey_Th.cpp.LOCAL.2427.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
270
CheckKey_Th.cpp.LOCAL.2593.cpp
Normal file
270
CheckKey_Th.cpp.LOCAL.2593.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
270
CheckKey_Th.cpp.LOCAL.2715.cpp
Normal file
270
CheckKey_Th.cpp.LOCAL.2715.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
270
CheckKey_Th.cpp.LOCAL.2915.cpp
Normal file
270
CheckKey_Th.cpp.LOCAL.2915.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
270
CheckKey_Th.cpp.REMOTE.2427.cpp
Normal file
270
CheckKey_Th.cpp.REMOTE.2427.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
#pragma endregion
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
270
CheckKey_Th.cpp.REMOTE.2593.cpp
Normal file
270
CheckKey_Th.cpp.REMOTE.2593.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
#pragma endregion
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
270
CheckKey_Th.cpp.REMOTE.2715.cpp
Normal file
270
CheckKey_Th.cpp.REMOTE.2715.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
#pragma endregion
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
270
CheckKey_Th.cpp.REMOTE.2915.cpp
Normal file
270
CheckKey_Th.cpp.REMOTE.2915.cpp
Normal file
@ -0,0 +1,270 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
#pragma endregion
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
#pragma endregion
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
300
CheckKey_Th.cpp.orig
Normal file
300
CheckKey_Th.cpp.orig
Normal file
@ -0,0 +1,300 @@
|
||||
#pragma once
|
||||
#include "CheckKey_Th.h"
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "STh.h"
|
||||
#include "externData.h"
|
||||
#include "externFunctions.h"
|
||||
|
||||
void getSubStrEx(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int szStartStr = strlen(startStr);
|
||||
int sz = ptr2 - ptr1 - szStartStr;
|
||||
strncpy(dest, ptr1 + szStartStr, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
void getSubStr(char *src, char *startStr, char *endStr, char *dest, int szDest)
|
||||
{
|
||||
ZeroMemory(dest, szDest);
|
||||
char *ptr1 = strstri(src, startStr);
|
||||
if(ptr1 != NULL)
|
||||
{
|
||||
char *ptr2 = strstri(ptr1, endStr);
|
||||
if(ptr2 != NULL)
|
||||
{
|
||||
int sz = ptr2 - ptr1;
|
||||
strncpy(dest, ptr1, sz < szDest ? sz : szDest);
|
||||
};
|
||||
};
|
||||
}
|
||||
int emitIfOK = -1;
|
||||
int KeyCheckerMain()
|
||||
{
|
||||
int kLen = strlen(trcPersKey);
|
||||
if(kLen == 0)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key field is empty.");
|
||||
return -1;
|
||||
}
|
||||
else if(kLen < 32)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] Key length is not valid.");
|
||||
return -1;
|
||||
};
|
||||
char msg[1024] = {0};
|
||||
char ndbServer[64] = {0};
|
||||
char ndbScript[64] = {0};
|
||||
|
||||
sockaddr_in sockAddr;
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/");
|
||||
strcat(msg, trcScr);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, trcSrv);
|
||||
strcat(msg, "\r\nX-Nescav3: True");
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(trcSrv) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(trcSrv);
|
||||
else if(host=gethostbyname (trcSrv)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
stt->doEmitionYellowFoundData("[Key check] Requesting server ip...");
|
||||
int test = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -connect() returned. Cannot connect to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
test = send(sock, msg, strlen(msg), 0);
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -send() returned. Cannot send to balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
int ror = sizeof(msg);
|
||||
|
||||
test = recv(sock, msg, sizeof(msg), 0);
|
||||
char buff[512] = {0};
|
||||
while((test = recv(sock, msg, sizeof(msg), 0)) != 0)
|
||||
{
|
||||
strcat(msg, buff);
|
||||
};
|
||||
|
||||
if(test == -1)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -recv() returned. Cannot recv from balancer! " + QString::number(WSAGetLastError()) + ".");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
char *t1;
|
||||
char *t2;
|
||||
if(strstr(msg, "http://") != NULL)
|
||||
{
|
||||
t1 = strstr(msg, "http://");
|
||||
if(strstr((char*)(t1 + strlen("http://")), "/") != NULL)
|
||||
{
|
||||
t2 = strstr((char*)(t1 + strlen("http://")), "/");
|
||||
int ln = t2 - t1 - strlen("http://");
|
||||
if(ln > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else strncpy(ndbServer, (char*)(t1 + strlen("http://")), ln);
|
||||
|
||||
|
||||
if(strlen(t2) > 64)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[Key check] -Fragmentation detected!");
|
||||
if(strstr(t2, "\r\n") != NULL)
|
||||
{
|
||||
char *t3 = strstr(t2, "\r\n");
|
||||
int y = (int)(t3 - t2);
|
||||
|
||||
if(y > 64)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(ndbScript, t2, y);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Received server string is not valid!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
} else strcpy(ndbScript, t2);
|
||||
}
|
||||
else
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Cannot receive script value!");
|
||||
CSSOCKET(sock);
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. -Server string aquired! Checking key...");
|
||||
CSSOCKET(sock);
|
||||
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons(atoi(trcSrvPortLine));
|
||||
strcpy(msg, "GET ");
|
||||
strcat(msg, "/api/checkaccount?key=");
|
||||
strncat(msg, trcPersKey, 32);
|
||||
strcat(msg, " HTTP/1.0\r\nHost: ");
|
||||
strcat(msg, ndbServer);
|
||||
strcat(msg, "\r\nConnection: close");
|
||||
strcat(msg, "\r\n\r\n");
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.S_un.S_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ndbServer) != INADDR_NONE) sockAddr.sin_addr.s_addr = inet_addr(ndbServer);
|
||||
else if(host=gethostbyname (ndbServer)) ((unsigned long*) &sockAddr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
int c = connect(sock, (sockaddr*)&sockAddr, sizeof(sockAddr));
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Connection timeout.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
c = send(sock, msg, strlen(msg), 0);
|
||||
if(c == SOCKET_ERROR)
|
||||
{
|
||||
stt->doEmitionRedFoundData("[Key check] -Send error.");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
test = recv(sock, msg, 512, 0);
|
||||
|
||||
if(strstr(msg, "202 Accepted") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
stt->doEmitionGreenFoundData("[Key check] -OK. Key is valid!");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
|
||||
if(emitIfOK == 0) stt->doEmitionStartScanIP();
|
||||
else if(emitIfOK == 1) stt->doEmitionStartScanDNS();
|
||||
else if(emitIfOK == 2) stt->doEmitionStartScanImport();
|
||||
return 1;
|
||||
}
|
||||
else if(strstr(msg, "400 Bad Request") != NULL)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
QString errorDef = GetNSErrorDefinition(msg, "notify");
|
||||
if(errorDef == "Invalid access key") stt->doEmitionYellowFoundData("[NS-Track] [Key is unauthorized] A valid key is required.");
|
||||
else stt->doEmitionYellowFoundData("[NS-Track] -FAIL! [400 Bad Request : " + GetNSErrorDefinition(msg, "notify") + "]");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else if(strstr(msg, "503 Bad Gateway") != NULL)
|
||||
{
|
||||
stt->doEmitionYellowFoundData("[NS-Track] 503 Backend not responding!");
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
char header[64] = {0};
|
||||
getSubStrEx(msg, "http/1.1 ", "\r\n", header, 64);
|
||||
stt->doEmitionYellowFoundData("[Key check] -FAIL! An error occured. (" + QString::number(WSAGetLastError()) + ") Header: <u>" + QString::fromLocal8Bit(header) + "</u>");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
};
|
||||
|
||||
ZeroMemory(msg, sizeof(msg));
|
||||
CSSOCKET(sock);
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
stt->doEmitionRedFoundData("[Key check] -Balancer replied with invalid string.");
|
||||
if(gDebugMode) stt->doEmitionDebugFoundData(QString(msg));
|
||||
CSSOCKET(sock);
|
||||
return -1;
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
};
|
||||
};
|
||||
|
||||
void CheckKey_Th::run()
|
||||
{
|
||||
KeyCheckerMain();
|
||||
};
|
208
CheckProxy_Th.cpp.BACKUP.3053.cpp
Normal file
208
CheckProxy_Th.cpp.BACKUP.3053.cpp
Normal file
@ -0,0 +1,208 @@
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "externData.h"
|
||||
|
||||
void CheckProxy_Th::doEmitChangeRedIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeRedIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeGreenIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeGreenIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeYellowIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeYellowIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeRawIRCDataInc(QString str)
|
||||
{
|
||||
emit chPTh->changeRawIRCDataInc(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeRawIRCDataOut(QString str)
|
||||
{
|
||||
emit chPTh->changeRawIRCDataOut(str);
|
||||
};
|
||||
|
||||
void CheckProxyLogic()
|
||||
{
|
||||
QString str1 = ui->ircProxyPort->text();
|
||||
QString str2 = ui->ircProxy->text();
|
||||
strcpy(ircProxy, str2.toUtf8().data());
|
||||
strcpy(ircProxyPort, str1.toUtf8().data());
|
||||
|
||||
int err, yes = 1;
|
||||
SOCKET pSock;
|
||||
char precvBuff[2048] = {0};
|
||||
sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(atoi(ircProxyPort));
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.S_un.S_addr = inet_addr(ircProxy);
|
||||
else if(host = gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.s_addr = inet_addr(ircProxy);
|
||||
else if(host=gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
pSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if(pSock == INVALID_SOCKET)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET.");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET.");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
}
|
||||
else
|
||||
{
|
||||
if(connect(pSock, (sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"));
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"));
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
send(pSock, "CONNECT 2ip.ru HTTP/1.1\r\n\r\n", strlen("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"), 0);
|
||||
|
||||
while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
if( (strstr(precvBuff, "HTTP/1.1 200 OK") || strstr(precvBuff, "200 OK")
|
||||
|| strstr(precvBuff, "OK 200") || strstr(precvBuff, "200 Connection")
|
||||
)
|
||||
&& (strlen(precvBuff) < 150)
|
||||
&& strstr(precvBuff, "404 File Not Found") == NULL
|
||||
&&
|
||||
(
|
||||
strstr(precvBuff, "Invalid Request") == NULL
|
||||
|| strstr(precvBuff, "Invalid request") == NULL || strstr(precvBuff, "invalid request") == NULL
|
||||
|| strstr(precvBuff, "400 Bad Request") == NULL || strstr(precvBuff, " 400 bad request") == NULL
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"));
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"));
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
send(pSock, "GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"), 0);
|
||||
ZeroMemory(precvBuff, sizeof(precvBuff));
|
||||
while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0)
|
||||
{
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
if(strstr(precvBuff, "404 File Not Found") == NULL && strstr(precvBuff, "Invalid Request") == NULL
|
||||
&& strstr(precvBuff, "Invalid request") == NULL && strstr(precvBuff, "invalid request") == NULL
|
||||
&& strstr(precvBuff, "400 Bad Request") == NULL && strstr(precvBuff, "400 bad request") == NULL
|
||||
&& strstr(precvBuff, "404 Not") == NULL && strstr(precvBuff, "404 not") == NULL
|
||||
&& strstr(precvBuff, "500 Internal") == NULL && strstr(precvBuff, "500 internal") == NULL
|
||||
&& strstr(precvBuff, "401 Unauthorized") == NULL && strstr(precvBuff, "401 unauthorized") == NULL
|
||||
&& strstr(precvBuff, "InvalidUrl") == NULL && strstr(precvBuff, "invalidurl") == NULL
|
||||
&& strstr(precvBuff, "Invalid Url") == NULL && strstr(precvBuff, "invalid url") == NULL
|
||||
&& strstr(precvBuff, "Gateway Timeout") == NULL && strstr(precvBuff, "Gateway timeout") == NULL
|
||||
&& strstr(precvBuff, "gateway timeout") == NULL
|
||||
)
|
||||
{
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
proxyEnabledFlag = 1;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
proxyEnabledFlag = 0;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
};
|
||||
};
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
proxyEnabledFlag = 0;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
|
||||
chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
|
||||
=======
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
#pragma endregion
|
||||
>>>>>>> 1f26df077976493c1916f7764c83dc03da1445fa
|
||||
proxyEnabledFlag = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
void CheckProxy_Th::run()
|
||||
{
|
||||
CheckProxyLogic();
|
||||
};
|
0
CheckProxy_Th.cpp.BASE.3053.cpp
Normal file
0
CheckProxy_Th.cpp.BASE.3053.cpp
Normal file
154
CheckProxy_Th.cpp.LOCAL.3053.cpp
Normal file
154
CheckProxy_Th.cpp.LOCAL.3053.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "externData.h"
|
||||
|
||||
void CheckProxy_Th::doEmitChangeRedIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeRedIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeGreenIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeGreenIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeYellowIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeYellowIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeRawIRCDataInc(QString str)
|
||||
{
|
||||
emit chPTh->changeRawIRCDataInc(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeRawIRCDataOut(QString str)
|
||||
{
|
||||
emit chPTh->changeRawIRCDataOut(str);
|
||||
};
|
||||
|
||||
void CheckProxyLogic()
|
||||
{
|
||||
QString str1 = ui->ircProxyPort->text();
|
||||
QString str2 = ui->ircProxy->text();
|
||||
strcpy(ircProxy, str2.toUtf8().data());
|
||||
strcpy(ircProxyPort, str1.toUtf8().data());
|
||||
|
||||
int err, yes = 1;
|
||||
SOCKET pSock;
|
||||
char precvBuff[2048] = {0};
|
||||
sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(atoi(ircProxyPort));
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.S_un.S_addr = inet_addr(ircProxy);
|
||||
else if(host = gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.s_addr = inet_addr(ircProxy);
|
||||
else if(host=gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
pSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if(pSock == INVALID_SOCKET)
|
||||
{
|
||||
|
||||
chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET.");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(connect(pSock, (sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR)
|
||||
{
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"));
|
||||
|
||||
send(pSock, "CONNECT 2ip.ru HTTP/1.1\r\n\r\n", strlen("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"), 0);
|
||||
|
||||
while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0)
|
||||
{
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
|
||||
if( (strstr(precvBuff, "HTTP/1.1 200 OK") || strstr(precvBuff, "200 OK")
|
||||
|| strstr(precvBuff, "OK 200") || strstr(precvBuff, "200 Connection")
|
||||
)
|
||||
&& (strlen(precvBuff) < 150)
|
||||
&& strstr(precvBuff, "404 File Not Found") == NULL
|
||||
&&
|
||||
(
|
||||
strstr(precvBuff, "Invalid Request") == NULL
|
||||
|| strstr(precvBuff, "Invalid request") == NULL || strstr(precvBuff, "invalid request") == NULL
|
||||
|| strstr(precvBuff, "400 Bad Request") == NULL || strstr(precvBuff, " 400 bad request") == NULL
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"));
|
||||
|
||||
send(pSock, "GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"), 0);
|
||||
ZeroMemory(precvBuff, sizeof(precvBuff));
|
||||
while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0)
|
||||
{
|
||||
|
||||
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
|
||||
if(strstr(precvBuff, "404 File Not Found") == NULL && strstr(precvBuff, "Invalid Request") == NULL
|
||||
&& strstr(precvBuff, "Invalid request") == NULL && strstr(precvBuff, "invalid request") == NULL
|
||||
&& strstr(precvBuff, "400 Bad Request") == NULL && strstr(precvBuff, "400 bad request") == NULL
|
||||
&& strstr(precvBuff, "404 Not") == NULL && strstr(precvBuff, "404 not") == NULL
|
||||
&& strstr(precvBuff, "500 Internal") == NULL && strstr(precvBuff, "500 internal") == NULL
|
||||
&& strstr(precvBuff, "401 Unauthorized") == NULL && strstr(precvBuff, "401 unauthorized") == NULL
|
||||
&& strstr(precvBuff, "InvalidUrl") == NULL && strstr(precvBuff, "invalidurl") == NULL
|
||||
&& strstr(precvBuff, "Invalid Url") == NULL && strstr(precvBuff, "invalid url") == NULL
|
||||
&& strstr(precvBuff, "Gateway Timeout") == NULL && strstr(precvBuff, "Gateway timeout") == NULL
|
||||
&& strstr(precvBuff, "gateway timeout") == NULL
|
||||
)
|
||||
{
|
||||
|
||||
|
||||
chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
|
||||
proxyEnabledFlag = 1;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
|
||||
proxyEnabledFlag = 0;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
};
|
||||
};
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
|
||||
proxyEnabledFlag = 0;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
|
||||
proxyEnabledFlag = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
void CheckProxy_Th::run()
|
||||
{
|
||||
CheckProxyLogic();
|
||||
};
|
154
CheckProxy_Th.cpp.REMOTE.3053.cpp
Normal file
154
CheckProxy_Th.cpp.REMOTE.3053.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
#include "CheckProxy_Th.h"
|
||||
#include "externData.h"
|
||||
|
||||
void CheckProxy_Th::doEmitChangeRedIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeRedIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeGreenIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeGreenIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeYellowIRCData(QString str)
|
||||
{
|
||||
emit chPTh->changeYellowIRCData(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeRawIRCDataInc(QString str)
|
||||
{
|
||||
emit chPTh->changeRawIRCDataInc(str);
|
||||
};
|
||||
void CheckProxy_Th::doEmitChangeRawIRCDataOut(QString str)
|
||||
{
|
||||
emit chPTh->changeRawIRCDataOut(str);
|
||||
};
|
||||
|
||||
void CheckProxyLogic()
|
||||
{
|
||||
QString str1 = ui->ircProxyPort->text();
|
||||
QString str2 = ui->ircProxy->text();
|
||||
strcpy(ircProxy, str2.toUtf8().data());
|
||||
strcpy(ircProxyPort, str1.toUtf8().data());
|
||||
|
||||
int err, yes = 1;
|
||||
SOCKET pSock;
|
||||
char precvBuff[2048] = {0};
|
||||
sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(atoi(ircProxyPort));
|
||||
|
||||
HOSTENT *host;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.S_un.S_addr = inet_addr(ircProxy);
|
||||
else if(host = gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#else
|
||||
if(inet_addr(ircProxy) != INADDR_NONE) addr.sin_addr.s_addr = inet_addr(ircProxy);
|
||||
else if(host=gethostbyname (ircProxy)) ((unsigned long*) &addr.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
||||
#endif
|
||||
pSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if(pSock == INVALID_SOCKET)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData("CheckProxy: -INVALID SOCKET.");
|
||||
#pragma endregion
|
||||
}
|
||||
else
|
||||
{
|
||||
if(connect(pSock, (sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"));
|
||||
#pragma endregion
|
||||
send(pSock, "CONNECT 2ip.ru HTTP/1.1\r\n\r\n", strlen("CONNECT 2ip.ru HTTP/1.1\r\n\r\n"), 0);
|
||||
|
||||
while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0)
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
#pragma endregion
|
||||
if( (strstr(precvBuff, "HTTP/1.1 200 OK") || strstr(precvBuff, "200 OK")
|
||||
|| strstr(precvBuff, "OK 200") || strstr(precvBuff, "200 Connection")
|
||||
)
|
||||
&& (strlen(precvBuff) < 150)
|
||||
&& strstr(precvBuff, "404 File Not Found") == NULL
|
||||
&&
|
||||
(
|
||||
strstr(precvBuff, "Invalid Request") == NULL
|
||||
|| strstr(precvBuff, "Invalid request") == NULL || strstr(precvBuff, "invalid request") == NULL
|
||||
|| strstr(precvBuff, "400 Bad Request") == NULL || strstr(precvBuff, " 400 bad request") == NULL
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataOut(QString::fromLocal8Bit("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"));
|
||||
#pragma endregion
|
||||
send(pSock, "GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: 2ip.ru\r\n\r\n"), 0);
|
||||
ZeroMemory(precvBuff, sizeof(precvBuff));
|
||||
while(recv(pSock, precvBuff, sizeof(precvBuff), 0) > 0)
|
||||
{
|
||||
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRawIRCDataInc(QString::fromLocal8Bit(precvBuff));
|
||||
#pragma endregion
|
||||
if(strstr(precvBuff, "404 File Not Found") == NULL && strstr(precvBuff, "Invalid Request") == NULL
|
||||
&& strstr(precvBuff, "Invalid request") == NULL && strstr(precvBuff, "invalid request") == NULL
|
||||
&& strstr(precvBuff, "400 Bad Request") == NULL && strstr(precvBuff, "400 bad request") == NULL
|
||||
&& strstr(precvBuff, "404 Not") == NULL && strstr(precvBuff, "404 not") == NULL
|
||||
&& strstr(precvBuff, "500 Internal") == NULL && strstr(precvBuff, "500 internal") == NULL
|
||||
&& strstr(precvBuff, "401 Unauthorized") == NULL && strstr(precvBuff, "401 unauthorized") == NULL
|
||||
&& strstr(precvBuff, "InvalidUrl") == NULL && strstr(precvBuff, "invalidurl") == NULL
|
||||
&& strstr(precvBuff, "Invalid Url") == NULL && strstr(precvBuff, "invalid url") == NULL
|
||||
&& strstr(precvBuff, "Gateway Timeout") == NULL && strstr(precvBuff, "Gateway timeout") == NULL
|
||||
&& strstr(precvBuff, "gateway timeout") == NULL
|
||||
)
|
||||
{
|
||||
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeGreenIRCData("[OK] Success! Now using " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
#pragma endregion
|
||||
proxyEnabledFlag = 1;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
#pragma endregion
|
||||
proxyEnabledFlag = 0;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
};
|
||||
};
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData(QString(ircProxy) + ":" + QString(ircProxyPort) + " - is not CONNECT proxy? Try another one.");
|
||||
#pragma endregion
|
||||
proxyEnabledFlag = 0;
|
||||
|
||||
CSSOCKET(pSock);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma region QTGUI_Area
|
||||
chPTh->doEmitChangeRedIRCData("Cannot connect to " + QString(ircProxy) + ":" + QString(ircProxyPort) + ".");
|
||||
#pragma endregion
|
||||
proxyEnabledFlag = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
void CheckProxy_Th::run()
|
||||
{
|
||||
CheckProxyLogic();
|
||||
};
|
@ -8,7 +8,7 @@
|
||||
#include "externData.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
#pragma comment(lib, "iphlpapi.lib")
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user