API CHANGE

Add a new API call to the sysadm/update class for reading all the current settings.

REST Request (example):
-------------------------------
PUT /sysadm/update
{
   "action" : "listsettings"
}

WebSocket Request:
-------------------------------
{
   "args" : {
      "action" : "listsettings"
   },
   "id" : "fooid",
   "namespace" : "sysadm",
   "name" : "update"
}

Response:
-------------------------------
{
  "args": {
    "listsettings": {
      "maxbe": " 5",
      "package_set": " EDGE"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Ken Moore
2016-08-09 12:45:27 -04:00
parent 06c71afa4a
commit 4457397733
3 changed files with 38 additions and 0 deletions

View File

@@ -585,6 +585,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonVal
}else if(act=="stopupdate"){
ok = true;
out->insert("stopupdate", sysadm::Update::stopUpdate() );
}else if(act=="listsettings"){
ok = true;
out->insert("listsettings", sysadm::Update::readSettings() );
}
} //end of "action" key usage

View File

@@ -14,6 +14,8 @@
#define UP_RBFILE "/tmp/.rebootRequired"
#define UP_UPFILE "/tmp/.updatesAvailable"
#define UP_CONFFILE "/usr/local/etc/trueos.conf"
using namespace sysadm;
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
@@ -214,3 +216,31 @@ QJsonObject Update::stopUpdate() {
}
return ret;
}
//SETTINGS OPTIONS
QJsonObject Update::readSettings(){
QJsonObject ret;
QStringList knownsettings;
knownsettings << "PACKAGE_SET" << "PACKAGE_URL" << "AUTO_UPDATE" << "MAXBE";// << "CDN_TYPE";
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();
if(knownsettings.contains(var)){
ret.insert(var.toLower(), line.section(":",1,-1).simplified());
}
}
return ret;
}
QJsonObject Update::writeSettings(QJsonObject){
QJsonObject ret;
//Check inputs
//Save Settings
return ret;
}

View File

@@ -19,6 +19,10 @@ public:
//Start/stop update routine
static QJsonObject startUpdate(QJsonObject);
static QJsonObject stopUpdate();
//Read/write update settings
static QJsonObject readSettings();
static QJsonObject writeSettings(QJsonObject);
};