2022-04-29 00:39:39 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Tyler Perkins
|
|
|
|
// 28-4-22
|
|
|
|
// Routes implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "routes.hpp"
|
|
|
|
|
|
|
|
void setRoutes(crow::SimpleApp& app){
|
2022-04-29 02:12:38 +00:00
|
|
|
CROW_ROUTE(app, "/proc/meminfo")([](const crow::request& req){
|
2022-04-29 01:32:07 +00:00
|
|
|
crow::json::wvalue json;
|
2022-04-29 02:29:43 +00:00
|
|
|
bool status;
|
|
|
|
std::string accept = req.get_header_value("Accept");
|
2022-04-29 01:32:07 +00:00
|
|
|
|
2022-04-29 02:29:43 +00:00
|
|
|
std::transform(accept.begin(), accept.end(), accept.begin(), ::tolower);
|
2022-04-29 02:12:38 +00:00
|
|
|
|
2022-04-29 02:29:43 +00:00
|
|
|
if(accept == "text/plain"){
|
|
|
|
accept.clear();
|
|
|
|
status = memory::getRawProcMem(accept);
|
|
|
|
return crow::response(status ? 200 : 503, accept);
|
|
|
|
} else {
|
|
|
|
status = memory::getProcMem(json);
|
|
|
|
return crow::response(status ? 200 : 503, json.dump());
|
|
|
|
}
|
2022-04-29 00:39:39 +00:00
|
|
|
});
|
|
|
|
|
2022-04-29 16:12:02 +00:00
|
|
|
CROW_ROUTE(app, "/proc/uptime")([](const crow::request& req){
|
2022-04-29 16:05:34 +00:00
|
|
|
crow::json::wvalue json;
|
|
|
|
bool status;
|
2022-04-29 16:12:02 +00:00
|
|
|
std::string accept = req.get_header_value("Accept");
|
2022-04-29 16:05:34 +00:00
|
|
|
|
2022-04-29 16:12:02 +00:00
|
|
|
std::transform(accept.begin(), accept.end(), accept.begin(), ::tolower);
|
2022-04-29 16:05:34 +00:00
|
|
|
|
2022-04-29 16:12:02 +00:00
|
|
|
if(accept == "text/plain"){
|
|
|
|
accept.clear();
|
|
|
|
status = state::getRawUptime(accept);
|
|
|
|
return crow::response(status ? 200 : 503, accept);
|
|
|
|
} else {
|
|
|
|
status = state::getUptime(json);
|
|
|
|
return crow::response(status ? 200: 503, json.dump());
|
|
|
|
}
|
2022-04-29 16:05:34 +00:00
|
|
|
});
|
|
|
|
|
2022-04-29 16:57:33 +00:00
|
|
|
CROW_ROUTE(app, "/uptime")([](){
|
|
|
|
crow::response ret;
|
|
|
|
ret.moved_perm("/proc/uptime");
|
|
|
|
return ret;
|
|
|
|
});
|
|
|
|
|
2022-04-29 00:39:39 +00:00
|
|
|
CROW_ROUTE(app, "/mem")([]{
|
|
|
|
return "mem";
|
|
|
|
});
|
2022-04-29 16:05:34 +00:00
|
|
|
|
2022-04-29 00:39:39 +00:00
|
|
|
}
|