diff --git a/cacic-teste/cacic-teste.pro b/cacic-teste/cacic-teste.pro index 0be3df3..295c43f 100644 --- a/cacic-teste/cacic-teste.pro +++ b/cacic-teste/cacic-teste.pro @@ -6,7 +6,7 @@ QT += testlib QT += network - +QT += axcontainer TARGET = cacic-teste CONFIG -= app_bundle CONFIG += c++11 @@ -21,10 +21,11 @@ SOURCES += \ testcacic.cpp \ ../src/ccacic.cpp \ ../src/cacic_computer.cpp \ - ../src/cacic_hardware.cpp \ ../src/operatingsystem.cpp \ ../src/cacic_software.cpp \ ../src/cacic_hardware.cpp \ + ../src/vqtconvert.cpp \ + ../src/vregistry.cpp \ # ../src/qtservice/src/qtservice.cpp \ # ../src/qtservice/src/qtservice_unix.cpp \ # ../src/qtservice/src/qtservice_win.cpp \ @@ -36,17 +37,19 @@ HEADERS += \ testcacic.h \ ../src/ccacic.h \ ../src/cacic_computer.h \ - ../src/cacic_hardware.h \ ../src/cacic_comm.h \ ../src/console.h \ ../src/operatingsystem.h \ ../src/cacic_software.h \ ../src/cacic_hardware.h \ + ../src/vqtconvert.h \ + ../src/vregistry.h \ # ../src/qtservice/src/qtservice.h \ # ../src/qtservice/src/qtservice_p.h \ # ../src/qtservice/src/qtunixserversocket.h \ # ../src/qtservice/src/qtunixsocket.h - ../src/cacic_hardware.h INCLUDEPATH += ../src \ ../src/crypto++/include/ + +include(../src/qtservice/src/qtservice.pri) diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index fc90068..2c7ee30 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -190,25 +190,6 @@ void CTestCacic::testStartService() QVERIFY(ok); } -void CTestCacic::testReadConfig() -{ - -// // Inicializa um arquivo de configuração stub -// // que seria parecido com o recebido do Gerente -// QJsonObject configJson; -// QJsonObject configHardware; - -// configHardware["computador"] = OCacicComp.toJsonObject(); - -// configJson["hardware"] = configHardware; - -// OCacic.setJsonToFile(configJson,"configRequest.json"); - - // Leitura do arquivo de configuração - - QVERIFY(false); -} - void CTestCacic::testSetRegistry() { QVariantMap valueMap; diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index 7f93756..2972872 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -16,9 +16,6 @@ #include #include #include -#include "../install-cacic/installcacic.h" -#include "../gercols/gercols.h" -#include "../cacicD/cacicd.h" class CTestCacic : public QObject { @@ -66,7 +63,6 @@ private slots: void testJsonToFile(); void testJsonFromFile(); void testStartService(); - void testReadConfig(); void testSetRegistry(); void testGetValueFromRegistry(); void testRemoveRegistry(); diff --git a/gercols/gercols.pro b/gercols/gercols.pro index 4b624c2..095a516 100644 --- a/gercols/gercols.pro +++ b/gercols/gercols.pro @@ -7,6 +7,7 @@ QT += core QT += network QT -= gui +QT += axcontainer TARGET = gercols CONFIG += console diff --git a/install-cacic/install-cacic.pro.user b/install-cacic/install-cacic.pro.user index 4d37786..6085eb7 100644 --- a/install-cacic/install-cacic.pro.user +++ b/install-cacic/install-cacic.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/src/cacic_hardware.cpp b/src/cacic_hardware.cpp index 1355276..f091a31 100644 --- a/src/cacic_hardware.cpp +++ b/src/cacic_hardware.cpp @@ -1,5 +1,4 @@ #include "cacic_hardware.h" - cacic_hardware::cacic_hardware() { } @@ -12,15 +11,30 @@ void cacic_hardware::iniciaColeta() this->coletaHardware = coletaLinux(); #endif } - +#ifdef Q_OS_WIN QJsonObject cacic_hardware::coletaWin() { -#if defined(Q_OS_WIN) - // Implementação seguindo as definições na documentação WMI. -#endif + QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); + QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)",QString("."),QString("root\\cimv2")); + if (objWMIService->isNull()) + { + return QJsonObject(); + } + QAxObject *returnList = objWMIService->querySubObject("ExecQuery(QString&)",QString("select SystemType from win32_computersystem")); + QAxObject *enum1 = returnList->querySubObject("_NewEnum"); + IEnumVARIANT* enumInterface; //to get this, include + enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface); + enumInterface->Reset(); //start at the beginning of the list. + for (int i=0;idynamicCall("Count").toInt();i++){ + VARIANT *theItem; + enumInterface->Next(1,theItem,NULL); + QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); + qDebug() << item->dynamicCall("Caption"); + } + return QJsonObject(); } - +#elif Q_OS_LINUX QJsonObject cacic_hardware::coletaLinux() { @@ -78,161 +92,6 @@ QJsonObject cacic_hardware::coletaLinux() return hardware; } -int cacic_hardware::wmi() -{ -// HRESULT hres; - -// // Step 1: -------------------------------------------------- -// // Initialize COM. ------------------------------------------ - -// hres = CoInitializeEx(0, COINIT_MULTITHREADED); -// if (FAILED(hres)) -// { -// cout << "Failed to initialize COM library. Error code = 0x" -// << hex << hres << endl; -// return 1; // Program has failed. -// } - -// // Step 2: -------------------------------------------------- -// // Set general COM security levels -------------------------- - -// hres = CoInitializeSecurity( -// NULL, -// -1, // COM authentication -// NULL, // Authentication services -// NULL, // Reserved -// RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication -// RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation -// NULL, // Authentication info -// EOAC_NONE, // Additional capabilities -// NULL // Reserved -// ); - - -// if (FAILED(hres)) -// { -// cout << "Failed to initialize security. Error code = 0x" -// << hex << hres << endl; -// CoUninitialize(); -// return 1; // Program has failed. -// } - -// // Step 3: --------------------------------------------------- -// // Obtain the initial locator to WMI ------------------------- - -// IWbemLocator *pLoc = NULL; - -// hres = CoCreateInstance( -// CLSID_WbemLocator, -// 0, -// CLSCTX_INPROC_SERVER, -// IID_IWbemLocator, (LPVOID *) &pLoc); - -// if (FAILED(hres)) -// { -// cout << "Failed to create IWbemLocator object." -// << " Err code = 0x" -// << hex << hres << endl; -// CoUninitialize(); -// return 1; // Program has failed. -// } - -// // Step 4: ----------------------------------------------------- -// // Connect to WMI through the IWbemLocator::ConnectServer method - -// IWbemServices *pSvc = NULL; - -// // Connect to the local root\cimv2 namespace -// // and obtain pointer pSvc to make IWbemServices calls. -// hres = pLoc->ConnectServer( -// _bstr_t(L"ROOT\\CIMV2"), -// NULL, -// NULL, -// 0, -// NULL, -// 0, -// 0, -// &pSvc -// ); - -// if (FAILED(hres)) -// { -// cout << "Could not connect. Error code = 0x" -// << hex << hres << endl; -// pLoc->Release(); -// CoUninitialize(); -// return 1; // Program has failed. -// } - -// cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; - - -// // Step 5: -------------------------------------------------- -// // Set security levels on the proxy ------------------------- - -// hres = CoSetProxyBlanket( -// pSvc, // Indicates the proxy to set -// RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx -// RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx -// NULL, // Server principal name -// RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx -// RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx -// NULL, // client identity -// EOAC_NONE // proxy capabilities -// ); - -// if (FAILED(hres)) -// { -// cout << "Could not set proxy blanket. Error code = 0x" -// << hex << hres << endl; -// pSvc->Release(); -// pLoc->Release(); -// CoUninitialize(); -// return 1; // Program has failed. -// } - -// // Step 6: -------------------------------------------------- -// // Use the IWbemServices pointer to make requests of WMI ---- - -// // For example, get the name of the operating system. -// // The IWbemService::ExecQueryAsync method will call -// // the QuerySink::Indicate method when it receives a result -// // and the QuerySink::Indicate method will display the OS name -// QuerySink* pResponseSink = new QuerySink(); -// hres = pSvc->ExecQueryAsync( -// bstr_t("WQL"), -// bstr_t("SELECT * FROM Win32_OperatingSystem"), -// WBEM_FLAG_BIDIRECTIONAL, -// NULL, -// pResponseSink); - -// if (FAILED(hres)) -// { -// cout << "Query for operating system name failed." -// << " Error code = 0x" -// << hex << hres << endl; -// pSvc->Release(); -// pLoc->Release(); -// pResponseSink->Release(); -// CoUninitialize(); -// return 1; // Program has failed. -// } - -// // Step 7: ------------------------------------------------- -// // Wait to get the data from the query in step 6 ----------- -// Sleep(500); -// pSvc->CancelAsyncCall(pResponseSink); - -// // Cleanup -// // ======== -// pSvc->Release(); -// pLoc->Release(); -// CoUninitialize(); - - return 0; // Program successfully completed. - -} - void cacic_hardware::coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component) { QJsonObject memory; @@ -297,7 +156,7 @@ void cacic_hardware::coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pc } } } - +#endif QJsonObject cacic_hardware::toJsonObject() { return coletaHardware; } diff --git a/src/cacic_hardware.h b/src/cacic_hardware.h index a7dc663..c4a9a47 100644 --- a/src/cacic_hardware.h +++ b/src/cacic_hardware.h @@ -3,20 +3,13 @@ #include #include #include -#include #include #include #include #include - -#if defined(Q_OS_WIN) - #define _WIN32_DCOM - #include - //using namespace std; - #include +#ifdef Q_OS_WIN + #include #include - # pragma comment(lib, "wbemuuid.lib") - #endif class cacic_hardware @@ -27,12 +20,14 @@ public: QJsonObject toJsonObject(); private: - int wmi(); +#ifdef Q_OS_WIN QJsonObject coletaWin(); +#elif Q_OS_LINUX QJsonObject coletaLinux(); void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson); +#endif CCacic oCacic; QJsonObject coletaHardware; diff --git a/src/cacic_software.cpp b/src/cacic_software.cpp index 8048606..ddfafa2 100644 --- a/src/cacic_software.cpp +++ b/src/cacic_software.cpp @@ -49,7 +49,7 @@ QJsonObject cacic_software::coletaWin() softwaresJson[key] = QJsonObject::fromVariantMap(software); } - qDebug() << softwaresJson; +// qDebug() << softwaesJson; } return softwaresJson; } -- libgit2 0.21.2