Commit bdfb95f6bfd0bf674a82d6206df45171b164ea49

Authored by Thiago Rocha
2 parents 3e212223 16466c26
Exists in master

Merge.

cacic-teste/cacic-teste.pro
@@ -21,8 +21,7 @@ SOURCES += \ @@ -21,8 +21,7 @@ SOURCES += \
21 testcacic.cpp \ 21 testcacic.cpp \
22 ../src/ccacic.cpp \ 22 ../src/ccacic.cpp \
23 ../src/cacic_computer.cpp \ 23 ../src/cacic_computer.cpp \
24 - ../src/operatingsystem.cpp \  
25 - ../gercols/gercols.cpp 24 + ../src/operatingsystem.cpp
26 25
27 26
28 HEADERS += \ 27 HEADERS += \
@@ -31,8 +30,7 @@ HEADERS += \ @@ -31,8 +30,7 @@ HEADERS += \
31 ../src/cacic_computer.h \ 30 ../src/cacic_computer.h \
32 ../src/cacic_comm.h \ 31 ../src/cacic_comm.h \
33 ../src/console.h \ 32 ../src/console.h \
34 - ../src/operatingsystem.h \  
35 - ../gercols/gercols.cpp 33 + ../src/operatingsystem.h
36 34
37 INCLUDEPATH += ../src \ 35 INCLUDEPATH += ../src \
38 ../src/crypto++/include/ 36 ../src/crypto++/include/
cacic-teste/testcacic.cpp
@@ -104,6 +104,8 @@ void CTestCacic::testConsole() @@ -104,6 +104,8 @@ void CTestCacic::testConsole()
104 ConsoleObject console; 104 ConsoleObject console;
105 #if defined(Q_OS_LINUX) 105 #if defined(Q_OS_LINUX)
106 QVERIFY(console("echo teste").toStdString() == "teste\n"); 106 QVERIFY(console("echo teste").toStdString() == "teste\n");
  107 +#elif defined(Q_OS_WIN)
  108 + QVERIFY(console("echo teste").toStdString() == "teste");
107 #else 109 #else
108 QVERIFY(false); 110 QVERIFY(false);
109 #endif 111 #endif
@@ -130,7 +132,9 @@ void CTestCacic::testSslConnection() @@ -130,7 +132,9 @@ void CTestCacic::testSslConnection()
130 { 132 {
131 bool ok; 133 bool ok;
132 QJsonObject json = OCacicComm.comm("", &ok, QJsonObject(), true); 134 QJsonObject json = OCacicComm.comm("", &ok, QJsonObject(), true);
133 - QJsonValue jsonvalue = json["codestatus"]; 135 + QJsonValue jsonvalue = (!json["codestatus"].isNull()) ?
  136 + json["codestatus"] :
  137 + QJsonValue::fromVariant(-1);
134 // qDebug() << jsonvalue.toDouble(); 138 // qDebug() << jsonvalue.toDouble();
135 QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); 139 QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302);
136 } 140 }
@@ -138,8 +142,9 @@ void CTestCacic::testSslConnection() @@ -138,8 +142,9 @@ void CTestCacic::testSslConnection()
138 void CTestCacic::testEnCrypt(){ 142 void CTestCacic::testEnCrypt(){
139 std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. 143 std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha.
140 std::string input = "aqui vai a url que sera encriptada"; 144 std::string input = "aqui vai a url que sera encriptada";
  145 + OCacic.setChaveCrypt("testecript123456");
141 this->cripTeste = OCacic.enCrypt(input, IV); 146 this->cripTeste = OCacic.enCrypt(input, IV);
142 - QVERIFY(!this->cripTeste.isNull()); 147 + QVERIFY(!this->cripTeste.isEmpty() && !this->cripTeste.isNull());
143 } 148 }
144 149
145 void CTestCacic::testDeCrypt(){ 150 void CTestCacic::testDeCrypt(){
@@ -171,6 +176,7 @@ void CTestCacic::testInstallCacicStart() @@ -171,6 +176,7 @@ void CTestCacic::testInstallCacicStart()
171 176
172 void CTestCacic::testCacicCompToJsonObject() 177 void CTestCacic::testCacicCompToJsonObject()
173 { 178 {
  179 +// qDebug() << OCacicComp.toJsonObject();
174 QVERIFY(!OCacicComp.toJsonObject().empty()); 180 QVERIFY(!OCacicComp.toJsonObject().empty());
175 } 181 }
176 182
@@ -191,27 +197,54 @@ void CTestCacic::testJsonFromFile() @@ -191,27 +197,54 @@ void CTestCacic::testJsonFromFile()
191 QVERIFY(OCacic.getJsonFromFile("teste.json")["teste"].toString() == "teste"); 197 QVERIFY(OCacic.getJsonFromFile("teste.json")["teste"].toString() == "teste");
192 } 198 }
193 199
  200 +void CTestCacic::testStartService()
  201 +{
  202 + bool ok;
  203 + QString exitStatus;
  204 +#ifdef Q_OS_WIN
  205 + exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic.exe", true, &ok);
  206 +#else
  207 + exitStatus = OCacic.startProcess("../../install-cacic/debug/install-cacic", &ok);
  208 +#endif
  209 + QVERIFY(ok);
  210 +}
  211 +
194 void CTestCacic::testReadConfig() 212 void CTestCacic::testReadConfig()
195 { 213 {
196 214
197 - // Inicializa um arquivo de configuração stub  
198 - // que seria parecido com o recebido do Gerente  
199 - QJsonObject configJson;  
200 - QJsonObject configHardware;  
201 - QJsonObject configSoftware; 215 +// // Inicializa um arquivo de configuração stub
  216 +// // que seria parecido com o recebido do Gerente
  217 +// QJsonObject configJson;
  218 +// QJsonObject configHardware;
202 219
203 - configHardware["network_interface"] = QJsonValue::fromVariant(QString(""));  
204 - configSoftware["operating_system"] = QJsonValue::fromVariant(QString("")); 220 +// configHardware["computador"] = OCacicComp.toJsonObject();
205 221
206 - configJson["hardware"] = configHardware;  
207 - configJson["software"] = configSoftware; 222 +// configJson["hardware"] = configHardware;
208 223
209 - OCacic.setJsonToFile(configJson,"configRequest.json"); 224 +// OCacic.setJsonToFile(configJson,"configRequest.json");
210 225
211 // Leitura do arquivo de configuração 226 // Leitura do arquivo de configuração
212 - OGercols.readConfig();  
213 227
214 - QVERIFY(OGercols.getConfigJson() == configJson); 228 + QVERIFY(false);
  229 +}
  230 +
  231 +void CTestCacic::testSetRegistry()
  232 +{
  233 + QVariantMap valueMap;
  234 + valueMap["teste1"] = QString("Teste 1");
  235 + valueMap["teste2"] = QString("Teste2");
  236 + OCacic.setValueToRegistry("Lightbase", "Teste", valueMap);
  237 + QSettings confirmaTeste("Lightbase", "Teste");
  238 + QVERIFY(confirmaTeste.value("teste1") == QVariant("Teste 1"));
  239 +}
  240 +
  241 +void CTestCacic::testRemoveRegistry()
  242 +{
  243 + OCacic.removeRegistry("Lightbase", "Teste");
  244 + QSettings confirmaTeste("Lightbase", "Teste");
  245 + QVERIFY(confirmaTeste.allKeys().isEmpty());
  246 + confirmaTeste.clear();
  247 + confirmaTeste.sync();
215 } 248 }
216 249
217 void CTestCacic::cleanupTestCase() 250 void CTestCacic::cleanupTestCase()
cacic-teste/testcacic.h
@@ -27,7 +27,6 @@ private: @@ -27,7 +27,6 @@ private:
27 CacicComm OCacicComm; 27 CacicComm OCacicComm;
28 CCacic OCacic; 28 CCacic OCacic;
29 CACIC_Computer OCacicComp; 29 CACIC_Computer OCacicComp;
30 - Gercols OGercols;  
31 QString testPath; 30 QString testPath;
32 QString testIniPath; 31 QString testIniPath;
33 QJsonObject session; 32 QJsonObject session;
@@ -61,7 +60,10 @@ private slots: @@ -61,7 +60,10 @@ private slots:
61 void testOperatingSystemToJsonObject(); 60 void testOperatingSystemToJsonObject();
62 void testJsonToFile(); 61 void testJsonToFile();
63 void testJsonFromFile(); 62 void testJsonFromFile();
  63 + void testStartService();
64 void testReadConfig(); 64 void testReadConfig();
  65 + void testSetRegistry();
  66 + void testRemoveRegistry();
65 void cleanupTestCase(); 67 void cleanupTestCase();
66 }; 68 };
67 69
gercols/gercols.cpp
1 #include "gercols.h" 1 #include "gercols.h"
2 2
3 -Gercols::Gercols(QObject *parent) :  
4 - QObject(parent) 3 +Gercols::Gercols(QObject *parent)
5 { 4 {
6 - 5 + /*Aqui vamos conectar o slot principal. Acho que algo do tipo:
  6 + * sinal iniciaColeta() chama o slot configuraColetas() que verifica
  7 + * quais coletas serao necessárias e realiza a conexão dos sinais com
  8 + * slots de coletas (coletaHardware, coletaSoftware, etc..)
  9 + */
7 } 10 }
8 11
9 -void Gercols::run(QStringList argv, int argc) 12 +void Gercols::run()
10 { 13 {
11 - std::cout << "Gercols" << std::endl;  
12 - readConfig();  
13 - std::cout << "Configuration file read." << std::endl;  
14 -} 14 + QJsonObject coleta;
  15 + /* Pega configurações do Json de configurações localizado
  16 + * na pasta principal do cacic (deverá ser pega do registro,
  17 + * estou tentando implementar isso no installcacic).
  18 + */
15 19
16 -void Gercols::readConfig()  
17 -{  
18 - CCacic OCacic;  
19 - QString file = "configRequest.json"; 20 + //Inicializa as classes e seta valores necessários oCacic.setCacicMainFolder(), por exemplo.
20 21
21 - this->configJson = OCacic.getJsonFromFile(file);  
22 -} 22 + //emite sinal para começar a coleta
23 23
24 -QJsonObject Gercols::getConfigJson()  
25 -{  
26 - return configJson; 24 + //aguarda todas as coletas serem realizadas
  25 +
  26 + //salva coleta em json
  27 + coleta["computador"] = oColeta.getOComputer().toJsonObject();
  28 + coleta["software"] = QJsonValue::fromVariant(QString("Aqui vai coleta de software"));
  29 + coleta["hardware"] = QJsonValue::fromVariant(QString("Aqui vai coleta de hardware"));
  30 + qDebug() << coleta;
  31 + //salva json em arquivo
  32 + oCacic.setJsonToFile(coleta, "coleta.json");
  33 + //emite sinal "finished" pra finalizar a aplicação
  34 + emit finished();
27 } 35 }
gercols/gercols.h
1 #ifndef GERCOLS_H 1 #ifndef GERCOLS_H
2 #define GERCOLS_H 2 #define GERCOLS_H
3 -  
4 #include <QtCore> 3 #include <QtCore>
5 -#include <QObject>  
6 -#include <QJsonObject>  
7 -#include <QString>  
8 -#include <iostream>  
9 -#include <../src/ccacic.h> 4 +#include <ccoleta.h>
  5 +#include <ccacic.h>
10 6
11 class Gercols : public QObject 7 class Gercols : public QObject
12 { 8 {
13 Q_OBJECT 9 Q_OBJECT
  10 +private:
  11 + CCacic oCacic;
  12 + CColeta oColeta;
14 public: 13 public:
15 explicit Gercols(QObject *parent = 0); 14 explicit Gercols(QObject *parent = 0);
16 15
17 - void readConfig();  
18 - QJsonObject getConfigJson();  
19 -  
20 -private:  
21 - QJsonObject configJson; 16 +public slots:
  17 + void run();
22 18
23 signals: 19 signals:
24 void finished(); 20 void finished();
25 -  
26 -public slots:  
27 - void run(QStringList argv, int argc);  
28 - 21 + void fimColeta();
29 }; 22 };
30 23
31 #endif // GERCOLS_H 24 #endif // GERCOLS_H
gercols/gercols.pro
@@ -25,6 +25,7 @@ SOURCES += \ @@ -25,6 +25,7 @@ SOURCES += \
25 ../src/ccacic.cpp \ 25 ../src/ccacic.cpp \
26 ../src/cacic_computer.cpp \ 26 ../src/cacic_computer.cpp \
27 ../src/operatingsystem.cpp \ 27 ../src/operatingsystem.cpp \
  28 + ../src/ccoleta.cpp \
28 ./gercols.cpp 29 ./gercols.cpp
29 30
30 31
@@ -33,6 +34,7 @@ HEADERS += \ @@ -33,6 +34,7 @@ HEADERS += \
33 ../src/cacic_computer.h \ 34 ../src/cacic_computer.h \
34 ../src/operatingsystem.h \ 35 ../src/operatingsystem.h \
35 ../src/console.h \ 36 ../src/console.h \
  37 + ../src/ccoleta.h \
36 ./gercols.h 38 ./gercols.h
37 39
38 INCLUDEPATH += ../src \ 40 INCLUDEPATH += ../src \
gercols/main.cpp
@@ -4,18 +4,12 @@ @@ -4,18 +4,12 @@
4 int main(int argc, char *argv[]) 4 int main(int argc, char *argv[])
5 { 5 {
6 QCoreApplication a(argc, argv); 6 QCoreApplication a(argc, argv);
7 -  
8 - QStringList args;  
9 - for (int i = 0; i<argc; i++)  
10 - args.append(argv[i]);  
11 -  
12 - Gercols *OGercols = new Gercols(&a);  
13 -  
14 - // This will cause the application to exit when  
15 - // the task signals finished.  
16 - QObject::connect(OGercols, SIGNAL(finished()), &a, SLOT(quit()));  
17 -  
18 - // This will run the task from the application event loop.  
19 - QMetaObject::invokeMethod(OGercols, "run", Qt::QueuedConnection, Q_ARG(QStringList, args), Q_ARG(int, argc)); 7 + //crio o objeto que será responsável pela execução
  8 + Gercols *oGercols = new Gercols(&a);
  9 + //conecto o sinal "finished" do objeto oGercols ao slot "quit" do objeto a(QCoreApplication)
  10 + //ou seja, quando o finished for chamado, a aplicacao é encerrada.
  11 + a.connect(oGercols, SIGNAL(finished()), &a, SLOT(quit()));
  12 + //invoco o metodo "run" do objeto oGercols assim que o loop (a.exec()) comecar
  13 + QMetaObject::invokeMethod(oGercols, "run", Qt::QueuedConnection);
20 return a.exec(); 14 return a.exec();
21 } 15 }
install-cacic/install-cacic.pro.user
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE QtCreatorProject> 2 <!DOCTYPE QtCreatorProject>
3 -<!-- Written by QtCreator 3.1.2, 2014-08-14T17:39:38. --> 3 +<!-- Written by QtCreator 3.1.2, 2014-08-15T20:38:37. -->
4 <qtcreator> 4 <qtcreator>
5 <data> 5 <data>
6 <variable>ProjectExplorer.Project.ActiveTarget</variable> 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -221,7 +221,7 @@ @@ -221,7 +221,7 @@
221 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> 221 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value>
222 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> 222 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
223 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro</value> 223 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro</value>
224 - <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-host=10.1.0.137/cacic/web/app_dev.php -user=cacic -password=cacic123</value> 224 + <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-uninstall</value>
225 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> 225 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value>
226 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> 226 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
227 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> 227 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value>
install-cacic/installcacic.cpp
@@ -7,10 +7,9 @@ InstallCacic::InstallCacic(QObject *parent) : @@ -7,10 +7,9 @@ InstallCacic::InstallCacic(QObject *parent) :
7 } 7 }
8 8
9 void InstallCacic::run(QStringList argv, int argc) { 9 void InstallCacic::run(QStringList argv, int argc) {
10 - QMap<QString, QString> args;  
11 bool ok; 10 bool ok;
12 //valida os parametros repassados 11 //valida os parametros repassados
13 - validaParametros(argv, argc, &ok); 12 + QMap<QString, QString> param = validaParametros(argv, argc, &ok);
14 //se tiver usuario, senha e url 13 //se tiver usuario, senha e url
15 if (ok){ 14 if (ok){
16 oCacicComm.setUrlGerente(this->argumentos["host"]); 15 oCacicComm.setUrlGerente(this->argumentos["host"]);
@@ -22,16 +21,29 @@ void InstallCacic::run(QStringList argv, int argc) { @@ -22,16 +21,29 @@ void InstallCacic::run(QStringList argv, int argc) {
22 oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); 21 oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString());
23 oCacic.setCacicMainFolder("c:/cacic"); 22 oCacic.setCacicMainFolder("c:/cacic");
24 oCacic.createFolder(oCacic.getCacicMainFolder()); 23 oCacic.createFolder(oCacic.getCacicMainFolder());
25 - //grava chave em arquivo json;  
26 - QJsonObject configJson = oCacic.getJsonFromFile(oCacic.getCacicMainFolder() + "/cacicTeste.json");  
27 - QJsonObject configToSave = configJson["configs"].toObject();  
28 - configToSave["chaveCrypt"] = QJsonValue::fromVariant(oCacic.getChaveCrypt());  
29 - configJson["configs"] = configToSave;  
30 - oCacic.setJsonToFile(configJson, oCacic.getCacicMainFolder() + "/cacicTeste.json");  
31 - }  
32 - else 24 + //grava chave em registro;
  25 +
  26 + QVariantMap registro;
  27 + registro["key"] = oCacic.getChaveCrypt();
  28 + oCacic.setValueToRegistry("Lightbase", "Cacic", registro);
  29 + //starta o processo do cacic.
  30 +#ifdef Q_OS_WIN
  31 + QString exitStatus = oCacic.startProcess("cacic.exe", true, &ok);
  32 + if (!ok)
  33 + std::cout << "Erro ao iniciar o processo: "
  34 + << exitStatus.toStdString() << "\n";
  35 +#else
  36 + oCacic.startProcess("cacic.exe", true, &ok);
  37 + if (!ok)
  38 + qDebug() << "Erro ao iniciar o processo.";
  39 +#endif
  40 + } else
33 std::cout << "Nao foi possivel realizar o login.\n " 41 std::cout << "Nao foi possivel realizar o login.\n "
34 << jsonLogin["error"].toString().toStdString(); 42 << jsonLogin["error"].toString().toStdString();
  43 + } else if ((param.contains("default")) && (param["default"] == "uninstall")){
  44 + oCacic.deleteFolder("c:/cacic");
  45 + oCacic.removeRegistry("Lightbase", "Cacic");
  46 + std::cout << "Cacic desinstalado com sucesso.\n";
35 } else { 47 } else {
36 std::cout << "\nInstalador do Agente Cacic.\n\n" 48 std::cout << "\nInstalador do Agente Cacic.\n\n"
37 << "Parametros incorretos. (<obrigatorios> [opcional])\n\n" 49 << "Parametros incorretos. (<obrigatorios> [opcional])\n\n"
@@ -53,6 +65,8 @@ QMap&lt;QString, QString&gt; InstallCacic::validaParametros(QStringList argv, int argc @@ -53,6 +65,8 @@ QMap&lt;QString, QString&gt; InstallCacic::validaParametros(QStringList argv, int argc
53 QStringList auxList = aux.split("="); 65 QStringList auxList = aux.split("=");
54 if ((auxList.at(0).at(0) == '-') && (auxList.size() > 1)) 66 if ((auxList.at(0).at(0) == '-') && (auxList.size() > 1))
55 map[auxList.at(0).mid(1)] = auxList.at(1); 67 map[auxList.at(0).mid(1)] = auxList.at(1);
  68 + else if (aux.at(0)== '-')
  69 + map["default"] = aux.mid(1);
56 } 70 }
57 *ok = (bool) map.contains("host") && map.contains("user") && map.contains("password"); 71 *ok = (bool) map.contains("host") && map.contains("user") && map.contains("password");
58 if (*ok){ 72 if (*ok){
install-cacic/installcacic.h
@@ -17,7 +17,9 @@ public: @@ -17,7 +17,9 @@ public:
17 QMap<QString, QString> getArgumentos(); 17 QMap<QString, QString> getArgumentos();
18 void setArgumentos(QMap<QString, QString> value); 18 void setArgumentos(QMap<QString, QString> value);
19 QMap<QString, QString> validaParametros(QStringList argv, int argc, bool *ok); 19 QMap<QString, QString> validaParametros(QStringList argv, int argc, bool *ok);
  20 + bool startProcess(QString pathprogram, bool wait, QStringList arguments);
20 21
  22 + void registro();
21 private: 23 private:
22 QMap<QString, QString> argumentos; 24 QMap<QString, QString> argumentos;
23 CacicComm oCacicComm; 25 CacicComm oCacicComm;
src/cacic_computer.cpp
@@ -20,11 +20,9 @@ QList&lt;QVariantMap&gt; CACIC_Computer::networkInterfacesRunning(){ @@ -20,11 +20,9 @@ QList&lt;QVariantMap&gt; CACIC_Computer::networkInterfacesRunning(){
20 20
21 foreach (QNetworkInterface in, interface.allInterfaces()) { 21 foreach (QNetworkInterface in, interface.allInterfaces()) {
22 if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && 22 if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) &&
23 - !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) &&  
24 - (bool)(in.flags() & QNetworkInterface::IsRunning)){  
25 - // qDebug() << in.humanReadableName() << "\n"; 23 + !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) &&
  24 + (bool)(in.flags() & QNetworkInterface::IsRunning)){
26 mapInterface["nome"] = in.humanReadableName(); 25 mapInterface["nome"] = in.humanReadableName();
27 - // qDebug() << in.hardwareAddress() << "\n";  
28 mapInterface["mac"] = in.hardwareAddress(); 26 mapInterface["mac"] = in.hardwareAddress();
29 foreach (QNetworkAddressEntry ae, in.addressEntries()){ 27 foreach (QNetworkAddressEntry ae, in.addressEntries()){
30 if (ae.ip().scopeId() == ""){ 28 if (ae.ip().scopeId() == ""){
@@ -34,34 +32,26 @@ QList&lt;QVariantMap&gt; CACIC_Computer::networkInterfacesRunning(){ @@ -34,34 +32,26 @@ QList&lt;QVariantMap&gt; CACIC_Computer::networkInterfacesRunning(){
34 mapInterface["ipv6"] = ae.ip().toString(); 32 mapInterface["ipv6"] = ae.ip().toString();
35 mapInterface["netmask_ipv6"] = ae.netmask().toString(); 33 mapInterface["netmask_ipv6"] = ae.netmask().toString();
36 } 34 }
37 - // qDebug() << ae.ip().toString() << "\n";  
38 } 35 }
39 listaMap.append(mapInterface); 36 listaMap.append(mapInterface);
40 mapInterface.clear(); 37 mapInterface.clear();
41 } 38 }
42 } 39 }
43 -// foreach (QVariantMap each, listaMap){  
44 -  
45 -// foreach (QVariant eachValue, each.values())  
46 -// qDebug() << eachValue.toString();  
47 -// }  
48 -  
49 return listaMap; 40 return listaMap;
50 } 41 }
51 42
52 QJsonObject CACIC_Computer::toJsonObject() 43 QJsonObject CACIC_Computer::toJsonObject()
53 { 44 {
54 QJsonObject json; 45 QJsonObject json;
55 - QJsonObject network; 46 + QJsonArray network;
56 int count = 1; 47 int count = 1;
57 json["usuario"] = QJsonValue::fromVariant(QString::fromStdString(this->usuario)); 48 json["usuario"] = QJsonValue::fromVariant(QString::fromStdString(this->usuario));
58 json["operatingSystem"] = this->oOperatingSystem.toJsonObject(); 49 json["operatingSystem"] = this->oOperatingSystem.toJsonObject();
59 foreach(QVariantMap auxMap, this->getNetworkInterface()){ 50 foreach(QVariantMap auxMap, this->getNetworkInterface()){
60 - network["network" + QVariant::fromValue(count).toString()] = QJsonObject::fromVariantMap(auxMap); 51 + network.append(QJsonObject::fromVariantMap(auxMap));
61 count++; 52 count++;
62 } 53 }
63 json["networkDevices"] = network; 54 json["networkDevices"] = network;
64 -// qDebug() << json;  
65 return json; 55 return json;
66 } 56 }
67 57
src/ccacic.cpp
@@ -159,16 +159,18 @@ QJsonObject CCacic::getJsonFromFile(QString filepath) @@ -159,16 +159,18 @@ QJsonObject CCacic::getJsonFromFile(QString filepath)
159 * */ 159 * */
160 QString CCacic::enCrypt(std::string str_in, std::string iv) { 160 QString CCacic::enCrypt(std::string str_in, std::string iv) {
161 std::string str_out; 161 std::string str_out;
162 - std::string key = this->getChaveCrypt().toStdString();  
163 - CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str());  
164 - CryptoPP::StringSource encryptor(str_in, true,  
165 - new CryptoPP::StreamTransformationFilter(encryption,  
166 - new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out),  
167 - false // do not append a newline 162 + if ((!this->getChaveCrypt().isNull())){
  163 + std::string key = (!this->getChaveCrypt().isNull()) ? this->getChaveCrypt().toStdString() : "";
  164 + CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str());
  165 + CryptoPP::StringSource encryptor(str_in, true,
  166 + new CryptoPP::StreamTransformationFilter(encryption,
  167 + new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out),
  168 + false // do not append a newline
  169 + )
168 ) 170 )
169 - )  
170 - );  
171 - //qDebug(QString::fromStdString(str_out).toLocal8Bit()); 171 + );
  172 + }
  173 +// qDebug() << QString::fromStdString(str_out);
172 return QString::fromStdString(str_out); 174 return QString::fromStdString(str_out);
173 } 175 }
174 176
@@ -184,18 +186,42 @@ QString CCacic::enCrypt(std::string str_in, std::string iv) { @@ -184,18 +186,42 @@ QString CCacic::enCrypt(std::string str_in, std::string iv) {
184 // * */ 186 // * */
185 QString CCacic::deCrypt(std::string str_in, std::string iv) { 187 QString CCacic::deCrypt(std::string str_in, std::string iv) {
186 std::string str_out; 188 std::string str_out;
187 - std::string key = this->getChaveCrypt().toStdString();  
188 - CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); 189 + if ((!this->getChaveCrypt().isNull())){
  190 + std::string key = this->getChaveCrypt().toStdString();
  191 + CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str());
189 192
190 - CryptoPP::StringSource decryptor(str_in, true,  
191 - new CryptoPP::Base64Decoder(  
192 - new CryptoPP::StreamTransformationFilter(decryption,  
193 - new CryptoPP::StringSink(str_out))  
194 - )  
195 - ); 193 + CryptoPP::StringSource decryptor(str_in, true,
  194 + new CryptoPP::Base64Decoder(
  195 + new CryptoPP::StreamTransformationFilter(decryption,
  196 + new CryptoPP::StringSink(str_out))
  197 + )
  198 + );
  199 + }
196 return QString::fromStdString(str_out); 200 return QString::fromStdString(str_out);
197 } 201 }
198 202
  203 +QString CCacic::startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments)
  204 +{
  205 + QProcess process;
  206 + arguments.empty() ? process.start(pathprogram) : process.start(pathprogram, arguments);
  207 + *ok = wait ? process.waitForFinished() : process.waitForStarted();
  208 + return process.errorString();
  209 +}
  210 +
  211 +void CCacic::setValueToRegistry(QString organization, QString application, QVariantMap values)
  212 +{
  213 + QSettings registry(organization, application);
  214 + for (QVariantMap::const_iterator i = values.constBegin(); i != values.constEnd(); i++)
  215 + registry.setValue(i.key(), i.value());
  216 + registry.sync();
  217 +}
  218 +
  219 +void CCacic::removeRegistry(QString organization, QString application)
  220 +{
  221 + QSettings registry(organization, application);
  222 + registry.clear();
  223 + registry.sync();
  224 +}
199 225
200 /*Getters/Setters 226 /*Getters/Setters
201 * Begin: 227 * Begin:
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 #define CCACIC_H 2 #define CCACIC_H
3 3
4 #include <QCoreApplication> 4 #include <QCoreApplication>
  5 +#include <QProcess>
5 #include <QObject> 6 #include <QObject>
6 #include <QFile> 7 #include <QFile>
7 #include <QSettings> 8 #include <QSettings>
@@ -34,6 +35,10 @@ public: @@ -34,6 +35,10 @@ public:
34 QJsonValue jsonValueFromJsonString(QString json, QString key); 35 QJsonValue jsonValueFromJsonString(QString json, QString key);
35 bool setJsonToFile(QJsonObject json, QString filepath); 36 bool setJsonToFile(QJsonObject json, QString filepath);
36 QJsonObject getJsonFromFile(QString filepath); 37 QJsonObject getJsonFromFile(QString filepath);
  38 + QString startProcess(QString pathprogram, bool wait, bool *ok, QStringList arguments = QStringList());
  39 + void setValueToRegistry(QString organization, QString application, QVariantMap values);
  40 + void removeRegistry(QString organization, QString application);
  41 +
37 42
38 //Geters/seters: 43 //Geters/seters:
39 44
src/ccoleta.cpp 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +#include "ccoleta.h"
  2 +
  3 +CColeta::CColeta()
  4 +{
  5 +}
  6 +
  7 +
  8 +CACIC_Computer CColeta::getOComputer() const
  9 +{
  10 + return oComputer;
  11 +}
src/ccoleta.h 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +#ifndef CCOLETA_H
  2 +#define CCOLETA_H
  3 +#include <cacic_computer.h>
  4 +
  5 +class CColeta
  6 +{
  7 +private:
  8 + CACIC_Computer oComputer;
  9 +public:
  10 + CColeta();
  11 + CACIC_Computer getOComputer() const;
  12 +};
  13 +
  14 +#endif // CCOLETA_H
@@ -21,7 +21,7 @@ public: @@ -21,7 +21,7 @@ public:
21 options << "-c" << QString::fromStdString(input); 21 options << "-c" << QString::fromStdString(input);
22 process->start("/bin/sh", options); 22 process->start("/bin/sh", options);
23 #elif defined(Q_OS_WIN) 23 #elif defined(Q_OS_WIN)
24 - process->start(input); 24 + process->start(QString::fromStdString(input));
25 #endif 25 #endif
26 process->waitForFinished(); 26 process->waitForFinished();
27 QString output = process->readAll(); 27 QString output = process->readAll();
src/operatingsystem.cpp
@@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
2 2
3 OperatingSystem::OperatingSystem() 3 OperatingSystem::OperatingSystem()
4 { 4 {
5 - this->idOs = this->coletaIdOs();  
6 this->nomeOs = this->coletaNomeOs(); 5 this->nomeOs = this->coletaNomeOs();
  6 + this->idOs = this->coletaIdOs();
7 } 7 }
8 8
9 9
@@ -38,7 +38,7 @@ int OperatingSystem::coletaIdOs(){ @@ -38,7 +38,7 @@ int OperatingSystem::coletaIdOs(){
38 } 38 }
39 39
40 #else 40 #else
41 - return 0; 41 + return -1;
42 #endif 42 #endif
43 } 43 }
44 44
@@ -47,6 +47,7 @@ QString OperatingSystem::coletaNomeOs() @@ -47,6 +47,7 @@ QString OperatingSystem::coletaNomeOs()
47 QString text; 47 QString text;
48 QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); 48 QStringList environment = QProcessEnvironment::systemEnvironment().toStringList();
49 foreach (text, environment) { 49 foreach (text, environment) {
  50 +// qDebug() << text;
50 if (text.contains("OS=" , Qt::CaseInsensitive) || 51 if (text.contains("OS=" , Qt::CaseInsensitive) ||
51 text.contains("SESSION=", Qt::CaseInsensitive) ){ 52 text.contains("SESSION=", Qt::CaseInsensitive) ){
52 QStringList split = text.split("="); 53 QStringList split = text.split("=");