Commit f3d2ba1e9ade8e98bb53770d52e5bce672cf9694
1 parent
e9c282ff
Exists in
master
Adicionado metodo e teste de captura de OS e User
Showing
4 changed files
with
165 additions
and
113 deletions
Show diff stats
cacic-teste/testcacic.cpp
... | ... | @@ -3,109 +3,114 @@ |
3 | 3 | QTEST_MAIN(CTestCacic) |
4 | 4 | |
5 | 5 | CTestCacic::CTestCacic(QObject *parent) : |
6 | - QObject(parent) | |
6 | + QObject(parent) | |
7 | 7 | { |
8 | 8 | } |
9 | 9 | |
10 | 10 | void CTestCacic::initTestCase() |
11 | 11 | { |
12 | - this->OCacicComm = CacicComm("http://teste.cacic.cc", | |
13 | - "rG/HcIDVTZ3pPKCf[[MAIS]]I6aigUb7OMeij3FfC7qNaznk0rBRYb6q6kSK3eNfjgptS8BfwW5yJqCvD2ai7xlw9I6P21j6cvQUqlHmAJpCbfwR13urdRE9AhjfokMcPrH6R1/zXPGMHveLRRgKLcqWu2X96rmoQQdRq9EW1SXmYUAx1dCV[[MAIS]]3Ha61XBw5pq58q35zH8Gjt998rTi3ecV8ShXXevqyK[[MAIS]]W07xpgTjbbd6Fbs/35gPfdRRgMNFjq7Gq[[MAIS]]llFgYMJ6UcEhw8f0ZLQo2oL/eRW/CNyeBW6wG0hIo6EIdpi/Ht0/95Uwn2Og[[MAIS]]2UPXsmKKuTMeGwUvPdbEfexlinUO0[[MAIS]]j9qIa2dpjtl0Y5Fyk1Bvw2ZYRTXwgJpUHsBboWmtTFpgX3wSGOWMipE80K8ktRTVYOp[[MAIS]]4qS/SzKWXpfCuZoCncfwE0lCEoreTH[[MAIS]]MLrTkHJP2oqYMAyFyQcjC0UGr3BQGa2edSNXjG7jrTdddga/SODUiF94jgh/QBwhiZby34b__CRYPTED__", | |
14 | - "P198PVwtz5F5CfZPSUrzuaQA/QG1sTnwzl/rBnj8M7y5MglANGodG5LLD4q7oY809HuDR4g5tL64lZRBKvKPmEgWd9iAZKvT4UAm9XWN3nKKLGaznCaJohmntNGqrJP1Zd9riTHGu10mPbg/Uh3TCbBHVOICvu5sDlINlCR6A3[[MAIS]]a55RhfKNidvr5uX0kozCxr5t2DyOb5oPocEGyJKyHLQ==__CRYPTED__", | |
15 | - "1", | |
16 | - "0", | |
17 | - "0", | |
18 | - "YwpgjzZ86/eCsjvOki1KkQ==__CRYPTED__", | |
19 | - "8PT6U445MPNr3S7WHFa20ge/8NJSspSYE/UL3zf[[MAIS]]wkEfNZ7p1B/2o6i89gTZ44Ok__CRYPTED__", | |
20 | - "wshPlZWvLPhbUEQFQ1aQmA==__CRYPTED__", | |
21 | - "E9aKtVz/OSmGv7v1xW4FwaFukOob3qQ/HFDIz916K3ys82qfX9vBDz[[MAIS]]M2cdoYedhNkXt[[MAIS]]UVb10nD[[MAIS]]tOfbn7mlOlTDoGzUl9CgdPCsb[[MAIS]]Qa4wzuCrMw0BcCuaKfr62E3b8vh6Ug4JJbOgBo3ohG3x5O7Ap0D94GKtAWjMuTXRBbhGxPrRS4M6AhzvaN5P8pWd9FikrCLWuMs4ebnRlftef3RmVKScBDQ5zmK6sKxYNmX[[MAIS]]kKn/Gi2[[MAIS]]HftZ7HD9JLvZBpYhp4yjqShblQ67d6PlWgrRWXxwDseIiJe3NlF70zrCPBBelkeAhVDXMXnsYtLms3ElsLzxa3c5vpWzTfgyE[[MAIS]]hvALy4ivew7zaxEwrg2KY1T7GOSWZ7vljIvbhVZJgtzbnYiulFjJTtm5W4uJMKLuUJNzB0rxMkzToIE9/kDmeO2OKiwFbIfbe2Wdq0VpllOkjKtj9WM676iBSpYAXG0MsmLMj9CZ/sNi06hGF[[MAIS]]rXxiOSk66M0Hq[[MAIS]]OeUBh4z3Ra6f9yPJn0K9hIQyT[[MAIS]]Dr/QW/QdJIOkLTW8ZyyAF4DW9ojiTlUdySvB5EB1jyZ5nNTpzyE38qIdg7uM1tdWdm9FZGYxMdHwi1tS2dBeIWkDfWEjih01xiVt2dmdRgo0zIZvmmYDJ9LhCU3XPDlwdeQ8[[MAIS]]F7fnxDfxGqZQjZJ[[MAIS]]Y/Q8bdLpgbhcd3gt3SzjMLE0M[[MAIS]]hTmHG1KP2CzCibZ7grFAN3Y3jSPjmEj5Fzs26tdhdjNzSIt1FCueea8P2c4NmxPYkJCg0D1mgNrkH3L5svsO[[MAIS]]6YYrl3df4s[[MAIS]]fcK/to9s/pnkKfBKrAPF6Z4s2WPsALUPBDS5ty7RC2vqXRvH6hPR4o7xhXzQOQ/1xytr/RoEWEVeZ2wgHVVbbtFsALul/IDc7B45wmwxBx9iZHVwpQJVlNZZUBtwKqKhnXz5pM[[MAIS]]7yUAkfhMcO09pPd5kB2MBdRJs[[MAIS]]2FIk0GRUw05IHkc1rZEX5Ow==__CRYPTED__", | |
22 | - "Yot8BeM9lOh431SB7dYQXw==__CRYPTED__", | |
23 | - "Dcr8b5IfZOJjt6qyH5dGyw==__CRYPTED__", | |
24 | - "2.5.1.1.256.32", | |
25 | - "2.8.1.7", | |
26 | - "2.8.1.6"); | |
27 | - this->testPath = QDir::currentPath() + "/teste"; | |
28 | - this->testIniPath = testPath + "/teste.ini"; | |
29 | - QVariantMap json; | |
30 | - json["session"] = "lakdhfalkfhsaklfhasfhsl"; | |
31 | - this->session = QJsonObject::fromVariantMap(json); | |
12 | + this->OCacicComm = CacicComm("http://teste.cacic.cc", | |
13 | + "rG/HcIDVTZ3pPKCf[[MAIS]]I6aigUb7OMeij3FfC7qNaznk0rBRYb6q6kSK3eNfjgptS8BfwW5yJqCvD2ai7xlw9I6P21j6cvQUqlHmAJpCbfwR13urdRE9AhjfokMcPrH6R1/zXPGMHveLRRgKLcqWu2X96rmoQQdRq9EW1SXmYUAx1dCV[[MAIS]]3Ha61XBw5pq58q35zH8Gjt998rTi3ecV8ShXXevqyK[[MAIS]]W07xpgTjbbd6Fbs/35gPfdRRgMNFjq7Gq[[MAIS]]llFgYMJ6UcEhw8f0ZLQo2oL/eRW/CNyeBW6wG0hIo6EIdpi/Ht0/95Uwn2Og[[MAIS]]2UPXsmKKuTMeGwUvPdbEfexlinUO0[[MAIS]]j9qIa2dpjtl0Y5Fyk1Bvw2ZYRTXwgJpUHsBboWmtTFpgX3wSGOWMipE80K8ktRTVYOp[[MAIS]]4qS/SzKWXpfCuZoCncfwE0lCEoreTH[[MAIS]]MLrTkHJP2oqYMAyFyQcjC0UGr3BQGa2edSNXjG7jrTdddga/SODUiF94jgh/QBwhiZby34b__CRYPTED__", | |
14 | + "P198PVwtz5F5CfZPSUrzuaQA/QG1sTnwzl/rBnj8M7y5MglANGodG5LLD4q7oY809HuDR4g5tL64lZRBKvKPmEgWd9iAZKvT4UAm9XWN3nKKLGaznCaJohmntNGqrJP1Zd9riTHGu10mPbg/Uh3TCbBHVOICvu5sDlINlCR6A3[[MAIS]]a55RhfKNidvr5uX0kozCxr5t2DyOb5oPocEGyJKyHLQ==__CRYPTED__", | |
15 | + "1", | |
16 | + "0", | |
17 | + "0", | |
18 | + "YwpgjzZ86/eCsjvOki1KkQ==__CRYPTED__", | |
19 | + "8PT6U445MPNr3S7WHFa20ge/8NJSspSYE/UL3zf[[MAIS]]wkEfNZ7p1B/2o6i89gTZ44Ok__CRYPTED__", | |
20 | + "wshPlZWvLPhbUEQFQ1aQmA==__CRYPTED__", | |
21 | + "E9aKtVz/OSmGv7v1xW4FwaFukOob3qQ/HFDIz916K3ys82qfX9vBDz[[MAIS]]M2cdoYedhNkXt[[MAIS]]UVb10nD[[MAIS]]tOfbn7mlOlTDoGzUl9CgdPCsb[[MAIS]]Qa4wzuCrMw0BcCuaKfr62E3b8vh6Ug4JJbOgBo3ohG3x5O7Ap0D94GKtAWjMuTXRBbhGxPrRS4M6AhzvaN5P8pWd9FikrCLWuMs4ebnRlftef3RmVKScBDQ5zmK6sKxYNmX[[MAIS]]kKn/Gi2[[MAIS]]HftZ7HD9JLvZBpYhp4yjqShblQ67d6PlWgrRWXxwDseIiJe3NlF70zrCPBBelkeAhVDXMXnsYtLms3ElsLzxa3c5vpWzTfgyE[[MAIS]]hvALy4ivew7zaxEwrg2KY1T7GOSWZ7vljIvbhVZJgtzbnYiulFjJTtm5W4uJMKLuUJNzB0rxMkzToIE9/kDmeO2OKiwFbIfbe2Wdq0VpllOkjKtj9WM676iBSpYAXG0MsmLMj9CZ/sNi06hGF[[MAIS]]rXxiOSk66M0Hq[[MAIS]]OeUBh4z3Ra6f9yPJn0K9hIQyT[[MAIS]]Dr/QW/QdJIOkLTW8ZyyAF4DW9ojiTlUdySvB5EB1jyZ5nNTpzyE38qIdg7uM1tdWdm9FZGYxMdHwi1tS2dBeIWkDfWEjih01xiVt2dmdRgo0zIZvmmYDJ9LhCU3XPDlwdeQ8[[MAIS]]F7fnxDfxGqZQjZJ[[MAIS]]Y/Q8bdLpgbhcd3gt3SzjMLE0M[[MAIS]]hTmHG1KP2CzCibZ7grFAN3Y3jSPjmEj5Fzs26tdhdjNzSIt1FCueea8P2c4NmxPYkJCg0D1mgNrkH3L5svsO[[MAIS]]6YYrl3df4s[[MAIS]]fcK/to9s/pnkKfBKrAPF6Z4s2WPsALUPBDS5ty7RC2vqXRvH6hPR4o7xhXzQOQ/1xytr/RoEWEVeZ2wgHVVbbtFsALul/IDc7B45wmwxBx9iZHVwpQJVlNZZUBtwKqKhnXz5pM[[MAIS]]7yUAkfhMcO09pPd5kB2MBdRJs[[MAIS]]2FIk0GRUw05IHkc1rZEX5Ow==__CRYPTED__", | |
22 | + "Yot8BeM9lOh431SB7dYQXw==__CRYPTED__", | |
23 | + "Dcr8b5IfZOJjt6qyH5dGyw==__CRYPTED__", | |
24 | + "2.5.1.1.256.32", | |
25 | + "2.8.1.7", | |
26 | + "2.8.1.6"); | |
27 | + this->testPath = QDir::currentPath() + "/teste"; | |
28 | + this->testIniPath = testPath + "/teste.ini"; | |
29 | + QVariantMap json; | |
30 | + json["session"] = "lakdhfalkfhsaklfhasfhsl"; | |
31 | + this->session = QJsonObject::fromVariantMap(json); | |
32 | 32 | } |
33 | 33 | |
34 | 34 | void CTestCacic::testCreateFolder() |
35 | 35 | { |
36 | - QVERIFY(OCacic.createFolder(testPath)); | |
36 | + QVERIFY(OCacic.createFolder(testPath)); | |
37 | 37 | } |
38 | 38 | |
39 | 39 | void CTestCacic::testGetAndSetValueFromFile() |
40 | 40 | { |
41 | - OCacic.setValueToFile("Teste", "teste", "Valor de teste", testIniPath); | |
42 | - QVERIFY( OCacic.getValueFromFile("Teste", "teste", testIniPath) == "Valor de teste"); | |
41 | + OCacic.setValueToFile("Teste", "teste", "Valor de teste", testIniPath); | |
42 | + QVERIFY( OCacic.getValueFromFile("Teste", "teste", testIniPath) == "Valor de teste"); | |
43 | 43 | } |
44 | 44 | |
45 | 45 | void CTestCacic::testGetValueFromTags() |
46 | 46 | { |
47 | - QString value = "blablab[teste]Valor de teste[/teste]feihgj"; | |
48 | - QVERIFY(OCacic.getValueFromTags(value, "teste") == "Valor de teste"); | |
47 | + QString value = "blablab[teste]Valor de teste[/teste]feihgj"; | |
48 | + QVERIFY(OCacic.getValueFromTags(value, "teste") == "Valor de teste"); | |
49 | 49 | } |
50 | 50 | |
51 | 51 | void CTestCacic::testCommStatus() |
52 | 52 | { |
53 | - QVERIFY(OCacicComm.commStatus()); | |
53 | + QVERIFY(OCacicComm.commStatus()); | |
54 | 54 | } |
55 | 55 | |
56 | 56 | void CTestCacic::testComm() |
57 | 57 | { |
58 | - if (OCacicComm.commStatus()){ | |
59 | - QJsonObject jsonreply = OCacicComm.comm("/ws/get/test"); | |
60 | - QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK")); | |
58 | + if (OCacicComm.commStatus()){ | |
59 | + QJsonObject jsonreply = OCacicComm.comm("/ws/get/test"); | |
60 | + QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK")); | |
61 | 61 | } else |
62 | - QSKIP("Teste de comunicação negativo!"); | |
62 | + QSKIP("Teste de comunicação negativo!"); | |
63 | 63 | } |
64 | 64 | |
65 | 65 | void CTestCacic::testDeleteFile() |
66 | 66 | { |
67 | - QDir file(testIniPath); | |
68 | - OCacic.deleteFile(testIniPath); | |
69 | - QVERIFY(!file.exists()); | |
67 | + QDir file(testIniPath); | |
68 | + OCacic.deleteFile(testIniPath); | |
69 | + QVERIFY(!file.exists()); | |
70 | 70 | } |
71 | 71 | |
72 | 72 | void CTestCacic::testDeleteFolder() |
73 | 73 | { |
74 | - QDir folder(testPath); | |
75 | - OCacic.deleteFolder(testPath); | |
76 | - QVERIFY(!folder.exists()); | |
74 | + QDir folder(testPath); | |
75 | + OCacic.deleteFolder(testPath); | |
76 | + QVERIFY(!folder.exists()); | |
77 | 77 | } |
78 | 78 | |
79 | 79 | void CTestCacic::testEnCrypt(){ |
80 | - std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
81 | - std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. | |
82 | - std::string input = "aqui vai a url que sera encriptada"; | |
83 | - QVERIFY(OCacic.enCrypt(input, key, IV) == "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="); | |
80 | + std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
81 | + std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. | |
82 | + std::string input = "aqui vai a url que sera encriptada"; | |
83 | + QVERIFY(OCacic.enCrypt(input, key, IV) == "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="); | |
84 | 84 | } |
85 | 85 | |
86 | 86 | void CTestCacic::testDeCrypt(){ |
87 | - std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
88 | - std::string IV = "0123456789123456asas"; //iv nunca se repete para a mesma senha. | |
89 | - std::string input = "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="; | |
90 | - QVERIFY(OCacic.deCrypt(input, key, IV) == "aqui vai a url que sera encriptada"); | |
87 | + std::string key = "qwertyuiopasdfghjklzxcvbnmqwerty"; //chave de 256 bits (32 caracteres) | |
88 | + std::string IV = "0123456789123456asas"; //iv nunca se repete para a mesma senha. | |
89 | + std::string input = "Va2WiUrdTVrn93tCrtx0njjU4HDpn7VFCsCVr/+YgaBCVQ=="; | |
90 | + QVERIFY(OCacic.deCrypt(input, key, IV) == "aqui vai a url que sera encriptada"); | |
91 | 91 | |
92 | 92 | } |
93 | 93 | |
94 | 94 | void CTestCacic::testInterfaceDeRede(){ |
95 | -// qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); | |
96 | - QVERIFY2(!OCacicComp.getNetworkInterface().empty(), "Nenhuma interface de rede encontrada."); | |
95 | + // qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); | |
96 | + QVERIFY2(!OCacicComp.getNetworkInterface().empty(), "Nenhuma interface de rede encontrada."); | |
97 | 97 | } |
98 | 98 | |
99 | 99 | void CTestCacic::testpegarOS(){ |
100 | - QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux")); | |
100 | + QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux")); | |
101 | 101 | } |
102 | 102 | |
103 | +void CTestCacic::testPegarUsu(){ | |
104 | + //lightbase = user do linux. | |
105 | + //Usuario = user da vm winxp. | |
106 | + QVERIFY(OCacicComp.getUser() == "lightbase" || OCacicComp.getUser() == "Usuario"); | |
107 | +} | |
103 | 108 | |
104 | 109 | void CTestCacic::testLogin(){ |
105 | - QJsonObject sessionjson = OCacicComm.login(); | |
106 | - QJsonValue session_str = sessionjson["codestatus"]; | |
107 | -// qDebug() << session_str.toVariant().toString(); | |
108 | - QVERIFY(!session_str.isNull()); | |
110 | + QJsonObject sessionjson = OCacicComm.login(); | |
111 | + QJsonValue session_str = sessionjson["codestatus"]; | |
112 | + // qDebug() << session_str.toVariant().toString(); | |
113 | + QVERIFY(!session_str.isNull()); | |
109 | 114 | } |
110 | 115 | |
111 | 116 | void CTestCacic::cleanupTestCase() | ... | ... |
cacic-teste/testcacic.h
1 | 1 | #ifndef TESTINSTALLCACIC_H |
2 | 2 | #define TESTINSTALLCACIC_H |
3 | 3 | |
4 | -#include <cacic_comm.h> | |
5 | -#include <ccacic.h> | |
6 | -#include <cacic_computer.h> | |
4 | +#include <../src/cacic_comm.h> | |
5 | +#include <../src/ccacic.h> | |
6 | +#include <../src/cacic_computer.h> | |
7 | 7 | #include <QtTest/QtTest> |
8 | 8 | #include <QDebug> |
9 | 9 | #include <QList> |
10 | 10 | #include <QProcess> |
11 | 11 | #include <QStringList> |
12 | 12 | #include <iostream> |
13 | -#include <QHostAddress> | |
13 | +#include <QtNetwork/QtNetwork> | |
14 | 14 | #include <QJsonObject> |
15 | 15 | |
16 | 16 | class CTestCacic : public QObject |
17 | 17 | { |
18 | - Q_OBJECT | |
18 | + Q_OBJECT | |
19 | 19 | public: |
20 | - explicit CTestCacic(QObject *parent = 0); | |
20 | + explicit CTestCacic(QObject *parent = 0); | |
21 | 21 | |
22 | 22 | private: |
23 | - CacicComm OCacicComm; | |
24 | - CCacic OCacic; | |
25 | - CACIC_Computer OCacicComp; | |
26 | - QString testPath; | |
27 | - QString testIniPath; | |
28 | - QJsonObject session; | |
23 | + CacicComm OCacicComm; | |
24 | + CCacic OCacic; | |
25 | + CACIC_Computer OCacicComp; | |
26 | + QString testPath; | |
27 | + QString testIniPath; | |
28 | + QJsonObject session; | |
29 | 29 | |
30 | 30 | signals: |
31 | 31 | |
32 | 32 | public slots: |
33 | 33 | |
34 | 34 | private slots: |
35 | - void initTestCase(); | |
36 | - void testCommStatus(); | |
37 | - void testComm(); | |
38 | - void testGetAndSetValueFromFile(); | |
39 | - void testGetValueFromTags(); | |
40 | - void testEnCrypt(); | |
41 | - void testDeCrypt(); | |
42 | - void testCreateFolder(); | |
43 | - void testDeleteFolder(); | |
44 | - void testDeleteFile(); | |
45 | - void testInterfaceDeRede(); | |
46 | - void testpegarOS(); | |
47 | - void testLogin(); | |
48 | - void cleanupTestCase(); | |
35 | + void initTestCase(); | |
36 | + void testCommStatus(); | |
37 | + void testComm(); | |
38 | + void testGetAndSetValueFromFile(); | |
39 | + void testGetValueFromTags(); | |
40 | + void testEnCrypt(); | |
41 | + void testDeCrypt(); | |
42 | + void testCreateFolder(); | |
43 | + void testDeleteFolder(); | |
44 | + void testDeleteFile(); | |
45 | + void testInterfaceDeRede(); | |
46 | + void testPegarUsu(); | |
47 | + void testpegarOS(); | |
48 | + void testLogin(); | |
49 | + void cleanupTestCase(); | |
49 | 50 | }; |
50 | 51 | |
51 | 52 | #endif // TESTINSTALLCACIC_H | ... | ... |
src/cacic_computer.cpp
... | ... | @@ -2,8 +2,9 @@ |
2 | 2 | |
3 | 3 | CACIC_Computer::CACIC_Computer() |
4 | 4 | { |
5 | - os = pegarOS(); | |
6 | - networkInterface = networkInterfacesRunning(); | |
5 | + os = pegarOS(); | |
6 | + networkInterface = networkInterfacesRunning(); | |
7 | + usu = pegarUsu(); | |
7 | 8 | } |
8 | 9 | |
9 | 10 | /*NetworkInterfacesRunning |
... | ... | @@ -14,31 +15,31 @@ CACIC_Computer::CACIC_Computer() |
14 | 15 | * |
15 | 16 | */ |
16 | 17 | QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ |
17 | - QNetworkInterface interface; | |
18 | - QList<std::string> lista; | |
19 | - QList<QList<std::string>> todasInterfaces; | |
18 | + QNetworkInterface interface; | |
19 | + QList<std::string> lista; | |
20 | + QList<QList<std::string>> todasInterfaces; | |
20 | 21 | |
21 | - foreach (QNetworkInterface in, interface.allInterfaces()) { | |
22 | - if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && | |
23 | - !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) && | |
24 | - (bool)(in.flags() & QNetworkInterface::IsRunning)){ | |
25 | -// qDebug() << in.humanReadableName() << "\n"; | |
26 | - lista.append(in.humanReadableName().toStdString()); | |
27 | -// qDebug() << in.hardwareAddress() << "\n"; | |
28 | - lista.append(in.hardwareAddress().toStdString()); | |
29 | - foreach (QNetworkAddressEntry ae, in.addressEntries()){ | |
30 | - if (ae.ip().scopeId() == ""){ | |
31 | - lista.append(ae.ip().toString().toStdString()); | |
22 | + foreach (QNetworkInterface in, interface.allInterfaces()) { | |
23 | + if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) && | |
24 | + !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) && | |
25 | + (bool)(in.flags() & QNetworkInterface::IsRunning)){ | |
26 | + // qDebug() << in.humanReadableName() << "\n"; | |
27 | + lista.append(in.humanReadableName().toStdString()); | |
28 | + // qDebug() << in.hardwareAddress() << "\n"; | |
29 | + lista.append(in.hardwareAddress().toStdString()); | |
30 | + foreach (QNetworkAddressEntry ae, in.addressEntries()){ | |
31 | + if (ae.ip().scopeId() == ""){ | |
32 | + lista.append(ae.ip().toString().toStdString()); | |
32 | 33 | } else { |
33 | - lista.append(ae.ip().toString().toStdString()); | |
34 | + lista.append(ae.ip().toString().toStdString()); | |
34 | 35 | } |
35 | -// qDebug() << ae.ip().toString() << "\n"; | |
36 | + // qDebug() << ae.ip().toString() << "\n"; | |
36 | 37 | } |
37 | - todasInterfaces.append(lista); | |
38 | - lista.clear(); | |
38 | + todasInterfaces.append(lista); | |
39 | + lista.clear(); | |
39 | 40 | } |
40 | 41 | } |
41 | - return todasInterfaces; | |
42 | + return todasInterfaces; | |
42 | 43 | } |
43 | 44 | |
44 | 45 | /*pegarOS |
... | ... | @@ -48,31 +49,73 @@ QList<QList<std::string>> CACIC_Computer::networkInterfacesRunning(){ |
48 | 49 | */ |
49 | 50 | std::string CACIC_Computer::pegarOS(){ |
50 | 51 | QString text; |
51 | - QStringList environment = QProcess::systemEnvironment(); | |
52 | + QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); | |
52 | 53 | foreach (text, environment) { |
53 | - if (text.contains("OS=", Qt::CaseInsensitive)){ | |
54 | - if ((QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8) && | |
55 | - (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8_1)); | |
56 | -// qDebug () << "win 8"; | |
57 | - else if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8_1) | |
58 | -// qDebug() << "win 8.1"; | |
59 | - return text.mid(text.indexOf("=")+1).toStdString(); | |
54 | + if (text.contains("OS=Win", Qt::CaseInsensitive)){ | |
55 | + //qDebug() << "Windows_NT"; | |
56 | + return "Windows_NT"; | |
57 | + }else{ | |
58 | + if (text.contains("SESSION=", Qt::CaseInsensitive)){ | |
59 | + //qDebug() << "linux"; | |
60 | + return "linux"; | |
61 | + } | |
62 | + } | |
63 | + } | |
64 | +} | |
65 | + | |
66 | + | |
67 | +/* | |
68 | + * PegarUsu() | |
69 | + * @return: std::string; | |
70 | + * retorna uma string o qual dirá qual é o usuario logado no sistema. | |
71 | +*/ | |
72 | +std::string CACIC_Computer::pegarUsu(){ | |
73 | + QString text; | |
74 | + QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); | |
75 | + foreach (text, environment) { | |
76 | + if (text.contains("USER=", Qt::CaseInsensitive)){ | |
77 | + QString x = text; | |
78 | + QString s = "USER="; | |
79 | + QString e = "\""; | |
80 | + int start = x.indexOf(s, 0, Qt::CaseInsensitive); | |
81 | + int end = x.indexOf(e, Qt::CaseInsensitive); | |
82 | + if(start != -1){ | |
83 | + QString y = x.mid(start + s.length(), ((end - (start + s.length())) > -1 ? (end - (start + s.length())) : -1)); | |
84 | + //qDebug() << y; | |
85 | + return y.toStdString(); | |
86 | + } | |
87 | + }else{ | |
88 | + if (text.contains("USERNAME=", Qt::CaseInsensitive)){ | |
89 | + QString x = text; | |
90 | + QString s = "USERNAME="; | |
91 | + QString e = "\""; | |
92 | + int start = x.indexOf(s, 0, Qt::CaseInsensitive); | |
93 | + int end = x.indexOf(e, Qt::CaseInsensitive); | |
94 | + if(start != -1){ | |
95 | + QString y = x.mid(start + s.length(), ((end - (start + s.length())) > -1 ? (end - (start + s.length())) : -1)); | |
96 | + // qDebug() << y; | |
97 | + return y.toStdString(); | |
98 | + } | |
99 | + } | |
60 | 100 | } |
61 | - //implementar o if pra quando for linux. | |
62 | 101 | } |
63 | - return ""; | |
102 | + return false; | |
64 | 103 | } |
65 | 104 | |
66 | 105 | /* |
67 | 106 | * getters/setters |
68 | - */ | |
107 | +*/ | |
69 | 108 | |
70 | 109 | std::string CACIC_Computer::getOs() const |
71 | 110 | { |
72 | - return os; | |
111 | + return os; | |
73 | 112 | } |
113 | + | |
114 | +std::string CACIC_Computer::getUser() const { | |
115 | + return usu; | |
116 | +} | |
117 | + | |
74 | 118 | QList<QList<std::string>> CACIC_Computer::getNetworkInterface() const |
75 | 119 | { |
76 | - return networkInterface; | |
120 | + return networkInterface; | |
77 | 121 | } |
78 | - | ... | ... |
src/cacic_computer.h
... | ... | @@ -14,13 +14,16 @@ public: |
14 | 14 | CACIC_Computer(); |
15 | 15 | |
16 | 16 | std::string pegarOS(); |
17 | + std::string pegarUsu(); | |
17 | 18 | std::string getOs() const; |
19 | + std::string getUser() const; | |
18 | 20 | QList<QList<std::string>> getNetworkInterface() const; |
19 | 21 | QList<QList<std::string>> networkInterfacesRunning(); |
20 | 22 | |
21 | 23 | private: |
22 | 24 | QList<QList<std::string>> networkInterface; |
23 | 25 | std::string os; |
26 | + std::string usu; | |
24 | 27 | |
25 | 28 | }; |
26 | 29 | ... | ... |