File Downloader carcas

This commit is contained in:
cora48 2015-03-30 17:31:06 +03:00
parent a514051bfd
commit 5c26625f85
5 changed files with 68 additions and 3 deletions

51
FileDownloader.cpp Normal file
View File

@ -0,0 +1,51 @@
#include "FileDownloader.h"
#include "Connector.h"
#include "FileUpdater.h"
#include "istream"
int getCL(std::string *buffer) {
std::size_t pos1 = buffer->find("Content-Length:");
if(pos1 == std::string::npos) {
stt->doEmitionFoundData("<font color=\"Pink\">Cannot find Content-Length.</font>");
return -1;
}
int pos2 = buffer->find("\r\n", pos1);
if(pos2 == std::string::npos) {
stt->doEmitionFoundData("<font color=\"Pink\">Weird reply.</font>");
return -1;
}
std::string res = buffer->substr(pos1 + 15, pos2 - pos1 - 15);
return stoi(res);
}
void checkWeb(const char *fileName, long *ptr, void *func(void)) {
std::string buffer;
Connector::nConnect(std::string("localhost/nesca/" + std::string(fileName)).c_str(), 8080, &buffer);
std::cout<<buffer<<std::endl;
int cl = getCL(&buffer);
if(cl == -1) return;
if(cl != *ptr) {
std::ofstream out(fileName);
out << buffer.substr(buffer.find("\r\n\r\n") + 4);
out.close();
stt->doEmitionFoundData("<font color=\"Pink\">File " + QString(fileName) + " downloaded.</font>");
}
}
void loadNegatives(){
}
void FileDownloader::checkWebFiles() {
//checkWeb("negatives.txt", &FileUpdater::oldNegLstSize, (void*(*)(void))loadNegatives);
//checkWeb("login.txt", (void*(*)(void))loadLogins);
//checkWeb("pass.txt", (void*(*)(void))loadPass);
//checkWeb("sshpass.txt", (void*(*)(void))loadSSHPass);
//checkWeb("wflogin.txt", (void*(*)(void))loadWFLogins);
//checkWeb("wfpass.txt", (void*(*)(void))loadWFPass);
}

9
FileDownloader.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef FILEDOWNLOADER_H
#define FILEDOWNLOADER_H
class FileDownloader {
public:
static void checkWebFiles();
};
#endif // FILEDOWNLOADER_H

View File

@ -42,7 +42,8 @@ SOURCES +=\
FTPAuth.cpp \ FTPAuth.cpp \
Threader.cpp \ Threader.cpp \
SSHAuth.cpp \ SSHAuth.cpp \
FileUpdater.cpp FileUpdater.cpp \
FileDownloader.cpp
HEADERS += ActivityDrawerTh_HorNet.h \ HEADERS += ActivityDrawerTh_HorNet.h \
@ -71,7 +72,8 @@ HEADERS += ActivityDrawerTh_HorNet.h \
FTPAuth.h \ FTPAuth.h \
Threader.h \ Threader.h \
SSHAuth.h \ SSHAuth.h \
FileUpdater.h FileUpdater.h \
FileDownloader.h
FORMS += nesca_3.ui FORMS += nesca_3.ui

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.2.1, 2015-03-23T10:43:12. --> <!-- Written by QtCreator 3.2.1, 2015-03-30T17:30:31. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -5,6 +5,7 @@
#include "Connector.h" #include "Connector.h"
#include "Threader.h" #include "Threader.h"
#include "FileUpdater.h" #include "FileUpdater.h"
#include "FileDownloader.h"
#include <thread> #include <thread>
QJsonArray *jsonArr = new QJsonArray(); QJsonArray *jsonArr = new QJsonArray();
@ -1764,6 +1765,8 @@ int _GetDNSFromMask(char *mask, char *saveMask, char *saveMaskEnder) {
void runAuxiliaryThreads() { void runAuxiliaryThreads() {
std::thread lpThread(FileUpdater::updateLists); std::thread lpThread(FileUpdater::updateLists);
lpThread.detach(); lpThread.detach();
std::thread fuThread(FileDownloader::checkWebFiles);
fuThread.detach();
std::thread saverThread(_saver); std::thread saverThread(_saver);
saverThread.detach(); saverThread.detach();
std::thread trackerThread(_tracker); std::thread trackerThread(_tracker);