mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Added starting iocage jail API call
Websocket is duplicated after REST call, so it actually shows the jail as up since the REST request has already run
REST Request:
-------------------------------
PUT /sysadm/iocage
{
"action" : "startjail",
"jail" : "test"
}
REST Response:
-------------------------------
{
"args": {
"startjail": {
"test": {
"* Starting 0bf985de-ca0f-11e5-8d45-d05099728dbf (test)": "",
"+ Started (shared IP mode) OK": "",
"+ Starting services OK": ""
}
}
}
}
WebSocket Request:
-------------------------------
{
"namespace" : "sysadm",
"id" : "fooid",
"args" : {
"action" : "startjail",
"jail" : "test"
},
"name" : "iocage"
}
WebSocket Response:
-------------------------------
{
"args": {
"startjail": {
"test": {
"INFO": " 0bf985de-ca0f-11e5-8d45-d05099728dbf (test) is already up"
}
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -39,10 +39,10 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO
|
||||
// - dispatcher (Internal to server - always available)
|
||||
//"read" is the event notifications, "write" is the ability to queue up jobs
|
||||
out->insert("rpc/dispatcher", allaccess ? "read/write" : "read");
|
||||
|
||||
|
||||
// - network
|
||||
out->insert("sysadm/network","read/write");
|
||||
|
||||
|
||||
// - lifepreserver
|
||||
if(QFile::exists("/usr/local/bin/lpreserver")){
|
||||
out->insert("sysadm/lifepreserver", "read/write");
|
||||
@@ -52,7 +52,7 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO
|
||||
if(QFile::exists("/usr/local/sbin/iocage")){
|
||||
out->insert("sysadm/iocage", "read/write");
|
||||
}
|
||||
|
||||
|
||||
// - iohyve
|
||||
if(QFile::exists("/usr/local/sbin/iohyve")){
|
||||
out->insert("sysadm/iohyve", "read/write");
|
||||
@@ -70,14 +70,14 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO
|
||||
}
|
||||
|
||||
RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStruct &IN, QJsonObject *out){
|
||||
/*Inputs:
|
||||
/*Inputs:
|
||||
"namesp" - namespace for the request
|
||||
"name" - name of the request
|
||||
"args" - JSON input arguments structure
|
||||
"out" - JSON output arguments structure
|
||||
*/
|
||||
QString namesp = IN.namesp.toLower(); QString name = IN.name.toLower();
|
||||
|
||||
|
||||
//Get/Verify subsystems
|
||||
if(namesp=="rpc" && name=="query"){
|
||||
return AvailableSubsystems(IN.fullaccess, out);
|
||||
@@ -86,8 +86,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru
|
||||
AvailableSubsystems(IN.fullaccess, &avail);
|
||||
if(!avail.contains(namesp+"/"+name)){ return RestOutputStruct::NOTFOUND; }
|
||||
}
|
||||
|
||||
//Go through and forward this request to the appropriate sub-system
|
||||
|
||||
//Go through and forward this request to the appropriate sub-system
|
||||
if(namesp=="rpc" && name=="dispatcher"){
|
||||
return EvaluateDispatcherRequest(IN.fullaccess, IN.args, out);
|
||||
}else if(namesp=="sysadm" && name=="iocage"){
|
||||
@@ -105,7 +105,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru
|
||||
}else if(namesp=="sysadm" && name=="update"){
|
||||
return EvaluateSysadmUpdateRequest(IN.args, out);
|
||||
}else{
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -148,7 +148,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(bool allaccess,
|
||||
//dispatcher only needs a list of sub-commands at the moment (might change later)
|
||||
if(!in_args.isObject() || !in_args.toObject().contains("action") ){ return RestOutputStruct::BADREQUEST; }
|
||||
QString act = in_args.toObject().value("action").toString().toLower();
|
||||
|
||||
|
||||
//Determing the type of action to perform
|
||||
if(act=="run"){
|
||||
if(!allaccess){ return RestOutputStruct::FORBIDDEN; } //this user does not have permission to queue jobs
|
||||
@@ -160,10 +160,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(bool allaccess,
|
||||
QJsonValue val = in_args.toObject().value(ids[i]);
|
||||
if(val.isArray()){ cmds = JsonArrayToStringList(val.toArray()); }
|
||||
else if(val.isString()){ cmds << val.toString(); }
|
||||
else{
|
||||
ids.removeAt(i);
|
||||
i--;
|
||||
continue;
|
||||
else{
|
||||
ids.removeAt(i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
//queue up this process
|
||||
|
||||
@@ -173,7 +173,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(bool allaccess,
|
||||
LogManager::log(LogManager::HOST, "Client Launched Processes["+SockPeerIP+"]: "+ids.join(",") );
|
||||
out->insert("started", QJsonArray::fromStringList(ids));
|
||||
//}else if(act=="read"){
|
||||
|
||||
|
||||
}else{
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmNetworkRequest(const QJsonVa
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
@@ -283,7 +283,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
@@ -343,7 +343,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemMgmtRequest(const QJso
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
@@ -371,7 +371,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonVal
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
@@ -389,6 +389,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal
|
||||
bool ok = false;
|
||||
if(keys.contains("action")){
|
||||
QString act = JsonValueToString(in_args.toObject().value("action"));
|
||||
if(act=="startjail"){
|
||||
ok = true;
|
||||
out->insert("startjail", sysadm::Iocage::startJail(in_args.toObject()));
|
||||
}
|
||||
if(act=="getdefaultsettings"){
|
||||
ok = true;
|
||||
out->insert("getdefaultsettings", sysadm::Iocage::getDefaultSettings());
|
||||
@@ -403,7 +407,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIocageRequest(const QJsonVal
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
@@ -427,7 +431,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmIohyveRequest(const QJsonVal
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
|
||||
@@ -11,6 +11,41 @@
|
||||
using namespace sysadm;
|
||||
|
||||
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
|
||||
|
||||
// Start a jail on the box
|
||||
QJsonObject Iocage::startJail(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
QStringList keys = jsin.keys();
|
||||
if (! keys.contains("jail") ) {
|
||||
retObject.insert("error", "Missing required keys");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Get the key values
|
||||
QString jail = jsin.value("jail").toString();
|
||||
|
||||
QStringList output = General::RunCommand("iocage start " + jail).split("\n");
|
||||
|
||||
QJsonObject vals;
|
||||
for ( int i = 0; i < output.size(); i++)
|
||||
{
|
||||
if ( output.at(i).indexOf("JID") != -1 )
|
||||
continue;
|
||||
|
||||
if ( output.at(i).isEmpty() )
|
||||
break;
|
||||
|
||||
QString key = output.at(i).simplified().section(":", 0, 0);
|
||||
QString value = output.at(i).simplified().section(":", 1, 1);
|
||||
|
||||
vals.insert(key, value);
|
||||
}
|
||||
|
||||
retObject.insert(jail, vals);
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Return all the default iocage settings
|
||||
QJsonObject Iocage::getDefaultSettings() {
|
||||
QJsonObject retObject;
|
||||
@@ -36,7 +71,7 @@ QJsonObject Iocage::getDefaultSettings() {
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// List the jails on the box
|
||||
// Return all of the jail settings
|
||||
QJsonObject Iocage::getJailSettings(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
|
||||
@@ -14,11 +14,12 @@ namespace sysadm{
|
||||
|
||||
class Iocage{
|
||||
public:
|
||||
static QJsonObject startJail(QJsonObject);
|
||||
static QJsonObject getDefaultSettings();
|
||||
static QJsonObject getJailSettings(QJsonObject);
|
||||
static QJsonObject listJails();
|
||||
};
|
||||
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user