From d219c14a87c23db477b03659435535680e0f9c6b Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Fri, 11 Dec 2015 13:38:17 -0500 Subject: [PATCH] Add the new sysadm-lifepreserver class, with example listCron() function so we can test --- src/binary/main.cpp | 7 +++++ src/library/library.pro | 2 ++ src/library/sysadm-lifepreserver.cpp | 46 ++++++++++++++++++++++++++++ src/library/sysadm-lifepreserver.h | 22 +++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 src/library/sysadm-lifepreserver.cpp create mode 100644 src/library/sysadm-lifepreserver.h diff --git a/src/binary/main.cpp b/src/binary/main.cpp index d2dde81..4ec38df 100644 --- a/src/binary/main.cpp +++ b/src/binary/main.cpp @@ -1,6 +1,7 @@ #include #include +#include #include int main( int argc, char ** argv ) @@ -47,6 +48,12 @@ int main( int argc, char ** argv ) qDebug() << " - Static Gateway:" << set.staticGateway; qDebug() << " - Allow Secure Wifi:" << set.wifisecurity; } + + // LP tests + qDebug() << "Life-Preserver::listCron()"; + QList cronSnaps = sysadm::LifePreserver::listCron(); + for ( int i = 0; i < cronSnaps.size(); i++) + qDebug() << cronSnaps.at(i); return 0; } diff --git a/src/library/library.pro b/src/library/library.pro index e99231f..114c2b2 100644 --- a/src/library/library.pro +++ b/src/library/library.pro @@ -12,10 +12,12 @@ VERSION = 1.0.0 HEADERS += sysadm-global.h \ sysadm-general.h \ + sysadm-lifepreserver.h \ sysadm-network.h SOURCES += sysadm-general.cpp \ + sysadm-lifepreserver.cpp \ sysadm-network.cpp \ NetDevice.cpp diff --git a/src/library/sysadm-lifepreserver.cpp b/src/library/sysadm-lifepreserver.cpp new file mode 100644 index 0000000..c2ed101 --- /dev/null +++ b/src/library/sysadm-lifepreserver.cpp @@ -0,0 +1,46 @@ +//=========================================== +// PC-BSD source code +// Copyright (c) 2015, PC-BSD Software/iXsystems +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "sysadm-general.h" +#include "sysadm-lifepreserver.h" +//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h + +#include "sysadm-global.h" + +using namespace sysadm; + +// Build list of scheduled cron snapshot jobs +QList LifePreserver::listCron() { + QStringList output = General::RunCommand("lpreserver listcron").split("\n"); + QList snaps; + QStringList snapitems; + + // Parse the output + bool inSection = false; + for ( int i = 0; i < output.size(); i++) + { + if ( output.at(i).indexOf("-----------------") != -1 ) { + inSection = true; + continue; + } + + if (!inSection) + continue; + + if ( output.at(i).isEmpty() || output.at(i).indexOf("-----------------") != -1 ) + break; + + // Save this cron job + snapitems.clear(); + snapitems << output.at(i).section("-", 0, 0).simplified(); + snapitems << output.at(i).section("-", 1, 1).simplified(); + snapitems << output.at(i).section("-", 2, 2).simplified().replace("total: ", ""); + + snaps << snapitems; + } + + return snaps; +} diff --git a/src/library/sysadm-lifepreserver.h b/src/library/sysadm-lifepreserver.h new file mode 100644 index 0000000..fba0635 --- /dev/null +++ b/src/library/sysadm-lifepreserver.h @@ -0,0 +1,22 @@ +//=========================================== +// PC-BSD source code +// Copyright (c) 2015, PC-BSD Software/iXsystems +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef __PCBSD_LIB_UTILS_LIFEPRESERVER_H +#define __PCBSD_LIB_UTILS_LIFEPRESERVER_H + +#include "sysadm-global.h" + +namespace sysadm{ + +class LifePreserver{ +public: + // List schedule snapshots + static QList listCron(); +}; + +} //end of pcbsd namespace + +#endif