mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralfms.git
synced 2025-10-29 09:52:20 +00:00
Framework update
This commit is contained in:
@@ -297,19 +297,20 @@ namespace OpenWifi::ProvObjects {
|
||||
|
||||
void InventoryTag::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
field_to_json(Obj, "serialNumber", serialNumber);
|
||||
field_to_json(Obj, "venue", venue);
|
||||
field_to_json(Obj, "entity", entity);
|
||||
field_to_json(Obj, "subscriber", subscriber);
|
||||
field_to_json(Obj, "deviceType", deviceType);
|
||||
field_to_json(Obj, "qrCode", qrCode);
|
||||
field_to_json(Obj, "geoCode", geoCode);
|
||||
field_to_json(Obj, "location", location);
|
||||
field_to_json(Obj, "contact", contact);
|
||||
field_to_json( Obj, "serialNumber", serialNumber);
|
||||
field_to_json( Obj, "venue", venue);
|
||||
field_to_json( Obj, "entity", entity);
|
||||
field_to_json( Obj, "subscriber", subscriber);
|
||||
field_to_json( Obj, "deviceType", deviceType);
|
||||
field_to_json( Obj, "qrCode", qrCode);
|
||||
field_to_json( Obj, "geoCode", geoCode);
|
||||
field_to_json( Obj, "location", location);
|
||||
field_to_json( Obj, "contact", contact);
|
||||
field_to_json( Obj,"deviceConfiguration",deviceConfiguration);
|
||||
field_to_json( Obj,"rrm",rrm);
|
||||
field_to_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_to_json( Obj,"state",state);
|
||||
field_to_json( Obj,"devClass",devClass);
|
||||
}
|
||||
|
||||
bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
@@ -320,7 +321,7 @@ namespace OpenWifi::ProvObjects {
|
||||
field_from_json( Obj,"entity",entity);
|
||||
field_from_json( Obj,"subscriber",subscriber);
|
||||
field_from_json( Obj,"deviceType",deviceType);
|
||||
field_from_json(Obj, "qrCode", qrCode);
|
||||
field_from_json( Obj, "qrCode", qrCode);
|
||||
field_from_json( Obj,"geoCode",geoCode);
|
||||
field_from_json( Obj,"location",location);
|
||||
field_from_json( Obj,"contact",contact);
|
||||
@@ -328,6 +329,7 @@ namespace OpenWifi::ProvObjects {
|
||||
field_from_json( Obj,"rrm",rrm);
|
||||
field_from_json( Obj,"managementPolicy",managementPolicy);
|
||||
field_from_json( Obj,"state",state);
|
||||
field_from_json( Obj,"devClass",devClass);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
@@ -601,6 +603,30 @@ namespace OpenWifi::ProvObjects {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SignupEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||
info.to_json(Obj);
|
||||
RESTAPI_utils::field_to_json( Obj,"email", email);
|
||||
RESTAPI_utils::field_to_json( Obj,"userId", userId);
|
||||
RESTAPI_utils::field_to_json( Obj,"serialNumber", serialNumber);
|
||||
RESTAPI_utils::field_to_json( Obj,"created", created);
|
||||
RESTAPI_utils::field_to_json( Obj,"completed", completed);
|
||||
}
|
||||
|
||||
bool SignupEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
info.from_json(Obj);
|
||||
RESTAPI_utils::field_from_json( Obj,"email", email);
|
||||
RESTAPI_utils::field_from_json( Obj,"userId", userId);
|
||||
RESTAPI_utils::field_from_json( Obj,"serialNumber", serialNumber);
|
||||
RESTAPI_utils::field_from_json( Obj,"created", created);
|
||||
RESTAPI_utils::field_from_json( Obj,"completed", completed);
|
||||
return true;
|
||||
} catch(...) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I) {
|
||||
uint64_t Now = std::time(nullptr);
|
||||
if(O->has("name"))
|
||||
|
||||
@@ -285,6 +285,7 @@ namespace OpenWifi::ProvObjects {
|
||||
std::string rrm;
|
||||
Types::UUID_t managementPolicy;
|
||||
std::string state;
|
||||
std::string devClass;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
@@ -385,6 +386,18 @@ namespace OpenWifi::ProvObjects {
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct SignupEntry {
|
||||
ObjectInfo info;
|
||||
std::string email;
|
||||
std::string userId;
|
||||
std::string serialNumber;
|
||||
uint64_t created = 0 ;
|
||||
uint64_t completed = 0 ;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
bool UpdateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I);
|
||||
bool CreateObjectInfo(const Poco::JSON::Object::Ptr &O, const SecurityObjects::UserInfo &U, ObjectInfo &I);
|
||||
};
|
||||
|
||||
@@ -2414,7 +2414,7 @@ namespace OpenWifi {
|
||||
} else if(format == "uc-mac") {
|
||||
if(std::regex_match(value,mac_regex))
|
||||
return;
|
||||
throw std::invalid_argument(value + " is not a valid MAC: should be something like 2e60:3500::/64.");
|
||||
throw std::invalid_argument(value + " is not a valid MAC: should be something like 11:22:33:44:55:66");
|
||||
} else if(format == "uc-timeout") {
|
||||
if(std::regex_match(value,uc_timeout_regex))
|
||||
return;
|
||||
|
||||
@@ -86,6 +86,8 @@ using namespace std::chrono_literals;
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
inline uint64_t Now() { return std::time(nullptr); };
|
||||
|
||||
enum UNAUTHORIZED_REASON {
|
||||
SUCCESS=0,
|
||||
PASSWORD_CHANGE_REQUIRED,
|
||||
|
||||
@@ -430,7 +430,6 @@ namespace ORM {
|
||||
Cache_->UpdateCache(R);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
@@ -467,9 +466,10 @@ namespace ORM {
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef std::vector<RecordTuple> RecordList;
|
||||
typedef std::vector<RecordTuple> RecordList;
|
||||
typedef std::vector<RecordType> RecordVec;
|
||||
|
||||
bool GetRecords( uint64_t Offset, uint64_t HowMany, std::vector<RecordType> & Records, const std::string & Where = "", const std::string & OrderBy = "") {
|
||||
bool GetRecords( uint64_t Offset, uint64_t HowMany, RecordVec & Records, const std::string & Where = "", const std::string & OrderBy = "") {
|
||||
try {
|
||||
Poco::Data::Session Session = Pool_.get();
|
||||
Poco::Data::Statement Select(Session);
|
||||
|
||||
@@ -67,6 +67,10 @@ namespace OpenWifi::RESTAPI::Errors {
|
||||
static const std::string SMSCouldNotBeSentRetry{"SMS could not be sent to validate device, try later or change the phone number."};
|
||||
static const std::string SMSCouldNotValidate{"Code and number could not be validated"};
|
||||
static const std::string InvalidDeviceClass{"Invalid device class. Must be: any, venue, entity, or subscriber"};
|
||||
static const std::string SerialNumberAlreadyProvisioned{"This device has already been provisioned to a subscriber."};
|
||||
static const std::string SerialNumberNotTheProperClass{"Device is not available to subscribers. It ahs been assigned to another class of devices."};
|
||||
static const std::string UserAlreadyExists{"Username already exists."};
|
||||
static const std::string NotImplemented{"Function not implemented."};
|
||||
}
|
||||
|
||||
namespace OpenWifi::RESTAPI::Protocol {
|
||||
@@ -201,87 +205,104 @@ namespace OpenWifi::RESTAPI::Protocol {
|
||||
|
||||
namespace OpenWifi::uCentralProtocol {
|
||||
|
||||
const int SERIAL_NUMBER_LENGTH = 30;
|
||||
const int SERIAL_NUMBER_LENGTH = 30;
|
||||
|
||||
// vocabulary used in the PROTOCOL.md file
|
||||
static const char * JSONRPC = "jsonrpc";
|
||||
static const char * ID = "id";
|
||||
static const char * UUID = "uuid";
|
||||
static const char * JSONRPC_VERSION = "2.0";
|
||||
static const char * METHOD = "method";
|
||||
static const char * PARAMS = "params";
|
||||
static const char * SERIAL = "serial";
|
||||
static const char * FIRMWARE = "firmware";
|
||||
static const char * CONNECT = "connect";
|
||||
static const char * STATE = "state";
|
||||
static const char * HEALTHCHECK = "healthcheck";
|
||||
static const char * LOG = "log";
|
||||
static const char * CRASHLOG = "crashlog";
|
||||
static const char * PING = "ping";
|
||||
static const char * CFGPENDING = "cfgpending";
|
||||
static const char * RECOVERY = "recovery";
|
||||
static const char * COMPRESS_64 = "compress_64";
|
||||
static const char * CAPABILITIES = "capabilities";
|
||||
static const char * REQUEST_UUID = "request_uuid";
|
||||
static const char * SANITY = "sanity";
|
||||
static const char * DATA = "data";
|
||||
static const char * LOGLINES = "loglines";
|
||||
static const char * SEVERITY = "severity";
|
||||
static const char * ACTIVE = "active";
|
||||
static const char * OVERRIDEDFS = "override_dfs";
|
||||
static const char * REBOOT = "reboot";
|
||||
static const char * WHEN = "when";
|
||||
static const char * CONFIG = "config";
|
||||
static const char * EMPTY_JSON_DOC = "{}";
|
||||
static const char * RESULT = "result";
|
||||
static const char * REQUEST = "request";
|
||||
static const char * PERFORM = "perform";
|
||||
static const char * CONFIGURE = "configure";
|
||||
static const char * PENDING = "pending";
|
||||
static const char * SUBMITTED_BY_SYSTEM = "*system";
|
||||
static const char * URI = "uri";
|
||||
static const char * COMMAND = "command";
|
||||
static const char * PAYLOAD = "payload";
|
||||
static const char * KEEP_REDIRECTOR = "keep_redirector";
|
||||
static const char * DURATION = "duration";
|
||||
static const char * PATTERN = "pattern";
|
||||
static const char * LEDS = "leds";
|
||||
static const char * ON = "on";
|
||||
static const char * OFF = "off";
|
||||
static const char * BLINK = "blink";
|
||||
static const char * PACKETS = "packets";
|
||||
static const char * NETWORK = "network";
|
||||
static const char * INTERFACE = "interface";
|
||||
static const char * TRACE = "trace";
|
||||
static const char * WIFISCAN = "wifiscan";
|
||||
static const char * TYPES = "types";
|
||||
static const char * EVENT = "event";
|
||||
static const char * MESSAGE = "message";
|
||||
static const char * RTTY = "rtty";
|
||||
static const char * TOKEN = "token";
|
||||
static const char * SERVER = "server";
|
||||
static const char * PORT = "port";
|
||||
static const char * USER = "user";
|
||||
static const char * TIMEOUT = "timeout";
|
||||
static const char * UPGRADE = "upgrade";
|
||||
static const char * FACTORY = "factory";
|
||||
static const char * VERBOSE = "verbose";
|
||||
static const char * BANDS = "bands";
|
||||
static const char * CHANNELS = "channels";
|
||||
static const char * PASSWORD = "password";
|
||||
static const char * DEVICEUPDATE = "deviceupdate";
|
||||
// vocabulary used in the PROTOCOL.md file
|
||||
static const char *JSONRPC = "jsonrpc";
|
||||
static const char *ID = "id";
|
||||
static const char *UUID = "uuid";
|
||||
static const char *JSONRPC_VERSION = "2.0";
|
||||
static const char *METHOD = "method";
|
||||
static const char *PARAMS = "params";
|
||||
static const char *SERIAL = "serial";
|
||||
static const char *FIRMWARE = "firmware";
|
||||
static const char *CONNECT = "connect";
|
||||
static const char *STATE = "state";
|
||||
static const char *STATUS = "status";
|
||||
static const char *ERROR = "error";
|
||||
static const char *TEXT = "text";
|
||||
static const char *HEALTHCHECK = "healthcheck";
|
||||
static const char *LOG = "log";
|
||||
static const char *CRASHLOG = "crashlog";
|
||||
static const char *PING = "ping";
|
||||
static const char *CFGPENDING = "cfgpending";
|
||||
static const char *RECOVERY = "recovery";
|
||||
static const char *COMPRESS_64 = "compress_64";
|
||||
static const char *CAPABILITIES = "capabilities";
|
||||
static const char *REQUEST_UUID = "request_uuid";
|
||||
static const char *SANITY = "sanity";
|
||||
static const char *DATA = "data";
|
||||
static const char *LOGLINES = "loglines";
|
||||
static const char *SEVERITY = "severity";
|
||||
static const char *ACTIVE = "active";
|
||||
static const char *OVERRIDEDFS = "override_dfs";
|
||||
static const char *REBOOT = "reboot";
|
||||
static const char *WHEN = "when";
|
||||
static const char *CONFIG = "config";
|
||||
static const char *EMPTY_JSON_DOC = "{}";
|
||||
static const char *RESULT = "result";
|
||||
static const char *REQUEST = "request";
|
||||
static const char *PERFORM = "perform";
|
||||
static const char *CONFIGURE = "configure";
|
||||
static const char *PENDING = "pending";
|
||||
static const char *SUBMITTED_BY_SYSTEM = "*system";
|
||||
static const char *URI = "uri";
|
||||
static const char *COMMAND = "command";
|
||||
static const char *PAYLOAD = "payload";
|
||||
static const char *KEEP_REDIRECTOR = "keep_redirector";
|
||||
static const char *DURATION = "duration";
|
||||
static const char *PATTERN = "pattern";
|
||||
static const char *LEDS = "leds";
|
||||
static const char *ON = "on";
|
||||
static const char *OFF = "off";
|
||||
static const char *BLINK = "blink";
|
||||
static const char *PACKETS = "packets";
|
||||
static const char *NETWORK = "network";
|
||||
static const char *INTERFACE = "interface";
|
||||
static const char *TRACE = "trace";
|
||||
static const char *WIFISCAN = "wifiscan";
|
||||
static const char *TYPES = "types";
|
||||
static const char *EVENT = "event";
|
||||
static const char *MESSAGE = "message";
|
||||
static const char *RTTY = "rtty";
|
||||
static const char *TOKEN = "token";
|
||||
static const char *SERVER = "server";
|
||||
static const char *PORT = "port";
|
||||
static const char *USER = "user";
|
||||
static const char *TIMEOUT = "timeout";
|
||||
static const char *UPGRADE = "upgrade";
|
||||
static const char *FACTORY = "factory";
|
||||
static const char *VERBOSE = "verbose";
|
||||
static const char *BANDS = "bands";
|
||||
static const char *CHANNELS = "channels";
|
||||
static const char *PASSWORD = "password";
|
||||
static const char *DEVICEUPDATE = "deviceupdate";
|
||||
|
||||
static const char * SERIALNUMBER = "serialNumber";
|
||||
static const char * COMPATIBLE = "compatible";
|
||||
static const char * DISCONNECTION = "disconnection";
|
||||
static const char * TIMESTAMP = "timestamp";
|
||||
static const char * SYSTEM = "system";
|
||||
static const char * HOST = "host";
|
||||
static const char * CONNECTIONIP = "connectionIp";
|
||||
static const char * TELEMETRY = "telemetry";
|
||||
static const char * BANDWIDTH = "bandwidth";
|
||||
static const char *SERIALNUMBER = "serialNumber";
|
||||
static const char *COMPATIBLE = "compatible";
|
||||
static const char *DISCONNECTION = "disconnection";
|
||||
static const char *TIMESTAMP = "timestamp";
|
||||
static const char *SYSTEM = "system";
|
||||
static const char *HOST = "host";
|
||||
static const char *CONNECTIONIP = "connectionIp";
|
||||
static const char *TELEMETRY = "telemetry";
|
||||
static const char *BANDWIDTH = "bandwidth";
|
||||
}
|
||||
|
||||
enum EVENT_MSG {
|
||||
namespace OpenWifi::uCentralProtocol::Events {
|
||||
|
||||
static const char *CONNECT = "connect";
|
||||
static const char *STATE = "state";
|
||||
static const char *HEALTHCHECK = "healthcheck";
|
||||
static const char *LOG = "log";
|
||||
static const char *CRASHLOG = "crashlog";
|
||||
static const char *PING = "ping";
|
||||
static const char *CFGPENDING = "cfgpending";
|
||||
static const char *RECOVERY = "recovery";
|
||||
static const char *TELEMETRY = "telemetry";
|
||||
static const char *DEVICEUPDATE = "deviceupdate";
|
||||
|
||||
enum EVENT_MSG {
|
||||
ET_UNKNOWN,
|
||||
ET_CONNECT,
|
||||
ET_STATE,
|
||||
@@ -296,29 +317,39 @@ namespace OpenWifi::uCentralProtocol {
|
||||
};
|
||||
|
||||
inline static EVENT_MSG EventFromString(const std::string & Method) {
|
||||
if (!Poco::icompare(Method, CONNECT)) {
|
||||
return ET_CONNECT;
|
||||
} else if (!Poco::icompare(Method, STATE)) {
|
||||
return ET_STATE;
|
||||
} else if (!Poco::icompare(Method, HEALTHCHECK)) {
|
||||
return ET_HEALTHCHECK;
|
||||
} else if (!Poco::icompare(Method, LOG)) {
|
||||
return ET_LOG;
|
||||
} else if (!Poco::icompare(Method, CRASHLOG)) {
|
||||
return ET_CRASHLOG;
|
||||
} else if (!Poco::icompare(Method, PING)) {
|
||||
return ET_PING;
|
||||
} else if (!Poco::icompare(Method, CFGPENDING)) {
|
||||
return ET_CFGPENDING;
|
||||
} else if (!Poco::icompare(Method, RECOVERY)) {
|
||||
return ET_RECOVERY;
|
||||
} else if (!Poco::icompare(Method, DEVICEUPDATE)) {
|
||||
return ET_DEVICEUPDATE;
|
||||
} else if (!Poco::icompare(Method, TELEMETRY)) {
|
||||
return ET_TELEMETRY;
|
||||
} else
|
||||
return ET_UNKNOWN;
|
||||
static std::vector<std::pair<const char *,EVENT_MSG>> Values{
|
||||
{ CFGPENDING , ET_CFGPENDING },
|
||||
{ CONNECT, ET_CONNECT },
|
||||
{ CRASHLOG, ET_CRASHLOG },
|
||||
{ DEVICEUPDATE, ET_DEVICEUPDATE },
|
||||
{ HEALTHCHECK, ET_HEALTHCHECK },
|
||||
{ LOG, ET_LOG },
|
||||
{ PING, ET_PING },
|
||||
{ RECOVERY, ET_RECOVERY },
|
||||
{ STATE, ET_STATE },
|
||||
{ TELEMETRY, ET_TELEMETRY }
|
||||
};
|
||||
|
||||
std::string L = Poco::toLower(Method);
|
||||
auto hint = std::find_if(cbegin(Values),cend(Values),[&](const std::pair<const char *,EVENT_MSG> &v) ->bool { return strcmp(v.first,L.c_str())==0; });
|
||||
if(hint == cend(Values))
|
||||
return ET_UNKNOWN;
|
||||
return hint->second;
|
||||
};
|
||||
}
|
||||
|
||||
namespace OpenWifi::Provisioning::DeviceClass {
|
||||
|
||||
static const char * ANY = "any";
|
||||
static const char * SUBSCRIBER = "subscriber";
|
||||
static const char * VENUE = "venue";
|
||||
static const char * ENTITY = "entity";
|
||||
|
||||
inline bool Validate(const char *s) {
|
||||
static std::vector<const char *> Values{ ANY, ENTITY, SUBSCRIBER, VENUE };
|
||||
return std::find(cbegin(Values), cend(Values), s) != cend(Values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user