кучка мелких фиксов + добавление перезагрузки модема и сброса настроек

This commit is contained in:
2024-11-14 16:42:24 +03:00
parent 6d076f03cd
commit ccc7766e88
5 changed files with 58 additions and 11 deletions

View File

@@ -24,6 +24,9 @@
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
constexpr const char* REBOOT_COMMAND = "web-action reboot";
constexpr const char* UPGRADE_COMMAND = "web-action upgrade";
static std::vector<char> loadFile(const std::string& path) {
std::ifstream is(path, std::ios::in | std::ios::binary);
@@ -407,6 +410,30 @@ public:
}
}));
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/reboot", this->auth, 0, [this](const auto& req, auto& rep) {
if (req.method != "POST") {
http::server::stockReply(http::server::bad_request, rep);
}
rep.status = http::server::ok;
rep.headers.clear();
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
const std::string result = R"({"status":"ok"})";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
system(REBOOT_COMMAND);
}));
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/resetSettings", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) {
if (req.method != "POST") {
http::server::stockReply(http::server::bad_request, rep);
}
rep.status = http::server::ok;
rep.headers.clear();
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
const std::string result = R"({"status":"ok"})";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
api->resetDefaultSettings();
system(REBOOT_COMMAND);
}));
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/firmwareUpdate", this->auth, http::auth::User::UPDATE_FIRMWARE, [this](const auto& req, auto& rep) {
if (req.method != "PUT") {
http::server::stockReply(http::server::bad_request, rep);

View File

@@ -58,6 +58,12 @@ std::pair<std::string, std::string> splitIpAndMask(const std::string& input) {
return std::make_pair(ip, mask_str);
}
static inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
}
class TerminalNetworkSettings {
public:
std::string managementIp, managementGateway, mode, dataIp;
@@ -103,6 +109,7 @@ private:
CP_GetNetwork(sid, "version", &version);
CP_GetNetwork(sid, "chip_id", &chip_id);
rtrim(chip_id);
CP_GetNetwork(sid, "serial", &sn);
CP_GetNetwork(sid, "mac_eth0", &mac0);
CP_GetNetwork(sid, "mac_eth1", &mac1);
@@ -468,6 +475,13 @@ public:
CP_GetDmaDebug(sid, "reset_cnt_rx", &tmp);
}
void resetDefaultSettings() {
std::lock_guard lock(this->cpApiMutex);
CP_SetDmaDebug(sid, "begin_save_config", " ");
CP_SetDmaDebug(sid, "default_params", "");
CP_SetDmaDebug(sid, "save_config", " ");
}
~TerminalApiDaemon() {
try {
daemon.interrupt();
@@ -873,6 +887,10 @@ void api_driver::ApiDriver::setDebugSendSettings(boost::property_tree::ptree &pt
boost::ignore_unused(pt);
}
void api_driver::ApiDriver::resetDefaultSettings() {
daemon->resetDefaultSettings();
}
bool api_driver::ApiDriver::getIsCinC() const {
modulator_settings s{};
daemon->getSettings(&s, nullptr, nullptr, nullptr, nullptr);

View File

@@ -65,6 +65,8 @@ namespace api_driver {
void setDebugSendSettings(boost::property_tree::ptree & pt);
void resetDefaultSettings();
~ApiDriver();
private: