stephb9959
2022-09-14 08:58:32 -07:00
parent 67910c982a
commit b79a3b6c12
6 changed files with 7607 additions and 40 deletions

2
build
View File

@@ -1 +1 @@
10
11

View File

@@ -172,6 +172,29 @@ namespace OpenWifi {
GetJSON("tx_packets", counters, DTP.ap_data.tx_packets, (uint64_t) 0);
}
InterfaceClientEntryMap_t ICEM;
if(interface.contains("clients") && interface["clients"].is_array()) {
try {
auto Clients = interface["clients"];
for(const auto & client: Clients) {
if(client.contains("mac") && client["mac"].is_string()) {
InterfaceClientEntry E;
if(client.contains("ipv4_addresses") && client["ipv4_addresses"].is_array()) {
for(const auto &ip:client["ipv4_addresses"])
E.ipv4_addresses.push_back(ip);
}
if(client.contains("ipv6_addresses") && client["ipv6_addresses"].is_array()) {
for(const auto &ip:client["ipv6_addresses"])
E.ipv6_addresses.push_back(ip);
}
ICEM[client["mac"]] = E;
}
}
} catch(...) {
}
}
if(interface.contains("ssids")) {
auto ssids = interface["ssids"];
for (const auto &ssid: ssids) {
@@ -243,8 +266,14 @@ namespace OpenWifi {
GetJSON("rx_packets",association,WFH.rx_packets,(uint64_t)0);
GetJSON("tx_packets",association,WFH.tx_packets,(uint64_t)0);
WFH.ipv4 = "---";
WFH.ipv6 = "----";
// try to locate the IP addresses
auto ClientInfo = ICEM.find(WFH.station_id);
if(ClientInfo!=end(ICEM)) {
if(!ClientInfo->second.ipv4_addresses.empty())
WFH.ipv4 = ClientInfo->second.ipv4_addresses[0];
if(!ClientInfo->second.ipv6_addresses.empty())
WFH.ipv6 = ClientInfo->second.ipv6_addresses[0];
}
for(const auto &rd:DTP.radio_data) {
if(rd.band == SSIDTP.band) {

View File

@@ -11,6 +11,13 @@
namespace OpenWifi {
struct InterfaceClientEntry {
std::vector<std::string> ipv4_addresses;
std::vector<std::string> ipv6_addresses;
};
using InterfaceClientEntryMap_t = std::map<std::string,InterfaceClientEntry>;
class AP {
public:
explicit AP(uint64_t mac, const std::string &venue_id, const std::string &BoardId, Poco::Logger &L) :

View File

@@ -4867,7 +4867,7 @@ namespace OpenWifi {
void run() override;
// MyParallelSocketReactor &ReactorPool();
Poco::Net::SocketReactor & Reactor() { return Reactor_; }
void NewClient(Poco::Net::WebSocket &WS, const std::string &Id);
void NewClient(Poco::Net::WebSocket &WS, const std::string &Id, const std::string &UserName);
bool Register(WebSocketClient *Client, const std::string &Id);
void SetProcessor(WebSocketClientProcessor *F);
void UnRegister(const std::string &Id);
@@ -4918,18 +4918,22 @@ namespace OpenWifi {
class WebSocketClient {
public:
explicit WebSocketClient(Poco::Net::WebSocket &WS, const std::string &Id, Poco::Logger &L,
WebSocketClientProcessor *Processor);
explicit WebSocketClient(Poco::Net::WebSocket &WS,
const std::string &Id,
const std::string &UserName,
Poco::Logger &L,
WebSocketClientProcessor *Processor);
virtual ~WebSocketClient();
[[nodiscard]] inline const std::string &Id();
[[nodiscard]] Poco::Logger &Logger();
inline bool Send(const std::string &Payload);
private:
std::unique_ptr<Poco::Net::WebSocket> WS_;
Poco::Net::SocketReactor &Reactor_;
std::string Id_;
Poco::Logger &Logger_;
bool Authenticated_ = false;
Poco::Net::SocketReactor &Reactor_;
std::string Id_;
std::string UserName_;
Poco::Logger &Logger_;
std::atomic_bool Authenticated_ = false;
SecurityObjects::UserInfoAndPolicy UserInfo_;
WebSocketClientProcessor *Processor_ = nullptr;
void OnSocketReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification> &pNf);
@@ -4937,33 +4941,9 @@ namespace OpenWifi {
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf);
};
/* inline MyParallelSocketReactor::MyParallelSocketReactor(uint32_t NumReactors) :
NumReactors_(NumReactors)
{
Reactors_ = new Poco::Net::SocketReactor[NumReactors_];
for(uint32_t i=0;i<NumReactors_;i++) {
ReactorPool_.start(Reactors_[i]);
}
}
inline MyParallelSocketReactor::~MyParallelSocketReactor() {
for(uint32_t i=0;i<NumReactors_;i++) {
Reactors_[i].stop();
}
ReactorPool_.stopAll();
ReactorPool_.joinAll();
delete [] Reactors_;
}
inline Poco::Net::SocketReactor & MyParallelSocketReactor::Reactor() {
return Reactors_[ rand() % NumReactors_ ];
}
// inline MyParallelSocketReactor & WebSocketClientServer::ReactorPool() { return *ReactorPool_; }
*/
inline void WebSocketClientServer::NewClient(Poco::Net::WebSocket & WS, const std::string &Id) {
inline void WebSocketClientServer::NewClient(Poco::Net::WebSocket & WS, const std::string &Id, const std::string &UserName ) {
std::lock_guard G(Mutex_);
auto Client = new WebSocketClient(WS,Id,Logger(), Processor_);
auto Client = new WebSocketClient(WS,Id,UserName,Logger(), Processor_);
Clients_[Id] = std::make_pair(Client,"");
}
@@ -5080,6 +5060,7 @@ namespace OpenWifi {
auto Op = flags & Poco::Net::WebSocket::FRAME_OP_BITMASK;
if (n == 0) {
Logger().warning(Poco::format("CLOSE(%s): %s UI Client is closing WS connection.", Id_, UserName_));
return delete this;
}
@@ -5092,7 +5073,7 @@ namespace OpenWifi {
case Poco::Net::WebSocket::FRAME_OP_PONG: {
} break;
case Poco::Net::WebSocket::FRAME_OP_CLOSE: {
Logger().warning(Poco::format("CLOSE(%s): UI Client is closing its connection.", Id_));
Logger().warning(Poco::format("CLOSE(%s): %s UI Client is closing WS connection.", Id_, UserName_));
Done = true;
} break;
case Poco::Net::WebSocket::FRAME_OP_TEXT: {
@@ -5104,6 +5085,8 @@ namespace OpenWifi {
if (Tokens.size() == 2 &&
AuthClient()->IsAuthorized(Tokens[1], UserInfo_, Expired, Contacted)) {
Authenticated_ = true;
UserName_ = UserInfo_.userinfo.email;
Logger().warning(Poco::format("START(%s): %s UI Client is starting WS connection.", Id_, UserName_));
std::string S{"Welcome! Bienvenue! Bienvenidos!"};
WS_->sendFrame(S.c_str(), S.size());
WebSocketClientServer()->SetUser(Id_, UserInfo_.userinfo.email);
@@ -5149,9 +5132,10 @@ namespace OpenWifi {
}
inline WebSocketClient::WebSocketClient( Poco::Net::WebSocket & WS , const std::string &Id, Poco::Logger & L, WebSocketClientProcessor * Processor) :
inline WebSocketClient::WebSocketClient( Poco::Net::WebSocket & WS , const std::string &Id, const std::string &UserName, Poco::Logger & L, WebSocketClientProcessor * Processor) :
Reactor_(WebSocketClientServer()->Reactor()),
Id_(Id),
UserName_(UserName),
Logger_(L),
Processor_(Processor) {
try {
@@ -5231,9 +5215,8 @@ namespace OpenWifi {
try
{
Poco::Net::WebSocket WS(*Request, *Response);
Logger().information("UI-WebSocket connection established.");
auto Id = MicroService::CreateUUID();
WebSocketClientServer()->NewClient(WS,Id);
WebSocketClientServer()->NewClient(WS,Id,UserInfo_.userinfo.email);
}
catch (...) {
std::cout << "Cannot create websocket client..." << std::endl;

View File

@@ -146,6 +146,10 @@ namespace OpenWifi {
WebSocketClientServer()->SendUserNotification(User,N);
}
/////
/////
/////
struct WebSocketNotificationRebootList {
std::string title,
details,
@@ -189,5 +193,58 @@ namespace OpenWifi {
WebSocketClientServer()->SendUserNotification(User,N);
}
/////
/////
/////
struct WebSocketNotificationUpgradeList {
std::string title,
details,
jobId;
std::vector<std::string> success,
skipped,
no_firmware,
not_connected;
uint64_t timeStamp=OpenWifi::Now();
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
typedef WebSocketNotification<WebSocketNotificationUpgradeList> WebSocketClientNotificationVenueUpgradeList_t;
inline void WebSocketNotificationUpgradeList::to_json(Poco::JSON::Object &Obj) const {
RESTAPI_utils::field_to_json(Obj,"title",title);
RESTAPI_utils::field_to_json(Obj,"jobId",jobId);
RESTAPI_utils::field_to_json(Obj,"success",success);
RESTAPI_utils::field_to_json(Obj,"notConnected",not_connected);
RESTAPI_utils::field_to_json(Obj,"noFirmware",no_firmware);
RESTAPI_utils::field_to_json(Obj,"skipped",skipped);
RESTAPI_utils::field_to_json(Obj,"timeStamp",timeStamp);
RESTAPI_utils::field_to_json(Obj,"details",details);
}
inline bool WebSocketNotificationUpgradeList::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
RESTAPI_utils::field_from_json(Obj,"title",title);
RESTAPI_utils::field_from_json(Obj,"jobId",jobId);
RESTAPI_utils::field_from_json(Obj,"success",success);
RESTAPI_utils::field_from_json(Obj,"notConnected",not_connected);
RESTAPI_utils::field_from_json(Obj,"noFirmware",no_firmware);
RESTAPI_utils::field_from_json(Obj,"skipped",skipped);
RESTAPI_utils::field_from_json(Obj,"timeStamp",timeStamp);
RESTAPI_utils::field_from_json(Obj,"details",details);
return true;
} catch(...) {
}
return false;
}
inline void WebSocketClientNotificationVenueUpgradeCompletionToUser( const std::string & User, WebSocketClientNotificationVenueUpgradeList_t &N) {
N.type = "venue_upgrader";
WebSocketClientServer()->SendUserNotification(User,N);
}
} // namespace OpenWifi

File diff suppressed because it is too large Load Diff