2015-03-22 00:43:15 +00:00
|
|
|
#include "Connector.h"
|
2015-03-23 17:11:00 +00:00
|
|
|
#include "SSHAuth.h"
|
2017-04-01 21:58:51 +00:00
|
|
|
// #include "Filter.h" // Pantene: Где файл?
|
2015-03-05 14:29:05 +00:00
|
|
|
|
2016-01-06 20:40:43 +00:00
|
|
|
//#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
|
|
|
//int _pingMyTarget(const char *ip)
|
|
|
|
//{
|
|
|
|
// HANDLE hIcmpFile;
|
|
|
|
// unsigned long ipaddr = INADDR_NONE;
|
|
|
|
// DWORD dwRetVal = 0;
|
|
|
|
// char SendData[32] = "Data Buffer";
|
|
|
|
// LPVOID ReplyBuffer = NULL;
|
|
|
|
// DWORD ReplySize = 0;
|
|
|
|
//
|
|
|
|
// ipaddr = inet_addr(ip);
|
|
|
|
//
|
|
|
|
// if (ipaddr == INADDR_NONE)
|
|
|
|
// {
|
|
|
|
// stt->doEmitionRedFoundData("[Pinger] INADDR_NONE! [" + QString(ip) + "]");
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// hIcmpFile = IcmpCreateFile();
|
|
|
|
// if (hIcmpFile == INVALID_HANDLE_VALUE)
|
|
|
|
// {
|
|
|
|
// stt->doEmitionRedFoundData("[Pinger] Unable to open handle. [" + QString::number(GetLastError()) + "]");
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
|
|
|
|
// ReplyBuffer = (VOID*) malloc(ReplySize);
|
|
|
|
// if (ReplyBuffer == NULL)
|
|
|
|
// {
|
|
|
|
// stt->doEmitionRedFoundData("[Pinger] Unable to allocate memory.");
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
|
|
|
|
// NULL, ReplyBuffer, ReplySize, gPingTimeout*1000);
|
|
|
|
// if (dwRetVal != 0) {
|
|
|
|
// PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
|
|
|
|
// struct in_addr ReplyAddr;
|
|
|
|
// ReplyAddr.S_un.S_addr = pEchoReply->Address;
|
|
|
|
// printf("\tSent icmp message to %s\n", "127.0.0.1");
|
|
|
|
// if (dwRetVal > 1)
|
|
|
|
// {
|
|
|
|
// if(gDebugMode) stt->doEmitionYellowFoundData("[Pinger] Received " + QString::number(dwRetVal) + " icmp message responses.");
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// if(gDebugMode) stt->doEmitionYellowFoundData("[Pinger] Received " + QString::number(dwRetVal) + " icmp message responses.");
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if(gDebugMode) stt->doEmitionYellowFoundData("[Pinger] Received from: " + QString(inet_ntoa( ReplyAddr )) + "; Status = " + QString::number(pEchoReply->Status) + "; Roundtrip time = " + QString::number(pEchoReply->RoundTripTime) + "ms.");
|
|
|
|
// return 1;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// printf("\tCall to IcmpSendEcho failed.\n");
|
|
|
|
// printf("\tIcmpSendEcho returned error: %ld\n", GetLastError() );
|
|
|
|
// if(gDebugMode) stt->doEmitionRedFoundData("[Pinger] Call to IcmpSendEcho failed. IcmpSendEcho returned error: " + QString::number(GetLastError()));
|
|
|
|
// return 0;
|
|
|
|
// };
|
|
|
|
//}
|
|
|
|
//#else
|
|
|
|
//int _pingMyTarget(const char *ip)
|
|
|
|
//{
|
|
|
|
// FILE *pipe = popen(("ping -w " + std::to_string(gPingTimeout) + " " + ip).c_str(), "r");
|
|
|
|
// if(!pipe) {
|
|
|
|
// stt->doEmitionRedFoundData("Ping pipe failed: cannot open pipe.");
|
|
|
|
// perror("pipe");
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// char buffer[128] = {0};
|
|
|
|
// std::string result;
|
|
|
|
//
|
|
|
|
// while(!feof(pipe)) {
|
|
|
|
// if(fgets(buffer, 128, pipe) != NULL){
|
|
|
|
// result += buffer;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// pclose(pipe);
|
|
|
|
//
|
|
|
|
// if(strstr((char*)result.c_str(), "100% packet loss") != NULL) return 0;
|
|
|
|
// return 1;
|
|
|
|
//}
|
|
|
|
//#endif
|
2015-03-06 14:32:36 +00:00
|
|
|
|
|
|
|
struct data {
|
|
|
|
char trace_ascii; /* 1 or 0 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
int my_trace(CURL *handle, curl_infotype type,
|
|
|
|
char *data, size_t size,
|
|
|
|
void *userp)
|
|
|
|
{
|
2015-03-17 14:30:53 +00:00
|
|
|
if (type == CURLINFO_HEADER_OUT) {
|
2016-01-31 20:09:42 +00:00
|
|
|
//data[size] = '\0';
|
|
|
|
//Activity += strlen(data);
|
2016-02-28 16:07:10 +00:00
|
|
|
data[size] = '\0';
|
2016-01-31 20:09:42 +00:00
|
|
|
QString qData = QString(data);
|
|
|
|
Activity += qData.length();
|
|
|
|
stt->doEmitionAddOutData(qData);
|
2015-03-06 14:32:36 +00:00
|
|
|
}
|
2016-01-31 20:09:42 +00:00
|
|
|
//else if (type == CURLINFO_HEADER_IN) {
|
|
|
|
// QString qData = QString(data);
|
|
|
|
// Activity += qData.length();
|
|
|
|
// stt->doEmitionAddIncData("", qData);
|
|
|
|
//}
|
2015-03-06 14:32:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-01 12:39:14 +00:00
|
|
|
size_t nWriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
2015-03-05 14:29:05 +00:00
|
|
|
{
|
2015-04-25 19:45:01 +00:00
|
|
|
size_t realsize = size * nmemb;
|
|
|
|
if (((std::string*)userp)->size() > 180000) return -1;
|
|
|
|
((std::string*)userp)->append((char*)contents, realsize);
|
|
|
|
Activity += realsize;
|
|
|
|
return realsize;
|
|
|
|
|
|
|
|
//struct MemoryStruct *mem = (struct MemoryStruct *)userp;
|
|
|
|
//if (mem->size > 180000) return -1;
|
|
|
|
//size_t realsize = size * nmemb;
|
|
|
|
//mem->memory = (char*)realloc(mem->memory, mem->size + realsize + 1);
|
|
|
|
|
|
|
|
//if (mem->memory == NULL) {
|
|
|
|
// stt->doEmitionRedFoundData("not enough memory (realloc returned NULL)\n");
|
|
|
|
// return 0;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//memcpy(&(mem->memory[mem->size]), contents, realsize);
|
|
|
|
//mem->size += realsize;
|
|
|
|
//mem->memory[mem->size] = 0;
|
|
|
|
//Activity += realsize;
|
|
|
|
//return realsize;
|
2015-03-05 14:29:05 +00:00
|
|
|
}
|
2015-03-06 14:32:36 +00:00
|
|
|
|
2015-12-29 10:58:43 +00:00
|
|
|
int pConnect(const char* ip, const int port, std::string *buffer,
|
|
|
|
const char *postData,
|
|
|
|
const std::vector<std::string> *customHeaders,
|
|
|
|
const std::string *lpString,
|
|
|
|
bool digestMode)
|
|
|
|
{
|
2015-04-25 19:45:01 +00:00
|
|
|
buffer->clear();
|
|
|
|
int res = 0;
|
2015-04-20 19:27:06 +00:00
|
|
|
CURL *curl = curl_easy_init();
|
2015-03-05 14:29:05 +00:00
|
|
|
|
2015-04-23 05:23:02 +00:00
|
|
|
if (curl != NULL)
|
|
|
|
{
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
|
|
|
|
if (MapWidgetOpened) {
|
|
|
|
struct data config;
|
|
|
|
config.trace_ascii = 1; /* enable ascii tracing */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
|
2016-01-31 20:09:42 +00:00
|
|
|
//curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
|
2015-04-23 05:23:02 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
}
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, ip);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PORT, port);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT,
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
|
2016-02-28 16:07:10 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 0L);
|
2015-04-23 05:23:02 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nWriteCallback);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
|
|
|
|
int proxyPort = std::atoi(gProxyPort);
|
2015-04-30 19:21:12 +00:00
|
|
|
if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
|
2015-04-23 05:23:02 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut + 3);
|
2016-01-31 20:09:42 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
|
2015-03-05 14:29:05 +00:00
|
|
|
|
2015-04-23 05:23:02 +00:00
|
|
|
if (postData != NULL) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData);
|
2015-03-05 14:29:05 +00:00
|
|
|
|
2015-04-23 05:23:02 +00:00
|
|
|
if (customHeaders != NULL) {
|
2015-03-05 14:29:05 +00:00
|
|
|
|
2015-04-23 05:23:02 +00:00
|
|
|
struct curl_slist *chunk = NULL;
|
|
|
|
for (auto &ch : *customHeaders) chunk = curl_slist_append(chunk, ch.c_str());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
|
|
|
|
}
|
2015-12-29 10:58:43 +00:00
|
|
|
|
2015-04-18 23:24:44 +00:00
|
|
|
if (lpString != NULL) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_FTPLISTONLY, 1L);
|
2015-03-22 00:43:15 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_USERPWD, lpString->c_str());
|
2015-04-18 23:24:44 +00:00
|
|
|
if (digestMode)
|
|
|
|
{
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
|
|
|
|
res = curl_easy_perform(curl);
|
2015-12-29 10:58:43 +00:00
|
|
|
|
2015-04-18 23:24:44 +00:00
|
|
|
if (port != 21 && lpString != NULL) {
|
|
|
|
int pos = Utils::ustrstr(*buffer, "\r\n\r\n");
|
|
|
|
if (pos != -1) {
|
|
|
|
*buffer = buffer->substr(pos + 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else res = curl_easy_perform(curl);
|
|
|
|
}
|
|
|
|
else res = curl_easy_perform(curl);
|
2015-12-29 10:58:43 +00:00
|
|
|
|
2015-04-28 16:00:51 +00:00
|
|
|
int sz = buffer->size();
|
2015-08-07 22:37:28 +00:00
|
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
2016-02-28 16:07:10 +00:00
|
|
|
|
|
|
|
if (res == 35) {
|
|
|
|
return -1;
|
|
|
|
} else if (res == CURLE_OK || sz > 0) {
|
2015-04-28 16:00:51 +00:00
|
|
|
return sz;
|
2015-08-30 14:40:00 +00:00
|
|
|
}
|
|
|
|
else if (res == CURLE_LOGIN_DENIED && port == 21) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (res == CURLE_OPERATION_TIMEDOUT
|
|
|
|
|| res == CURLE_COULDNT_CONNECT
|
|
|
|
|| res == CURLE_SEND_ERROR
|
|
|
|
|| res == CURLE_RECV_ERROR
|
|
|
|
) {
|
2016-01-07 00:39:35 +00:00
|
|
|
//if (gNegDebugMode)
|
|
|
|
//{
|
|
|
|
// stt->doEmitionDebugFoundData("NConnect failed (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(ip) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(ip) + " Port:" + QString::number(port) + "</font></a>]");
|
|
|
|
//}
|
2015-12-11 23:13:28 +00:00
|
|
|
SOCKET eNobuffSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
shutdown(eNobuffSocket, SD_BOTH);
|
|
|
|
closesocket(eNobuffSocket);
|
|
|
|
if (ENOBUFS == eNobuffSocket || ENOMEM == eNobuffSocket) {
|
|
|
|
stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
|
|
|
|
Sleep(10000);
|
|
|
|
}
|
2015-08-30 14:40:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
2015-04-04 07:24:31 +00:00
|
|
|
if (res == 6) return -2;
|
2015-08-30 14:40:00 +00:00
|
|
|
else if (res != 13 &&
|
2015-03-22 00:43:15 +00:00
|
|
|
res != 67 &&
|
2016-05-02 23:11:20 +00:00
|
|
|
res != CURLE_GOT_NOTHING &&
|
2015-04-01 16:58:12 +00:00
|
|
|
res != 56 &&
|
|
|
|
res != 35 &&
|
2015-04-01 17:01:06 +00:00
|
|
|
res != 19 &&
|
2015-12-29 10:58:43 +00:00
|
|
|
res != 23)
|
2015-04-28 16:00:51 +00:00
|
|
|
{
|
2015-03-22 00:43:15 +00:00
|
|
|
if (res == 5) {
|
2015-08-07 22:37:28 +00:00
|
|
|
stt->doEmitionRedFoundData("The given proxy host could not be resolved.");
|
2015-03-22 00:43:15 +00:00
|
|
|
return -2;
|
2015-12-29 10:58:43 +00:00
|
|
|
}
|
|
|
|
else if (res == 8) {
|
2015-03-22 00:43:15 +00:00
|
|
|
return -2;
|
|
|
|
}
|
2015-03-22 11:05:58 +00:00
|
|
|
else if (res == 18) {
|
|
|
|
return -2;
|
2015-03-22 00:43:15 +00:00
|
|
|
}
|
2016-01-31 20:09:42 +00:00
|
|
|
else stt->doEmitionRedFoundData("CURL error: (" + QString::number(res) + ") " + QString(ip));
|
2015-04-28 16:55:27 +00:00
|
|
|
};
|
2015-12-29 10:58:43 +00:00
|
|
|
|
2015-08-30 14:40:00 +00:00
|
|
|
//if (res == 23 && sz > 0) {
|
|
|
|
// return sz;
|
|
|
|
//}
|
|
|
|
return sz;
|
|
|
|
//else return -1;
|
2015-03-22 00:43:15 +00:00
|
|
|
}
|
2015-04-25 19:45:01 +00:00
|
|
|
|
2016-01-31 20:09:42 +00:00
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stt->doEmitionRedFoundData("Curl error.");
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
}
|
2016-02-28 16:07:10 +00:00
|
|
|
int pConnectRTSP(const char* ip, const int port, std::string *buffer, const std::string *lpString, bool isDigest)
|
2016-01-31 20:09:42 +00:00
|
|
|
{
|
|
|
|
buffer->clear();
|
|
|
|
int res = 0;
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
|
|
|
|
if (curl != NULL)
|
|
|
|
{
|
2016-02-28 16:07:10 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
|
2016-01-31 20:09:42 +00:00
|
|
|
if (MapWidgetOpened) {
|
|
|
|
struct data config;
|
|
|
|
config.trace_ascii = 1; /* enable ascii tracing */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
}
|
|
|
|
|
2016-02-28 16:07:10 +00:00
|
|
|
curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT,
|
|
|
|
"LibVLC/2.1.5 (LIVE555 Streaming Media v2014.05.27)");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, ip);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, ip);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nWriteCallback);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
|
|
|
|
int proxyPort = std::atoi(gProxyPort);
|
|
|
|
if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut + 3);
|
|
|
|
if (isDigest) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
|
|
|
|
}
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERPWD, lpString->c_str());
|
2016-01-31 20:09:42 +00:00
|
|
|
|
2016-02-28 16:07:10 +00:00
|
|
|
res = curl_easy_perform(curl);
|
2016-01-31 20:09:42 +00:00
|
|
|
|
|
|
|
int sz = buffer->size();
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
2016-02-28 16:07:10 +00:00
|
|
|
if (res == CURLE_OK || sz > 0) {
|
2016-01-31 20:09:42 +00:00
|
|
|
return sz;
|
|
|
|
}
|
2016-02-28 16:07:10 +00:00
|
|
|
|
2015-12-29 10:58:43 +00:00
|
|
|
return -1;
|
2016-02-28 16:07:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stt->doEmitionRedFoundData("Curl error.");
|
|
|
|
return -1;
|
2015-03-05 14:29:05 +00:00
|
|
|
}
|
2015-03-17 14:30:53 +00:00
|
|
|
|
2015-12-29 10:58:43 +00:00
|
|
|
void eraser(std::string *buffer, const std::string delim1, const std::string delim2) {
|
|
|
|
int pos = -1;
|
|
|
|
while ((pos = buffer->find(delim1)) != -1) {
|
|
|
|
int ePos = buffer->find(delim2, pos);
|
|
|
|
if (ePos != -1) {
|
|
|
|
buffer->erase(pos, ePos - pos - 1 + delim2.length());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buffer->erase(pos, buffer->length() - pos - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void cutoutComments(std::string *buffer) {
|
2016-01-24 19:03:28 +00:00
|
|
|
//eraser(buffer, "//", "\n"); //Cant's handle urls: http://bla.bla
|
2015-12-29 10:58:43 +00:00
|
|
|
eraser(buffer, "<!--", "-->");
|
|
|
|
eraser(buffer, "/*", "*/");
|
|
|
|
}
|
|
|
|
|
|
|
|
int Connector::nConnect(const char* ip, const int port, std::string *buffer,
|
|
|
|
const char *postData,
|
|
|
|
const std::vector<std::string> *customHeaders,
|
|
|
|
const std::string *lpString,
|
2016-01-31 20:09:42 +00:00
|
|
|
bool digestMode,
|
2016-02-28 16:07:10 +00:00
|
|
|
bool isRTSP, bool isDigest){
|
2016-01-31 20:09:42 +00:00
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
if (!isRTSP) {
|
|
|
|
res = pConnect(ip, port, buffer, postData, customHeaders, lpString, digestMode);
|
|
|
|
}
|
|
|
|
else {
|
2016-02-28 16:07:10 +00:00
|
|
|
res = pConnectRTSP(ip, port, buffer, lpString, isDigest);
|
2016-01-31 20:09:42 +00:00
|
|
|
}
|
2015-12-29 10:58:43 +00:00
|
|
|
cutoutComments(buffer);
|
|
|
|
|
2016-01-31 20:09:42 +00:00
|
|
|
if (MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(buffer->c_str()));
|
|
|
|
Activity += buffer->size();
|
|
|
|
|
2016-01-07 03:55:10 +00:00
|
|
|
return res;
|
2015-12-29 10:58:43 +00:00
|
|
|
}
|
|
|
|
|
2016-02-28 16:07:10 +00:00
|
|
|
int Connector::checkIsDigestRTSP(const char *ip, std::string *buffer) {
|
|
|
|
|
|
|
|
buffer->clear();
|
|
|
|
int res = 0;
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
|
|
|
|
if (curl != NULL)
|
|
|
|
{
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
|
|
|
|
if (MapWidgetOpened) {
|
|
|
|
struct data config;
|
|
|
|
config.trace_ascii = 1; /* enable ascii tracing */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT,
|
|
|
|
"LibVLC/2.1.5 (LIVE555 Streaming Media v2014.05.27)");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, ip);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, ip);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nWriteCallback);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer);
|
|
|
|
int proxyPort = std::atoi(gProxyPort);
|
|
|
|
if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut + 3);
|
|
|
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
|
|
|
int sz = buffer->size();
|
|
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
if (res == CURLE_OK || sz > 0) {
|
|
|
|
if (MapWidgetOpened) stt->doEmitionAddIncData(QString(ip), QString(buffer->c_str()));
|
|
|
|
Activity += sz;
|
|
|
|
|
|
|
|
if (Utils::ustrstr(buffer, "200 ok") != -1) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (Utils::ustrstr(buffer, "not found") != -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (Utils::ustrstr(buffer, "digest") != -1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
stt->doEmitionRedFoundData("Curl error.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-07 22:37:28 +00:00
|
|
|
bool portCheck(const char * sDVRIP, int wDVRPort) {
|
2015-12-15 12:28:32 +00:00
|
|
|
// sockaddr_in sa;
|
|
|
|
// sa.sin_family = AF_INET;
|
|
|
|
// sa.sin_port = htons(wDVRPort);
|
|
|
|
//
|
|
|
|
// hostent *host = NULL;
|
|
|
|
//#if defined(WIN32)
|
|
|
|
// if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.S_un.S_addr = inet_addr(sDVRIP);
|
|
|
|
//#else
|
|
|
|
// if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
|
|
|
|
//#endif
|
|
|
|
// else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
|
|
|
|
// else {
|
|
|
|
// stt->doEmitionDebugFoundData("Port check failed - inet_addr failure. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// SOCKET sock = INVALID_SOCKET;
|
|
|
|
// sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
// if (sock == INVALID_SOCKET) return false;
|
|
|
|
// else if (ENOBUFS == sock || ENOMEM == sock) {
|
|
|
|
// stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// int res = connect(sock, (sockaddr*)&sa, sizeof(sa));
|
|
|
|
//
|
|
|
|
// //shutdown(sock, SD_BOTH);
|
|
|
|
// //closesocket(sock);
|
|
|
|
// int resE = WSAGetLastError();
|
|
|
|
// if (res == SOCKET_ERROR) {
|
|
|
|
// if (gNegDebugMode)
|
|
|
|
// {
|
|
|
|
// stt->doEmitionDebugFoundData("Port check failed - SOCKET_ERROR. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// stt->doEmitionDebugFoundData("WSAGetLastError1: " + QString::number(resE) + "socket: " + QString::number(sock) + " [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
// char tBuff[1] = { 0 };
|
|
|
|
// int recvCode = send(sock, tBuff, 0, 0);
|
|
|
|
// resE = WSAGetLastError();
|
|
|
|
// stt->doEmitionDebugFoundData("WSAGetLastError2: " + QString::number(resE) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
// if (-1 == recvCode) {
|
|
|
|
// stt->doEmitionDebugFoundData("Port check failed (recv code: " + QString::number(recvCode) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// shutdown(sock, SD_BOTH);
|
|
|
|
// closesocket(sock);
|
|
|
|
// if (gNegDebugMode)
|
|
|
|
// {
|
|
|
|
// stt->doEmitionDebugFoundData("Port check succeeded (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (gNegDebugMode)
|
|
|
|
// {
|
|
|
|
// stt->doEmitionDebugFoundData("Port check failed - unknown socket error. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
// }
|
|
|
|
// return false;
|
2015-08-07 22:37:28 +00:00
|
|
|
|
2015-12-15 12:28:32 +00:00
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
if (curl != NULL) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, sDVRIP);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PORT, wDVRPort);
|
|
|
|
int proxyPort = std::atoi(gProxyPort);
|
|
|
|
if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
|
|
|
int res = curl_easy_perform(curl);
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
if (gNegDebugMode)
|
|
|
|
{
|
2016-01-07 03:55:10 +00:00
|
|
|
/*stt->doEmitionDebugFoundData("Port check failed (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");*/
|
2015-12-15 12:28:32 +00:00
|
|
|
SOCKET eNobuffSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
shutdown(eNobuffSocket, SD_BOTH);
|
|
|
|
closesocket(eNobuffSocket);
|
|
|
|
if (ENOBUFS == eNobuffSocket || ENOMEM == eNobuffSocket) {
|
|
|
|
stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
|
|
|
|
Sleep(10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (gNegDebugMode)
|
|
|
|
{
|
2016-01-31 20:09:42 +00:00
|
|
|
stt->doEmitionDebugFoundData("Port check succeeded (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) +
|
|
|
|
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + "</font></a>]");
|
2015-12-15 12:28:32 +00:00
|
|
|
}
|
|
|
|
return true;
|
2015-08-07 22:37:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-11 23:13:28 +00:00
|
|
|
else {
|
2016-01-07 03:55:10 +00:00
|
|
|
//if (gNegDebugMode)
|
|
|
|
//{
|
|
|
|
// stt->doEmitionDebugFoundData("Port check failed - curl_easy_init() error. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
|
|
|
|
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
|
|
|
|
//}
|
2015-12-15 12:28:32 +00:00
|
|
|
return false;
|
2015-12-11 23:13:28 +00:00
|
|
|
}
|
2015-08-07 22:37:28 +00:00
|
|
|
}
|
2015-04-18 13:05:35 +00:00
|
|
|
int Connector::connectToPort(char* ip, int port)
|
2015-03-05 14:29:05 +00:00
|
|
|
{
|
2016-01-06 20:40:43 +00:00
|
|
|
// if(gPingNScan)
|
|
|
|
// {
|
|
|
|
// if(_pingMyTarget(ip) == 0) return -2;
|
|
|
|
// };
|
2015-03-05 14:29:05 +00:00
|
|
|
|
|
|
|
std::string buffer;
|
|
|
|
int size = 0;
|
2015-11-08 15:44:33 +00:00
|
|
|
char tempIp[128] = { 0 };
|
|
|
|
int sz = strlen(ip);
|
|
|
|
if (443 == port) {
|
2016-01-31 20:09:42 +00:00
|
|
|
sprintf(tempIp, "https://%s:%d", ip, port);
|
|
|
|
//strcpy(tempIp, "https://");
|
2015-12-27 22:52:37 +00:00
|
|
|
}
|
|
|
|
else if (21 == port) {
|
2016-01-31 20:09:42 +00:00
|
|
|
//strcpy(tempIp, "ftp://");
|
|
|
|
sprintf(tempIp, "ftp://%s:%d", ip, port);
|
2016-04-09 21:16:03 +00:00
|
|
|
//sprintf(tempIp, "%s", ip);
|
2015-11-08 15:44:33 +00:00
|
|
|
}
|
2016-02-28 16:07:10 +00:00
|
|
|
/*else if (554 == port) {
|
|
|
|
sprintf(tempIp, "rtsp://%s:%d", ip, port);
|
|
|
|
}*/
|
2015-11-08 15:44:33 +00:00
|
|
|
else {
|
2016-01-31 20:09:42 +00:00
|
|
|
//strcpy(tempIp, "http://");
|
|
|
|
sprintf(tempIp, "http://%s:%d", ip, port);
|
2015-11-08 15:44:33 +00:00
|
|
|
}
|
2016-01-31 20:09:42 +00:00
|
|
|
//strncat(tempIp, ip, sz > 96 ? 96 : sz);
|
2015-03-05 14:29:05 +00:00
|
|
|
|
2015-08-07 22:37:28 +00:00
|
|
|
if (port != 37777 && port != 8000 && port != 34567 && port != 9000){
|
|
|
|
if (port == 22) size = SSHAuth::SSHLobby(ip, port, &buffer); //SSH
|
2016-04-09 21:16:03 +00:00
|
|
|
else if (21 == port) size = nConnect(ip, port, &buffer);
|
2015-11-08 15:44:33 +00:00
|
|
|
else size = nConnect(tempIp, port, &buffer);
|
2015-03-05 14:29:05 +00:00
|
|
|
|
2015-08-07 22:37:28 +00:00
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
++Alive;//ME2
|
|
|
|
++found;//PieStat
|
|
|
|
Lexems lx;
|
2016-01-31 20:09:42 +00:00
|
|
|
lx.filler(tempIp, ip, port, &buffer, size, &lx);
|
2015-08-07 22:37:28 +00:00
|
|
|
}
|
|
|
|
else if (size == -2) return -2;
|
|
|
|
} else {
|
2015-12-11 10:51:03 +00:00
|
|
|
if (portCheck(ip, port)) {
|
2015-08-07 22:37:28 +00:00
|
|
|
++Alive;//ME2
|
|
|
|
++found;//PieStat
|
|
|
|
Lexems lx;
|
2016-01-31 20:09:42 +00:00
|
|
|
lx.filler(ip, ip, port, &buffer, size, &lx);
|
2015-08-07 22:37:28 +00:00
|
|
|
};
|
2015-04-03 18:50:54 +00:00
|
|
|
}
|
2015-08-07 22:37:28 +00:00
|
|
|
return 0;
|
2015-03-05 14:29:05 +00:00
|
|
|
}
|