mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
API CHANGE
Add a new API call to the sysadm/update class:
"action":"changesettings"
This allows for changing the various updatemanager settings (maxbe, package_set, package_url, auto_update)
REST Request (example):
-------------------------------
PUT /sysadm/update
{
"action" : "changesettings",
"maxbe" : "6"
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"name" : "update",
"namespace" : "sysadm",
"args" : {
"maxbe" : "6",
"action" : "changesettings"
}
}
Response:
-------------------------------
{
"args": {
"changesettings": {
"result": "success"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -589,6 +589,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonVal
|
||||
}else if(act=="listsettings"){
|
||||
ok = true;
|
||||
out->insert("listsettings", sysadm::Update::readSettings() );
|
||||
|
||||
}else if(act=="changesettings"){
|
||||
ok = true;
|
||||
out->insert("changesettings", sysadm::Update::writeSettings(in_args.toObject()) );
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
@@ -235,12 +235,45 @@ QJsonObject Update::readSettings(){
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJsonObject Update::writeSettings(QJsonObject){
|
||||
QJsonObject Update::writeSettings(QJsonObject obj){
|
||||
QJsonObject ret;
|
||||
//Check inputs
|
||||
|
||||
QStringList knownsettings;
|
||||
knownsettings << "PACKAGE_SET" << "PACKAGE_URL" << "AUTO_UPDATE" << "MAXBE";// << "CDN_TYPE";
|
||||
QStringList keys = obj.keys();
|
||||
QStringList vals;
|
||||
for(int i=0; i<keys.length(); i++){
|
||||
if(knownsettings.contains(keys[i].toUpper())){
|
||||
vals << obj.value(keys[i]).toString();
|
||||
keys[i] = keys[i].toUpper();
|
||||
}else{
|
||||
keys.removeAt(i); i--;
|
||||
}
|
||||
}
|
||||
if(keys.isEmpty()){ ret.insert("result","no changes"); return ret; }
|
||||
//Note: Now the keys/vals lists are "paired" up, with same size and info for the same index in the list
|
||||
//Save Settings
|
||||
|
||||
// - first replace existing variables in the config file
|
||||
QStringList info = General::readTextFile(UP_CONFFILE);
|
||||
for(int i=0; i<info.length(); i++){
|
||||
if(info[i].section("#",0,0).simplified().isEmpty()){ continue; } //nothing on this line
|
||||
QString line = info[i].section("#",0,0).simplified();
|
||||
QString var = line.section(":",0,0).simplified();
|
||||
int index = keys.indexOf(var);
|
||||
if(index>=0){
|
||||
info[i] = keys[index]+": "+vals[index];
|
||||
keys.removeAt(index); vals.removeAt(index);
|
||||
}
|
||||
}
|
||||
// if the variable was not previously defined, just add it to the end
|
||||
for(int i=0; i<keys.length(); i++){
|
||||
info << keys[i]+": "+vals[i];
|
||||
}
|
||||
if( General::writeTextFile(UP_CONFFILE, info, true) ){
|
||||
ret.insert("result","success");
|
||||
}else{
|
||||
ret.insert("result","error");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user