2022-09-11 16:18:55 +08:00
|
|
|
#include "stdafx.h"
|
2022-09-18 11:15:37 +08:00
|
|
|
#include "user_status.h"
|
2022-09-11 16:18:55 +08:00
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
user_status::user_status(const char* addr, acl::sslbase_conf& ssl_conf,
|
|
|
|
const char* stok)
|
2022-09-11 16:18:55 +08:00
|
|
|
: addr_(addr)
|
|
|
|
, ssl_conf_(ssl_conf)
|
2022-09-18 11:15:37 +08:00
|
|
|
, stok_(stok)
|
2022-09-11 16:18:55 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
user_status::~user_status(void) {}
|
2022-09-11 16:18:55 +08:00
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
void user_status::build_request(acl::string& buf) {
|
2022-09-11 16:18:55 +08:00
|
|
|
request_t req;
|
|
|
|
|
|
|
|
acl::serialize<request_t>(req, buf);
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
bool user_status::parse_response(const acl::string& data, response_t& res) {
|
2022-09-11 16:18:55 +08:00
|
|
|
acl::json json;
|
|
|
|
json.update(data);
|
|
|
|
if (!json.finish()) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger_error("invalid json=%s", data.c_str());
|
2022-09-11 16:18:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
acl::string err;
|
|
|
|
if (!acl::deserialize<response_t>(json, res, &err)) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger_error("parse json=%s\r\n\r\nerr=%s\r\n",
|
|
|
|
data.c_str(), err.c_str());
|
2022-09-11 16:18:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
void user_status::show_status(const response_t& res) {
|
2022-09-18 09:26:31 +08:00
|
|
|
//logger("");
|
2022-09-11 16:18:55 +08:00
|
|
|
if (res.host_management.host_info.empty()) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger("host_info empty!");
|
2022-09-11 16:18:55 +08:00
|
|
|
}
|
|
|
|
|
2022-09-18 09:26:31 +08:00
|
|
|
#if 0
|
2022-09-13 22:20:02 +08:00
|
|
|
for (auto it : res.host_management.host_info) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger("name=%s", it.first.c_str());
|
|
|
|
logger("hostname=%s, ip=%s, mac=%s, up_limit=%s, down_limit=%s",
|
2022-09-13 22:20:02 +08:00
|
|
|
it.second.hostname.c_str(),
|
|
|
|
it.second.ip.c_str(),
|
|
|
|
it.second.mac.c_str(),
|
|
|
|
it.second.up_limit.c_str(),
|
|
|
|
it.second.down_limit.c_str());
|
|
|
|
}
|
|
|
|
|
2022-09-15 23:13:17 +08:00
|
|
|
logger("--------------------------------------------------------");
|
2022-09-18 09:26:31 +08:00
|
|
|
#endif
|
2022-09-13 22:20:02 +08:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2022-09-11 16:18:55 +08:00
|
|
|
|
|
|
|
if (res.wireless.sta_list.empty()) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger("sta_list empty!\r\n");
|
2022-09-11 16:18:55 +08:00
|
|
|
}
|
|
|
|
|
2022-09-18 09:26:31 +08:00
|
|
|
int i = 0;
|
2022-09-11 16:18:55 +08:00
|
|
|
for (auto it : res.wireless.sta_list) {
|
2022-09-18 09:26:31 +08:00
|
|
|
if (atoi(it.second.rx_rate.c_str()) >= 5) {
|
|
|
|
logger("");
|
|
|
|
logger("name=%s", it.first.c_str());
|
|
|
|
logger("name=%s, mac=%s, ip=%s, tx_rate=%s, rx_rate=%s",
|
|
|
|
it.second.name.c_str(),
|
|
|
|
it.second.mac.c_str(),
|
|
|
|
it.second.ip.c_str(),
|
|
|
|
it.second.tx_rate.c_str(),
|
|
|
|
it.second.rx_rate.c_str());
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i > 0) {
|
|
|
|
logger("========================================================");
|
2022-09-11 16:18:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
bool user_status::get_status(const char* stok) {
|
2022-09-11 16:18:55 +08:00
|
|
|
acl::http_request conn(addr_);
|
|
|
|
conn.set_ssl(&ssl_conf_);
|
|
|
|
|
|
|
|
acl::string url;
|
|
|
|
url << "/stok=" << stok << "/ds";
|
|
|
|
|
|
|
|
acl::string req;
|
|
|
|
build_request(req);
|
|
|
|
|
|
|
|
conn.request_header().set_url(url)
|
|
|
|
.set_host(addr_)
|
|
|
|
.set_content_type("application/json; charset=UTF-8")
|
|
|
|
.add_entry("Origin", "https://192.168.1.65/")
|
|
|
|
.add_entry("Referer", "https://192.168.1.65/")
|
|
|
|
.set_content_length(req.size());
|
|
|
|
|
|
|
|
//printf("url=%s\r\n", url.c_str());
|
|
|
|
//printf("req=%s\r\n", req.c_str());
|
|
|
|
|
|
|
|
if (!conn.request(req, req.size())) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger_error("send request error, req=%s", req.c_str());
|
2022-09-11 16:18:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
acl::string buf;
|
|
|
|
if (!conn.get_body(buf)) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger_error("get response error");
|
2022-09-11 16:18:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//printf("%s\n", buf.c_str());
|
|
|
|
|
|
|
|
response_t res;
|
|
|
|
if (!parse_response(buf, res)) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger_error("parse response error");
|
2022-09-11 16:18:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
show_status(res);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
bool user_status::start(void) {
|
2022-09-11 16:18:55 +08:00
|
|
|
while (true) {
|
2022-09-18 11:15:37 +08:00
|
|
|
bool ret = get_status(stok_);
|
2022-09-11 16:18:55 +08:00
|
|
|
sleep(1);
|
2022-09-15 23:13:17 +08:00
|
|
|
|
|
|
|
if (!ret) {
|
2022-09-18 11:15:37 +08:00
|
|
|
return false;
|
2022-09-15 23:13:17 +08:00
|
|
|
}
|
2022-09-11 16:18:55 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|