Commit ba316028b1050a3d3059d210843ea9c67aa5a6ce
1 parent
50cd216a
Exists in
master
Inserção da classe hardware.
Showing
10 changed files
with
248 additions
and
18 deletions
Show diff stats
cacic-teste/cacic-teste.pro
... | ... | @@ -21,6 +21,7 @@ SOURCES += \ |
21 | 21 | testcacic.cpp \ |
22 | 22 | ../src/ccacic.cpp \ |
23 | 23 | ../src/cacic_computer.cpp \ |
24 | + ../src/cacic_hardware.cpp \ | |
24 | 25 | ../src/operatingsystem.cpp \ |
25 | 26 | ../src/cacic_software.cpp \ |
26 | 27 | # ../src/qtservice/src/qtservice.cpp \ |
... | ... | @@ -34,6 +35,7 @@ HEADERS += \ |
34 | 35 | testcacic.h \ |
35 | 36 | ../src/ccacic.h \ |
36 | 37 | ../src/cacic_computer.h \ |
38 | + ../src/cacic_hardware.h \ | |
37 | 39 | ../src/cacic_comm.h \ |
38 | 40 | ../src/console.h \ |
39 | 41 | ../src/operatingsystem.h \ | ... | ... |
cacic-teste/testcacic.cpp
... | ... | @@ -243,6 +243,12 @@ void CTestCacic::testColetaSoftware() |
243 | 243 | QVERIFY(!OCacicSoftware.toJsonObject().empty()); |
244 | 244 | } |
245 | 245 | |
246 | +void CTestCacic::testColetaHardware() | |
247 | +{ | |
248 | + OCacicHardware.iniciaColeta(); | |
249 | + QVERIFY(false); | |
250 | +} | |
251 | + | |
246 | 252 | void CTestCacic::cleanupTestCase() |
247 | 253 | { |
248 | 254 | OCacic.deleteFile("configRequest.json"); | ... | ... |
cacic-teste/testcacic.h
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | #include <ccacic.h> |
6 | 6 | #include <cacic_computer.h> |
7 | 7 | #include <cacic_software.h> |
8 | +#include <cacic_hardware.h> | |
8 | 9 | #include <console.h> |
9 | 10 | #include <operatingsystem.h> |
10 | 11 | #include <QtTest/QtTest> |
... | ... | @@ -30,6 +31,7 @@ private: |
30 | 31 | CCacic OCacic; |
31 | 32 | CACIC_Computer OCacicComp; |
32 | 33 | cacic_software OCacicSoftware; |
34 | + cacic_hardware OCacicHardware; | |
33 | 35 | QString testPath; |
34 | 36 | QString testIniPath; |
35 | 37 | QJsonObject session; |
... | ... | @@ -70,6 +72,7 @@ private slots: |
70 | 72 | void testRemoveRegistry(); |
71 | 73 | void testIniciarDaemon(); |
72 | 74 | void testColetaSoftware(); |
75 | + void testColetaHardware(); | |
73 | 76 | void cleanupTestCase(); |
74 | 77 | }; |
75 | 78 | ... | ... |
gercols/gercols.cpp
... | ... | @@ -45,11 +45,9 @@ void Gercols::run() |
45 | 45 | //emite sinal para começar a coleta |
46 | 46 | emit iniciaColeta(); |
47 | 47 | |
48 | - | |
49 | - //salva coleta em json | |
50 | - qDebug() << oColeta->toJsonObject(); | |
51 | 48 | //salva json em arquivo |
52 | 49 | oCacic.setJsonToFile(oColeta->toJsonObject(), "coleta.json"); |
50 | + oCacic.deleteFile("configReq.json"); | |
53 | 51 | //emite sinal "finished" pra finalizar a aplicação |
54 | 52 | emit finished(); |
55 | 53 | } | ... | ... |
gercols/gercols.pro
... | ... | @@ -26,6 +26,7 @@ SOURCES += \ |
26 | 26 | ../src/ccacic.cpp \ |
27 | 27 | ../src/cacic_computer.cpp \ |
28 | 28 | ../src/cacic_software.cpp \ |
29 | + ../src/cacic_hardware.cpp \ | |
29 | 30 | ../src/operatingsystem.cpp \ |
30 | 31 | ../src/ccoleta.cpp \ |
31 | 32 | ./gercols.cpp |
... | ... | @@ -35,6 +36,7 @@ HEADERS += \ |
35 | 36 | ../src/ccacic.h \ |
36 | 37 | ../src/cacic_computer.h \ |
37 | 38 | ../src/cacic_software.h \ |
39 | + ../src/cacic_hardware.h \ | |
38 | 40 | ../src/operatingsystem.h \ |
39 | 41 | ../src/console.h \ |
40 | 42 | ../src/ccoleta.h \ | ... | ... |
install-cacic/install-cacic.pro.user
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | 2 | <!DOCTYPE QtCreatorProject> |
3 | -<!-- Written by QtCreator 3.1.2, 2014-08-18T18:02:05. --> | |
3 | +<!-- Written by QtCreator 3.1.2, 2014-08-20T18:37:20. --> | |
4 | 4 | <qtcreator> |
5 | 5 | <data> |
6 | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
... | ... | @@ -217,7 +217,9 @@ |
217 | 217 | <value type="int">14</value> |
218 | 218 | </valuelist> |
219 | 219 | <value type="int" key="PE.EnvironmentAspect.Base">2</value> |
220 | - <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> | |
220 | + <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"> | |
221 | + <value type="QString">PROCESSOR_ARCHITECTURE=x64</value> | |
222 | + </valuelist> | |
221 | 223 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> |
222 | 224 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
223 | 225 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro</value> | ... | ... |
src/cacic_hardware.cpp
... | ... | @@ -3,3 +3,188 @@ |
3 | 3 | cacic_hardware::cacic_hardware() |
4 | 4 | { |
5 | 5 | } |
6 | + | |
7 | +void cacic_hardware::iniciaColeta() | |
8 | +{ | |
9 | +#ifdef Q_OS_WIN | |
10 | + this->coletaHardware = coletaWin(); | |
11 | +#else | |
12 | + this->coletaHardware = coletaLinux(); | |
13 | +#endif | |
14 | +} | |
15 | + | |
16 | +QJsonObject cacic_hardware::coletaWin() | |
17 | +{ | |
18 | + QJsonObject coleta; | |
19 | + wmi(); | |
20 | + return coleta; | |
21 | +} | |
22 | + | |
23 | +QJsonObject cacic_hardware::coletaLinux() | |
24 | +{ | |
25 | + QJsonObject coleta; | |
26 | + | |
27 | + return coleta; | |
28 | +} | |
29 | + | |
30 | + | |
31 | +QJsonObject cacic_hardware::toJsonObject() | |
32 | +{ | |
33 | + QJsonObject coleta; | |
34 | + | |
35 | + return coleta; | |
36 | +} | |
37 | + | |
38 | +int cacic_hardware::wmi() | |
39 | +{ | |
40 | +// HRESULT hres; | |
41 | + | |
42 | +// // Step 1: -------------------------------------------------- | |
43 | +// // Initialize COM. ------------------------------------------ | |
44 | + | |
45 | +// hres = CoInitializeEx(0, COINIT_MULTITHREADED); | |
46 | +// if (FAILED(hres)) | |
47 | +// { | |
48 | +// cout << "Failed to initialize COM library. Error code = 0x" | |
49 | +// << hex << hres << endl; | |
50 | +// return 1; // Program has failed. | |
51 | +// } | |
52 | + | |
53 | +// // Step 2: -------------------------------------------------- | |
54 | +// // Set general COM security levels -------------------------- | |
55 | + | |
56 | +// hres = CoInitializeSecurity( | |
57 | +// NULL, | |
58 | +// -1, // COM authentication | |
59 | +// NULL, // Authentication services | |
60 | +// NULL, // Reserved | |
61 | +// RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication | |
62 | +// RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation | |
63 | +// NULL, // Authentication info | |
64 | +// EOAC_NONE, // Additional capabilities | |
65 | +// NULL // Reserved | |
66 | +// ); | |
67 | + | |
68 | + | |
69 | +// if (FAILED(hres)) | |
70 | +// { | |
71 | +// cout << "Failed to initialize security. Error code = 0x" | |
72 | +// << hex << hres << endl; | |
73 | +// CoUninitialize(); | |
74 | +// return 1; // Program has failed. | |
75 | +// } | |
76 | + | |
77 | +// // Step 3: --------------------------------------------------- | |
78 | +// // Obtain the initial locator to WMI ------------------------- | |
79 | + | |
80 | +// IWbemLocator *pLoc = NULL; | |
81 | + | |
82 | +// hres = CoCreateInstance( | |
83 | +// CLSID_WbemLocator, | |
84 | +// 0, | |
85 | +// CLSCTX_INPROC_SERVER, | |
86 | +// IID_IWbemLocator, (LPVOID *) &pLoc); | |
87 | + | |
88 | +// if (FAILED(hres)) | |
89 | +// { | |
90 | +// cout << "Failed to create IWbemLocator object." | |
91 | +// << " Err code = 0x" | |
92 | +// << hex << hres << endl; | |
93 | +// CoUninitialize(); | |
94 | +// return 1; // Program has failed. | |
95 | +// } | |
96 | + | |
97 | +// // Step 4: ----------------------------------------------------- | |
98 | +// // Connect to WMI through the IWbemLocator::ConnectServer method | |
99 | + | |
100 | +// IWbemServices *pSvc = NULL; | |
101 | + | |
102 | +// // Connect to the local root\cimv2 namespace | |
103 | +// // and obtain pointer pSvc to make IWbemServices calls. | |
104 | +// hres = pLoc->ConnectServer( | |
105 | +// _bstr_t(L"ROOT\\CIMV2"), | |
106 | +// NULL, | |
107 | +// NULL, | |
108 | +// 0, | |
109 | +// NULL, | |
110 | +// 0, | |
111 | +// 0, | |
112 | +// &pSvc | |
113 | +// ); | |
114 | + | |
115 | +// if (FAILED(hres)) | |
116 | +// { | |
117 | +// cout << "Could not connect. Error code = 0x" | |
118 | +// << hex << hres << endl; | |
119 | +// pLoc->Release(); | |
120 | +// CoUninitialize(); | |
121 | +// return 1; // Program has failed. | |
122 | +// } | |
123 | + | |
124 | +// cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; | |
125 | + | |
126 | + | |
127 | +// // Step 5: -------------------------------------------------- | |
128 | +// // Set security levels on the proxy ------------------------- | |
129 | + | |
130 | +// hres = CoSetProxyBlanket( | |
131 | +// pSvc, // Indicates the proxy to set | |
132 | +// RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx | |
133 | +// RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx | |
134 | +// NULL, // Server principal name | |
135 | +// RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx | |
136 | +// RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx | |
137 | +// NULL, // client identity | |
138 | +// EOAC_NONE // proxy capabilities | |
139 | +// ); | |
140 | + | |
141 | +// if (FAILED(hres)) | |
142 | +// { | |
143 | +// cout << "Could not set proxy blanket. Error code = 0x" | |
144 | +// << hex << hres << endl; | |
145 | +// pSvc->Release(); | |
146 | +// pLoc->Release(); | |
147 | +// CoUninitialize(); | |
148 | +// return 1; // Program has failed. | |
149 | +// } | |
150 | + | |
151 | +// // Step 6: -------------------------------------------------- | |
152 | +// // Use the IWbemServices pointer to make requests of WMI ---- | |
153 | + | |
154 | +// // For example, get the name of the operating system. | |
155 | +// // The IWbemService::ExecQueryAsync method will call | |
156 | +// // the QuerySink::Indicate method when it receives a result | |
157 | +// // and the QuerySink::Indicate method will display the OS name | |
158 | +// QuerySink* pResponseSink = new QuerySink(); | |
159 | +// hres = pSvc->ExecQueryAsync( | |
160 | +// bstr_t("WQL"), | |
161 | +// bstr_t("SELECT * FROM Win32_OperatingSystem"), | |
162 | +// WBEM_FLAG_BIDIRECTIONAL, | |
163 | +// NULL, | |
164 | +// pResponseSink); | |
165 | + | |
166 | +// if (FAILED(hres)) | |
167 | +// { | |
168 | +// cout << "Query for operating system name failed." | |
169 | +// << " Error code = 0x" | |
170 | +// << hex << hres << endl; | |
171 | +// pSvc->Release(); | |
172 | +// pLoc->Release(); | |
173 | +// pResponseSink->Release(); | |
174 | +// CoUninitialize(); | |
175 | +// return 1; // Program has failed. | |
176 | +// } | |
177 | + | |
178 | +// // Step 7: ------------------------------------------------- | |
179 | +// // Wait to get the data from the query in step 6 ----------- | |
180 | +// Sleep(500); | |
181 | +// pSvc->CancelAsyncCall(pResponseSink); | |
182 | + | |
183 | +// // Cleanup | |
184 | +// // ======== | |
185 | +// pSvc->Release(); | |
186 | +// pLoc->Release(); | |
187 | +// CoUninitialize(); | |
188 | + | |
189 | + return 0; // Program successfully completed. | |
190 | +} | ... | ... |
src/cacic_hardware.h
1 | 1 | #ifndef CACIC_HARDWARE_H |
2 | 2 | #define CACIC_HARDWARE_H |
3 | +#include <ccacic.h> | |
4 | +#include <wbemidl.h> | |
5 | +#include <querysink.h> | |
6 | +#include <iostream> | |
7 | +using namespace std; | |
8 | +#include <comutil.h> | |
9 | +# pragma comment(lib, "wbemuuid.lib") | |
3 | 10 | |
4 | 11 | class cacic_hardware |
5 | 12 | { |
6 | 13 | public: |
7 | 14 | cacic_hardware(); |
15 | + void iniciaColeta(); | |
16 | + QJsonObject toJsonObject(); | |
17 | + | |
18 | +private: | |
19 | + QJsonObject coletaHardware; | |
20 | + int wmi(); | |
21 | + | |
22 | + QJsonObject coletaWin(); | |
23 | + QJsonObject coletaLinux(); | |
8 | 24 | }; |
9 | 25 | |
10 | 26 | #endif // CACIC_HARDWARE_H | ... | ... |
src/cacic_software.cpp
... | ... | @@ -16,20 +16,35 @@ void cacic_software::iniciaColeta() |
16 | 16 | QJsonObject cacic_software::coletaWin() |
17 | 17 | { |
18 | 18 | QJsonObject softwaresJson; |
19 | - QSettings softwares("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat); | |
20 | -// qDebug() << softwares.childGroups(); | |
21 | - foreach (QString group, softwares.childGroups()){ | |
22 | - QVariantMap software; | |
23 | - softwares.beginGroup(group); | |
24 | - software["DisplayName"] = softwares.value("DisplayName"); | |
25 | - software["Publisher"] = softwares.value("Publisher"); | |
26 | - software["InstallLocation"] = softwares.value("InstallLocation"); | |
27 | - software["InstallDate"] = softwares.value("InstallDate"); | |
28 | - software["URLInfoAbout"] = softwares.value("URLInfoAbout"); | |
29 | - softwares.endGroup(); | |
30 | - softwaresJson[group] = QJsonObject::fromVariantMap(software); | |
31 | - } | |
19 | + QStringList regedit; | |
20 | + regedit.append("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); | |
21 | + regedit.append("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); | |
22 | + foreach(QString registry, regedit){ | |
23 | + QSettings softwares(registry, QSettings::NativeFormat); | |
24 | + // qDebug() << softwares.childGroups(); | |
25 | + foreach (QString group, softwares.childGroups()){ | |
26 | + QVariantMap software; | |
27 | + softwares.beginGroup(group); | |
28 | + qDebug() << softwares.fileName() << softwares.value("DisplayName"); | |
29 | + if (!softwares.value("DisplayName").isNull()) | |
30 | + software["DisplayName"] = softwares.value("DisplayName"); | |
31 | + if (!softwares.value("Publisher").isNull()) | |
32 | + software["Publisher"] = softwares.value("Publisher"); | |
33 | + if (!softwares.value("InstallLocation").isNull()) | |
34 | + software["InstallLocation"] = softwares.value("InstallLocation"); | |
35 | + if (!softwares.value("InstallDate").isNull()) | |
36 | + software["InstallDate"] = softwares.value("InstallDate"); | |
37 | + if (!softwares.value("URLInfoAbout").isNull()) | |
38 | + software["URLInfoAbout"] = softwares.value("URLInfoAbout"); | |
39 | + if (!softwares.value("UninstallString").isNull()) | |
40 | + software["UninstallString"] = software.value("UninstallString"); | |
41 | + if (!softwares.value("QuietUninstallString").isNull()) | |
42 | + software["QuietUninstallString"] = software.value("QuietUninstallString"); | |
43 | + softwares.endGroup(); | |
44 | + softwaresJson[group] = QJsonObject::fromVariantMap(software); | |
45 | + } | |
32 | 46 | // qDebug() << softwaresJson; |
47 | + } | |
33 | 48 | return softwaresJson; |
34 | 49 | } |
35 | 50 | ... | ... |