mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-30 02:02:36 +00:00
Fixed UpdateDeviceTypes.
This commit is contained in:
@@ -69,7 +69,6 @@ add_executable(owprov
|
|||||||
src/StorageService.cpp src/StorageService.h
|
src/StorageService.cpp src/StorageService.h
|
||||||
src/SubSystemServer.cpp src/SubSystemServer.h
|
src/SubSystemServer.cpp src/SubSystemServer.h
|
||||||
src/RESTAPI_ProvObjects.cpp src/RESTAPI_ProvObjects.h
|
src/RESTAPI_ProvObjects.cpp src/RESTAPI_ProvObjects.h
|
||||||
src/storage_pgql.cpp src/storage_mysql.cpp src/storage_sqlite.cpp
|
|
||||||
src/storage_entity.cpp src/storage_entity.h
|
src/storage_entity.cpp src/storage_entity.h
|
||||||
src/storage_policies.cpp src/storage_policies.h
|
src/storage_policies.cpp src/storage_policies.h
|
||||||
src/OpenWifiTypes.h
|
src/OpenWifiTypes.h
|
||||||
@@ -84,9 +83,9 @@ add_executable(owprov
|
|||||||
src/RESTAPI_inventory_handler.cpp src/RESTAPI_inventory_handler.h
|
src/RESTAPI_inventory_handler.cpp src/RESTAPI_inventory_handler.h
|
||||||
src/RESTAPI_managementPolicy_handler.cpp src/RESTAPI_managementPolicy_handler.h
|
src/RESTAPI_managementPolicy_handler.cpp src/RESTAPI_managementPolicy_handler.h
|
||||||
src/RESTAPI_inventory_list_handler.cpp src/RESTAPI_inventory_list_handler.h
|
src/RESTAPI_inventory_list_handler.cpp src/RESTAPI_inventory_list_handler.h
|
||||||
src/dbhelpers.h
|
|
||||||
src/RESTAPI_entity_list_handler.cpp src/RESTAPI_entity_list_handler.h
|
src/RESTAPI_entity_list_handler.cpp src/RESTAPI_entity_list_handler.h
|
||||||
src/storage_management_roles.cpp src/storage_management_roles.h)
|
src/storage_management_roles.cpp src/storage_management_roles.h
|
||||||
|
src/storage_setup.cpp)
|
||||||
|
|
||||||
target_link_libraries(owprov PUBLIC
|
target_link_libraries(owprov PUBLIC
|
||||||
${Poco_LIBRARIES} ${MySQL_LIBRARIES}
|
${Poco_LIBRARIES} ${MySQL_LIBRARIES}
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -26,7 +26,20 @@ You must use the query command parameters to modify other properties
|
|||||||
## Inventory Tags
|
## Inventory Tags
|
||||||
### Creation rules
|
### Creation rules
|
||||||
- Entity must point to an existing non-root entity
|
- Entity must point to an existing non-root entity
|
||||||
- If you associate a venue, it must exist
|
- If you associate a venue, it must exist.
|
||||||
|
- You must use an existing device type. Device type cannot be empty.
|
||||||
|
- Name, description, notes are allowed.
|
||||||
|
|
||||||
|
### Modification rules
|
||||||
|
- You can modify the device type to another valid one.
|
||||||
|
|
||||||
|
## Venue
|
||||||
|
### Creation rules
|
||||||
|
- If you include an entity, the parent must bot be set
|
||||||
|
- if you include a parent, the entity must not be set
|
||||||
|
- You cannot have children upon creation.
|
||||||
|
- You may include an array of devices UUIDs
|
||||||
|
- Topology and design cannot be set
|
||||||
|
|
||||||
### Modification rules
|
### Modification rules
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ components:
|
|||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/ManagementPolicyEntry'
|
$ref: '#/components/schemas/ManagementPolicyEntry'
|
||||||
|
inUse:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
example: each uuid is preceded by ent, or ven to say that the elemenet is entity or venue
|
||||||
|
|
||||||
# uuids: ent:<uuid>
|
# uuids: ent:<uuid>
|
||||||
Entity:
|
Entity:
|
||||||
@@ -291,17 +297,12 @@ components:
|
|||||||
contact:
|
contact:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
venues:
|
inUse:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
entities:
|
example: each uuid is preceded by ent, or ven to say that the elemenet is entity or venue
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
format: uuid
|
|
||||||
|
|
||||||
|
|
||||||
# uuids: con:<uuid>
|
# uuids: con:<uuid>
|
||||||
Contact:
|
Contact:
|
||||||
@@ -346,34 +347,29 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
accessPIN:
|
accessPIN:
|
||||||
type: string
|
type: string
|
||||||
venues:
|
inUse:
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
format: uuid
|
|
||||||
entities:
|
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
|
||||||
# uuids: svc:<uuid>
|
DeviceConfigurationElement:
|
||||||
ServiceConfiguration:
|
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
name:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
weight:
|
||||||
|
type: integer
|
||||||
|
configuration:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
|
||||||
managementPolicy:
|
|
||||||
$ref: '#/components/schemas/ManagementPolicy'
|
|
||||||
|
|
||||||
# uuids: cfg:<uuid>
|
|
||||||
DeviceConfiguration:
|
DeviceConfiguration:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
allOf:
|
||||||
type: string
|
$ref: '#/components/schemas/ObjectInfo'
|
||||||
format: uuid
|
|
||||||
managementPolicy:
|
managementPolicy:
|
||||||
$ref: '#/components/schemas/ManagementPolicy'
|
$ref: '#/components/schemas/ManagementPolicy'
|
||||||
deviceTypes:
|
deviceTypes:
|
||||||
@@ -381,7 +377,14 @@ components:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
configuration:
|
configuration:
|
||||||
type: string
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/DeviceConfigurationElement'
|
||||||
|
inUse:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
|
||||||
InventoryTag:
|
InventoryTag:
|
||||||
type: object
|
type: object
|
||||||
@@ -398,16 +401,16 @@ components:
|
|||||||
entity:
|
entity:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
subEntity:
|
|
||||||
type: string
|
|
||||||
format: uuid
|
|
||||||
subVenue:
|
|
||||||
type: string
|
|
||||||
format: uuid
|
|
||||||
qrCode:
|
qrCode:
|
||||||
type: string
|
type: string
|
||||||
geoCode:
|
geoCode:
|
||||||
type: string
|
type: string
|
||||||
|
location:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
contact:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
|
||||||
InventoryTagList:
|
InventoryTagList:
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
@@ -54,12 +54,14 @@ namespace OpenWifi::ProvObjects {
|
|||||||
void ManagementPolicy::to_json(Poco::JSON::Object &Obj) const {
|
void ManagementPolicy::to_json(Poco::JSON::Object &Obj) const {
|
||||||
info.to_json(Obj);
|
info.to_json(Obj);
|
||||||
RESTAPI_utils::field_to_json(Obj, "entries", entries);
|
RESTAPI_utils::field_to_json(Obj, "entries", entries);
|
||||||
|
RESTAPI_utils::field_to_json(Obj, "inUse", inUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ManagementPolicy::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
bool ManagementPolicy::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
try {
|
try {
|
||||||
info.from_json(Obj);
|
info.from_json(Obj);
|
||||||
RESTAPI_utils::field_from_json(Obj, "entries", entries);
|
RESTAPI_utils::field_from_json(Obj, "entries", entries);
|
||||||
|
RESTAPI_utils::field_from_json(Obj, "inUse", inUse);
|
||||||
return true;
|
return true;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
|
|
||||||
@@ -184,9 +186,8 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_to_json( Obj,"country",country);
|
RESTAPI_utils::field_to_json( Obj,"country",country);
|
||||||
RESTAPI_utils::field_to_json( Obj,"phones",phones);
|
RESTAPI_utils::field_to_json( Obj,"phones",phones);
|
||||||
RESTAPI_utils::field_to_json( Obj,"mobiles",mobiles);
|
RESTAPI_utils::field_to_json( Obj,"mobiles",mobiles);
|
||||||
RESTAPI_utils::field_to_json( Obj,"venues",venues);
|
|
||||||
RESTAPI_utils::field_to_json( Obj,"entities",entities);
|
|
||||||
RESTAPI_utils::field_to_json( Obj,"geoCode",geoCode);
|
RESTAPI_utils::field_to_json( Obj,"geoCode",geoCode);
|
||||||
|
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Location::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
bool Location::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
@@ -203,9 +204,8 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_from_json( Obj,"country",country);
|
RESTAPI_utils::field_from_json( Obj,"country",country);
|
||||||
RESTAPI_utils::field_from_json( Obj,"phones",phones);
|
RESTAPI_utils::field_from_json( Obj,"phones",phones);
|
||||||
RESTAPI_utils::field_from_json( Obj,"mobiles",mobiles);
|
RESTAPI_utils::field_from_json( Obj,"mobiles",mobiles);
|
||||||
RESTAPI_utils::field_from_json( Obj,"venues",venues);
|
|
||||||
RESTAPI_utils::field_from_json( Obj,"entities",entities);
|
|
||||||
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
||||||
|
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
||||||
@@ -227,8 +227,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_to_json( Obj,"primaryEmail",primaryEmail);
|
RESTAPI_utils::field_to_json( Obj,"primaryEmail",primaryEmail);
|
||||||
RESTAPI_utils::field_to_json( Obj,"secondaryEmail",secondaryEmail);
|
RESTAPI_utils::field_to_json( Obj,"secondaryEmail",secondaryEmail);
|
||||||
RESTAPI_utils::field_to_json( Obj,"accessPIN",accessPIN);
|
RESTAPI_utils::field_to_json( Obj,"accessPIN",accessPIN);
|
||||||
RESTAPI_utils::field_to_json( Obj,"venues",venues);
|
RESTAPI_utils::field_to_json( Obj,"inUse",inUse);
|
||||||
RESTAPI_utils::field_to_json( Obj,"entities",entities);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Contact::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
bool Contact::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
@@ -248,8 +247,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_from_json( Obj,"primaryEmail",primaryEmail);
|
RESTAPI_utils::field_from_json( Obj,"primaryEmail",primaryEmail);
|
||||||
RESTAPI_utils::field_from_json( Obj,"secondaryEmail",secondaryEmail);
|
RESTAPI_utils::field_from_json( Obj,"secondaryEmail",secondaryEmail);
|
||||||
RESTAPI_utils::field_from_json( Obj,"accessPIN",accessPIN);
|
RESTAPI_utils::field_from_json( Obj,"accessPIN",accessPIN);
|
||||||
RESTAPI_utils::field_from_json( Obj,"venues",venues);
|
RESTAPI_utils::field_from_json( Obj,"inUse",inUse);
|
||||||
RESTAPI_utils::field_from_json( Obj,"entities",entities);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
||||||
@@ -278,12 +276,12 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_to_json(Obj, "serialNumber", serialNumber);
|
RESTAPI_utils::field_to_json(Obj, "serialNumber", serialNumber);
|
||||||
RESTAPI_utils::field_to_json(Obj, "venue", venue);
|
RESTAPI_utils::field_to_json(Obj, "venue", venue);
|
||||||
RESTAPI_utils::field_to_json(Obj, "entity", entity);
|
RESTAPI_utils::field_to_json(Obj, "entity", entity);
|
||||||
RESTAPI_utils::field_to_json(Obj, "subEntity", subEntity);
|
|
||||||
RESTAPI_utils::field_to_json(Obj, "subVenue", subVenue);
|
|
||||||
RESTAPI_utils::field_to_json(Obj, "subscriber", subscriber);
|
RESTAPI_utils::field_to_json(Obj, "subscriber", subscriber);
|
||||||
RESTAPI_utils::field_to_json(Obj, "deviceType", deviceType);
|
RESTAPI_utils::field_to_json(Obj, "deviceType", deviceType);
|
||||||
RESTAPI_utils::field_to_json(Obj, "qrCode", qrCode);
|
RESTAPI_utils::field_to_json(Obj, "qrCode", qrCode);
|
||||||
RESTAPI_utils::field_to_json(Obj, "geoCode", geoCode);
|
RESTAPI_utils::field_to_json(Obj, "geoCode", geoCode);
|
||||||
|
RESTAPI_utils::field_to_json(Obj, "location", location);
|
||||||
|
RESTAPI_utils::field_to_json(Obj, "contact", contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
@@ -292,12 +290,12 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_from_json( Obj,"serialNumber",serialNumber);
|
RESTAPI_utils::field_from_json( Obj,"serialNumber",serialNumber);
|
||||||
RESTAPI_utils::field_from_json( Obj,"venue",venue);
|
RESTAPI_utils::field_from_json( Obj,"venue",venue);
|
||||||
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
RESTAPI_utils::field_from_json( Obj,"entity",entity);
|
||||||
RESTAPI_utils::field_from_json( Obj,"subEntity",subEntity);
|
|
||||||
RESTAPI_utils::field_from_json( Obj,"subVenue",subVenue);
|
|
||||||
RESTAPI_utils::field_from_json( Obj,"subscriber",subscriber);
|
RESTAPI_utils::field_from_json( Obj,"subscriber",subscriber);
|
||||||
RESTAPI_utils::field_from_json( Obj,"deviceType",deviceType);
|
RESTAPI_utils::field_from_json( Obj,"deviceType",deviceType);
|
||||||
RESTAPI_utils::field_from_json(Obj, "qrCode", qrCode);
|
RESTAPI_utils::field_from_json(Obj, "qrCode", qrCode);
|
||||||
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
RESTAPI_utils::field_from_json( Obj,"geoCode",geoCode);
|
||||||
|
RESTAPI_utils::field_from_json( Obj,"location",location);
|
||||||
|
RESTAPI_utils::field_from_json( Obj,"contact",contact);
|
||||||
return true;
|
return true;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
struct ManagementPolicy {
|
struct ManagementPolicy {
|
||||||
ObjectInfo info;
|
ObjectInfo info;
|
||||||
std::vector<ManagementPolicyEntry> entries;
|
std::vector<ManagementPolicyEntry> entries;
|
||||||
|
Types::StringVec inUse;
|
||||||
|
|
||||||
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);
|
||||||
@@ -142,9 +143,8 @@ namespace OpenWifi::ProvObjects {
|
|||||||
std::string country;
|
std::string country;
|
||||||
Types::StringVec phones;
|
Types::StringVec phones;
|
||||||
Types::StringVec mobiles;
|
Types::StringVec mobiles;
|
||||||
Types::StringVec venues;
|
|
||||||
Types::StringVec entities;
|
|
||||||
std::string geoCode;
|
std::string geoCode;
|
||||||
|
Types::StringVec inUse;
|
||||||
|
|
||||||
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);
|
||||||
@@ -204,8 +204,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
std::string primaryEmail;
|
std::string primaryEmail;
|
||||||
std::string secondaryEmail;
|
std::string secondaryEmail;
|
||||||
std::string accessPIN;
|
std::string accessPIN;
|
||||||
Types::StringVec venues;
|
Types::StringVec inUse;
|
||||||
Types::StringVec entities;
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -234,12 +233,12 @@ namespace OpenWifi::ProvObjects {
|
|||||||
std::string serialNumber;
|
std::string serialNumber;
|
||||||
std::string venue;
|
std::string venue;
|
||||||
std::string entity;
|
std::string entity;
|
||||||
std::string subEntity;
|
|
||||||
std::string subVenue;
|
|
||||||
std::string subscriber;
|
std::string subscriber;
|
||||||
std::string deviceType;
|
std::string deviceType;
|
||||||
std::string qrCode;
|
std::string qrCode;
|
||||||
std::string geoCode;
|
std::string geoCode;
|
||||||
|
std::string location;
|
||||||
|
std::string contact;
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ namespace OpenWifi::SecurityObjects {
|
|||||||
struct SystemEndpoint {
|
struct SystemEndpoint {
|
||||||
std::string type;
|
std::string type;
|
||||||
uint64_t id = 0;
|
uint64_t id = 0;
|
||||||
std::string vendor;
|
std::string vendor{"OpenWiFi"};
|
||||||
std::string uri;
|
std::string uri;
|
||||||
std::string authenticationType;
|
std::string authenticationType{"internal_v1"};
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -81,19 +81,9 @@ namespace OpenWifi{
|
|||||||
C.info.id = Daemon()->CreateUUID();
|
C.info.id = Daemon()->CreateUUID();
|
||||||
C.info.created = C.info.modified = std::time(nullptr);
|
C.info.created = C.info.modified = std::time(nullptr);
|
||||||
|
|
||||||
if(C.entities.empty() || C.entities.size()!=1) {
|
|
||||||
BadRequest(Request, Response, "A contact must have a single entity set.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string f{RESTAPI::Protocol::ID};
|
std::string f{RESTAPI::Protocol::ID};
|
||||||
if(!Storage()->EntityDB().Exists("id",C.entities[0])) {
|
|
||||||
BadRequest(Request, Response, "Unknown entity: " + C.entities[0] );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Storage()->ContactDB().CreateRecord(C)) {
|
if(Storage()->ContactDB().CreateRecord(C)) {
|
||||||
Storage()->EntityDB().AddContact("id",C.entities[0],C.info.id);
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
C.to_json(Answer);
|
C.to_json(Answer);
|
||||||
ReturnObject(Request, Answer, Response);
|
ReturnObject(Request, Answer, Response);
|
||||||
|
|||||||
@@ -214,18 +214,19 @@ namespace OpenWifi{
|
|||||||
if(Storage()->EntityDB().UpdateRecord("id",UUID,LocalObject)) {
|
if(Storage()->EntityDB().UpdateRecord("id",UUID,LocalObject)) {
|
||||||
for(const auto &i:Request) {
|
for(const auto &i:Request) {
|
||||||
std::string Child{i.second};
|
std::string Child{i.second};
|
||||||
if(i.first == "addContact") {
|
auto UUID_parts = Utils::Split(Child,':');
|
||||||
Storage()->EntityDB().AddContact("id", UUID, Child);
|
if(i.first=="add" && UUID_parts[0] == "con") {
|
||||||
Storage()->ContactDB().AddEntity("id",Child,UUID);
|
Storage()->EntityDB().AddContact("id", UUID, UUID_parts[1]);
|
||||||
} else if (i.first == "delContact") {
|
Storage()->ContactDB().AddInUse("id",UUID_parts[1],UUID);
|
||||||
Storage()->EntityDB().DeleteContact("id", UUID, Child);
|
} else if (i.first == "del" && UUID_parts[0] == "con") {
|
||||||
Storage()->ContactDB().DeleteEntity("id",Child,UUID);
|
Storage()->EntityDB().DeleteContact("id", UUID, UUID_parts[1]);
|
||||||
} else if (i.first == "addLocation") {
|
Storage()->ContactDB().DeleteInUse("id",UUID_parts[1],UUID);
|
||||||
Storage()->EntityDB().AddLocation("id", UUID, Child);
|
} else if (i.first == "add" && UUID_parts[0] == "loc") {
|
||||||
Storage()->LocationDB().AddEntity("id",Child,UUID);
|
Storage()->EntityDB().AddLocation("id", UUID, UUID_parts[1]);
|
||||||
} else if (i.first == "delLocation") {
|
Storage()->LocationDB().AddInUse("id",UUID_parts[1],UUID);
|
||||||
Storage()->EntityDB().DeleteLocation("id", UUID, Child);
|
} else if (i.first == "del" && UUID_parts[0] == "loc") {
|
||||||
Storage()->LocationDB().DeleteEntity("id",Child,UUID);
|
Storage()->EntityDB().DeleteLocation("id", UUID, UUID_parts[1]);
|
||||||
|
Storage()->LocationDB().DeleteInUse("id",UUID_parts[1],UUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
|
|||||||
@@ -71,15 +71,6 @@ namespace OpenWifi{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!IT.entity.empty())
|
|
||||||
Storage()->EntityDB().DeleteChild(RESTAPI::Protocol::ID,IT.entity,IT.info.id);
|
|
||||||
if(!IT.subEntity.empty())
|
|
||||||
Storage()->EntityDB().DeleteChild(RESTAPI::Protocol::ID,IT.subEntity,IT.info.id);
|
|
||||||
if(!IT.venue.empty())
|
|
||||||
Storage()->EntityDB().DeleteChild(RESTAPI::Protocol::ID,IT.venue,IT.info.id);
|
|
||||||
if(!IT.subVenue.empty())
|
|
||||||
Storage()->EntityDB().DeleteChild(RESTAPI::Protocol::ID,IT.subVenue,IT.info.id);
|
|
||||||
|
|
||||||
Storage()->InventoryDB().DeleteRecord(RESTAPI::Protocol::ID, IT.info.id);
|
Storage()->InventoryDB().DeleteRecord(RESTAPI::Protocol::ID, IT.info.id);
|
||||||
OK(Request, Response);
|
OK(Request, Response);
|
||||||
return;
|
return;
|
||||||
@@ -111,7 +102,17 @@ namespace OpenWifi{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(IT.entity.empty() || OpenWifi::EntityDB::IsRoot(IT.entity) || !Storage()->InventoryDB().Exists("id",IT.entity)) {
|
if(IT.info.name.empty()) {
|
||||||
|
BadRequest(Request, Response, "Name cannot be empty.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IT.deviceType.empty() || !Storage()->IsAcceptableDeviceType(IT.deviceType)) {
|
||||||
|
BadRequest(Request, Response, "DeviceType: '" + IT.deviceType + "' does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IT.entity.empty() || OpenWifi::EntityDB::IsRoot(IT.entity) || !Storage()->EntityDB().Exists("id",IT.entity)) {
|
||||||
BadRequest(Request, Response, "Device must be associated with a non-root and existing entity. UUID="+IT.entity);
|
BadRequest(Request, Response, "Device must be associated with a non-root and existing entity. UUID="+IT.entity);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -122,13 +123,9 @@ namespace OpenWifi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
IT.info.modified = IT.info.created = std::time(nullptr);
|
IT.info.modified = IT.info.created = std::time(nullptr);
|
||||||
IT.subEntity = IT.subVenue = "";
|
|
||||||
IT.info.id = Daemon()->CreateUUID();
|
IT.info.id = Daemon()->CreateUUID();
|
||||||
|
|
||||||
if(Storage()->InventoryDB().CreateRecord(IT)) {
|
if(Storage()->InventoryDB().CreateRecord(IT)) {
|
||||||
Storage()->EntityDB().AddChild("id",IT.entity,IT.info.id);
|
|
||||||
if(!IT.venue.empty())
|
|
||||||
Storage()->VenueDB().AddChild("id",IT.venue,IT.info.id);
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
IT.to_json(Answer);
|
IT.to_json(Answer);
|
||||||
ReturnObject(Request, Answer, Response);
|
ReturnObject(Request, Answer, Response);
|
||||||
@@ -163,12 +160,21 @@ namespace OpenWifi{
|
|||||||
SecurityObjects::append_from_json(RawObject, UserInfo_.userinfo, ExistingObject.info.notes);
|
SecurityObjects::append_from_json(RawObject, UserInfo_.userinfo, ExistingObject.info.notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RawObject->has("name"))
|
if(RawObject->has("name") && !RawObject->get("name").toString().empty())
|
||||||
ExistingObject.info.name = RawObject->get("name").toString();
|
ExistingObject.info.name = RawObject->get("name").toString();
|
||||||
if(RawObject->has("description"))
|
if(RawObject->has("description"))
|
||||||
ExistingObject.info.description = RawObject->get("description").toString();
|
ExistingObject.info.description = RawObject->get("description").toString();
|
||||||
ExistingObject.info.modified = std::time(nullptr);
|
ExistingObject.info.modified = std::time(nullptr);
|
||||||
|
|
||||||
|
if(RawObject->has("deviceType")) {
|
||||||
|
std::string DeviceType{RawObject->get("deviceType").toString()};
|
||||||
|
if(!Storage()->IsAcceptableDeviceType(DeviceType)) {
|
||||||
|
BadRequest(Request, Response, "DeviceType: '" + DeviceType + "' does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ExistingObject.deviceType = DeviceType;
|
||||||
|
}
|
||||||
|
|
||||||
// if we are changing venues...
|
// if we are changing venues...
|
||||||
if(RawObject->has("entity")) {
|
if(RawObject->has("entity")) {
|
||||||
std::string Entity{RawObject->get("entity").toString()};
|
std::string Entity{RawObject->get("entity").toString()};
|
||||||
@@ -176,22 +182,7 @@ namespace OpenWifi{
|
|||||||
BadRequest(Request, Response, "Entity association does not exist.");
|
BadRequest(Request, Response, "Entity association does not exist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Entity!=ExistingObject.entity) {
|
ExistingObject.entity = Entity;
|
||||||
Storage()->EntityDB().DeleteChild("id", ExistingObject.entity, ExistingObject.info.id);
|
|
||||||
Storage()->EntityDB().AddChild("id",Entity,ExistingObject.info.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("subEntity")) {
|
|
||||||
std::string subEntity{RawObject->get("subEntity").toString()};
|
|
||||||
if(!Storage()->EntityDB().Exists("id",subEntity)) {
|
|
||||||
BadRequest(Request, Response, "subEntity association does not exist.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(subEntity!=ExistingObject.entity) {
|
|
||||||
Storage()->EntityDB().DeleteChild("id", ExistingObject.subEntity, ExistingObject.info.id);
|
|
||||||
Storage()->EntityDB().AddChild("id",subEntity,ExistingObject.info.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RawObject->has("venue")) {
|
if(RawObject->has("venue")) {
|
||||||
@@ -200,29 +191,7 @@ namespace OpenWifi{
|
|||||||
BadRequest(Request, Response, "Venue association does not exist.");
|
BadRequest(Request, Response, "Venue association does not exist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Venue!=ExistingObject.venue) {
|
ExistingObject.venue = Venue;
|
||||||
if(!ExistingObject.venue.empty())
|
|
||||||
Storage()->VenueDB().DeleteChild("id", ExistingObject.venue, ExistingObject.info.id);
|
|
||||||
Storage()->VenueDB().AddChild("id",Venue,ExistingObject.info.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("subVenue")) {
|
|
||||||
std::string subVenue{RawObject->get("subVenue").toString()};
|
|
||||||
if(!Storage()->VenueDB().Exists("id",subVenue)) {
|
|
||||||
BadRequest(Request, Response, "Venue association does not exist.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(subVenue!=ExistingObject.subVenue) {
|
|
||||||
if(!ExistingObject.subVenue.empty())
|
|
||||||
Storage()->VenueDB().DeleteChild("id", ExistingObject.subVenue, ExistingObject.info.id);
|
|
||||||
Storage()->VenueDB().AddChild("id",subVenue,ExistingObject.info.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RawObject->has("deviceType")) {
|
|
||||||
std::string DeviceType{RawObject->get("deviceType").toString()};
|
|
||||||
ExistingObject.deviceType = DeviceType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Storage()->InventoryDB().UpdateRecord("id", ExistingObject.info.id, ExistingObject)) {
|
if(Storage()->InventoryDB().UpdateRecord("id", ExistingObject.info.id, ExistingObject)) {
|
||||||
|
|||||||
@@ -19,11 +19,6 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
class Storage *Storage::instance_ = nullptr;
|
class Storage *Storage::instance_ = nullptr;
|
||||||
|
|
||||||
Storage::Storage() noexcept:
|
|
||||||
SubSystemServer("Storage", "STORAGE-SVR", "storage")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int Storage::Start() {
|
int Storage::Start() {
|
||||||
SubMutexGuard Guard(Mutex_);
|
SubMutexGuard Guard(Mutex_);
|
||||||
|
|
||||||
@@ -152,48 +147,101 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
bool Storage::Validate(const Poco::URI::QueryParameters &P, std::string &Error) {
|
bool Storage::Validate(const Poco::URI::QueryParameters &P, std::string &Error) {
|
||||||
for(const auto &i:P) {
|
for(const auto &i:P) {
|
||||||
if(i.first == "addContact" || i.first == "delContact") {
|
auto uuid_parts = Utils::Split(i.second,':');
|
||||||
if(!ContactDB_->Exists("id",i.second)) {
|
if(uuid_parts.size()==2) {
|
||||||
Error = "Unknown contact UUID: " + i.second;
|
if(uuid_parts[0] == "con")
|
||||||
break;
|
if(!ContactDB_->Exists("id",uuid_parts[1])) {
|
||||||
}
|
Error = "Unknown contact UUID: " + i.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(i.first == "addLocation" || i.first == "delLocation") {
|
|
||||||
if(!LocationDB_->Exists("id",i.second)) {
|
if(uuid_parts.size()==2) {
|
||||||
Error = "Unknown Location UUID: " + i.second;
|
if(uuid_parts[0] == "loc")
|
||||||
break;
|
if(!LocationDB_->Exists("id",uuid_parts[1])) {
|
||||||
}
|
Error = "Unknown location UUID: " + i.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(i.first == "addEntity" || i.first == "delEntity") {
|
|
||||||
if(!EntityDB_->Exists("id",i.second)) {
|
if(uuid_parts.size()==2) {
|
||||||
Error = "Unknown Entity UUID: " + i.second;
|
if(uuid_parts[0] == "ent")
|
||||||
break;
|
if(!EntityDB_->Exists("id",uuid_parts[1])) {
|
||||||
}
|
Error = "Unknown entity UUID: " + i.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(i.first == "addVenue" || i.first == "delVenue") {
|
|
||||||
if(!VenueDB_->Exists("id",i.second)) {
|
if(uuid_parts.size()==2) {
|
||||||
Error = "Unknown Venue UUID: " + i.second;
|
if(uuid_parts[0] == "ven")
|
||||||
break;
|
if(!VenueDB_->Exists("id",uuid_parts[1])) {
|
||||||
}
|
Error = "Unknown venue UUID: " + i.second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(i.first == "addManager" || i.first == "delManager") {
|
|
||||||
/*
|
if(uuid_parts.size()==2) {
|
||||||
if(!VenueDB_->Exists("id",i.second)) {
|
if(uuid_parts[0] == "dev")
|
||||||
Error = "Unknown Manager UUID: " + i.second;
|
if(!InventoryDB_->Exists("id",uuid_parts[1])) {
|
||||||
break;
|
Error = "Unknown device UUID: " + i.second;
|
||||||
}*/
|
break;
|
||||||
}
|
}
|
||||||
if(i.first == "addDevice" || i.first == "delDevice") {
|
|
||||||
if(!InventoryDB_->Exists("id",i.second)) {
|
|
||||||
Error = "Unknown Inventory UUID: " + i.second;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Error.empty())
|
if(Error.empty())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Storage::Validate(const Types::StringVec &P, std::string &Error) {
|
||||||
|
for(const auto &i:P) {
|
||||||
|
auto uuid_parts = Utils::Split(i,':');
|
||||||
|
if(uuid_parts.size()==2) {
|
||||||
|
if(uuid_parts[0] == "con")
|
||||||
|
if(!ContactDB_->Exists("id",uuid_parts[1])) {
|
||||||
|
Error = "Unknown contact UUID: " + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(uuid_parts.size()==2) {
|
||||||
|
if(uuid_parts[0] == "loc")
|
||||||
|
if(!LocationDB_->Exists("id",uuid_parts[1])) {
|
||||||
|
Error = "Unknown location UUID: " + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(uuid_parts.size()==2) {
|
||||||
|
if(uuid_parts[0] == "ent")
|
||||||
|
if(!EntityDB_->Exists("id",uuid_parts[1])) {
|
||||||
|
Error = "Unknown entity UUID: " + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(uuid_parts.size()==2) {
|
||||||
|
if(uuid_parts[0] == "ven")
|
||||||
|
if(!VenueDB_->Exists("id",uuid_parts[1])) {
|
||||||
|
Error = "Unknown venue UUID: " + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(uuid_parts.size()==2) {
|
||||||
|
if(uuid_parts[0] == "dev")
|
||||||
|
if(!InventoryDB_->Exists("id",uuid_parts[1])) {
|
||||||
|
Error = "Unknown device UUID: " + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Error.empty())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,10 +44,6 @@ class Storage : public SubSystemServer, Poco::Runnable {
|
|||||||
|
|
||||||
[[nodiscard]] std::string ConvertParams(const std::string &S) const;
|
[[nodiscard]] std::string ConvertParams(const std::string &S) const;
|
||||||
|
|
||||||
int Setup_SQLite();
|
|
||||||
int Setup_MySQL();
|
|
||||||
int Setup_PostgreSQL();
|
|
||||||
|
|
||||||
OpenWifi::EntityDB & EntityDB() { return *EntityDB_; };
|
OpenWifi::EntityDB & EntityDB() { return *EntityDB_; };
|
||||||
OpenWifi::PolicyDB & PolicyDB() { return *PolicyDB_; };
|
OpenWifi::PolicyDB & PolicyDB() { return *PolicyDB_; };
|
||||||
OpenWifi::VenueDB & VenueDB() { return *VenueDB_; };
|
OpenWifi::VenueDB & VenueDB() { return *VenueDB_; };
|
||||||
@@ -57,6 +53,7 @@ class Storage : public SubSystemServer, Poco::Runnable {
|
|||||||
OpenWifi::ManagementRoleDB & RolesDB() { return *RolesDB_; };
|
OpenWifi::ManagementRoleDB & RolesDB() { return *RolesDB_; };
|
||||||
|
|
||||||
bool Validate(const Poco::URI::QueryParameters &P, std::string &Error);
|
bool Validate(const Poco::URI::QueryParameters &P, std::string &Error);
|
||||||
|
bool Validate(const Types::StringVec &P, std::string &Error);
|
||||||
|
|
||||||
inline bool IsAcceptableDeviceType(const std::string &D) const { return (DeviceTypes_.find(D)!=DeviceTypes_.end());};
|
inline bool IsAcceptableDeviceType(const std::string &D) const { return (DeviceTypes_.find(D)!=DeviceTypes_.end());};
|
||||||
|
|
||||||
@@ -83,7 +80,14 @@ class Storage : public SubSystemServer, Poco::Runnable {
|
|||||||
std::atomic_bool Running_=false;
|
std::atomic_bool Running_=false;
|
||||||
|
|
||||||
bool UpdateDeviceTypes();
|
bool UpdateDeviceTypes();
|
||||||
Storage() noexcept;
|
Storage() noexcept:
|
||||||
|
SubSystemServer("Storage", "STORAGE-SVR", "storage")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int Setup_SQLite();
|
||||||
|
int Setup_MySQL();
|
||||||
|
int Setup_PostgreSQL();
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Storage * Storage() { return Storage::instance(); }
|
inline Storage * Storage() { return Storage::instance(); }
|
||||||
|
|||||||
@@ -535,6 +535,14 @@ namespace ORM {
|
|||||||
return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, false);
|
return ManipulateVectorMember(&RecordType::entities, FieldName, ParentUUID, ChildUUID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool AddInUse(const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
|
||||||
|
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, ChildUUID, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool DeleteInUse(const char *FieldName, std::string & ParentUUID, std::string & ChildUUID) {
|
||||||
|
return ManipulateVectorMember(&RecordType::inUse,FieldName, ParentUUID, ChildUUID, false);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline std::string ComputeRange(uint64_t From, uint64_t HowMany) {
|
[[nodiscard]] inline std::string ComputeRange(uint64_t From, uint64_t HowMany) {
|
||||||
if(From<1) From=1;
|
if(From<1) From=1;
|
||||||
if(Type==ORM::sqlite) {
|
if(Type==ORM::sqlite) {
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"primaryEmail",ORM::FieldType::FT_TEXT},
|
ORM::Field{"primaryEmail",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"secondaryEmail",ORM::FieldType::FT_TEXT},
|
ORM::Field{"secondaryEmail",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"accessPIN",ORM::FieldType::FT_TEXT},
|
ORM::Field{"accessPIN",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"venues",ORM::FieldType::FT_TEXT},
|
ORM::Field{"inUse",ORM::FieldType::FT_TEXT}
|
||||||
ORM::Field{"entities",ORM::FieldType::FT_TEXT}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec ContactDB_Indexes{
|
static ORM::IndexVec ContactDB_Indexes{
|
||||||
@@ -66,8 +65,7 @@ template<> void ORM::DB< OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects
|
|||||||
Out.primaryEmail = In.get<15>();
|
Out.primaryEmail = In.get<15>();
|
||||||
Out.secondaryEmail = In.get<16>();
|
Out.secondaryEmail = In.get<16>();
|
||||||
Out.accessPIN = In.get<17>();
|
Out.accessPIN = In.get<17>();
|
||||||
OpenWifi::Types::from_string(In.get<18>(), Out.venues);
|
OpenWifi::Types::from_string(In.get<18>(), Out.inUse);
|
||||||
OpenWifi::Types::from_string(In.get<19>(), Out.entities);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ORM::DB< OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects::Contact>::Convert(OpenWifi::ProvObjects::Contact &In, OpenWifi::ContactDBRecordType &Out) {
|
template<> void ORM::DB< OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects::Contact>::Convert(OpenWifi::ProvObjects::Contact &In, OpenWifi::ContactDBRecordType &Out) {
|
||||||
@@ -89,6 +87,5 @@ template<> void ORM::DB< OpenWifi::ContactDBRecordType, OpenWifi::ProvObjects
|
|||||||
Out.set<15>(In.primaryEmail);
|
Out.set<15>(In.primaryEmail);
|
||||||
Out.set<16>(In.secondaryEmail);
|
Out.set<16>(In.secondaryEmail);
|
||||||
Out.set<17>(In.accessPIN);
|
Out.set<17>(In.accessPIN);
|
||||||
Out.set<18>(OpenWifi::Types::to_string(In.venues));
|
Out.set<18>(OpenWifi::Types::to_string(In.inUse));
|
||||||
Out.set<19>(OpenWifi::Types::to_string(In.entities));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ namespace OpenWifi {
|
|||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
std::string,
|
|
||||||
std::string
|
std::string
|
||||||
> ContactDBRecordType;
|
> ContactDBRecordType;
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"serialNumber",ORM::FieldType::FT_TEXT},
|
ORM::Field{"serialNumber",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"venue",ORM::FieldType::FT_TEXT},
|
ORM::Field{"venue",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"entity",ORM::FieldType::FT_TEXT},
|
ORM::Field{"entity",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"subEntity",ORM::FieldType::FT_TEXT},
|
ORM::Field{"subscriber",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"subVenue",ORM::FieldType::FT_TEXT},
|
|
||||||
ORM::Field{"deviceType",ORM::FieldType::FT_TEXT},
|
ORM::Field{"deviceType",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"qrcode",ORM::FieldType::FT_TEXT}
|
ORM::Field{"qrcode",ORM::FieldType::FT_TEXT},
|
||||||
|
ORM::Field{"geocode",ORM::FieldType::FT_TEXT},
|
||||||
|
ORM::Field{"location",ORM::FieldType::FT_TEXT},
|
||||||
|
ORM::Field{"contact",ORM::FieldType::FT_TEXT}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec InventoryDB_Indexes{
|
static ORM::IndexVec InventoryDB_Indexes{
|
||||||
@@ -53,10 +55,12 @@ template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjec
|
|||||||
Out.serialNumber = In.get<6>();
|
Out.serialNumber = In.get<6>();
|
||||||
Out.venue = In.get<7>();
|
Out.venue = In.get<7>();
|
||||||
Out.entity = In.get<8>();
|
Out.entity = In.get<8>();
|
||||||
Out.subEntity = In.get<9>();
|
Out.subscriber = In.get<9>();
|
||||||
Out.subVenue = In.get<10>();
|
Out.deviceType = In.get<10>();
|
||||||
Out.deviceType = In.get<11>();
|
|
||||||
Out.qrCode = In.get<11>();
|
Out.qrCode = In.get<11>();
|
||||||
|
Out.geoCode = In.get<12>();
|
||||||
|
Out.location = In.get<13>();
|
||||||
|
Out.contact = In.get<14>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTag>::Convert(OpenWifi::ProvObjects::InventoryTag &In, OpenWifi::InventoryDBRecordType &Out) {
|
template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjects::InventoryTag>::Convert(OpenWifi::ProvObjects::InventoryTag &In, OpenWifi::InventoryDBRecordType &Out) {
|
||||||
@@ -69,8 +73,10 @@ template<> void ORM::DB< OpenWifi::InventoryDBRecordType, OpenWifi::ProvObjec
|
|||||||
Out.set<6>(In.serialNumber);
|
Out.set<6>(In.serialNumber);
|
||||||
Out.set<7>(In.venue);
|
Out.set<7>(In.venue);
|
||||||
Out.set<8>(In.entity);
|
Out.set<8>(In.entity);
|
||||||
Out.set<9>(In.subEntity);
|
Out.set<9>(In.subscriber);
|
||||||
Out.set<10>(In.subVenue);
|
Out.set<10>(In.deviceType);
|
||||||
Out.set<11>(In.deviceType);
|
|
||||||
Out.set<11>(In.qrCode);
|
Out.set<11>(In.qrCode);
|
||||||
|
Out.set<12>(In.geoCode);
|
||||||
|
Out.set<13>(In.location);
|
||||||
|
Out.set<14>(In.contact);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace OpenWifi {
|
|||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
|
std::string,
|
||||||
|
std::string,
|
||||||
std::string
|
std::string
|
||||||
> InventoryDBRecordType;
|
> InventoryDBRecordType;
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"country",ORM::FieldType::FT_TEXT},
|
ORM::Field{"country",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"phones",ORM::FieldType::FT_TEXT},
|
ORM::Field{"phones",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"mobiles",ORM::FieldType::FT_TEXT},
|
ORM::Field{"mobiles",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"venues",ORM::FieldType::FT_TEXT},
|
ORM::Field{"geoCode",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"entities",ORM::FieldType::FT_TEXT},
|
ORM::Field{"inUse",ORM::FieldType::FT_TEXT}
|
||||||
ORM::Field{"geoCode",ORM::FieldType::FT_TEXT}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec LocationDB_Indexes{
|
static ORM::IndexVec LocationDB_Indexes{
|
||||||
@@ -60,9 +59,8 @@ template<> void ORM::DB<OpenWifi::LocationDBRecordType, OpenWifi::ProvObjects::L
|
|||||||
Out.country = In.get<12>();
|
Out.country = In.get<12>();
|
||||||
OpenWifi::Types::from_string(In.get<13>(), Out.phones);
|
OpenWifi::Types::from_string(In.get<13>(), Out.phones);
|
||||||
OpenWifi::Types::from_string(In.get<14>(), Out.mobiles);
|
OpenWifi::Types::from_string(In.get<14>(), Out.mobiles);
|
||||||
OpenWifi::Types::from_string(In.get<15>(), Out.venues);
|
Out.geoCode = In.get<15>();
|
||||||
OpenWifi::Types::from_string(In.get<16>(), Out.entities);
|
OpenWifi::Types::from_string(In.get<16>(), Out.inUse);
|
||||||
Out.geoCode = In.get<17>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ::ORM::DB<OpenWifi::LocationDBRecordType, OpenWifi::ProvObjects::Location>::Convert(OpenWifi::ProvObjects::Location &In, OpenWifi::LocationDBRecordType &Out) {
|
template<> void ::ORM::DB<OpenWifi::LocationDBRecordType, OpenWifi::ProvObjects::Location>::Convert(OpenWifi::ProvObjects::Location &In, OpenWifi::LocationDBRecordType &Out) {
|
||||||
@@ -81,8 +79,7 @@ template<> void ::ORM::DB<OpenWifi::LocationDBRecordType, OpenWifi::ProvObjects:
|
|||||||
Out.set<12>(In.country);
|
Out.set<12>(In.country);
|
||||||
Out.set<13>(OpenWifi::Types::to_string(In.phones));
|
Out.set<13>(OpenWifi::Types::to_string(In.phones));
|
||||||
Out.set<14>(OpenWifi::Types::to_string(In.mobiles));
|
Out.set<14>(OpenWifi::Types::to_string(In.mobiles));
|
||||||
Out.set<15>(OpenWifi::Types::to_string(In.venues));
|
Out.set<15>(In.geoCode);
|
||||||
Out.set<16>(OpenWifi::Types::to_string(In.entities));
|
Out.set<16>(OpenWifi::Types::to_string(In.inUse));
|
||||||
Out.set<17>(In.geoCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ namespace OpenWifi {
|
|||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
std::string,
|
|
||||||
std::string
|
std::string
|
||||||
> LocationDBRecordType;
|
> LocationDBRecordType;
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
//
|
|
||||||
// License type: BSD 3-Clause License
|
|
||||||
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
|
|
||||||
//
|
|
||||||
// Created by Stephane Bourque on 2021-03-04.
|
|
||||||
// Arilia Wireless Inc.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Daemon.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
#ifdef SMALL_BUILD
|
|
||||||
int Service::Setup_MySQL() { instance()->exit(Poco::Util::Application::EXIT_CONFIG);}
|
|
||||||
#else
|
|
||||||
|
|
||||||
int Storage::Setup_MySQL() {
|
|
||||||
|
|
||||||
Logger_.notice("MySQL Storage enabled.");
|
|
||||||
auto NumSessions = Daemon()->ConfigGetInt("storage.type.mysql.maxsessions", 64);
|
|
||||||
auto IdleTime = Daemon()->ConfigGetInt("storage.type.mysql.idletime", 60);
|
|
||||||
auto Host = Daemon()->ConfigGetString("storage.type.mysql.host");
|
|
||||||
auto Username = Daemon()->ConfigGetString("storage.type.mysql.username");
|
|
||||||
auto Password = Daemon()->ConfigGetString("storage.type.mysql.password");
|
|
||||||
auto Database = Daemon()->ConfigGetString("storage.type.mysql.database");
|
|
||||||
auto Port = Daemon()->ConfigGetString("storage.type.mysql.port");
|
|
||||||
|
|
||||||
std::string ConnectionStr =
|
|
||||||
"host=" + Host +
|
|
||||||
";user=" + Username +
|
|
||||||
";password=" + Password +
|
|
||||||
";db=" + Database +
|
|
||||||
";port=" + Port +
|
|
||||||
";compress=true;auto-reconnect=true";
|
|
||||||
|
|
||||||
MySQLConn_ = std::make_unique<Poco::Data::MySQL::Connector>();
|
|
||||||
MySQLConn_->registerConnector();
|
|
||||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(MySQLConn_->name(), ConnectionStr, 4, NumSessions, IdleTime);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
//
|
|
||||||
// License type: BSD 3-Clause License
|
|
||||||
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
|
|
||||||
//
|
|
||||||
// Created by Stephane Bourque on 2021-03-04.
|
|
||||||
// Arilia Wireless Inc.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Daemon.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
|
|
||||||
#ifdef SMALL_BUILD
|
|
||||||
int Service::Setup_PostgreSQL() { instance()->exit(Poco::Util::Application::EXIT_CONFIG);}
|
|
||||||
#else
|
|
||||||
int Storage::Setup_PostgreSQL() {
|
|
||||||
Logger_.notice("PostgreSQL Storage enabled.");
|
|
||||||
|
|
||||||
auto NumSessions = Daemon()->ConfigGetInt("storage.type.postgresql.maxsessions", 64);
|
|
||||||
auto IdleTime = Daemon()->ConfigGetInt("storage.type.postgresql.idletime", 60);
|
|
||||||
auto Host = Daemon()->ConfigGetString("storage.type.postgresql.host");
|
|
||||||
auto Username = Daemon()->ConfigGetString("storage.type.postgresql.username");
|
|
||||||
auto Password = Daemon()->ConfigGetString("storage.type.postgresql.password");
|
|
||||||
auto Database = Daemon()->ConfigGetString("storage.type.postgresql.database");
|
|
||||||
auto Port = Daemon()->ConfigGetString("storage.type.postgresql.port");
|
|
||||||
auto ConnectionTimeout = Daemon()->ConfigGetString("storage.type.postgresql.connectiontimeout");
|
|
||||||
|
|
||||||
std::string ConnectionStr =
|
|
||||||
"host=" + Host +
|
|
||||||
" user=" + Username +
|
|
||||||
" password=" + Password +
|
|
||||||
" dbname=" + Database +
|
|
||||||
" port=" + Port +
|
|
||||||
" connect_timeout=" + ConnectionTimeout;
|
|
||||||
|
|
||||||
PostgresConn_ = std::make_unique<Poco::Data::PostgreSQL::Connector>();
|
|
||||||
PostgresConn_->registerConnector();
|
|
||||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(PostgresConn_->name(), ConnectionStr, 4, NumSessions, IdleTime);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,8 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"notes",ORM::FieldType::FT_TEXT},
|
ORM::Field{"notes",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"created",ORM::FieldType::FT_BIGINT},
|
ORM::Field{"created",ORM::FieldType::FT_BIGINT},
|
||||||
ORM::Field{"modified",ORM::FieldType::FT_BIGINT},
|
ORM::Field{"modified",ORM::FieldType::FT_BIGINT},
|
||||||
ORM::Field{"entries",ORM::FieldType::FT_TEXT}
|
ORM::Field{"entries",ORM::FieldType::FT_TEXT},
|
||||||
|
ORM::Field{"inUse",ORM::FieldType::FT_TEXT}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec PolicyDB_Indexes{
|
static ORM::IndexVec PolicyDB_Indexes{
|
||||||
@@ -41,8 +42,10 @@ template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects:
|
|||||||
Out.info.created = In.get<4>();
|
Out.info.created = In.get<4>();
|
||||||
Out.info.modified = In.get<5>();
|
Out.info.modified = In.get<5>();
|
||||||
Out.entries = OpenWifi::RESTAPI_utils::to_object_array<OpenWifi::ProvObjects::ManagementPolicyEntry>(In.get<6>());
|
Out.entries = OpenWifi::RESTAPI_utils::to_object_array<OpenWifi::ProvObjects::ManagementPolicyEntry>(In.get<6>());
|
||||||
|
OpenWifi::Types::from_string(In.get<7>(), Out.inUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects::ManagementPolicy>::Convert(OpenWifi::ProvObjects::ManagementPolicy &In, OpenWifi::PolicyDBRecordType &Out) {
|
template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects::ManagementPolicy>::Convert(OpenWifi::ProvObjects::ManagementPolicy &In, OpenWifi::PolicyDBRecordType &Out) {
|
||||||
Out.set<0>(In.info.id);
|
Out.set<0>(In.info.id);
|
||||||
Out.set<1>(In.info.name);
|
Out.set<1>(In.info.name);
|
||||||
@@ -51,4 +54,5 @@ template<> void ORM::DB< OpenWifi::PolicyDBRecordType, OpenWifi::ProvObjects:
|
|||||||
Out.set<4>(In.info.created);
|
Out.set<4>(In.info.created);
|
||||||
Out.set<5>(In.info.modified);
|
Out.set<5>(In.info.modified);
|
||||||
Out.set<6>(OpenWifi::RESTAPI_utils::to_string(In.entries));
|
Out.set<6>(OpenWifi::RESTAPI_utils::to_string(In.entries));
|
||||||
|
Out.set<7>(OpenWifi::Types::to_string(In.inUse));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace OpenWifi {
|
|||||||
std::string,
|
std::string,
|
||||||
uint64_t,
|
uint64_t,
|
||||||
uint64_t,
|
uint64_t,
|
||||||
|
std::string,
|
||||||
std::string
|
std::string
|
||||||
> PolicyDBRecordType;
|
> PolicyDBRecordType;
|
||||||
|
|
||||||
|
|||||||
82
src/storage_setup.cpp
Normal file
82
src/storage_setup.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
//
|
||||||
|
// Created by stephane bourque on 2021-08-22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "StorageService.h"
|
||||||
|
#include "Daemon.h"
|
||||||
|
|
||||||
|
namespace OpenWifi {
|
||||||
|
|
||||||
|
#ifdef SMALL_BUILD
|
||||||
|
int Service::Setup_MySQL() { Daemon()->exit(Poco::Util::Application::EXIT_CONFIG); return 0; }
|
||||||
|
int Service::Setup_PostgreSQL() { Daemon()->exit(Poco::Util::Application::EXIT_CONFIG); return 0; }
|
||||||
|
#else
|
||||||
|
|
||||||
|
int Storage::Setup_SQLite() {
|
||||||
|
Logger_.notice("SQLite Storage enabled.");
|
||||||
|
auto DBName = Daemon()->DataDir() + "/" + Daemon()->ConfigGetString("storage.type.sqlite.db");
|
||||||
|
auto NumSessions = Daemon()->ConfigGetInt("storage.type.sqlite.maxsessions", 64);
|
||||||
|
auto IdleTime = Daemon()->ConfigGetInt("storage.type.sqlite.idletime", 60);
|
||||||
|
SQLiteConn_ = std::make_unique<Poco::Data::SQLite::Connector>();
|
||||||
|
SQLiteConn_->registerConnector();
|
||||||
|
Pool_ = std::make_unique<Poco::Data::SessionPool>(SQLiteConn_->name(), DBName, 4, NumSessions, IdleTime);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Storage::Setup_MySQL() {
|
||||||
|
|
||||||
|
Logger_.notice("MySQL Storage enabled.");
|
||||||
|
auto NumSessions = Daemon()->ConfigGetInt("storage.type.mysql.maxsessions", 64);
|
||||||
|
auto IdleTime = Daemon()->ConfigGetInt("storage.type.mysql.idletime", 60);
|
||||||
|
auto Host = Daemon()->ConfigGetString("storage.type.mysql.host");
|
||||||
|
auto Username = Daemon()->ConfigGetString("storage.type.mysql.username");
|
||||||
|
auto Password = Daemon()->ConfigGetString("storage.type.mysql.password");
|
||||||
|
auto Database = Daemon()->ConfigGetString("storage.type.mysql.database");
|
||||||
|
auto Port = Daemon()->ConfigGetString("storage.type.mysql.port");
|
||||||
|
|
||||||
|
std::string ConnectionStr =
|
||||||
|
"host=" + Host +
|
||||||
|
";user=" + Username +
|
||||||
|
";password=" + Password +
|
||||||
|
";db=" + Database +
|
||||||
|
";port=" + Port +
|
||||||
|
";compress=true;auto-reconnect=true";
|
||||||
|
|
||||||
|
MySQLConn_ = std::make_unique<Poco::Data::MySQL::Connector>();
|
||||||
|
MySQLConn_->registerConnector();
|
||||||
|
Pool_ = std::make_unique<Poco::Data::SessionPool>(MySQLConn_->name(), ConnectionStr, 4, NumSessions, IdleTime);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Storage::Setup_PostgreSQL() {
|
||||||
|
Logger_.notice("PostgreSQL Storage enabled.");
|
||||||
|
|
||||||
|
auto NumSessions = Daemon()->ConfigGetInt("storage.type.postgresql.maxsessions", 64);
|
||||||
|
auto IdleTime = Daemon()->ConfigGetInt("storage.type.postgresql.idletime", 60);
|
||||||
|
auto Host = Daemon()->ConfigGetString("storage.type.postgresql.host");
|
||||||
|
auto Username = Daemon()->ConfigGetString("storage.type.postgresql.username");
|
||||||
|
auto Password = Daemon()->ConfigGetString("storage.type.postgresql.password");
|
||||||
|
auto Database = Daemon()->ConfigGetString("storage.type.postgresql.database");
|
||||||
|
auto Port = Daemon()->ConfigGetString("storage.type.postgresql.port");
|
||||||
|
auto ConnectionTimeout = Daemon()->ConfigGetString("storage.type.postgresql.connectiontimeout");
|
||||||
|
|
||||||
|
std::string ConnectionStr =
|
||||||
|
"host=" + Host +
|
||||||
|
" user=" + Username +
|
||||||
|
" password=" + Password +
|
||||||
|
" dbname=" + Database +
|
||||||
|
" port=" + Port +
|
||||||
|
" connect_timeout=" + ConnectionTimeout;
|
||||||
|
|
||||||
|
PostgresConn_ = std::make_unique<Poco::Data::PostgreSQL::Connector>();
|
||||||
|
PostgresConn_->registerConnector();
|
||||||
|
Pool_ = std::make_unique<Poco::Data::SessionPool>(PostgresConn_->name(), ConnectionStr, 4, NumSessions, IdleTime);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
//
|
|
||||||
// License type: BSD 3-Clause License
|
|
||||||
// License copy: https://github.com/Telecominfraproject/wlan-cloud-ucentralgw/blob/master/LICENSE
|
|
||||||
//
|
|
||||||
// Created by Stephane Bourque on 2021-03-04.
|
|
||||||
// Arilia Wireless Inc.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Daemon.h"
|
|
||||||
#include "StorageService.h"
|
|
||||||
|
|
||||||
namespace OpenWifi {
|
|
||||||
int Storage::Setup_SQLite() {
|
|
||||||
Logger_.notice("SQLite Storage enabled.");
|
|
||||||
|
|
||||||
auto DBName = Daemon()->DataDir() + "/" + Daemon()->ConfigGetString("storage.type.sqlite.db");
|
|
||||||
auto NumSessions = Daemon()->ConfigGetInt("storage.type.sqlite.maxsessions", 64);
|
|
||||||
auto IdleTime = Daemon()->ConfigGetInt("storage.type.sqlite.idletime", 60);
|
|
||||||
|
|
||||||
SQLiteConn_ = std::make_unique<Poco::Data::SQLite::Connector>();
|
|
||||||
SQLiteConn_->registerConnector();
|
|
||||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(SQLiteConn_->name(), DBName, 4, NumSessions, IdleTime);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user