Adding configuration validation.

This commit is contained in:
stephb9959
2021-09-14 18:28:03 -07:00
parent f487625fbc
commit 6a0136efad
4 changed files with 97 additions and 21 deletions

2
build
View File

@@ -1 +1 @@
158
160

View File

@@ -2084,29 +2084,18 @@ namespace OpenWifi {
if(Initialized_)
return;
std::cout << __LINE__ << std::endl;
std::string FileName{ Daemon()->DataDir() + "/ucentral.schema.json" };
try {
std::cout << __LINE__ << std::endl;
std::ifstream input(FileName);
std::cout << __LINE__ << std::endl;
std::stringstream schema_file;
schema_file << input.rdbuf();
std::cout << __LINE__ << std::endl;
input.close();
std::cout << __LINE__ << std::endl;
auto schema = json::parse(schema_file.str());
std::cout << __LINE__ << std::endl;
Validator_->set_root_schema(schema);
Initialized_ = Working_ = true;
std::cout << __LINE__ << std::endl;
} catch (const std::exception &E ) {
std::cout << __LINE__ << std::endl;
Validator_->set_root_schema(DefaultUCentralSchema);
std::cout << __LINE__ << std::endl;
Initialized_ = Working_ = true;
std::cout << __LINE__ << std::endl;
}
}

View File

@@ -107,25 +107,16 @@ namespace OpenWifi{
std::string Arg;
if(HasParameter("validateOnly",Arg) && Arg=="true") {
std::cout << __LINE__ << std::endl;
auto Body = ParseStream();
std::cout << __LINE__ << std::endl;
if(!Body->has("configuration")) {
std::cout << __LINE__ << std::endl;
BadRequest("Must have 'configuration' element.");
return;
}
std::cout << __LINE__ << std::endl;
auto Config=Body->get("configuration").toString();
std::cout << __LINE__ << std::endl;
Poco::JSON::Object Answer;
std::cout << __LINE__ << std::endl;
auto Res = ValidateUCentralConfiguration(Config);
std::cout << __LINE__ << std::endl;
Answer.set("valid",Res);
std::cout << __LINE__ << std::endl;
ReturnObject(Answer);
std::cout << __LINE__ << std::endl;
return;
}

View File

@@ -0,0 +1,96 @@
{
"configuration" : {
"badstuff": [
{
"band": "5G",
"channel": 52,
"channel-mode": "HE",
"channel-width": 80,
"country": "CA"
},
{
"band": "2G",
"channel": 11,
"channel-mode": "HE",
"channel-width": 20,
"country": "CA"
}
],
"interfaces": [
{
"name": "WAN",
"role": "upstream",
"services": [ "lldp" ],
"ethernet": [
{
"select-ports": [
"WAN*"
]
}
],
"ipv4": {
"addressing": "dynamic"
}
},
{
"name": "LAN",
"role": "downstream",
"services": [ "ssh", "lldp" ],
"ethernet": [
{
"select-ports": [
"LAN*"
]
}
],
"ipv4": {
"addressing": "static",
"subnet": "192.168.1.1/24",
"dhcp": {
"lease-first": 10,
"lease-count": 100,
"lease-time": "6h"
}
},
"ssids": [
{
"name": "OpenWifi",
"role": "downstream",
"wifi-bands": [
"2G", "5G"
],
"bss-mode": "ap",
"encryption": {
"proto": "psk2",
"key": "OpenWifi",
"ieee80211w": "optional"
}
}
]
}
],
"metrics": {
"statistics": {
"interval": 120,
"types": [ "ssids", "lldp", "clients" ]
},
"health": {
"interval": 120
},
"wifi-frames": {
"filters": [ "probe", "auth" ]
}
},
"services": {
"lldp": {
"describe": "uCentral",
"location": "universe"
},
"ssh": {
"port": 22
}
}
}
}