From e665e55d9d5455d6f8977f5fa50dac43e85d7361 Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Wed, 13 Aug 2014 18:46:43 -0300 Subject: [PATCH] Test cacic alterado devido a algumas modificações na classe comm; Installcacic começando a ser implementado, já verificando os argumentos; Acrescentado 'sinal' na função de comunicação para retorno true ou false para saber se deu certo ou não --- cacic-teste/testcacic.cpp | 31 +++++++++++++++++++++++++++---- cacic-teste/testcacic.h | 14 ++++++++------ install-cacic/install-cacic.pro | 9 +++++++++ install-cacic/install-cacic.pro.user | 40 ++++++++++++++-------------------------- install-cacic/installcacic.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- install-cacic/installcacic.h | 17 ++++++++++++++--- install-cacic/main.cpp | 9 +++++---- src/cacic_comm.h | 30 ++++++++++++++++++++++++------ src/ccacic.cpp | 18 +++++++++--------- src/ccacic.h | 14 +++++++------- 10 files changed, 170 insertions(+), 70 deletions(-) diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index c8441a2..667968c 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -58,8 +58,9 @@ void CTestCacic::testCommStatus() void CTestCacic::testComm() { + bool ok; if (OCacicComm.commStatus()){ - QJsonObject jsonreply = OCacicComm.comm("/ws/get/test"); + QJsonObject jsonreply = OCacicComm.comm("/ws/get/test", &ok); // qDebug() << jsonreply["codestatus"].toString(); QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK")); } else @@ -100,16 +101,18 @@ void CTestCacic::testJsonValueFromJsonString() } void CTestCacic::testLogin(){ - QJsonObject jsonReply = OCacicComm.login(); + bool ok; + QJsonObject jsonReply = OCacicComm.login(&ok); QJsonValue sessionvalue = jsonReply["reply"]; // qDebug() << sessionvalue.toObject()["session"].toString(); // qDebug() << sessionvalue.toString(); - QVERIFY(sessionvalue.isObject()); + QVERIFY(ok); } void CTestCacic::testSslConnection() { - QJsonObject json = OCacicComm.comm("", QJsonObject(), true); + bool ok; + QJsonObject json = OCacicComm.comm("", &ok, QJsonObject(), true); QJsonValue jsonvalue = json["codestatus"]; // qDebug() << jsonvalue.toDouble(); QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); @@ -130,6 +133,26 @@ void CTestCacic::testDeCrypt(){ } +void CTestCacic::testInstallCacicStart() +{ +// char *argva[] = {"program name", "-host=teste.cacic.cpp", "-user=asda", "-password=qwesd", NULL}; +// int argca = sizeof(argva) / sizeof(char*) - 1; +// QCoreApplication a(argca, argva); + +// InstallCacic *oInstallCacic = new InstallCacic(&a); + +// QStringList args; +// for (int i = 0; i #include #include +#include "../install-cacic/installcacic.h" class CTestCacic : public QObject { @@ -20,12 +21,12 @@ public: explicit CTestCacic(QObject *parent = 0); private: - CacicComm OCacicComm; - CCacic OCacic; - CACIC_Computer OCacicComp; - QString testPath; - QString testIniPath; - QJsonObject session; + CacicComm OCacicComm; + CCacic OCacic; + CACIC_Computer OCacicComp; + QString testPath; + QString testIniPath; + QJsonObject session; signals: @@ -48,6 +49,7 @@ private slots: void testSslConnection(); void testEnCrypt(); void testDeCrypt(); + void testInstallCacicStart(); void cleanupTestCase(); }; diff --git a/install-cacic/install-cacic.pro b/install-cacic/install-cacic.pro index 69db888..4b8cb99 100644 --- a/install-cacic/install-cacic.pro +++ b/install-cacic/install-cacic.pro @@ -13,6 +13,12 @@ CONFIG += console CONFIG -= app_bundle CONFIG += c++11 +win32 { + LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp +} else { + LIBS += -L/usr/lib -lcryptopp +} + TEMPLATE = app SOURCES += main.cpp \ @@ -25,3 +31,6 @@ HEADERS += \ ../src/ccacic.h \ ../src/cacic_computer.h \ ../src/cacic_comm.h + +INCLUDEPATH += ../src \ + ../src/crypto++/include/ diff --git a/install-cacic/install-cacic.pro.user b/install-cacic/install-cacic.pro.user index 2d75127..5bcd0c3 100644 --- a/install-cacic/install-cacic.pro.user +++ b/install-cacic/install-cacic.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -54,14 +54,14 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.3.0 GCC 64bit - Desktop Qt 5.3.0 GCC 64bit - qt.53.gcc_64_kit + Desktop Qt 5.3.0 MinGW 32bit + Desktop Qt 5.3.0 MinGW 32bit + qt.53.win32_mingw482_kit 0 0 0 - /home/eduardo/srv/cacic-agente-new/build-install-cacic-Desktop_Qt_5_3_0_GCC_64bit-Debug + E:/LightBase/cacic-agente-project/builds/install-cacic true @@ -78,10 +78,7 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + false @@ -97,10 +94,7 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean @@ -120,7 +114,7 @@ true - /home/eduardo/srv/cacic-agente-new/build-install-cacic-Desktop_Qt_5_3_0_GCC_64bit-Release + E:/LightBase/cacic-agente-project/cacic-agente/build-install-cacic-Release true @@ -137,10 +131,7 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + false @@ -156,10 +147,7 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean @@ -231,9 +219,9 @@ 2 install-cacic - install-cacic2 - Qt4ProjectManager.Qt4RunConfiguration:/home/eduardo/srv/cacic-agente/install-cacic/install-cacic.pro - + + Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro + -host=10.1.0.137/cacic/web/app_dev.php -user=cacic -password=cacic123 install-cacic.pro false true @@ -254,7 +242,7 @@ ProjectExplorer.Project.Updater.EnvironmentId - {05f74523-32aa-49a4-aa35-22a4457a2f3f} + {2d43e969-a5af-4db4-9730-35c8f8cce80d} ProjectExplorer.Project.Updater.FileVersion diff --git a/install-cacic/installcacic.cpp b/install-cacic/installcacic.cpp index 207de84..1824a79 100644 --- a/install-cacic/installcacic.cpp +++ b/install-cacic/installcacic.cpp @@ -4,13 +4,61 @@ InstallCacic::InstallCacic(QObject *parent) : QObject(parent) { + +} + +void InstallCacic::run(QStringList argv, int argc) { + QMap args; + bool ok; + //valida os parametros repassados + validaParametros(argv, argc, &ok); + //se tiver usuario, senha e url + if (ok){ + oCacicComm.setUrlGerente(this->argumentos["host"]); + oCacicComm.setUsuario(this->argumentos["user"]); + oCacicComm.setPassword(this->argumentos["password"]); + QJsonObject jsonLogin = oCacicComm.login(&ok); + if (ok){ + //TODO: Conectado. armazenar chave em arquivo e sessao na comm; + qDebug() << "Logado"; + } + else + qDebug() << "falha no login"; + } else { + std::cout << "Parametros incorretos. ([obrigatorios] )\n"; + std::cout << " [-host=url_gerente] \n"; + std::cout << " [-user=usuario] \n"; + std::cout << " [-password=senha] \n"; + std::cout << " <-help> \n"; + } + + emit finished(); } -void InstallCacic::run() { - int code; - std::cout << "Hello World\n"; - std::cin >> code; - emit finished(code); +QMap InstallCacic::validaParametros(QStringList argv, int argc, bool *ok) +{ + QMap map; + for (int i = 0; i 1)) + map[auxList.at(0).mid(1)] = auxList.at(1); + } + *ok = (bool) map.contains("host") && map.contains("user") && map.contains("password"); + if (*ok){ + this->argumentos = map; + } + return map; +} + +QMap InstallCacic::getArgumentos() +{ + return argumentos; +} + +void InstallCacic::setArgumentos(QMap value) +{ + this->argumentos = value; } diff --git a/install-cacic/installcacic.h b/install-cacic/installcacic.h index 558f12e..4baaa7c 100644 --- a/install-cacic/installcacic.h +++ b/install-cacic/installcacic.h @@ -2,6 +2,10 @@ #define INSTALLCACIC_H #include +#include +#include +#include +#include class InstallCacic : public QObject { @@ -9,13 +13,20 @@ class InstallCacic : public QObject public: explicit InstallCacic(QObject *parent = 0); -private: + QMap getArgumentos(); + void setArgumentos(QMap value); + QMap validaParametros(QStringList argv, int argc, bool *ok); +private: + QMap argumentos; + CacicComm oCacicComm; + CACIC_Computer oCacicComputer; + CCacic oCacic; signals: - void finished(int); + void finished(); public slots: - void run(); + void run(QStringList argv, int argc); }; #endif // INSTALLCACIC_H diff --git a/install-cacic/main.cpp b/install-cacic/main.cpp index d0e1e2f..1e06ac7 100644 --- a/install-cacic/main.cpp +++ b/install-cacic/main.cpp @@ -5,15 +5,16 @@ int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - + QStringList args; + for (int i = 0; iurlGerente + route : this->urlSsl + route; req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); } else url = urlGerente + route; @@ -106,7 +106,7 @@ public: QJsonValue::fromVariant(replyVariant.toString()); // qDebug() << "Response:" << jsonObj["reply"]; // qDebug() << "Response:" << strReply; - + *ok = true; delete reply; } else { //failure @@ -156,14 +156,16 @@ public: * @return retorna json com sessão e chave de criptografia * exemplo: 200 OK */ - QJsonObject login() { + QJsonObject login(bool *ok) { + *ok = false; // Cria dados de login QVariantMap login; login["user"] = this->usuario; login["password"] = this->password; // QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); // Cria conexão e retorna Json da sessão - QJsonObject retorno = this->comm("/ws/neo/login", QJsonObject::fromVariantMap(login), true); +// qDebug() << "Conectando."; + QJsonObject retorno = this->comm("/ws/neo/login", ok, QJsonObject::fromVariantMap(login), true); return retorno; } @@ -175,6 +177,22 @@ public: this->urlSsl = value; } + QString getUrlGerente (){ + return this->urlGerente; + } + + void setUrlGerente(QString value){ + if (value.contains("http://", Qt::CaseInsensitive)){ + value = value.mid(value.indexOf("http://") + 7); + } else if (value.contains("https://", Qt::CaseInsensitive)){ + value = value.mid(value.indexOf("https://") + 8); + } + if (value.endsWith("/")){ + value.remove(value.size()-1, 1); + } + this->urlGerente = value; + } + QString getPassword() { return this->password; diff --git a/src/ccacic.cpp b/src/ccacic.cpp index e3b963e..e661e02 100644 --- a/src/ccacic.cpp +++ b/src/ccacic.cpp @@ -137,15 +137,15 @@ std::string CCacic::enCrypt(std::string str_in, std::string key, std::string iv) } /*deCrypt - * @parameter std::string str_in: string encriptada convertida em base64. - * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits - * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty - * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. - * *Um IV jamais deve ser utilizado mais de uma vez com a mesma chave. - * *(http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) - * *exemplo de iv: 0123456789123456 - * @return QString: retorna a string desencriptada convertida em base64. - * */ +// * @parameter std::string str_in: string encriptada convertida em base64. +// * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits +// * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty +// * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. +// * *Um IV jamais deve ser utilizado mais de uma vez com a mesma chave. +// * *(http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) +// * *exemplo de iv: 0123456789123456 +// * @return QString: retorna a string desencriptada convertida em base64. +// * */ std::string CCacic::deCrypt(std::string str_in, std::string key, std::string iv) { std::string str_out; CryptoPP::CFB_Mode::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); diff --git a/src/ccacic.h b/src/ccacic.h index 9028a53..df55571 100644 --- a/src/ccacic.h +++ b/src/ccacic.h @@ -4,19 +4,19 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include #include #include +#include +#include +#include +//#include +//#include +//#include +//#include class CCacic : public QObject { -- libgit2 0.21.2