2015-03-30 14:31:06 +00:00
|
|
|
#include "FileDownloader.h"
|
2015-04-02 10:26:32 +00:00
|
|
|
#include "fstream"
|
2015-03-30 14:31:06 +00:00
|
|
|
|
2015-04-02 10:26:32 +00:00
|
|
|
std::string FileDownloader::lastModifiedNeg = "";
|
|
|
|
std::string FileDownloader::lastModifiedL = "";
|
|
|
|
std::string FileDownloader::lastModifiedP = "";
|
|
|
|
std::string FileDownloader::lastModifiedSSH = "";
|
|
|
|
std::string FileDownloader::lastModifiedWFL = "";
|
|
|
|
std::string FileDownloader::lastModifiedWFP = "";
|
2015-04-01 19:23:52 +00:00
|
|
|
|
2015-04-02 10:26:32 +00:00
|
|
|
std::string getLM(std::string *buffer) {
|
2015-03-30 14:31:06 +00:00
|
|
|
|
2015-04-02 10:26:32 +00:00
|
|
|
std::size_t pos1 = buffer->find("Last-Modified:");
|
2015-03-30 14:31:06 +00:00
|
|
|
if(pos1 == std::string::npos) {
|
2015-04-02 10:26:32 +00:00
|
|
|
stt->doEmitionFoundData("<font color=\"Pink\">Cannot find Last-Modified.</font>");
|
|
|
|
return "";
|
2015-03-30 14:31:06 +00:00
|
|
|
}
|
|
|
|
int pos2 = buffer->find("\r\n", pos1);
|
|
|
|
if(pos2 == std::string::npos) {
|
|
|
|
stt->doEmitionFoundData("<font color=\"Pink\">Weird reply.</font>");
|
2015-04-02 10:26:32 +00:00
|
|
|
return "";
|
2015-03-30 14:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string res = buffer->substr(pos1 + 15, pos2 - pos1 - 15);
|
2015-04-02 10:26:32 +00:00
|
|
|
return res;
|
2015-03-30 14:31:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 10:26:32 +00:00
|
|
|
void checkWeb(const char *fileName, std::string *oldLM) {
|
2015-03-30 14:31:06 +00:00
|
|
|
std::string buffer;
|
2015-04-01 19:23:52 +00:00
|
|
|
Connector::nConnect(std::string("http://nesca.d3w.org/files/" + std::string(fileName)).c_str(), 80, &buffer);
|
2015-03-30 14:31:06 +00:00
|
|
|
|
2015-04-02 10:26:32 +00:00
|
|
|
const std::string &lm = getLM(&buffer);
|
|
|
|
if(lm.size() == 0) return;
|
|
|
|
|
|
|
|
if(lm.compare(*oldLM) != 0) {
|
|
|
|
*oldLM = lm;
|
|
|
|
std::string res(buffer.substr(buffer.find("\r\n\r\n") + 4).c_str());
|
|
|
|
std::ofstream out(fileName);
|
|
|
|
out << std::string(res);
|
2015-03-30 14:31:06 +00:00
|
|
|
out.close();
|
|
|
|
|
|
|
|
stt->doEmitionFoundData("<font color=\"Pink\">File " + QString(fileName) + " downloaded.</font>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDownloader::checkWebFiles() {
|
2015-04-02 10:26:32 +00:00
|
|
|
while (true) {
|
|
|
|
checkWeb("negatives.txt", &lastModifiedNeg);
|
|
|
|
checkWeb("login.txt", &lastModifiedL);
|
|
|
|
checkWeb("pass.txt", &lastModifiedP);
|
|
|
|
checkWeb("sshpass.txt", &lastModifiedSSH);
|
|
|
|
checkWeb("wflogin.txt", &lastModifiedWFL);
|
|
|
|
checkWeb("wfpass.txt", &lastModifiedWFP);
|
2015-04-02 10:32:26 +00:00
|
|
|
Sleep(600000);
|
2015-04-02 10:26:32 +00:00
|
|
|
}
|
2015-03-30 14:31:06 +00:00
|
|
|
}
|
|
|
|
|