Commit bdfb95f6bfd0bf674a82d6206df45171b164ea49
Exists in
master
Merge.
Showing
17 changed files
with
203 additions
and
110 deletions
Show diff stats
cacic-teste/cacic-teste.pro
| ... | ... | @@ -21,8 +21,7 @@ SOURCES += \ |
| 21 | 21 | testcacic.cpp \ |
| 22 | 22 | ../src/ccacic.cpp \ |
| 23 | 23 | ../src/cacic_computer.cpp \ |
| 24 | - ../src/operatingsystem.cpp \ | |
| 25 | - ../gercols/gercols.cpp | |
| 24 | + ../src/operatingsystem.cpp | |
| 26 | 25 | |
| 27 | 26 | |
| 28 | 27 | HEADERS += \ |
| ... | ... | @@ -31,8 +30,7 @@ HEADERS += \ |
| 31 | 30 | ../src/cacic_computer.h \ |
| 32 | 31 | ../src/cacic_comm.h \ |
| 33 | 32 | ../src/console.h \ |
| 34 | - ../src/operatingsystem.h \ | |
| 35 | - ../gercols/gercols.cpp | |
| 33 | + ../src/operatingsystem.h | |
| 36 | 34 | |
| 37 | 35 | INCLUDEPATH += ../src \ |
| 38 | 36 | ../src/crypto++/include/ | ... | ... |
cacic-teste/testcacic.cpp
| ... | ... | @@ -104,6 +104,8 @@ void CTestCacic::testConsole() |
| 104 | 104 | ConsoleObject console; |
| 105 | 105 | #if defined(Q_OS_LINUX) |
| 106 | 106 | QVERIFY(console("echo teste").toStdString() == "teste\n"); |
| 107 | +#elif defined(Q_OS_WIN) | |
| 108 | + QVERIFY(console("echo teste").toStdString() == "teste"); | |
| 107 | 109 | #else |
| 108 | 110 | QVERIFY(false); |
| 109 | 111 | #endif |
| ... | ... | @@ -130,7 +132,9 @@ void CTestCacic::testSslConnection() |
| 130 | 132 | { |
| 131 | 133 | bool ok; |
| 132 | 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 | 138 | // qDebug() << jsonvalue.toDouble(); |
| 135 | 139 | QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); |
| 136 | 140 | } |
| ... | ... | @@ -138,8 +142,9 @@ void CTestCacic::testSslConnection() |
| 138 | 142 | void CTestCacic::testEnCrypt(){ |
| 139 | 143 | std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. |
| 140 | 144 | std::string input = "aqui vai a url que sera encriptada"; |
| 145 | + OCacic.setChaveCrypt("testecript123456"); | |
| 141 | 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 | 150 | void CTestCacic::testDeCrypt(){ |
| ... | ... | @@ -171,6 +176,7 @@ void CTestCacic::testInstallCacicStart() |
| 171 | 176 | |
| 172 | 177 | void CTestCacic::testCacicCompToJsonObject() |
| 173 | 178 | { |
| 179 | +// qDebug() << OCacicComp.toJsonObject(); | |
| 174 | 180 | QVERIFY(!OCacicComp.toJsonObject().empty()); |
| 175 | 181 | } |
| 176 | 182 | |
| ... | ... | @@ -191,27 +197,54 @@ void CTestCacic::testJsonFromFile() |
| 191 | 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 | 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 | 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 | 250 | void CTestCacic::cleanupTestCase() | ... | ... |
cacic-teste/testcacic.h
| ... | ... | @@ -27,7 +27,6 @@ private: |
| 27 | 27 | CacicComm OCacicComm; |
| 28 | 28 | CCacic OCacic; |
| 29 | 29 | CACIC_Computer OCacicComp; |
| 30 | - Gercols OGercols; | |
| 31 | 30 | QString testPath; |
| 32 | 31 | QString testIniPath; |
| 33 | 32 | QJsonObject session; |
| ... | ... | @@ -61,7 +60,10 @@ private slots: |
| 61 | 60 | void testOperatingSystemToJsonObject(); |
| 62 | 61 | void testJsonToFile(); |
| 63 | 62 | void testJsonFromFile(); |
| 63 | + void testStartService(); | |
| 64 | 64 | void testReadConfig(); |
| 65 | + void testSetRegistry(); | |
| 66 | + void testRemoveRegistry(); | |
| 65 | 67 | void cleanupTestCase(); |
| 66 | 68 | }; |
| 67 | 69 | ... | ... |
gercols/gercols.cpp
| 1 | 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 | 1 | #ifndef GERCOLS_H |
| 2 | 2 | #define GERCOLS_H |
| 3 | - | |
| 4 | 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 | 7 | class Gercols : public QObject |
| 12 | 8 | { |
| 13 | 9 | Q_OBJECT |
| 10 | +private: | |
| 11 | + CCacic oCacic; | |
| 12 | + CColeta oColeta; | |
| 14 | 13 | public: |
| 15 | 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 | 19 | signals: |
| 24 | 20 | void finished(); |
| 25 | - | |
| 26 | -public slots: | |
| 27 | - void run(QStringList argv, int argc); | |
| 28 | - | |
| 21 | + void fimColeta(); | |
| 29 | 22 | }; |
| 30 | 23 | |
| 31 | 24 | #endif // GERCOLS_H | ... | ... |
gercols/gercols.pro
| ... | ... | @@ -25,6 +25,7 @@ SOURCES += \ |
| 25 | 25 | ../src/ccacic.cpp \ |
| 26 | 26 | ../src/cacic_computer.cpp \ |
| 27 | 27 | ../src/operatingsystem.cpp \ |
| 28 | + ../src/ccoleta.cpp \ | |
| 28 | 29 | ./gercols.cpp |
| 29 | 30 | |
| 30 | 31 | |
| ... | ... | @@ -33,6 +34,7 @@ HEADERS += \ |
| 33 | 34 | ../src/cacic_computer.h \ |
| 34 | 35 | ../src/operatingsystem.h \ |
| 35 | 36 | ../src/console.h \ |
| 37 | + ../src/ccoleta.h \ | |
| 36 | 38 | ./gercols.h |
| 37 | 39 | |
| 38 | 40 | INCLUDEPATH += ../src \ | ... | ... |
gercols/main.cpp
| ... | ... | @@ -4,18 +4,12 @@ |
| 4 | 4 | int main(int argc, char *argv[]) |
| 5 | 5 | { |
| 6 | 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 | 14 | return a.exec(); |
| 21 | 15 | } | ... | ... |
install-cacic/install-cacic.pro.user
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | 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 | 4 | <qtcreator> |
| 5 | 5 | <data> |
| 6 | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
| ... | ... | @@ -221,7 +221,7 @@ |
| 221 | 221 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> |
| 222 | 222 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
| 223 | 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 | 225 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> |
| 226 | 226 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> |
| 227 | 227 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> | ... | ... |
install-cacic/installcacic.cpp
| ... | ... | @@ -7,10 +7,9 @@ InstallCacic::InstallCacic(QObject *parent) : |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | void InstallCacic::run(QStringList argv, int argc) { |
| 10 | - QMap<QString, QString> args; | |
| 11 | 10 | bool ok; |
| 12 | 11 | //valida os parametros repassados |
| 13 | - validaParametros(argv, argc, &ok); | |
| 12 | + QMap<QString, QString> param = validaParametros(argv, argc, &ok); | |
| 14 | 13 | //se tiver usuario, senha e url |
| 15 | 14 | if (ok){ |
| 16 | 15 | oCacicComm.setUrlGerente(this->argumentos["host"]); |
| ... | ... | @@ -22,16 +21,29 @@ void InstallCacic::run(QStringList argv, int argc) { |
| 22 | 21 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); |
| 23 | 22 | oCacic.setCacicMainFolder("c:/cacic"); |
| 24 | 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 | 41 | std::cout << "Nao foi possivel realizar o login.\n " |
| 34 | 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 | 47 | } else { |
| 36 | 48 | std::cout << "\nInstalador do Agente Cacic.\n\n" |
| 37 | 49 | << "Parametros incorretos. (<obrigatorios> [opcional])\n\n" |
| ... | ... | @@ -53,6 +65,8 @@ QMap<QString, QString> InstallCacic::validaParametros(QStringList argv, int argc |
| 53 | 65 | QStringList auxList = aux.split("="); |
| 54 | 66 | if ((auxList.at(0).at(0) == '-') && (auxList.size() > 1)) |
| 55 | 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 | 71 | *ok = (bool) map.contains("host") && map.contains("user") && map.contains("password"); |
| 58 | 72 | if (*ok){ | ... | ... |
install-cacic/installcacic.h
| ... | ... | @@ -17,7 +17,9 @@ public: |
| 17 | 17 | QMap<QString, QString> getArgumentos(); |
| 18 | 18 | void setArgumentos(QMap<QString, QString> value); |
| 19 | 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 | 23 | private: |
| 22 | 24 | QMap<QString, QString> argumentos; |
| 23 | 25 | CacicComm oCacicComm; | ... | ... |
src/cacic_computer.cpp
| ... | ... | @@ -20,11 +20,9 @@ QList<QVariantMap> CACIC_Computer::networkInterfacesRunning(){ |
| 20 | 20 | |
| 21 | 21 | foreach (QNetworkInterface in, interface.allInterfaces()) { |
| 22 | 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 | 25 | mapInterface["nome"] = in.humanReadableName(); |
| 27 | - // qDebug() << in.hardwareAddress() << "\n"; | |
| 28 | 26 | mapInterface["mac"] = in.hardwareAddress(); |
| 29 | 27 | foreach (QNetworkAddressEntry ae, in.addressEntries()){ |
| 30 | 28 | if (ae.ip().scopeId() == ""){ |
| ... | ... | @@ -34,34 +32,26 @@ QList<QVariantMap> CACIC_Computer::networkInterfacesRunning(){ |
| 34 | 32 | mapInterface["ipv6"] = ae.ip().toString(); |
| 35 | 33 | mapInterface["netmask_ipv6"] = ae.netmask().toString(); |
| 36 | 34 | } |
| 37 | - // qDebug() << ae.ip().toString() << "\n"; | |
| 38 | 35 | } |
| 39 | 36 | listaMap.append(mapInterface); |
| 40 | 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 | 40 | return listaMap; |
| 50 | 41 | } |
| 51 | 42 | |
| 52 | 43 | QJsonObject CACIC_Computer::toJsonObject() |
| 53 | 44 | { |
| 54 | 45 | QJsonObject json; |
| 55 | - QJsonObject network; | |
| 46 | + QJsonArray network; | |
| 56 | 47 | int count = 1; |
| 57 | 48 | json["usuario"] = QJsonValue::fromVariant(QString::fromStdString(this->usuario)); |
| 58 | 49 | json["operatingSystem"] = this->oOperatingSystem.toJsonObject(); |
| 59 | 50 | foreach(QVariantMap auxMap, this->getNetworkInterface()){ |
| 60 | - network["network" + QVariant::fromValue(count).toString()] = QJsonObject::fromVariantMap(auxMap); | |
| 51 | + network.append(QJsonObject::fromVariantMap(auxMap)); | |
| 61 | 52 | count++; |
| 62 | 53 | } |
| 63 | 54 | json["networkDevices"] = network; |
| 64 | -// qDebug() << json; | |
| 65 | 55 | return json; |
| 66 | 56 | } |
| 67 | 57 | ... | ... |
src/ccacic.cpp
| ... | ... | @@ -159,16 +159,18 @@ QJsonObject CCacic::getJsonFromFile(QString filepath) |
| 159 | 159 | * */ |
| 160 | 160 | QString CCacic::enCrypt(std::string str_in, std::string iv) { |
| 161 | 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 | 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 | 186 | // * */ |
| 185 | 187 | QString CCacic::deCrypt(std::string str_in, std::string iv) { |
| 186 | 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 | 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 | 226 | /*Getters/Setters |
| 201 | 227 | * Begin: | ... | ... |
src/ccacic.h
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | #define CCACIC_H |
| 3 | 3 | |
| 4 | 4 | #include <QCoreApplication> |
| 5 | +#include <QProcess> | |
| 5 | 6 | #include <QObject> |
| 6 | 7 | #include <QFile> |
| 7 | 8 | #include <QSettings> |
| ... | ... | @@ -34,6 +35,10 @@ public: |
| 34 | 35 | QJsonValue jsonValueFromJsonString(QString json, QString key); |
| 35 | 36 | bool setJsonToFile(QJsonObject json, QString filepath); |
| 36 | 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 | 43 | //Geters/seters: |
| 39 | 44 | ... | ... |
src/console.h
| ... | ... | @@ -21,7 +21,7 @@ public: |
| 21 | 21 | options << "-c" << QString::fromStdString(input); |
| 22 | 22 | process->start("/bin/sh", options); |
| 23 | 23 | #elif defined(Q_OS_WIN) |
| 24 | - process->start(input); | |
| 24 | + process->start(QString::fromStdString(input)); | |
| 25 | 25 | #endif |
| 26 | 26 | process->waitForFinished(); |
| 27 | 27 | QString output = process->readAll(); | ... | ... |
src/operatingsystem.cpp
| ... | ... | @@ -2,8 +2,8 @@ |
| 2 | 2 | |
| 3 | 3 | OperatingSystem::OperatingSystem() |
| 4 | 4 | { |
| 5 | - this->idOs = this->coletaIdOs(); | |
| 6 | 5 | this->nomeOs = this->coletaNomeOs(); |
| 6 | + this->idOs = this->coletaIdOs(); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | |
| ... | ... | @@ -38,7 +38,7 @@ int OperatingSystem::coletaIdOs(){ |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | #else |
| 41 | - return 0; | |
| 41 | + return -1; | |
| 42 | 42 | #endif |
| 43 | 43 | } |
| 44 | 44 | |
| ... | ... | @@ -47,6 +47,7 @@ QString OperatingSystem::coletaNomeOs() |
| 47 | 47 | QString text; |
| 48 | 48 | QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); |
| 49 | 49 | foreach (text, environment) { |
| 50 | +// qDebug() << text; | |
| 50 | 51 | if (text.contains("OS=" , Qt::CaseInsensitive) || |
| 51 | 52 | text.contains("SESSION=", Qt::CaseInsensitive) ){ |
| 52 | 53 | QStringList split = text.split("="); | ... | ... |