diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 494aeca..6b755dc 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -33,7 +33,7 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO */ // - server settings (always available) out->insert("sysadm/settings","read/write"); - + // - syscache if(QFile::exists("/var/run/syscache.pipe")){ out->insert("rpc/syscache","read"); //no write to syscache - only reads @@ -150,9 +150,9 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSettingsRequest(const QJsonV }else if(act=="revoke_ssl_cert" && keys.contains("pub_key") ){ //Additional arguments: "user" (optional), "pub_key" (String) QString user; if(keys.contains("user")){ user = argsO.value("user").toString(); } - ok = AUTHSYSTEM->RevokeCertificate(SockAuthToken,argsO.value("pub_key").toString(), user); + ok = AUTHSYSTEM->RevokeCertificate(SockAuthToken,argsO.value("pub_key").toString(), user); } - + if(ok){ return RestOutputStruct::OK; } else{ return RestOutputStruct::BADREQUEST; } } @@ -471,6 +471,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal bool ok = false; if(keys.contains("action")){ QString act = JsonValueToString(in_args.toObject().value("action")); + if(act=="createjail"){ + ok = true; + out->insert("createjail", sysadm::Iocage::createJail(in_args.toObject())); + } if(act=="clonejail"){ ok = true; out->insert("clonejail", sysadm::Iocage::cloneJail(in_args.toObject())); diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index 9b0133b..2ebd8be 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -12,6 +12,51 @@ using namespace sysadm; //PLEASE: Keep the functions in the same order as listed in pcbsd-general.h +// Create a jail on the box +QJsonObject Iocage::createJail(QJsonObject jsin) { + QJsonObject retObject; + + QStringList keys = jsin.keys(); + + // Get the key values + QString switches = jsin.value("switches").toString(); + QString props = jsin.value("props").toString(); + QStringList output; + + if ( keys.contains("switches" ) ) { + output = General::RunCommand("iocage create " + switches + " " + props).split("\n"); + } else { + output = General::RunCommand("iocage create " + props).split("\n"); + } + + QJsonObject vals; + for ( int i = 0; i < output.size(); i++) + { + if ( output.at(i).isEmpty() ) + break; + + if ( output.at(i).indexOf("ERROR:") != -1 ) { + retObject.insert("error", output.at(i)); + return retObject; + } else { + QString key = output.at(i).simplified().section(":", 0, 0); + QString value = output.at(i).simplified().section(":", 1, 1); + + if ( keys.contains("switches" ) ) { + vals.insert("uuid", key); + } else { + vals.insert(key, value); + } + } + } + + retObject.insert("switches", switches); + retObject.insert("props", props); + retObject.insert("success", vals); + + return retObject; +} + // Clone a jail on the box QJsonObject Iocage::cloneJail(QJsonObject jsin) { QJsonObject retObject; @@ -38,8 +83,8 @@ QJsonObject Iocage::cloneJail(QJsonObject jsin) { retObject.insert("error", output.at(i)); return retObject; } else { - QString key = output.at(i).simplified().section(":", 0, 0); - QString value = output.at(i).simplified().section(":", 1, 1); + QString key = output.at(i).simplified().section(":", 0, 0); + QString value = output.at(i).simplified().section(":", 1, 1); vals.insert(key, value); } diff --git a/src/server/library/sysadm-iocage.h b/src/server/library/sysadm-iocage.h index e3e6471..52785c0 100644 --- a/src/server/library/sysadm-iocage.h +++ b/src/server/library/sysadm-iocage.h @@ -14,6 +14,7 @@ namespace sysadm{ class Iocage{ public: + static QJsonObject createJail(QJsonObject); static QJsonObject cloneJail(QJsonObject); static QJsonObject cleanAll(); static QJsonObject cleanTemplates();