diff --git a/build b/build index a46c9d22..27a37eb5 100644 --- a/build +++ b/build @@ -1 +1 @@ -91 \ No newline at end of file +93 \ No newline at end of file diff --git a/openapi/owgw.yaml b/openapi/owgw.yaml index e57fbc6f..cbb08955 100644 --- a/openapi/owgw.yaml +++ b/openapi/owgw.yaml @@ -42,12 +42,10 @@ components: schemas: DeviceType: type: string - default: AP + default: ap enum: - - AP - - SWITCH - - IOT - - MESH + - ap + - switch DeviceRestrictionsKeyInfo: type: object diff --git a/src/CapabilitiesCache.h b/src/CapabilitiesCache.h index 866a8efb..6658a0f1 100644 --- a/src/CapabilitiesCache.h +++ b/src/CapabilitiesCache.h @@ -10,6 +10,7 @@ #include #include "framework/MicroServiceFuncs.h" +#include "framework/ow_constants.h" #include "CentralConfig.h" #include "nlohmann/json.hpp" @@ -34,7 +35,7 @@ namespace OpenWifi { std::lock_guard G(Mutex_); if (!PlatformsLoaded_) LoadPlatforms(); - auto P = Poco::toUpper(Caps.Platform()); + auto P = Poco::toLower(Caps.Platform()); auto Hint = Platforms_.find(Caps.Compatible()); if (Hint == Platforms_.end()) { Platforms_.insert(std::make_pair(Caps.Compatible(), P)); @@ -68,7 +69,7 @@ namespace OpenWifi { auto Hint = Platforms_.find(DeviceType); if (Hint == Platforms_.end()) - return "AP"; + return Platforms::AP; return Hint->second; } @@ -110,7 +111,7 @@ namespace OpenWifi { i >> cache; for (const auto &[Type, Platform] : cache.items()) { - Platforms_[Type] = Platform; + Platforms_[Type] = Poco::toLower(to_string(Platform)); } } catch (...) { } diff --git a/src/Daemon.cpp b/src/Daemon.cpp index b3633d4c..73e391e3 100644 --- a/src/Daemon.cpp +++ b/src/Daemon.cpp @@ -78,7 +78,7 @@ namespace OpenWifi { if (Id == DeviceType) return Type; } - return "AP"; + return Platforms::AP; } void DaemonPostInitialization(Poco::Util::Application &self) { diff --git a/src/RESTAPI/RESTAPI_default_configuration.cpp b/src/RESTAPI/RESTAPI_default_configuration.cpp index df3dcfe7..2f8ddc17 100644 --- a/src/RESTAPI/RESTAPI_default_configuration.cpp +++ b/src/RESTAPI/RESTAPI_default_configuration.cpp @@ -60,8 +60,8 @@ namespace OpenWifi { return BadRequest(RESTAPI::Errors::ModelIDListCannotBeEmpty); } - DefConfig.Platform = DefConfig.Platform.empty() ? "AP" : DefConfig.Platform; - if(DefConfig.Platform != "AP" && DefConfig.Platform != "SWITCH") { + DefConfig.Platform = DefConfig.Platform.empty() ? Platforms::AP : DefConfig.Platform; + if(DefConfig.Platform != Platforms::AP && DefConfig.Platform != Platforms::SWITCH) { return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); } @@ -95,11 +95,11 @@ namespace OpenWifi { } if(Existing.Platform.empty()) { - Existing.Platform = "AP"; + Existing.Platform = Platforms::AP; } if(ParsedBody_->has("platform")) { - if(NewConfig.Platform.empty() || (NewConfig.Platform != "AP" && NewConfig.Platform != "SWITCH")) { + if(NewConfig.Platform.empty() || (NewConfig.Platform != Platforms::AP && NewConfig.Platform != Platforms::SWITCH)) { return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); } Existing.Platform = NewConfig.Platform; diff --git a/src/RESTAPI/RESTAPI_device_handler.cpp b/src/RESTAPI/RESTAPI_device_handler.cpp index afe38d1f..778a9027 100644 --- a/src/RESTAPI/RESTAPI_device_handler.cpp +++ b/src/RESTAPI/RESTAPI_device_handler.cpp @@ -102,7 +102,7 @@ namespace OpenWifi { auto Config = Obj->get("configuration").toString(); Poco::JSON::Object Answer; std::string Error; - auto DeviceType = GetParameter("deviceType", "AP"); + auto DeviceType = Poco::toLower(GetParameter("deviceType", Platforms::AP)); auto Res = ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceType),Config, Error, GetBoolParameter("strict", false)); Answer.set("valid", Res); diff --git a/src/RESTAPI/RESTAPI_devices_handler.cpp b/src/RESTAPI/RESTAPI_devices_handler.cpp index bb880fbc..2a78cf7b 100644 --- a/src/RESTAPI/RESTAPI_devices_handler.cpp +++ b/src/RESTAPI/RESTAPI_devices_handler.cpp @@ -87,7 +87,7 @@ namespace OpenWifi { auto deviceWithStatus = GetBoolParameter(RESTAPI::Protocol::DEVICEWITHSTATUS, false); auto completeInfo = GetBoolParameter("completeInfo", false); - if(!platform.empty() && (platform!="ap" && platform!="switch" && platform!="all")) { + if(!platform.empty() && (platform!=Platforms::AP && platform!=Platforms::SWITCH && platform!="all")) { return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters); } diff --git a/src/RESTObjects/RESTAPI_AnalyticsObjects.h b/src/RESTObjects/RESTAPI_AnalyticsObjects.h index dac46c78..27195182 100644 --- a/src/RESTObjects/RESTAPI_AnalyticsObjects.h +++ b/src/RESTObjects/RESTAPI_AnalyticsObjects.h @@ -7,6 +7,7 @@ #include "RESTAPI_ProvObjects.h" #include "framework/utils.h" #include +#include "framework/ow_constants.h" namespace OpenWifi { diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 8f118676..e04c88a3 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -492,7 +492,7 @@ namespace OpenWifi::ProvObjects { bool doNotAllowOverrides = false; std::uint64_t imported=0; std::uint64_t connected=0; - std::string platform{"AP"}; + std::string platform{Platforms::AP}; void to_json(Poco::JSON::Object &Obj) const; bool from_json(const Poco::JSON::Object::Ptr &Obj); diff --git a/src/StorageService.cpp b/src/StorageService.cpp index 1bc1bd2d..2adb993d 100644 --- a/src/StorageService.cpp +++ b/src/StorageService.cpp @@ -22,6 +22,8 @@ namespace OpenWifi { ScriptDB_->Create(); ScriptDB_->Initialize(); + FixDeviceTypeBug(); + return 0; } diff --git a/src/StorageService.h b/src/StorageService.h index d6fbaa89..8be929cc 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -294,6 +294,8 @@ namespace OpenWifi { bool AnalyzeCommands(Types::CountedMap &R); bool AnalyzeDevices(GWObjects::Dashboard &D); + void FixDeviceTypeBug(); + int Start() override; void Stop() override; diff --git a/src/framework/ConfigurationValidator.h b/src/framework/ConfigurationValidator.h index a533881f..5986802c 100644 --- a/src/framework/ConfigurationValidator.h +++ b/src/framework/ConfigurationValidator.h @@ -5,7 +5,7 @@ #pragma once #include "framework/SubSystemServer.h" - +#include "framework/ow_constants.h" #include #include #include @@ -32,9 +32,9 @@ namespace OpenWifi { inline static ConfigurationType GetType(const std::string &type) { std::string Type = Poco::toUpper(type); - if (Type == "AP") + if (Type == Platforms::AP) return ConfigurationType::AP; - if (Type == "SWITCH") + if (Type == Platforms::SWITCH) return ConfigurationType::SWITCH; return ConfigurationType::AP; } diff --git a/src/framework/default_device_types.h b/src/framework/default_device_types.h index 02941db4..c19cd3fb 100644 --- a/src/framework/default_device_types.h +++ b/src/framework/default_device_types.h @@ -7,57 +7,59 @@ #include #include +#include "ow_constants.h" + namespace OpenWifi { inline const std::vector> DefaultDeviceTypeList{ - {"actiontec_web7200", "AP"}, - {"cig_wf186w", "AP"}, - {"cig_wf188n", "AP"}, - {"cig_wf194c4", "AP"}, - {"cig_wf196", "AP"}, - {"cig_wf196-ca", "AP"}, - {"cig_wf196-ca-ath12", "AP"}, - {"cig_wf196-us", "AP"}, - {"cig_wf610d", "AP"}, - {"cig_wf660a", "AP"}, - {"cig_wf808", "AP"}, - {"cybertan_eww622-a1", "AP"}, - {"edgecore_eap101", "AP"}, - {"edgecore_eap101-ath12", "AP"}, - {"edgecore_eap102", "AP"}, - {"edgecore_eap104", "AP"}, - {"edgecore_eap104-ath12", "AP"}, - {"edgecore_ecs4100-12ph", "AP"}, - {"edgecore_ecw5211", "AP"}, - {"edgecore_ecw5410", "AP"}, - {"edgecore_oap100", "AP"}, - {"edgecore_spw2ac1200", "SWITCH"}, - {"edgecore_spw2ac1200-lan-poe", "SWITCH"}, - {"edgecore_ssw2ac2600", "SWITCH"}, - {"hfcl_ion4", "AP"}, - {"hfcl_ion4x", "AP"}, - {"hfcl_ion4x_2", "AP"}, - {"hfcl_ion4xe", "AP"}, - {"hfcl_ion4xi", "AP"}, - {"indio_um-305ac", "AP"}, - {"indio_um-305ax", "AP"}, - {"indio_um-310ax-v1", "AP"}, - {"indio_um-325ac", "AP"}, - {"indio_um-510ac-v3", "AP"}, - {"indio_um-510axm-v1", "AP"}, - {"indio_um-510axp-v1", "AP"}, - {"indio_um-550ac", "AP"}, - {"linksys_e8450-ubi", "AP"}, - {"linksys_ea6350-v4", "AP"}, - {"linksys_ea8300", "AP"}, - {"liteon_wpx8324", "AP"}, - {"meshpp_s618_cp01", "AP"}, - {"meshpp_s618_cp03", "AP"}, - {"udaya_a5-id2", "AP"}, - {"wallys_dr40x9", "AP"}, - {"wallys_dr6018", "AP"}, - {"wallys_dr6018_v4", "AP"}, - {"x64_vm", "AP"}, - {"yuncore_ax840", "AP"}, - {"yuncore_fap640", "AP"}, - {"yuncore_fap650", "AP"}}; + {"actiontec_web7200", Platforms::AP}, + {"cig_wf186w", Platforms::AP}, + {"cig_wf188n", Platforms::AP}, + {"cig_wf194c4", Platforms::AP}, + {"cig_wf196", Platforms::AP}, + {"cig_wf196-ca", Platforms::AP}, + {"cig_wf196-ca-ath12", Platforms::AP}, + {"cig_wf196-us", Platforms::AP}, + {"cig_wf610d", Platforms::AP}, + {"cig_wf660a", Platforms::AP}, + {"cig_wf808", Platforms::AP}, + {"cybertan_eww622-a1", Platforms::AP}, + {"edgecore_eap101", Platforms::AP}, + {"edgecore_eap101-ath12", Platforms::AP}, + {"edgecore_eap102", Platforms::AP}, + {"edgecore_eap104", Platforms::AP}, + {"edgecore_eap104-ath12", Platforms::AP}, + {"edgecore_ecs4100-12ph", Platforms::AP}, + {"edgecore_ecw5211", Platforms::AP}, + {"edgecore_ecw5410", Platforms::AP}, + {"edgecore_oap100", Platforms::AP}, + {"edgecore_spw2ac1200", Platforms::SWITCH}, + {"edgecore_spw2ac1200-lan-poe", Platforms::SWITCH}, + {"edgecore_ssw2ac2600", Platforms::SWITCH}, + {"hfcl_ion4", Platforms::AP}, + {"hfcl_ion4x", Platforms::AP}, + {"hfcl_ion4x_2", Platforms::AP}, + {"hfcl_ion4xe", Platforms::AP}, + {"hfcl_ion4xi", Platforms::AP}, + {"indio_um-305ac", Platforms::AP}, + {"indio_um-305ax", Platforms::AP}, + {"indio_um-310ax-v1", Platforms::AP}, + {"indio_um-325ac", Platforms::AP}, + {"indio_um-510ac-v3", Platforms::AP}, + {"indio_um-510axm-v1", Platforms::AP}, + {"indio_um-510axp-v1", Platforms::AP}, + {"indio_um-550ac", Platforms::AP}, + {"linksys_e8450-ubi", Platforms::AP}, + {"linksys_ea6350-v4", Platforms::AP}, + {"linksys_ea8300", Platforms::AP}, + {"liteon_wpx8324", Platforms::AP}, + {"meshpp_s618_cp01", Platforms::AP}, + {"meshpp_s618_cp03", Platforms::AP}, + {"udaya_a5-id2", Platforms::AP}, + {"wallys_dr40x9", Platforms::AP}, + {"wallys_dr6018", Platforms::AP}, + {"wallys_dr6018_v4", Platforms::AP}, + {"x64_vm", Platforms::AP}, + {"yuncore_ax840", Platforms::AP}, + {"yuncore_fap640", Platforms::AP}, + {"yuncore_fap650", Platforms::AP}}; } diff --git a/src/framework/ow_constants.h b/src/framework/ow_constants.h index 7ef84243..2e838ff2 100644 --- a/src/framework/ow_constants.h +++ b/src/framework/ow_constants.h @@ -831,6 +831,11 @@ namespace OpenWifi::Provisioning::DeviceClass { } // namespace OpenWifi::Provisioning::DeviceClass +namespace OpenWifi::Platforms { + static const std::string AP = "ap"; + static const std::string SWITCH = "switch"; +} + #if defined(__GNUC__) #pragma GCC diagnostic pop #endif diff --git a/src/storage/storage_defconfig.cpp b/src/storage/storage_defconfig.cpp index fc876a2d..ef7d2c44 100644 --- a/src/storage/storage_defconfig.cpp +++ b/src/storage/storage_defconfig.cpp @@ -221,31 +221,30 @@ namespace OpenWifi { return false; } - bool Storage::FindDefaultConfigurationForModel(const std::string &Model, const std::string &Platform, - GWObjects::DefaultConfiguration &DefConfig) { + bool Storage::FindDefaultConfigurationForModel(const std::string &DeviceModel, const std::string &Platform, + GWObjects::DefaultConfiguration &Config) { try { - DefConfigRecordList Records; + DefConfigRecordList DefConfigs; Poco::Data::Session Sess = Pool_->get(); Poco::Data::Statement Select(Sess); Select << "SELECT " + DB_DefConfig_SelectFields + " FROM DefaultConfigs", - Poco::Data::Keywords::into(Records); + Poco::Data::Keywords::into(DefConfigs); Select.execute(); - for (const auto &i : Records) { - GWObjects::DefaultConfiguration Config; - Convert(i, Config); - for (const auto &j : Config.Models) { - if ((j == "*" || j == Model) && (Poco::toUpper(Config.Platform) == Poco::toUpper(Platform))){ - DefConfig = Config; + for (const auto &DefConfig : DefConfigs) { + GWObjects::DefaultConfiguration C; + Convert(DefConfig, C); + for (const auto &Model : C.Models) { + if ((Model == "*" || Model == DeviceModel) && (Config.Platform == Platform)){ + Config = C; return true; } } } Logger().information( - fmt::format("AUTO-PROVISIONING: no default configuration for model:{}", Model)); - return false; + fmt::format("AUTO-PROVISIONING: no default configuration for model:{}", DeviceModel)); } catch (const Poco::Exception &E) { poco_warning(Logger(), fmt::format("{}: Failed with: {}", std::string(__func__), E.displayText())); diff --git a/src/storage/storage_device.cpp b/src/storage/storage_device.cpp index 8275a07b..bdc71448 100644 --- a/src/storage/storage_device.cpp +++ b/src/storage/storage_device.cpp @@ -582,10 +582,18 @@ namespace OpenWifi { Config::Config NewConfig(DefConfig.Configuration); NewConfig.SetUUID(Now); D.Configuration = NewConfig.get(); - } else if (!Found && Caps.Platform()=="AP") { - Config::Config NewConfig; - NewConfig.SetUUID(Now); - D.Configuration = NewConfig.get(); + } else if (!Found) { + if(Caps.Platform()==Platforms::AP) { + Config::Config NewConfig; + NewConfig.SetUUID(Now); + D.Configuration = NewConfig.get(); + } else { + Poco::JSON::Object Obj; + Obj.set("uuid", Now); + std::ostringstream os; + Obj.stringify(os); + D.Configuration = os.str(); + } } // We need to insert the country code according to the IP in the radios section... @@ -1107,4 +1115,25 @@ namespace OpenWifi { FieldList.push_back(field); } + void Storage::FixDeviceTypeBug() { + try { + std::vector ScriptLines{ + "update devices set devicetype='ap' where devicetype='AP';", + "update devices set devicetype='switch' where devicetype='SWITCH';", + "update devices set devicetype='ap' where devicetype!='ap' and devicetype!='switch';" + }; + + for (const auto &ScriptLine : ScriptLines) { + try { + Poco::Data::Session Sess = Pool_->get(); + Poco::Data::Statement SqlStatement(Sess); + SqlStatement << ScriptLine, Poco::Data::Keywords::now; + } catch (...) { + } + } + } catch (const Poco::Exception &E) { + Logger().log(E); + } + } + } // namespace OpenWifi