mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-02 03:27:51 +00:00
Framework update
This commit is contained in:
@@ -82,7 +82,7 @@ add_executable(owprov
|
||||
src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h
|
||||
src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp
|
||||
src/RESTObjects/RESTAPI_FMSObjects.h src/RESTObjects/RESTAPI_FMSObjects.cpp
|
||||
src/RESTAPI/RESTAPI_Servers.cpp
|
||||
src/RESTAPI/RESTAPI_routers.cpp
|
||||
src/Daemon.cpp src/Daemon.h
|
||||
src/Dashboard.h src/Dashboard.cpp
|
||||
src/StorageService.cpp src/StorageService.h
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace OpenWifi {
|
||||
class AutoDiscovery : public SubSystemServer, Poco::Runnable {
|
||||
public:
|
||||
|
||||
static AutoDiscovery *instance() {
|
||||
static AutoDiscovery * instance_ = new AutoDiscovery;
|
||||
static auto instance() {
|
||||
static auto instance_ = new AutoDiscovery;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenWifi {
|
||||
}
|
||||
};
|
||||
|
||||
inline AutoDiscovery * AutoDiscovery() { return AutoDiscovery::instance(); }
|
||||
inline auto AutoDiscovery() { return AutoDiscovery::instance(); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ namespace OpenWifi {
|
||||
|
||||
class JobRegistry {
|
||||
public:
|
||||
static JobRegistry *instance() {
|
||||
static JobRegistry * instance_ = new JobRegistry;
|
||||
static auto instance() {
|
||||
static auto instance_ = new JobRegistry;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -100,12 +100,12 @@ namespace OpenWifi {
|
||||
std::map<std::string,Job::WorkerFunction> JobTypes_;
|
||||
};
|
||||
|
||||
inline JobRegistry * JobRegistry() { return JobRegistry::instance(); }
|
||||
inline auto JobRegistry() { return JobRegistry::instance(); }
|
||||
|
||||
class JobController : public SubSystemServer, Poco::Runnable {
|
||||
public:
|
||||
static JobController *instance() {
|
||||
static JobController * instance_ = new JobController;
|
||||
static auto instance() {
|
||||
static auto instance_ = new JobController;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace OpenWifi {
|
||||
{
|
||||
}
|
||||
};
|
||||
inline JobController * JobController() { return JobController::instance(); }
|
||||
inline auto JobController() { return JobController::instance(); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -174,4 +174,17 @@ namespace OpenWifi {
|
||||
return R.ReturnObject(Answer);
|
||||
}
|
||||
|
||||
inline bool NormalizeMac(std::string & Mac) {
|
||||
Poco::replaceInPlace(Mac,":","");
|
||||
Poco::replaceInPlace(Mac,"-","");
|
||||
if(Mac.size()!=12)
|
||||
return false;
|
||||
for(const auto &i:Mac) {
|
||||
if(!std::isxdigit(i))
|
||||
return false;
|
||||
}
|
||||
Poco::toLowerInPlace(Mac);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -142,11 +142,10 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
}
|
||||
|
||||
if(!Utils::ValidSerialNumber(SerialNumber)) {
|
||||
if(!NormalizeMac(SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidSerialNumber);
|
||||
}
|
||||
|
||||
Poco::toLowerInPlace(SerialNumber);
|
||||
if(DB_.Exists(RESTAPI::Protocol::SERIALNUMBER,SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::SerialNumberExists + " (" + SerialNumber + ")");
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ namespace OpenWifi::SecurityObjects {
|
||||
return ADMIN;
|
||||
else if (!Poco::icompare(U,"subscriber"))
|
||||
return SUBSCRIBER;
|
||||
else if (!Poco::icompare(U,"partner"))
|
||||
return PARTNER;
|
||||
else if (!Poco::icompare(U,"csr"))
|
||||
return CSR;
|
||||
else if (!Poco::icompare(U, "system"))
|
||||
@@ -72,6 +74,7 @@ namespace OpenWifi::SecurityObjects {
|
||||
case ROOT: return "root";
|
||||
case ADMIN: return "admin";
|
||||
case SUBSCRIBER: return "subscriber";
|
||||
case PARTNER: return "partner";
|
||||
case CSR: return "csr";
|
||||
case SYSTEM: return "system";
|
||||
case INSTALLER: return "installer";
|
||||
@@ -265,6 +268,8 @@ namespace OpenWifi::SecurityObjects {
|
||||
field_from_json(Obj,"currentLoginURI",currentLoginURI);
|
||||
field_from_json(Obj,"locale",locale);
|
||||
field_from_json(Obj,"notes",notes);
|
||||
field_from_json(Obj,"location", location);
|
||||
field_from_json(Obj,"owner", owner);
|
||||
field_from_json<USER_ROLE>(Obj,"userRole",userRole, UserTypeFromString);
|
||||
field_from_json(Obj,"securityPolicy",securityPolicy);
|
||||
field_from_json(Obj,"userTypeProprietaryInfo",userTypeProprietaryInfo);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
enum USER_ROLE {
|
||||
UNKNOWN, ROOT, ADMIN, SUBSCRIBER, CSR, SYSTEM, INSTALLER, NOC, ACCOUNTING
|
||||
UNKNOWN, ROOT, ADMIN, SUBSCRIBER, CSR, SYSTEM, INSTALLER, NOC, ACCOUNTING, PARTNER
|
||||
};
|
||||
|
||||
USER_ROLE UserTypeFromString(const std::string &U);
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace OpenWifi {
|
||||
|
||||
typedef std::vector<DeviceTypeCacheEntry> SerialCacheContent;
|
||||
|
||||
static SerialNumberCache *instance() {
|
||||
static SerialNumberCache * instance_ = new SerialNumberCache;
|
||||
static auto instance() {
|
||||
static auto instance_ = new SerialNumberCache;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenWifi {
|
||||
}
|
||||
};
|
||||
|
||||
inline SerialNumberCache * SerialNumberCache() { return SerialNumberCache::instance(); }
|
||||
inline auto SerialNumberCache() { return SerialNumberCache::instance(); }
|
||||
|
||||
} // namespace OpenWiFi
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace OpenWifi {
|
||||
typedef std::map<std::string,uint32_t> DictMap;
|
||||
typedef std::map<std::string,DictMap> EntityToDict;
|
||||
|
||||
static TagServer *instance() {
|
||||
static TagServer * instance_ = new TagServer;
|
||||
static auto instance() {
|
||||
static auto instance_ = new TagServer;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,6 @@ namespace OpenWifi {
|
||||
}
|
||||
};
|
||||
|
||||
inline TagServer * TagServer() { return TagServer::instance(); }
|
||||
inline auto TagServer() { return TagServer::instance(); }
|
||||
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace OpenWifi {
|
||||
|
||||
class WebSocketClientServer : public SubSystemServer, Poco::Runnable {
|
||||
public:
|
||||
static WebSocketClientServer *instance() {
|
||||
static WebSocketClientServer * instance_ = new WebSocketClientServer;
|
||||
static auto instance() {
|
||||
static auto instance_ = new WebSocketClientServer;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenWifi {
|
||||
}
|
||||
};
|
||||
|
||||
inline WebSocketClientServer * WebSocketClientServer() { return WebSocketClientServer::instance(); }
|
||||
inline auto WebSocketClientServer() { return WebSocketClientServer::instance(); }
|
||||
|
||||
class WebSocketClient {
|
||||
public:
|
||||
@@ -154,5 +154,6 @@ namespace OpenWifi {
|
||||
void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification>& pNf);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,9 @@ namespace OpenWifi {
|
||||
ACCESS_DENIED,
|
||||
INVALID_TOKEN,
|
||||
EXPIRED_TOKEN,
|
||||
RATE_LIMIT_EXCEEDED
|
||||
RATE_LIMIT_EXCEEDED,
|
||||
BAD_MFA_TRANSACTION,
|
||||
MFA_FAILURE
|
||||
};
|
||||
|
||||
class AppServiceRegistry {
|
||||
@@ -1578,7 +1580,7 @@ namespace OpenWifi {
|
||||
if (AlwaysAuthorize_ && !IsAuthorized(Expired, SubOnlyService_)) {
|
||||
if(Expired)
|
||||
return UnAuthorized(RESTAPI::Errors::ExpiredToken, EXPIRED_TOKEN);
|
||||
return UnAuthorized(RESTAPI::Errors::InvalidCredentials, ACCESS_DENIED);
|
||||
return UnAuthorized(RESTAPI::Errors::InvalidCredentials, INVALID_TOKEN);
|
||||
}
|
||||
|
||||
std::string Reason;
|
||||
@@ -1588,19 +1590,19 @@ namespace OpenWifi {
|
||||
|
||||
ParseParameters();
|
||||
if (Request->getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
|
||||
DoGet();
|
||||
return DoGet();
|
||||
else if (Request->getMethod() == Poco::Net::HTTPRequest::HTTP_POST)
|
||||
DoPost();
|
||||
return DoPost();
|
||||
else if (Request->getMethod() == Poco::Net::HTTPRequest::HTTP_DELETE)
|
||||
DoDelete();
|
||||
return DoDelete();
|
||||
else if (Request->getMethod() == Poco::Net::HTTPRequest::HTTP_PUT)
|
||||
DoPut();
|
||||
return DoPut();
|
||||
else
|
||||
BadRequest(RESTAPI::Errors::UnsupportedHTTPMethod);
|
||||
return BadRequest(RESTAPI::Errors::UnsupportedHTTPMethod);
|
||||
return;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
BadRequest(RESTAPI::Errors::InternalError);
|
||||
return BadRequest(RESTAPI::Errors::InternalError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2073,7 +2075,7 @@ namespace OpenWifi {
|
||||
EndPoint_(EndPoint),
|
||||
QueryData_(QueryData),
|
||||
msTimeout_(msTimeout) {};
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus Do(Poco::JSON::Object::Ptr &ResponseObject);
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus Do(Poco::JSON::Object::Ptr &ResponseObject, const std::string & BearerToken = "");
|
||||
private:
|
||||
std::string Type_;
|
||||
std::string EndPoint_;
|
||||
@@ -2094,7 +2096,7 @@ namespace OpenWifi {
|
||||
msTimeout_(msTimeout),
|
||||
Body_(Body){};
|
||||
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus Do(Poco::JSON::Object::Ptr &ResponseObject);
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus Do(Poco::JSON::Object::Ptr &ResponseObject, const std::string & BearerToken = "");
|
||||
|
||||
private:
|
||||
std::string Type_;
|
||||
@@ -2116,7 +2118,7 @@ namespace OpenWifi {
|
||||
QueryData_(QueryData),
|
||||
msTimeout_(msTimeout),
|
||||
Body_(Body){};
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus Do(Poco::JSON::Object::Ptr &ResponseObject);
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus Do(Poco::JSON::Object::Ptr &ResponseObject, const std::string & BearerToken = "");
|
||||
private:
|
||||
std::string Type_;
|
||||
std::string EndPoint_;
|
||||
@@ -3648,7 +3650,7 @@ namespace OpenWifi {
|
||||
void DoDelete() final {};
|
||||
};
|
||||
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus OpenAPIRequestGet::Do(Poco::JSON::Object::Ptr &ResponseObject) {
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus OpenAPIRequestGet::Do(Poco::JSON::Object::Ptr &ResponseObject, const std::string & BearerToken) {
|
||||
try {
|
||||
auto Services = MicroService::instance().GetServices(Type_);
|
||||
for(auto const &Svc:Services) {
|
||||
@@ -3665,8 +3667,15 @@ namespace OpenWifi {
|
||||
Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_GET,
|
||||
Path,
|
||||
Poco::Net::HTTPMessage::HTTP_1_1);
|
||||
|
||||
if(BearerToken.empty()) {
|
||||
Request.add("X-API-KEY", Svc.AccessKey);
|
||||
Request.add("X-INTERNAL-NAME", MicroService::instance().PublicEndPoint());
|
||||
} else {
|
||||
// Authorization: Bearer ${token}
|
||||
Request.add("Authorization", "Bearer " + BearerToken);
|
||||
}
|
||||
|
||||
Session.sendRequest(Request);
|
||||
|
||||
Poco::Net::HTTPResponse Response;
|
||||
@@ -3685,7 +3694,7 @@ namespace OpenWifi {
|
||||
return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT;
|
||||
}
|
||||
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus OpenAPIRequestPut::Do(Poco::JSON::Object::Ptr &ResponseObject) {
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus OpenAPIRequestPut::Do(Poco::JSON::Object::Ptr &ResponseObject, const std::string & BearerToken) {
|
||||
try {
|
||||
auto Services = MicroService::instance().GetServices(Type_);
|
||||
for(auto const &Svc:Services) {
|
||||
@@ -3708,8 +3717,13 @@ namespace OpenWifi {
|
||||
Request.setContentType("application/json");
|
||||
Request.setContentLength(obody.str().size());
|
||||
|
||||
if(BearerToken.empty()) {
|
||||
Request.add("X-API-KEY", Svc.AccessKey);
|
||||
Request.add("X-INTERNAL-NAME", MicroService::instance().PublicEndPoint());
|
||||
} else {
|
||||
// Authorization: Bearer ${token}
|
||||
Request.add("Authorization", "Bearer " + BearerToken);
|
||||
}
|
||||
|
||||
std::ostream & os = Session.sendRequest(Request);
|
||||
os << obody.str();
|
||||
@@ -3733,9 +3747,10 @@ namespace OpenWifi {
|
||||
return Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT;
|
||||
}
|
||||
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus OpenAPIRequestPost::Do(Poco::JSON::Object::Ptr &ResponseObject) {
|
||||
inline Poco::Net::HTTPServerResponse::HTTPStatus OpenAPIRequestPost::Do(Poco::JSON::Object::Ptr &ResponseObject, const std::string & BearerToken) {
|
||||
try {
|
||||
auto Services = MicroService::instance().GetServices(Type_);
|
||||
|
||||
for(auto const &Svc:Services) {
|
||||
Poco::URI URI(Svc.PrivateEndPoint);
|
||||
Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
|
||||
@@ -3756,8 +3771,13 @@ namespace OpenWifi {
|
||||
Request.setContentType("application/json");
|
||||
Request.setContentLength(obody.str().size());
|
||||
|
||||
if(BearerToken.empty()) {
|
||||
Request.add("X-API-KEY", Svc.AccessKey);
|
||||
Request.add("X-INTERNAL-NAME", MicroService::instance().PublicEndPoint());
|
||||
} else {
|
||||
// Authorization: Bearer ${token}
|
||||
Request.add("Authorization", "Bearer " + BearerToken);
|
||||
}
|
||||
|
||||
std::ostream & os = Session.sendRequest(Request);
|
||||
os << obody.str();
|
||||
|
||||
@@ -35,7 +35,7 @@ fi
|
||||
token=""
|
||||
result_file=result.json
|
||||
username="tip@ucentral.com"
|
||||
password="openwifi"
|
||||
password="Ninja650!!!"
|
||||
browser_list=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
||||
browser=""
|
||||
|
||||
@@ -43,7 +43,7 @@ login() {
|
||||
payload="{ \"userId\" : \"$username\" , \"password\" : \"$password\" }"
|
||||
token=$(curl ${FLAGS} -X POST -H "Content-Type: application/json" -d "$payload" "https://${OWSEC}/api/v1/oauth2" | jq -r '.access_token')
|
||||
|
||||
if [[ "${token}" == "" ]]
|
||||
if [[ "${token}" == "null" ]]
|
||||
then
|
||||
echo "Could not login. Please verify the host and username/password."
|
||||
exit 13
|
||||
@@ -459,7 +459,7 @@ affecteddevices() {
|
||||
|
||||
shopt -s nocasematch
|
||||
case "$1" in
|
||||
"login") login; help ; logout ;;
|
||||
"login") login; echo "You are logged in..." ; logout ;;
|
||||
"getroot") login; getroot; logout;;
|
||||
"setroot") login; setroot; logout;;
|
||||
"addentity") login; addentity "$2" ; logout;;
|
||||
|
||||
Reference in New Issue
Block a user