Commit e665e55d9d5455d6f8977f5fa50dac43e85d7361
1 parent
d0bdc415
Exists in
master
Test cacic alterado devido a algumas modificações na classe comm; Installcacic c…
…omeçando a ser implementado, já verificando os argumentos; Acrescentado 'sinal' na função de comunicação para retorno true ou false para saber se deu certo ou não
Showing
10 changed files
with
170 additions
and
70 deletions
Show diff stats
cacic-teste/testcacic.cpp
@@ -58,8 +58,9 @@ void CTestCacic::testCommStatus() | @@ -58,8 +58,9 @@ void CTestCacic::testCommStatus() | ||
58 | 58 | ||
59 | void CTestCacic::testComm() | 59 | void CTestCacic::testComm() |
60 | { | 60 | { |
61 | + bool ok; | ||
61 | if (OCacicComm.commStatus()){ | 62 | if (OCacicComm.commStatus()){ |
62 | - QJsonObject jsonreply = OCacicComm.comm("/ws/get/test"); | 63 | + QJsonObject jsonreply = OCacicComm.comm("/ws/get/test", &ok); |
63 | // qDebug() << jsonreply["codestatus"].toString(); | 64 | // qDebug() << jsonreply["codestatus"].toString(); |
64 | QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK")); | 65 | QVERIFY(OCacic.getValueFromTags(jsonreply["reply"].toString(), "Comm_Status", "<>") == QString("OK")); |
65 | } else | 66 | } else |
@@ -100,16 +101,18 @@ void CTestCacic::testJsonValueFromJsonString() | @@ -100,16 +101,18 @@ void CTestCacic::testJsonValueFromJsonString() | ||
100 | } | 101 | } |
101 | 102 | ||
102 | void CTestCacic::testLogin(){ | 103 | void CTestCacic::testLogin(){ |
103 | - QJsonObject jsonReply = OCacicComm.login(); | 104 | + bool ok; |
105 | + QJsonObject jsonReply = OCacicComm.login(&ok); | ||
104 | QJsonValue sessionvalue = jsonReply["reply"]; | 106 | QJsonValue sessionvalue = jsonReply["reply"]; |
105 | // qDebug() << sessionvalue.toObject()["session"].toString(); | 107 | // qDebug() << sessionvalue.toObject()["session"].toString(); |
106 | // qDebug() << sessionvalue.toString(); | 108 | // qDebug() << sessionvalue.toString(); |
107 | - QVERIFY(sessionvalue.isObject()); | 109 | + QVERIFY(ok); |
108 | } | 110 | } |
109 | 111 | ||
110 | void CTestCacic::testSslConnection() | 112 | void CTestCacic::testSslConnection() |
111 | { | 113 | { |
112 | - QJsonObject json = OCacicComm.comm("", QJsonObject(), true); | 114 | + bool ok; |
115 | + QJsonObject json = OCacicComm.comm("", &ok, QJsonObject(), true); | ||
113 | QJsonValue jsonvalue = json["codestatus"]; | 116 | QJsonValue jsonvalue = json["codestatus"]; |
114 | // qDebug() << jsonvalue.toDouble(); | 117 | // qDebug() << jsonvalue.toDouble(); |
115 | QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); | 118 | QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); |
@@ -130,6 +133,26 @@ void CTestCacic::testDeCrypt(){ | @@ -130,6 +133,26 @@ void CTestCacic::testDeCrypt(){ | ||
130 | 133 | ||
131 | } | 134 | } |
132 | 135 | ||
136 | +void CTestCacic::testInstallCacicStart() | ||
137 | +{ | ||
138 | +// char *argva[] = {"program name", "-host=teste.cacic.cpp", "-user=asda", "-password=qwesd", NULL}; | ||
139 | +// int argca = sizeof(argva) / sizeof(char*) - 1; | ||
140 | +// QCoreApplication a(argca, argva); | ||
141 | + | ||
142 | +// InstallCacic *oInstallCacic = new InstallCacic(&a); | ||
143 | + | ||
144 | +// QStringList args; | ||
145 | +// for (int i = 0; i<argca; i++) | ||
146 | +// args.append(argva[i]); | ||
147 | +// // This will cause the application to exit when | ||
148 | +// // the task signals finished. | ||
149 | +// QObject::connect(oInstallCacic, SIGNAL(finished()), &a, SLOT(quit())); | ||
150 | + | ||
151 | +// // This will run the task from the application event loop. | ||
152 | +// QMetaObject::invokeMethod(oInstallCacic, "run", Qt::QueuedConnection, Q_ARG(QStringList, args), Q_ARG(int, argca)); | ||
153 | + QVERIFY(false); | ||
154 | +} | ||
155 | + | ||
133 | void CTestCacic::cleanupTestCase() | 156 | void CTestCacic::cleanupTestCase() |
134 | { | 157 | { |
135 | 158 |
cacic-teste/testcacic.h
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | #include <iostream> | 12 | #include <iostream> |
13 | #include <QtNetwork/QtNetwork> | 13 | #include <QtNetwork/QtNetwork> |
14 | #include <QJsonObject> | 14 | #include <QJsonObject> |
15 | +#include "../install-cacic/installcacic.h" | ||
15 | 16 | ||
16 | class CTestCacic : public QObject | 17 | class CTestCacic : public QObject |
17 | { | 18 | { |
@@ -20,12 +21,12 @@ public: | @@ -20,12 +21,12 @@ public: | ||
20 | explicit CTestCacic(QObject *parent = 0); | 21 | explicit CTestCacic(QObject *parent = 0); |
21 | 22 | ||
22 | private: | 23 | private: |
23 | - CacicComm OCacicComm; | ||
24 | - CCacic OCacic; | ||
25 | - CACIC_Computer OCacicComp; | ||
26 | - QString testPath; | ||
27 | - QString testIniPath; | ||
28 | - QJsonObject session; | 24 | + CacicComm OCacicComm; |
25 | + CCacic OCacic; | ||
26 | + CACIC_Computer OCacicComp; | ||
27 | + QString testPath; | ||
28 | + QString testIniPath; | ||
29 | + QJsonObject session; | ||
29 | 30 | ||
30 | signals: | 31 | signals: |
31 | 32 | ||
@@ -48,6 +49,7 @@ private slots: | @@ -48,6 +49,7 @@ private slots: | ||
48 | void testSslConnection(); | 49 | void testSslConnection(); |
49 | void testEnCrypt(); | 50 | void testEnCrypt(); |
50 | void testDeCrypt(); | 51 | void testDeCrypt(); |
52 | + void testInstallCacicStart(); | ||
51 | void cleanupTestCase(); | 53 | void cleanupTestCase(); |
52 | }; | 54 | }; |
53 | 55 |
install-cacic/install-cacic.pro
@@ -13,6 +13,12 @@ CONFIG += console | @@ -13,6 +13,12 @@ CONFIG += console | ||
13 | CONFIG -= app_bundle | 13 | CONFIG -= app_bundle |
14 | CONFIG += c++11 | 14 | CONFIG += c++11 |
15 | 15 | ||
16 | +win32 { | ||
17 | + LIBS += -LE:\LightBase\cacic-agente-project\cacic-agente\src\crypto++\lib -lcryptopp | ||
18 | +} else { | ||
19 | + LIBS += -L/usr/lib -lcryptopp | ||
20 | +} | ||
21 | + | ||
16 | TEMPLATE = app | 22 | TEMPLATE = app |
17 | 23 | ||
18 | SOURCES += main.cpp \ | 24 | SOURCES += main.cpp \ |
@@ -25,3 +31,6 @@ HEADERS += \ | @@ -25,3 +31,6 @@ HEADERS += \ | ||
25 | ../src/ccacic.h \ | 31 | ../src/ccacic.h \ |
26 | ../src/cacic_computer.h \ | 32 | ../src/cacic_computer.h \ |
27 | ../src/cacic_comm.h | 33 | ../src/cacic_comm.h |
34 | + | ||
35 | +INCLUDEPATH += ../src \ | ||
36 | + ../src/crypto++/include/ |
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.1, 2014-08-05T11:41:11. --> | 3 | +<!-- Written by QtCreator 3.1.2, 2014-08-13T18:44:40. --> |
4 | <qtcreator> | 4 | <qtcreator> |
5 | <data> | 5 | <data> |
6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
@@ -54,14 +54,14 @@ | @@ -54,14 +54,14 @@ | ||
54 | <data> | 54 | <data> |
55 | <variable>ProjectExplorer.Project.Target.0</variable> | 55 | <variable>ProjectExplorer.Project.Target.0</variable> |
56 | <valuemap type="QVariantMap"> | 56 | <valuemap type="QVariantMap"> |
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 | - <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.53.gcc_64_kit</value> | 57 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.3.0 MinGW 32bit</value> |
58 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.3.0 MinGW 32bit</value> | ||
59 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.53.win32_mingw482_kit</value> | ||
60 | <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> | 60 | <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> |
61 | <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> | 61 | <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> |
62 | <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> | 62 | <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> |
63 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> | 63 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> |
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> | 64 | + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/LightBase/cacic-agente-project/builds/install-cacic</value> |
65 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> | 65 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
66 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> | 66 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
67 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> | 67 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
@@ -78,10 +78,7 @@ | @@ -78,10 +78,7 @@ | ||
78 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> | 78 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
79 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> | 79 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
80 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> | 80 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
81 | - <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"> | ||
82 | - <value type="QString">-w</value> | ||
83 | - <value type="QString">-r</value> | ||
84 | - </valuelist> | 81 | + <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
85 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> | 82 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> |
86 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value> | 83 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value> |
87 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> | 84 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
@@ -97,10 +94,7 @@ | @@ -97,10 +94,7 @@ | ||
97 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> | 94 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
98 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> | 95 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
99 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> | 96 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
100 | - <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"> | ||
101 | - <value type="QString">-w</value> | ||
102 | - <value type="QString">-r</value> | ||
103 | - </valuelist> | 97 | + <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
104 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value> | 98 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value> |
105 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value> | 99 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value> |
106 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> | 100 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
@@ -120,7 +114,7 @@ | @@ -120,7 +114,7 @@ | ||
120 | <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> | 114 | <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> |
121 | </valuemap> | 115 | </valuemap> |
122 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> | 116 | <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> |
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> | 117 | + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/LightBase/cacic-agente-project/cacic-agente/build-install-cacic-Release</value> |
124 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> | 118 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
125 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> | 119 | <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
126 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> | 120 | <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
@@ -137,10 +131,7 @@ | @@ -137,10 +131,7 @@ | ||
137 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> | 131 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
138 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> | 132 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
139 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> | 133 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
140 | - <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"> | ||
141 | - <value type="QString">-w</value> | ||
142 | - <value type="QString">-r</value> | ||
143 | - </valuelist> | 134 | + <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
144 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> | 135 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> |
145 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value> | 136 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value> |
146 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> | 137 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
@@ -156,10 +147,7 @@ | @@ -156,10 +147,7 @@ | ||
156 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> | 147 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
157 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> | 148 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
158 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> | 149 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
159 | - <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"> | ||
160 | - <value type="QString">-w</value> | ||
161 | - <value type="QString">-r</value> | ||
162 | - </valuelist> | 150 | + <valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"/> |
163 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value> | 151 | <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value> |
164 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value> | 152 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value> |
165 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> | 153 | <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
@@ -231,9 +219,9 @@ | @@ -231,9 +219,9 @@ | ||
231 | <value type="int" key="PE.EnvironmentAspect.Base">2</value> | 219 | <value type="int" key="PE.EnvironmentAspect.Base">2</value> |
232 | <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> | 220 | <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> |
233 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> | 221 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> |
234 | - <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">install-cacic2</value> | ||
235 | - <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/eduardo/srv/cacic-agente/install-cacic/install-cacic.pro</value> | ||
236 | - <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> | 222 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
223 | + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro</value> | ||
224 | + <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-host=10.1.0.137/cacic/web/app_dev.php -user=cacic -password=cacic123</value> | ||
237 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> | 225 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> |
238 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> | 226 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> |
239 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> | 227 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> |
@@ -254,7 +242,7 @@ | @@ -254,7 +242,7 @@ | ||
254 | </data> | 242 | </data> |
255 | <data> | 243 | <data> |
256 | <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable> | 244 | <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable> |
257 | - <value type="QByteArray">{05f74523-32aa-49a4-aa35-22a4457a2f3f}</value> | 245 | + <value type="QByteArray">{2d43e969-a5af-4db4-9730-35c8f8cce80d}</value> |
258 | </data> | 246 | </data> |
259 | <data> | 247 | <data> |
260 | <variable>ProjectExplorer.Project.Updater.FileVersion</variable> | 248 | <variable>ProjectExplorer.Project.Updater.FileVersion</variable> |
install-cacic/installcacic.cpp
@@ -4,13 +4,61 @@ | @@ -4,13 +4,61 @@ | ||
4 | InstallCacic::InstallCacic(QObject *parent) : | 4 | InstallCacic::InstallCacic(QObject *parent) : |
5 | QObject(parent) | 5 | QObject(parent) |
6 | { | 6 | { |
7 | + | ||
8 | +} | ||
9 | + | ||
10 | +void InstallCacic::run(QStringList argv, int argc) { | ||
11 | + QMap<QString, QString> args; | ||
12 | + bool ok; | ||
13 | + //valida os parametros repassados | ||
14 | + validaParametros(argv, argc, &ok); | ||
15 | + //se tiver usuario, senha e url | ||
16 | + if (ok){ | ||
17 | + oCacicComm.setUrlGerente(this->argumentos["host"]); | ||
18 | + oCacicComm.setUsuario(this->argumentos["user"]); | ||
19 | + oCacicComm.setPassword(this->argumentos["password"]); | ||
20 | + QJsonObject jsonLogin = oCacicComm.login(&ok); | ||
21 | + if (ok){ | ||
22 | + //TODO: Conectado. armazenar chave em arquivo e sessao na comm; | ||
23 | + qDebug() << "Logado"; | ||
24 | + } | ||
25 | + else | ||
26 | + qDebug() << "falha no login"; | ||
27 | + } else { | ||
28 | + std::cout << "Parametros incorretos. ([obrigatorios] <opcional>)\n"; | ||
29 | + std::cout << " [-host=url_gerente] <Descricao aqui>\n"; | ||
30 | + std::cout << " [-user=usuario] <Descricao aqui>\n"; | ||
31 | + std::cout << " [-password=senha] <Descricao aqui>\n"; | ||
32 | + std::cout << " <-help> <Descricao aqui>\n"; | ||
33 | + } | ||
34 | + | ||
35 | + emit finished(); | ||
7 | } | 36 | } |
8 | 37 | ||
9 | -void InstallCacic::run() { | ||
10 | - int code; | ||
11 | - std::cout << "Hello World\n"; | ||
12 | - std::cin >> code; | ||
13 | - emit finished(code); | 38 | +QMap<QString, QString> InstallCacic::validaParametros(QStringList argv, int argc, bool *ok) |
39 | +{ | ||
40 | + QMap<QString, QString> map; | ||
41 | + for (int i = 0; i<argc; i++){ | ||
42 | + QString aux = argv[i]; | ||
43 | + QStringList auxList = aux.split("="); | ||
44 | + if ((auxList.at(0).at(0) == '-') && (auxList.size() > 1)) | ||
45 | + map[auxList.at(0).mid(1)] = auxList.at(1); | ||
46 | + } | ||
47 | + *ok = (bool) map.contains("host") && map.contains("user") && map.contains("password"); | ||
48 | + if (*ok){ | ||
49 | + this->argumentos = map; | ||
50 | + } | ||
51 | + return map; | ||
52 | +} | ||
53 | + | ||
54 | +QMap<QString, QString> InstallCacic::getArgumentos() | ||
55 | +{ | ||
56 | + return argumentos; | ||
57 | +} | ||
58 | + | ||
59 | +void InstallCacic::setArgumentos(QMap<QString, QString> value) | ||
60 | +{ | ||
61 | + this->argumentos = value; | ||
14 | } | 62 | } |
15 | 63 | ||
16 | 64 |
install-cacic/installcacic.h
@@ -2,6 +2,10 @@ | @@ -2,6 +2,10 @@ | ||
2 | #define INSTALLCACIC_H | 2 | #define INSTALLCACIC_H |
3 | 3 | ||
4 | #include <QObject> | 4 | #include <QObject> |
5 | +#include <QtCore> | ||
6 | +#include <cacic_comm.h> | ||
7 | +#include <cacic_computer.h> | ||
8 | +#include <ccacic.h> | ||
5 | 9 | ||
6 | class InstallCacic : public QObject | 10 | class InstallCacic : public QObject |
7 | { | 11 | { |
@@ -9,13 +13,20 @@ class InstallCacic : public QObject | @@ -9,13 +13,20 @@ class InstallCacic : public QObject | ||
9 | public: | 13 | public: |
10 | explicit InstallCacic(QObject *parent = 0); | 14 | explicit InstallCacic(QObject *parent = 0); |
11 | 15 | ||
12 | -private: | 16 | + QMap<QString, QString> getArgumentos(); |
17 | + void setArgumentos(QMap<QString, QString> value); | ||
18 | + QMap<QString, QString> validaParametros(QStringList argv, int argc, bool *ok); | ||
13 | 19 | ||
20 | +private: | ||
21 | + QMap<QString, QString> argumentos; | ||
22 | + CacicComm oCacicComm; | ||
23 | + CACIC_Computer oCacicComputer; | ||
24 | + CCacic oCacic; | ||
14 | signals: | 25 | signals: |
15 | - void finished(int); | 26 | + void finished(); |
16 | 27 | ||
17 | public slots: | 28 | public slots: |
18 | - void run(); | 29 | + void run(QStringList argv, int argc); |
19 | }; | 30 | }; |
20 | 31 | ||
21 | #endif // INSTALLCACIC_H | 32 | #endif // INSTALLCACIC_H |
install-cacic/main.cpp
@@ -5,15 +5,16 @@ | @@ -5,15 +5,16 @@ | ||
5 | int main(int argc, char *argv[]) | 5 | int main(int argc, char *argv[]) |
6 | { | 6 | { |
7 | QCoreApplication a(argc, argv); | 7 | QCoreApplication a(argc, argv); |
8 | - | 8 | + QStringList args; |
9 | + for (int i = 0; i<argc; i++) | ||
10 | + args.append(argv[i]); | ||
9 | InstallCacic *installcacic = new InstallCacic(&a); | 11 | InstallCacic *installcacic = new InstallCacic(&a); |
10 | 12 | ||
11 | // This will cause the application to exit when | 13 | // This will cause the application to exit when |
12 | // the task signals finished. | 14 | // the task signals finished. |
13 | - QObject::connect(installcacic, SIGNAL(finished(int)), &a, SLOT(quit())); | 15 | + QObject::connect(installcacic, SIGNAL(finished()), &a, SLOT(quit())); |
14 | 16 | ||
15 | // This will run the task from the application event loop. | 17 | // This will run the task from the application event loop. |
16 | - QTimer::singleShot(0, installcacic, SLOT(run())); | ||
17 | - | 18 | + QMetaObject::invokeMethod(installcacic, "run", Qt::QueuedConnection, Q_ARG(QStringList, args), Q_ARG(int, argc)); |
18 | return a.exec(); | 19 | return a.exec(); |
19 | } | 20 | } |
src/cacic_comm.h
@@ -26,7 +26,6 @@ private: | @@ -26,7 +26,6 @@ private: | ||
26 | 26 | ||
27 | public: | 27 | public: |
28 | CacicComm (){ | 28 | CacicComm (){ |
29 | - | ||
30 | } | 29 | } |
31 | 30 | ||
32 | CacicComm (QString urlGerente, QString operatingSystem, QString computerSystem, QString csCipher, | 31 | CacicComm (QString urlGerente, QString operatingSystem, QString computerSystem, QString csCipher, |
@@ -53,15 +52,16 @@ public: | @@ -53,15 +52,16 @@ public: | ||
53 | 52 | ||
54 | } | 53 | } |
55 | 54 | ||
56 | - QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false) | 55 | + QJsonObject comm(QString route, bool *ok, const QJsonObject &json = QJsonObject(), bool isSsl = false) |
57 | { | 56 | { |
57 | + *ok = false; | ||
58 | QByteArray data; | 58 | QByteArray data; |
59 | QNetworkRequest req; | 59 | QNetworkRequest req; |
60 | QUrl url; | 60 | QUrl url; |
61 | QString strReply; | 61 | QString strReply; |
62 | QJsonObject jsonObj; | 62 | QJsonObject jsonObj; |
63 | if (isSsl){ | 63 | if (isSsl){ |
64 | - url = urlSsl + route; | 64 | + url = urlSsl.isEmpty() ? "https://" + this->urlGerente + route : this->urlSsl + route; |
65 | req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); | 65 | req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); |
66 | } else | 66 | } else |
67 | url = urlGerente + route; | 67 | url = urlGerente + route; |
@@ -106,7 +106,7 @@ public: | @@ -106,7 +106,7 @@ public: | ||
106 | QJsonValue::fromVariant(replyVariant.toString()); | 106 | QJsonValue::fromVariant(replyVariant.toString()); |
107 | // qDebug() << "Response:" << jsonObj["reply"]; | 107 | // qDebug() << "Response:" << jsonObj["reply"]; |
108 | // qDebug() << "Response:" << strReply; | 108 | // qDebug() << "Response:" << strReply; |
109 | - | 109 | + *ok = true; |
110 | delete reply; | 110 | delete reply; |
111 | } else { | 111 | } else { |
112 | //failure | 112 | //failure |
@@ -156,14 +156,16 @@ public: | @@ -156,14 +156,16 @@ public: | ||
156 | * @return retorna json com sessão e chave de criptografia | 156 | * @return retorna json com sessão e chave de criptografia |
157 | * exemplo: 200 OK | 157 | * exemplo: 200 OK |
158 | */ | 158 | */ |
159 | - QJsonObject login() { | 159 | + QJsonObject login(bool *ok) { |
160 | + *ok = false; | ||
160 | // Cria dados de login | 161 | // Cria dados de login |
161 | QVariantMap login; | 162 | QVariantMap login; |
162 | login["user"] = this->usuario; | 163 | login["user"] = this->usuario; |
163 | login["password"] = this->password; | 164 | login["password"] = this->password; |
164 | // QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); | 165 | // QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); |
165 | // Cria conexão e retorna Json da sessão | 166 | // Cria conexão e retorna Json da sessão |
166 | - QJsonObject retorno = this->comm("/ws/neo/login", QJsonObject::fromVariantMap(login), true); | 167 | +// qDebug() << "Conectando."; |
168 | + QJsonObject retorno = this->comm("/ws/neo/login", ok, QJsonObject::fromVariantMap(login), true); | ||
167 | return retorno; | 169 | return retorno; |
168 | } | 170 | } |
169 | 171 | ||
@@ -175,6 +177,22 @@ public: | @@ -175,6 +177,22 @@ public: | ||
175 | this->urlSsl = value; | 177 | this->urlSsl = value; |
176 | } | 178 | } |
177 | 179 | ||
180 | + QString getUrlGerente (){ | ||
181 | + return this->urlGerente; | ||
182 | + } | ||
183 | + | ||
184 | + void setUrlGerente(QString value){ | ||
185 | + if (value.contains("http://", Qt::CaseInsensitive)){ | ||
186 | + value = value.mid(value.indexOf("http://") + 7); | ||
187 | + } else if (value.contains("https://", Qt::CaseInsensitive)){ | ||
188 | + value = value.mid(value.indexOf("https://") + 8); | ||
189 | + } | ||
190 | + if (value.endsWith("/")){ | ||
191 | + value.remove(value.size()-1, 1); | ||
192 | + } | ||
193 | + this->urlGerente = value; | ||
194 | + } | ||
195 | + | ||
178 | QString getPassword() | 196 | QString getPassword() |
179 | { | 197 | { |
180 | return this->password; | 198 | return this->password; |
src/ccacic.cpp
@@ -137,15 +137,15 @@ std::string CCacic::enCrypt(std::string str_in, std::string key, std::string iv) | @@ -137,15 +137,15 @@ std::string CCacic::enCrypt(std::string str_in, std::string key, std::string iv) | ||
137 | } | 137 | } |
138 | 138 | ||
139 | /*deCrypt | 139 | /*deCrypt |
140 | - * @parameter std::string str_in: string encriptada convertida em base64. | ||
141 | - * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits | ||
142 | - * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty | ||
143 | - * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. | ||
144 | - * *Um IV jamais deve ser utilizado mais de uma vez com a mesma chave. | ||
145 | - * *(http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) | ||
146 | - * *exemplo de iv: 0123456789123456 | ||
147 | - * @return QString: retorna a string desencriptada convertida em base64. | ||
148 | - * */ | 140 | +// * @parameter std::string str_in: string encriptada convertida em base64. |
141 | +// * std::string key: chave utilizada na encriptação (32 caracteres) 32*8 = 256 bits | ||
142 | +// * *exemplo: qwertyuiopasdfghjklzxcvbnmqwerty | ||
143 | +// * std::string iv: IV (Vetor de Inicialização) deve ser aleatório. | ||
144 | +// * *Um IV jamais deve ser utilizado mais de uma vez com a mesma chave. | ||
145 | +// * *(http://pt.wikipedia.org/wiki/Modo_de_opera%C3%A7%C3%A3o_%28criptografia%29#Vetor_de_inicializa.C3.A7.C3.A3o_.28IV.29) | ||
146 | +// * *exemplo de iv: 0123456789123456 | ||
147 | +// * @return QString: retorna a string desencriptada convertida em base64. | ||
148 | +// * */ | ||
149 | std::string CCacic::deCrypt(std::string str_in, std::string key, std::string iv) { | 149 | std::string CCacic::deCrypt(std::string str_in, std::string key, std::string iv) { |
150 | std::string str_out; | 150 | std::string str_out; |
151 | CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); | 151 | CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); |
src/ccacic.h
@@ -4,19 +4,19 @@ | @@ -4,19 +4,19 @@ | ||
4 | #include <QCoreApplication> | 4 | #include <QCoreApplication> |
5 | #include <QObject> | 5 | #include <QObject> |
6 | #include <QFile> | 6 | #include <QFile> |
7 | -#include <aes.h> | ||
8 | -#include <base64.h> | ||
9 | -#include <modes.h> | ||
10 | -#include <filters.h> | ||
11 | -#include <hex.h> | ||
12 | -#include <sha.h> | ||
13 | -#include <md5.h> | ||
14 | #include <QSettings> | 7 | #include <QSettings> |
15 | #include <QDir> | 8 | #include <QDir> |
16 | #include <QDebug> | 9 | #include <QDebug> |
17 | #include <QJsonDocument> | 10 | #include <QJsonDocument> |
18 | #include <QJsonObject> | 11 | #include <QJsonObject> |
19 | #include <QJsonValue> | 12 | #include <QJsonValue> |
13 | +#include <aes.h> | ||
14 | +#include <base64.h> | ||
15 | +#include <modes.h> | ||
16 | +//#include <filters.h> | ||
17 | +//#include <hex.h> | ||
18 | +//#include <sha.h> | ||
19 | +//#include <md5.h> | ||
20 | 20 | ||
21 | class CCacic : public QObject | 21 | class CCacic : public QObject |
22 | { | 22 | { |