mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
API CHANGE: Get the sysadm-bridge all finished up. Now to add the necessary bits to the server/client so we can try using it.
NOTE: There is a special API/event for the bridge to announce which server/client connections are available (clients will see only servers, and vice versa)
The syntax for this event is:
{
"namespace":"events",
"name":"bridge",
"id":"",
"args":{
"available_connections":["ID1","ID2", etc..]
}
}
Note that the available_connections are *all* the connections available at that time (it is not a difference from a previous state), so there may be both new ID's in the list and ID's which are no longer listed.
This event will get sent out any time a new connection/disconnection is made from the bridge which impacts the current connection (so a client will only get the event when a server connects/disconnects and vice versa).
This commit is contained in:
@@ -43,6 +43,14 @@ void BridgeConnection::forwardMessage(QString msg){
|
||||
if(SOCKET!=0 && SOCKET->isValid()){ SOCKET->sendTextMessage(msg); }
|
||||
}
|
||||
|
||||
bool BridgeConnection::isServer(){
|
||||
return serverconn;
|
||||
}
|
||||
|
||||
QStringList BridgeConnection::validKeySums(){
|
||||
return knownkeys;
|
||||
}
|
||||
|
||||
//=======================
|
||||
// PRIVATE
|
||||
//=======================
|
||||
@@ -108,6 +116,13 @@ void BridgeConnection::HandleAPIMessage(QString msg){
|
||||
QString id = JM.value("id").toString();
|
||||
if(id=="sysadm_bridge_request_ident"){
|
||||
serverconn = (JM.value("args").toObject().value("type").toString() == "server");
|
||||
}else if("bridge_request_list_keys"){
|
||||
QStringList keys = JsonArrayToStringList(JM.value("args").toObject().value("md5_keys").toArray());
|
||||
//Now see what has changed (if anything)
|
||||
if(keys!=knownkeys){
|
||||
knownkeys = keys;
|
||||
emit keysChanged(SockID, serverconn, knownkeys);
|
||||
}
|
||||
}
|
||||
//no response needed
|
||||
}else{
|
||||
@@ -140,6 +155,7 @@ void BridgeConnection::HandleAPIMessage(QString msg){
|
||||
array.append(SockAuthToken);
|
||||
array.append(AUTHSYSTEM->checkAuthTimeoutSecs(SockAuthToken));
|
||||
outargs = array;
|
||||
QTimer::singleShot(10 ,this, SLOT(requestKeyList()) );
|
||||
}else{
|
||||
out.insert("name","error");
|
||||
outargs = "unauthorized";
|
||||
@@ -213,3 +229,30 @@ void BridgeConnection::SslError(const QList<QSslError> &err){ //sslErrors() sign
|
||||
// ======================
|
||||
// PUBLIC SLOTS
|
||||
// ======================
|
||||
void BridgeConnection::requestKeyList(){
|
||||
if(!AUTHSYSTEM->checkAuth(SockAuthToken)){ return; } //not authorized yet
|
||||
QJsonObject obj;
|
||||
obj.insert("id","bridge_request_list_keys");
|
||||
obj.insert("namespace","rpc");
|
||||
obj.insert("name","settings");
|
||||
QJsonObject args;
|
||||
args.insert("action","list_ssl_checksums");
|
||||
obj.insert("args",args);
|
||||
|
||||
SOCKET->sendTextMessage( QJsonDocument(obj).toJson(QJsonDocument::Compact) );
|
||||
}
|
||||
|
||||
void BridgeConnection::announceIDAvailability(QStringList IDs){
|
||||
if(!AUTHSYSTEM->checkAuth(SockAuthToken)){ return; } //not authorized yet
|
||||
if(lastKnownConnections == IDs){ return; } //don't announce changes when nothing changed
|
||||
lastKnownConnections = IDs; //save for comparison later
|
||||
QJsonObject obj;
|
||||
obj.insert("id","");
|
||||
obj.insert("namespace","events");
|
||||
obj.insert("name","bridge");
|
||||
QJsonObject args;
|
||||
args.insert("available_connections",QJsonArray::fromStringList(IDs));
|
||||
obj.insert("args",args);
|
||||
|
||||
SOCKET->sendTextMessage( QJsonDocument(obj).toJson(QJsonDocument::Compact) );
|
||||
}
|
||||
|
||||
@@ -18,11 +18,15 @@ public:
|
||||
void forwardMessage(QString msg);
|
||||
bool isServer();
|
||||
|
||||
QStringList validKeySums();
|
||||
|
||||
private:
|
||||
QTimer *idletimer;
|
||||
QWebSocket *SOCKET;
|
||||
QString SockID, SockAuthToken, SockPeerIP;
|
||||
bool serverconn;
|
||||
QStringList knownkeys;
|
||||
QStringList lastKnownConnections;
|
||||
|
||||
//Simplification functions
|
||||
QString JsonValueToString(QJsonValue);
|
||||
@@ -46,10 +50,13 @@ private slots:
|
||||
void SslError(const QList<QSslError>&); //sslErrors() signal
|
||||
|
||||
public slots:
|
||||
void requestKeyList();
|
||||
void announceIDAvailability(QStringList IDs);
|
||||
|
||||
signals:
|
||||
void SocketClosed(QString); //ID
|
||||
void SocketMessage(QString, QString);
|
||||
void SocketMessage(QString, QString); //toID / Message
|
||||
void keysChanged(QString, bool, QStringList); //ID, isServer, goodkeys
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,12 +12,11 @@
|
||||
//=======================
|
||||
BridgeServer::BridgeServer() : QWebSocketServer("sysadm-bridge", QWebSocketServer::SecureMode){
|
||||
//Setup all the various settings
|
||||
//AUTH = new AuthorizationManager();
|
||||
connect(AUTHSYSTEM, SIGNAL(BlockHost(QHostAddress)), this, SLOT(BlackListConnection(QHostAddress)) );
|
||||
}
|
||||
|
||||
BridgeServer::~BridgeServer(){
|
||||
//delete AUTH;
|
||||
|
||||
}
|
||||
|
||||
bool BridgeServer::startServer(quint16 port){
|
||||
@@ -125,6 +124,7 @@ void BridgeServer::NewSocketConnection(){
|
||||
//qDebug() << "New Socket Connection";
|
||||
connect(sock, SIGNAL(SocketClosed(QString)), this, SLOT(SocketClosed(QString)) );
|
||||
connect(sock, SIGNAL(SocketMessage(QString, QString)), this, SLOT(SendMessage(QString, QString)) );
|
||||
connect(sock, SIGNAL(keysChanged(QString, bool, QStringList)), this, SLOT(announceKeyChange(QString, bool, QStringList)) );
|
||||
OpenSockets << sock;
|
||||
}
|
||||
|
||||
@@ -183,3 +183,24 @@ void BridgeServer::SocketClosed(QString ID){
|
||||
}
|
||||
QTimer::singleShot(0,this, SLOT(NewSocketConnection()) ); //check for a new connection
|
||||
}
|
||||
|
||||
// Connection Keys Changed
|
||||
void BridgeServer::announceKeyChange(QString ID, bool isServer, QStringList keys){
|
||||
for(int c = 0; c<OpenSockets.length(); c++){
|
||||
bool server = OpenSockets[c]->isServer();
|
||||
QStringList keys = OpenSockets[c]->validKeySums();
|
||||
keys.removeDuplicates();
|
||||
QStringList IDs;
|
||||
for(int i=0; i<OpenSockets.length(); i++){
|
||||
if(i==c){ continue; } //current socket
|
||||
else if(OpenSockets[i]->isServer() != server){ //look for a server/client pair
|
||||
//compare keys to look for matches
|
||||
QStringList chkkeys = OpenSockets[i ]->validKeySums();
|
||||
chkkeys.removeDuplicates();
|
||||
chkkeys << keys;
|
||||
if(chkkeys.removeDuplicates() > 0){ IDs << OpenSockets[i]->ID(); }
|
||||
}
|
||||
}//end inner loop of sockets
|
||||
OpenSockets[c]->announceIDAvailability(IDs);
|
||||
} //end loop over sockets to check
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ private slots:
|
||||
void PeerVerifyError(const QSslError&); //peerVerifyError() signal
|
||||
void SslErrors(const QList<QSslError>&); //sslErrors() signal
|
||||
void SocketClosed(QString ID);
|
||||
// Connection Keys Changed
|
||||
void announceKeyChange(QString ID, bool isServer, QStringList keys);
|
||||
|
||||
signals:
|
||||
void ForwardMessage(QString, QString); //toID, msg
|
||||
|
||||
Reference in New Issue
Block a user