добавление включения/выключения логгирования через скрипт
This commit is contained in:
parent
130c3c4dfc
commit
5f0959b521
41
devtool.py
Normal file
41
devtool.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
USERNAME = "admin"
|
||||||
|
PASSWORD = "admin"
|
||||||
|
|
||||||
|
|
||||||
|
def do_login(base_url):
|
||||||
|
session = requests.session()
|
||||||
|
|
||||||
|
login_data = json.dumps({
|
||||||
|
"username": USERNAME,
|
||||||
|
"password": PASSWORD
|
||||||
|
}, ensure_ascii=True, indent=0)
|
||||||
|
|
||||||
|
session.get(f"{base_url}/login")
|
||||||
|
|
||||||
|
login_result = json.loads(session.post(f"{base_url}/login", headers={'Content-Type': 'application/json'}, data=login_data).content.decode('utf-8'))
|
||||||
|
if "error" in login_result:
|
||||||
|
raise RuntimeError(f"Failed to login: {login_result}")
|
||||||
|
|
||||||
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
def set_logging(base_url, value):
|
||||||
|
session = do_login(base_url)
|
||||||
|
res = session.post(f"{base_url}/dev/cpapicall?f=SetDmaDebug¶m=log_bool&value={value}")
|
||||||
|
print(res.content.decode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print(f"Usage: {sys.argv[0]} http(s)://terminal-api logging on|off")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if sys.argv[2] == "logging":
|
||||||
|
set_logging(sys.argv[1], {"on": "true", "off": "false"}[sys.argv[3]])
|
||||||
|
else:
|
||||||
|
print(f"Unknown action: {sys.argv[1]}")
|
38
src/main.cpp
38
src/main.cpp
@ -402,6 +402,7 @@ public:
|
|||||||
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) {
|
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") {
|
if (req.method != "PUT") {
|
||||||
http::server::stockReply(http::server::bad_request, rep);
|
http::server::stockReply(http::server::bad_request, rep);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this->upgradeOrRebootRunning = true;
|
this->upgradeOrRebootRunning = true;
|
||||||
onUploadFirmware(req);
|
onUploadFirmware(req);
|
||||||
@ -420,6 +421,7 @@ public:
|
|||||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/doFirmwareUpgrade", this->auth, http::auth::User::UPDATE_FIRMWARE, [this](const auto& req, auto& rep) {
|
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/api/doFirmwareUpgrade", this->auth, http::auth::User::UPDATE_FIRMWARE, [this](const auto& req, auto& rep) {
|
||||||
if (req.method != "POST") {
|
if (req.method != "POST") {
|
||||||
http::server::stockReply(http::server::bad_request, rep);
|
http::server::stockReply(http::server::bad_request, rep);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this->upgradeOrRebootRunning = true;
|
this->upgradeOrRebootRunning = true;
|
||||||
doTerminalUpgrade();
|
doTerminalUpgrade();
|
||||||
@ -435,6 +437,42 @@ public:
|
|||||||
sf->serve(DEV_HTML, rep);
|
sf->serve(DEV_HTML, rep);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/dev/cpapicall", this->auth, http::auth::User::SUPERUSER, [this](const http::server::Request& req, auto& rep) {
|
||||||
|
if (req.method != "POST") {
|
||||||
|
http::server::stockReply(http::server::bad_request, rep);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (req.url->params.find("f") == req.url->params.end()) {
|
||||||
|
http::server::stockReply(http::server::bad_request, rep);
|
||||||
|
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 sid) {
|
||||||
|
CP_SetDmaDebug(sid, req.url->params["param"].c_str(), 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 sid) {
|
||||||
|
std::string tmp{};
|
||||||
|
CP_GetDmaDebug(sid, req.url->params["param"].c_str(), &tmp);
|
||||||
|
result = R"({"status":"ok","result":)";
|
||||||
|
result += api_driver::buildEscapedString(tmp);
|
||||||
|
result += "}";
|
||||||
|
});
|
||||||
|
} 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)});
|
||||||
|
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||||
|
}));
|
||||||
|
|
||||||
// s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/dev/fetchParams", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) {
|
// s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/dev/fetchParams", this->auth, http::auth::User::SUPERUSER, [this](const auto& req, auto& rep) {
|
||||||
// rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
// rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||||
// std::string result = R"({"status":"ok","fwsize":)";
|
// std::string result = R"({"status":"ok","fwsize":)";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user