From 407b9a8d5df5ba44dd89cc6442bc912455686ec2 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 2 Feb 2016 14:07:25 -0500 Subject: [PATCH] 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. --- src/server/EventWatcher.cpp | 10 ---- src/server/LogManager.h | 2 +- src/server/dispatcher-client.cpp | 88 -------------------------------- src/server/dispatcher-client.h | 31 ----------- src/server/server.pro | 2 - 5 files changed, 1 insertion(+), 132 deletions(-) delete mode 100644 src/server/dispatcher-client.cpp delete mode 100644 src/server/dispatcher-client.h diff --git a/src/server/EventWatcher.cpp b/src/server/EventWatcher.cpp index dedb90e..10d6d12 100644 --- a/src/server/EventWatcher.cpp +++ b/src/server/EventWatcher.cpp @@ -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(); } diff --git a/src/server/LogManager.h b/src/server/LogManager.h index eee6ac0..94e4636 100644 --- a/src/server/LogManager.h +++ b/src/server/LogManager.h @@ -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") diff --git a/src/server/dispatcher-client.cpp b/src/server/dispatcher-client.cpp deleted file mode 100644 index c5e63d3..0000000 --- a/src/server/dispatcher-client.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "dispatcher-client.h" -#include -#include - -#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 -#include -#include -#include - -#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 diff --git a/src/server/server.pro b/src/server/server.pro index a1c42e2..e99e9db 100644 --- a/src/server/server.pro +++ b/src/server/server.pro @@ -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 \