Commit 0e8988e849e26ad23014f14feed28579b3d9d1b9
1 parent
c1389ace
Exists in
master
Começo do wmi
Showing
6 changed files
with
54 additions
and
48 deletions
Show diff stats
cacic-teste/cacic-teste.pro
| @@ -6,8 +6,10 @@ | @@ -6,8 +6,10 @@ | ||
| 6 | 6 | ||
| 7 | QT += testlib | 7 | QT += testlib |
| 8 | QT += network | 8 | QT += network |
| 9 | -QT += axcontainer | 9 | + |
| 10 | TARGET = cacic-teste | 10 | TARGET = cacic-teste |
| 11 | + | ||
| 12 | +QT += axcontainer | ||
| 11 | CONFIG -= app_bundle | 13 | CONFIG -= app_bundle |
| 12 | CONFIG += c++11 | 14 | CONFIG += c++11 |
| 13 | TEMPLATE = app | 15 | TEMPLATE = app |
cacic-teste/testcacic.cpp
| @@ -158,6 +158,7 @@ void CTestCacic::testDeCrypt(){ | @@ -158,6 +158,7 @@ void CTestCacic::testDeCrypt(){ | ||
| 158 | void CTestCacic::testCacicCompToJsonObject() | 158 | void CTestCacic::testCacicCompToJsonObject() |
| 159 | { | 159 | { |
| 160 | // qDebug() << OCacicComp.toJsonObject(); | 160 | // qDebug() << OCacicComp.toJsonObject(); |
| 161 | +// OCacic.setJsonToFile(OCacicComp.toJsonObject(), "jsoncomp.json"); | ||
| 161 | QVERIFY(!OCacicComp.toJsonObject().empty()); | 162 | QVERIFY(!OCacicComp.toJsonObject().empty()); |
| 162 | } | 163 | } |
| 163 | 164 | ||
| @@ -238,6 +239,15 @@ void CTestCacic::testConvertDouble() | @@ -238,6 +239,15 @@ void CTestCacic::testConvertDouble() | ||
| 238 | QVERIFY(converted.toDouble() == number); | 239 | QVERIFY(converted.toDouble() == number); |
| 239 | } | 240 | } |
| 240 | 241 | ||
| 242 | +void CTestCacic::testGetTest() | ||
| 243 | +{ | ||
| 244 | + bool ok; | ||
| 245 | + QJsonObject envio; | ||
| 246 | + envio["computador"] = OCacicComp.toJsonObject(); | ||
| 247 | + OCacicComm.setUrlGerente("http://10.1.0.137/cacic/web/app_dev.php"); | ||
| 248 | + QVERIFY(ok); | ||
| 249 | +} | ||
| 250 | + | ||
| 241 | void CTestCacic::cleanupTestCase() | 251 | void CTestCacic::cleanupTestCase() |
| 242 | { | 252 | { |
| 243 | OCacic.deleteFile("configRequest.json"); | 253 | OCacic.deleteFile("configRequest.json"); |
cacic-teste/testcacic.h
| @@ -70,6 +70,7 @@ private slots: | @@ -70,6 +70,7 @@ private slots: | ||
| 70 | void testColetaSoftware(); | 70 | void testColetaSoftware(); |
| 71 | void testColetaHardware(); | 71 | void testColetaHardware(); |
| 72 | void testConvertDouble(); | 72 | void testConvertDouble(); |
| 73 | + void testGetTest(); | ||
| 73 | void cleanupTestCase(); | 74 | void cleanupTestCase(); |
| 74 | }; | 75 | }; |
| 75 | 76 |
src/cacic_comm.h
| @@ -19,7 +19,6 @@ private: | @@ -19,7 +19,6 @@ private: | ||
| 19 | QUrlQuery params; | 19 | QUrlQuery params; |
| 20 | QString urlGerente; | 20 | QString urlGerente; |
| 21 | QString urlSsl; | 21 | QString urlSsl; |
| 22 | - // FIXME: Get from configuration | ||
| 23 | QString usuario; | 22 | QString usuario; |
| 24 | QString password; | 23 | QString password; |
| 25 | QString session; | 24 | QString session; |
| @@ -67,35 +66,27 @@ public: | @@ -67,35 +66,27 @@ public: | ||
| 67 | url = "http://" + urlGerente + route; | 66 | url = "http://" + urlGerente + route; |
| 68 | req.setUrl(url); | 67 | req.setUrl(url); |
| 69 | req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); | 68 | req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); |
| 70 | - if (json.empty()) | ||
| 71 | - { | 69 | + if (json.empty()){ |
| 72 | //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) | 70 | //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) |
| 73 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); | 71 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); |
| 74 | data.append(params.toString()); | 72 | data.append(params.toString()); |
| 75 | } else { | 73 | } else { |
| 76 | // Add JSON | 74 | // Add JSON |
| 77 | QJsonDocument d(json); | 75 | QJsonDocument d(json); |
| 78 | - data.append(d.toVariant().toString()); | 76 | + data.append(d.toJson()); |
| 79 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 77 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); |
| 80 | } | 78 | } |
| 81 | -// qDebug() << QString::fromUtf8(d.toJson().trimmed()); | ||
| 82 | - // cria um event-loop temporario | ||
| 83 | QEventLoop eventLoop; | 79 | QEventLoop eventLoop; |
| 84 | - // "quit()" o event-loop, when the network request "finished()" | ||
| 85 | QNetworkAccessManager mgr; | 80 | QNetworkAccessManager mgr; |
| 86 | QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); | 81 | QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); |
| 87 | 82 | ||
| 88 | - // a requisição HTTP | ||
| 89 | - | ||
| 90 | QNetworkReply *reply = mgr.post(req, data); | 83 | QNetworkReply *reply = mgr.post(req, data); |
| 91 | if (!reply->sslConfiguration().isNull()){ | 84 | if (!reply->sslConfiguration().isNull()){ |
| 92 | -// qDebug() << "Eh ssl"; | ||
| 93 | reply->ignoreSslErrors(); | 85 | reply->ignoreSslErrors(); |
| 94 | } | 86 | } |
| 95 | eventLoop.exec(); // sai do looping chamando o "finished()". | 87 | eventLoop.exec(); // sai do looping chamando o "finished()". |
| 96 | - //grava codigo de retorno | 88 | + |
| 97 | jsonObj.insert("codestatus", QJsonValue::fromVariant(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute))); | 89 | jsonObj.insert("codestatus", QJsonValue::fromVariant(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute))); |
| 98 | -// qDebug() << "code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); | ||
| 99 | 90 | ||
| 100 | if (reply->error() == QNetworkReply::NoError) { | 91 | if (reply->error() == QNetworkReply::NoError) { |
| 101 | //se não houver erro, grava o retorno; | 92 | //se não houver erro, grava o retorno; |
| @@ -104,20 +95,13 @@ public: | @@ -104,20 +95,13 @@ public: | ||
| 104 | jsonObj["reply"] = (!replyDocument.isNull()) ? | 95 | jsonObj["reply"] = (!replyDocument.isNull()) ? |
| 105 | replyDocument.object() : | 96 | replyDocument.object() : |
| 106 | QJsonValue::fromVariant(replyVariant.toString()); | 97 | QJsonValue::fromVariant(replyVariant.toString()); |
| 107 | -// qDebug() << "Response:" << jsonObj["reply"]; | ||
| 108 | -// qDebug() << "Response:" << strReply; | ||
| 109 | *ok = true; | 98 | *ok = true; |
| 110 | delete reply; | 99 | delete reply; |
| 111 | } else { | 100 | } else { |
| 112 | - //failure | ||
| 113 | -// qDebug() << "Failure" <<reply->errorString(); | ||
| 114 | strReply = reply->errorString(); | 101 | strReply = reply->errorString(); |
| 115 | jsonObj.insert("error", QJsonValue::fromVariant(strReply)); | 102 | jsonObj.insert("error", QJsonValue::fromVariant(strReply)); |
| 116 | delete reply; | 103 | delete reply; |
| 117 | - | ||
| 118 | - | ||
| 119 | } | 104 | } |
| 120 | - //retorna o json; | ||
| 121 | return jsonObj; | 105 | return jsonObj; |
| 122 | } | 106 | } |
| 123 | 107 | ||
| @@ -154,7 +138,6 @@ public: | @@ -154,7 +138,6 @@ public: | ||
| 154 | /* login | 138 | /* login |
| 155 | * realiza login com usuario e senha | 139 | * realiza login com usuario e senha |
| 156 | * @return retorna json com sessão e chave de criptografia | 140 | * @return retorna json com sessão e chave de criptografia |
| 157 | - * exemplo: 200 OK | ||
| 158 | */ | 141 | */ |
| 159 | QJsonObject login(bool *ok) { | 142 | QJsonObject login(bool *ok) { |
| 160 | *ok = false; | 143 | *ok = false; |
| @@ -162,10 +145,8 @@ public: | @@ -162,10 +145,8 @@ public: | ||
| 162 | QVariantMap login; | 145 | QVariantMap login; |
| 163 | login["user"] = this->usuario; | 146 | login["user"] = this->usuario; |
| 164 | login["password"] = this->password; | 147 | login["password"] = this->password; |
| 165 | -// QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); | ||
| 166 | // Cria conexão e retorna Json da sessão | 148 | // Cria conexão e retorna Json da sessão |
| 167 | -// qDebug() << "Conectando."; | ||
| 168 | - QJsonObject retorno = this->comm("/ws/neo/login", ok, QJsonObject::fromVariantMap(login), true); | 149 | + QJsonObject retorno = this->comm("/ws/neo/getLogin", ok, QJsonObject::fromVariantMap(login), true); |
| 169 | if (*ok) | 150 | if (*ok) |
| 170 | this->session = retorno["reply"].toObject()["session"].toString(); | 151 | this->session = retorno["reply"].toObject()["session"].toString(); |
| 171 | return retorno; | 152 | return retorno; |
| @@ -184,10 +165,8 @@ public: | @@ -184,10 +165,8 @@ public: | ||
| 184 | } | 165 | } |
| 185 | 166 | ||
| 186 | void setUrlGerente(QString value){ | 167 | void setUrlGerente(QString value){ |
| 187 | - if (value.contains("http://", Qt::CaseInsensitive)){ | ||
| 188 | - value = value.mid(value.indexOf("http://") + 7); | ||
| 189 | - } else if (value.contains("https://", Qt::CaseInsensitive)){ | ||
| 190 | - value = value.mid(value.indexOf("https://") + 8); | 168 | + if (value.contains("://", Qt::CaseInsensitive)){ |
| 169 | + value = value.mid(value.indexOf("://") + 3); | ||
| 191 | } | 170 | } |
| 192 | if (value.endsWith("/")){ | 171 | if (value.endsWith("/")){ |
| 193 | value.remove(value.size()-1, 1); | 172 | value.remove(value.size()-1, 1); |
src/cacic_hardware.cpp
| @@ -13,25 +13,39 @@ void cacic_hardware::iniciaColeta() | @@ -13,25 +13,39 @@ void cacic_hardware::iniciaColeta() | ||
| 13 | } | 13 | } |
| 14 | #ifdef Q_OS_WIN | 14 | #ifdef Q_OS_WIN |
| 15 | QJsonObject cacic_hardware::coletaWin() | 15 | QJsonObject cacic_hardware::coletaWin() |
| 16 | -{ | ||
| 17 | -// QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); | ||
| 18 | -// QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)",QString("."),QString("root\\cimv2")); | ||
| 19 | -// if (objWMIService->isNull()) | ||
| 20 | -// { | ||
| 21 | -// return QJsonObject(); | ||
| 22 | -// } | ||
| 23 | -// QAxObject *returnList = objWMIService->querySubObject("ExecQuery(QString&)",QString("select SystemType from win32_computersystem")); | ||
| 24 | -// QAxObject *enum1 = returnList->querySubObject("_NewEnum"); | ||
| 25 | -// IEnumVARIANT* enumInterface; //to get this, include <windows.h> | ||
| 26 | -// enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface); | ||
| 27 | -// enumInterface->Reset(); //start at the beginning of the list. | ||
| 28 | -// for (int i=0;i<returnList->dynamicCall("Count").toInt();i++){ | ||
| 29 | -// VARIANT *theItem; | ||
| 30 | -// enumInterface->Next(1,theItem,NULL); | ||
| 31 | -// QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); | ||
| 32 | -// qDebug() << item->dynamicCall("Caption"); | ||
| 33 | -// } | ||
| 34 | - | 16 | +{ |
| 17 | + QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); | ||
| 18 | + QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)", | ||
| 19 | + QString("."), | ||
| 20 | + QString("root\\CIMV2") | ||
| 21 | + ); | ||
| 22 | + QAxObject* returnList = objWMIService->querySubObject("ExecQuery(QString&)", | ||
| 23 | + QString("SELECT * FROM Win32_ComputerSystem") | ||
| 24 | + ); | ||
| 25 | + QAxObject *enum1 = returnList->querySubObject("_NewEnum"); | ||
| 26 | + //ui->textBrowser_4->setHtml(enum1->generateDocumentation()); | ||
| 27 | + IEnumVARIANT* enumInterface = 0; | ||
| 28 | + enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface); | ||
| 29 | + | ||
| 30 | + //ui->textBrowser_4->setHtml(enumInterface->); | ||
| 31 | + enumInterface->Reset(); | ||
| 32 | + // QAxObject *item = 0; | ||
| 33 | + | ||
| 34 | + //qDebug()<<"the count of objinterlist is "<<QString::number(objInterList->dynamicCall("Count").toInt()); | ||
| 35 | + for (int i = 0; i < returnList->dynamicCall("Count").toInt(); i++) { | ||
| 36 | + VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT)); | ||
| 37 | + if (enumInterface->Next(1,theItem,NULL) != S_FALSE){ | ||
| 38 | + QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); | ||
| 39 | + | ||
| 40 | + if(item){ | ||
| 41 | + qDebug() <<" string is "<<item->dynamicCall("ProcessorId").toString(); | ||
| 42 | + qDebug() <<" string is "<<item->dynamicCall("GetText_(WbemObjectTextFormatEnum)", QVariant(1)).toString(); | ||
| 43 | + } | ||
| 44 | + // item-> | ||
| 45 | + //QString val = | ||
| 46 | + qDebug()<<"item name is "<< item->property("objectName").toString(); | ||
| 47 | + } | ||
| 48 | + } | ||
| 35 | return QJsonObject(); | 49 | return QJsonObject(); |
| 36 | } | 50 | } |
| 37 | #elif Q_OS_LINUX | 51 | #elif Q_OS_LINUX |
src/cacic_hardware.h
| @@ -8,8 +8,8 @@ | @@ -8,8 +8,8 @@ | ||
| 8 | #include <console.h> | 8 | #include <console.h> |
| 9 | #include <operatingsystem.h> | 9 | #include <operatingsystem.h> |
| 10 | #ifdef Q_OS_WIN | 10 | #ifdef Q_OS_WIN |
| 11 | -// #include <QAxObject> | ||
| 12 | #include <windows.h> | 11 | #include <windows.h> |
| 12 | + #include <ActiveQt/ActiveQt> | ||
| 13 | #endif | 13 | #endif |
| 14 | 14 | ||
| 15 | class cacic_hardware | 15 | class cacic_hardware |