-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
external.001
authored and
external.001
committed
Feb 24, 2015
0 parents
commit 98b9fc2
Showing
51 changed files
with
16,391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "ActivityDrawerTh_HorNet.h" | ||
#include "externData.h" | ||
|
||
void ActivityDrawerTh_HorNet::doEmitDrawActivityLine(QString data) | ||
{ | ||
emit adtHN->sDrawActivityLine(data); | ||
}; | ||
void ActivityDrawerTh_HorNet::doEmitDrawGrid() | ||
{ | ||
emit adtHN->sDrawGrid(); | ||
}; | ||
|
||
void makeActLine(int val) | ||
{ | ||
if(actLst.size() < 50) actLst.push_back(val); | ||
else | ||
{ | ||
actLst.pop_front(); | ||
actLst.push_back(val); | ||
}; | ||
}; | ||
void ActivityDrawerTh_HorNet::run() | ||
{ | ||
adtHN->doEmitDrawGrid(); | ||
int maxAct = Activity + 1; | ||
int nm = 0; | ||
while(true) | ||
{ | ||
if(maxAct < Activity) maxAct = Activity; | ||
if(maxAct > 1000) nm = maxAct-=1000; | ||
else if(maxAct > 10) nm = maxAct-=10; | ||
makeActLine(((float)Activity/(nm != 0 ? nm : 1)) * 10); | ||
adtHN->doEmitDrawActivityLine(QString::number(Activity) + "b"); | ||
Activity = 0; | ||
msleep(130); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef ACTIVITYDRAWERTH_HORNET_H | ||
#define ACTIVITYDRAWERTH_HORNET_H | ||
|
||
#pragma once | ||
#include "STh.h" | ||
|
||
class ActivityDrawerTh_HorNet : public QThread | ||
{ | ||
Q_OBJECT | ||
|
||
public: signals: void sDrawActivityLine(QString); | ||
public: signals: void sDrawGrid(); | ||
|
||
public: | ||
static void doEmitDrawActivityLine(QString data); | ||
static void doEmitDrawGrid(); | ||
protected: | ||
void run(); | ||
}; | ||
extern ActivityDrawerTh_HorNet *adtHN; | ||
#endif // ACTIVITYDRAWERTH_HORNET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef CHECKKEY_TH_H | ||
#define CHECKKEY_TH_H | ||
|
||
#pragma once | ||
#include "STh.h" | ||
extern int emitIfOK; | ||
class CheckKey_Th : public QThread | ||
{ | ||
Q_OBJECT | ||
|
||
protected: | ||
void run(); | ||
}; | ||
|
||
extern CheckKey_Th *chKTh; | ||
#endif // CHECKKEY_TH_H |
Oops, something went wrong.