Commit a65e13cfb5a1a588df74f7378d97891e3930e9a7

Authored by Eric Menezes Noronha
1 parent b1048928
Exists in master

alteração da coleta, inclusão da coleta de software para windows

cacic-teste/cacic-teste.pro
@@ -22,11 +22,12 @@ SOURCES += \ @@ -22,11 +22,12 @@ SOURCES += \
22 ../src/ccacic.cpp \ 22 ../src/ccacic.cpp \
23 ../src/cacic_computer.cpp \ 23 ../src/cacic_computer.cpp \
24 ../src/operatingsystem.cpp \ 24 ../src/operatingsystem.cpp \
25 - ../src/qtservice/src/qtservice.cpp \  
26 - ../src/qtservice/src/qtservice_unix.cpp \  
27 - ../src/qtservice/src/qtservice_win.cpp \  
28 - ../src/qtservice/src/qtunixserversocket.cpp \  
29 - ../src/qtservice/src/qtunixsocket.cpp 25 + ../src/cacic_software.cpp \
  26 +# ../src/qtservice/src/qtservice.cpp \
  27 +# ../src/qtservice/src/qtservice_unix.cpp \
  28 +# ../src/qtservice/src/qtservice_win.cpp \
  29 +# ../src/qtservice/src/qtunixserversocket.cpp \
  30 +# ../src/qtservice/src/qtunixsocket.cpp
30 31
31 32
32 HEADERS += \ 33 HEADERS += \
@@ -36,10 +37,11 @@ HEADERS += \ @@ -36,10 +37,11 @@ HEADERS += \
36 ../src/cacic_comm.h \ 37 ../src/cacic_comm.h \
37 ../src/console.h \ 38 ../src/console.h \
38 ../src/operatingsystem.h \ 39 ../src/operatingsystem.h \
39 - ../src/qtservice/src/qtservice.h \  
40 - ../src/qtservice/src/qtservice_p.h \  
41 - ../src/qtservice/src/qtunixserversocket.h \  
42 - ../src/qtservice/src/qtunixsocket.h 40 + ../src/cacic_software.h \
  41 +# ../src/qtservice/src/qtservice.h \
  42 +# ../src/qtservice/src/qtservice_p.h \
  43 +# ../src/qtservice/src/qtunixserversocket.h \
  44 +# ../src/qtservice/src/qtunixsocket.h
43 45
44 INCLUDEPATH += ../src \ 46 INCLUDEPATH += ../src \
45 ../src/crypto++/include/ 47 ../src/crypto++/include/
cacic-teste/testcacic.cpp
@@ -237,6 +237,12 @@ void CTestCacic::testIniciarDaemon(){ @@ -237,6 +237,12 @@ void CTestCacic::testIniciarDaemon(){
237 237
238 } 238 }
239 239
  240 +void CTestCacic::testColetaSoftware()
  241 +{
  242 + OCacicSoftware.iniciaColeta();
  243 + QVERIFY(!OCacicSoftware.toJsonObject().empty());
  244 +}
  245 +
240 void CTestCacic::cleanupTestCase() 246 void CTestCacic::cleanupTestCase()
241 { 247 {
242 OCacic.deleteFile("configRequest.json"); 248 OCacic.deleteFile("configRequest.json");
cacic-teste/testcacic.h
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 #include <cacic_comm.h> 4 #include <cacic_comm.h>
5 #include <ccacic.h> 5 #include <ccacic.h>
6 #include <cacic_computer.h> 6 #include <cacic_computer.h>
  7 +#include <cacic_software.h>
7 #include <console.h> 8 #include <console.h>
8 #include <operatingsystem.h> 9 #include <operatingsystem.h>
9 #include <QtTest/QtTest> 10 #include <QtTest/QtTest>
@@ -28,11 +29,12 @@ private: @@ -28,11 +29,12 @@ private:
28 CacicComm OCacicComm; 29 CacicComm OCacicComm;
29 CCacic OCacic; 30 CCacic OCacic;
30 CACIC_Computer OCacicComp; 31 CACIC_Computer OCacicComp;
  32 + cacic_software OCacicSoftware;
31 QString testPath; 33 QString testPath;
32 QString testIniPath; 34 QString testIniPath;
33 QJsonObject session; 35 QJsonObject session;
34 QString cripTeste; 36 QString cripTeste;
35 - cacicD OcacicD; 37 +// cacicD OcacicD;
36 38
37 signals: 39 signals:
38 40
@@ -67,6 +69,7 @@ private slots: @@ -67,6 +69,7 @@ private slots:
67 void testGetValueFromRegistry(); 69 void testGetValueFromRegistry();
68 void testRemoveRegistry(); 70 void testRemoveRegistry();
69 void testIniciarDaemon(); 71 void testIniciarDaemon();
  72 + void testColetaSoftware();
70 void cleanupTestCase(); 73 void cleanupTestCase();
71 }; 74 };
72 75
cacicD/cacicD.pro
@@ -36,3 +36,6 @@ HEADERS += \ @@ -36,3 +36,6 @@ HEADERS += \
36 cacicd.h 36 cacicd.h
37 37
38 include(../src/qtservice/src/qtservice.pri) 38 include(../src/qtservice/src/qtservice.pri)
  39 +
  40 +INCLUDEPATH += ../src \
  41 + ../src/crypto++/include/
cacicD/main.cpp
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 #include <QStringList> 2 #include <QStringList>
3 #include <QDir> 3 #include <QDir>
4 #include <QSettings> 4 #include <QSettings>
5 -#include "../src/qtservice/src/qtservice.h" 5 +#include <qtservice/src/qtservice.h>
6 6
7 int main(int argc, char **argv) 7 int main(int argc, char **argv)
8 { 8 {
gercols/gercols.cpp
@@ -22,11 +22,9 @@ Gercols::Gercols(QObject *parent) @@ -22,11 +22,9 @@ Gercols::Gercols(QObject *parent)
22 oCacic.setJsonToFile(configTeste,"configReq.json"); 22 oCacic.setJsonToFile(configTeste,"configReq.json");
23 /******************************************/ 23 /******************************************/
24 24
25 - getConfigJson();  
26 qDebug() << "TESTE"; 25 qDebug() << "TESTE";
27 oColeta = new CColeta(); 26 oColeta = new CColeta();
28 - oColeta->setColeta(configReq);  
29 -qDebug() << oColeta->getColeta(); 27 +
30 QObject::connect(this, SIGNAL(iniciaConfiguracao()), oColeta, SLOT(configuraColetas())); 28 QObject::connect(this, SIGNAL(iniciaConfiguracao()), oColeta, SLOT(configuraColetas()));
31 QObject::connect(this, SIGNAL(iniciaColeta()), oColeta, SLOT(run())); 29 QObject::connect(this, SIGNAL(iniciaColeta()), oColeta, SLOT(run()));
32 30
@@ -49,15 +47,9 @@ void Gercols::run() @@ -49,15 +47,9 @@ void Gercols::run()
49 47
50 48
51 //salva coleta em json 49 //salva coleta em json
52 - qDebug() << oColeta->getColeta(); 50 + qDebug() << oColeta->toJsonObject();
53 //salva json em arquivo 51 //salva json em arquivo
54 - oCacic.setJsonToFile(oColeta->getColeta(), "coleta.json"); 52 + oCacic.setJsonToFile(oColeta->toJsonObject(), "coleta.json");
55 //emite sinal "finished" pra finalizar a aplicação 53 //emite sinal "finished" pra finalizar a aplicação
56 emit finished(); 54 emit finished();
57 } 55 }
58 -  
59 -bool Gercols::getConfigJson()  
60 -{  
61 - configReq = oCacic.getJsonFromFile("configReq.json");  
62 - oCacic.deleteFile("configReq.json");  
63 -}  
gercols/gercols.h
@@ -13,8 +13,6 @@ private: @@ -13,8 +13,6 @@ private:
13 CColeta *oColeta; 13 CColeta *oColeta;
14 QJsonObject configReq; 14 QJsonObject configReq;
15 15
16 - bool getConfigJson();  
17 -  
18 public: 16 public:
19 explicit Gercols(QObject *parent = 0); 17 explicit Gercols(QObject *parent = 0);
20 18
gercols/gercols.pro
@@ -25,6 +25,7 @@ SOURCES += \ @@ -25,6 +25,7 @@ SOURCES += \
25 main.cpp \ 25 main.cpp \
26 ../src/ccacic.cpp \ 26 ../src/ccacic.cpp \
27 ../src/cacic_computer.cpp \ 27 ../src/cacic_computer.cpp \
  28 + ../src/cacic_software.cpp \
28 ../src/operatingsystem.cpp \ 29 ../src/operatingsystem.cpp \
29 ../src/ccoleta.cpp \ 30 ../src/ccoleta.cpp \
30 ./gercols.cpp 31 ./gercols.cpp
@@ -33,6 +34,7 @@ SOURCES += \ @@ -33,6 +34,7 @@ SOURCES += \
33 HEADERS += \ 34 HEADERS += \
34 ../src/ccacic.h \ 35 ../src/ccacic.h \
35 ../src/cacic_computer.h \ 36 ../src/cacic_computer.h \
  37 + ../src/cacic_software.h \
36 ../src/operatingsystem.h \ 38 ../src/operatingsystem.h \
37 ../src/console.h \ 39 ../src/console.h \
38 ../src/ccoleta.h \ 40 ../src/ccoleta.h \
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-18T11:08:49. --> 3 +<!-- Written by QtCreator 3.1.2, 2014-08-18T18:02:05. -->
4 <qtcreator> 4 <qtcreator>
5 <data> 5 <data>
6 <variable>ProjectExplorer.Project.ActiveTarget</variable> 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
src/cacic_software.cpp
@@ -3,3 +3,41 @@ @@ -3,3 +3,41 @@
3 cacic_software::cacic_software() 3 cacic_software::cacic_software()
4 { 4 {
5 } 5 }
  6 +
  7 +void cacic_software::iniciaColeta()
  8 +{
  9 +#ifdef Q_OS_WIN
  10 + this->coletaSoftware = coletaWin();
  11 +#else
  12 + this->coletaSoftware = coletaLinux();
  13 +#endif
  14 +}
  15 +
  16 +QJsonObject cacic_software::coletaWin()
  17 +{
  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 + }
  32 +// qDebug() << softwaresJson;
  33 + return softwaresJson;
  34 +}
  35 +
  36 +void cacic_software::coletaLinux()
  37 +{
  38 +
  39 +}
  40 +QJsonObject cacic_software::toJsonObject()
  41 +{
  42 + return coletaSoftware;
  43 +}
src/cacic_software.h
1 #ifndef CACIC_SOFTWARE_H 1 #ifndef CACIC_SOFTWARE_H
2 #define CACIC_SOFTWARE_H 2 #define CACIC_SOFTWARE_H
3 - 3 +#include <QtCore>
  4 +#include <ccacic.h>
4 class cacic_software 5 class cacic_software
5 { 6 {
6 public: 7 public:
7 cacic_software(); 8 cacic_software();
  9 + void iniciaColeta();
  10 + QJsonObject toJsonObject();
  11 +
  12 +private:
  13 + QJsonObject coletaWin();
  14 + void coletaLinux();
  15 +
  16 + CCacic oCacic;
  17 + QJsonObject coletaSoftware;
8 }; 18 };
9 19
10 #endif // CACIC_SOFTWARE_H 20 #endif // CACIC_SOFTWARE_H
src/ccacic.cpp
1 #include "ccacic.h" 1 #include "ccacic.h"
2 2
3 -CCacic::CCacic(QObject *parent) :  
4 - QObject(parent) 3 +CCacic::CCacic()
5 { 4 {
6 } 5 }
7 /* getValueFromFile 6 /* getValueFromFile
@@ -19,11 +19,10 @@ @@ -19,11 +19,10 @@
19 //#include <sha.h> 19 //#include <sha.h>
20 //#include <md5.h> 20 //#include <md5.h>
21 21
22 -class CCacic : public QObject 22 +class CCacic
23 { 23 {
24 - Q_OBJECT  
25 public: 24 public:
26 - explicit CCacic(QObject *parent = 0); 25 + CCacic();
27 QString getValueFromFile(QString sectionName, QString keyName, QString filePath); 26 QString getValueFromFile(QString sectionName, QString keyName, QString filePath);
28 void setValueToFile(QString sectionName, QString keyName, QString value, QString filePath); 27 void setValueToFile(QString sectionName, QString keyName, QString value, QString filePath);
29 QString getValueFromTags(QString fullString, QString tag, QString tagType = "[]"); 28 QString getValueFromTags(QString fullString, QString tag, QString tagType = "[]");
@@ -69,10 +68,6 @@ private: @@ -69,10 +68,6 @@ private:
69 QString chksisInfFilePath; 68 QString chksisInfFilePath;
70 QString chaveCrypt; 69 QString chaveCrypt;
71 70
72 -signals:  
73 -  
74 -public slots:  
75 -  
76 }; 71 };
77 72
78 #endif // CCACIC_H 73 #endif // CCACIC_H
src/ccoleta.cpp
@@ -5,89 +5,49 @@ CColeta::CColeta(QObject *parent) @@ -5,89 +5,49 @@ CColeta::CColeta(QObject *parent)
5 5
6 } 6 }
7 7
8 -void CColeta::coletaComputer()  
9 -{  
10 - qDebug() << "coletaComputer() executado";  
11 - QJsonObject coletaComputer = coleta["computer"].toObject();  
12 - if( coletaComputer.contains("operating_system") )  
13 - emit beginOperatingSystem();  
14 - if( coletaComputer.contains("user") )  
15 - emit beginUser();  
16 -  
17 -}  
18 -  
19 void CColeta::coletaHardware() 8 void CColeta::coletaHardware()
20 { 9 {
21 qDebug() << "coletaHardware() executado"; 10 qDebug() << "coletaHardware() executado";
22 - QJsonObject coletaHardware = coleta["hardware"].toObject();  
23 -}  
24 -  
25 -void CColeta::coletaNetworkInterfaces()  
26 -{  
27 - qDebug() << "coletaOperatingSystem() executado";  
28 -  
29 -// QJsonObject coletaComputer = coleta["computer"].toObject();  
30 -// coletaComputer["network_interfaces"] = QJsonValue::fromVariant(QString(oComputer.getNetworkInterface()));  
31 -  
32 -// coleta["computer"] = coletaComputer; 11 +// oHardware.iniciaColeta();
33 } 12 }
34 13
35 -void CColeta::coletaOperatingSystem()  
36 -{  
37 - qDebug() << "coletaOperatingSystem() executado";  
38 -  
39 - QJsonObject coletaComputer = coleta["computer"].toObject();  
40 - coletaComputer["operating_system"] = QJsonValue::fromVariant(QString(oComputer.getOs().getNomeOs()));  
41 -  
42 - coleta["computer"] = coletaComputer;  
43 -}  
44 14
45 void CColeta::coletaSoftware() 15 void CColeta::coletaSoftware()
46 { 16 {
47 qDebug() << "coletaSoftware() executado"; 17 qDebug() << "coletaSoftware() executado";
48 - QJsonObject coletaSoftware = coleta["software"].toObject();  
49 -}  
50 -  
51 -void CColeta::coletaUser()  
52 -{  
53 - qDebug() << "coletauser() executado";  
54 -  
55 - QJsonObject coletaComputer = coleta["computer"].toObject();  
56 - coletaComputer["user"] = QJsonValue::fromVariant(QString::fromStdString(oComputer.getUser()));  
57 -  
58 - coleta["computer"] = coletaComputer; 18 + oSoftware.iniciaColeta();
59 } 19 }
60 20
61 void CColeta::configuraColetas(){ 21 void CColeta::configuraColetas(){
62 - QObject::connect(this, SIGNAL(beginComputer()), this, SLOT(coletaComputer()));  
63 - QObject::connect(this, SIGNAL(beginNetworkInterfaces()), this, SLOT(coletaNetworkInterfaces()));  
64 - QObject::connect(this, SIGNAL(beginOperatingSystem()), this, SLOT(coletaOperatingSystem()));  
65 - QObject::connect(this, SIGNAL(beginUser()), this, SLOT(coletaUser()));  
66 QObject::connect(this, SIGNAL(beginHardware()), this, SLOT(coletaHardware())); 22 QObject::connect(this, SIGNAL(beginHardware()), this, SLOT(coletaHardware()));
67 QObject::connect(this, SIGNAL(beginSoftware()), this, SLOT(coletaSoftware())); 23 QObject::connect(this, SIGNAL(beginSoftware()), this, SLOT(coletaSoftware()));
68 } 24 }
69 25
70 -QJsonObject CColeta::getColeta() const 26 +CACIC_Computer CColeta::getOComputer() const
71 { 27 {
72 - return coleta; 28 + return oComputer;
73 } 29 }
74 30
75 -CACIC_Computer CColeta::getOComputer() const 31 +cacic_software CColeta::getOSoftware() const
76 { 32 {
77 - return oComputer; 33 + return oSoftware;
78 } 34 }
79 35
80 void CColeta::run() 36 void CColeta::run()
81 { 37 {
82 - if( coleta.contains("computer") )  
83 - emit beginComputer(); 38 + QJsonObject coleta = oCacic.getJsonFromFile("configReq.json");
  39 +
84 if( coleta.contains("hardware") ) 40 if( coleta.contains("hardware") )
85 emit beginHardware(); 41 emit beginHardware();
86 if ( coleta.contains("software") ) 42 if ( coleta.contains("software") )
87 emit beginSoftware(); 43 emit beginSoftware();
  44 +
88 } 45 }
89 46
90 -void CColeta::setColeta(QJsonObject config) 47 +QJsonObject CColeta::toJsonObject()
91 { 48 {
92 - this->coleta = config; 49 + QJsonObject coletaJson;
  50 + coletaJson["computer"] = oComputer.toJsonObject();
  51 + coletaJson["software"] = oSoftware.toJsonObject();
  52 + return coletaJson;
93 } 53 }
@@ -4,8 +4,9 @@ @@ -4,8 +4,9 @@
4 #include <QObject> 4 #include <QObject>
5 #include <QJsonObject> 5 #include <QJsonObject>
6 #include <QDebug> 6 #include <QDebug>
  7 +#include <ccacic.h>
7 #include <cacic_computer.h> 8 #include <cacic_computer.h>
8 -#include "cacic_computer.h" 9 +#include <cacic_software.h>
9 10
10 11
11 class CColeta : public QObject 12 class CColeta : public QObject
@@ -13,24 +14,21 @@ class CColeta : public QObject @@ -13,24 +14,21 @@ class CColeta : public QObject
13 Q_OBJECT 14 Q_OBJECT
14 15
15 private: 16 private:
16 - QJsonObject coleta;  
17 - 17 + CCacic oCacic;
18 CACIC_Computer oComputer; 18 CACIC_Computer oComputer;
  19 + cacic_software oSoftware;
19 20
20 public: 21 public:
21 explicit CColeta(QObject *parent = 0); 22 explicit CColeta(QObject *parent = 0);
22 23
23 - QJsonObject getColeta() const;  
24 CACIC_Computer getOComputer() const; 24 CACIC_Computer getOComputer() const;
25 - void setColeta(QJsonObject config); 25 + cacic_software getOSoftware() const;
  26 +
  27 + QJsonObject toJsonObject();
26 28
27 public slots: 29 public slots:
28 - void coletaComputer();  
29 void coletaHardware(); 30 void coletaHardware();
30 - void coletaNetworkInterfaces();  
31 - void coletaOperatingSystem();  
32 void coletaSoftware(); 31 void coletaSoftware();
33 - void coletaUser();  
34 void configuraColetas(); 32 void configuraColetas();
35 void run(); 33 void run();
36 34