Commit f0cbb68ecc7b6943e122a878208f5717a90d443b

Authored by Eric Menezes Noronha
1 parent 621ddcc0
Exists in master

-Adicionado pathDownload nos métodos de download, pra salvar onde desejar;

-Alterado variável password para pass nos argumentos do installcacic;
-Sendo possível pegar o nome do computador agora;
-Versão ainda sendo pega com código fixo, deve ser arrumada;
-Alterado variáveis da coleta do linux retirando o "_", pra ficar padrão.
cacic-daemon/cacicD/cacicd.cpp
... ... @@ -4,7 +4,6 @@ cacicD::cacicD(int argc, char **argv) : QtService<QCoreApplication>(argc, argv,
4 4 {
5 5 try{
6 6 this->createApplication(argc, argv);
7   -
8 7 Ocacictimer = new CacicTimer(application()->applicationDirPath());
9 8 ccacic = new CCacic;
10 9 setServiceDescription("Cacic Daemon");
... ...
cacic-daemon/cacicD/cacicd.h
... ... @@ -6,6 +6,7 @@
6 6 #include "cacictimer.h"
7 7 #include "QLogger.h"
8 8  
  9 +#define APP_VERSION "3.0"
9 10  
10 11 class cacicD : public QtService<QCoreApplication>
11 12 {
... ...
cacic-teste/testcacic.cpp
... ... @@ -323,7 +323,7 @@ void CTestCacic::testLogger()
323 323  
324 324 void CTestCacic::testFtpDownload()
325 325 {
326   - OCacicComm->ftpDownload("ftp://ftp.unicamp.br", "/pub/gnu/Licenses/gpl-2.0.txt");
  326 + OCacicComm->ftpDownload("ftp://ftp.unicamp.br", "/pub/gnu/Licenses/gpl-2.0.txt", "");
327 327 QFile downloaded("gpl-2.0.txt");
328 328  
329 329 QVERIFY( downloaded.open(QIODevice::ReadOnly) );
... ...
install-cacic/installcacic.cpp
... ... @@ -25,7 +25,7 @@ void InstallCacic::run(QStringList argv, int argc) {
25 25 if (ok){
26 26 oCacicComm->setUrlGerente(this->argumentos["host"]);
27 27 oCacicComm->setUsuario(this->argumentos["user"]);
28   - oCacicComm->setPassword(this->argumentos["password"]);
  28 + oCacicComm->setPassword(this->argumentos["pass"]);
29 29 QJsonObject jsonLogin = oCacicComm->login(&ok);
30 30 if (ok){
31 31 QJsonObject jsonComm;
... ... @@ -57,14 +57,14 @@ void InstallCacic::run(QStringList argv, int argc) {
57 57  
58 58 //TO DO: Fazer download do serviço
59 59 #ifdef Q_OS_WIN
60   - oCacicComm->ftpDownload("agentes/cacic-service.exe");
  60 + oCacicComm->ftpDownload("agentes/cacic-service.exe", oCacic.getCacicMainFolder());
61 61  
62 62 QString exitStatus = oCacic.startProcess(oCacic.getCacicMainFolder() + "cacic-service.exe",
63 63 false,
64 64 &ok,
65 65 QStringList("-install");
66 66 #else
67   - oCacicComm->ftpDownload("agentes/cacic-service");
  67 + oCacicComm->ftpDownload("agentes/cacic-service", oCacic.getCacicMainFolder());
68 68  
69 69 QJsonObject configsJson = configs["reply"].toObject();
70 70 QString senhaAgente;
... ... @@ -86,15 +86,15 @@ void InstallCacic::run(QStringList argv, int argc) {
86 86 std::cout << "Erro ao iniciar o processo: "
87 87 << exitStatus.toStdString() << "\n";
88 88 else {
89   - std::cout << "Instalação realizada com sucesso.";
  89 + std::cout << "Instalação realizada com sucesso." << "\n";
90 90 }
91 91 } else {
92   - std::cout << "Falha ao pegar configurações: " << configs["error"].toString().toStdString();
  92 + std::cout << "Falha ao pegar configurações: " << configs["error"].toString().toStdString() << "\n";
93 93 }
94 94  
95 95 } else
96 96 std::cout << "Nao foi possivel realizar o login.\n "
97   - << jsonLogin["error"].toString().toStdString();
  97 + << jsonLogin["error"].toString().toStdString() << "\n";
98 98 } else if ((param.contains("default")) && (param["default"] == "uninstall")){
99 99 oCacic.deleteFolder("c:/cacic");
100 100 oCacic.removeRegistry("Lightbase", "Cacic");
... ... @@ -105,7 +105,7 @@ void InstallCacic::run(QStringList argv, int argc) {
105 105 << "<-host=url_gerente> <-user=usuario> <-password=senha> [-help]\n\n"
106 106 << " <-host=url_gerente> url_gerente: Caminho para a aplicação do gerente.\n"
107 107 << " <-user=usuario> usuario: usuário de login no gerente.\n"
108   - << " <-password=senha> senha: senha de login no gerente\n"
  108 + << " <-pass=senha> senha: senha de login no gerente\n"
109 109 << " [-help] Lista todos comandos.\n";
110 110 }
111 111  
... ... @@ -124,7 +124,7 @@ QMap&lt;QString, QString&gt; InstallCacic::validaParametros(QStringList argv, int argc
124 124 else if (aux.at(0)== '-')
125 125 map["default"] = aux.mid(1);
126 126 }
127   - *ok = (bool) map.contains("host") && map.contains("user") && map.contains("password");
  127 + *ok = (bool) map.contains("host") && map.contains("user") && map.contains("pass");
128 128 if (*ok){
129 129 this->argumentos = map;
130 130 }
... ...
src/cacic_comm.cpp
... ... @@ -139,7 +139,7 @@ QJsonObject CacicComm::login(bool *ok) {
139 139 * Faz o download de um arquivo usando o protocolo mode
140 140 * a partir da url do gerente e do caminho até o arquivo.
141 141 */
142   -bool CacicComm::fileDownload(const QString &mode, const QString &path){
  142 +bool CacicComm::fileDownload(const QString &mode, const QString &path, const QString &pathDownload){
143 143 QEventLoop eventLoop;
144 144 QNetworkAccessManager manager;
145 145 QNetworkRequest request;
... ... @@ -150,7 +150,7 @@ bool CacicComm::fileDownload(const QString &amp;mode, const QString &amp;path){
150 150  
151 151 QStringList splitPath = path.split("/");
152 152  
153   - fileHandler = new QFile(splitPath[splitPath.size() - 1]);
  153 + fileHandler = new QFile(pathDownload + splitPath[splitPath.size() - 1]);
154 154 if( !fileHandler->open(QIODevice::WriteOnly) ) {
155 155 qDebug() << "ftpDownload: fileHandler nâo pode abrir arquivo.";
156 156 return false;
... ... @@ -176,7 +176,7 @@ bool CacicComm::fileDownload(const QString &amp;mode, const QString &amp;path){
176 176 * Faz o download de um arquivo usando o protocolo mode
177 177 * a partir da url recebida e do caminho até o arquivo.
178 178 */
179   -bool CacicComm::fileDownload(const QString &mode, const QString &urlServer, const QString &path){
  179 +bool CacicComm::fileDownload(const QString &mode, const QString &urlServer, const QString &path, const QString &pathDownload){
180 180 QEventLoop eventLoop;
181 181 QNetworkAccessManager manager;
182 182 QNetworkRequest request;
... ... @@ -187,7 +187,7 @@ bool CacicComm::fileDownload(const QString &amp;mode, const QString &amp;urlServer, cons
187 187  
188 188 QStringList splitPath = path.split("/");
189 189  
190   - fileHandler = new QFile(splitPath[splitPath.size() - 1]);
  190 + fileHandler = new QFile(pathDownload + splitPath[splitPath.size() - 1]);
191 191 if( !fileHandler->open(QIODevice::WriteOnly) ) {
192 192 qDebug() << "ftpDownload: fileHandler nâo pode abrir arquivo.";
193 193 return false;
... ... @@ -208,20 +208,20 @@ bool CacicComm::fileDownload(const QString &amp;mode, const QString &amp;urlServer, cons
208 208 return true;
209 209 }
210 210  
211   -bool CacicComm::ftpDownload( const QString &path ){
212   - return fileDownload("ftp", path);
  211 +bool CacicComm::ftpDownload( const QString &path, const QString &pathDownload ){
  212 + return fileDownload("ftp", path, pathDownload);
213 213 }
214 214  
215   -bool CacicComm::ftpDownload( const QString &urlServer, const QString &path ){
216   - return fileDownload("ftp", urlServer, path);
  215 +bool CacicComm::ftpDownload( const QString &urlServer, const QString &path, const QString &pathDownload ){
  216 + return fileDownload("ftp", urlServer, path, pathDownload);
217 217 }
218 218  
219   -bool CacicComm::httpDownload( const QString &path ){
220   - return fileDownload("http", path);
  219 +bool CacicComm::httpDownload( const QString &path, const QString &pathDownload ){
  220 + return fileDownload("http", path, pathDownload);
221 221 }
222 222  
223   -bool CacicComm::httpDownload( const QString &urlServer, const QString &path ){
224   - return fileDownload("http", urlServer, path);
  223 +bool CacicComm::httpDownload( const QString &urlServer, const QString &path,const QString &pathDownload ){
  224 + return fileDownload("http", urlServer, path, pathDownload);
225 225 }
226 226  
227 227 QString CacicComm::getUrlSsl (){
... ...
src/cacic_comm.h
... ... @@ -27,10 +27,10 @@ public:
27 27 QJsonObject comm(QString route, bool *ok, const QJsonObject &json = QJsonObject(), bool isSsl = false);
28 28 bool commStatus();
29 29 QJsonObject login(bool *ok);
30   - bool ftpDownload(const QString &path);
31   - bool ftpDownload(const QString &urlServer, const QString &path);
32   - bool httpDownload(const QString &path);
33   - bool httpDownload(const QString &urlServer, const QString &path);
  30 + bool ftpDownload(const QString &path, const QString &pathDownload);
  31 + bool ftpDownload(const QString &urlServer, const QString &path, const QString &pathDownload);
  32 + bool httpDownload(const QString &path, const QString &pathDownload);
  33 + bool httpDownload(const QString &urlServer, const QString &path,const QString &pathDownload);
34 34 QString getUrlSsl ();
35 35 void setUrlSsl(QString value);
36 36 QString getUrlGerente ();
... ... @@ -51,8 +51,8 @@ private slots:
51 51  
52 52 private:
53 53  
54   - bool fileDownload(const QString &mode, const QString &path);
55   - bool fileDownload(const QString &mode, const QString &urlServer, const QString &path);
  54 + bool fileDownload(const QString &mode, const QString &path, const QString &pathDownload);
  55 + bool fileDownload(const QString &mode, const QString &urlServer, const QString &path, const QString &pathDownload);
56 56  
57 57 QUrlQuery params;
58 58 QString urlGerente;
... ...
src/cacic_computer.cpp
... ... @@ -2,8 +2,12 @@
2 2  
3 3 CACIC_Computer::CACIC_Computer()
4 4 {
  5 + struct utsname sysName;
  6 + uname(&sysName);
5 7 networkInterface = networkInterfacesRunning();
6 8 usuario = pegarUsu();
  9 + computerName = sysName.nodename;
  10 +// qDebug() << sysName.nodename << sysName.machine << sysName.sysname << sysName.release << sysName.version;
7 11 }
8 12  
9 13 /*NetworkInterfacesRunning
... ... @@ -53,8 +57,8 @@ QJsonObject CACIC_Computer::toJsonObject()
53 57 count++;
54 58 }
55 59 json["networkDevices"] = network;
56   - json["nmComputador"] = QJsonValue::fromVariant(QString("TODO"));
57   - json["versaoAgente"] = QJsonValue::fromVariant(QString("TODO"));
  60 + json["nmComputador"] = QJsonValue::fromVariant(QString::fromStdString(this->computerName));
  61 + json["versaoAgente"] = QJsonValue::fromVariant(QString("3.0 (manual)"));
58 62 return json;
59 63 }
60 64  
... ...
src/cacic_computer.h
... ... @@ -9,6 +9,7 @@
9 9 #include <QSysInfo>
10 10 #include "operatingsystem.h"
11 11 #include "console.h"
  12 +#include <sys/utsname.h>
12 13  
13 14 class CACIC_Computer
14 15 {
... ... @@ -31,6 +32,7 @@ private:
31 32  
32 33 QList<QVariantMap> networkInterface;
33 34 std::string usuario;
  35 + std::string computerName;
34 36  
35 37 };
36 38  
... ...
src/cacic_hardware.cpp
... ... @@ -375,11 +375,11 @@ void cacic_hardware::coletaLinuxBios(QJsonObject &amp;hardware)
375 375 } else if(line.contains("Version:")){
376 376 bios["version"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
377 377 } else if(line.contains("Release Date:")){
378   - bios["release_date"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
  378 + bios["releaseDate"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
379 379 } else if(line.contains("Runtime Size:")){
380   - bios["runtime_size"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
  380 + bios["runtimeSize"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
381 381 } else if(line.contains("ROM Size:")){
382   - bios["rom_size"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
  382 + bios["romSize"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
383 383 } else if(line.contains("BIOS Revision:")){
384 384 bios["revision"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
385 385 }
... ... @@ -399,13 +399,13 @@ void cacic_hardware::coletaLinuxMotherboard(QJsonObject &amp;hardware)
399 399 if(line.contains("Manufacturer:") ){
400 400 motherboard["manufacturer"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
401 401 } else if(line.contains("Product Name:")){
402   - motherboard["product_name"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
  402 + motherboard["productName"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
403 403 } else if(line.contains("Version:")){
404 404 motherboard["version"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
405 405 } else if(line.contains("Asset Tag:")){
406   - motherboard["asset_tag"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
  406 + motherboard["assetTag"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
407 407 } else if(line.contains("Serial Number:")){
408   - motherboard["serial_number"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
  408 + motherboard["serialNumber"] = QJsonValue::fromVariant( QString(line.split(":")[1].mid(1)) );
409 409 }
410 410 }
411 411  
... ... @@ -419,7 +419,7 @@ void cacic_hardware::coletaLinuxMotherboard(QJsonObject &amp;hardware)
419 419  
420 420 }
421 421  
422   - motherboard["onboard_capabilities"] = QJsonValue::fromVariant(onboardCapabilities);
  422 + motherboard["onboardCapabilities"] = QJsonValue::fromVariant(onboardCapabilities);
423 423  
424 424 hardware["motherboard"] = motherboard;
425 425 }
... ... @@ -433,8 +433,8 @@ void cacic_hardware::coletaLinuxIsNotebook(QJsonObject &amp;hardware)
433 433 // qDebug() << consoleOutput;
434 434 foreach(QString line, consoleOutput){
435 435 if(line.contains("Type:")
436   - && line.contains("Notebook") ){
437   - hardware["is_notebook"] = QJsonValue::fromVariant(QString("true"));
  436 + && (line.contains("Notebook") || line.contains("Portable")) ){
  437 + hardware["isNotebook"] = QJsonValue::fromVariant(QString("true"));
438 438 }
439 439 }
440 440  
... ...