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
cacic-teste/testcacic.cpp
| ... | ... | @@ -158,6 +158,7 @@ void CTestCacic::testDeCrypt(){ |
| 158 | 158 | void CTestCacic::testCacicCompToJsonObject() |
| 159 | 159 | { |
| 160 | 160 | // qDebug() << OCacicComp.toJsonObject(); |
| 161 | +// OCacic.setJsonToFile(OCacicComp.toJsonObject(), "jsoncomp.json"); | |
| 161 | 162 | QVERIFY(!OCacicComp.toJsonObject().empty()); |
| 162 | 163 | } |
| 163 | 164 | |
| ... | ... | @@ -238,6 +239,15 @@ void CTestCacic::testConvertDouble() |
| 238 | 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 | 251 | void CTestCacic::cleanupTestCase() |
| 242 | 252 | { |
| 243 | 253 | OCacic.deleteFile("configRequest.json"); | ... | ... |
cacic-teste/testcacic.h
src/cacic_comm.h
| ... | ... | @@ -19,7 +19,6 @@ private: |
| 19 | 19 | QUrlQuery params; |
| 20 | 20 | QString urlGerente; |
| 21 | 21 | QString urlSsl; |
| 22 | - // FIXME: Get from configuration | |
| 23 | 22 | QString usuario; |
| 24 | 23 | QString password; |
| 25 | 24 | QString session; |
| ... | ... | @@ -67,35 +66,27 @@ public: |
| 67 | 66 | url = "http://" + urlGerente + route; |
| 68 | 67 | req.setUrl(url); |
| 69 | 68 | req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); |
| 70 | - if (json.empty()) | |
| 71 | - { | |
| 69 | + if (json.empty()){ | |
| 72 | 70 | //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) |
| 73 | 71 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); |
| 74 | 72 | data.append(params.toString()); |
| 75 | 73 | } else { |
| 76 | 74 | // Add JSON |
| 77 | 75 | QJsonDocument d(json); |
| 78 | - data.append(d.toVariant().toString()); | |
| 76 | + data.append(d.toJson()); | |
| 79 | 77 | req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); |
| 80 | 78 | } |
| 81 | -// qDebug() << QString::fromUtf8(d.toJson().trimmed()); | |
| 82 | - // cria um event-loop temporario | |
| 83 | 79 | QEventLoop eventLoop; |
| 84 | - // "quit()" o event-loop, when the network request "finished()" | |
| 85 | 80 | QNetworkAccessManager mgr; |
| 86 | 81 | QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); |
| 87 | 82 | |
| 88 | - // a requisição HTTP | |
| 89 | - | |
| 90 | 83 | QNetworkReply *reply = mgr.post(req, data); |
| 91 | 84 | if (!reply->sslConfiguration().isNull()){ |
| 92 | -// qDebug() << "Eh ssl"; | |
| 93 | 85 | reply->ignoreSslErrors(); |
| 94 | 86 | } |
| 95 | 87 | eventLoop.exec(); // sai do looping chamando o "finished()". |
| 96 | - //grava codigo de retorno | |
| 88 | + | |
| 97 | 89 | jsonObj.insert("codestatus", QJsonValue::fromVariant(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute))); |
| 98 | -// qDebug() << "code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); | |
| 99 | 90 | |
| 100 | 91 | if (reply->error() == QNetworkReply::NoError) { |
| 101 | 92 | //se não houver erro, grava o retorno; |
| ... | ... | @@ -104,20 +95,13 @@ public: |
| 104 | 95 | jsonObj["reply"] = (!replyDocument.isNull()) ? |
| 105 | 96 | replyDocument.object() : |
| 106 | 97 | QJsonValue::fromVariant(replyVariant.toString()); |
| 107 | -// qDebug() << "Response:" << jsonObj["reply"]; | |
| 108 | -// qDebug() << "Response:" << strReply; | |
| 109 | 98 | *ok = true; |
| 110 | 99 | delete reply; |
| 111 | 100 | } else { |
| 112 | - //failure | |
| 113 | -// qDebug() << "Failure" <<reply->errorString(); | |
| 114 | 101 | strReply = reply->errorString(); |
| 115 | 102 | jsonObj.insert("error", QJsonValue::fromVariant(strReply)); |
| 116 | 103 | delete reply; |
| 117 | - | |
| 118 | - | |
| 119 | 104 | } |
| 120 | - //retorna o json; | |
| 121 | 105 | return jsonObj; |
| 122 | 106 | } |
| 123 | 107 | |
| ... | ... | @@ -154,7 +138,6 @@ public: |
| 154 | 138 | /* login |
| 155 | 139 | * realiza login com usuario e senha |
| 156 | 140 | * @return retorna json com sessão e chave de criptografia |
| 157 | - * exemplo: 200 OK | |
| 158 | 141 | */ |
| 159 | 142 | QJsonObject login(bool *ok) { |
| 160 | 143 | *ok = false; |
| ... | ... | @@ -162,10 +145,8 @@ public: |
| 162 | 145 | QVariantMap login; |
| 163 | 146 | login["user"] = this->usuario; |
| 164 | 147 | login["password"] = this->password; |
| 165 | -// QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); | |
| 166 | 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 | 150 | if (*ok) |
| 170 | 151 | this->session = retorno["reply"].toObject()["session"].toString(); |
| 171 | 152 | return retorno; |
| ... | ... | @@ -184,10 +165,8 @@ public: |
| 184 | 165 | } |
| 185 | 166 | |
| 186 | 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 | 171 | if (value.endsWith("/")){ |
| 193 | 172 | value.remove(value.size()-1, 1); | ... | ... |
src/cacic_hardware.cpp
| ... | ... | @@ -13,25 +13,39 @@ void cacic_hardware::iniciaColeta() |
| 13 | 13 | } |
| 14 | 14 | #ifdef Q_OS_WIN |
| 15 | 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 | 49 | return QJsonObject(); |
| 36 | 50 | } |
| 37 | 51 | #elif Q_OS_LINUX | ... | ... |
src/cacic_hardware.h