mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Start adding the bridge data handling into the server so there can be unique encryption keys and auth tokens per bridged system connection.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
WebSocket::WebSocket(QWebSocket *sock, QString ID, AuthorizationManager *auth){
|
||||
SockID = ID;
|
||||
isBridge = false;
|
||||
SockAuthToken.clear(); //nothing set initially
|
||||
SOCKET = sock;
|
||||
TSOCKET = 0;
|
||||
@@ -126,6 +127,8 @@ void WebSocket::EvaluateREST(QString msg){
|
||||
if(IN.name.startsWith("auth") || (IN.namesp.toLower()=="rpc" && IN.name.toLower()=="identify") ){
|
||||
//Keep auth/pre-auth system requests in order
|
||||
EvaluateRequest(IN);
|
||||
}else if(isBridge && (IN.name=="response" || (IN.namesp=="events" && IN.name=="bridge") ) ){
|
||||
EvaluateResponse(IN);
|
||||
}else{
|
||||
QtConcurrent::run(this, &WebSocket::EvaluateRequest, IN);
|
||||
}
|
||||
@@ -296,6 +299,20 @@ if(out.in_struct.namesp.toLower() == "rpc"){
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket::EvaluateResponse(const RestInputStruct& IN){
|
||||
if(IN.namesp=="events" && IN.name=="bridge"){
|
||||
QStringList bids = JsonArrayToStringList(IN.args.toObject().value("available_connections").toArray());
|
||||
QStringList keys = BRIDGE.keys();
|
||||
for(int i=0; i<keys.length(); i++){
|
||||
if(bids.contains(keys[i])){ bids.removeAll(keys[i]); } //already handled
|
||||
else{ AUTHSYSTEM->clearAuth(BRIDGE[keys[i]].auth_tok); BRIDGE.remove(keys[i]); } //no longer available
|
||||
}
|
||||
//Now add any new bridge ID's to the hash
|
||||
for(int i=0; i<bids.length(); i++){
|
||||
BRIDGE.insert(bids[i], bridge_data());
|
||||
}
|
||||
}
|
||||
}
|
||||
// === GENERAL PURPOSE UTILITY FUNCTIONS ===
|
||||
QString WebSocket::JsonValueToString(QJsonValue val){
|
||||
//Note: Do not use this on arrays - only use this on single-value values
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "RestStructs.h"
|
||||
#include "AuthorizationManager.h"
|
||||
|
||||
struct bridge_data{
|
||||
QString enc_key, auth_tok;
|
||||
};
|
||||
|
||||
class WebSocket : public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -28,13 +32,19 @@ private:
|
||||
AuthorizationManager *AUTHSYSTEM;
|
||||
QList<EventWatcher::EVENT_TYPE> ForwardEvents;
|
||||
|
||||
//Data handling for bridged connections (1 connection for multiple clients)
|
||||
QHash<QString, bridge_data> BRIDGE; //ID/data
|
||||
bool isBridge;
|
||||
|
||||
// Where we store incoming Tcp data
|
||||
QString incomingbuffer;
|
||||
void ParseIncoming();
|
||||
|
||||
//Main connection comminucations procedure
|
||||
//Main connection communications procedure
|
||||
void EvaluateREST(QString); //STAGE 1 response: Text -> Rest/JSON struct
|
||||
void EvaluateRequest(const RestInputStruct&); //STAGE 2 response: Parse Rest/JSON (does auth/events)
|
||||
//Response handling
|
||||
void EvaluateResponse(const RestInputStruct&);
|
||||
|
||||
//Simplification functions
|
||||
QString JsonValueToString(QJsonValue);
|
||||
|
||||
Reference in New Issue
Block a user