First version of ATBUpdateCheck
This commit is contained in:
114
Check/main.cpp
114
Check/main.cpp
@@ -9,8 +9,18 @@
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
#include "commandline_parser.h"
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QRegularExpression>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "message_handler.h"
|
||||
#include "ismas_client.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QByteArray const value = qgetenv("LC_ALL");
|
||||
@@ -18,9 +28,6 @@ int main(int argc, char **argv) {
|
||||
qputenv("LC_ALL", "C");
|
||||
}
|
||||
|
||||
|
||||
// qputenv("XDG_RUNTIME_DIR", "/var/run/user/0");
|
||||
|
||||
openlog("ATB-UPDATE_CHECK", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER);
|
||||
|
||||
QCoreApplication a(argc, argv);
|
||||
@@ -36,15 +43,106 @@ int main(int argc, char **argv) {
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption ismasConnectOption("ismas-connected");
|
||||
QCommandLineOption updateRequestedOption("update-requested");
|
||||
QCommandLineOption verboseOption("verbose");
|
||||
parser.addOption(ismasConnectOption);
|
||||
parser.addOption(updateRequestedOption);
|
||||
parser.addOption(verboseOption);
|
||||
parser.process(a);
|
||||
|
||||
if (parser.isSet(ismasConnectOption)) {
|
||||
qCritical() << parser.isSet(ismasConnectOption);
|
||||
} else
|
||||
QString connectionStatus{"not connected"};
|
||||
QString updateRequestStatus{"not requested"};
|
||||
|
||||
if (std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DIRECT_PORT,
|
||||
"#M=APISM#C=REQ_SELF#J={}")) {
|
||||
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
|
||||
for (QString const &k : d.object().keys()) {
|
||||
if (k.contains("CMD_GET_APISMSTATUS_RESPONSE")) {
|
||||
QJsonObject o = d.object()[k].toObject();
|
||||
QJsonObject::const_iterator it = o.find("Broker");
|
||||
if (it != o.constEnd()) {
|
||||
// value for "Broker"
|
||||
QString const &v = it->toString();
|
||||
if (v.contains("connected", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "connected";
|
||||
} else
|
||||
if (v.contains("not connected", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
} else
|
||||
if (v.contains("disconnected", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
} else
|
||||
if (v.contains("connecting", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
} else
|
||||
if (v.contains("disconnecting", Qt::CaseInsensitive)) {
|
||||
connectionStatus = "not connected";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parser.isSet(updateRequestedOption)) {
|
||||
qCritical() << parser.isSet(updateRequestedOption);
|
||||
if (connectionStatus == "connected") {
|
||||
if (std::optional<QString> result
|
||||
= IsmasClient::sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DIRECT_PORT,
|
||||
"#M=APISM#C=REQ_ISMASPARAMETER#J={}")) {
|
||||
|
||||
QJsonDocument d = QJsonDocument::fromJson(result.value().toUtf8());
|
||||
for (QString const &k : d.object().keys()) {
|
||||
if (k.contains("REQ_ISMASPARAMETER")) {
|
||||
QJsonObject o = d.object()[k].toObject();
|
||||
|
||||
QJsonObject::const_iterator it = o.find("Aknoledge");
|
||||
if (it == o.constEnd()) continue;
|
||||
|
||||
QString const &v = it->toString();
|
||||
if (v != "OK") break;
|
||||
|
||||
for (QString const &k : d.object().keys()) { // request ack
|
||||
if (!k.contains("FileUpload", Qt::CaseInsensitive)) continue;
|
||||
QJsonObject o = d.object()[k].toObject();
|
||||
|
||||
QJsonObject::const_iterator it = o.find("TRG");
|
||||
if (it == o.constEnd()) break;
|
||||
|
||||
QString const &v = it->toString();
|
||||
if (v == "WAIT") {
|
||||
updateRequestStatus = "requested";
|
||||
} else
|
||||
if (v.isEmpty()) {
|
||||
QFile f("/mnt/system_data/cust_nr");
|
||||
if (!f.exists()) break;
|
||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) break;
|
||||
|
||||
QTextStream in(&f);
|
||||
in.setCodec("UTF-8");
|
||||
if(!in.atEnd()) {
|
||||
unsigned custNr = in.readLine().toInt();
|
||||
if (custNr > 0) {
|
||||
QString custRepo = QString("/opt/app/tools/atbupdate/customer_%1").arg(custNr);
|
||||
if (!QDir(custRepo).exists()) {
|
||||
updateRequestStatus = "not necessary";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qCritical() << updateRequestStatus;
|
||||
}
|
||||
|
||||
if (parser.isSet(ismasConnectOption)) {
|
||||
qCritical() << connectionStatus;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user