mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
A bit more cleanup in the server.
Remove the dispatcher-client files (the dispatcher is now an internal system, not an external script). Clean up some comments and log stuff.
This commit is contained in:
@@ -108,15 +108,6 @@ void EventWatcher::DispatchFinished(QJsonObject obj){
|
||||
// === PRIVATE SLOTS ===
|
||||
void EventWatcher::WatcherUpdate(const QString &path){
|
||||
if(!starting){ qDebug() << "Event Watcher Update:" << path; }
|
||||
/*if(path==DISPATCHWORKING){
|
||||
//Read the file contents
|
||||
QString stat = readFile(DISPATCHWORKING);
|
||||
if(stat.simplified().isEmpty()){ stat = "idle"; }
|
||||
//qDebug() << "Dispatcher Update:" << stat;
|
||||
HASH.insert(DISPATCHER,stat); //save for later
|
||||
//Forward those contents on to the currently-open sockets
|
||||
emit NewEvent(DISPATCHER, QJsonValue(stat) );
|
||||
}else*/
|
||||
if(path==LPLOG){
|
||||
//Main Life Preserver Log File
|
||||
ReadLPLogFile();
|
||||
@@ -141,7 +132,6 @@ void EventWatcher::CheckLogFiles(){
|
||||
if(!watched.contains(LPLOG) && QFile::exists(LPLOG)){ watcher->addPath(LPLOG); }
|
||||
if(!watched.contains(LPERRLOG) && QFile::exists(LPERRLOG)){ watcher->addPath(LPERRLOG); }
|
||||
if(!watched.contains(tmpLPRepFile) && QFile::exists(tmpLPRepFile)){ watcher->addPath(tmpLPRepFile); }
|
||||
//if(!watched.contains(DISPATCHWORKING) && QFile::exists(LPLOG)){ watcher->addPath(DISPATCHWORKING); }
|
||||
//qDebug() << "watched:" << watcher->files() << watcher->directories();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//===========================================
|
||||
// Event Files (EV_*): JSON input/output (full event)
|
||||
// HOST: String input/output (simple messages)
|
||||
// DISPATCH: Full log of dispatcher processes
|
||||
// DISPATCH: Full log of dispatcher processes output (JSON)
|
||||
//===========================================
|
||||
#define LOGDIR QString("/var/log/sysadm")
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
#include "dispatcher-client.h"
|
||||
#include <QFile>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#define DISPATCH QString("/usr/local/share/appcafe/dispatcher")
|
||||
#define DISPATCHIDFILE QString("/var/tmp/appcafe/dispatch-id")
|
||||
#define DISPATCHENVVAR QString("PHP_DISID")
|
||||
|
||||
DispatcherClient::DispatcherClient(AuthorizationManager *auth, QObject *parent) : QProcess(parent){
|
||||
this->setProcessChannelMode(QProcess::MergedChannels);
|
||||
AUTH = auth;
|
||||
}
|
||||
|
||||
DispatcherClient::~DispatcherClient(){
|
||||
}
|
||||
|
||||
bool DispatcherClient::setupProcAuth(){
|
||||
//First check that the dispatcher binary actually exists
|
||||
if(!QFile::exists(DISPATCH) || AUTH==0){ qWarning() << "AppCafe Dispatcher binary not found:"; return false; }
|
||||
//Now check the current authorization key
|
||||
QString key = ReadKey();
|
||||
if(!AUTH->checkAuth(key) ){
|
||||
//Key now invalid - generate a new one (this ensures that the secure key rotates on a regular basis)
|
||||
key = AUTH->LoginService(QHostAddress::LocalHost, "dispatcher");
|
||||
//Save the auth key to the file and lock it down
|
||||
if(!WriteKey(key)){
|
||||
qWarning() << "Could not save dispatcher authorization key: **No dispatcher availability**. ";
|
||||
AUTH->clearAuth(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Now put that key into the process environment for the dispatcher to see/verify
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert("LANG", "C");
|
||||
env.insert("LC_ALL", "C");
|
||||
env.insert(DISPATCHENVVAR, key);
|
||||
this->setProcessEnvironment(env);
|
||||
return true;
|
||||
}
|
||||
|
||||
QString DispatcherClient::GetProcOutput(QString args){
|
||||
this->start(DISPATCH+" "+args);
|
||||
if(!this->waitForStarted(5000)){ return ""; } //process never started - max wait of 5 seconds
|
||||
while(!this->waitForFinished(1000)){
|
||||
if(this->state() != QProcess::Running){ break; } //somehow missed the finished signal
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
return QString(this->readAllStandardOutput());
|
||||
}
|
||||
|
||||
QStringList DispatcherClient::parseInputs(QStringList inputs, AuthorizationManager *auth){
|
||||
DispatcherClient client(auth);
|
||||
if(!client.setupProcAuth()){ return QStringList(); } //unauthorized
|
||||
QStringList outputs;
|
||||
for(int i=0; i<inputs.length(); i++){
|
||||
outputs << client.GetProcOutput(inputs[i]);
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
bool DispatcherClient::DispatcherAvailable(){
|
||||
return QFile::exists(DISPATCH);
|
||||
}
|
||||
|
||||
QString DispatcherClient::ReadKey(){
|
||||
QFile file(DISPATCHIDFILE);
|
||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ return ""; }
|
||||
QString key;
|
||||
QTextStream in(&file);
|
||||
key = in.readAll();
|
||||
file.close();
|
||||
return key;
|
||||
}
|
||||
|
||||
bool DispatcherClient::WriteKey(QString key){
|
||||
QFile file(DISPATCHIDFILE);
|
||||
if(!file.open(QIODevice::WriteOnly | QIODevice::Text)){ return false; }
|
||||
QTextStream out(&file);
|
||||
out << key;
|
||||
file.close();
|
||||
//Now lock down the file (root only read/write)
|
||||
if(!file.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner)){
|
||||
//Could not lock down the file - this is insecure and should not be used
|
||||
file.remove();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef _WEB_SERVER_DISPATCHER_CLIENT_MAIN_H
|
||||
#define _WEB_SERVER_DISPATCHER_CLIENT_MAIN_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
|
||||
#include "AuthorizationManager.h"
|
||||
|
||||
class DispatcherClient : public QProcess{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DispatcherClient(AuthorizationManager *auth, QObject *parent=0);
|
||||
~DispatcherClient();
|
||||
|
||||
bool setupProcAuth();
|
||||
QString GetProcOutput(QString args);
|
||||
|
||||
//Static function to run a request and wait for it to finish before returning
|
||||
static QStringList parseInputs(QStringList inputs, AuthorizationManager *auth);
|
||||
static bool DispatcherAvailable();
|
||||
|
||||
private:
|
||||
AuthorizationManager *AUTH;
|
||||
|
||||
QString ReadKey();
|
||||
bool WriteKey(QString key);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,6 @@ HEADERS += globals.h globals-qt.h \
|
||||
WebServer.h \
|
||||
WebSocket.h \
|
||||
syscache-client.h \
|
||||
dispatcher-client.h \
|
||||
RestStructs.h \
|
||||
AuthorizationManager.h \
|
||||
SslServer.h \
|
||||
@@ -21,7 +20,6 @@ SOURCES += main.cpp \
|
||||
WebSocket.cpp \
|
||||
WebBackend.cpp \
|
||||
syscache-client.cpp \
|
||||
dispatcher-client.cpp \
|
||||
AuthorizationManager.cpp \
|
||||
EventWatcher.cpp \
|
||||
LogManager.cpp \
|
||||
|
||||
Reference in New Issue
Block a user