diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index de0b17b..9ae2e91 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -1004,11 +1004,15 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmServiceRequest(const QJsonVa sysadm::ServiceManager SMGR; if(action=="list_services"){ QList list = SMGR.GetServices(); + QList listEnabled = SMGR.isEnabled(list); QJsonObject services; for(int i=0; i ServiceManager::GetServices() return services; } +QList ServiceManager::isRunning(QList services){ + //return list in the same order as the input list + QList out; + for(int i=0; i run = isRunning( QList() << service); + if(!run.isEmpty()){ return run.first(); } + else{ return false; } +} + +QList ServiceManager::isEnabled(QList services){ + //return list in the same order as the input list + QList out; + //Read all the rc.conf files in highest-priority order + QHash data; + QDir dir("/etc"); + QStringList confs = dir.entryList(QStringList() << "rc.conf*", QDir::Files, QDir::Name | QDir::Reversed); + qDebug() << "Conf file order:" << confs; + for(int i=0; i use = isEnabled( QList() << service); + if(!use.isEmpty()){ return use.first(); } + else{ return false; } +} + void ServiceManager::Start(Service service) { // Start the process @@ -120,7 +187,8 @@ Service ServiceManager::loadServices(QString name) if ( file.open( QIODevice::ReadOnly ) ) { valid=false; - service.Directory=directory[i]; + service.Directory=directory[i]; //filename only + service.Path = dir+"/"+directory[i]; //full path w/ filename QTextStream stream( &file ); stream.setCodec("UTF-8"); QString line; @@ -159,6 +227,9 @@ Service ServiceManager::loadServices(QString name) service.Tag=service.Tag + "_enable"; break; } + if (line.simplified().startsWith("desc=")) { + service.Description = line.section("=\"",1,-1).section("\"",0,0); + } } file.close(); diff --git a/src/server/library/sysadm-servicemanager.h b/src/server/library/sysadm-servicemanager.h index 1721bfb..55c69dc 100644 --- a/src/server/library/sysadm-servicemanager.h +++ b/src/server/library/sysadm-servicemanager.h @@ -16,6 +16,8 @@ struct Service{ QString Name; QString Tag; QString Directory; + QString Path; + QString Description; }; class ServiceManager @@ -40,6 +42,12 @@ public: */ QList GetServices(); + QList isRunning(QList services); //return list in the same order as the input list + bool isRunning(Service service); //single-item overload + + QList isEnabled(QList services); //return list in the same order as the input list + bool isEnabled(Service service); //single-item overload + /** * @brief Start starts a service * @param service the service to start