Commit dab2fadb6aa331e2f899341baa37b7e23acaff44
1 parent
f78ed3f8
Exists in
master
debug e merge
Showing
8 changed files
with
36 additions
and
201 deletions
Show diff stats
cacic-teste/cacic-teste.pro
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | |
| 7 | 7 | QT += testlib |
| 8 | 8 | QT += network |
| 9 | - | |
| 9 | +QT += axcontainer | |
| 10 | 10 | TARGET = cacic-teste |
| 11 | 11 | CONFIG -= app_bundle |
| 12 | 12 | CONFIG += c++11 |
| ... | ... | @@ -21,10 +21,11 @@ SOURCES += \ |
| 21 | 21 | testcacic.cpp \ |
| 22 | 22 | ../src/ccacic.cpp \ |
| 23 | 23 | ../src/cacic_computer.cpp \ |
| 24 | - ../src/cacic_hardware.cpp \ | |
| 25 | 24 | ../src/operatingsystem.cpp \ |
| 26 | 25 | ../src/cacic_software.cpp \ |
| 27 | 26 | ../src/cacic_hardware.cpp \ |
| 27 | + ../src/vqtconvert.cpp \ | |
| 28 | + ../src/vregistry.cpp \ | |
| 28 | 29 | # ../src/qtservice/src/qtservice.cpp \ |
| 29 | 30 | # ../src/qtservice/src/qtservice_unix.cpp \ |
| 30 | 31 | # ../src/qtservice/src/qtservice_win.cpp \ |
| ... | ... | @@ -36,17 +37,19 @@ HEADERS += \ |
| 36 | 37 | testcacic.h \ |
| 37 | 38 | ../src/ccacic.h \ |
| 38 | 39 | ../src/cacic_computer.h \ |
| 39 | - ../src/cacic_hardware.h \ | |
| 40 | 40 | ../src/cacic_comm.h \ |
| 41 | 41 | ../src/console.h \ |
| 42 | 42 | ../src/operatingsystem.h \ |
| 43 | 43 | ../src/cacic_software.h \ |
| 44 | 44 | ../src/cacic_hardware.h \ |
| 45 | + ../src/vqtconvert.h \ | |
| 46 | + ../src/vregistry.h \ | |
| 45 | 47 | # ../src/qtservice/src/qtservice.h \ |
| 46 | 48 | # ../src/qtservice/src/qtservice_p.h \ |
| 47 | 49 | # ../src/qtservice/src/qtunixserversocket.h \ |
| 48 | 50 | # ../src/qtservice/src/qtunixsocket.h |
| 49 | - ../src/cacic_hardware.h | |
| 50 | 51 | |
| 51 | 52 | INCLUDEPATH += ../src \ |
| 52 | 53 | ../src/crypto++/include/ |
| 54 | + | |
| 55 | +include(../src/qtservice/src/qtservice.pri) | ... | ... |
cacic-teste/testcacic.cpp
| ... | ... | @@ -190,25 +190,6 @@ void CTestCacic::testStartService() |
| 190 | 190 | QVERIFY(ok); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | -void CTestCacic::testReadConfig() | |
| 194 | -{ | |
| 195 | - | |
| 196 | -// // Inicializa um arquivo de configuração stub | |
| 197 | -// // que seria parecido com o recebido do Gerente | |
| 198 | -// QJsonObject configJson; | |
| 199 | -// QJsonObject configHardware; | |
| 200 | - | |
| 201 | -// configHardware["computador"] = OCacicComp.toJsonObject(); | |
| 202 | - | |
| 203 | -// configJson["hardware"] = configHardware; | |
| 204 | - | |
| 205 | -// OCacic.setJsonToFile(configJson,"configRequest.json"); | |
| 206 | - | |
| 207 | - // Leitura do arquivo de configuração | |
| 208 | - | |
| 209 | - QVERIFY(false); | |
| 210 | -} | |
| 211 | - | |
| 212 | 193 | void CTestCacic::testSetRegistry() |
| 213 | 194 | { |
| 214 | 195 | QVariantMap valueMap; | ... | ... |
cacic-teste/testcacic.h
| ... | ... | @@ -16,9 +16,6 @@ |
| 16 | 16 | #include <iostream> |
| 17 | 17 | #include <QtNetwork/QtNetwork> |
| 18 | 18 | #include <QJsonObject> |
| 19 | -#include "../install-cacic/installcacic.h" | |
| 20 | -#include "../gercols/gercols.h" | |
| 21 | -#include "../cacicD/cacicd.h" | |
| 22 | 19 | |
| 23 | 20 | class CTestCacic : public QObject |
| 24 | 21 | { |
| ... | ... | @@ -66,7 +63,6 @@ private slots: |
| 66 | 63 | void testJsonToFile(); |
| 67 | 64 | void testJsonFromFile(); |
| 68 | 65 | void testStartService(); |
| 69 | - void testReadConfig(); | |
| 70 | 66 | void testSetRegistry(); |
| 71 | 67 | void testGetValueFromRegistry(); |
| 72 | 68 | void testRemoveRegistry(); | ... | ... |
gercols/gercols.pro
install-cacic/install-cacic.pro.user
src/cacic_hardware.cpp
| 1 | 1 | #include "cacic_hardware.h" |
| 2 | - | |
| 3 | 2 | cacic_hardware::cacic_hardware() |
| 4 | 3 | { |
| 5 | 4 | } |
| ... | ... | @@ -12,15 +11,30 @@ void cacic_hardware::iniciaColeta() |
| 12 | 11 | this->coletaHardware = coletaLinux(); |
| 13 | 12 | #endif |
| 14 | 13 | } |
| 15 | - | |
| 14 | +#ifdef Q_OS_WIN | |
| 16 | 15 | QJsonObject cacic_hardware::coletaWin() |
| 17 | 16 | { |
| 18 | -#if defined(Q_OS_WIN) | |
| 19 | - // Implementação seguindo as definições na documentação WMI. | |
| 20 | -#endif | |
| 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 | + | |
| 21 | 35 | return QJsonObject(); |
| 22 | 36 | } |
| 23 | - | |
| 37 | +#elif Q_OS_LINUX | |
| 24 | 38 | QJsonObject cacic_hardware::coletaLinux() |
| 25 | 39 | { |
| 26 | 40 | |
| ... | ... | @@ -78,161 +92,6 @@ QJsonObject cacic_hardware::coletaLinux() |
| 78 | 92 | return hardware; |
| 79 | 93 | } |
| 80 | 94 | |
| 81 | -int cacic_hardware::wmi() | |
| 82 | -{ | |
| 83 | -// HRESULT hres; | |
| 84 | - | |
| 85 | -// // Step 1: -------------------------------------------------- | |
| 86 | -// // Initialize COM. ------------------------------------------ | |
| 87 | - | |
| 88 | -// hres = CoInitializeEx(0, COINIT_MULTITHREADED); | |
| 89 | -// if (FAILED(hres)) | |
| 90 | -// { | |
| 91 | -// cout << "Failed to initialize COM library. Error code = 0x" | |
| 92 | -// << hex << hres << endl; | |
| 93 | -// return 1; // Program has failed. | |
| 94 | -// } | |
| 95 | - | |
| 96 | -// // Step 2: -------------------------------------------------- | |
| 97 | -// // Set general COM security levels -------------------------- | |
| 98 | - | |
| 99 | -// hres = CoInitializeSecurity( | |
| 100 | -// NULL, | |
| 101 | -// -1, // COM authentication | |
| 102 | -// NULL, // Authentication services | |
| 103 | -// NULL, // Reserved | |
| 104 | -// RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication | |
| 105 | -// RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation | |
| 106 | -// NULL, // Authentication info | |
| 107 | -// EOAC_NONE, // Additional capabilities | |
| 108 | -// NULL // Reserved | |
| 109 | -// ); | |
| 110 | - | |
| 111 | - | |
| 112 | -// if (FAILED(hres)) | |
| 113 | -// { | |
| 114 | -// cout << "Failed to initialize security. Error code = 0x" | |
| 115 | -// << hex << hres << endl; | |
| 116 | -// CoUninitialize(); | |
| 117 | -// return 1; // Program has failed. | |
| 118 | -// } | |
| 119 | - | |
| 120 | -// // Step 3: --------------------------------------------------- | |
| 121 | -// // Obtain the initial locator to WMI ------------------------- | |
| 122 | - | |
| 123 | -// IWbemLocator *pLoc = NULL; | |
| 124 | - | |
| 125 | -// hres = CoCreateInstance( | |
| 126 | -// CLSID_WbemLocator, | |
| 127 | -// 0, | |
| 128 | -// CLSCTX_INPROC_SERVER, | |
| 129 | -// IID_IWbemLocator, (LPVOID *) &pLoc); | |
| 130 | - | |
| 131 | -// if (FAILED(hres)) | |
| 132 | -// { | |
| 133 | -// cout << "Failed to create IWbemLocator object." | |
| 134 | -// << " Err code = 0x" | |
| 135 | -// << hex << hres << endl; | |
| 136 | -// CoUninitialize(); | |
| 137 | -// return 1; // Program has failed. | |
| 138 | -// } | |
| 139 | - | |
| 140 | -// // Step 4: ----------------------------------------------------- | |
| 141 | -// // Connect to WMI through the IWbemLocator::ConnectServer method | |
| 142 | - | |
| 143 | -// IWbemServices *pSvc = NULL; | |
| 144 | - | |
| 145 | -// // Connect to the local root\cimv2 namespace | |
| 146 | -// // and obtain pointer pSvc to make IWbemServices calls. | |
| 147 | -// hres = pLoc->ConnectServer( | |
| 148 | -// _bstr_t(L"ROOT\\CIMV2"), | |
| 149 | -// NULL, | |
| 150 | -// NULL, | |
| 151 | -// 0, | |
| 152 | -// NULL, | |
| 153 | -// 0, | |
| 154 | -// 0, | |
| 155 | -// &pSvc | |
| 156 | -// ); | |
| 157 | - | |
| 158 | -// if (FAILED(hres)) | |
| 159 | -// { | |
| 160 | -// cout << "Could not connect. Error code = 0x" | |
| 161 | -// << hex << hres << endl; | |
| 162 | -// pLoc->Release(); | |
| 163 | -// CoUninitialize(); | |
| 164 | -// return 1; // Program has failed. | |
| 165 | -// } | |
| 166 | - | |
| 167 | -// cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; | |
| 168 | - | |
| 169 | - | |
| 170 | -// // Step 5: -------------------------------------------------- | |
| 171 | -// // Set security levels on the proxy ------------------------- | |
| 172 | - | |
| 173 | -// hres = CoSetProxyBlanket( | |
| 174 | -// pSvc, // Indicates the proxy to set | |
| 175 | -// RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx | |
| 176 | -// RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx | |
| 177 | -// NULL, // Server principal name | |
| 178 | -// RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx | |
| 179 | -// RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx | |
| 180 | -// NULL, // client identity | |
| 181 | -// EOAC_NONE // proxy capabilities | |
| 182 | -// ); | |
| 183 | - | |
| 184 | -// if (FAILED(hres)) | |
| 185 | -// { | |
| 186 | -// cout << "Could not set proxy blanket. Error code = 0x" | |
| 187 | -// << hex << hres << endl; | |
| 188 | -// pSvc->Release(); | |
| 189 | -// pLoc->Release(); | |
| 190 | -// CoUninitialize(); | |
| 191 | -// return 1; // Program has failed. | |
| 192 | -// } | |
| 193 | - | |
| 194 | -// // Step 6: -------------------------------------------------- | |
| 195 | -// // Use the IWbemServices pointer to make requests of WMI ---- | |
| 196 | - | |
| 197 | -// // For example, get the name of the operating system. | |
| 198 | -// // The IWbemService::ExecQueryAsync method will call | |
| 199 | -// // the QuerySink::Indicate method when it receives a result | |
| 200 | -// // and the QuerySink::Indicate method will display the OS name | |
| 201 | -// QuerySink* pResponseSink = new QuerySink(); | |
| 202 | -// hres = pSvc->ExecQueryAsync( | |
| 203 | -// bstr_t("WQL"), | |
| 204 | -// bstr_t("SELECT * FROM Win32_OperatingSystem"), | |
| 205 | -// WBEM_FLAG_BIDIRECTIONAL, | |
| 206 | -// NULL, | |
| 207 | -// pResponseSink); | |
| 208 | - | |
| 209 | -// if (FAILED(hres)) | |
| 210 | -// { | |
| 211 | -// cout << "Query for operating system name failed." | |
| 212 | -// << " Error code = 0x" | |
| 213 | -// << hex << hres << endl; | |
| 214 | -// pSvc->Release(); | |
| 215 | -// pLoc->Release(); | |
| 216 | -// pResponseSink->Release(); | |
| 217 | -// CoUninitialize(); | |
| 218 | -// return 1; // Program has failed. | |
| 219 | -// } | |
| 220 | - | |
| 221 | -// // Step 7: ------------------------------------------------- | |
| 222 | -// // Wait to get the data from the query in step 6 ----------- | |
| 223 | -// Sleep(500); | |
| 224 | -// pSvc->CancelAsyncCall(pResponseSink); | |
| 225 | - | |
| 226 | -// // Cleanup | |
| 227 | -// // ======== | |
| 228 | -// pSvc->Release(); | |
| 229 | -// pLoc->Release(); | |
| 230 | -// CoUninitialize(); | |
| 231 | - | |
| 232 | - return 0; // Program successfully completed. | |
| 233 | - | |
| 234 | -} | |
| 235 | - | |
| 236 | 95 | void cacic_hardware::coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component) |
| 237 | 96 | { |
| 238 | 97 | QJsonObject memory; |
| ... | ... | @@ -297,7 +156,7 @@ void cacic_hardware::coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pc |
| 297 | 156 | } |
| 298 | 157 | } |
| 299 | 158 | } |
| 300 | - | |
| 159 | +#endif | |
| 301 | 160 | QJsonObject cacic_hardware::toJsonObject() { |
| 302 | 161 | return coletaHardware; |
| 303 | 162 | } | ... | ... |
src/cacic_hardware.h
| ... | ... | @@ -3,20 +3,13 @@ |
| 3 | 3 | #include <ccacic.h> |
| 4 | 4 | #include <QtCore> |
| 5 | 5 | #include <QJsonArray> |
| 6 | -#include <QJsonArray> | |
| 7 | 6 | #include <cmath> |
| 8 | 7 | #include <ccacic.h> |
| 9 | 8 | #include <console.h> |
| 10 | 9 | #include <operatingsystem.h> |
| 11 | - | |
| 12 | -#if defined(Q_OS_WIN) | |
| 13 | - #define _WIN32_DCOM | |
| 14 | - #include <iostream> | |
| 15 | - //using namespace std; | |
| 16 | - #include <wbemidl.h> | |
| 10 | +#ifdef Q_OS_WIN | |
| 11 | + #include <QAxObject> | |
| 17 | 12 | #include <windows.h> |
| 18 | - # pragma comment(lib, "wbemuuid.lib") | |
| 19 | - | |
| 20 | 13 | #endif |
| 21 | 14 | |
| 22 | 15 | class cacic_hardware |
| ... | ... | @@ -27,12 +20,14 @@ public: |
| 27 | 20 | QJsonObject toJsonObject(); |
| 28 | 21 | |
| 29 | 22 | private: |
| 30 | - int wmi(); | |
| 23 | +#ifdef Q_OS_WIN | |
| 31 | 24 | QJsonObject coletaWin(); |
| 25 | +#elif Q_OS_LINUX | |
| 32 | 26 | QJsonObject coletaLinux(); |
| 33 | 27 | void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); |
| 34 | 28 | void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); |
| 35 | 29 | void coletaLinuxPci(QJsonObject &hardware, const QJsonObject &pciJson); |
| 30 | +#endif | |
| 36 | 31 | |
| 37 | 32 | CCacic oCacic; |
| 38 | 33 | QJsonObject coletaHardware; | ... | ... |
src/cacic_software.cpp