mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Merge branch 'master' of https://github.com/pcbsd/sysadm
This commit is contained in:
@@ -18,7 +18,7 @@ BridgeConnection::BridgeConnection(QWebSocket *sock, QString ID){
|
||||
idletimer = new QTimer(this);
|
||||
idletimer->setInterval(IDLETIMEOUTMINS*60000); //connection timout for idle sockets
|
||||
idletimer->setSingleShot(true);
|
||||
connect(idletimer, SIGNAL(timeout()), this, SLOT(checkIdle()) );
|
||||
connect(idletimer, SIGNAL(timeout()), this, SLOT(checkgonintendoIdle()) );
|
||||
connect(SOCKET, SIGNAL(textMessageReceived(const QString&)), this, SLOT(EvaluateMessage(const QString&)) );
|
||||
connect(SOCKET, SIGNAL(binaryMessageReceived(const QByteArray&)), this, SLOT(EvaluateMessage(const QByteArray&)) );
|
||||
connect(SOCKET, SIGNAL(aboutToClose()), this, SLOT(SocketClosing()) );
|
||||
@@ -42,6 +42,7 @@ void BridgeConnection::forwardMessage(QString msg){
|
||||
//qDebug() << "Sending Socket Reply:" << msg;
|
||||
if(SOCKET!=0 && SOCKET->isValid()){ SOCKET->sendTextMessage(msg); }
|
||||
}
|
||||
|
||||
//=======================
|
||||
// PRIVATE
|
||||
//=======================
|
||||
|
||||
@@ -75,7 +75,6 @@ bool BridgeServer::setupWebSocket(quint16 port){
|
||||
//Setup Connections
|
||||
connect(this, SIGNAL(newConnection()), this, SLOT(NewSocketConnection()) );
|
||||
connect(this, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(NewConnectError(QAbstractSocket::SocketError)) );
|
||||
// -- websocket specific signals
|
||||
connect(this, SIGNAL(closed()), this, SLOT(ServerClosed()) );
|
||||
connect(this, SIGNAL(serverError(QWebSocketProtocol::CloseCode)), this, SLOT(ServerError(QWebSocketProtocol::CloseCode)) );
|
||||
connect(this, SIGNAL(originAuthenticationRequired(QWebSocketCorsAuthenticator*)), this, SLOT(OriginAuthRequired(QWebSocketCorsAuthenticator*)) );
|
||||
@@ -125,7 +124,7 @@ void BridgeServer::NewSocketConnection(){
|
||||
if(sock==0){ return; } //no new connection
|
||||
//qDebug() << "New Socket Connection";
|
||||
connect(sock, SIGNAL(SocketClosed(QString)), this, SLOT(SocketClosed(QString)) );
|
||||
connect(sock, SIGNAL(SocketMessage(QString, QString)), this, SIGNAL(ForwardMessage(QString, QString)) );
|
||||
connect(sock, SIGNAL(SocketMessage(QString, QString)), this, SLOT(SendMessage(QString, QString)) );
|
||||
OpenSockets << sock;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <QStringList>
|
||||
#include <QSettings>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QHash>
|
||||
|
||||
@@ -51,8 +51,7 @@ void MessageOutput(QtMsgType type, const QMessageLogContext &context, const QStr
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
//Evaluate input arguments
|
||||
quint16 cport = 12148; //client-side port number
|
||||
quint16 sport = 12149; //server-side port number
|
||||
quint16 port = 12149; //port number
|
||||
bool settingchange = false;
|
||||
for(int i=1; i<argc; i++){
|
||||
if(settingchange){
|
||||
@@ -62,8 +61,7 @@ int main( int argc, char ** argv )
|
||||
qDebug() << "Changing bridge setting:" << info;
|
||||
if(var=="blacklist/blockmins"){ CONFIG->setValue("blacklist_settings/blockmins",val.toInt()); }
|
||||
}
|
||||
else if( QString(argv[i])=="-clientport" && (i+1<argc)){ i++; cport = QString(argv[i]).toUInt(); }
|
||||
else if( QString(argv[i])=="-serverport" && (i+1<argc) ){ i++; sport = QString(argv[i]).toUInt(); }
|
||||
else if( (QString(argv[i])=="-port" || QString(argv[i])=="-p") && (i+1<argc)){ i++; port = QString(argv[i]).toUInt(); }
|
||||
else if( QString(argv[i])=="-set" && i+1<argc){ settingchange = true; }
|
||||
}
|
||||
if(settingchange){ return 0; }
|
||||
@@ -85,26 +83,17 @@ int main( int argc, char ** argv )
|
||||
|
||||
//Create the two servers and connect them
|
||||
qDebug() << "Starting the PC-BSD sysadm bridge....";
|
||||
BridgeServer cserver; //client side
|
||||
BridgeServer sserver; //server side
|
||||
QObject::connect(&cserver, SIGNAL(ForwardMessage(QString, QString)), &sserver, SLOT(SendMessage(QString, QString)) );
|
||||
QObject::connect(&sserver, SIGNAL(ForwardMessage(QString, QString)), &cserver, SLOT(SendMessage(QString, QString)) );
|
||||
|
||||
BridgeServer server;
|
||||
|
||||
//Start the servers
|
||||
int ret = 1; //error return value
|
||||
bool badstart = false;
|
||||
badstart = !cserver.startServer(cport);
|
||||
if(badstart){ qDebug() << "Could not start client-side server on port:" << cport; }
|
||||
else{ badstart = !sserver.startServer(sport); }
|
||||
if(badstart){ qDebug() << "Could not start server-side server on port:" << sport; }
|
||||
if(!server.startServer(port)){ qDebug() << "Could not start bridge server on port:" << port; }
|
||||
else{
|
||||
//Now start the main event loop
|
||||
qDebug() << "Bridge Started:" << QDateTime::currentDateTime().toString(Qt::ISODate);
|
||||
ret = a.exec();
|
||||
qDebug() << "Bridge Stopped:" << QDateTime::currentDateTime().toString(Qt::ISODate);
|
||||
}
|
||||
if(cserver.isListening()){ cserver.close(); }
|
||||
if(sserver.isListening()){ sserver.close(); }
|
||||
|
||||
//Cleanup any globals
|
||||
delete CONFIG;
|
||||
|
||||
Reference in New Issue
Block a user