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 | 36 | QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em ").append(application()->applicationDirPath()).append(".")); |
| 37 | 37 | |
| 38 | 38 | QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath() + "/getConfig.json"); |
| 39 | + | |
| 39 | 40 | if(!result.contains("error") && !result.isEmpty()){ |
| 40 | 41 | Ocacictimer->iniciarTimer(result["codestatus"].toInt(), application()->applicationDirPath()); |
| 41 | 42 | }else{ | ... | ... |
cacic-daemon/cacicD/cacictimer.cpp
| ... | ... | @@ -5,14 +5,15 @@ CacicTimer::CacicTimer() |
| 5 | 5 | OCacicComm = new CacicComm(); |
| 6 | 6 | ccacic = new CCacic(); |
| 7 | 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 | 9 | connect(timer,SIGNAL(timeout()),this,SLOT(mslot())); |
| 11 | 10 | } |
| 12 | 11 | |
| 13 | 12 | void CacicTimer::iniciarTimer(int x, QString applicationDirPath) |
| 14 | 13 | { |
| 15 | 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 | 17 | timer->start(x); |
| 17 | 18 | } |
| 18 | 19 | |
| ... | ... | @@ -21,14 +22,51 @@ void CacicTimer::mslot(){ |
| 21 | 22 | //manager->QLogger::QLog_Trace("ModuleName", "Message: "); |
| 22 | 23 | if(getConfig()){ |
| 23 | 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 | 61 | //aqui irá abrir o semaforo e iniciar a coleta. |
| 26 | 62 | |
| 27 | 63 | }else{ |
| 28 | 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 | 67 | }else{ |
| 31 | 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 | 108 | return false; |
| 71 | 109 | } |
| 72 | 110 | try{ |
| 73 | - ccacic->setJsonToFile(jsonresult, getApplicationDirPath() + "/getConfig.json"); | |
| 111 | + ccacic->setJsonToFile(jsonresult, getApplicationDirPath().append("/getConfigNew.json")); | |
| 74 | 112 | return true; |
| 75 | 113 | } catch (...) { |
| 76 | 114 | qDebug() << "Erro ao salvar o arquivo de configurações."; |
| ... | ... | @@ -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 | 143 | QString getconfigMD5 = QString(QCryptographicHash::hash( |
| 106 | - (getconfigfile.toVariant().toByteArray()),QCryptographicHash::Md5).toHex()); | |
| 144 | + (document01.toByteArray()),QCryptographicHash::Md5).toHex()); | |
| 107 | 145 | QString getconfigMD52 = QString(QCryptographicHash::hash( |
| 108 | - (getConfig.toVariant().toByteArray()),QCryptographicHash::Md5).toHex()); | |
| 146 | + (document02.toByteArray()),QCryptographicHash::Md5).toHex()); | |
| 109 | 147 | if(getconfigMD5 == getconfigMD52){ |
| 110 | 148 | return true; |
| 111 | 149 | }else{ | ... | ... |
cacic-daemon/cacicD/cacictimer.h
| ... | ... | @@ -23,14 +23,18 @@ public: |
| 23 | 23 | void iniciarTimer(int x, QString applicationDirPath); |
| 24 | 24 | bool getTest(); |
| 25 | 25 | bool getConfig(); |
| 26 | - bool compararHashMD5(QJsonDocument getconfigfile,QJsonDocument getConfig); | |
| 26 | + bool Md5IsEqual(QVariant document01,QVariant document02); | |
| 27 | 27 | QString getApplicationDirPath() const; |
| 28 | 28 | void setApplicationDirPath(const QString &value); |
| 29 | 29 | |
| 30 | 30 | private: |
| 31 | 31 | void registraFim(); |
| 32 | 32 | void registraInicio(); |
| 33 | + | |
| 34 | + QJsonObject jsonConfig; | |
| 35 | + QLogger::QLoggerManager *logManager; | |
| 33 | 36 | QString applicationDirPath; |
| 37 | + QStringList moduleList; | |
| 34 | 38 | |
| 35 | 39 | private slots: |
| 36 | 40 | void mslot(); | ... | ... |
install-cacic/install-cacic.pro
| ... | ... | @@ -7,7 +7,6 @@ |
| 7 | 7 | QT += core |
| 8 | 8 | QT += network |
| 9 | 9 | QT -= gui |
| 10 | -QT += axcontainer | |
| 11 | 10 | |
| 12 | 11 | TARGET = install-cacic |
| 13 | 12 | CONFIG += console |
| ... | ... | @@ -16,6 +15,7 @@ CONFIG += c++11 |
| 16 | 15 | |
| 17 | 16 | win32 { |
| 18 | 17 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp |
| 18 | + QT += axcontainer | |
| 19 | 19 | } else { |
| 20 | 20 | LIBS += -L/usr/lib -lcryptopp |
| 21 | 21 | } |
| ... | ... | @@ -27,7 +27,8 @@ SOURCES += main.cpp \ |
| 27 | 27 | ../src/ccacic.cpp \ |
| 28 | 28 | ../src/cacic_computer.cpp \ |
| 29 | 29 | ../src/operatingsystem.cpp \ |
| 30 | - ../src/wmi.cpp | |
| 30 | + ../src/wmi.cpp \ | |
| 31 | + ../src/QLogger.cpp | |
| 31 | 32 | |
| 32 | 33 | HEADERS += \ |
| 33 | 34 | installcacic.h \ |
| ... | ... | @@ -35,7 +36,8 @@ HEADERS += \ |
| 35 | 36 | ../src/cacic_computer.h \ |
| 36 | 37 | ../src/cacic_comm.h \ |
| 37 | 38 | ../src/operatingsystem.h \ |
| 38 | - ../src/wmi.h | |
| 39 | + ../src/wmi.h \ | |
| 40 | + ../src/QLogger.h | |
| 39 | 41 | |
| 40 | 42 | INCLUDEPATH += ../src \ |
| 41 | 43 | ../src/crypto++/include/ | ... | ... |
install-cacic/installcacic.cpp
| ... | ... | @@ -3,10 +3,13 @@ |
| 3 | 3 | InstallCacic::InstallCacic(QObject *parent) : |
| 4 | 4 | QObject(parent) |
| 5 | 5 | { |
| 6 | - | |
| 6 | + logManager = QLogger::QLoggerManager::getInstance(); | |
| 7 | + logManager->addDestination("./log.txt","Install",QLogger::DebugLevel); | |
| 7 | 8 | } |
| 8 | 9 | |
| 9 | 10 | void InstallCacic::run(QStringList argv, int argc) { |
| 11 | + | |
| 12 | + QLogger::QLog_Debug("Install", "Inicio de instalacao"); | |
| 10 | 13 | bool ok; |
| 11 | 14 | //valida os parametros repassados |
| 12 | 15 | QMap<QString, QString> param = validaParametros(argv, argc, &ok); |
| ... | ... | @@ -21,7 +24,7 @@ void InstallCacic::run(QStringList argv, int argc) { |
| 21 | 24 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); |
| 22 | 25 | #ifdef Q_OS_WIN |
| 23 | 26 | oCacic.setCacicMainFolder("c:/cacic"); |
| 24 | -#elif Q_LINUX | |
| 27 | +#elif defined(Q_OS_LINUX) | |
| 25 | 28 | oCacic.setCacicMainFolder("/home/cacic"); |
| 26 | 29 | #endif |
| 27 | 30 | oCacic.createFolder(oCacic.getCacicMainFolder()); |
| ... | ... | @@ -57,6 +60,7 @@ void InstallCacic::run(QStringList argv, int argc) { |
| 57 | 60 | << " [-help] Lista todos comandos.\n"; |
| 58 | 61 | } |
| 59 | 62 | |
| 63 | + logManager->closeLogger(); | |
| 60 | 64 | emit finished(); |
| 61 | 65 | } |
| 62 | 66 | ... | ... |
install-cacic/installcacic.h
| ... | ... | @@ -7,6 +7,7 @@ |
| 7 | 7 | #include <cacic_computer.h> |
| 8 | 8 | #include <ccacic.h> |
| 9 | 9 | #include "iostream" |
| 10 | +#include "QLogger.h" | |
| 10 | 11 | |
| 11 | 12 | class InstallCacic : public QObject |
| 12 | 13 | { |
| ... | ... | @@ -25,6 +26,7 @@ private: |
| 25 | 26 | CacicComm oCacicComm; |
| 26 | 27 | CACIC_Computer oCacicComputer; |
| 27 | 28 | CCacic oCacic; |
| 29 | + QLogger::QLoggerManager *logManager; | |
| 28 | 30 | signals: |
| 29 | 31 | void finished(); |
| 30 | 32 | ... | ... |