Commit 611eaf16b8f5357b22923b6237b971f3a3433783

Authored by Eric Menezes Noronha
2 parents bb45c9b0 cd149826
Exists in master

Merge branch 'master' of https://github.com/lightbase/cacic-agente

Conflicts:
	cacic-teste/testcacic.cpp
	cacic-teste/testcacic.h
cacic-teste/cacic-teste.pro
... ... @@ -22,6 +22,7 @@ SOURCES += \
22 22 ../src/ccacic.cpp \
23 23 ../src/cacic_computer.cpp
24 24  
  25 +
25 26 HEADERS += \
26 27 testcacic.h \
27 28 ../src/ccacic.h \
... ...
cacic-teste/testcacic.cpp
... ... @@ -5,7 +5,11 @@ QTEST_MAIN(CTestCacic)
5 5 CTestCacic::CTestCacic(QObject *parent) :
6 6 QObject(parent)
7 7 {
8   - OCacicComm = CacicComm("http://teste.cacic.cc",
  8 +}
  9 +
  10 +void CTestCacic::initTestCase()
  11 +{
  12 + this->OCacicComm = CacicComm("http://teste.cacic.cc",
9 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__",
10 14 "P198PVwtz5F5CfZPSUrzuaQA/QG1sTnwzl/rBnj8M7y5MglANGodG5LLD4q7oY809HuDR4g5tL64lZRBKvKPmEgWd9iAZKvT4UAm9XWN3nKKLGaznCaJohmntNGqrJP1Zd9riTHGu10mPbg/Uh3TCbBHVOICvu5sDlINlCR6A3[[MAIS]]a55RhfKNidvr5uX0kozCxr5t2DyOb5oPocEGyJKyHLQ==__CRYPTED__",
11 15 "1",
... ... @@ -20,8 +24,11 @@ CTestCacic::CTestCacic(QObject *parent) :
20 24 "2.5.1.1.256.32",
21 25 "2.8.1.7",
22 26 "2.8.1.6");
23   - testPath = QDir::currentPath() + "/teste";
24   - testIniPath = testPath + "/teste.ini";
  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);
25 32 }
26 33  
27 34 void CTestCacic::testCreateFolder()
... ... @@ -93,9 +100,14 @@ void CTestCacic::testpegarOS(){
93 100 QVERIFY((OCacicComp.getOs() == "Windows_NT") || (OCacicComp.getOs() == "linux"));
94 101 }
95 102  
96   -void CTestCacic::testSslConnection()
97   -{
98   - OSslComm.start("127.0.0.1", 8888);
99   - QVERIFY(false);
  103 +
  104 +void CTestCacic::testLogin(){
  105 + QJsonObject sessionjson = OCacicComm.login();
  106 + QJsonValue session_str = sessionjson["session"];
  107 + QVERIFY(session_str.isString());
100 108 }
101 109  
  110 +void CTestCacic::cleanupTestCase()
  111 +{
  112 +
  113 +}
... ...
cacic-teste/testcacic.h
... ... @@ -10,7 +10,8 @@
10 10 #include <QProcess>
11 11 #include <QStringList>
12 12 #include <iostream>
13   -#include <csslcomm.h>
  13 +#include <QHostAddress>
  14 +#include <QJsonObject>
14 15  
15 16 class CTestCacic : public QObject
16 17 {
... ... @@ -24,13 +25,14 @@ private:
24 25 CACIC_Computer OCacicComp;
25 26 QString testPath;
26 27 QString testIniPath;
27   - CSslComm OSslComm;
  28 + QJsonObject session;
28 29  
29 30 signals:
30 31  
31 32 public slots:
32 33  
33 34 private slots:
  35 + void initTestCase();
34 36 void testCommStatus();
35 37 void testComm();
36 38 void testGetAndSetValueFromFile();
... ... @@ -42,7 +44,9 @@ private slots:
42 44 void testDeleteFile();
43 45 void testInterfaceDeRede();
44 46 void testpegarOS();
45   - void testSslConnection();
  47 + void testJson();
  48 + void testLogin();
  49 + void cleanupTestCase();
46 50 };
47 51  
48 52 #endif // TESTINSTALLCACIC_H
... ...
install-cacic/install-cacic.pro
... ... @@ -11,6 +11,7 @@ QT -= gui
11 11 TARGET = install-cacic
12 12 CONFIG += console
13 13 CONFIG -= app_bundle
  14 +CONFIG += c++11
14 15  
15 16 TEMPLATE = app
16 17  
... ... @@ -21,6 +22,6 @@ SOURCES += main.cpp \
21 22  
22 23 HEADERS += \
23 24 installcacic.h \
24   - ../src/CACIC_comm.h \
25 25 ../src/ccacic.h \
26   - ../src/cacic_computer.h
  26 + ../src/cacic_computer.h \
  27 + ../src/cacic_comm.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-07-21T17:43:51. -->
  3 +<!-- Written by QtCreator 3.1.1, 2014-08-05T11:41:11. -->
4 4 <qtcreator>
5 5 <data>
6 6 <variable>ProjectExplorer.Project.ActiveTarget</variable>
... ... @@ -54,14 +54,14 @@
54 54 <data>
55 55 <variable>ProjectExplorer.Project.Target.0</variable>
56 56 <valuemap type="QVariantMap">
57   - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.3 GCC 64bit</value>
58   - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.3 GCC 64bit</value>
  57 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.3.0 GCC 64bit</value>
  58 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.3.0 GCC 64bit</value>
59 59 <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.53.gcc_64_kit</value>
60 60 <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
61 61 <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
62 62 <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
63 63 <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
64   - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/lightbase/cacic-agente/builds</value>
  64 + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eduardo/srv/cacic-agente-new/build-install-cacic-Desktop_Qt_5_3_0_GCC_64bit-Debug</value>
65 65 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
66 66 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
67 67 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
... ... @@ -120,7 +120,7 @@
120 120 <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
121 121 </valuemap>
122 122 <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
123   - <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/lightbase/Projeto Cacic/cacic-agente/build-install-cacic-Desktop_Qt_5_3_GCC_64bit-Release</value>
  123 + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eduardo/srv/cacic-agente-new/build-install-cacic-Desktop_Qt_5_3_0_GCC_64bit-Release</value>
124 124 <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
125 125 <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
126 126 <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
... ... @@ -232,7 +232,7 @@
232 232 <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
233 233 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value>
234 234 <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">install-cacic2</value>
235   - <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/lightbase/cacic-agente/install-cacic/install-cacic.pro</value>
  235 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/eduardo/srv/cacic-agente/install-cacic/install-cacic.pro</value>
236 236 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
237 237 <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value>
238 238 <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
... ... @@ -254,7 +254,7 @@
254 254 </data>
255 255 <data>
256 256 <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
257   - <value type="QByteArray">{ece4f619-8231-4029-8d3b-e5858b910820}</value>
  257 + <value type="QByteArray">{05f74523-32aa-49a4-aa35-22a4457a2f3f}</value>
258 258 </data>
259 259 <data>
260 260 <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
... ...
src/CACIC_comm.h
... ... @@ -1,115 +0,0 @@
1   -#ifndef CACIC_COMM_H
2   -#define CACIC_COMM_H
3   -
4   -#include <QCoreApplication>
5   -#include <QObject>
6   -#include <QDebug>
7   -#include <QFile>
8   -#include <QUrlQuery>
9   -#include <QtNetwork/QNetworkAccessManager>
10   -#include <QtNetwork/QNetworkRequest>
11   -#include <QtNetwork/QNetworkReply>
12   -#include <QUrlQuery>
13   -
14   -
15   -class CacicComm {
16   -
17   -private:
18   - QUrlQuery params;
19   - QString urlGerente;
20   -
21   -public:
22   - CacicComm (){
23   -
24   - }
25   -
26   - CacicComm (QString urlGerente, QString operatingSystem, QString computerSystem, QString csCipher,
27   - QString csDebug, QString csCompress, QString httpUserAgent, QString moduleFolderName,
28   - QString moduleProgramName, QString networkConfiguration,QString phpAuthPw, QString phpAuthUser,
29   - QString so, QString cacicVersion, QString gercolsVersion)
30   - {
31   - this->urlGerente = urlGerente;
32   -
33   - params.addQueryItem("OperatingSystem", operatingSystem);
34   - params.addQueryItem("ComputerSystem",computerSystem);
35   - params.addQueryItem("cs_cipher",csCipher);
36   - params.addQueryItem("cs_debug",csDebug);
37   - params.addQueryItem("cs_compress",csCompress);
38   - params.addQueryItem("HTTP_USER_AGENT",httpUserAgent);
39   - params.addQueryItem("ModuleFolderName",moduleFolderName);
40   - params.addQueryItem("ModuleProgramName",moduleProgramName);
41   - params.addQueryItem("NetworkAdapterConfiguration",networkConfiguration);
42   - params.addQueryItem("PHP_AUTH_PW",phpAuthPw);
43   - params.addQueryItem("PHP_AUTH_USER",phpAuthUser);
44   - params.addQueryItem("te_so",so);
45   - params.addQueryItem("te_versao_cacic",cacicVersion);
46   - params.addQueryItem("te_versao_gercols",gercolsVersion);
47   - }
48   -
49   - QString comm(QString route)
50   - {
51   - QString retorno = "0";
52   - QByteArray data;
53   - QUrl url = urlGerente + route;
54   -
55   - data.append(params.toString());
56   -
57   - // cria um event-loop temporario
58   - QEventLoop eventLoop;
59   - // "quit()" o event-loop, when the network request "finished()"
60   - QNetworkAccessManager mgr;
61   - QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
62   -
63   - // a requisição HTTP
64   -
65   - QNetworkRequest req(url);
66   - req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente");
67   -
68   - QNetworkReply *reply = mgr.post(req, data);
69   - eventLoop.exec(); // sai do looping chamando o "finished()".
70   -
71   -
72   - if (reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).isValid()){
73   - retorno = reply->readAll();
74   - // qDebug() << "Status:" << codigoStatus.toInt() << retorno;
75   - }else{
76   - retorno = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
77   - // qDebug() << "Error:" << reason;
78   - }
79   - return retorno;
80   - }
81   -
82   -
83   - /* commStatus
84   - * execulta um teste do tipo GET na urlGerente;
85   - * @return retorna o resultado da conexão HTTP:
86   - * exemplo: 200 OK
87   - */
88   - bool commStatus(){
89   - // cria um event-loop temporario
90   - QEventLoop eventLoop;
91   - // "quit()" o event-loop, when the network request "finished()"
92   - QNetworkAccessManager mgr;
93   - QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
94   - // a requisição HTTP
95   - QUrl url = urlGerente;
96   - QNetworkRequest req( url );
97   - QNetworkReply *reply = mgr.get(req);
98   - eventLoop.exec(); // sai do looping chamando o "finished()".
99   -
100   - QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
101   - if (reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).isValid()){
102   - qDebug() << "Status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << reason;
103   - return true;
104   - }else{
105   - reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
106   - // qDebug() << "Error:" << reason;
107   - return false;
108   - }
109   - }
110   -
111   -signals:
112   - void finished(QNetworkReply* reply);
113   -};
114   -
115   -#endif // CACIC_COMM_H
src/cacic_comm.h 0 → 100644
... ... @@ -0,0 +1,152 @@
  1 +#ifndef CACIC_COMM_H
  2 +#define CACIC_COMM_H
  3 +
  4 +#include <QCoreApplication>
  5 +#include <QObject>
  6 +#include <QDebug>
  7 +#include <QFile>
  8 +#include <QUrlQuery>
  9 +#include <QtNetwork/QNetworkAccessManager>
  10 +#include <QtNetwork/QNetworkRequest>
  11 +#include <QtNetwork/QNetworkReply>
  12 +#include <QUrlQuery>
  13 +#include <QJsonObject>
  14 +#include <QJsonDocument>
  15 +
  16 +
  17 +class CacicComm {
  18 +
  19 +private:
  20 + QUrlQuery params;
  21 + QString urlGerente;
  22 + // FIXME: Get from configuration
  23 + QString usuario = "user";
  24 + QString password = "123456";
  25 +
  26 +public:
  27 + CacicComm (){
  28 +
  29 + }
  30 +
  31 + CacicComm (QString urlGerente, QString operatingSystem, QString computerSystem, QString csCipher,
  32 + QString csDebug, QString csCompress, QString httpUserAgent, QString moduleFolderName,
  33 + QString moduleProgramName, QString networkConfiguration,QString phpAuthPw, QString phpAuthUser,
  34 + QString so, QString cacicVersion, QString gercolsVersion)
  35 + {
  36 + this->urlGerente = urlGerente;
  37 +
  38 + params.addQueryItem("OperatingSystem", operatingSystem);
  39 + params.addQueryItem("ComputerSystem",computerSystem);
  40 + params.addQueryItem("cs_cipher",csCipher);
  41 + params.addQueryItem("cs_debug",csDebug);
  42 + params.addQueryItem("cs_compress",csCompress);
  43 + params.addQueryItem("HTTP_USER_AGENT",httpUserAgent);
  44 + params.addQueryItem("ModuleFolderName",moduleFolderName);
  45 + params.addQueryItem("ModuleProgramName",moduleProgramName);
  46 + params.addQueryItem("NetworkAdapterConfiguration",networkConfiguration);
  47 + params.addQueryItem("PHP_AUTH_PW",phpAuthPw);
  48 + params.addQueryItem("PHP_AUTH_USER",phpAuthUser);
  49 + params.addQueryItem("te_so",so);
  50 + params.addQueryItem("te_versao_cacic",cacicVersion);
  51 + params.addQueryItem("te_versao_gercols",gercolsVersion);
  52 + }
  53 +
  54 + QJsonObject comm(QString route, const QJsonObject &json)
  55 + {
  56 + QString retorno = "0";
  57 + QByteArray data;
  58 + QUrl url = urlGerente + route;
  59 +
  60 + //data.append(params.toString());
  61 +
  62 + // Add JSON
  63 + QJsonDocument d(json);
  64 + data.append(d.toVariant().toString());
  65 +
  66 + // cria um event-loop temporario
  67 + QEventLoop eventLoop;
  68 + // "quit()" o event-loop, when the network request "finished()"
  69 + QNetworkAccessManager mgr;
  70 + QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
  71 +
  72 + // a requisição HTTP
  73 + QNetworkRequest req(url);
  74 + req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
  75 + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente");
  76 +
  77 + QNetworkReply *reply = mgr.post(req, data);
  78 + eventLoop.exec(); // sai do looping chamando o "finished()".
  79 +
  80 + if (reply->error() == QNetworkReply::NoError) {
  81 +
  82 + QString strReply = (QString)reply->readAll();
  83 +
  84 + //parse json
  85 + qDebug() << "Response:" << strReply;
  86 + QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
  87 +
  88 + QJsonObject jsonObj = jsonResponse.object();
  89 +
  90 + //qDebug() << "Time:" << jsonObj["time"].toString();
  91 + //qDebug() << "Date:" << jsonObj["date"].toString();
  92 +
  93 + delete reply;
  94 +
  95 + return jsonObj;
  96 + } else {
  97 + //failure
  98 + qDebug() << "Failure" <<reply->errorString();
  99 + delete reply;
  100 +
  101 + return QJsonObject ();
  102 + }
  103 + }
  104 +
  105 +
  106 + /* commStatus
  107 + * execulta um teste do tipo GET na urlGerente;
  108 + * @return retorna o resultado da conexão HTTP:
  109 + * exemplo: 200 OK
  110 + */
  111 + bool commStatus(){
  112 + // cria um event-loop temporario
  113 + QEventLoop eventLoop;
  114 + // "quit()" o event-loop, when the network request "finished()"
  115 + QNetworkAccessManager mgr;
  116 + QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
  117 + // a requisição HTTP
  118 + QUrl url = urlGerente;
  119 + QNetworkRequest req( url );
  120 + QNetworkReply *reply = mgr.get(req);
  121 + eventLoop.exec(); // sai do looping chamando o "finished()".
  122 +
  123 + QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
  124 + if (reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).isValid()){
  125 + qDebug() << "Status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << reason;
  126 + return true;
  127 + }else{
  128 + reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
  129 + // qDebug() << "Error:" << reason;
  130 + return false;
  131 + }
  132 + }
  133 +
  134 + QJsonObject login() {
  135 + // Cria dados de login
  136 + QVariantMap loginMap;
  137 + loginMap["user"] = this->usuario;
  138 + loginMap["password"] = this->password;
  139 + QJsonObject loginJson = QJsonObject::fromVariantMap(loginMap);
  140 +
  141 + // Cria conexão e retorna Json da sessão
  142 + QJsonObject retorno = this->comm("login", loginJson);
  143 +
  144 + return retorno;
  145 +
  146 + }
  147 +
  148 +signals:
  149 + void finished(QNetworkReply* reply);
  150 +};
  151 +
  152 +#endif // CACIC_COMM_H
... ...