API CHANGE

Add a "groupadd" action to the sysadm/users class.
This will create a new group on the system
REQUIRED: "name"
OPTIONAL: "gid","users"

REST Request (example):
-------------------------------
PUT /sysadm/users
{
   "action" : "groupadd",
   "name" : "testgroup"
}

WebSocket Request:
-------------------------------
{
   "id" : "fooid",
   "namespace" : "sysadm",
   "args" : {
      "action" : "groupadd",
      "name" : "testgroup"
   },
   "name" : "users"
}

Response:
-------------------------------
{
  "args": {
    "result": "success"
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Ken Moore
2016-07-28 16:11:35 -04:00
parent a0d82f2367
commit 4a260b66e2
2 changed files with 18 additions and 1 deletions

View File

@@ -205,12 +205,26 @@ bool UserManager::listGroups(QJsonObject* out, QString user ){
out->insert(ginfo[0], obj);
}
}
if(!ok){ out->insert("error",info.join("\n")); }
return ok;
}
bool UserManager::addGroup(QJsonObject* out, QJsonObject input){
bool ok = false;
// REQUIRED: "name"
// OPTIONAL: "gid", "users"
if(input.contains("name")){
QStringList args;
args << "groupadd" << "-n" << input.value("name").toString();
if(input.contains("gid")){ args << "-g" << input.value("gid").toString(); }
if(input.contains("users")){
if(input.value("users").isArray()){ args << "-M" << General::JsonArrayToStringList(input.value("users").toArray()).join(","); }
else if(input.value("users").isString()){ args << "-M" << input.value("users").toString(); }
}
QString res = General::RunCommand(ok, "pw", args, "",QStringList() << "MM_CHARSET=UTF-8");
if(ok){ out->insert("result","success"); }
else{ out->insert("error", res); }
}
return ok;
}