компилируемая версия веб-сервера, находится на стадии отладки
This commit is contained in:
152
src/main.cpp
152
src/main.cpp
@@ -104,6 +104,8 @@ public:
|
||||
static constexpr const char* INDEX_HTML = "/main-tdma.html";
|
||||
#elif defined(MODEM_IS_SCPC)
|
||||
static constexpr const char* INDEX_HTML = "/main-scpc.html";
|
||||
#elif defined(MODEM_IS_SHPS)
|
||||
static constexpr const char* INDEX_HTML = "/main-shps.html";
|
||||
#else
|
||||
#error "Modem type not defined!"
|
||||
#endif
|
||||
@@ -179,7 +181,7 @@ public:
|
||||
try {
|
||||
auto reqJson = nlohmann::json::parse(std::string(req.payload.begin(), req.payload.end()));
|
||||
|
||||
auto u = auth.doAuth(reqJson["username"], reqJson["username"], req, rep);
|
||||
auto u = auth.doAuth(reqJson["username"], reqJson["password"], req, rep);
|
||||
if (u == nullptr) {
|
||||
throw std::runtime_error("invalid session");
|
||||
}
|
||||
@@ -217,10 +219,21 @@ public:
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
return;
|
||||
}
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
const auto result = api->loadTerminalState();
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["state"] = api->loadTerminalState();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/qos): Can't set QoS settings: " << e.what();
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
|
||||
@@ -229,12 +242,22 @@ public:
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
return;
|
||||
}
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
std::string result = R"({"settings":)";
|
||||
result += api->loadSettings();
|
||||
result += "}";
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["settings"] = api->loadSettings();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/get/settings): Can't get object: " << e.what();
|
||||
resultJson.clear();
|
||||
rep.status = http::server::internal_server_error;
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
|
||||
@@ -246,7 +269,20 @@ public:
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
const auto result = api->loadFirmwareVersion();
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["firmware"] = api->loadFirmwareVersion();
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/get/aboutFirmware): Can't get object: " << e.what();
|
||||
resultJson.clear();
|
||||
rep.status = http::server::internal_server_error;
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
|
||||
@@ -451,7 +487,13 @@ public:
|
||||
http::server::stockReply(http::server::bad_request, rep);
|
||||
return;
|
||||
}
|
||||
this->upgradeOrRebootRunning = true;
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
this->upgradeOrRebootRunning = true;
|
||||
#ifdef MODEM_IS_TDMA
|
||||
if (req.url->params.find("ota") != req.url->params.end()) {
|
||||
doTerminalUpgradeOta();
|
||||
@@ -461,10 +503,15 @@ public:
|
||||
#else
|
||||
doTerminalUpgrade();
|
||||
#endif
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.clear();
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
const auto result = api->loadFirmwareVersion();
|
||||
resultJson["status"] = "ok";
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/doFirmwareUpgrade): Error: " << e.what();
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
|
||||
@@ -483,28 +530,67 @@ public:
|
||||
return;
|
||||
}
|
||||
const auto func = req.url->params["f"];
|
||||
std::string result = R"({"status":"ok"})";
|
||||
if (func == "SetDmaDebug") {
|
||||
if (req.url->params.find("param") == req.url->params.end()) { http::server::stockReply(http::server::bad_request, rep); return; }
|
||||
if (req.url->params.find("value") == req.url->params.end()) { http::server::stockReply(http::server::bad_request, rep); return; }
|
||||
this->api->executeInApi([&](auto& cp) {
|
||||
cp.setDmaDebug(req.url->params["param"], req.url->params["value"]);
|
||||
});
|
||||
} else if (func == "GetDmaDebug") {
|
||||
if (req.url->params.find("param") == req.url->params.end()) { http::server::stockReply(http::server::bad_request, rep); return; }
|
||||
this->api->executeInApi([&](auto& cp) {
|
||||
nlohmann::json tmp;
|
||||
tmp["status"] = "ok";
|
||||
tmp["result"] = cp.getDmaDebug(req.url->params["param"]);
|
||||
result = tmp.dump();
|
||||
});
|
||||
} else {
|
||||
http::server::stockReply(http::server::not_implemented, rep);
|
||||
return;
|
||||
}
|
||||
|
||||
rep.status = http::server::ok;
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||
nlohmann::json resultJson;
|
||||
|
||||
try {
|
||||
resultJson["status"] = "error";
|
||||
if (func == "SetDmaDebug") {
|
||||
if (req.url->params.find("param") == req.url->params.end()) {
|
||||
rep.status = http::server::bad_request;
|
||||
resultJson["error"] = "missing required adgument: `param`";
|
||||
} else if (req.url->params.find("value") == req.url->params.end()) {
|
||||
rep.status = http::server::bad_request;
|
||||
resultJson["error"] = "missing required adgument: `value`";
|
||||
} else {
|
||||
this->api->executeInApi([&](auto& cp) {
|
||||
cp.setDmaDebug(req.url->params["param"], req.url->params["value"]);
|
||||
});
|
||||
}
|
||||
} else if (func == "GetDmaDebug") {
|
||||
if (req.url->params.find("param") == req.url->params.end()) {
|
||||
rep.status = http::server::bad_request;
|
||||
resultJson["error"] = "missing required adgument: `param`";
|
||||
} else {
|
||||
this->api->executeInApi([&](auto& cp) {
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["result"] = cp.getDmaDebug(req.url->params["param"]);
|
||||
});
|
||||
}
|
||||
} else if (func == "SetNetwork") {
|
||||
if (req.url->params.find("param") == req.url->params.end()) {
|
||||
rep.status = http::server::bad_request;
|
||||
resultJson["error"] = "missing required adgument: `param`";
|
||||
} else if (req.url->params.find("value") == req.url->params.end()) {
|
||||
rep.status = http::server::bad_request;
|
||||
resultJson["error"] = "missing required adgument: `value`";
|
||||
} else {
|
||||
this->api->executeInApi([&](auto& cp) {
|
||||
cp.setNetwork(req.url->params["param"], req.url->params["value"]);
|
||||
});
|
||||
}
|
||||
} else if (func == "GetNetwork") {
|
||||
if (req.url->params.find("param") == req.url->params.end()) {
|
||||
rep.status = http::server::bad_request;
|
||||
resultJson["error"] = "missing required adgument: `param`";
|
||||
} else {
|
||||
this->api->executeInApi([&](auto& cp) {
|
||||
resultJson["status"] = "ok";
|
||||
resultJson["result"] = cp.getNetwork(req.url->params["param"]);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
resultJson["error"] = "function not supported";
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/qos): Can't set QoS settings: " << e.what();
|
||||
resultJson.clear();
|
||||
resultJson["status"] = "error";
|
||||
resultJson["error"] = e.what();
|
||||
}
|
||||
|
||||
auto result = resultJson.dump();
|
||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||
}));
|
||||
#ifdef API_OBJECT_DEBUG_METRICS_ENABLE
|
||||
|
||||
Reference in New Issue
Block a user