Commit 9989db7c3bb17b08e44c65b7b71dcaafb1cd7ced
1 parent
c4982c45
Exists in
master
Concluída base para processamento após obtenção do getConfig, mas assumindo como…
… está o .json e parte de download de executável incompleta.
Showing
2 changed files
with
99 additions
and
16 deletions
Show diff stats
cacic-daemon/cacicD/cacictimer.cpp
... | ... | @@ -6,9 +6,37 @@ CacicTimer::CacicTimer() |
6 | 6 | ccacic = new CCacic(); |
7 | 7 | timer = new QTimer(this); |
8 | 8 | logManager = QLogger::QLoggerManager::getInstance(); |
9 | + | |
10 | + OCacicComm = CacicComm("http://teste.cacic.cc", | |
11 | + "rG/HcIDVTZ3pPKCf[[MAIS]]I6aigUb7OMeij3FfC7qNaznk0rBRYb6q6kSK3eNfjgptS8BfwW5yJqCvD2ai7xlw9I6P21j6cvQUqlHmAJpCbfwR13urdRE9AhjfokMcPrH6R1/zXPGMHveLRRgKLcqWu2X96rmoQQdRq9EW1SXmYUAx1dCV[[MAIS]]3Ha61XBw5pq58q35zH8Gjt998rTi3ecV8ShXXevqyK[[MAIS]]W07xpgTjbbd6Fbs/35gPfdRRgMNFjq7Gq[[MAIS]]llFgYMJ6UcEhw8f0ZLQo2oL/eRW/CNyeBW6wG0hIo6EIdpi/Ht0/95Uwn2Og[[MAIS]]2UPXsmKKuTMeGwUvPdbEfexlinUO0[[MAIS]]j9qIa2dpjtl0Y5Fyk1Bvw2ZYRTXwgJpUHsBboWmtTFpgX3wSGOWMipE80K8ktRTVYOp[[MAIS]]4qS/SzKWXpfCuZoCncfwE0lCEoreTH[[MAIS]]MLrTkHJP2oqYMAyFyQcjC0UGr3BQGa2edSNXjG7jrTdddga/SODUiF94jgh/QBwhiZby34b__CRYPTED__", | |
12 | + "P198PVwtz5F5CfZPSUrzuaQA/QG1sTnwzl/rBnj8M7y5MglANGodG5LLD4q7oY809HuDR4g5tL64lZRBKvKPmEgWd9iAZKvT4UAm9XWN3nKKLGaznCaJohmntNGqrJP1Zd9riTHGu10mPbg/Uh3TCbBHVOICvu5sDl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hcd3gt3SzjMLE0M[[MAIS]]hTmHG1KP2CzCibZ7grFAN3Y3jSPjmEj5Fzs26tdhdjNzSIt1FCueea8P2c4NmxPYkJCg0D1mgNrkH3L5svsO[[MAIS]]6YYrl3df4s[[MAIS]]fcK/to9s/pnkKfBKrAPF6Z4s2WPsALUPBDS5ty7RC2vqXRvH6hPR4o7xhXzQOQ/1xytr/RoEWEVeZ2wgHVVbbtFsALul/IDc7B45wmwxBx9iZHVwpQJVlNZZUBtwKqKhnXz5pM[[MAIS]]7yUAkfhMcO09pPd5kB2MBdRJs[[MAIS]]2FIk0GRUw05IHkc1rZEX5Ow==__CRYPTED__", | |
20 | + "Yot8BeM9lOh431SB7dYQXw==__CRYPTED__", | |
21 | + "Dcr8b5IfZOJjt6qyH5dGyw==__CRYPTED__", | |
22 | + "2.5.1.1.256.32", | |
23 | + "2.8.1.7", | |
24 | + "2.8.1.6"); | |
25 | + OCacicComm->setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php"); | |
26 | + OCacicComm->setUsuario("cacic"); | |
27 | + OCacicComm->setPassword("cacic123"); | |
28 | + | |
9 | 29 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); |
10 | 30 | } |
11 | 31 | |
32 | +CacicTimer::~CacicTimer() | |
33 | +{ | |
34 | + logManager->closeLogger(); | |
35 | + delete logManager; | |
36 | + delete ccacic; | |
37 | + delete OCacicComm; | |
38 | +} | |
39 | + | |
12 | 40 | void CacicTimer::iniciarTimer(int x, QString applicationDirPath) |
13 | 41 | { |
14 | 42 | setApplicationDirPath(applicationDirPath); |
... | ... | @@ -26,36 +54,88 @@ void CacicTimer::mslot(){ |
26 | 54 | |
27 | 55 | // Compara o novo arquivo de configuração com um antigo e se forem diferentes |
28 | 56 | // mantem o mais recente; caso iguais simplesmente apaga o novo. |
29 | - QFile *fileConfig = new QFile(getApplicationDirPath().append("/getConfig.json")); | |
30 | - QFile *fileConfigNew = new QFile(getApplicationDirPath().append("/getConfigNew.json")); | |
31 | - | |
32 | - if( fileConfig->exists() && fileConfigNew->exists() ){ | |
33 | - if( Md5IsEqual(QVariant::fromValue(fileConfig), QVariant::fromValue(fileConfigNew)) ) { | |
34 | - fileConfigNew->remove(); | |
35 | - delete fileConfigNew; | |
57 | + QFile *fileOld; | |
58 | + QFile *fileNew; | |
59 | + | |
60 | + fileOld = new QFile(getApplicationDirPath().append("/getConfig.json")); | |
61 | + fileNew = new QFile(getApplicationDirPath().append("/getConfigNew.json")); | |
62 | + if( fileOld->exists() && fileNew->exists() ){ | |
63 | + if( Md5IsEqual(QVariant::fromValue(fileOld), QVariant::fromValue(fileNew)) ) { | |
64 | + fileNew->remove(); | |
36 | 65 | } else { |
37 | 66 | // Renomeia getConfigNew.json para getConfig.json |
38 | - fileConfig->remove(); | |
39 | - delete fileConfig; | |
40 | - fileConfigNew->rename("getConfigNew.json","getConfig.json"); | |
41 | - delete fileConfigNew; | |
67 | + fileOld->remove(); | |
68 | + fileNew->rename("getConfigNew.json","getConfig.json"); | |
42 | 69 | } |
43 | 70 | jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); |
44 | - } else if( fileConfig->exists() ){ | |
71 | + } else if( fileOld->exists() ){ | |
45 | 72 | jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); |
46 | 73 | } else { |
47 | 74 | QLogger::QLog_Error("Cacic Daemon", "Arquivo de configuração não criado."); |
48 | 75 | } |
76 | + delete fileOld; | |
77 | + delete fileNew; | |
49 | 78 | |
50 | 79 | /* lê json de configurações e armazena quais módulos executáveis. |
51 | 80 | * E faz o mesmo tipo de comparação de hashs, com o fim de: |
52 | 81 | * ou mantem o binário do módulo ou baixa um novo. |
53 | 82 | */ |
54 | - foreach( QVariant vectorsContent, jsonConfig["modulos"].toArray().toVariantList().toVector() ) | |
55 | - moduleList.append( vectorsContent.toString() ); | |
56 | 83 | |
57 | - foreach( QString modulo, moduleList ) { | |
84 | + /* Aqui estou assumindo um formato do .json em que: | |
85 | + * há a key modulos contem uma lista com o nome dos executaveis e os seus valores hash md5 | |
86 | + * há a key metodo que explicita o método de download dos executaveis | |
87 | + */ | |
88 | + foreach( QJsonValue moduloValues, jsonConfig["modulos"].toArray() ) { | |
89 | + QString moduloKey, moduloValue; | |
90 | + | |
91 | + moduloKey = moduloValues.toObject()["md5"].toString(); | |
92 | + moduloValue = moduloValues.toObject()["nome"].toString(); | |
93 | + | |
94 | + moduleMap.insert(moduloKey, moduloValue); | |
95 | + } | |
96 | + metodoDownload = jsonConfig["metodo"].toString(); | |
97 | + | |
98 | + int countExecNotFound = 0; | |
99 | + QMap<QString, QString>::const_iterator mapIterator = moduleMap.constBegin(); | |
100 | + while (mapIterator != moduleMap.constEnd()) { | |
101 | + QString nomeModulo = mapIterator.value(); | |
102 | + QString hashModulo = mapIterator.key(); | |
103 | + | |
104 | + // Calcula hash do binario atual | |
105 | +#if defined(Q_OS_WIN) | |
106 | + fileOld = new QFile(getApplicationDirPath().append("/").append(modulo).append(".exe")); | |
107 | +#else | |
108 | + fileOld = new QFile(getApplicationDirPath().append("/").append(nomeModulo)); | |
109 | +#endif | |
110 | + if(!fileOld->exists()) { | |
111 | + QLogger::QLog_Error("Cacic Daemon", QString("Módulo ").append(nomeModulo).append(" não encontrado.")); | |
112 | + | |
113 | + countExecNotFound++; | |
114 | + if( countExecNotFound == moduleMap.size() ) { | |
115 | + QLogger::QLog_Error("Cacic Daemon", "Não foi possível encontrar nenhum módulo executável!"); | |
116 | + return; | |
117 | + } | |
118 | + continue; | |
119 | + } | |
120 | + | |
121 | + QString oldMd5 = QString(QCryptographicHash::hash(fileOld->readAll(),QCryptographicHash::Md5).toHex()); | |
122 | + | |
123 | + if ( oldMd5 != hashModulo ) { | |
124 | + | |
125 | + fileOld->rename(getApplicationDirPath().append("/").append(nomeModulo), | |
126 | + getApplicationDirPath().append("/").append("nomeModulo").append("Old") ); | |
127 | + | |
128 | + // Download nova versão do executável | |
129 | + if(metodoDownload == "ftp" || metodoDownload == "") { | |
130 | +// OCacicComm->ftpDownload( QString("/ws/get/").append(nomeModulo) ); | |
131 | + } | |
132 | + | |
133 | + | |
134 | + fileOld->remove(); | |
135 | + delete fileOld; | |
136 | + } | |
58 | 137 | |
138 | + mapIterator++; | |
59 | 139 | } |
60 | 140 | |
61 | 141 | //aqui irá abrir o semaforo e iniciar a coleta. | ... | ... |
cacic-daemon/cacicD/cacictimer.h
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | #include <QDebug> |
6 | 6 | #include <QDir> |
7 | 7 | #include <QDateTime> |
8 | +#include <QMap> | |
8 | 9 | #include "ccacic.h" |
9 | 10 | #include "cacic_comm.h" |
10 | 11 | #include "cacic_computer.h" |
... | ... | @@ -34,7 +35,9 @@ private: |
34 | 35 | QJsonObject jsonConfig; |
35 | 36 | QLogger::QLoggerManager *logManager; |
36 | 37 | QString applicationDirPath; |
37 | - QStringList moduleList; | |
38 | + QString metodoDownload; | |
39 | + QMap<QString, QString> moduleMap; // key = hash md5, value = nome do modulo | |
40 | + | |
38 | 41 | |
39 | 42 | private slots: |
40 | 43 | void mslot(); | ... | ... |