Commit 1d0c0bfec0121a41ce2388f23c8d4211f6d2f377
1 parent
abdd064e
Exists in
master
Algumas mudanças no install-cacic; e começando já a comparação de binários locai…
…s e do servidor de acordo com o getConfig().
Showing
6 changed files
with
63 additions
and
12 deletions
Show diff stats
cacic-daemon/cacicD/cacicd.cpp
@@ -36,6 +36,7 @@ void cacicD::start() { | @@ -36,6 +36,7 @@ void cacicD::start() { | ||
36 | QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em ").append(application()->applicationDirPath()).append(".")); | 36 | QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em ").append(application()->applicationDirPath()).append(".")); |
37 | 37 | ||
38 | QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath() + "/getConfig.json"); | 38 | QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath() + "/getConfig.json"); |
39 | + | ||
39 | if(!result.contains("error") && !result.isEmpty()){ | 40 | if(!result.contains("error") && !result.isEmpty()){ |
40 | Ocacictimer->iniciarTimer(result["codestatus"].toInt(), application()->applicationDirPath()); | 41 | Ocacictimer->iniciarTimer(result["codestatus"].toInt(), application()->applicationDirPath()); |
41 | }else{ | 42 | }else{ |
cacic-daemon/cacicD/cacictimer.cpp
@@ -5,14 +5,15 @@ CacicTimer::CacicTimer() | @@ -5,14 +5,15 @@ CacicTimer::CacicTimer() | ||
5 | OCacicComm = new CacicComm(); | 5 | OCacicComm = new CacicComm(); |
6 | ccacic = new CCacic(); | 6 | ccacic = new CCacic(); |
7 | timer = new QTimer(this); | 7 | timer = new QTimer(this); |
8 | - //manager = QLogger::QLoggerManager::getInstance(); | ||
9 | - //manager->addDestination("cacicLog.txt", QStringList("CacicD"), QLogger::LogLevel); | 8 | + logManager = QLogger::QLoggerManager::getInstance(); |
10 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); | 9 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); |
11 | } | 10 | } |
12 | 11 | ||
13 | void CacicTimer::iniciarTimer(int x, QString applicationDirPath) | 12 | void CacicTimer::iniciarTimer(int x, QString applicationDirPath) |
14 | { | 13 | { |
15 | setApplicationDirPath(applicationDirPath); | 14 | setApplicationDirPath(applicationDirPath); |
15 | + logManager->addDestination(getApplicationDirPath().append("/cacicLog.txt"), QStringList("Cacic Daemon"), QLogger::InfoLevel); | ||
16 | + logManager->addDestination(getApplicationDirPath().append("/cacicLog.txt"), QStringList("Cacic Daemon"), QLogger::ErrorLevel); | ||
16 | timer->start(x); | 17 | timer->start(x); |
17 | } | 18 | } |
18 | 19 | ||
@@ -21,14 +22,51 @@ void CacicTimer::mslot(){ | @@ -21,14 +22,51 @@ void CacicTimer::mslot(){ | ||
21 | //manager->QLogger::QLog_Trace("ModuleName", "Message: "); | 22 | //manager->QLogger::QLog_Trace("ModuleName", "Message: "); |
22 | if(getConfig()){ | 23 | if(getConfig()){ |
23 | qDebug() << "getConfig() success. - " + QDateTime::currentDateTime().toLocalTime().toString(); | 24 | qDebug() << "getConfig() success. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
25 | + QLogger::QLog_Info("Cacic Daemon", "getConfig() executado com sucesso."); | ||
26 | + | ||
27 | + // Compara o novo arquivo de configuração com um antigo e se forem diferentes | ||
28 | + // 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; | ||
36 | + } else { | ||
37 | + // Renomeia getConfigNew.json para getConfig.json | ||
38 | + fileConfig->remove(); | ||
39 | + delete fileConfig; | ||
40 | + fileConfigNew->rename("getConfigNew.json","getConfig.json"); | ||
41 | + delete fileConfigNew; | ||
42 | + } | ||
43 | + jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); | ||
44 | + } else if( fileConfig->exists() ){ | ||
45 | + jsonConfig = ccacic->getJsonFromFile(getApplicationDirPath().append("/getConfig.json")); | ||
46 | + } else { | ||
47 | + QLogger::QLog_Error("Cacic Daemon", "Arquivo de configuração não criado."); | ||
48 | + } | ||
49 | + | ||
50 | + /* lê json de configurações e armazena quais módulos executáveis. | ||
51 | + * E faz o mesmo tipo de comparação de hashs, com o fim de: | ||
52 | + * ou mantem o binário do módulo ou baixa um novo. | ||
53 | + */ | ||
54 | + foreach( QVariant vectorsContent, jsonConfig["modulos"].toArray().toVariantList().toVector() ) | ||
55 | + moduleList.append( vectorsContent.toString() ); | ||
56 | + | ||
57 | + foreach( QString modulo, moduleList ) { | ||
58 | + | ||
59 | + } | ||
24 | 60 | ||
25 | //aqui irá abrir o semaforo e iniciar a coleta. | 61 | //aqui irá abrir o semaforo e iniciar a coleta. |
26 | 62 | ||
27 | }else{ | 63 | }else{ |
28 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | 64 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
65 | + QLogger::QLog_Error("Cacic Daemon", "Falha na obtenção do arquivo de configuração."); | ||
29 | } | 66 | } |
30 | }else{ | 67 | }else{ |
31 | qDebug() << "getTest() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | 68 | qDebug() << "getTest() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
69 | + QLogger::QLog_Error("Cacic Daemon", "Falha na execução do getTest()."); | ||
32 | } | 70 | } |
33 | } | 71 | } |
34 | 72 | ||
@@ -70,7 +108,7 @@ bool CacicTimer::getConfig(){ | @@ -70,7 +108,7 @@ bool CacicTimer::getConfig(){ | ||
70 | return false; | 108 | return false; |
71 | } | 109 | } |
72 | try{ | 110 | try{ |
73 | - ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getConfig.json"); | 111 | + ccacic->setJsonToFile(jsonresult, getApplicationDirPath().append("/getConfigNew.json")); |
74 | return true; | 112 | return true; |
75 | } catch (...) { | 113 | } catch (...) { |
76 | qDebug() << "Erro ao salvar o arquivo de configurações."; | 114 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
@@ -101,11 +139,11 @@ void CacicTimer::registraFim() | @@ -101,11 +139,11 @@ void CacicTimer::registraFim() | ||
101 | { | 139 | { |
102 | } | 140 | } |
103 | 141 | ||
104 | -bool CacicTimer::compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig){ | 142 | +bool CacicTimer::Md5IsEqual(QVariant document01,QVariant document02){ |
105 | QString getconfigMD5 = QString(QCryptographicHash::hash( | 143 | QString getconfigMD5 = QString(QCryptographicHash::hash( |
106 | - (getconfigfile.toVariant().toByteArray()),QCryptographicHash::Md5).toHex()); | 144 | + (document01.toByteArray()),QCryptographicHash::Md5).toHex()); |
107 | QString getconfigMD52 = QString(QCryptographicHash::hash( | 145 | QString getconfigMD52 = QString(QCryptographicHash::hash( |
108 | - (getConfig.toVariant().toByteArray()),QCryptographicHash::Md5).toHex()); | 146 | + (document02.toByteArray()),QCryptographicHash::Md5).toHex()); |
109 | if(getconfigMD5 == getconfigMD52){ | 147 | if(getconfigMD5 == getconfigMD52){ |
110 | return true; | 148 | return true; |
111 | }else{ | 149 | }else{ |
cacic-daemon/cacicD/cacictimer.h
@@ -23,14 +23,18 @@ public: | @@ -23,14 +23,18 @@ public: | ||
23 | void iniciarTimer(int x, QString applicationDirPath); | 23 | void iniciarTimer(int x, QString applicationDirPath); |
24 | bool getTest(); | 24 | bool getTest(); |
25 | bool getConfig(); | 25 | bool getConfig(); |
26 | - bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig); | 26 | + bool Md5IsEqual(QVariant document01,QVariant document02); |
27 | QString getApplicationDirPath() const; | 27 | QString getApplicationDirPath() const; |
28 | void setApplicationDirPath(const QString &value); | 28 | void setApplicationDirPath(const QString &value); |
29 | 29 | ||
30 | private: | 30 | private: |
31 | void registraFim(); | 31 | void registraFim(); |
32 | void registraInicio(); | 32 | void registraInicio(); |
33 | + | ||
34 | + QJsonObject jsonConfig; | ||
35 | + QLogger::QLoggerManager *logManager; | ||
33 | QString applicationDirPath; | 36 | QString applicationDirPath; |
37 | + QStringList moduleList; | ||
34 | 38 | ||
35 | private slots: | 39 | private slots: |
36 | void mslot(); | 40 | void mslot(); |
install-cacic/install-cacic.pro
@@ -7,7 +7,6 @@ | @@ -7,7 +7,6 @@ | ||
7 | QT += core | 7 | QT += core |
8 | QT += network | 8 | QT += network |
9 | QT -= gui | 9 | QT -= gui |
10 | -QT += axcontainer | ||
11 | 10 | ||
12 | TARGET = install-cacic | 11 | TARGET = install-cacic |
13 | CONFIG += console | 12 | CONFIG += console |
@@ -16,6 +15,7 @@ CONFIG += c++11 | @@ -16,6 +15,7 @@ CONFIG += c++11 | ||
16 | 15 | ||
17 | win32 { | 16 | win32 { |
18 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp | 17 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp |
18 | + QT += axcontainer | ||
19 | } else { | 19 | } else { |
20 | LIBS += -L/usr/lib -lcryptopp | 20 | LIBS += -L/usr/lib -lcryptopp |
21 | } | 21 | } |
@@ -27,7 +27,8 @@ SOURCES += main.cpp \ | @@ -27,7 +27,8 @@ SOURCES += main.cpp \ | ||
27 | ../src/ccacic.cpp \ | 27 | ../src/ccacic.cpp \ |
28 | ../src/cacic_computer.cpp \ | 28 | ../src/cacic_computer.cpp \ |
29 | ../src/operatingsystem.cpp \ | 29 | ../src/operatingsystem.cpp \ |
30 | - ../src/wmi.cpp | 30 | + ../src/wmi.cpp \ |
31 | + ../src/QLogger.cpp | ||
31 | 32 | ||
32 | HEADERS += \ | 33 | HEADERS += \ |
33 | installcacic.h \ | 34 | installcacic.h \ |
@@ -35,7 +36,8 @@ HEADERS += \ | @@ -35,7 +36,8 @@ HEADERS += \ | ||
35 | ../src/cacic_computer.h \ | 36 | ../src/cacic_computer.h \ |
36 | ../src/cacic_comm.h \ | 37 | ../src/cacic_comm.h \ |
37 | ../src/operatingsystem.h \ | 38 | ../src/operatingsystem.h \ |
38 | - ../src/wmi.h | 39 | + ../src/wmi.h \ |
40 | + ../src/QLogger.h | ||
39 | 41 | ||
40 | INCLUDEPATH += ../src \ | 42 | INCLUDEPATH += ../src \ |
41 | ../src/crypto++/include/ | 43 | ../src/crypto++/include/ |
install-cacic/installcacic.cpp
@@ -3,10 +3,13 @@ | @@ -3,10 +3,13 @@ | ||
3 | InstallCacic::InstallCacic(QObject *parent) : | 3 | InstallCacic::InstallCacic(QObject *parent) : |
4 | QObject(parent) | 4 | QObject(parent) |
5 | { | 5 | { |
6 | - | 6 | + logManager = QLogger::QLoggerManager::getInstance(); |
7 | + logManager->addDestination("./log.txt","Install",QLogger::DebugLevel); | ||
7 | } | 8 | } |
8 | 9 | ||
9 | void InstallCacic::run(QStringList argv, int argc) { | 10 | void InstallCacic::run(QStringList argv, int argc) { |
11 | + | ||
12 | + QLogger::QLog_Debug("Install", "Inicio de instalacao"); | ||
10 | bool ok; | 13 | bool ok; |
11 | //valida os parametros repassados | 14 | //valida os parametros repassados |
12 | QMap<QString, QString> param = validaParametros(argv, argc, &ok); | 15 | QMap<QString, QString> param = validaParametros(argv, argc, &ok); |
@@ -21,7 +24,7 @@ void InstallCacic::run(QStringList argv, int argc) { | @@ -21,7 +24,7 @@ void InstallCacic::run(QStringList argv, int argc) { | ||
21 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); | 24 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); |
22 | #ifdef Q_OS_WIN | 25 | #ifdef Q_OS_WIN |
23 | oCacic.setCacicMainFolder("c:/cacic"); | 26 | oCacic.setCacicMainFolder("c:/cacic"); |
24 | -#elif Q_LINUX | 27 | +#elif defined(Q_OS_LINUX) |
25 | oCacic.setCacicMainFolder("/home/cacic"); | 28 | oCacic.setCacicMainFolder("/home/cacic"); |
26 | #endif | 29 | #endif |
27 | oCacic.createFolder(oCacic.getCacicMainFolder()); | 30 | oCacic.createFolder(oCacic.getCacicMainFolder()); |
@@ -57,6 +60,7 @@ void InstallCacic::run(QStringList argv, int argc) { | @@ -57,6 +60,7 @@ void InstallCacic::run(QStringList argv, int argc) { | ||
57 | << " [-help] Lista todos comandos.\n"; | 60 | << " [-help] Lista todos comandos.\n"; |
58 | } | 61 | } |
59 | 62 | ||
63 | + logManager->closeLogger(); | ||
60 | emit finished(); | 64 | emit finished(); |
61 | } | 65 | } |
62 | 66 |
install-cacic/installcacic.h
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | #include <cacic_computer.h> | 7 | #include <cacic_computer.h> |
8 | #include <ccacic.h> | 8 | #include <ccacic.h> |
9 | #include "iostream" | 9 | #include "iostream" |
10 | +#include "QLogger.h" | ||
10 | 11 | ||
11 | class InstallCacic : public QObject | 12 | class InstallCacic : public QObject |
12 | { | 13 | { |
@@ -25,6 +26,7 @@ private: | @@ -25,6 +26,7 @@ private: | ||
25 | CacicComm oCacicComm; | 26 | CacicComm oCacicComm; |
26 | CACIC_Computer oCacicComputer; | 27 | CACIC_Computer oCacicComputer; |
27 | CCacic oCacic; | 28 | CCacic oCacic; |
29 | + QLogger::QLoggerManager *logManager; | ||
28 | signals: | 30 | signals: |
29 | void finished(); | 31 | void finished(); |
30 | 32 |