stephb9959
2024-02-20 13:26:49 -08:00
parent 4ded8997cd
commit fd85c70c2f
10 changed files with 4716 additions and 119 deletions

2
build
View File

@@ -1 +1 @@
14 18

View File

@@ -815,6 +815,17 @@ components:
type: string type: string
minLength: 2 minLength: 2
maxLength: 2 maxLength: 2
imported:
type: integer
format: int64
connected:
type: integer
format: int64
platform:
type: string
enum:
- AP
- SWITCH
VenueDeviceList: VenueDeviceList:
type: object type: object
@@ -3240,6 +3251,15 @@ paths:
schema: schema:
type: boolean type: boolean
required: false required: false
- in: query
name: deviceType
schema:
type: string
enum:
- AP
- SWITCH
required: false
default: AP
requestBody: requestBody:
description: Information used to create the new entity description: Information used to create the new entity
content: content:
@@ -3268,6 +3288,15 @@ paths:
format: uuid format: uuid
example: When modifying the root entity, the uuid 0000-0000-0000 must be entered. example: When modifying the root entity, the uuid 0000-0000-0000 must be entered.
required: true required: true
- in: query
name: deviceType
schema:
type: string
enum:
- AP
- SWITCH
required: false
default: AP
requestBody: requestBody:
description: Information used to modify the new entity description: Information used to modify the new entity
content: content:

View File

@@ -91,9 +91,10 @@ namespace OpenWifi {
} }
auto Config = RawObject->get("configuration").toString(); auto Config = RawObject->get("configuration").toString();
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
auto deviceType = GetParameter("deviceType", "AP");
std::vector<std::string> Error; std::vector<std::string> Error;
auto Res = auto Res =
ValidateUCentralConfiguration(Config, Error, GetBoolParameter("strict", true)); ValidateUCentralConfiguration(ConfigurationValidator::GetType(deviceType),Config, Error, GetBoolParameter("strict", true));
Answer.set("valid", Res); Answer.set("valid", Res);
Answer.set("error", Error); Answer.set("error", Error);
return ReturnObject(Answer); return ReturnObject(Answer);
@@ -134,7 +135,8 @@ namespace OpenWifi {
} }
std::vector<std::string> Errors; std::vector<std::string> Errors;
if (!ValidateConfigBlock(NewObject, Errors)) { auto deviceType = GetParameter("deviceType", "AP");
if (!ValidateConfigBlock(ConfigurationValidator::GetType(deviceType), NewObject, Errors)) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid); return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
} }
@@ -185,7 +187,8 @@ namespace OpenWifi {
Existing.deviceTypes = NewObject.deviceTypes; Existing.deviceTypes = NewObject.deviceTypes;
std::vector<std::string> Errors; std::vector<std::string> Errors;
if (!ValidateConfigBlock(NewObject, Errors)) { auto deviceType = GetParameter("deviceType", "AP");
if (!ValidateConfigBlock(ConfigurationValidator::GetType(deviceType), NewObject, Errors)) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid); return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
} }

View File

@@ -431,7 +431,7 @@ namespace OpenWifi {
return EntityDB::RootUUID(); return EntityDB::RootUUID();
} }
inline bool ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, inline bool ValidateConfigBlock(ConfigurationValidator::ConfigurationType Type, const ProvObjects::DeviceConfiguration &Config,
std::vector<std::string> &Errors) { std::vector<std::string> &Errors) {
static const std::vector<std::string> SectionNames{ static const std::vector<std::string> SectionNames{
"globals", "interfaces", "metrics", "radios", "services", "unit", "globals", "interfaces", "metrics", "radios", "services", "unit",
@@ -460,7 +460,7 @@ namespace OpenWifi {
} }
try { try {
if (ValidateUCentralConfiguration(i.configuration, Errors, true)) { if (ValidateUCentralConfiguration(Type,i.configuration, Errors, true)) {
// std::cout << "Block: " << i.name << " is valid" << std::endl; // std::cout << "Block: " << i.name << " is valid" << std::endl;
} else { } else {
return false; return false;
@@ -535,7 +535,7 @@ namespace OpenWifi {
ProvObjects::DeviceConfiguration DC; ProvObjects::DeviceConfiguration DC;
if (DC.from_json(ConfigurationDetails)) { if (DC.from_json(ConfigurationDetails)) {
if constexpr (std::is_same_v<Type, ProvObjects::InventoryTag>) { if constexpr (std::is_same_v<Type, ProvObjects::InventoryTag>) {
if (!ValidateConfigBlock(DC, Errors)) { if (!ValidateConfigBlock(ConfigurationValidator::ConfigurationType::AP,DC, Errors)) {
break; break;
} }
ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo, DC.info); ProvObjects::CreateObjectInfo(R.UserInfo_.userinfo, DC.info);

View File

@@ -587,6 +587,9 @@ namespace OpenWifi::ProvObjects {
field_to_json(Obj, "locale", locale); field_to_json(Obj, "locale", locale);
field_to_json(Obj, "realMacAddress", realMacAddress); field_to_json(Obj, "realMacAddress", realMacAddress);
field_to_json(Obj, "doNotAllowOverrides", doNotAllowOverrides); field_to_json(Obj, "doNotAllowOverrides", doNotAllowOverrides);
field_to_json(Obj, "imported", imported);
field_to_json(Obj, "connected", connected);
field_to_json(Obj, "platform", platform);
} }
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) { bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -609,6 +612,9 @@ namespace OpenWifi::ProvObjects {
field_from_json(Obj, "locale", locale); field_from_json(Obj, "locale", locale);
field_from_json(Obj, "realMacAddress", realMacAddress); field_from_json(Obj, "realMacAddress", realMacAddress);
field_from_json(Obj, "doNotAllowOverrides", doNotAllowOverrides); field_from_json(Obj, "doNotAllowOverrides", doNotAllowOverrides);
field_from_json(Obj, "imported", imported);
field_from_json(Obj, "connected", connected);
field_from_json(Obj, "platform", platform);
return true; return true;
} catch (...) { } catch (...) {
} }

View File

@@ -490,9 +490,11 @@ namespace OpenWifi::ProvObjects {
std::string locale; std::string locale;
std::string realMacAddress; std::string realMacAddress;
bool doNotAllowOverrides = false; bool doNotAllowOverrides = false;
std::uint64_t imported=0;
std::uint64_t connected=0;
std::string platform{"AP"};
void to_json(Poco::JSON::Object &Obj) const; void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj); bool from_json(const Poco::JSON::Object::Ptr &Obj);
}; };

File diff suppressed because it is too large Load Diff

View File

@@ -17,33 +17,45 @@
namespace OpenWifi { namespace OpenWifi {
class ConfigurationValidator : public SubSystemServer { class ConfigurationValidator : public SubSystemServer {
public: public:
enum class ConfigurationType { AP = 0 , SWITCH = 1};
static auto instance() { static auto instance() {
static auto instance_ = new ConfigurationValidator; static auto instance_ = new ConfigurationValidator;
return instance_; return instance_;
} }
bool Validate(const std::string &C, std::vector<std::string> &Errors, bool Strict); bool Validate(ConfigurationType Type, const std::string &C, std::vector<std::string> &Errors, bool Strict);
int Start() override; int Start() override;
void Stop() override; void Stop() override;
void reinitialize(Poco::Util::Application &self) override; void reinitialize(Poco::Util::Application &self) override;
inline static ConfigurationType GetType(const std::string &type) {
std::string Type = Poco::toUpper(type);
if (Type == "AP")
return ConfigurationType::AP;
if (Type == "SWITCH")
return ConfigurationType::SWITCH;
return ConfigurationType::AP;
}
private: private:
bool Initialized_ = false; bool Initialized_ = false;
bool Working_ = false; bool Working_ = false;
void Init(); void Init();
std::unique_ptr<valijson::Schema> RootSchema_; std::array<std::unique_ptr<valijson::Schema>,2> RootSchema_;
std::unique_ptr<valijson::SchemaParser> SchemaParser_; std::array<std::unique_ptr<valijson::SchemaParser>,2> SchemaParser_;
std::unique_ptr<valijson::adapters::PocoJsonAdapter> PocoJsonAdapter_; std::array<std::unique_ptr<valijson::adapters::PocoJsonAdapter>,2> PocoJsonAdapter_;
Poco::JSON::Object::Ptr SchemaDocPtr_; std::array<Poco::JSON::Object::Ptr,2> SchemaDocPtr_;
bool SetSchema(const std::string &SchemaStr); bool SetSchema(ConfigurationType Type, const std::string &SchemaStr);
ConfigurationValidator() ConfigurationValidator()
: SubSystemServer("ConfigValidator", "CFG-VALIDATOR", "config.validator") {} : SubSystemServer("ConfigValidator", "CFG-VALIDATOR", "config.validator") {}
}; };
inline auto ConfigurationValidator() { return ConfigurationValidator::instance(); } inline auto ConfigurationValidator() { return ConfigurationValidator::instance(); }
inline bool ValidateUCentralConfiguration(const std::string &C, std::vector<std::string> &Error, inline bool ValidateUCentralConfiguration(ConfigurationValidator::ConfigurationType Type, const std::string &C, std::vector<std::string> &Error,
bool strict) { bool strict) {
return ConfigurationValidator::instance()->Validate(C, Error, strict); return ConfigurationValidator::instance()->Validate(Type, C, Error, strict);
} }
} // namespace OpenWifi } // namespace OpenWifi

View File

@@ -44,7 +44,10 @@ namespace OpenWifi {
ORM::Field{"devClass", ORM::FieldType::FT_TEXT}, ORM::Field{"devClass", ORM::FieldType::FT_TEXT},
ORM::Field{"locale", ORM::FieldType::FT_TEXT}, ORM::Field{"locale", ORM::FieldType::FT_TEXT},
ORM::Field{"realMacAddress", ORM::FieldType::FT_TEXT}, ORM::Field{"realMacAddress", ORM::FieldType::FT_TEXT},
ORM::Field{"doNotAllowOverrides", ORM::FieldType::FT_BOOLEAN}}; ORM::Field{"doNotAllowOverrides", ORM::FieldType::FT_BOOLEAN},
ORM::Field{"imported", ORM::FieldType::FT_BIGINT},
ORM::Field{"connected", ORM::FieldType::FT_BIGINT},
ORM::Field{"platform", ORM::FieldType::FT_TEXT}};
static ORM::IndexVec InventoryDB_Indexes{ static ORM::IndexVec InventoryDB_Indexes{
{std::string("inventory_name_index"), {std::string("inventory_name_index"),
@@ -60,6 +63,9 @@ namespace OpenWifi {
"alter table " + TableName_ + " add column realMacAddress text", "alter table " + TableName_ + " add column realMacAddress text",
"alter table " + TableName_ + " add column devClass text", "alter table " + TableName_ + " add column devClass text",
"alter table " + TableName_ + " add column deviceRules text", "alter table " + TableName_ + " add column deviceRules text",
"alter table " + TableName_ + " add column platform text default 'AP'",
"alter table " + TableName_ + " add column imported bigint",
"alter table " + TableName_ + " add column connected bigint",
"alter table " + TableName_ + " add column doNotAllowOverrides boolean"}; "alter table " + TableName_ + " add column doNotAllowOverrides boolean"};
for (const auto &i : Script) { for (const auto &i : Script) {
@@ -106,6 +112,8 @@ namespace OpenWifi {
StateDoc["date"] = Utils::Now(); StateDoc["date"] = Utils::Now();
NewDevice.state = to_string(StateDoc); NewDevice.state = to_string(StateDoc);
NewDevice.devClass = "any"; NewDevice.devClass = "any";
NewDevice.connected = Now;
NewDevice.imported = 0;
if (!IP.empty()) { if (!IP.empty()) {
StorageService()->VenueDB().GetByIP(IP, NewDevice.venue); StorageService()->VenueDB().GetByIP(IP, NewDevice.venue);
if (NewDevice.venue.empty()) { if (NewDevice.venue.empty()) {
@@ -176,6 +184,7 @@ namespace OpenWifi {
if (modified) { if (modified) {
ExistingDevice.info.modified = Utils::Now(); ExistingDevice.info.modified = Utils::Now();
ExistingDevice.connected = Utils::Now();
StorageService()->InventoryDB().UpdateRecord("id", ExistingDevice.info.id, StorageService()->InventoryDB().UpdateRecord("id", ExistingDevice.info.id,
ExistingDevice); ExistingDevice);
} }
@@ -326,6 +335,9 @@ void ORM::DB<OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTa
Out.locale = In.get<21>(); Out.locale = In.get<21>();
Out.realMacAddress = In.get<22>(); Out.realMacAddress = In.get<22>();
Out.doNotAllowOverrides = In.get<23>(); Out.doNotAllowOverrides = In.get<23>();
Out.imported = In.get<24>();
Out.connected = In.get<25>();
Out.platform = In.get<26>();
} }
template <> template <>
@@ -355,4 +367,7 @@ void ORM::DB<OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTa
Out.set<21>(In.locale); Out.set<21>(In.locale);
Out.set<22>(In.realMacAddress); Out.set<22>(In.realMacAddress);
Out.set<23>(In.doNotAllowOverrides); Out.set<23>(In.doNotAllowOverrides);
Out.set<24>(In.imported);
Out.set<25>(In.connected);
Out.set<26>(In.platform);
} }

View File

@@ -16,7 +16,7 @@ namespace OpenWifi {
std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string,
std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string,
std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string,
std::string, std::string, bool> std::string, std::string, bool, uint64_t, uint64_t, std::string>
InventoryDBRecordType; InventoryDBRecordType;
class InventoryDB : public ORM::DB<InventoryDBRecordType, ProvObjects::InventoryTag> { class InventoryDB : public ORM::DB<InventoryDBRecordType, ProvObjects::InventoryTag> {