mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-01 19:17:47 +00:00
Improving Subscriber Signup
This commit is contained in:
@@ -507,6 +507,9 @@ components:
|
|||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
|
subscriberOnly:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
rrm:
|
rrm:
|
||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
@@ -762,6 +765,9 @@ components:
|
|||||||
format: int64
|
format: int64
|
||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
|
statusCode:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
|
||||||
Variable:
|
Variable:
|
||||||
type: object
|
type: object
|
||||||
@@ -2794,10 +2800,8 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
- cancel
|
- cancel
|
||||||
- success
|
- emailVerified
|
||||||
- inprogress
|
- deviceVerified
|
||||||
- failed
|
|
||||||
- poll
|
|
||||||
required: true
|
required: true
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
|
|||||||
@@ -115,8 +115,16 @@ namespace OpenWifi{
|
|||||||
if(!Existing.contact.empty())
|
if(!Existing.contact.empty())
|
||||||
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
|
StorageService()->ContactDB().DeleteInUse("id",Existing.contact,DB_.Prefix(),Existing.info.id);
|
||||||
|
|
||||||
if(!Existing.deviceConfiguration.empty())
|
if(!Existing.deviceConfiguration.empty()) {
|
||||||
StorageService()->ConfigurationDB().DeleteInUse("id", Existing.deviceConfiguration, DB_.Prefix(), Existing.info.id);
|
ProvObjects::DeviceConfiguration DC;
|
||||||
|
if(StorageService()->ConfigurationDB().GetRecord("id", Existing.deviceConfiguration, DC)) {
|
||||||
|
if(DC.subscriberOnly)
|
||||||
|
StorageService()->ConfigurationDB().DeleteRecord("id", Existing.deviceConfiguration);
|
||||||
|
else
|
||||||
|
StorageService()->ConfigurationDB().DeleteInUse("id", Existing.deviceConfiguration, DB_.Prefix(),
|
||||||
|
Existing.info.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(DB_.DeleteRecord("id", Existing.info.id)) {
|
if(DB_.DeleteRecord("id", Existing.info.id)) {
|
||||||
DB_.DeleteRecord(RESTAPI::Protocol::ID, Existing.info.id);
|
DB_.DeleteRecord(RESTAPI::Protocol::ID, Existing.info.id);
|
||||||
|
|||||||
@@ -9,52 +9,42 @@
|
|||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
void RESTAPI_signup_handler::DoPost() {
|
void RESTAPI_signup_handler::DoPost() {
|
||||||
|
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
auto UserName = GetParameter("email","");
|
auto UserName = GetParameter("email","");
|
||||||
Poco::toLowerInPlace(UserName);
|
Poco::toLowerInPlace(UserName);
|
||||||
auto SerialNumber = GetParameter("serialNumber","");
|
auto SerialNumber = GetParameter("serialNumber","");
|
||||||
Poco::toLowerInPlace(SerialNumber);
|
Poco::toLowerInPlace(SerialNumber);
|
||||||
|
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
if(UserName.empty() || SerialNumber.empty()) {
|
if(UserName.empty() || SerialNumber.empty()) {
|
||||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
if(!Utils::ValidEMailAddress(UserName)) {
|
if(!Utils::ValidEMailAddress(UserName)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidEmailAddress);
|
return BadRequest(RESTAPI::Errors::InvalidEmailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
if(!Utils::ValidSerialNumber(SerialNumber)) {
|
if(!Utils::ValidSerialNumber(SerialNumber)) {
|
||||||
return BadRequest(RESTAPI::Errors::InvalidSerialNumber);
|
return BadRequest(RESTAPI::Errors::InvalidSerialNumber);
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
// if a signup already exists for this user, we should just return its value
|
// if a signup already exists for this user, we should just return its value completion
|
||||||
// or its completion
|
|
||||||
SignupDB::RecordVec SEs;
|
SignupDB::RecordVec SEs;
|
||||||
std::cout << __LINE__ << std::endl;
|
if(StorageService()->SignupDB().GetRecords(0,100, SEs, " email='" + UserName + "' and serialNumber='"+SerialNumber+"' ")) {
|
||||||
if(StorageService()->SignupDB().GetRecords(0,100, SEs, "email='" + UserName + "'")) {
|
|
||||||
for(const auto &i:SEs) {
|
for(const auto &i:SEs) {
|
||||||
if((i.submitted + Signup()->GracePeriod()) > OpenWifi::Now() && i.serialNumber==SerialNumber) {
|
if (i.statusCode == ProvObjects::SignupStatusCodes::SignupWaitingForEmail ||
|
||||||
Poco::JSON::Object Answer;
|
i.statusCode == ProvObjects::SignupStatusCodes::SignupWaitingForDevice ||
|
||||||
|
i.statusCode == ProvObjects::SignupStatusCodes::SignupSuccess ) {
|
||||||
|
Logger().information(Poco::format("SIGNUP: Returning existing signup record for '%s'",i.email));
|
||||||
|
Poco::JSON::Object Answer;
|
||||||
i.to_json(Answer);
|
i.to_json(Answer);
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
} else if((i.submitted + Signup()->GracePeriod()) < OpenWifi::Now() && i.completed==0) {
|
|
||||||
StorageService()->SignupDB().DeleteRecord("id", i.info.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
// So we do not have an outstanding signup...
|
// So we do not have an outstanding signup...
|
||||||
// Can we actually claim this serial number??? if not, we need to return an error
|
// Can we actually claim this serial number??? if not, we need to return an error
|
||||||
ProvObjects::InventoryTag IT;
|
ProvObjects::InventoryTag IT;
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
if(StorageService()->InventoryDB().GetRecord("serialNumber",SerialNumber,IT)) {
|
if(StorageService()->InventoryDB().GetRecord("serialNumber",SerialNumber,IT)) {
|
||||||
|
|
||||||
if(!IT.subscriber.empty()) {
|
if(!IT.subscriber.empty()) {
|
||||||
return BadRequest(RESTAPI::Errors::SerialNumberAlreadyProvisioned);
|
return BadRequest(RESTAPI::Errors::SerialNumberAlreadyProvisioned);
|
||||||
}
|
}
|
||||||
@@ -63,13 +53,12 @@ namespace OpenWifi {
|
|||||||
return BadRequest(RESTAPI::Errors::SerialNumberNotTheProperClass);
|
return BadRequest(RESTAPI::Errors::SerialNumberNotTheProperClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
// OK, we can claim this device, can we create a userid?
|
// OK, we can claim this device, can we create a userid?
|
||||||
// Let's create one
|
// Let's create one
|
||||||
// If sec.signup("email",uuid);
|
// If sec.signup("email",uuid);
|
||||||
auto SignupUUID = MicroService::instance().CreateUUID();
|
auto SignupUUID = MicroService::instance().CreateUUID();
|
||||||
std::cout << __LINE__ << std::endl;
|
Logger().information(Poco::format("SIGNUP: Creating signup entry for '%s', uuid=%s",UserName, SignupUUID));
|
||||||
|
|
||||||
Poco::JSON::Object Body;
|
Poco::JSON::Object Body;
|
||||||
OpenAPIRequestPost CreateUser( uSERVICE_SECURITY, "/api/v1/signup", {
|
OpenAPIRequestPost CreateUser( uSERVICE_SECURITY, "/api/v1/signup", {
|
||||||
@@ -77,7 +66,6 @@ namespace OpenWifi {
|
|||||||
{ "signupUUID" , SignupUUID }
|
{ "signupUUID" , SignupUUID }
|
||||||
}, Body, 30000);
|
}, Body, 30000);
|
||||||
|
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
Poco::JSON::Object::Ptr Answer;
|
Poco::JSON::Object::Ptr Answer;
|
||||||
if(CreateUser.Do(Answer) == Poco::Net::HTTPServerResponse::HTTP_OK) {
|
if(CreateUser.Do(Answer) == Poco::Net::HTTPServerResponse::HTTP_OK) {
|
||||||
SecurityObjects::UserInfo UI;
|
SecurityObjects::UserInfo UI;
|
||||||
@@ -85,11 +73,10 @@ namespace OpenWifi {
|
|||||||
UI.from_json(Answer);
|
UI.from_json(Answer);
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
Answer->stringify(os);
|
Answer->stringify(os);
|
||||||
std::cout << "Create user: " << std::endl << os.str() << std::endl;
|
Logger().information(Poco::format("SIGNUP: email: '%s' signupID: '%s' userId: '%s'", UserName, SignupUUID, UI.id));
|
||||||
|
|
||||||
// so create the Signup entry and modify the inventory
|
// so create the Signup entry and modify the inventory
|
||||||
ProvObjects::SignupEntry SE;
|
ProvObjects::SignupEntry SE;
|
||||||
|
|
||||||
SE.info.id = SignupUUID;
|
SE.info.id = SignupUUID;
|
||||||
SE.info.created = SE.info.modified = SE.submitted = OpenWifi::Now();
|
SE.info.created = SE.info.modified = SE.submitted = OpenWifi::Now();
|
||||||
SE.completed = 0 ;
|
SE.completed = 0 ;
|
||||||
@@ -98,12 +85,10 @@ namespace OpenWifi {
|
|||||||
SE.userId = UI.id;
|
SE.userId = UI.id;
|
||||||
SE.email = UserName;
|
SE.email = UserName;
|
||||||
SE.status = "waiting-for-email-verification";
|
SE.status = "waiting-for-email-verification";
|
||||||
|
SE.statusCode = ProvObjects::SignupStatusCodes::SignupWaitingForEmail;
|
||||||
std::cout << "Creating signup entry: " << SE.email << std::endl;
|
|
||||||
StorageService()->SignupDB().CreateRecord(SE);
|
StorageService()->SignupDB().CreateRecord(SE);
|
||||||
Signup()->AddOutstandingSignup(SE);
|
Signup()->AddOutstandingSignup(SE);
|
||||||
|
|
||||||
// We do not have a device, so let's create one.
|
|
||||||
if(IT.serialNumber.empty()) {
|
if(IT.serialNumber.empty()) {
|
||||||
IT.serialNumber = SerialNumber;
|
IT.serialNumber = SerialNumber;
|
||||||
IT.info.id = MicroService::instance().CreateUUID();
|
IT.info.id = MicroService::instance().CreateUUID();
|
||||||
@@ -112,7 +97,8 @@ namespace OpenWifi {
|
|||||||
Poco::JSON::Object StateDoc;
|
Poco::JSON::Object StateDoc;
|
||||||
StateDoc.set("method", "signup");
|
StateDoc.set("method", "signup");
|
||||||
StateDoc.set("claimer", UserName);
|
StateDoc.set("claimer", UserName);
|
||||||
StateDoc.set("claimId", UI.id);
|
StateDoc.set("claimerId", UI.id);
|
||||||
|
StateDoc.set("signupUUID", SignupUUID);
|
||||||
StateDoc.set("errorCode",0);
|
StateDoc.set("errorCode",0);
|
||||||
StateDoc.set("date", OpenWifi::Now());
|
StateDoc.set("date", OpenWifi::Now());
|
||||||
StateDoc.set("status", "waiting for email-verification");
|
StateDoc.set("status", "waiting for email-verification");
|
||||||
@@ -125,7 +111,8 @@ namespace OpenWifi {
|
|||||||
Poco::JSON::Object StateDoc;
|
Poco::JSON::Object StateDoc;
|
||||||
StateDoc.set("method", "signup");
|
StateDoc.set("method", "signup");
|
||||||
StateDoc.set("claimer", UserName);
|
StateDoc.set("claimer", UserName);
|
||||||
StateDoc.set("claimId", UI.id);
|
StateDoc.set("claimerId", UI.id);
|
||||||
|
StateDoc.set("signupUUID", SignupUUID);
|
||||||
StateDoc.set("errorCode",0);
|
StateDoc.set("errorCode",0);
|
||||||
StateDoc.set("date", OpenWifi::Now());
|
StateDoc.set("date", OpenWifi::Now());
|
||||||
StateDoc.set("status", "waiting for email-verification");
|
StateDoc.set("status", "waiting for email-verification");
|
||||||
@@ -141,9 +128,6 @@ namespace OpenWifi {
|
|||||||
SE.to_json(SEAnswer);
|
SE.to_json(SEAnswer);
|
||||||
return ReturnObject(SEAnswer);
|
return ReturnObject(SEAnswer);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
|
|
||||||
return BadRequest(RESTAPI::Errors::UserAlreadyExists);
|
return BadRequest(RESTAPI::Errors::UserAlreadyExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,20 +145,19 @@ namespace OpenWifi {
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Operation == "emailVerified") {
|
if(Operation == "emailVerified" && SE.statusCode==ProvObjects::SignupStatusCodes::SignupWaitingForEmail) {
|
||||||
std::cout << "Verified email for : " << SE.email << std::endl;
|
std::cout << "Verified email for : " << SE.email << std::endl;
|
||||||
|
|
||||||
SE.info.modified = OpenWifi::Now();
|
SE.info.modified = OpenWifi::Now();
|
||||||
SE.status = "emailVerified";
|
SE.status = "emailVerified";
|
||||||
|
SE.statusCode = ProvObjects::SignupStatusCodes::SignupWaitingForDevice;
|
||||||
StorageService()->SignupDB().UpdateRecord("id", SE.info.id, SE);
|
StorageService()->SignupDB().UpdateRecord("id", SE.info.id, SE);
|
||||||
Signup()->AddOutstandingSignup(SE);
|
Signup()->AddOutstandingSignup(SE);
|
||||||
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
SE.to_json(Answer);
|
SE.to_json(Answer);
|
||||||
|
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return BadRequest("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RESTAPI_signup_handler::DoGet() {
|
void RESTAPI_signup_handler::DoGet() {
|
||||||
|
|||||||
@@ -404,6 +404,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
field_to_json( Obj,"rrm",rrm);
|
field_to_json( Obj,"rrm",rrm);
|
||||||
field_to_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
field_to_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
||||||
field_to_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
field_to_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
||||||
|
field_to_json( Obj,"subscriberOnly",subscriberOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
bool DeviceConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
@@ -417,6 +418,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
field_from_json( Obj,"rrm",rrm);
|
field_from_json( Obj,"rrm",rrm);
|
||||||
field_from_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
field_from_json( Obj,"firmwareUpgrade",firmwareUpgrade);
|
||||||
field_from_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
field_from_json( Obj,"firmwareRCOnly",firmwareRCOnly);
|
||||||
|
field_from_json( Obj,"subscriberOnly",subscriberOnly);
|
||||||
return true;
|
return true;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
|
|
||||||
@@ -635,6 +637,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_to_json( Obj,"completed", completed);
|
RESTAPI_utils::field_to_json( Obj,"completed", completed);
|
||||||
RESTAPI_utils::field_to_json( Obj,"status", status);
|
RESTAPI_utils::field_to_json( Obj,"status", status);
|
||||||
RESTAPI_utils::field_to_json( Obj,"error", error);
|
RESTAPI_utils::field_to_json( Obj,"error", error);
|
||||||
|
RESTAPI_utils::field_to_json( Obj,"statusCode", statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SignupEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
bool SignupEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
@@ -647,6 +650,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
RESTAPI_utils::field_from_json( Obj,"completed", completed);
|
RESTAPI_utils::field_from_json( Obj,"completed", completed);
|
||||||
RESTAPI_utils::field_from_json( Obj,"status", status);
|
RESTAPI_utils::field_from_json( Obj,"status", status);
|
||||||
RESTAPI_utils::field_from_json( Obj,"error", error);
|
RESTAPI_utils::field_from_json( Obj,"error", error);
|
||||||
|
RESTAPI_utils::field_from_json( Obj,"statusCode", statusCode);
|
||||||
return true;
|
return true;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
|
|
||||||
|
|||||||
@@ -264,6 +264,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
std::string rrm;
|
std::string rrm;
|
||||||
std::string firmwareUpgrade;
|
std::string firmwareUpgrade;
|
||||||
bool firmwareRCOnly=false;
|
bool firmwareRCOnly=false;
|
||||||
|
bool subscriberOnly=false;
|
||||||
|
|
||||||
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);
|
||||||
@@ -396,6 +397,16 @@ namespace OpenWifi::ProvObjects {
|
|||||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum SignupStatusCodes {
|
||||||
|
SignupCreated = 0 ,
|
||||||
|
SignupWaitingForEmail,
|
||||||
|
SignupWaitingForDevice,
|
||||||
|
SignupSuccess,
|
||||||
|
SignupFailure,
|
||||||
|
SignupCanceled,
|
||||||
|
SignupTimedOut
|
||||||
|
};
|
||||||
|
|
||||||
struct SignupEntry {
|
struct SignupEntry {
|
||||||
ObjectInfo info;
|
ObjectInfo info;
|
||||||
std::string email;
|
std::string email;
|
||||||
@@ -405,6 +416,7 @@ namespace OpenWifi::ProvObjects {
|
|||||||
uint64_t completed = 0 ;
|
uint64_t completed = 0 ;
|
||||||
std::string status;
|
std::string status;
|
||||||
uint64_t error=0;
|
uint64_t error=0;
|
||||||
|
uint64_t statusCode=0;
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace OpenWifi {
|
|||||||
// get the list of outstanding stuff and see if we have gotten the device...
|
// get the list of outstanding stuff and see if we have gotten the device...
|
||||||
std::lock_guard G(Mutex_);
|
std::lock_guard G(Mutex_);
|
||||||
for(auto &[uuid,SE]:OutstandingSignups_) {
|
for(auto &[uuid,SE]:OutstandingSignups_) {
|
||||||
if(SE.status == "emailVerified") {
|
if(SE.statusCode == ProvObjects::SignupStatusCodes::SignupWaitingForDevice) {
|
||||||
// look for the device...
|
// look for the device...
|
||||||
ProvObjects::InventoryTag IT;
|
ProvObjects::InventoryTag IT;
|
||||||
if(StorageService()->InventoryDB().GetRecord("serialNumber",SE.serialNumber,IT)) {
|
if(StorageService()->InventoryDB().GetRecord("serialNumber",SE.serialNumber,IT)) {
|
||||||
@@ -75,6 +75,7 @@ namespace OpenWifi {
|
|||||||
StorageService()->InventoryDB().UpdateRecord("id",IT.info.id,IT);
|
StorageService()->InventoryDB().UpdateRecord("id",IT.info.id,IT);
|
||||||
|
|
||||||
SE.status = "signup completed";
|
SE.status = "signup completed";
|
||||||
|
SE.statusCode = ProvObjects::SignupStatusCodes::SignupSuccess;
|
||||||
SE.completed = OpenWifi::Now();
|
SE.completed = OpenWifi::Now();
|
||||||
SE.info.modified = OpenWifi::Now();
|
SE.info.modified = OpenWifi::Now();
|
||||||
SE.error = 0 ;
|
SE.error = 0 ;
|
||||||
|
|||||||
@@ -64,6 +64,21 @@ namespace OpenWifi::SDK::Sec {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Delete(RESTAPIHandler *client, const Types::UUID_t & Id) {
|
||||||
|
OpenAPIRequestDelete Req( uSERVICE_SECURITY,
|
||||||
|
"/api/v1/subuser/" + Id,
|
||||||
|
{},
|
||||||
|
5000);
|
||||||
|
|
||||||
|
auto StatusCode = Req.Do();
|
||||||
|
if( StatusCode == Poco::Net::HTTPResponse::HTTP_OK ||
|
||||||
|
StatusCode == Poco::Net::HTTPResponse::HTTP_NO_CONTENT ||
|
||||||
|
StatusCode == Poco::Net::HTTPResponse::HTTP_ACCEPTED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace OpenWifi::SDK::Sec {
|
|||||||
namespace Subscriber {
|
namespace Subscriber {
|
||||||
bool Exists(RESTAPIHandler *client, const Types::UUID_t & User);
|
bool Exists(RESTAPIHandler *client, const Types::UUID_t & User);
|
||||||
bool Get(RESTAPIHandler *client, const Types::UUID_t & User, SecurityObjects::UserInfo & UserInfo);
|
bool Get(RESTAPIHandler *client, const Types::UUID_t & User, SecurityObjects::UserInfo & UserInfo);
|
||||||
|
bool Delete(RESTAPIHandler *client, const Types::UUID_t & User);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
|
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
ORM::Field{"tags",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"firmwareUpgrade",ORM::FieldType::FT_TEXT},
|
ORM::Field{"firmwareUpgrade",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"firmwareRCOnly",ORM::FieldType::FT_INT}
|
ORM::Field{"firmwareRCOnly",ORM::FieldType::FT_INT},
|
||||||
|
ORM::Field{"subscriberOnly",ORM::FieldType::FT_BOOLEAN}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ORM::IndexVec ConfigurationDB_Indexes{
|
static ORM::IndexVec ConfigurationDB_Indexes{
|
||||||
@@ -41,6 +42,15 @@ namespace OpenWifi {
|
|||||||
ORM::Indextype::ASC} } }
|
ORM::Indextype::ASC} } }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool ConfigurationDB::Upgrade(uint32_t from, uint32_t &to) {
|
||||||
|
std::vector<std::string> Statements{
|
||||||
|
"alter table " + TableName_ + " add column subscriberOnly BOOLEAN;"
|
||||||
|
};
|
||||||
|
RunScript(Statements);
|
||||||
|
to = 2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
ConfigurationDB::ConfigurationDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
|
ConfigurationDB::ConfigurationDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
|
||||||
DB(T, "configurations", ConfigurationDB_Fields, ConfigurationDB_Indexes, P, L, "cfg") {}
|
DB(T, "configurations", ConfigurationDB_Fields, ConfigurationDB_Indexes, P, L, "cfg") {}
|
||||||
|
|
||||||
@@ -137,6 +147,7 @@ template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvO
|
|||||||
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<12>());
|
Out.info.tags = OpenWifi::RESTAPI_utils::to_taglist(In.get<12>());
|
||||||
Out.firmwareUpgrade = In.get<13>();
|
Out.firmwareUpgrade = In.get<13>();
|
||||||
Out.firmwareRCOnly = In.get<14>();
|
Out.firmwareRCOnly = In.get<14>();
|
||||||
|
Out.subscriberOnly = In.get<15>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvObjects::DeviceConfiguration>::Convert(const OpenWifi::ProvObjects::DeviceConfiguration &In, OpenWifi::ConfigurationDBRecordType &Out) {
|
template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvObjects::DeviceConfiguration>::Convert(const OpenWifi::ProvObjects::DeviceConfiguration &In, OpenWifi::ConfigurationDBRecordType &Out) {
|
||||||
@@ -155,4 +166,5 @@ template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvO
|
|||||||
Out.set<12>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
Out.set<12>(OpenWifi::RESTAPI_utils::to_string(In.info.tags));
|
||||||
Out.set<13>(In.firmwareUpgrade);
|
Out.set<13>(In.firmwareUpgrade);
|
||||||
Out.set<14>(In.firmwareRCOnly);
|
Out.set<14>(In.firmwareRCOnly);
|
||||||
|
Out.set<15>(In.subscriberOnly);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,15 @@ namespace OpenWifi {
|
|||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
std::string,
|
std::string,
|
||||||
uint32_t
|
uint32_t,
|
||||||
|
bool
|
||||||
> ConfigurationDBRecordType;
|
> ConfigurationDBRecordType;
|
||||||
|
|
||||||
class ConfigurationDB : public ORM::DB<ConfigurationDBRecordType, ProvObjects::DeviceConfiguration> {
|
class ConfigurationDB : public ORM::DB<ConfigurationDBRecordType, ProvObjects::DeviceConfiguration> {
|
||||||
public:
|
public:
|
||||||
ConfigurationDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
ConfigurationDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
||||||
bool GetListOfAffectedDevices(const Types::UUID_t & ConfigUUID, Types::UUIDvec_t & DeviceSerialNumbers );
|
bool GetListOfAffectedDevices(const Types::UUID_t & ConfigUUID, Types::UUIDvec_t & DeviceSerialNumbers );
|
||||||
|
bool Upgrade(uint32_t from, uint32_t &to) override;
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "StorageService.h"
|
#include "StorageService.h"
|
||||||
#include "framework/MicroService.h"
|
#include "framework/MicroService.h"
|
||||||
#include "Signup.h"
|
#include "Signup.h"
|
||||||
|
#include "sdks/SDK_sec.h"
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
@@ -26,7 +27,8 @@ namespace OpenWifi {
|
|||||||
ORM::Field{"submitted",ORM::FieldType::FT_BIGINT},
|
ORM::Field{"submitted",ORM::FieldType::FT_BIGINT},
|
||||||
ORM::Field{"completed",ORM::FieldType::FT_BIGINT},
|
ORM::Field{"completed",ORM::FieldType::FT_BIGINT},
|
||||||
ORM::Field{"status",ORM::FieldType::FT_TEXT},
|
ORM::Field{"status",ORM::FieldType::FT_TEXT},
|
||||||
ORM::Field{"error",ORM::FieldType::FT_BIGINT}
|
ORM::Field{"error",ORM::FieldType::FT_BIGINT},
|
||||||
|
ORM::Field{"statusCode",ORM::FieldType::FT_BIGINT}
|
||||||
};
|
};
|
||||||
|
|
||||||
const static ORM::IndexVec SignupDB_Indexes{
|
const static ORM::IndexVec SignupDB_Indexes{
|
||||||
@@ -37,7 +39,7 @@ namespace OpenWifi {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SignupDB::SignupDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) noexcept :
|
SignupDB::SignupDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) noexcept :
|
||||||
DB(T, "signups", SignupDB_Fields, SignupDB_Indexes, P, L, "sig") {
|
DB(T, "signups2", SignupDB_Fields, SignupDB_Indexes, P, L, "sig") {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SignupDB::GetIncompleteSignups(SignupDB::RecordVec &Signups) {
|
bool SignupDB::GetIncompleteSignups(SignupDB::RecordVec &Signups) {
|
||||||
@@ -51,10 +53,63 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
void SignupDB::RemoveIncompleteSignups() {
|
void SignupDB::RemoveIncompleteSignups() {
|
||||||
try {
|
try {
|
||||||
uint64_t Floor = OpenWifi::Now() - Signup()->GracePeriod() ;
|
Types::StringVec ToDelete, TimedOut;
|
||||||
uint64_t TooOld = OpenWifi::Now() - Signup()->LingerPeriod() ;
|
uint64_t now = OpenWifi::Now();
|
||||||
DeleteRecords(" completed=0 and submitted < " + std::to_string(Floor) ); // Remove incomplete entries
|
auto F = [&](const SignupDB::RecordName &R) -> bool {
|
||||||
DeleteRecords(" completed < " + std::to_string(TooOld) ); // Remove really old stuff
|
|
||||||
|
if(R.completed!=0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if((now-R.submitted)>Signup()->LingerPeriod()) {
|
||||||
|
ToDelete.emplace_back(R.info.id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((now-R.submitted)>Signup()->GracePeriod()) {
|
||||||
|
TimedOut.push_back(R.info.id);
|
||||||
|
// delete this temporary user
|
||||||
|
SDK::Sec::Subscriber::Delete(nullptr,R.userId);
|
||||||
|
if(R.statusCode==ProvObjects::SignupStatusCodes::SignupWaitingForDevice) {
|
||||||
|
ProvObjects::InventoryTag IT;
|
||||||
|
if(StorageService()->InventoryDB().GetRecord("serialNumber",R.serialNumber,IT)) {
|
||||||
|
if(IT.devClass.empty() || IT.devClass=="any" || IT.devClass=="subscriber") {
|
||||||
|
try {
|
||||||
|
auto DeviceStatus = nlohmann::json::parse(IT.state);
|
||||||
|
if(DeviceStatus["method"]=="signup" && DeviceStatus["signupUUID"]==R.info.id) {
|
||||||
|
DeviceStatus["claimer"] = "";
|
||||||
|
DeviceStatus["claimerId"] = "";
|
||||||
|
DeviceStatus["signupUUID"] = "";
|
||||||
|
IT.subscriber = "";
|
||||||
|
IT.info.modified = Now();
|
||||||
|
IT.info.notes.push_back(SecurityObjects::NoteInfo{.created=Now(),.createdBy="signup-bot",.note="Device release from signup process."});
|
||||||
|
StorageService()->InventoryDB().UpdateRecord("serialNumber",R.serialNumber,IT);
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
Iterate(F);
|
||||||
|
|
||||||
|
for(const auto &i:ToDelete)
|
||||||
|
DeleteRecord("id",i);
|
||||||
|
|
||||||
|
for(const auto &i:TimedOut) {
|
||||||
|
SignupDB::RecordName R;
|
||||||
|
if(GetRecord("id",i,R)) {
|
||||||
|
R.statusCode=ProvObjects::SignupStatusCodes::SignupTimedOut;
|
||||||
|
R.status = "timedOut";
|
||||||
|
R.info.modified=Now();
|
||||||
|
UpdateRecord("id",i,R);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -75,6 +130,7 @@ template<> void ORM::DB< OpenWifi::SignupDBRecordType, OpenWifi::ProvObjects:
|
|||||||
Out.completed = In.get<10>();
|
Out.completed = In.get<10>();
|
||||||
Out.status = In.get<11>();
|
Out.status = In.get<11>();
|
||||||
Out.error = In.get<12>();
|
Out.error = In.get<12>();
|
||||||
|
Out.statusCode = In.get<13>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void ORM::DB< OpenWifi::SignupDBRecordType, OpenWifi::ProvObjects::SignupEntry>::Convert(const OpenWifi::ProvObjects::SignupEntry &In, OpenWifi::SignupDBRecordType &Out) {
|
template<> void ORM::DB< OpenWifi::SignupDBRecordType, OpenWifi::ProvObjects::SignupEntry>::Convert(const OpenWifi::ProvObjects::SignupEntry &In, OpenWifi::SignupDBRecordType &Out) {
|
||||||
@@ -91,4 +147,5 @@ template<> void ORM::DB< OpenWifi::SignupDBRecordType, OpenWifi::ProvObjects:
|
|||||||
Out.set<10>(In.completed);
|
Out.set<10>(In.completed);
|
||||||
Out.set<11>(In.status);
|
Out.set<11>(In.status);
|
||||||
Out.set<12>(In.error);
|
Out.set<12>(In.error);
|
||||||
|
Out.set<13>(In.statusCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace OpenWifi {
|
|||||||
uint64_t,
|
uint64_t,
|
||||||
uint64_t,
|
uint64_t,
|
||||||
std::string,
|
std::string,
|
||||||
|
uint64_t,
|
||||||
uint64_t
|
uint64_t
|
||||||
> SignupDBRecordType;
|
> SignupDBRecordType;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user