Commit ebd01e4b5cbb0c20d7bdfd1ab0faf5db6b16f9b3

Authored by Eric Menezes Noronha
1 parent df1422ff
Exists in master

Modificação do esquema de verificação dos módulos. (Não funcional ainda)

cacic-daemon/cacicD/cacicd.cpp
@@ -40,7 +40,7 @@ void cacicD::start() { @@ -40,7 +40,7 @@ void cacicD::start() {
40 //o valor nu_intervalo_exec vem em minutos. O valor que o timer aceita é em milisegundos,por isso 60000 40 //o valor nu_intervalo_exec vem em minutos. O valor que o timer aceita é em milisegundos,por isso 60000
41 Ocacictimer->setPeriodicidadeExecucao(configuracoes["nu_intervalo_exec"].toString().toInt() * 60000); 41 Ocacictimer->setPeriodicidadeExecucao(configuracoes["nu_intervalo_exec"].toString().toInt() * 60000);
42 Ocacictimer->iniciarTimer(); 42 Ocacictimer->iniciarTimer();
43 - }else{ 43 + } else {
44 //Iniciar com um timer default (4 horas), pra não ficar freezado pra sempre. 44 //Iniciar com um timer default (4 horas), pra não ficar freezado pra sempre.
45 QLogger::QLog_Error("Cacic Daemon", QString("Problemas com o arquivo getConfig.json")); 45 QLogger::QLog_Error("Cacic Daemon", QString("Problemas com o arquivo getConfig.json"));
46 QLogger::QLog_Info("Cacic Daemon", QString("Inicializando periodicidade de execução do serviço com tempo padrão.")); 46 QLogger::QLog_Info("Cacic Daemon", QString("Inicializando periodicidade de execução do serviço com tempo padrão."));
cacic-daemon/cacicD/cacictimer.cpp
@@ -48,42 +48,44 @@ void CacicTimer::mslot(){ @@ -48,42 +48,44 @@ void CacicTimer::mslot(){
48 QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Não foi possivel verificar a periodicidade no getConfig.json")); 48 QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Não foi possivel verificar a periodicidade no getConfig.json"));
49 } 49 }
50 50
51 - verificarEIniciarQMutex();  
52 -  
53 - if(getTest()){  
54 - QLogger::QLog_Info("Cacic Daemon (Timer)", QString("getTeste() success."));  
55 - if(getConfig()){  
56 - QLogger::QLog_Info("Cacic Daemon (Timer)", QString("getConfig() success."));  
57 - // QStringList nomesModulos = verificarModulos();  
58 - // if ( !nomesModulos.empty() ) {  
59 - // foreach( QString nome, nomesModulos ) {  
60 - QString nome = "gercols";  
61 - definirDirModulo(getApplicationDirPath(), nome);  
62 - cacicthread->setCcacic(ccacic);  
63 - cacicthread->setOCacicComm(OCacicComm);  
64 - cacicthread->setNomeModulo(nome);  
65 - cacicthread->setCMutex(cMutex);  
66 - cacicthread->setModuloDirPath(getDirProgram());  
67 - cacicthread->start(QThread::NormalPriority);  
68 -// if(nome == "gercols" ){  
69 -// //Envio do json gerado na coleta  
70 -// bool ok = false;  
71 -// QJsonObject jsonColeta = ccacic->getJsonFromFile(this->applicationDirPath + "/coleta.json");  
72 -// OCacicComm->comm("/ws/neo/coleta", &ok, jsonColeta , false);  
73 -// if(&ok){  
74 -// QLogger::QLog_Info("Cacic Daemon (Timer)", QString("coleta enviada com sucesso."));  
75 -// }  
76 -// } 51 + //Caso verifique que a thread ainda está em execução e não consiga finalizá-la.
  52 + //Acredito que seja difícil acontecer, mas vai que...
  53 + if (verificarEIniciarQMutex()) {
  54 + if(getTest()){
  55 + QLogger::QLog_Info("Cacic Daemon (Timer)", QString("getTeste() success."));
  56 + if(getConfig()){
  57 + QLogger::QLog_Info("Cacic Daemon (Timer)", QString("getConfig() success."));
  58 + // QStringList nomesModulos = verificarModulos();
  59 + // if ( !nomesModulos.empty() ) {
  60 + // foreach( QString nome, nomesModulos ) {
  61 + QString nome = "gercols";
  62 + definirDirModulo(getApplicationDirPath(), nome);
  63 + cacicthread->setCcacic(ccacic);
  64 + cacicthread->setOCacicComm(OCacicComm);
  65 + cacicthread->setNomeModulo(nome);
  66 + cacicthread->setCMutex(cMutex);
  67 + cacicthread->setModuloDirPath(getDirProgram());
  68 + cacicthread->start(QThread::NormalPriority);
  69 + // if(nome == "gercols" ){
  70 + // //Envio do json gerado na coleta
  71 + // bool ok = false;
  72 + // QJsonObject jsonColeta = ccacic->getJsonFromFile(this->applicationDirPath + "/coleta.json");
  73 + // OCacicComm->comm("/ws/neo/coleta", &ok, jsonColeta , false);
  74 + // if(&ok){
  75 + // QLogger::QLog_Info("Cacic Daemon (Timer)", QString("coleta enviada com sucesso."));
  76 + // }
  77 + // }
  78 + }else{
  79 + QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração.");
  80 + }
77 }else{ 81 }else{
78 - QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração."); 82 + QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na execução do getTest().");
79 } 83 }
80 - }else{  
81 - QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na execução do getTest().");  
82 } 84 }
83 } 85 }
84 86
85 87
86 -void CacicTimer::verificarEIniciarQMutex(){ 88 +bool CacicTimer::verificarEIniciarQMutex(){
87 if(!cacicthread->isRunning()){ 89 if(!cacicthread->isRunning()){
88 cMutex->lock(); 90 cMutex->lock();
89 QLogger::QLog_Info("Cacic Daemon (Timer)", "Semáforo fechado com sucesso."); 91 QLogger::QLog_Info("Cacic Daemon (Timer)", "Semáforo fechado com sucesso.");
@@ -94,10 +96,11 @@ void CacicTimer::verificarEIniciarQMutex(){ @@ -94,10 +96,11 @@ void CacicTimer::verificarEIniciarQMutex(){
94 QLogger::QLog_Info("Cacic Daemon (Timer)", "Gercols finalizado com sucesso."); 96 QLogger::QLog_Info("Cacic Daemon (Timer)", "Gercols finalizado com sucesso.");
95 }catch (...){ 97 }catch (...){
96 QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha ao finalizar gercols."); 98 QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha ao finalizar gercols.");
97 - return; 99 + return false;
98 } 100 }
99 cMutex->lock(); 101 cMutex->lock();
100 QLogger::QLog_Info("Cacic Daemon (Timer)", "Semáforo fechado com sucesso."); 102 QLogger::QLog_Info("Cacic Daemon (Timer)", "Semáforo fechado com sucesso.");
  103 + return true;
101 } 104 }
102 } 105 }
103 106
@@ -120,7 +123,7 @@ bool CacicTimer::getTest(){ @@ -120,7 +123,7 @@ bool CacicTimer::getTest(){
120 try{ 123 try{
121 ccacic->setJsonToFile(jsonresult.contains("reply") ? jsonresult["reply"].toObject() : jsonresult, 124 ccacic->setJsonToFile(jsonresult.contains("reply") ? jsonresult["reply"].toObject() : jsonresult,
122 this->applicationDirPath + "/getTest.json"); 125 this->applicationDirPath + "/getTest.json");
123 - return true; //acho que seria melhor retornar a variável 'ok'. Se der erro na conexão eu acho que não cai no catch. 126 + return ok;
124 } catch (...) { 127 } catch (...) {
125 qDebug() << "Erro ao salvar o arquivo de configurações."; 128 qDebug() << "Erro ao salvar o arquivo de configurações.";
126 return false; 129 return false;
@@ -146,7 +149,7 @@ bool CacicTimer::getConfig(){ @@ -146,7 +149,7 @@ bool CacicTimer::getConfig(){
146 try{ 149 try{
147 ccacic->setJsonToFile(jsonresult.contains("reply") ? jsonresult["reply"].toObject() : jsonresult, 150 ccacic->setJsonToFile(jsonresult.contains("reply") ? jsonresult["reply"].toObject() : jsonresult,
148 this->applicationDirPath + "/getConfigNew.json"); 151 this->applicationDirPath + "/getConfigNew.json");
149 - return true; //mesma observação do getTest 152 + return ok;
150 } catch (...) { 153 } catch (...) {
151 qDebug() << "Erro ao salvar o arquivo de configurações."; 154 qDebug() << "Erro ao salvar o arquivo de configurações.";
152 return false; 155 return false;
@@ -157,47 +160,6 @@ bool CacicTimer::getConfig(){ @@ -157,47 +160,6 @@ bool CacicTimer::getConfig(){
157 } 160 }
158 } 161 }
159 162
160 -void CacicTimer::lerArquivoConfig ( const QJsonObject& jsonConfig )  
161 -{  
162 - /* lê json de configurações e armazena quais módulos executáveis.  
163 - * E faz o mesmo tipo de comparação de hashs, com o fim de:  
164 - * ou mantem o binário do módulo ou baixa um novo.  
165 - */  
166 - foreach( QJsonValue individualModule, jsonConfig["modulos"].toArray() ) {  
167 - QString moduloKey, moduloValue;  
168 -  
169 - moduloKey = individualModule.toObject()["hash"].toString();  
170 - moduloValue = individualModule.toObject()["nome"].toString();  
171 -  
172 - moduleMap.insert(moduloKey, moduloValue);  
173 - }  
174 -  
175 - if ( jsonConfig["metodoDownload"].isArray() ) {  
176 -  
177 - foreach (QJsonValue individualMetodo, jsonConfig["metodoDownload"].toArray() ) {  
178 - QMap<QString, QString> newEntry;  
179 -  
180 - newEntry.insert(QString("tipo"), individualMetodo.toObject()["tipo"].toString() );  
181 - newEntry.insert(QString("url"), individualMetodo.toObject()["url"].toString() );  
182 - newEntry.insert(QString("path"), individualMetodo.toObject()["path"].toString() );  
183 - newEntry.insert(QString("usuario"), individualMetodo.toObject()["usario"].toString() );  
184 - newEntry.insert(QString("senha"), individualMetodo.toObject()["senha"].toString() );  
185 -  
186 - metodosDownload.append( newEntry );  
187 - }  
188 - } else {  
189 - QMap<QString, QString> newEntry;  
190 -  
191 - newEntry.insert(QString("tipo"), jsonConfig["metodoDownload"].toObject()["tipo"].toString() );  
192 - newEntry.insert(QString("url"), jsonConfig["metodoDownload"].toObject()["url"].toString() );  
193 - newEntry.insert(QString("path"), jsonConfig["metodoDownload"].toObject()["path"].toString() );  
194 - newEntry.insert(QString("usuario"), jsonConfig["metodoDownload"].toObject()["usario"].toString() );  
195 - newEntry.insert(QString("senha"), jsonConfig["metodoDownload"].toObject()["senha"].toString() );  
196 -  
197 - metodosDownload.append( newEntry );  
198 - }  
199 -}  
200 -  
201 QString CacicTimer::getDirProgram() const 163 QString CacicTimer::getDirProgram() const
202 { 164 {
203 return dirProgram; 165 return dirProgram;
@@ -271,94 +233,3 @@ void CacicTimer::setPeriodicidadeExecucao(int value) @@ -271,94 +233,3 @@ void CacicTimer::setPeriodicidadeExecucao(int value)
271 { 233 {
272 periodicidadeExecucao = value; 234 periodicidadeExecucao = value;
273 } 235 }
274 -  
275 -  
276 -QStringList CacicTimer::verificarModulos(){  
277 - // Compara o novo arquivo de configuração com um antigo e se forem diferentes  
278 - // mantem o mais recente; caso iguais simplesmente apaga o novo.  
279 - QFile *fileOld;  
280 - QFile *fileNew;  
281 -  
282 - fileOld = new QFile(this->applicationDirPath + "/getConfig.json");  
283 - fileNew = new QFile(this->applicationDirPath + "/getConfigNew.json");  
284 -  
285 - if( fileOld->exists() && fileNew->exists() ){  
286 - if( Md5IsEqual(QVariant::fromValue(fileOld), QVariant::fromValue(fileNew)) ) {  
287 - fileNew->remove();  
288 - } else {  
289 - // Renomeia getConfigNew.json para getConfig.json  
290 - fileOld->remove();  
291 - fileNew->rename("getConfigNew.json","getConfig.json");  
292 - }  
293 - jsonConfig = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json");  
294 - } else if( fileOld->exists() ){  
295 - jsonConfig = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json");  
296 - } else {  
297 - QLogger::QLog_Error("Cacic Daemon (Timer)", "Arquivo de configuração não criado.");  
298 - }  
299 - delete fileOld;  
300 - delete fileNew;  
301 - lerArquivoConfig(jsonConfig["agentcomputer"].toObject());  
302 -  
303 - QStringList nomesModulos;  
304 -  
305 - int countExecNotFound = 0;  
306 - QMap<QString, QString>::const_iterator moduloIterator = moduleMap.constBegin();  
307 - while (moduloIterator != moduleMap.constEnd()) {  
308 - QString nomeModulo = moduloIterator.value();  
309 - QString hashModulo = moduloIterator.key();  
310 - // Calcula hash do binario atual  
311 -#if defined(Q_OS_WIN)  
312 - fileOld = new QFile(this->applicationDirPath + "/" + nomeModulo + ".exe");  
313 -#else  
314 - fileOld = new QFile(this->applicationDirPath + "/" + nomeModulo);  
315 -#endif  
316 - if(!fileOld->exists()) {  
317 - QLogger::QLog_Error("Cacic Daemon (Timer)", QString("Módulo ").append(nomeModulo).append(" não encontrado."));  
318 - countExecNotFound++;  
319 -  
320 - if( countExecNotFound == moduleMap.size() ) {  
321 - QLogger::QLog_Error("Cacic Daemon (Timer)", "Não foi possível encontrar nenhum módulo executável!");  
322 - return QStringList();  
323 - }  
324 -  
325 - // pula para o próximo módulo no moduloMap  
326 - moduloIterator++;  
327 - continue;  
328 - }  
329 -  
330 - QString oldMd5 = QString(QCryptographicHash::hash(fileOld->readAll(),QCryptographicHash::Md5).toHex());  
331 - if ( oldMd5 != hashModulo ) {  
332 -  
333 -#if defined(Q_OS_WIN)  
334 - fileOld->rename(this->applicationDirPath + "/" + nomeModulo + ".exe",  
335 - this->applicationDirPath + "/" + nomeModulo + "Old.exe");  
336 -#elif defined(Q_OS_LINUX)  
337 - fileOld->rename(this->applicationDirPath + "/" + nomeModulo,  
338 - this->applicationDirPath + "/" + nomeModulo + "Old");  
339 -#endif  
340 -  
341 - // Download nova versão do executável  
342 - QList<QMap<QString,QString> >::const_iterator metodosIterator = metodosDownload.constBegin();  
343 - bool downloadSucess = false;  
344 - while ( !downloadSucess && metodosIterator != metodosDownload.constEnd() ) {  
345 - if( metodosIterator->value("tipo") == "ftp" || metodosIterator->value("tipo") == "" ) {  
346 - if ( OCacicComm->ftpDownload( metodosIterator->value("url"), metodosIterator->value("path") ) )  
347 - downloadSucess = true;  
348 - } else if ( metodosIterator->value("tipo") == "http" ) {  
349 - if( OCacicComm->httpDownload( metodosIterator->value("url"), metodosIterator->value("path") ) )  
350 - downloadSucess = true;  
351 - }  
352 - metodosIterator++;  
353 - }  
354 - fileOld->remove();  
355 - delete fileOld;  
356 - }  
357 -  
358 - nomesModulos.append(nomeModulo);  
359 -  
360 - moduloIterator++;  
361 - }  
362 -  
363 - return nomesModulos;  
364 -}  
cacic-daemon/cacicD/cacictimer.h
@@ -35,7 +35,7 @@ public: @@ -35,7 +35,7 @@ public:
35 void setPeriodicidadeExecucao(int value); 35 void setPeriodicidadeExecucao(int value);
36 36
37 private: 37 private:
38 - void verificarEIniciarQMutex(); 38 + bool verificarEIniciarQMutex();
39 QStringList verificarModulos(); 39 QStringList verificarModulos();
40 void reiniciarTimer(); 40 void reiniciarTimer();
41 QLogger::QLoggerManager *logManager; 41 QLogger::QLoggerManager *logManager;
@@ -50,8 +50,6 @@ private: @@ -50,8 +50,6 @@ private:
50 QJsonObject jsonConfig; 50 QJsonObject jsonConfig;
51 int periodicidadeExecucao = 14400; // 4*3600. Tempo default de execução. 51 int periodicidadeExecucao = 14400; // 4*3600. Tempo default de execução.
52 int getPeriodicidadeExecucao() const; 52 int getPeriodicidadeExecucao() const;
53 - QList<QMap<QString,QString> > metodosDownload;  
54 - QMap<QString, QString> moduleMap; // key = hash md5, value = nome do modulo  
55 53
56 private slots: 54 private slots:
57 void mslot(); 55 void mslot();
cacic-teste/cacic-teste.pro
@@ -31,7 +31,8 @@ SOURCES += \ @@ -31,7 +31,8 @@ SOURCES += \
31 ../src/vregistry.cpp \ 31 ../src/vregistry.cpp \
32 ../src/ccoleta.cpp \ 32 ../src/ccoleta.cpp \
33 ../src/wmi.cpp \ 33 ../src/wmi.cpp \
34 - ../src/QLogger.cpp 34 + ../src/QLogger.cpp \
  35 + ../src/checkmodules.cpp
35 # ../src/qtservice/src/qtservice.cpp \ 36 # ../src/qtservice/src/qtservice.cpp \
36 # ../src/qtservice/src/qtservice_unix.cpp \ 37 # ../src/qtservice/src/qtservice_unix.cpp \
37 # ../src/qtservice/src/qtservice_win.cpp \ 38 # ../src/qtservice/src/qtservice_win.cpp \
@@ -52,7 +53,8 @@ HEADERS += \ @@ -52,7 +53,8 @@ HEADERS += \
52 ../src/vregistry.h \ 53 ../src/vregistry.h \
53 ../src/ccoleta.h \ 54 ../src/ccoleta.h \
54 ../src/wmi.h \ 55 ../src/wmi.h \
55 - ../src/QLogger.h 56 + ../src/QLogger.h \
  57 + ../src/checkmodules.h
56 # ../src/qtservice/src/qtservice.h \ 58 # ../src/qtservice/src/qtservice.h \
57 # ../src/qtservice/src/qtservice_p.h \ 59 # ../src/qtservice/src/qtservice_p.h \
58 # ../src/qtservice/src/qtunixserversocket.h \ 60 # ../src/qtservice/src/qtunixserversocket.h \
cacic-teste/testcacic.cpp
@@ -246,18 +246,14 @@ void CTestCacic::testGetTest() @@ -246,18 +246,14 @@ void CTestCacic::testGetTest()
246 QVERIFY(ok); 246 QVERIFY(ok);
247 } 247 }
248 248
249 -void CTestCacic::testColeta() 249 +void CTestCacic::testGetConfig()
250 { 250 {
251 bool ok; 251 bool ok;
252 QJsonObject configEnvio; 252 QJsonObject configEnvio;
253 configEnvio["computador"] = oColeta.getOComputer().toJsonObject(); 253 configEnvio["computador"] = oColeta.getOComputer().toJsonObject();
254 - OCacic.setJsonToFile(OCacicComm->comm("/ws/neo/config", &ok, configEnvio), "getConfig.json");  
255 - oColeta.configuraColetas();  
256 - oColeta.run();  
257 - oColeta.waitToCollect(); 254 + OCacic.setJsonToFile(OCacicComm->comm("/ws/neo/config", &ok, configEnvio)["reply"].toObject(), "getConfig.json");
258 255
259 - QVERIFY(!oColeta.toJsonObject()["software"].toObject().isEmpty() &&  
260 - !oColeta.toJsonObject()["hardware"].toObject().isEmpty()); 256 + QVERIFY(ok);
261 } 257 }
262 258
263 void CTestCacic::testLogger() 259 void CTestCacic::testLogger()
@@ -334,6 +330,12 @@ void CTestCacic::testEnviaColeta() @@ -334,6 +330,12 @@ void CTestCacic::testEnviaColeta()
334 QVERIFY(ok); 330 QVERIFY(ok);
335 } 331 }
336 332
  333 +void CTestCacic::testGetModulesValues()
  334 +{
  335 + oCheckModules = new CheckModules(QDir::currentPath());
  336 + QVERIFY(false);
  337 +}
  338 +
337 void CTestCacic::cleanupTestCase() 339 void CTestCacic::cleanupTestCase()
338 { 340 {
339 // OCacic.deleteFile("gpl-2.0.txt"); 341 // OCacic.deleteFile("gpl-2.0.txt");
@@ -347,5 +349,5 @@ void CTestCacic::cleanupTestCase() @@ -347,5 +349,5 @@ void CTestCacic::cleanupTestCase()
347 OCacic.deleteFolder("../logs"); 349 OCacic.deleteFolder("../logs");
348 OCacic.deleteFile("configRequest.json"); 350 OCacic.deleteFile("configRequest.json");
349 OCacic.deleteFile("teste.json"); 351 OCacic.deleteFile("teste.json");
350 - OCacic.deleteFile("getConfig.json"); 352 +// OCacic.deleteFile("getConfig.json");
351 } 353 }
cacic-teste/testcacic.h
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
18 #include <QJsonObject> 18 #include <QJsonObject>
19 #include <ccoleta.h> 19 #include <ccoleta.h>
20 #include <QLogger.h> 20 #include <QLogger.h>
  21 +#include <checkmodules.h>
21 22
22 class CTestCacic : public QObject 23 class CTestCacic : public QObject
23 { 24 {
@@ -36,6 +37,7 @@ private: @@ -36,6 +37,7 @@ private:
36 QJsonObject session; 37 QJsonObject session;
37 QString cripTeste; 38 QString cripTeste;
38 CColeta oColeta; 39 CColeta oColeta;
  40 + CheckModules *oCheckModules;
39 // cacicD OcacicD; 41 // cacicD OcacicD;
40 42
41 signals: 43 signals:
@@ -73,10 +75,11 @@ private slots: @@ -73,10 +75,11 @@ private slots:
73 void testColetaHardware(); 75 void testColetaHardware();
74 void testConvertDouble(); 76 void testConvertDouble();
75 void testGetTest(); 77 void testGetTest();
76 - void testColeta(); 78 + void testGetConfig();
77 void testLogger(); 79 void testLogger();
78 void testFtpDownload(); 80 void testFtpDownload();
79 void testEnviaColeta(); 81 void testEnviaColeta();
  82 + void testGetModulesValues();
80 void cleanupTestCase(); 83 void cleanupTestCase();
81 }; 84 };
82 85
src/checkmodules.cpp
1 #include "checkmodules.h" 1 #include "checkmodules.h"
2 2
3 -CheckModules::CheckModules() 3 +CheckModules::CheckModules(const QString &workingPath)
4 { 4 {
  5 + QJsonObject configFile;
  6 + configFile = oCacic.getJsonFromFile(workingPath + "/getConfig.json");
  7 + if (!configFile.isEmpty()) {
  8 + QJsonArray modulos;
  9 + modulos = configFile["agentcomputer"].toObject()["modulos"].toArray();
  10 + foreach (QJsonValue modulo, modulos){
  11 + modules[modulo.toObject()["nome"].toString()] = modulo.toObject()["hash"].toString();
  12 + }
  13 + }
  14 + //TODO: Completar constructor. Agora que tenho os nomes dos módulos e os hashs, fazer a verificação.
  15 + qDebug() << modules;
5 } 16 }
  17 +
  18 +bool CheckModules::start(){
  19 + return true;
  20 +}
  21 +
  22 +//QStringList CheckModules::verificaModulos(){
  23 +// // 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.
  25 +// QFile *fileOld;
  26 +// QFile *fileNew;
  27 +
  28 +// fileOld = new QFile(this->applicationDirPath + "/getConfig.json");
  29 +// fileNew = new QFile(this->applicationDirPath + "/getConfigNew.json");
  30 +
  31 +// if( fileOld->exists() && fileNew->exists() ){
  32 +// if( Md5IsEqual(QVariant::fromValue(fileOld), QVariant::fromValue(fileNew)) ) {
  33 +// fileNew->remove();
  34 +// } else {
  35 +// // Renomeia getConfigNew.json para getConfig.json
  36 +// fileOld->remove();
  37 +// fileNew->rename("getConfigNew.json","getConfig.json");
  38 +// }
  39 +// jsonConfig = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json");
  40 +// } else if( fileOld->exists() ){
  41 +// jsonConfig = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json");
  42 +// } else {
  43 +// QLogger::QLog_Error("Cacic Daemon (Timer)", "Arquivo de configuração não criado.");
  44 +// }
  45 +// delete fileOld;
  46 +// delete fileNew;
  47 +// lerArquivoConfig(jsonConfig["agentcomputer"].toObject());
  48 +
  49 +// QStringList nomesModulos;
  50 +
  51 +// int countExecNotFound = 0;
  52 +// QMap<QString, QString>::const_iterator moduloIterator = moduleMap.constBegin();
  53 +// while (moduloIterator != moduleMap.constEnd()) {
  54 +// QString nomeModulo = moduloIterator.value();
  55 +// QString hashModulo = moduloIterator.key();
  56 +// // Calcula hash do binario atual
  57 +//#if defined(Q_OS_WIN)
  58 +// fileOld = new QFile(this->applicationDirPath + "/" + nomeModulo + ".exe");
  59 +//#else
  60 +// fileOld = new QFile(this->applicationDirPath + "/" + nomeModulo);
  61 +//#endif
  62 +// if(!fileOld->exists()) {
  63 +// QLogger::QLog_Error("Cacic Daemon (Timer)", QString("Módulo ").append(nomeModulo).append(" não encontrado."));
  64 +// countExecNotFound++;
  65 +
  66 +// if( countExecNotFound == moduleMap.size() ) {
  67 +// QLogger::QLog_Error("Cacic Daemon (Timer)", "Não foi possível encontrar nenhum módulo executável!");
  68 +// return QStringList();
  69 +// }
  70 +
  71 +// // pula para o próximo módulo no moduloMap
  72 +// moduloIterator++;
  73 +// continue;
  74 +// }
  75 +
  76 +// QString oldMd5 = QString(QCryptographicHash::hash(fileOld->readAll(),QCryptographicHash::Md5).toHex());
  77 +// if ( oldMd5 != hashModulo ) {
  78 +
  79 +//#if defined(Q_OS_WIN)
  80 +// fileOld->rename(this->applicationDirPath + "/" + nomeModulo + ".exe",
  81 +// this->applicationDirPath + "/" + nomeModulo + "Old.exe");
  82 +//#elif defined(Q_OS_LINUX)
  83 +// fileOld->rename(this->applicationDirPath + "/" + nomeModulo,
  84 +// this->applicationDirPath + "/" + nomeModulo + "Old");
  85 +//#endif
  86 +
  87 +// // Download nova versão do executável
  88 +// QList<QMap<QString,QString> >::const_iterator metodosIterator = metodosDownload.constBegin();
  89 +// bool downloadSucess = false;
  90 +// while ( !downloadSucess && metodosIterator != metodosDownload.constEnd() ) {
  91 +// if( metodosIterator->value("tipo") == "ftp" || metodosIterator->value("tipo") == "" ) {
  92 +// if ( OCacicComm->ftpDownload( metodosIterator->value("url"), metodosIterator->value("path") ) )
  93 +// downloadSucess = true;
  94 +// } else if ( metodosIterator->value("tipo") == "http" ) {
  95 +// if( OCacicComm->httpDownload( metodosIterator->value("url"), metodosIterator->value("path") ) )
  96 +// downloadSucess = true;
  97 +// }
  98 +// metodosIterator++;
  99 +// }
  100 +// fileOld->remove();
  101 +// delete fileOld;
  102 +// }
  103 +
  104 +// nomesModulos.append(nomeModulo);
  105 +
  106 +// moduloIterator++;
  107 +// }
  108 +
  109 +// return nomesModulos;
  110 +//}
  111 +
  112 +//void CheckModules::lerArquivoConfig ( const QJsonObject& jsonConfig )
  113 +//{
  114 +// /* lê json de configurações e armazena quais módulos executáveis.
  115 +// * E faz o mesmo tipo de comparação de hashs, com o fim de:
  116 +// * ou mantem o binário do módulo ou baixa um novo.
  117 +// */
  118 +// foreach( QJsonValue individualModule, jsonConfig["modulos"].toArray() ) {
  119 +// QString moduloKey, moduloValue;
  120 +
  121 +// moduloKey = individualModule.toObject()["hash"].toString();
  122 +// moduloValue = individualModule.toObject()["nome"].toString();
  123 +
  124 +// moduleMap.insert(moduloKey, moduloValue);
  125 +// }
  126 +
  127 +// if ( jsonConfig["metodoDownload"].isArray() ) {
  128 +
  129 +// foreach (QJsonValue individualMetodo, jsonConfig["metodoDownload"].toArray() ) {
  130 +// QMap<QString, QString> newEntry;
  131 +
  132 +// newEntry.insert(QString("tipo"), individualMetodo.toObject()["tipo"].toString() );
  133 +// newEntry.insert(QString("url"), individualMetodo.toObject()["url"].toString() );
  134 +// newEntry.insert(QString("path"), individualMetodo.toObject()["path"].toString() );
  135 +// newEntry.insert(QString("usuario"), individualMetodo.toObject()["usario"].toString() );
  136 +// newEntry.insert(QString("senha"), individualMetodo.toObject()["senha"].toString() );
  137 +
  138 +// metodosDownload.append( newEntry );
  139 +// }
  140 +// } else {
  141 +// QMap<QString, QString> newEntry;
  142 +
  143 +// newEntry.insert(QString("tipo"), jsonConfig["metodoDownload"].toObject()["tipo"].toString() );
  144 +// newEntry.insert(QString("url"), jsonConfig["metodoDownload"].toObject()["url"].toString() );
  145 +// newEntry.insert(QString("path"), jsonConfig["metodoDownload"].toObject()["path"].toString() );
  146 +// newEntry.insert(QString("usuario"), jsonConfig["metodoDownload"].toObject()["usario"].toString() );
  147 +// newEntry.insert(QString("senha"), jsonConfig["metodoDownload"].toObject()["senha"].toString() );
  148 +
  149 +// metodosDownload.append( newEntry );
  150 +// }
  151 +//}
src/checkmodules.h
1 #ifndef CHECKMODULES_H 1 #ifndef CHECKMODULES_H
2 #define CHECKMODULES_H 2 #define CHECKMODULES_H
3 3
  4 +#include <ccacic.h>
  5 +#include <cacic_comm.h>
  6 +#include <cacic_computer.h>
  7 +
4 class CheckModules 8 class CheckModules
5 { 9 {
6 public: 10 public:
7 - CheckModules(); 11 + CheckModules(const QString &workingPath);
  12 +// QStringList verificaModulos();
  13 + bool start();
  14 +private:
  15 + CCacic oCacic;
  16 + QVariantMap modules; //modules["name"] = hash;
  17 +// void lerArquivoConfig(const QJsonObject& jsonConfig);
8 }; 18 };
9 19
10 #endif // CHECKMODULES_H 20 #endif // CHECKMODULES_H