Commit b0435f21501a980c7d9e8c701d6bc989a953b2f5
1 parent
9f6a985d
Exists in
master
Consulta WMI quase pronta, só falta colocar quais classes é pra pesquisar
Showing
9 changed files
with
132 additions
and
21 deletions
Show diff stats
cacic-teste/testcacic.cpp
@@ -228,7 +228,7 @@ void CTestCacic::testColetaSoftware() | @@ -228,7 +228,7 @@ void CTestCacic::testColetaSoftware() | ||
228 | void CTestCacic::testColetaHardware() | 228 | void CTestCacic::testColetaHardware() |
229 | { | 229 | { |
230 | OCacicHardware.iniciaColeta(); | 230 | OCacicHardware.iniciaColeta(); |
231 | - QVERIFY(false); | 231 | + QVERIFY(!OCacicHardware.toJsonObject().isEmpty()); |
232 | } | 232 | } |
233 | void CTestCacic::testConvertDouble() | 233 | void CTestCacic::testConvertDouble() |
234 | { | 234 | { |
gercols/gercols.pro
@@ -14,6 +14,7 @@ CONFIG -= app_bundle | @@ -14,6 +14,7 @@ CONFIG -= app_bundle | ||
14 | CONFIG += qt | 14 | CONFIG += qt |
15 | 15 | ||
16 | win32 { | 16 | win32 { |
17 | + QT += axcontainer | ||
17 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp | 18 | LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp |
18 | } else { | 19 | } else { |
19 | LIBS += -L/usr/lib -lcryptopp | 20 | LIBS += -L/usr/lib -lcryptopp |
install-cacic/install-cacic.pro.user
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <!DOCTYPE QtCreatorProject> | 2 | <!DOCTYPE QtCreatorProject> |
3 | -<!-- Written by QtCreator 3.1.2, 2014-08-27T13:16:15. --> | 3 | +<!-- Written by QtCreator 3.1.2, 2014-08-27T18:46:27. --> |
4 | <qtcreator> | 4 | <qtcreator> |
5 | <data> | 5 | <data> |
6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
src/cacic_hardware.cpp
@@ -14,13 +14,101 @@ void cacic_hardware::iniciaColeta() | @@ -14,13 +14,101 @@ void cacic_hardware::iniciaColeta() | ||
14 | #ifdef Q_OS_WIN | 14 | #ifdef Q_OS_WIN |
15 | QJsonObject cacic_hardware::coletaWin() | 15 | QJsonObject cacic_hardware::coletaWin() |
16 | { | 16 | { |
17 | + QJsonObject hardware; | ||
18 | + QStringList params; | ||
19 | + QJsonObject wmi; | ||
20 | + // Win32_ComputerSystem (Caption, Description, Domain, DNSHostName, Manufacturer, | ||
21 | + // Model, Name, PrimaryOwnerName, TotalPhysicalMemory, Workgroup) | ||
22 | + params << "Caption" << "Description" << "Domain" << "DNSHostName" << "Manufacturer" << "Model" | ||
23 | + << "Name" << "PrimaryOwnerName" << "TotalPhysicalMemory" << "Workgroup"; | ||
24 | + wmi = wmiSearch("Win32_ComputerSystem", params); | ||
25 | + if (!wmi.isEmpty()) | ||
26 | + hardware["ComputerSystem"] = wmiSearch("Win32_ComputerSystem", params); | ||
27 | + //Win32_PortableBattery | ||
28 | + // (Verifica se é notebook) | ||
29 | + params.clear(); | ||
30 | + hardware["IsNotebook"] = QJsonValue::fromVariant(!wmiSearch("Win32_PortableBattery", params).isEmpty()); | ||
31 | + //Win32_Bios | ||
32 | + // (Manufacturer, SMBIOSBIOSVersion, BIOSVersion, Version, SerialNumber, ReleaseDate) | ||
33 | + params.clear(); | ||
34 | + params << "Manufacturer" << "SMBIOSBIOSVersion" << "BIOSVersion" << "Version" << "SerialNumber" << "ReleaseDate"; | ||
35 | + wmi = wmiSearch("Win32_Bios", params); | ||
36 | + if (!wmi.isEmpty()) | ||
37 | + hardware["Bios"] = wmi; | ||
38 | + //Win32_BaseBoard | ||
39 | + // (Manufacturer, Model, SerialNumber) | ||
40 | + params.clear(); | ||
41 | + params << "Manufacturer" << "Model" << "SerialNumber"; | ||
42 | + wmi = wmiSearch("Win32_Baseboard", params); | ||
43 | + if (!wmi.isEmpty()) | ||
44 | + hardware["BaseBoard"] = wmi; | ||
45 | + //Win32_SystemEnclosure | ||
46 | + // (Manufacturer, ChassisTypes, SerialNumber, SMBIOSAssetTag) | ||
47 | + //Win32_FloppyDrive | ||
48 | + // (Manufacturer, Caption, Description, Name, MediaType, Size) | ||
49 | + //Win32_DiskDrive | ||
50 | + // (Manufacturer, Caption, Description, Name, MediaType, Size, SerialNumber, Model, FirmwareRevision) | ||
51 | + //Win32_CDROMDrive | ||
52 | + // (Manufacturer, Caption, Description, Name, MediaType, Size) | ||
53 | + //Win32_FloppyController | ||
54 | + // (Manufacturer, Caption, Description, Name) | ||
55 | + //Win32_SCSIController | ||
56 | + // (Manufacturer, Caption, Description, Name, HardwareVersion) | ||
57 | + //Win32_InfraredDevice | ||
58 | + // (Manufacturer, Caption, Description, Name) | ||
59 | + //Win32_USBController | ||
60 | + // (Manufacturer, Caption, Description, Name) | ||
61 | + //Win32_PCMCIAController | ||
62 | + // (Manufacturer, Caption, Description, Name) | ||
63 | + //Win32_VideoController | ||
64 | + // (Description, VideoProcessor, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution) | ||
65 | + //Win32_DesktopMonitor | ||
66 | + // (MonitorManufacturer, Caption, Description, MonitorType) | ||
67 | + //Win32_Printer | ||
68 | + // (Name, DriverName, PortName, ServerName, ShareName, HorizontalResolution, VerticalResolution, Comment, Shared, Network) | ||
69 | + //Win32_PortConnector | ||
70 | + // (ExternalReferenceDesignator, PortType, ConnectorType) | ||
71 | + //Win32_SerialPort | ||
72 | + // (Name, Caption, Description, StatusInfo) | ||
73 | + //Win32_Processor | ||
74 | + // (MaxClockSpeed, Name, Architecture, NumberOfCores, SocketDesignation, Manufacturer, Name, Architecture, NumberOfCores | ||
75 | + // CurrentClockSpeed, MaxClockSpeed, L2CacheSize, AddressWidth, DataWidth, VoltageCaps, CpuStatus, | ||
76 | + // ProcessorId || UniqueId, AddressWidth) | ||
77 | + //Win32_OperatingSystem | ||
78 | + // (Name, Version, CSDVersion, Description, InstallDate, Organization, RegisteredUser, SerialNumber) | ||
79 | + //Win32_SystemSlot | ||
80 | + // (Name, Description, SlotDesignation, CurrentUsage, Status, Shared) | ||
81 | + //Win32_LogicalDisk | ||
82 | + // (Caption, DriveType, Filesystem, VolumeName, ProviderName, Filesystem, VolumeName, Size, FreeSpace) | ||
83 | + //Win32_PhysicalMemory | ||
84 | + // (Caption, Description, BankLabel, DeviceLocator, Capacity, Speed, MemoryTypem, SerialNumber) | ||
85 | + //Win32_Keyboard | ||
86 | + // (Manufacturer, Caption, Description) | ||
87 | + //Win32_PointingDevice | ||
88 | + // (Manufacturer, Caption, Description, PointingType, DeviceInterface) | ||
89 | + //Win32_PnPSignedDriver | ||
90 | + // (Manufacturer, DeviceName, Description, Location, DeviceClass) | ||
91 | + qDebug() << hardware; | ||
92 | + return hardware; | ||
93 | +} | ||
94 | + | ||
95 | +QJsonObject cacic_hardware::wmiSearch(QString classe, QStringList params) | ||
96 | +{ | ||
97 | + QJsonObject wmiReturn; | ||
98 | + QString paramsString; | ||
99 | + if (!params.empty()){ | ||
100 | + for(int i = 0; i!=params.size();i++) | ||
101 | + paramsString.append(params.at(i) + ((i != params.size() - 1) ? "," : "")); | ||
102 | + } | ||
17 | QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); | 103 | QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); |
18 | QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)", | 104 | QAxObject *objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)", |
19 | QString("."), | 105 | QString("."), |
20 | QString("root\\CIMV2") | 106 | QString("root\\CIMV2") |
21 | ); | 107 | ); |
22 | QAxObject* returnList = objWMIService->querySubObject("ExecQuery(QString&)", | 108 | QAxObject* returnList = objWMIService->querySubObject("ExecQuery(QString&)", |
23 | - QString("SELECT * FROM Win32_ComputerSystem") | 109 | + QString("SELECT " + ((!paramsString.isEmpty()) ? |
110 | + paramsString : "*") + | ||
111 | + " FROM " + classe) | ||
24 | ); | 112 | ); |
25 | QAxObject *enum1 = returnList->querySubObject("_NewEnum"); | 113 | QAxObject *enum1 = returnList->querySubObject("_NewEnum"); |
26 | //ui->textBrowser_4->setHtml(enum1->generateDocumentation()); | 114 | //ui->textBrowser_4->setHtml(enum1->generateDocumentation()); |
@@ -36,17 +124,45 @@ QJsonObject cacic_hardware::coletaWin() | @@ -36,17 +124,45 @@ QJsonObject cacic_hardware::coletaWin() | ||
36 | VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT)); | 124 | VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT)); |
37 | if (enumInterface->Next(1,theItem,NULL) != S_FALSE){ | 125 | if (enumInterface->Next(1,theItem,NULL) != S_FALSE){ |
38 | QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); | 126 | QAxObject *item = new QAxObject((IUnknown *)theItem->punkVal); |
39 | - | ||
40 | if(item){ | 127 | if(item){ |
41 | - qDebug() <<" string is "<<item->dynamicCall("ProcessorId").toString(); | ||
42 | - qDebug() <<" string is "<<item->dynamicCall("GetText_(WbemObjectTextFormatEnum)", QVariant(1)).toString(); | 128 | + //pega o retorno da query |
129 | + QString instance = item->dynamicCall("GetObjectText_(int)", QVariant(0)).toString(); | ||
130 | + QStringList instanceList = instance.split("\n\t"); | ||
131 | + //Pra cada linha grava no json os valores com cada tag | ||
132 | + foreach(QString value, instanceList){ | ||
133 | + qDebug() << value; | ||
134 | + QStringList valueList = value.split("="); | ||
135 | + if (valueList.size() > 1){ | ||
136 | + QString tag = valueList.at(0).trimmed(); | ||
137 | + QString aux = valueList.at(1).trimmed(); | ||
138 | + aux.remove("\""); | ||
139 | + aux.remove(";"); | ||
140 | + aux.remove("\n"); | ||
141 | + //verifica se é lista | ||
142 | + qDebug() << aux; | ||
143 | + if(aux.contains("{") && aux.contains("}")){ | ||
144 | + QStringList auxList = aux.split(","); | ||
145 | + QJsonArray jList; | ||
146 | + foreach(QString valueList, auxList){ | ||
147 | + if (valueList.contains("{")) | ||
148 | + valueList.remove("{"); | ||
149 | + else if (valueList.contains("}")) | ||
150 | + valueList.remove("}"); | ||
151 | + jList.append(valueList.trimmed()); | ||
152 | + } | ||
153 | + wmiReturn[tag] = jList; | ||
154 | + } else { | ||
155 | + //O último valor sempre volta com "}" no final. | ||
156 | + if (aux.contains("}")) | ||
157 | + aux.remove("}"); | ||
158 | + wmiReturn[tag] = QJsonValue::fromVariant(aux.trimmed()); | ||
159 | + } | ||
160 | + } | ||
161 | + } | ||
43 | } | 162 | } |
44 | - // item-> | ||
45 | - //QString val = | ||
46 | - qDebug()<<"item name is "<< item->property("objectName").toString(); | ||
47 | } | 163 | } |
48 | } | 164 | } |
49 | - return QJsonObject(); | 165 | + return wmiReturn; |
50 | } | 166 | } |
51 | #elif defined(Q_OS_LINUX) | 167 | #elif defined(Q_OS_LINUX) |
52 | QJsonObject cacic_hardware::coletaLinux() | 168 | QJsonObject cacic_hardware::coletaLinux() |
src/cacic_hardware.h
@@ -22,12 +22,9 @@ public: | @@ -22,12 +22,9 @@ public: | ||
22 | private: | 22 | private: |
23 | #ifdef Q_OS_WIN | 23 | #ifdef Q_OS_WIN |
24 | QJsonObject coletaWin(); | 24 | QJsonObject coletaWin(); |
25 | + QJsonObject wmiSearch(QString classe, QStringList params); | ||
25 | 26 | ||
26 | #elif defined(Q_OS_LINUX) | 27 | #elif defined(Q_OS_LINUX) |
27 | -/* Thiago aqui: | ||
28 | - * Ao menos nos elif's tem que deixar com o "defined()". | ||
29 | - * Por isso antes eu preferia deixar todas essas verificações com ele, mesmo tendo o ifdef. | ||
30 | - */ | ||
31 | QJsonObject coletaLinux(); | 28 | QJsonObject coletaLinux(); |
32 | void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); | 29 | void coletaLinuxMem(QJsonObject &hardware, const QJsonObject &component); |
33 | void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); | 30 | void coletaLinuxCpu(QJsonObject &hardware, const QJsonObject &component); |
src/vqtconvert.cpp
src/vqtconvert.h
@@ -6,7 +6,7 @@ Created with: QT 4.5 and QT Creator 1.2 | @@ -6,7 +6,7 @@ Created with: QT 4.5 and QT Creator 1.2 | ||
6 | Tested on: Windows XP SP3 | 6 | Tested on: Windows XP SP3 |
7 | Bryan Cairns - August 2009 | 7 | Bryan Cairns - August 2009 |
8 | */ | 8 | */ |
9 | - | 9 | +#include <QObject> |
10 | #if defined(Q_OS_WIN) | 10 | #if defined(Q_OS_WIN) |
11 | 11 | ||
12 | #ifndef VQTCONVERT_H | 12 | #ifndef VQTCONVERT_H |
src/vregistry.cpp
@@ -6,10 +6,8 @@ Created with: QT 4.5 and QT Creator 1.2 | @@ -6,10 +6,8 @@ Created with: QT 4.5 and QT Creator 1.2 | ||
6 | Tested on: Windows XP SP3 | 6 | Tested on: Windows XP SP3 |
7 | Bryan Cairns | 7 | Bryan Cairns |
8 | */ | 8 | */ |
9 | - | ||
10 | -#if defined(Q_OS_WIN) | ||
11 | - | ||
12 | #include "vregistry.h" | 9 | #include "vregistry.h" |
10 | +#if defined(Q_OS_WIN) | ||
13 | #include "windows.h" | 11 | #include "windows.h" |
14 | #include "VQTConvert.h" | 12 | #include "VQTConvert.h" |
15 | #include <QString> | 13 | #include <QString> |
src/vregistry.h
@@ -6,7 +6,7 @@ Created with: QT 4.5 and QT Creator 1.2 | @@ -6,7 +6,7 @@ Created with: QT 4.5 and QT Creator 1.2 | ||
6 | Tested on: Windows XP SP3 | 6 | Tested on: Windows XP SP3 |
7 | Bryan Cairns | 7 | Bryan Cairns |
8 | */ | 8 | */ |
9 | - | 9 | +#include <QObject> |
10 | #if defined(Q_OS_WIN) | 10 | #if defined(Q_OS_WIN) |
11 | #ifndef VREGISTRY_H | 11 | #ifndef VREGISTRY_H |
12 | #define VREGISTRY_H | 12 | #define VREGISTRY_H |