diff --git a/src/bridge/main.cpp b/src/bridge/main.cpp index 488a576..9dfaa48 100644 --- a/src/bridge/main.cpp +++ b/src/bridge/main.cpp @@ -50,11 +50,11 @@ qDebug() << "Starting the bridge:"; qDebug() << " \"sysadm-bridge [-port ]\""; qDebug() << "CLI flags for configuring the bridge:"; qDebug() << " \"-h\" or \"help\": Show this help text"; -qDebug() << " \"-import_ssl_file \": Loads a .crt or .key file and enables the public key for authorization access later"; -qDebug() << " \"-import_ssl_pubkey \": Enables the public key for authorization access later"; -qDebug() << " \"-list_ssl\": Show all known SSL keys"; -qDebug() << " \"-remove_ssl \": Removes a public key from allowing authorization access"; -qDebug() << " \"-set =\": Used for adjusting individual settings for the bridge"; +qDebug() << " \"import_ssl_file \": Loads a .crt or .key file and enables the public key for authorization access later"; +qDebug() << " \"import_ssl_pubkey \": Enables the public key for authorization access later"; +qDebug() << " \"list_ssl\": Show all known SSL keys"; +qDebug() << " \"remove_ssl \": Removes a public key from allowing authorization access"; +qDebug() << " \"set =\": Used for adjusting individual settings for the bridge"; qDebug() << " - Possible variables:"; qDebug() << " \"blacklist/block_minutes\" (integer): Number of minutes a system remains on the automatic blacklist"; qDebug() << " \"blacklist/fails_to_block\" (integer): Number of times a system must fail authentication to be placed on blacklist"; @@ -92,9 +92,9 @@ int main( int argc, char ** argv ) // ------------------------- else if( (QString(argv[i])=="-port" || QString(argv[i])=="-p") && (i+1setValue("RegisteredCerts/"+id+"/"+enc_key, "Date Registered: "+QDateTime::currentDateTime().toString(Qt::ISODate) ); settingchange=true; // ------------------------- - }else if( QString(argv[i])=="-list_ssl" ){ + }else if( QString(argv[i])=="list_ssl" ){ qDebug() << "Known SSL Keys (base64)"; settingchange = true; QStringList keys = QStringList(CONFIG->allKeys());//.filter("RegisteredCerts/"); @@ -139,7 +139,7 @@ int main( int argc, char ** argv ) qDebug() << keys[i].section("/",1,1) << keys[i].section("/",2,-1) << CONFIG->value(keys[i]).toString(); } // ------------------------- - }else if( QString(argv[i])=="-remove_ssl" && i+1allKeys().filter("RegisteredCerts/"+id+"/"); diff --git a/src/server/WebServer.cpp b/src/server/WebServer.cpp index ddaf6d4..8345c0e 100644 --- a/src/server/WebServer.cpp +++ b/src/server/WebServer.cpp @@ -211,7 +211,7 @@ void WebServer::SslErrors(const QList &list){ // - More Functions for all socket interactions void WebServer::SocketClosed(QString ID){ - qDebug() << "Socket Closed:" << ID; + qDebug() << "Socket Closed:" << ID << QDateTime::currentDateTime().toString(Qt::ISODate); for(int i=0; iID()==ID){ delete OpenSockets.takeAt(i); break; } } diff --git a/src/server/WebSocket.cpp b/src/server/WebSocket.cpp index 828c58d..136df25 100644 --- a/src/server/WebSocket.cpp +++ b/src/server/WebSocket.cpp @@ -14,6 +14,7 @@ WebSocket::WebSocket(QObject *parent, QWebSocket *sock, QString ID, AuthorizationManager *auth) : QObject(parent){ SockID = ID; isBridge = false; + connecting = false; SockAuthToken.clear(); //nothing set initially SOCKET = sock; TSOCKET = 0; @@ -42,6 +43,7 @@ WebSocket::WebSocket(QObject *parent, QSslSocket *sock, QString ID, Authorizatio SockAuthToken.clear(); //nothing set initially TSOCKET = sock; SOCKET = 0; + connecting = false; SockPeerIP = TSOCKET->peerAddress().toString(); LogManager::log(LogManager::HOST,"New Connection: "+SockPeerIP); AUTHSYSTEM = auth; @@ -96,7 +98,8 @@ WebSocket::WebSocket(QObject *parent, QString url, QString ID, AuthorizationMana url.section(":",-1).toInt(&hasport); //check if the last piece of the url is a valid number if(!hasport){ url.append(":"+QString::number(BRIDGEPORTNUMBER)); } //Now setup/init the connection - qDebug() << "Connecting to bridge:" << url; + qDebug() << "Connecting to bridge:" << url << QDateTime::currentDateTime().toString(Qt::ISODate); + connecting = true; SOCKET->setSslConfiguration(QSslConfiguration::defaultConfiguration()); SOCKET->open(QUrl(url)); connCheckTimer = new QTimer(this); @@ -134,7 +137,7 @@ void WebSocket::closeConnection(){ bool WebSocket::isActive(){ bool ok = false; if(SOCKET!=0){ - ok = SOCKET->isValid(); + ok = (SOCKET->isValid() || connecting); }else if(TSOCKET!=0){ ok = TSOCKET->isValid(); } @@ -492,6 +495,7 @@ QStringList WebSocket::JsonArrayToStringList(QJsonArray array){ // ===================== void WebSocket::checkConnection(){ if(SOCKET !=0 && !SOCKET->isValid()){ + if(connecting){ SOCKET->abort(); } emit SocketClosed(SockID); } else if(TSOCKET !=0 && !TSOCKET->isValid() ){ @@ -636,6 +640,7 @@ void WebSocket::SslError(const QList &err){ //sslErrors() signal } void WebSocket::startBridgeAuth(){ + connecting = false; //now connected SockPeerIP = SOCKET->peerAddress().toString(); LogManager::log(LogManager::HOST,"New Bridge Connection: "+SockPeerIP); //qDebug() << "Init Bridge Auth..."; diff --git a/src/server/WebSocket.h b/src/server/WebSocket.h index de3bc48..18c033c 100644 --- a/src/server/WebSocket.h +++ b/src/server/WebSocket.h @@ -36,6 +36,7 @@ private: QString SockID, SockAuthToken, SockPeerIP; AuthorizationManager *AUTHSYSTEM; QList ForwardEvents; + bool connecting; //flag for whether the connection is still being established //Data handling for bridged connections (1 connection for multiple clients) QHash BRIDGE; //ID/data diff --git a/src/server/main.cpp b/src/server/main.cpp index e6ac3dd..aefd466 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -63,6 +63,20 @@ inline QString ReadFile(QString path){ return str; } +void showUsage(){ +qDebug() << "sysadm-binary usage:"; +qDebug() << "Starting the server:"; +qDebug() << " \"sysadm-binary [-rest] [-port ]\""; +qDebug() << "CLI flags for configuring the server:"; +qDebug() << " \"-h\" or \"help\": Show this help text"; +qDebug() << " \"import_ssl_file []\": Loads a .crt or .key file and enables the public key for authorization access later"; +qDebug() << "Configuring server->bridge connections (websockets only):"; +qDebug() << " \"bridge_list\": Show all bridges that are currently setup"; +qDebug() << " \"bridge_add \": Create a new bridge connection with the given nickname"; +qDebug() << " \"bridge_remove \": Remove the bridge connection with the given nickname"; +qDebug() << " \"bridge_export_key [file]\": Export the public SSL key the server uses to connect to bridges"; +} + int main( int argc, char ** argv ) { @@ -79,6 +93,7 @@ int main( int argc, char ** argv ) for(int i=1; i