API CHANGE

Add 3 new API calls (all almost the same - just different "actions" and the return message will be slightly different)

"action":"start" OR "stop" OR "restart"
This will [start/stop/restart] services on the system.
REQUIRED ARGUMENTS:
"services" : <string with a single service, or array of services>

EXAMPLE "start" command (change "services_started" in responce to "services_[started/stopped/restarted]" as needed to match the action:

REST Request (example):
-------------------------------
PUT /sysadm/services
{
   "action" : "start",
   "services" : [
      "cupsd"
   ]
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "action" : "start",
      "services" : [
         "cupsd"
      ]
   },
   "name" : "services",
   "id" : "fooid",
   "namespace" : "sysadm"
}

Response:
-------------------------------
{
  "args": {
    "services_started": [
      "cupsd"
    ]
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Ken Moore
2016-08-30 11:27:51 -04:00
parent 200a7de9e0
commit 8a594044bb
2 changed files with 48 additions and 0 deletions

View File

@@ -1019,7 +1019,50 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmServiceRequest(const QJsonVa
}
ok = true;
out->insert("services",services);
}else if(action=="start" && in_args.toObject().contains("services") ){
QJsonValue sval = in_args.toObject().value("services");
QStringList services;
if(sval.isString()){ services << sval.toString(); }
else if(sval.isArray()){ services = JsonArrayToStringList(sval.toArray()); }
if(!services.isEmpty()){
QStringList success;
ok = true;
for(int i=0; i<services.length(); i++){
if( SMGR.Start( SMGR.GetService(services[i]) ) ){ success << services[i]; }
}
out->insert("services_started", QJsonArray::fromStringList(success));
}
}else if(action=="stop" && in_args.toObject().contains("services") ){
QJsonValue sval = in_args.toObject().value("services");
QStringList services;
if(sval.isString()){ services << sval.toString(); }
else if(sval.isArray()){ services = JsonArrayToStringList(sval.toArray()); }
if(!services.isEmpty()){
QStringList success;
ok = true;
for(int i=0; i<services.length(); i++){
if( SMGR.Stop( SMGR.GetService(services[i]) ) ){ success << services[i]; }
}
out->insert("services_stopped", QJsonArray::fromStringList(success));
}
}else if(action=="restart" && in_args.toObject().contains("services") ){
QJsonValue sval = in_args.toObject().value("services");
QStringList services;
if(sval.isString()){ services << sval.toString(); }
else if(sval.isArray()){ services = JsonArrayToStringList(sval.toArray()); }
if(!services.isEmpty()){
QStringList success;
ok = true;
for(int i=0; i<services.length(); i++){
if( SMGR.Restart( SMGR.GetService(services[i]) ) ){ success << services[i]; }
}
out->insert("services_restarted", QJsonArray::fromStringList(success));
}
}
if(out->keys().isEmpty()){
if(ok){ out->insert("result","success"); }
else{ out->insert("error","error"); }