Commit d3a104d576bad0d0f1b69787a67c6e494d8915be
1 parent
237ed6cf
Exists in
master
Conexão ssl, test ssl, nova funcao de auxilio json, tipo de lista de networkInterfaces alterada
Showing
7 changed files
with
53 additions
and
29 deletions
Show diff stats
cacic-teste/testcacic.cpp
| @@ -24,6 +24,7 @@ void CTestCacic::initTestCase() | @@ -24,6 +24,7 @@ void CTestCacic::initTestCase() | ||
| 24 | "2.5.1.1.256.32", | 24 | "2.5.1.1.256.32", |
| 25 | "2.8.1.7", | 25 | "2.8.1.7", |
| 26 | "2.8.1.6"); | 26 | "2.8.1.6"); |
| 27 | + OCacicComm.setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php"); | ||
| 27 | this->testPath = QDir::currentPath() + "/teste"; | 28 | this->testPath = QDir::currentPath() + "/teste"; |
| 28 | this->testIniPath = testPath + "/teste.ini"; | 29 | this->testIniPath = testPath + "/teste.ini"; |
| 29 | QVariantMap json; | 30 | QVariantMap json; |
| @@ -92,7 +93,7 @@ void CTestCacic::testDeCrypt(){ | @@ -92,7 +93,7 @@ void CTestCacic::testDeCrypt(){ | ||
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | void CTestCacic::testInterfaceDeRede(){ | 95 | void CTestCacic::testInterfaceDeRede(){ |
| 95 | - // qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); | 96 | +// qDebug() << OCacicComp.getNetworkInterface().at(0)["nome"].toString(); |
| 96 | QVERIFY2(!OCacicComp.getNetworkInterface().empty(), "Nenhuma interface de rede encontrada."); | 97 | QVERIFY2(!OCacicComp.getNetworkInterface().empty(), "Nenhuma interface de rede encontrada."); |
| 97 | } | 98 | } |
| 98 | 99 | ||
| @@ -105,22 +106,28 @@ void CTestCacic::testPegarUsu(){ | @@ -105,22 +106,28 @@ void CTestCacic::testPegarUsu(){ | ||
| 105 | } | 106 | } |
| 106 | 107 | ||
| 107 | void CTestCacic::testLogin(){ | 108 | void CTestCacic::testLogin(){ |
| 108 | - QJsonObject sessionjson = OCacicComm.login(); | ||
| 109 | - QJsonValue session_str = sessionjson["codestatus"]; | ||
| 110 | - // qDebug() << session_str.toVariant().toString(); | ||
| 111 | - QVERIFY(!session_str.isNull()); | 109 | + |
| 110 | + QVariantMap login; | ||
| 111 | + login["user"] = "eric"; | ||
| 112 | + login["password"] = "612ef9b1"; | ||
| 113 | + OCacicComm.setUrlSsl("https://10.1.0.137/cacic/web/app_dev.php"); | ||
| 114 | + QJsonObject json = OCacicComm.comm("/ws/neo/login", QJsonObject::fromVariantMap(login), true); | ||
| 115 | + QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); | ||
| 116 | +// qDebug() << sessionvalue.toString(); | ||
| 117 | + QVERIFY(!sessionvalue.isNull()); | ||
| 112 | } | 118 | } |
| 113 | 119 | ||
| 114 | void CTestCacic::testSslConnection() | 120 | void CTestCacic::testSslConnection() |
| 115 | { | 121 | { |
| 116 | - QVariantMap login; | ||
| 117 | - login["user"] = "cacic"; | ||
| 118 | - login["password"] = "cacic"; | ||
| 119 | - OCacicComm.setUrlSsl("https://teste.cacic.cc"); | ||
| 120 | - QJsonObject json = OCacicComm.comm("", QJsonObject::fromVariantMap(login), true); | ||
| 121 | - QJsonValue jsonvalue = json["reply"]; | ||
| 122 | -// qDebug() << jsonvalue.toVariant().toString(); | ||
| 123 | - QVERIFY(!jsonvalue.isNull()); | 122 | + QJsonObject json = OCacicComm.comm("", QJsonObject(), true); |
| 123 | + QJsonValue jsonvalue = json["codestatus"]; | ||
| 124 | +// qDebug() << jsonvalue.toString(); | ||
| 125 | + QVERIFY(jsonvalue.toString() == "200" || jsonvalue.toString() == "302"); | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +void CTestCacic::testJsonValueFromJsonString() | ||
| 129 | +{ | ||
| 130 | + QVERIFY(OCacic.jsonValueFromJsonString("{\"nome\":\"teste\"}", "nome").toString() == "teste"); | ||
| 124 | } | 131 | } |
| 125 | 132 | ||
| 126 | void CTestCacic::cleanupTestCase() | 133 | void CTestCacic::cleanupTestCase() |
cacic-teste/testcacic.h
| @@ -47,6 +47,7 @@ private slots: | @@ -47,6 +47,7 @@ private slots: | ||
| 47 | void testpegarOS(); | 47 | void testpegarOS(); |
| 48 | void testLogin(); | 48 | void testLogin(); |
| 49 | void testSslConnection(); | 49 | void testSslConnection(); |
| 50 | + void testJsonValueFromJsonString(); | ||
| 50 | void cleanupTestCase(); | 51 | void cleanupTestCase(); |
| 51 | }; | 52 | }; |
| 52 | 53 |
src/cacic_comm.h
| @@ -22,6 +22,7 @@ private: | @@ -22,6 +22,7 @@ private: | ||
| 22 | // FIXME: Get from configuration | 22 | // FIXME: Get from configuration |
| 23 | QString usuario = "user"; | 23 | QString usuario = "user"; |
| 24 | QString password = "123456"; | 24 | QString password = "123456"; |
| 25 | + std::string session; | ||
| 25 | 26 | ||
| 26 | public: | 27 | public: |
| 27 | CacicComm (){ | 28 | CacicComm (){ |
| @@ -34,7 +35,6 @@ public: | @@ -34,7 +35,6 @@ public: | ||
| 34 | QString so, QString cacicVersion, QString gercolsVersion) | 35 | QString so, QString cacicVersion, QString gercolsVersion) |
| 35 | { | 36 | { |
| 36 | this->urlGerente = urlGerente; | 37 | this->urlGerente = urlGerente; |
| 37 | - | ||
| 38 | params.addQueryItem("OperatingSystem", operatingSystem); | 38 | params.addQueryItem("OperatingSystem", operatingSystem); |
| 39 | params.addQueryItem("ComputerSystem",computerSystem); | 39 | params.addQueryItem("ComputerSystem",computerSystem); |
| 40 | params.addQueryItem("cs_cipher",csCipher); | 40 | params.addQueryItem("cs_cipher",csCipher); |
| @@ -94,6 +94,7 @@ public: | @@ -94,6 +94,7 @@ public: | ||
| 94 | QVariantMap replyValue; | 94 | QVariantMap replyValue; |
| 95 | //grava o código de retorno | 95 | //grava o código de retorno |
| 96 | replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); | 96 | replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); |
| 97 | +// qDebug() << "code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); | ||
| 97 | 98 | ||
| 98 | if (reply->error() == QNetworkReply::NoError) { | 99 | if (reply->error() == QNetworkReply::NoError) { |
| 99 | //se não houver erro, grava o retorno; | 100 | //se não houver erro, grava o retorno; |
src/cacic_computer.cpp
| @@ -14,32 +14,38 @@ CACIC_Computer::CACIC_Computer() | @@ -14,32 +14,38 @@ CACIC_Computer::CACIC_Computer() | ||
| 14 | * outra lista que conterá todas as interfaces. | 14 | * outra lista que conterá todas as interfaces. |
| 15 | * | 15 | * |
| 16 | */ | 16 | */ |
| 17 | -QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ | 17 | +QList<QVariantMap> CACIC_Computer::networkInterfacesRunning(){ |
| 18 | QNetworkInterface interface; | 18 | QNetworkInterface interface; |
| 19 | - QList<std::string> lista; | ||
| 20 | - QList<QList<std::string>> todasInterfaces; | 19 | + QVariantMap mapInterface; |
| 20 | + QList<QVariantMap> listaMap; | ||
| 21 | 21 | ||
| 22 | foreach (QNetworkInterface in, interface.allInterfaces()) { | 22 | foreach (QNetworkInterface in, interface.allInterfaces()) { |
| 23 | if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && | 23 | if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && |
| 24 | !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) && | 24 | !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) && |
| 25 | (bool)(in.flags() & QNetworkInterface::IsRunning)){ | 25 | (bool)(in.flags() & QNetworkInterface::IsRunning)){ |
| 26 | // qDebug() << in.humanReadableName() << "\n"; | 26 | // qDebug() << in.humanReadableName() << "\n"; |
| 27 | - lista.append(in.humanReadableName().toStdString()); | 27 | + mapInterface["nome"] = in.humanReadableName(); |
| 28 | // qDebug() << in.hardwareAddress() << "\n"; | 28 | // qDebug() << in.hardwareAddress() << "\n"; |
| 29 | - lista.append(in.hardwareAddress().toStdString()); | 29 | + mapInterface["mac"] = in.hardwareAddress(); |
| 30 | foreach (QNetworkAddressEntry ae, in.addressEntries()){ | 30 | foreach (QNetworkAddressEntry ae, in.addressEntries()){ |
| 31 | if (ae.ip().scopeId() == ""){ | 31 | if (ae.ip().scopeId() == ""){ |
| 32 | - lista.append(ae.ip().toString().toStdString()); | 32 | + mapInterface["ipv4"] = ae.ip().toString(); |
| 33 | } else { | 33 | } else { |
| 34 | - lista.append(ae.ip().toString().toStdString()); | 34 | + mapInterface["ipv6"] = ae.ip().toString(); |
| 35 | } | 35 | } |
| 36 | // qDebug() << ae.ip().toString() << "\n"; | 36 | // qDebug() << ae.ip().toString() << "\n"; |
| 37 | } | 37 | } |
| 38 | - todasInterfaces.append(lista); | ||
| 39 | - lista.clear(); | 38 | + listaMap.append(mapInterface); |
| 39 | + mapInterface.clear(); | ||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | - return todasInterfaces; | 42 | +// foreach (QVariantMap each, listaMap){ |
| 43 | + | ||
| 44 | +// foreach (QVariant eachValue, each.values()) | ||
| 45 | +// qDebug() << eachValue.toString(); | ||
| 46 | +// } | ||
| 47 | + | ||
| 48 | + return listaMap; | ||
| 43 | } | 49 | } |
| 44 | 50 | ||
| 45 | /*pegarOS | 51 | /*pegarOS |
| @@ -93,7 +99,7 @@ std::string CACIC_Computer::getUser() const { | @@ -93,7 +99,7 @@ std::string CACIC_Computer::getUser() const { | ||
| 93 | return usu; | 99 | return usu; |
| 94 | } | 100 | } |
| 95 | 101 | ||
| 96 | -QList<QList<std::string>> CACIC_Computer::getNetworkInterface() const | 102 | +QList<QVariantMap> CACIC_Computer::getNetworkInterface() const |
| 97 | { | 103 | { |
| 98 | return networkInterface; | 104 | return networkInterface; |
| 99 | } | 105 | } |
src/cacic_computer.h
| @@ -17,11 +17,11 @@ public: | @@ -17,11 +17,11 @@ public: | ||
| 17 | std::string pegarUsu(); | 17 | std::string pegarUsu(); |
| 18 | int getOs() const; | 18 | int getOs() const; |
| 19 | std::string getUser() const; | 19 | std::string getUser() const; |
| 20 | - QList<QList<std::string>> getNetworkInterface() const; | ||
| 21 | - QList<QList<std::string>> networkInterfacesRunning(); | 20 | + QList<QVariantMap> getNetworkInterface() const; |
| 21 | + QList<QVariantMap> networkInterfacesRunning(); | ||
| 22 | 22 | ||
| 23 | private: | 23 | private: |
| 24 | - QList<QList<std::string>> networkInterface; | 24 | + QList<QVariantMap> networkInterface; |
| 25 | int os; | 25 | int os; |
| 26 | std::string usu; | 26 | std::string usu; |
| 27 | 27 |
src/ccacic.cpp
| @@ -103,6 +103,11 @@ bool CCacic::deleteFile(QString path) | @@ -103,6 +103,11 @@ bool CCacic::deleteFile(QString path) | ||
| 103 | return true; | 103 | return true; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | +QJsonValue CCacic::jsonValueFromJsonString(QString json, QString key) | ||
| 107 | +{ | ||
| 108 | + return QJsonDocument::fromJson(json.toUtf8()).object()[key]; | ||
| 109 | +} | ||
| 110 | + | ||
| 106 | /*enCrypt | 111 | /*enCrypt |
| 107 | * @parameter std::string str_in: string que será encriptada (url). | 112 | * @parameter std::string str_in: string que será encriptada (url). |
| 108 | * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits | 113 | * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits |
src/ccacic.h
| @@ -14,7 +14,10 @@ | @@ -14,7 +14,10 @@ | ||
| 14 | #include <QSettings> | 14 | #include <QSettings> |
| 15 | #include <QDir> | 15 | #include <QDir> |
| 16 | #include <QDebug> | 16 | #include <QDebug> |
| 17 | -//#include <jvson.h> | 17 | +#include <QJsonDocument> |
| 18 | +#include <QJsonObject> | ||
| 19 | +#include <QJsonValue> | ||
| 20 | + | ||
| 18 | class CCacic : public QObject | 21 | class CCacic : public QObject |
| 19 | { | 22 | { |
| 20 | Q_OBJECT | 23 | Q_OBJECT |
| @@ -28,6 +31,7 @@ public: | @@ -28,6 +31,7 @@ public: | ||
| 28 | bool createFolder(QString path); | 31 | bool createFolder(QString path); |
| 29 | bool deleteFolder(QString path); | 32 | bool deleteFolder(QString path); |
| 30 | bool deleteFile(QString path); | 33 | bool deleteFile(QString path); |
| 34 | + QJsonValue jsonValueFromJsonString(QString json, QString key); | ||
| 31 | 35 | ||
| 32 | //Geters/seters: | 36 | //Geters/seters: |
| 33 | 37 |