diff --git a/src/server/DispatcherParsing.cpp b/src/server/DispatcherParsing.cpp index 6413385..77ef1ff 100644 --- a/src/server/DispatcherParsing.cpp +++ b/src/server/DispatcherParsing.cpp @@ -10,6 +10,8 @@ #include "EventWatcher.h" #include "Dispatcher.h" #include "library/sysadm-update.h" +#include "library/sysadm-sourcectl.h" + QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObject log, bool full_log){ //NOTE: full_log = true when the process has finished. If it is false, the process is still running and you are probably getting an incremental update of the process log @@ -79,8 +81,33 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec args.insert("impacts_pkgs",QJsonArray::fromStringList(effects)); } + // == sysadm/sourcecrl == + }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_downloadsource"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadsource"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::saveSourceLog(cLog); //save this for use later } + }else if(ID.startsWith("sysadm_sourcectl")){ + if(ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){ + namesp = "sysadm"; name="soucectl"; + //No special parsing here: the git output should be available as-is + args.insert("update_log",cLog); + }else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){ + //qDebug() << "Got update check process finished"; + sysadm::sourcectl::savePortsLog(cLog); //save this for use later +} +} + +//Now assemble the output as needed +if(namesp.isEmpty() || name.isEmpty()){ return QJsonObject(); } //no event +args.insert("event_system",namesp+"/"+name); +return args; + //Now assemble the output as needed if(namesp.isEmpty() || name.isEmpty()){ return QJsonObject(); } //no event args.insert("event_system",namesp+"/"+name); diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index b711768..4a616f5 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -25,6 +25,7 @@ #include "library/sysadm-firewall.h" #include "library/sysadm-moused.h" #include "library/sysadm-powerd.h" +#include "library/sysadm-sourcectl.h" #define DEBUG 0 //#define SCLISTDELIM QString("::::") //SysCache List Delimiter @@ -45,7 +46,6 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO out->insert("sysadm/beadm", "read/write"); } - // - dispatcher (Internal to server - always available) //"read" is the event notifications, "write" is the ability to queue up jobs out->insert("rpc/dispatcher", allaccess ? "read/write" : "read"); @@ -104,6 +104,10 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO if(QFile::exists("/usr/sbin/powerd")){ out->insert("sysadm/powerd", "read/write"); } + // - sourcectl + if(QFile::exists("/usr/local/bin/git")){ + out->insert("sysadm/sourcectl", "read/write"); + } return RestOutputStruct::OK; } @@ -164,6 +168,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru return EvaluateSysadmMousedRequest(IN.args, out); }else if(namesp=="sysadm" && name=="powerd"){ return EvaluateSysadmPowerdRequest(IN.args, out); + }else if(namesp=="sysadm" && name=="sourcectl"){ + return EvaluateSysadmSourceCTLRequest(IN.args, out); }else{ return RestOutputStruct::BADREQUEST; } @@ -1329,3 +1335,33 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPowerdRequest(const QJsonVal return RestOutputStruct::BADREQUEST; } } + +// ==== SYSADM SOURCECTL API ==== +RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSourceCTLRequest(const QJsonValue in_args, QJsonObject *out){ + QString action = in_args.toObject().value("action").toString(); + QJsonObject outobj; + if(action == "downloadports"){ + outobj = sysadm::sourcectl::downloadports(); + }else if(action == "updateports"){ + outobj = sysadm::sourcectl::updateports(); + }else if(action == "deleteports"){ + outobj = sysadm::sourcectl::deleteports(); + }else if(action == "stopports"){ + outobj = sysadm::sourcectl::stopports(); + }else if(action == "downloadsource"){ + outobj = sysadm::sourcectl::downloadsource(); + }else if(action == "updatesource"){ + outobj = sysadm::sourcectl::updatesource(); + }else if(action == "deletesource"){ + outobj = sysadm::sourcectl::deletesource(); + }else if(action == "stopsource"){ + outobj = sysadm::sourcectl::stopsource(); + //check return structure for validity + if(!outobj.keys().isEmpty()){ + out->insert(action, outobj); + return RestOutputStruct::OK; + }else{ + return RestOutputStruct::BADREQUEST; + } + } +} diff --git a/src/server/WebSocket.h b/src/server/WebSocket.h index e0f0673..128401e 100644 --- a/src/server/WebSocket.h +++ b/src/server/WebSocket.h @@ -100,6 +100,8 @@ private: RestOutputStruct::ExitCode EvaluateSysadmMousedRequest(const QJsonValue in_args, QJsonObject *out); // -- sysadm powerd API RestOutputStruct::ExitCode EvaluateSysadmPowerdRequest(const QJsonValue in_args, QJsonObject *out); + // -- sysadm sourcectl API + RestOutputStruct::ExitCode EvaluateSysadmSourceCTLRequest(const QJsonValue in_args, QJsonObject *out); private slots: void sendReply(QString msg); diff --git a/src/server/library/library.pri b/src/server/library/library.pri index ef6042a..5a1d124 100644 --- a/src/server/library/library.pri +++ b/src/server/library/library.pri @@ -17,7 +17,9 @@ HEADERS += $${PWD}/sysadm-global.h \ $${PWD}/sysadm-zfs.h \ $${PWD}/sysadm-pkg.h \ $${PWD}/sysadm-moused.h \ - $${PWD}/sysadm-powerd.h + $${PWD}/sysadm-powerd.h \ + $${PWD}/sysadm-sourcectl.h + SOURCES += $${PWD}/NetDevice.cpp \ $${PWD}/sysadm-general.cpp \ @@ -35,4 +37,5 @@ SOURCES += $${PWD}/NetDevice.cpp \ $${PWD}/sysadm-zfs.cpp \ $${PWD}/sysadm-pkg.cpp \ $${PWD}/sysadm-moused.cpp \ - $${PWD}/sysadm-powerd.cpp + $${PWD}/sysadm-powerd.cpp \ + $${PWD}/sysadm-sourcectl.cpp