diff --git a/src/server/DispatcherParsing.cpp b/src/server/DispatcherParsing.cpp index 49c04f1..0f6039f 100644 --- a/src/server/DispatcherParsing.cpp +++ b/src/server/DispatcherParsing.cpp @@ -43,6 +43,20 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec namesp = "sysadm"; name="update"; //No special parsing here: the pc-updatemanager output should be available as-is args.insert("update_log",cLog); + + + // == sysadm/pkg == + }else if(ID.startsWith("sysadm_pkg")){ + namesp = "sysadm"; name="pkg"; + //most pkg commands have no special parsing the pkg output should be available as-is + args.insert("pkg_log",cLog); + args.insert("action", ID.section("-",0,0).section("_pkg_",-1) ); //so the client/user can tell which type of pkg action this is for + if(ID.section("-",0,0)=="sysadm_pkg_check_upgrade"){ + if(isFinished){ + bool hasupdates = !cLog.section("\n",-1,QString::SectionSkipEmpty).contains("packages are up to date"); + args.insert("updates_available", hasupdates ? "true" : "false"); + } + } } //Now assemble the output as needed diff --git a/src/server/globals-qt.h b/src/server/globals-qt.h index 0f5b927..5440fb5 100644 --- a/src/server/globals-qt.h +++ b/src/server/globals-qt.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include diff --git a/src/server/library/sysadm-pkg.cpp b/src/server/library/sysadm-pkg.cpp index 12ddb85..4fbd4bd 100644 --- a/src/server/library/sysadm-pkg.cpp +++ b/src/server/library/sysadm-pkg.cpp @@ -225,6 +225,15 @@ QStringList PKG::pkg_search(QString repo, QString searchterm, QString category){ while(query.next()){ found << query.value("origin").toString(); //need the origin for later } + if(found.isEmpty()){ + //Expand the search to names containing the term + q_string = "SELECT origin FROM packages WHERE name LIKE '%"+searchterm+"%'"; + if(!category.isEmpty()){ q_string.append(" AND origin LIKE '"+category+"/%'"); } + QSqlQuery q2(q_string); + while(q2.next()){ + found << q2.value("origin").toString(); //need the origin for later + } + } if(found.isEmpty()){ //Expand the search to comments q_string = "SELECT origin FROM packages WHERE comment LIKE '%"+searchterm+"%'"; @@ -275,12 +284,23 @@ QJsonArray PKG::list_categories(QString repo){ //qDebug() << " - could not be opened"; return QJsonArray(); } + //Get all the pkg origins for this repo + QStringList origins; + QSqlQuery q_o("SELECT origin FROM packages"); + while(q_o.next()){ + origins << q_o.value("origin").toString(); //need the origin for later + } + //Now get all the categories QString q_string = "SELECT name FROM categories"; QSqlQuery query(q_string); QStringList found; while(query.next()){ found << query.value("name").toString(); //need the origin for later } + //Now check all the categories to ensure that pkgs exist within it + for(int i=0; iqueueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} + +QJsonObject PKG::pkg_remove(QStringList origins, bool recursive){ + //Generate the command to run + QString cmd = "pkg delete -y %1"; + if(recursive){ cmd = cmd.arg("-R %1"); } //also remove all packages which depend on these pkgs + cmd = cmd.arg( origins.join(" ") ); + //Now kick off the dispatcher process (within the pkg queue - since only one pkg process can run at a time) + QString ID = "sysadm_pkg_remove-"+QUuid::createUuid().toString(); //create a random tag for the process + DISPATCHER->queueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} + +QJsonObject PKG::pkg_lock(QStringList origins){ + //Generate the command to run + QString cmd = "pkg lock -y %1"; + cmd = cmd.arg( origins.join(" ") ); + //Now kick off the dispatcher process (within the pkg queue - since only one pkg process can run at a time) + QString ID = "sysadm_pkg_lock-"+QUuid::createUuid().toString(); //create a random tag for the process + DISPATCHER->queueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} + +QJsonObject PKG::pkg_unlock(QStringList origins){ + //Generate the command to run + QString cmd = "pkg unlock -y %1"; + cmd = cmd.arg( origins.join(" ") ); + //Now kick off the dispatcher process (within the pkg queue - since only one pkg process can run at a time) + QString ID = "sysadm_pkg_unlock-"+QUuid::createUuid().toString(); //create a random tag for the process + DISPATCHER->queueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} + +//================== +//pkg administration routines +//================== +QJsonObject PKG::pkg_update(bool force){ + //Generate the command to run + QString cmd = "pkg update"; + if(force){ cmd.append(" -f"); } + //Now kick off the dispatcher process (within the pkg queue - since only one pkg process can run at a time) + QString ID = "sysadm_pkg_update-"+QUuid::createUuid().toString(); //create a random tag for the process + DISPATCHER->queueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} + +QJsonObject PKG::pkg_check_upgrade(){ + //Generate the command to run + QString cmd = "pkg upgrade -n"; + //Now kick off the dispatcher process (within the pkg queue - since only one pkg process can run at a time) + QString ID = "sysadm_pkg_check_upgrade-"+QUuid::createUuid().toString(); //create a random tag for the process + DISPATCHER->queueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} + +QJsonObject PKG::pkg_upgrade(){ + //Generate the command to run + QString cmd = "pkg upgrade -y"; + //Now kick off the dispatcher process (within the pkg queue - since only one pkg process can run at a time) + QString ID = "sysadm_pkg_upgrade-"+QUuid::createUuid().toString(); //create a random tag for the process + DISPATCHER->queueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} + +QJsonObject PKG::pkg_audit(){ + //Generate the command to run + QString cmd = "pkg audit -qr"; + //Now kick off the dispatcher process (within the pkg queue - since only one pkg process can run at a time) + QString ID = "sysadm_pkg_audit-"+QUuid::createUuid().toString(); //create a random tag for the process + DISPATCHER->queueProcess(Dispatcher::PKG_QUEUE, ID, cmd); + //Now return the info about the process + QJsonObject obj; + obj.insert("status", "pending"); + obj.insert("proc_cmd",cmd); + obj.insert("proc_id",ID); + return obj; +} diff --git a/src/server/library/sysadm-pkg.h b/src/server/library/sysadm-pkg.h index d33e6ab..2871250 100644 --- a/src/server/library/sysadm-pkg.h +++ b/src/server/library/sysadm-pkg.h @@ -14,14 +14,29 @@ #include #include #include + namespace sysadm{ class PKG{ public: + //Information fetch routines static QJsonObject pkg_info(QStringList origins, QString repo, QString category = "", bool fullresults = true); static QStringList pkg_search(QString repo, QString searchterm, QString category = ""); static QJsonArray list_categories(QString repo); static QJsonArray list_repos(); + + //pkg modification routines (dispatcher events for notifications) + static QJsonObject pkg_install(QStringList origins, QString repo); + static QJsonObject pkg_remove(QStringList origins, bool recursive = true); + static QJsonObject pkg_lock(QStringList origins); //local/installed pkgs only + static QJsonObject pkg_unlock(QStringList origins); //local/installed pkgs only + + //pkg administration routines + static QJsonObject pkg_update(bool force = false); //update databases + static QJsonObject pkg_check_upgrade(); //Check for updates to pkgs + static QJsonObject pkg_upgrade(); //upgrade all pkgs (use sysadm/updates if possible instead) + static QJsonObject pkg_audit(); //List details of vulnerable packages + }; } //end of sysadm namespace