Commit 6391f957424e2946aba4a8b044fdfedc03cc0ed0
1 parent
2586f1df
Exists in
master
cacic-teste: adicionado 4 novos testes;
install-cacic: pegando chave do login e gravando em arquivo; caciccomm: carregando sessao em atributo privado da classe ao logar; ccacic: novos métodos de auxilio ao json (setJsonToFile e getJsonFromFile); caciccomp: pegando nome do so tambem, modificado o nome das variaveis; criado metodo toJsonObject nas classes cacicomp e operatingsystem;
Showing
12 changed files
with
117 additions
and
25 deletions
Show diff stats
cacic-teste/cacic-teste.pro
... | ... | @@ -20,7 +20,8 @@ win32 { |
20 | 20 | SOURCES += \ |
21 | 21 | testcacic.cpp \ |
22 | 22 | ../src/ccacic.cpp \ |
23 | - ../src/cacic_computer.cpp | |
23 | + ../src/cacic_computer.cpp \ | |
24 | + ../src/operatingsystem.cpp | |
24 | 25 | |
25 | 26 | |
26 | 27 | HEADERS += \ |
... | ... | @@ -28,7 +29,8 @@ HEADERS += \ |
28 | 29 | ../src/ccacic.h \ |
29 | 30 | ../src/cacic_computer.h \ |
30 | 31 | ../src/cacic_comm.h \ |
31 | - ../src/console.h | |
32 | + ../src/console.h \ | |
33 | + ../src/operatingsystem.h | |
32 | 34 | |
33 | 35 | INCLUDEPATH += ../src \ |
34 | 36 | ../src/crypto++/include/ | ... | ... |
cacic-teste/testcacic.cpp
... | ... | @@ -88,14 +88,15 @@ void CTestCacic::testInterfaceDeRede(){ |
88 | 88 | |
89 | 89 | void CTestCacic::testpegarOS(){ |
90 | 90 | //basta que seja um retorno válido, não precisa validar todos. |
91 | - QVERIFY(OCacicComp.getOs().getIdSo() != -1 ); | |
91 | + QVERIFY(OCacicComp.getOs().getIdOs() != -1 ); | |
92 | 92 | } |
93 | 93 | |
94 | 94 | void CTestCacic::testConsole() |
95 | 95 | { |
96 | 96 | ConsoleObject console; |
97 | 97 | |
98 | - QVERIFY(console("echo teste").toStdString() == "teste\n"); | |
98 | +// QVERIFY(console("echo teste").toStdString() == "teste\n"); | |
99 | + QVERIFY(false); | |
99 | 100 | } |
100 | 101 | |
101 | 102 | void CTestCacic::testPegarUsu(){ |
... | ... | @@ -165,7 +166,24 @@ void CTestCacic::testCacicCompToJsonObject() |
165 | 166 | QVERIFY(!OCacicComp.toJsonObject().empty()); |
166 | 167 | } |
167 | 168 | |
168 | -void CTestCacic::cleanupTestCase() | |
169 | +void CTestCacic::testOperatingSystemToJsonObject() | |
170 | +{ | |
171 | + QVERIFY(!OCacicComp.getOs().toJsonObject().empty()); | |
172 | +} | |
173 | + | |
174 | +void CTestCacic::testJsonToFile() | |
169 | 175 | { |
176 | + QJsonObject json; | |
177 | + json["teste"] = QJsonValue::fromVariant(QString("teste")); | |
178 | + QVERIFY(OCacic.setJsonToFile(json, "teste.json")); | |
179 | +} | |
170 | 180 | |
181 | +void CTestCacic::testJsonFromFile() | |
182 | +{ | |
183 | + QVERIFY(OCacic.getJsonFromFile("teste.json")["teste"].toString() == "teste"); | |
184 | +} | |
185 | + | |
186 | +void CTestCacic::cleanupTestCase() | |
187 | +{ | |
188 | + OCacic.deleteFile("teste.json"); | |
171 | 189 | } | ... | ... |
cacic-teste/testcacic.h
install-cacic/install-cacic.pro
... | ... | @@ -24,13 +24,15 @@ TEMPLATE = app |
24 | 24 | SOURCES += main.cpp \ |
25 | 25 | installcacic.cpp \ |
26 | 26 | ../src/ccacic.cpp \ |
27 | - ../src/cacic_computer.cpp | |
27 | + ../src/cacic_computer.cpp \ | |
28 | + ../src/operatingsystem.cpp | |
28 | 29 | |
29 | 30 | HEADERS += \ |
30 | 31 | installcacic.h \ |
31 | 32 | ../src/ccacic.h \ |
32 | 33 | ../src/cacic_computer.h \ |
33 | - ../src/cacic_comm.h | |
34 | + ../src/cacic_comm.h \ | |
35 | + ../src/operatingsystem.h | |
34 | 36 | |
35 | 37 | INCLUDEPATH += ../src \ |
36 | 38 | ../src/crypto++/include/ | ... | ... |
install-cacic/installcacic.cpp
... | ... | @@ -19,7 +19,10 @@ void InstallCacic::run(QStringList argv, int argc) { |
19 | 19 | QJsonObject jsonLogin = oCacicComm.login(&ok); |
20 | 20 | if (ok){ |
21 | 21 | //TODO: Conectado. armazenar chave em arquivo e sessao na comm; |
22 | - qDebug() << "Logado"; | |
22 | + oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); | |
23 | + QJsonObject configToSave; | |
24 | + configToSave["chaveCrypt"] = QJsonValue::fromVariant(oCacic.getChaveCrypt()); | |
25 | + oCacic.setJsonToFile(configToSave, "cacicTeste.json"); | |
23 | 26 | } |
24 | 27 | else |
25 | 28 | qDebug() << "falha no login"; | ... | ... |
src/cacic_comm.h
... | ... | @@ -22,7 +22,7 @@ private: |
22 | 22 | // FIXME: Get from configuration |
23 | 23 | QString usuario; |
24 | 24 | QString password; |
25 | - std::string session; | |
25 | + QString session; | |
26 | 26 | |
27 | 27 | public: |
28 | 28 | CacicComm (){ |
... | ... | @@ -166,6 +166,7 @@ public: |
166 | 166 | // Cria conexão e retorna Json da sessão |
167 | 167 | // qDebug() << "Conectando."; |
168 | 168 | QJsonObject retorno = this->comm("/ws/neo/login", ok, QJsonObject::fromVariantMap(login), true); |
169 | + this->session = retorno["reply"].toObject()["session"].toString(); | |
169 | 170 | return retorno; |
170 | 171 | } |
171 | 172 | ... | ... |
src/cacic_computer.cpp
... | ... | @@ -2,7 +2,6 @@ |
2 | 2 | |
3 | 3 | CACIC_Computer::CACIC_Computer() |
4 | 4 | { |
5 | - operatingSystem = OperatingSystem(); | |
6 | 5 | networkInterface = networkInterfacesRunning(); |
7 | 6 | usuario = pegarUsu(); |
8 | 7 | } |
... | ... | @@ -56,6 +55,7 @@ QJsonObject CACIC_Computer::toJsonObject() |
56 | 55 | QJsonObject network; |
57 | 56 | int count = 1; |
58 | 57 | json["usuario"] = QJsonValue::fromVariant(QString::fromStdString(this->usuario)); |
58 | + json["operatingSystem"] = this->oOperatingSystem.toJsonObject(); | |
59 | 59 | foreach(QVariantMap auxMap, this->getNetworkInterface()){ |
60 | 60 | network["network" + QVariant::fromValue(count).toString()] = QJsonObject::fromVariantMap(auxMap); |
61 | 61 | count++; |
... | ... | @@ -89,7 +89,7 @@ std::string CACIC_Computer::pegarUsu(){ |
89 | 89 | */ |
90 | 90 | OperatingSystem CACIC_Computer::getOs() const |
91 | 91 | { |
92 | - return operatingSystem; | |
92 | + return oOperatingSystem; | |
93 | 93 | } |
94 | 94 | |
95 | 95 | std::string CACIC_Computer::getUser() const { | ... | ... |
src/cacic_computer.h
... | ... | @@ -7,7 +7,6 @@ |
7 | 7 | #include <QtSerialPort/QSerialPortInfo> |
8 | 8 | #include <QtNetwork/QtNetwork> |
9 | 9 | #include <QSysInfo> |
10 | - | |
11 | 10 | #include <operatingsystem.h> |
12 | 11 | |
13 | 12 | class CACIC_Computer |
... | ... | @@ -23,7 +22,7 @@ public: |
23 | 22 | |
24 | 23 | private: |
25 | 24 | |
26 | - OperatingSystem operatingSystem; | |
25 | + OperatingSystem oOperatingSystem; | |
27 | 26 | int pegarOS(); |
28 | 27 | std::string pegarUsu(); |
29 | 28 | ... | ... |
src/ccacic.cpp
... | ... | @@ -113,6 +113,26 @@ QJsonValue CCacic::jsonValueFromJsonString(QString json, QString key) |
113 | 113 | return QJsonDocument::fromJson(json.toUtf8()).object()[key]; |
114 | 114 | } |
115 | 115 | |
116 | +bool CCacic::setJsonToFile(QJsonObject json, QString filepath) | |
117 | +{ | |
118 | + QFile configFile(filepath); | |
119 | + if (!configFile.open(QIODevice::WriteOnly)){ | |
120 | + qDebug() << "Não foi possivel abrir o arquivo."; | |
121 | + } | |
122 | + QJsonDocument docJson(json); | |
123 | + return (configFile.write(docJson.toJson()) != -1); | |
124 | +} | |
125 | + | |
126 | +QJsonObject CCacic::getJsonFromFile(QString filepath) | |
127 | +{ | |
128 | + QFile configFile(filepath); | |
129 | + QJsonObject json; | |
130 | + if (!configFile.open(QIODevice::ReadOnly)) | |
131 | + qDebug() << "Nao foi possivel ler o arquivo"; | |
132 | + json = QJsonDocument::fromJson(configFile.readAll()).object(); | |
133 | + return json; | |
134 | +} | |
135 | + | |
116 | 136 | /*enCrypt |
117 | 137 | * @parameter std::string str_in: string que será encriptada (url). |
118 | 138 | * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits |
... | ... | @@ -208,6 +228,16 @@ void CCacic::setChksisInfFilePath(const QString &value) |
208 | 228 | { |
209 | 229 | chksisInfFilePath = value; |
210 | 230 | } |
231 | +QString CCacic::getChaveCrypt() const | |
232 | +{ | |
233 | + return chaveCrypt; | |
234 | +} | |
235 | + | |
236 | +void CCacic::setChaveCrypt(const QString &value) | |
237 | +{ | |
238 | + chaveCrypt = value; | |
239 | +} | |
240 | + | |
211 | 241 | |
212 | 242 | /*Getters/Setters |
213 | 243 | * End. | ... | ... |
src/ccacic.h
... | ... | @@ -32,6 +32,8 @@ public: |
32 | 32 | bool deleteFolder(QString path); |
33 | 33 | bool deleteFile(QString path); |
34 | 34 | QJsonValue jsonValueFromJsonString(QString json, QString key); |
35 | + bool setJsonToFile(QJsonObject json, QString filepath); | |
36 | + QJsonObject getJsonFromFile(QString filepath); | |
35 | 37 | |
36 | 38 | //Geters/seters: |
37 | 39 | |
... | ... | @@ -50,12 +52,16 @@ public: |
50 | 52 | QString getChksisInfFilePath() const; |
51 | 53 | void setChksisInfFilePath(const QString &value); |
52 | 54 | |
55 | + QString getChaveCrypt() const; | |
56 | + void setChaveCrypt(const QString &value); | |
57 | + | |
53 | 58 | private: |
54 | 59 | QString cacicMainFolder; |
55 | 60 | QString mainModuleName; |
56 | 61 | QString urlGerente; |
57 | 62 | QString gerColsInfFilePath; |
58 | 63 | QString chksisInfFilePath; |
64 | + QString chaveCrypt; | |
59 | 65 | |
60 | 66 | signals: |
61 | 67 | ... | ... |
src/operatingsystem.cpp
1 | 1 | #include "operatingsystem.h" |
2 | 2 | |
3 | +OperatingSystem::OperatingSystem() | |
4 | +{ | |
5 | + this->idOs = this->coletaIdOs(); | |
6 | + this->nomeOs = this->coletaNomeOs(); | |
7 | +} | |
8 | + | |
3 | 9 | /*pegarOS |
4 | 10 | * @return: int; |
5 | 11 | * retorna um id referente a versão do SO. |
... | ... | @@ -10,7 +16,7 @@ |
10 | 16 | * 176 = Windows 8.1 |
11 | 17 | * 200 = Linux |
12 | 18 | */ |
13 | -int OperatingSystem::pegarOS(){ | |
19 | +int OperatingSystem::coletaIdOs(){ | |
14 | 20 | #if defined (Q_OS_WIN) |
15 | 21 | return QSysInfo::WindowsVersion; |
16 | 22 | #elif defined (Q_OS_LINUX) |
... | ... | @@ -20,16 +26,36 @@ int OperatingSystem::pegarOS(){ |
20 | 26 | #endif |
21 | 27 | } |
22 | 28 | |
23 | -int OperatingSystem::getIdSo() const | |
29 | +QString OperatingSystem::coletaNomeOs() | |
24 | 30 | { |
25 | - return idSo; | |
31 | + QString text; | |
32 | + QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); | |
33 | + foreach (text, environment) { | |
34 | + if (text.contains("OS=" , Qt::CaseInsensitive) || | |
35 | + text.contains("SESSION=", Qt::CaseInsensitive) ){ | |
36 | + QStringList split = text.split("="); | |
37 | + // qDebug() << split[1]; | |
38 | + return split[1]; | |
39 | + } | |
40 | + } | |
41 | + return ""; | |
26 | 42 | } |
27 | 43 | |
28 | -void OperatingSystem::setIdSo(int value) | |
44 | +QJsonObject OperatingSystem::toJsonObject() | |
29 | 45 | { |
30 | - idSo = value; | |
46 | + QJsonObject json; | |
47 | + json["idOs"] = QJsonValue::fromVariant(QVariant::fromValue(this->idOs)); | |
48 | + json["nomeOs"] = QJsonValue::fromVariant(this->nomeOs); | |
49 | +// qDebug() << json; | |
50 | + return json; | |
31 | 51 | } |
32 | 52 | |
33 | -OperatingSystem::OperatingSystem() | |
53 | +QString OperatingSystem::getNomeOs() | |
54 | +{ | |
55 | + return this->nomeOs; | |
56 | +} | |
57 | + | |
58 | +int OperatingSystem::getIdOs() const | |
34 | 59 | { |
60 | + return this->idOs; | |
35 | 61 | } | ... | ... |
src/operatingsystem.h
... | ... | @@ -3,16 +3,18 @@ |
3 | 3 | |
4 | 4 | #include <QtCore> |
5 | 5 | #include <QSysInfo> |
6 | +#include <ccacic.h> | |
6 | 7 | |
7 | 8 | class OperatingSystem |
8 | 9 | { |
9 | 10 | private: |
10 | - int idSo; | |
11 | - | |
12 | - int pegarOS(); | |
11 | + int idOs; | |
12 | + int coletaIdOs(); | |
13 | + QString nomeOs; | |
14 | + QString coletaNomeOs(); | |
13 | 15 | public: |
14 | 16 | OperatingSystem(); |
15 | - | |
17 | + QJsonObject toJsonObject(); | |
16 | 18 | enum OsList { |
17 | 19 | MAC, |
18 | 20 | LINUX_DEBIAN, |
... | ... | @@ -21,8 +23,8 @@ public: |
21 | 23 | }; |
22 | 24 | static const enum OsList OsList; |
23 | 25 | |
24 | - int getIdSo() const; | |
25 | - void setIdSo(int value); | |
26 | + QString getNomeOs(); | |
27 | + int getIdOs() const; | |
26 | 28 | }; |
27 | 29 | |
28 | 30 | #endif // OPERATINGSYSTEM_H | ... | ... |