Commit 4ac208010963fc91925ac238c76c2542691c0250
1 parent
ebd01e4b
Exists in
master
Implementação da classe checkmodules. Quase completa, só realizar o teste na int…
…ra e corrigir os bugs
Showing
9 changed files
with
151 additions
and
35 deletions
Show diff stats
cacic-daemon/cacicD/cacictimer.cpp
@@ -177,13 +177,7 @@ void CacicTimer::setApplicationDirPath(const QString &value) | @@ -177,13 +177,7 @@ void CacicTimer::setApplicationDirPath(const QString &value) | ||
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | -bool CacicTimer::Md5IsEqual(QVariant document01,QVariant document02){ | ||
181 | - QString getconfigMD5 = QString(QCryptographicHash::hash( | ||
182 | - (document01.toByteArray()),QCryptographicHash::Md5).toHex()); | ||
183 | - QString getconfigMD52 = QString(QCryptographicHash::hash( | ||
184 | - (document02.toByteArray()),QCryptographicHash::Md5).toHex()); | ||
185 | - return getconfigMD5 == getconfigMD52; | ||
186 | -} | 180 | + |
187 | 181 | ||
188 | void CacicTimer::iniciarInstancias(){ | 182 | void CacicTimer::iniciarInstancias(){ |
189 | logManager = QLogger::QLoggerManager::getInstance(); | 183 | logManager = QLogger::QLoggerManager::getInstance(); |
cacic-daemon/cacicD/cacictimer.h
@@ -28,7 +28,6 @@ public: | @@ -28,7 +28,6 @@ public: | ||
28 | void iniciarTimer(); | 28 | void iniciarTimer(); |
29 | bool getTest(); | 29 | bool getTest(); |
30 | bool getConfig(); | 30 | bool getConfig(); |
31 | - bool Md5IsEqual(QVariant document01,QVariant document02); | ||
32 | void setApplicationDirPath(const QString &value); | 31 | void setApplicationDirPath(const QString &value); |
33 | QString getApplicationDirPath(); | 32 | QString getApplicationDirPath(); |
34 | void setDirProgram(const QString &value); | 33 | void setDirProgram(const QString &value); |
cacic-teste/testcacic.cpp
@@ -333,12 +333,13 @@ void CTestCacic::testEnviaColeta() | @@ -333,12 +333,13 @@ void CTestCacic::testEnviaColeta() | ||
333 | void CTestCacic::testGetModulesValues() | 333 | void CTestCacic::testGetModulesValues() |
334 | { | 334 | { |
335 | oCheckModules = new CheckModules(QDir::currentPath()); | 335 | oCheckModules = new CheckModules(QDir::currentPath()); |
336 | + oCheckModules->start(); | ||
336 | QVERIFY(false); | 337 | QVERIFY(false); |
337 | } | 338 | } |
338 | 339 | ||
339 | void CTestCacic::cleanupTestCase() | 340 | void CTestCacic::cleanupTestCase() |
340 | { | 341 | { |
341 | - // OCacic.deleteFile("gpl-2.0.txt"); | 342 | + OCacic.deleteFile("gpl-2.0.txt"); |
342 | OCacic.deleteFile("log01.txt"); | 343 | OCacic.deleteFile("log01.txt"); |
343 | OCacic.deleteFile("./log02.txt"); | 344 | OCacic.deleteFile("./log02.txt"); |
344 | OCacic.deleteFile("../log03.txt"); | 345 | OCacic.deleteFile("../log03.txt"); |
@@ -349,5 +350,5 @@ void CTestCacic::cleanupTestCase() | @@ -349,5 +350,5 @@ void CTestCacic::cleanupTestCase() | ||
349 | OCacic.deleteFolder("../logs"); | 350 | OCacic.deleteFolder("../logs"); |
350 | OCacic.deleteFile("configRequest.json"); | 351 | OCacic.deleteFile("configRequest.json"); |
351 | OCacic.deleteFile("teste.json"); | 352 | OCacic.deleteFile("teste.json"); |
352 | -// OCacic.deleteFile("getConfig.json"); | 353 | + OCacic.deleteFile("getConfig.json"); |
353 | } | 354 | } |
src/cacic_comm.cpp
@@ -4,10 +4,10 @@ CacicComm::CacicComm () | @@ -4,10 +4,10 @@ CacicComm::CacicComm () | ||
4 | { | 4 | { |
5 | } | 5 | } |
6 | 6 | ||
7 | -CacicComm::CacicComm (QString urlGerente, QString operatingSystem, QString computerSystem, QString csCipher, | ||
8 | - QString csDebug, QString csCompress, QString httpUserAgent, QString moduleFolderName, | ||
9 | - QString moduleProgramName, QString networkConfiguration,QString phpAuthPw, QString phpAuthUser, | ||
10 | - QString so, QString cacicVersion, QString gercolsVersion) | 7 | +CacicComm::CacicComm (const QString &urlGerente, const QString &operatingSystem, const QString &computerSystem, const QString &csCipher, |
8 | + const QString &csDebug, const QString &csCompress, const QString &httpUserAgent, const QString &moduleFolderName, | ||
9 | + const QString &moduleProgramName, const QString &networkConfiguration,const QString &phpAuthPw, const QString &phpAuthUser, | ||
10 | + const QString &so, const QString &cacicVersion, const QString &gercolsVersion) | ||
11 | { | 11 | { |
12 | this->setUrlGerente(urlGerente); | 12 | this->setUrlGerente(urlGerente); |
13 | params.addQueryItem("OperatingSystem", operatingSystem); | 13 | params.addQueryItem("OperatingSystem", operatingSystem); |
@@ -159,6 +159,11 @@ bool CacicComm::fileDownload(const QString &mode, const QString &path, const QSt | @@ -159,6 +159,11 @@ bool CacicComm::fileDownload(const QString &mode, const QString &path, const QSt | ||
159 | QUrl url(urlGerente); | 159 | QUrl url(urlGerente); |
160 | url.setScheme(mode); | 160 | url.setScheme(mode); |
161 | url.setPath(path); | 161 | url.setPath(path); |
162 | + if (!this->ftpUser.isEmpty()) | ||
163 | + url.setUserName(ftpUser); | ||
164 | + if (!this->ftpPass.isEmpty()) | ||
165 | + url.setPassword(ftpPass); | ||
166 | + | ||
162 | request.setUrl(url); | 167 | request.setUrl(url); |
163 | 168 | ||
164 | reply = manager.get(request); | 169 | reply = manager.get(request); |
@@ -196,6 +201,11 @@ bool CacicComm::fileDownload(const QString &mode, const QString &urlServer, cons | @@ -196,6 +201,11 @@ bool CacicComm::fileDownload(const QString &mode, const QString &urlServer, cons | ||
196 | QUrl url(urlServer); | 201 | QUrl url(urlServer); |
197 | url.setScheme(mode); | 202 | url.setScheme(mode); |
198 | url.setPath(path); | 203 | url.setPath(path); |
204 | + if (!this->ftpUser.isEmpty()) | ||
205 | + url.setUserName(ftpUser); | ||
206 | + if (!this->ftpPass.isEmpty()) | ||
207 | + url.setPassword(ftpPass); | ||
208 | + | ||
199 | request.setUrl(url); | 209 | request.setUrl(url); |
200 | 210 | ||
201 | reply = manager.get(request); | 211 | reply = manager.get(request); |
@@ -208,6 +218,38 @@ bool CacicComm::fileDownload(const QString &mode, const QString &urlServer, cons | @@ -208,6 +218,38 @@ bool CacicComm::fileDownload(const QString &mode, const QString &urlServer, cons | ||
208 | return true; | 218 | return true; |
209 | } | 219 | } |
210 | 220 | ||
221 | +void CacicComm::fileDownloadFinished(QNetworkReply* reply) | ||
222 | +{ | ||
223 | + if (reply->size() > 0){ | ||
224 | + QTextStream out(fileHandler); | ||
225 | + out << reply->readAll(); | ||
226 | + fileHandler->close(); | ||
227 | + reply->close(); | ||
228 | + } else { | ||
229 | + qDebug() << "Falha ao baixar arquivo."; | ||
230 | + } | ||
231 | +} | ||
232 | + | ||
233 | +QString CacicComm::getFtpPass() const | ||
234 | +{ | ||
235 | + return ftpPass; | ||
236 | +} | ||
237 | + | ||
238 | +void CacicComm::setFtpPass(const QString &value) | ||
239 | +{ | ||
240 | + ftpPass = value; | ||
241 | +} | ||
242 | + | ||
243 | +QString CacicComm::getFtpUser() const | ||
244 | +{ | ||
245 | + return ftpUser; | ||
246 | +} | ||
247 | + | ||
248 | +void CacicComm::setFtpUser(const QString &value) | ||
249 | +{ | ||
250 | + ftpUser = value; | ||
251 | +} | ||
252 | + | ||
211 | bool CacicComm::ftpDownload( const QString &path, const QString &pathDownload ){ | 253 | bool CacicComm::ftpDownload( const QString &path, const QString &pathDownload ){ |
212 | return fileDownload("ftp", path, pathDownload); | 254 | return fileDownload("ftp", path, pathDownload); |
213 | } | 255 | } |
@@ -228,7 +270,7 @@ QString CacicComm::getUrlSsl (){ | @@ -228,7 +270,7 @@ QString CacicComm::getUrlSsl (){ | ||
228 | return this->urlSsl; | 270 | return this->urlSsl; |
229 | } | 271 | } |
230 | 272 | ||
231 | -void CacicComm::setUrlSsl(QString value){ | 273 | +void CacicComm::setUrlSsl(const QString &value){ |
232 | this->urlSsl = value; | 274 | this->urlSsl = value; |
233 | } | 275 | } |
234 | 276 | ||
@@ -251,7 +293,7 @@ QString CacicComm::getPassword() | @@ -251,7 +293,7 @@ QString CacicComm::getPassword() | ||
251 | return this->password; | 293 | return this->password; |
252 | } | 294 | } |
253 | 295 | ||
254 | -void CacicComm::setPassword(QString value) | 296 | +void CacicComm::setPassword(const QString &value) |
255 | { | 297 | { |
256 | this->password = value; | 298 | this->password = value; |
257 | } | 299 | } |
@@ -260,15 +302,9 @@ QString CacicComm::getUsuario() | @@ -260,15 +302,9 @@ QString CacicComm::getUsuario() | ||
260 | return this->usuario; | 302 | return this->usuario; |
261 | } | 303 | } |
262 | 304 | ||
263 | -void CacicComm::setUsuario(QString value) | 305 | +void CacicComm::setUsuario(const QString &value) |
264 | { | 306 | { |
265 | this->usuario = value; | 307 | this->usuario = value; |
266 | } | 308 | } |
267 | 309 | ||
268 | -void CacicComm::fileDownloadFinished(QNetworkReply* reply) | ||
269 | -{ | ||
270 | - QTextStream out(fileHandler); | ||
271 | - out << reply->readAll(); | ||
272 | - fileHandler->close(); | ||
273 | - reply->close(); | ||
274 | -} | 310 | + |
src/cacic_comm.h
@@ -20,10 +20,10 @@ class CacicComm : public QObject{ | @@ -20,10 +20,10 @@ class CacicComm : public QObject{ | ||
20 | public: | 20 | public: |
21 | 21 | ||
22 | CacicComm (); | 22 | CacicComm (); |
23 | - CacicComm (QString urlGerente, QString operatingSystem, QString computerSystem, QString csCipher, | ||
24 | - QString csDebug, QString csCompress, QString httpUserAgent, QString moduleFolderName, | ||
25 | - QString moduleProgramName, QString networkConfiguration,QString phpAuthPw, QString phpAuthUser, | ||
26 | - QString so, QString cacicVersion, QString gercolsVersion); | 23 | + CacicComm (const QString &urlGerente, const QString &operatingSystem, const QString &computerSystem, const QString &csCipher, |
24 | + const QString &csDebug, const QString &csCompress, const QString &httpUserAgent, const QString &moduleFolderName, | ||
25 | + const QString &moduleProgramName, const QString &networkConfiguration,const QString &phpAuthPw, const QString &phpAuthUser, | ||
26 | + const QString &so, const QString &cacicVersion, const QString &gercolsVersion); | ||
27 | QJsonObject comm(QString route, bool *ok, const QJsonObject &json = QJsonObject(), bool isSsl = false); | 27 | QJsonObject comm(QString route, bool *ok, const QJsonObject &json = QJsonObject(), bool isSsl = false); |
28 | bool commStatus(); | 28 | bool commStatus(); |
29 | QJsonObject login(bool *ok); | 29 | QJsonObject login(bool *ok); |
@@ -32,18 +32,20 @@ public: | @@ -32,18 +32,20 @@ public: | ||
32 | bool httpDownload(const QString &path, const QString &pathDownload); | 32 | bool httpDownload(const QString &path, const QString &pathDownload); |
33 | bool httpDownload(const QString &urlServer, const QString &path,const QString &pathDownload); | 33 | bool httpDownload(const QString &urlServer, const QString &path,const QString &pathDownload); |
34 | QString getUrlSsl (); | 34 | QString getUrlSsl (); |
35 | - void setUrlSsl(QString value); | 35 | + void setUrlSsl(const QString &value); |
36 | QString getUrlGerente (); | 36 | QString getUrlGerente (); |
37 | void setUrlGerente(QString value); | 37 | void setUrlGerente(QString value); |
38 | QString getPassword(); | 38 | QString getPassword(); |
39 | - void setPassword(QString value); | 39 | + void setPassword(const QString &value); |
40 | QString getUsuario(); | 40 | QString getUsuario(); |
41 | - void setUsuario(QString value); | ||
42 | - | ||
43 | - | 41 | + void setUsuario(const QString &value); |
42 | + QString getFtpUser() const; | ||
43 | + void setFtpUser(const QString &value); | ||
44 | + QString getFtpPass() const; | ||
45 | + void setFtpPass(const QString &value); | ||
44 | 46 | ||
45 | signals: | 47 | signals: |
46 | -// void finished(QNetworkReply* reply); | 48 | + void finished(QNetworkReply* reply); |
47 | 49 | ||
48 | private slots: | 50 | private slots: |
49 | 51 | ||
@@ -60,6 +62,8 @@ private: | @@ -60,6 +62,8 @@ private: | ||
60 | QString usuario; | 62 | QString usuario; |
61 | QString password; | 63 | QString password; |
62 | QString session; | 64 | QString session; |
65 | + QString ftpUser; | ||
66 | + QString ftpPass; | ||
63 | 67 | ||
64 | QFile *fileHandler; | 68 | QFile *fileHandler; |
65 | 69 |
src/ccacic.cpp
@@ -199,6 +199,22 @@ QString CCacic::deCrypt(std::string str_in, std::string iv) { | @@ -199,6 +199,22 @@ QString CCacic::deCrypt(std::string str_in, std::string iv) { | ||
199 | return QString::fromStdString(str_out); | 199 | return QString::fromStdString(str_out); |
200 | } | 200 | } |
201 | 201 | ||
202 | +bool CCacic::Md5IsEqual(QVariant document01,QVariant document02){ | ||
203 | + QString file1 = QString(QCryptographicHash::hash( | ||
204 | + (document01.toByteArray()),QCryptographicHash::Md5).toHex()); | ||
205 | + QString file2 = QString(QCryptographicHash::hash( | ||
206 | + (document02.toByteArray()),QCryptographicHash::Md5).toHex()); | ||
207 | + return file1 == file2; | ||
208 | +} | ||
209 | + | ||
210 | +bool CCacic::Md5IsEqual(QVariant document01,QString document02){ | ||
211 | + QString file1 = QString(QCryptographicHash::hash( | ||
212 | + (document01.toByteArray()),QCryptographicHash::Md5).toHex()); | ||
213 | + QString file2 = document02; | ||
214 | + return file1 == file2; | ||
215 | +} | ||
216 | + | ||
217 | + | ||
202 | QString CCacic::startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments) | 218 | QString CCacic::startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments) |
203 | { | 219 | { |
204 | QProcess process; | 220 | QProcess process; |
src/ccacic.h
@@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
17 | #include "../src/crypto++/include/aes.h" | 17 | #include "../src/crypto++/include/aes.h" |
18 | #include "../src/crypto++/include/base64.h" | 18 | #include "../src/crypto++/include/base64.h" |
19 | #include "../src/crypto++/include/modes.h" | 19 | #include "../src/crypto++/include/modes.h" |
20 | +#include <QCryptographicHash> | ||
20 | 21 | ||
21 | class CCacic | 22 | class CCacic |
22 | { | 23 | { |
@@ -60,6 +61,8 @@ public: | @@ -60,6 +61,8 @@ public: | ||
60 | QString getChaveCrypt() const; | 61 | QString getChaveCrypt() const; |
61 | void setChaveCrypt(const QString &value); | 62 | void setChaveCrypt(const QString &value); |
62 | 63 | ||
64 | + bool Md5IsEqual(QVariant document01, QVariant document02); | ||
65 | + bool Md5IsEqual(QVariant document01, QString document02); | ||
63 | private: | 66 | private: |
64 | QString cacicMainFolder; | 67 | QString cacicMainFolder; |
65 | QString mainModuleName; | 68 | QString mainModuleName; |
src/checkmodules.cpp
@@ -2,23 +2,83 @@ | @@ -2,23 +2,83 @@ | ||
2 | 2 | ||
3 | CheckModules::CheckModules(const QString &workingPath) | 3 | CheckModules::CheckModules(const QString &workingPath) |
4 | { | 4 | { |
5 | + oCacic.setCacicMainFolder(workingPath); | ||
5 | QJsonObject configFile; | 6 | QJsonObject configFile; |
6 | configFile = oCacic.getJsonFromFile(workingPath + "/getConfig.json"); | 7 | configFile = oCacic.getJsonFromFile(workingPath + "/getConfig.json"); |
7 | if (!configFile.isEmpty()) { | 8 | if (!configFile.isEmpty()) { |
9 | + //pega url do gerente. | ||
10 | + this->applicationUrl = configFile["agentcomputer"].toObject()["applicationUrl"].toString(); | ||
8 | QJsonArray modulos; | 11 | QJsonArray modulos; |
12 | + //pega o jsonarray dos módulos | ||
9 | modulos = configFile["agentcomputer"].toObject()["modulos"].toArray(); | 13 | modulos = configFile["agentcomputer"].toObject()["modulos"].toArray(); |
10 | foreach (QJsonValue modulo, modulos){ | 14 | foreach (QJsonValue modulo, modulos){ |
15 | + //grava o nome com o hash de cada modulo | ||
11 | modules[modulo.toObject()["nome"].toString()] = modulo.toObject()["hash"].toString(); | 16 | modules[modulo.toObject()["nome"].toString()] = modulo.toObject()["hash"].toString(); |
12 | } | 17 | } |
13 | } | 18 | } |
14 | //TODO: Completar constructor. Agora que tenho os nomes dos módulos e os hashs, fazer a verificação. | 19 | //TODO: Completar constructor. Agora que tenho os nomes dos módulos e os hashs, fazer a verificação. |
15 | - qDebug() << modules; | 20 | + |
21 | + QDir tempPath(oCacic.getCacicMainFolder() + "/temp"); | ||
22 | + if (!tempPath.exists()){ | ||
23 | + qDebug() << "criando diretório temporário"; | ||
24 | + tempPath.mkdir(oCacic.getCacicMainFolder() + "/temp"); | ||
25 | + } | ||
16 | } | 26 | } |
17 | 27 | ||
18 | bool CheckModules::start(){ | 28 | bool CheckModules::start(){ |
29 | + if (!modules.isEmpty()){ | ||
30 | + QVariantMap::const_iterator i = modules.constBegin(); | ||
31 | + while (i != modules.constEnd()){ | ||
32 | + qDebug() << "Módulo: " << i.key() << " | Hash: " << i.value().toString(); | ||
33 | + this->verificaModulo(i.key(), i.value().toString()); | ||
34 | + i++; | ||
35 | + } | ||
36 | + } | ||
19 | return true; | 37 | return true; |
20 | } | 38 | } |
21 | 39 | ||
40 | +bool CheckModules::verificaModulo(const QString &moduloName, const QString &moduloHash) | ||
41 | +{ | ||
42 | + QFile *modulo; | ||
43 | + bool downloadOk = false; | ||
44 | + //pega o arquivo do módulo selecionado | ||
45 | + modulo = new QFile(oCacic.getCacicMainFolder() + "/" + moduloName); | ||
46 | + //verifica se o módulo existe, se o tamaho é maior que 1 byte e se o hash é igual ao informado pelo json | ||
47 | + if (!(modulo->exists() && modulo->size()>1 && oCacic.Md5IsEqual(QVariant::fromValue(modulo), moduloHash))){ | ||
48 | + QFile *novoModulo; | ||
49 | + QJsonObject metodoDownload; | ||
50 | + //verifica o tipo de download e tenta baixar o módulo para a pasta temporária. | ||
51 | + metodoDownload = oCacic.getJsonFromFile("getConfig.json")["agentcomputer"].toObject()["metodoDownload"].toObject(); | ||
52 | + oCacicComm.setFtpUser(metodoDownload["usuario"].toString()); | ||
53 | + oCacicComm.setFtpPass(metodoDownload["senha"].toString()); | ||
54 | + if(metodoDownload["tipo"].toString() == "ftp"){ | ||
55 | + qDebug() << moduloName << "ftp download"; | ||
56 | + downloadOk = oCacicComm.ftpDownload(this->applicationUrl, | ||
57 | + metodoDownload["path"].toString() + "/" + moduloName, | ||
58 | + oCacic.getCacicMainFolder() + "/temp/"); | ||
59 | + } else if (metodoDownload["tipo"].toString() == "http"){ | ||
60 | + qDebug() << moduloName << "http download"; | ||
61 | + downloadOk = oCacicComm.httpDownload(this->applicationUrl, | ||
62 | + metodoDownload["path"].toString() + "/" + moduloName, | ||
63 | + oCacic.getCacicMainFolder() + "/temp/"); | ||
64 | + } else { | ||
65 | + qDebug() << moduloName << "metodo de download incorreto"; | ||
66 | + return false; | ||
67 | + } | ||
68 | + //faz uma verificação do novo módulo. | ||
69 | + novoModulo = new QFile(oCacic.getCacicMainFolder() + "/temp/" + moduloName); | ||
70 | + if (!(novoModulo->exists() && novoModulo->size()>1 && oCacic.Md5IsEqual(QVariant::fromValue(modulo), moduloHash))){ | ||
71 | + qDebug() << moduloName << "falha no download.."; | ||
72 | + novoModulo->remove(); | ||
73 | + return false; | ||
74 | + } else { | ||
75 | + qDebug() << moduloName << "Sucesso!"; | ||
76 | + return true; | ||
77 | + } | ||
78 | + | ||
79 | + } | ||
80 | +} | ||
81 | + | ||
22 | //QStringList CheckModules::verificaModulos(){ | 82 | //QStringList CheckModules::verificaModulos(){ |
23 | // // Compara o novo arquivo de configuração com um antigo e se forem diferentes | 83 | // // Compara o novo arquivo de configuração com um antigo e se forem diferentes |
24 | // // mantem o mais recente; caso iguais simplesmente apaga o novo. | 84 | // // mantem o mais recente; caso iguais simplesmente apaga o novo. |
src/checkmodules.h
@@ -13,7 +13,10 @@ public: | @@ -13,7 +13,10 @@ public: | ||
13 | bool start(); | 13 | bool start(); |
14 | private: | 14 | private: |
15 | CCacic oCacic; | 15 | CCacic oCacic; |
16 | + CacicComm oCacicComm; | ||
17 | + QString applicationUrl; | ||
16 | QVariantMap modules; //modules["name"] = hash; | 18 | QVariantMap modules; //modules["name"] = hash; |
19 | + bool verificaModulo(const QString &moduloName, const QString &moduloHash); | ||
17 | // void lerArquivoConfig(const QJsonObject& jsonConfig); | 20 | // void lerArquivoConfig(const QJsonObject& jsonConfig); |
18 | }; | 21 | }; |
19 | 22 |