diff --git a/cacic-teste/cacic-teste.pro b/cacic-teste/cacic-teste.pro index fa949f6..1ce5c40 100644 --- a/cacic-teste/cacic-teste.pro +++ b/cacic-teste/cacic-teste.pro @@ -9,6 +9,7 @@ QT += network TARGET = cacic-teste CONFIG -= app_bundle +CONFIG += c++11 TEMPLATE = app win32 { LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index 58dc3e5..11a1520 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -85,10 +85,14 @@ void CTestCacic::testDeCrypt(){ } void CTestCacic::testInterfaceDeRede(){ -// qDebug() << QString::fromStdString(OCacicComp.getIp()); +// qDebug() << QString::fromStdString(OCacicComp.getNetworkInterface().at(0).at(0)); QVERIFY(!OCacicComp.getNetworkInterface().empty()); } void CTestCacic::testpegarOS(){ - QVERIFY(OCacicComp.getOs() == "Windows_NT"); + QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux")); } + +//void CTestCacic::testJson(){ +// OCacic.readJson(); +//} diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index 174ced8..dd4e55a 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -40,6 +40,7 @@ private slots: void testDeleteFile(); void testInterfaceDeRede(); void testpegarOS(); +// void testJson(); }; #endif // TESTINSTALLCACIC_H diff --git a/src/cacic_computer.cpp b/src/cacic_computer.cpp index 174e1c3..02e4997 100644 --- a/src/cacic_computer.cpp +++ b/src/cacic_computer.cpp @@ -3,41 +3,44 @@ CACIC_Computer::CACIC_Computer(QObject *parent) : QObject(parent) { - ip = pegarIPInterfaceDeRede(); - mac = pegarMACInterfaceDeRede(); + os = pegarOS(); + networkInterface = networkInterfacesRunning(); } -std::string CACIC_Computer::pegarIPInterfaceDeRede() { - QNetworkInterface interface; - QList IpList = interface.allAddresses(); - for (int i = 0; i < IpList.size(); i++){ - if((!IpList.at(i).isLoopback()) & (IpList.at(i).scopeId() == "")){ - return IpList.at(i).toString().toStdString(); +QList> CACIC_Computer::networkInterfacesRunning(){ + QNetworkInterface interface; + QList lista; + QList> todasInterfaces; + + foreach (QNetworkInterface in, interface.allInterfaces()) { + if (!(bool)(in.flags() & QNetworkInterface::IsLoopBack) & + !(bool)(in.flags() & QNetworkInterface::IsPointToPoint) & + (bool)(in.flags() & QNetworkInterface::IsRunning)){ + lista.append(in.humanReadableName().toStdString()); + lista.append(in.hardwareAddress().toStdString()); + foreach (QNetworkAddressEntry ae, in.addressEntries()){ + if (ae.ip().scopeId() == ""){ + lista.append(ae.ip().toString().toStdString()); + } else { + lista.append(ae.ip().toString().toStdString()); + } + } + todasInterfaces.append(lista); + lista.clear(); } } - return ""; -} - - -std::string CACIC_Computer::pegarMACInterfaceDeRede(){ - foreach (const QNetworkInterface &ni, QNetworkInterface::allInterfaces()) { - if (!(ni.flags() & ni.IsLoopBack)){ - //qDebug() << ni.hardwareAddress(); - return ni.hardwareAddress().toStdString(); - } - } - return "ERROR MAC"; + return todasInterfaces; } std::string CACIC_Computer::pegarOS(){ QString text; - qint32 x=0; - //QStringList environment = QProcessEnvironment::systemEnvironment().toStringList(); QStringList environment = QProcess::systemEnvironment(); -// foreach (text, environment) { -// qDebug() << x << sear; -// x++; -// } + foreach (text, environment) { + if (text.contains("OS=", Qt::CaseInsensitive)){ + return text.mid(text.indexOf("=")+1).toStdString(); + } + //implementar o if pra quando for linux. + } return ""; } @@ -45,17 +48,14 @@ std::string CACIC_Computer::pegarOS(){ * getters/setters */ -std::string CACIC_Computer::getIp() const -{ - return ip; -} -std::string CACIC_Computer::getMac() const -{ - return mac; -} std::string CACIC_Computer::getOs() const { return os; } +QList> CACIC_Computer::getNetworkInterface() const +{ + return networkInterface; +} + diff --git a/src/cacic_computer.h b/src/cacic_computer.h index 4b77c6a..0097b59 100644 --- a/src/cacic_computer.h +++ b/src/cacic_computer.h @@ -6,25 +6,21 @@ #include #include #include -#include class CACIC_Computer : public QObject { Q_OBJECT public: - explicit CACIC_Computer(QObject *parent = 0); - std::string pegarIPInterfaceDeRede(); - std::string pegarMACInterfaceDeRede(); - std::string pegarOS(); - void setOs(const std::string &value); - std::string getIp() const; - std::string getMac() const; - std::string getOs() const; + explicit CACIC_Computer(QObject *parent = 0); + + std::string pegarOS(); + std::string getOs() const; + QList> getNetworkInterface() const; + QList> networkInterfacesRunning(); private: - std::string ip; - std::string mac; - std::string os; + QList> networkInterface; + std::string os; signals: diff --git a/src/ccacic.cpp b/src/ccacic.cpp index 8d9bf07..343fed0 100644 --- a/src/ccacic.cpp +++ b/src/ccacic.cpp @@ -149,6 +149,33 @@ QString CCacic::deCrypt(QString str_in, QString key, QString iv) { return QString::fromStdString(str_out).toLocal8Bit(); } +//void CCacic::readJson() +//{ +// QString val; +// QFile file; +// file.setFileName("e:/Lightbase/teste.json"); +// file.open(QIODevice::ReadOnly | QIODevice::Text); +// val = file.readAll(); +// file.close(); +// qWarning() << val; +// QJsonDocument d = QJsonDocument::fromJson(val.toUtf8()); +// QJsonObject sett2 = d.object(); +// QJsonValue value = sett2.value(QString("appName")); +// qWarning() << value; +// QJsonObject item = value.toObject(); +// qWarning() << tr("QJsonObject of description: ") << item; + +// /* incase of string value get value and convert into string*/ +// qWarning() << tr("QJsonObject[appName] of description: ") << item["description"]; +// QJsonValue subobj = item["description"]; +// qWarning() << subobj.toString(); + +// /* incase of array get array and convert into string*/ +// qWarning() << tr("QJsonObject[appName] of value: ") << item["imp"]; +// QJsonArray test = item["imp"].toArray(); +// qWarning() << test[1].toString(); +//} + /*Getters/Setters * Begin: */ diff --git a/src/ccacic.h b/src/ccacic.h index b643768..ef5027c 100644 --- a/src/ccacic.h +++ b/src/ccacic.h @@ -30,6 +30,7 @@ public: bool createFolder(QString path); bool deleteFolder(QString path); bool deleteFile(QString path); +// void readJson(); //Geters/seters: -- libgit2 0.21.2