store tokens in QByteArray, minor fixes
This commit is contained in:
parent
0198da6595
commit
fd57796114
4 changed files with 11 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
project(smsub LANGUAGES CXX VERSION 0.10)
|
project(smsub LANGUAGES CXX VERSION 0.10.1)
|
||||||
|
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
|
|
@ -113,15 +113,15 @@ void SMSubServer::newConnection()
|
||||||
bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
|
bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
|
||||||
{
|
{
|
||||||
// Only allow commands being sent if authenticated
|
// Only allow commands being sent if authenticated
|
||||||
const bool isAuthenticated = socket->property("Authenticated").toBool();
|
const bool isAuthenticated = isVariantTrue(socket->property("Authenticated"));
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
if (message == "+dbg") {
|
if (message == "+dbg") {
|
||||||
socket->setProperty("ReceiveDbgMsg", true);
|
socket->setProperty("ReceiveDbgMsg", true);
|
||||||
sendMessage(socket, "Debug messages enabled!\n");
|
debugOutput(socket, "Debug messages enabled!");
|
||||||
}
|
}
|
||||||
else if (message == "-dbg") {
|
else if (message == "-dbg") {
|
||||||
|
debugOutput(socket, "Debug messages disabled!");
|
||||||
socket->setProperty("ReceiveDbgMsg", false);
|
socket->setProperty("ReceiveDbgMsg", false);
|
||||||
sendMessage(socket, "Debug messages disabled!\n");
|
|
||||||
}
|
}
|
||||||
else if (message == "+json") {
|
else if (message == "+json") {
|
||||||
socket->setProperty("ReceiveJson", true);
|
socket->setProperty("ReceiveJson", true);
|
||||||
|
@ -152,7 +152,7 @@ bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
|
||||||
QByteArray authUuid = QUuid::createUuid().toByteArray(QUuid::Id128) +
|
QByteArray authUuid = QUuid::createUuid().toByteArray(QUuid::Id128) +
|
||||||
QUuid::createUuid().toByteArray(QUuid::Id128);
|
QUuid::createUuid().toByteArray(QUuid::Id128);
|
||||||
authUuid = QByteArray::fromHex(authUuid).toBase64(QByteArray::OmitTrailingEquals);
|
authUuid = QByteArray::fromHex(authUuid).toBase64(QByteArray::OmitTrailingEquals);
|
||||||
emit tokenRegistered(QString::fromUtf8(authUuid));
|
emit tokenRegistered(authUuid);
|
||||||
sendMessage(socket, "Token: " + authUuid + '\n');
|
sendMessage(socket, "Token: " + authUuid + '\n');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -215,7 +215,7 @@ bool SMSubServer::messageReceived(QObject *socket, const QByteArray &message)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Authenticate when token is valid, otherwise disconnect
|
// Authenticate when token is valid, otherwise disconnect
|
||||||
if (tokens.contains(QString::fromUtf8(message))) {
|
if (tokens.contains(message)) {
|
||||||
// Set client as authenticated and add it to vector
|
// Set client as authenticated and add it to vector
|
||||||
socket->setProperty("Authenticated", true);
|
socket->setProperty("Authenticated", true);
|
||||||
sendMessage(socket, "Login successful!\n");
|
sendMessage(socket, "Login successful!\n");
|
||||||
|
@ -349,7 +349,7 @@ void SMSubServer::sendMessage(QObject *socket, const QByteArray &message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SMSubServer::registerToken(const QString &token)
|
void SMSubServer::registerToken(const QByteArray &token)
|
||||||
{
|
{
|
||||||
// Register temporary token for a secure remote connection
|
// Register temporary token for a secure remote connection
|
||||||
tokens << token;
|
tokens << token;
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void writeOutput(const QByteArray &output);
|
void writeOutput(const QByteArray &output);
|
||||||
void registerToken(const QString &token);
|
void registerToken(const QByteArray &token);
|
||||||
void statusUpdated(const bool status, const qint64 time);
|
void statusUpdated(const bool status, const qint64 time);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -60,7 +60,7 @@ private:
|
||||||
inline bool isVariantTrue(const QVariant &variant);
|
inline bool isVariantTrue(const QVariant &variant);
|
||||||
SMSubServerSettings *serverSettings;
|
SMSubServerSettings *serverSettings;
|
||||||
QVector<QObject*> sockets;
|
QVector<QObject*> sockets;
|
||||||
QVector<QString> tokens;
|
QVector<QByteArray> tokens;
|
||||||
qint64 startTime;
|
qint64 startTime;
|
||||||
qint64 stopTime;
|
qint64 stopTime;
|
||||||
ServerType type;
|
ServerType type;
|
||||||
|
@ -68,7 +68,7 @@ private:
|
||||||
bool status;
|
bool status;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void tokenRegistered(const QString &password);
|
void tokenRegistered(const QByteArray &token);
|
||||||
void inputWritten(const QByteArray &input);
|
void inputWritten(const QByteArray &input);
|
||||||
void startRequested();
|
void startRequested();
|
||||||
void stopRequested();
|
void stopRequested();
|
||||||
|
|
2
main.cpp
2
main.cpp
|
@ -134,7 +134,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
a.setApplicationName("Server Manager Subprocess");
|
a.setApplicationName("Server Manager Subprocess");
|
||||||
a.setApplicationVersion("0.10");
|
a.setApplicationVersion("0.10.1");
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
catchUnixSignals({SIGINT, SIGHUP, SIGQUIT, SIGTERM});
|
catchUnixSignals({SIGINT, SIGHUP, SIGQUIT, SIGTERM});
|
||||||
|
|
Loading…
Reference in a new issue