mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 09:42:38 +00:00
Framework update
This commit is contained in:
@@ -155,9 +155,8 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename DB, typename Record> void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) {
|
template <typename DB, typename Record> void ReturnRecordList(const char *ArrayName,DB & DBInstance, RESTAPIHandler & R) {
|
||||||
const auto UUIDs = Utils::Split(R.SelectedRecords());
|
|
||||||
Poco::JSON::Array ObjArr;
|
Poco::JSON::Array ObjArr;
|
||||||
for(const auto &i:UUIDs) {
|
for(const auto &i:R.SelectedRecords()) {
|
||||||
Record E;
|
Record E;
|
||||||
if(DBInstance.GetRecord("id",i,E)) {
|
if(DBInstance.GetRecord("id",i,E)) {
|
||||||
Poco::JSON::Object Obj;
|
Poco::JSON::Object Obj;
|
||||||
|
|||||||
178
src/RESTObjects/RESTAPI_CertObjects.cpp
Normal file
178
src/RESTObjects/RESTAPI_CertObjects.cpp
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
//
|
||||||
|
// Created by stephane bourque on 2021-12-07.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "RESTAPI_CertObjects.h"
|
||||||
|
|
||||||
|
using OpenWifi::RESTAPI_utils::field_to_json;
|
||||||
|
using OpenWifi::RESTAPI_utils::field_from_json;
|
||||||
|
|
||||||
|
namespace OpenWifi {
|
||||||
|
namespace CertObjects {
|
||||||
|
void CertificateEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||||
|
field_to_json(Obj,"id", id);
|
||||||
|
field_to_json(Obj,"entity", entity);
|
||||||
|
field_to_json(Obj,"creator", creator);
|
||||||
|
field_to_json(Obj,"type", type);
|
||||||
|
field_to_json(Obj,"status", status);
|
||||||
|
field_to_json(Obj,"certificate", certificate);
|
||||||
|
field_to_json(Obj,"key", key);
|
||||||
|
field_to_json(Obj,"devid", devid);
|
||||||
|
field_to_json(Obj,"cas", cas);
|
||||||
|
field_to_json(Obj,"manufacturer", manufacturer);
|
||||||
|
field_to_json(Obj,"model", model);
|
||||||
|
field_to_json(Obj,"redirector", redirector);
|
||||||
|
field_to_json(Obj,"commonName", commonName);
|
||||||
|
field_to_json(Obj,"certificateId", certificateId);
|
||||||
|
field_to_json(Obj,"batch", batch);
|
||||||
|
field_to_json(Obj,"created", created);
|
||||||
|
field_to_json(Obj,"modified", modified);
|
||||||
|
field_to_json(Obj,"revoked", revoked);
|
||||||
|
field_to_json(Obj,"revokeCount", revokeCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CertificateEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
|
try {
|
||||||
|
field_from_json(Obj,"id", id);
|
||||||
|
field_from_json(Obj,"entity", entity);
|
||||||
|
field_from_json(Obj,"creator", creator);
|
||||||
|
field_from_json(Obj,"type", type);
|
||||||
|
field_from_json(Obj,"status", status);
|
||||||
|
field_from_json(Obj,"certificate", certificate);
|
||||||
|
field_from_json(Obj,"key", key);
|
||||||
|
field_from_json(Obj,"devid", devid);
|
||||||
|
field_from_json(Obj,"cas", cas);
|
||||||
|
field_from_json(Obj,"manufacturer", manufacturer);
|
||||||
|
field_from_json(Obj,"model", model);
|
||||||
|
field_from_json(Obj,"redirector", redirector);
|
||||||
|
field_from_json(Obj,"commonName", commonName);
|
||||||
|
field_from_json(Obj,"certificateId", certificateId);
|
||||||
|
field_from_json(Obj,"batch", batch);
|
||||||
|
field_from_json(Obj,"created", created);
|
||||||
|
field_from_json(Obj,"modified", modified);
|
||||||
|
field_from_json(Obj,"revoked", revoked);
|
||||||
|
field_from_json(Obj,"revokeCount", revokeCount);
|
||||||
|
return true;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||||
|
field_to_json(Obj,"id", id);
|
||||||
|
field_to_json(Obj,"creator", creator);
|
||||||
|
field_to_json(Obj,"name", name);
|
||||||
|
field_to_json(Obj,"description", description);
|
||||||
|
field_to_json(Obj,"defaultRedirector", defaultRedirector);
|
||||||
|
field_to_json(Obj,"apiKey", apiKey);
|
||||||
|
field_to_json(Obj,"serverEnrollmentProfile", serverEnrollmentProfile);
|
||||||
|
field_to_json(Obj,"clientEnrollmentProfile", clientEnrollmentProfile);
|
||||||
|
field_to_json(Obj,"organization", organization);
|
||||||
|
field_to_json(Obj,"created", created);
|
||||||
|
field_to_json(Obj,"modified", modified);
|
||||||
|
field_to_json(Obj,"suspended", suspended);
|
||||||
|
field_to_json(Obj,"deleted", deleted);
|
||||||
|
field_to_json(Obj,"notes", notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EntityEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
|
try {
|
||||||
|
field_from_json(Obj,"id", id);
|
||||||
|
field_from_json(Obj,"creator", creator);
|
||||||
|
field_from_json(Obj,"name", name);
|
||||||
|
field_from_json(Obj,"description", description);
|
||||||
|
field_from_json(Obj,"defaultRedirector", defaultRedirector);
|
||||||
|
field_from_json(Obj,"apiKey", apiKey);
|
||||||
|
field_from_json(Obj,"serverEnrollmentProfile", serverEnrollmentProfile);
|
||||||
|
field_from_json(Obj,"clientEnrollmentProfile", clientEnrollmentProfile);
|
||||||
|
field_from_json(Obj,"organization", organization);
|
||||||
|
field_from_json(Obj,"created", created);
|
||||||
|
field_from_json(Obj,"modified", modified);
|
||||||
|
field_from_json(Obj,"suspended", suspended);
|
||||||
|
field_from_json(Obj,"deleted", deleted);
|
||||||
|
field_from_json(Obj,"notes", notes);
|
||||||
|
return true;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||||
|
field_to_json(Obj,"id", id);
|
||||||
|
field_to_json(Obj,"entity", entity);
|
||||||
|
field_to_json(Obj,"creator", creator);
|
||||||
|
field_to_json(Obj,"name", name);
|
||||||
|
field_to_json(Obj,"description", description);
|
||||||
|
field_to_json(Obj,"manufacturer", manufacturer);
|
||||||
|
field_to_json(Obj,"model", model);
|
||||||
|
field_to_json(Obj,"redirector", redirector);
|
||||||
|
field_to_json(Obj,"commonNames", commonNames);
|
||||||
|
field_to_json(Obj,"jobHistory", jobHistory);
|
||||||
|
field_to_json(Obj,"notes", notes);
|
||||||
|
field_to_json(Obj,"submitted", submitted);
|
||||||
|
field_to_json(Obj,"started", started);
|
||||||
|
field_to_json(Obj,"completed", completed);
|
||||||
|
field_to_json(Obj,"modified", modified);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BatchEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
|
try {
|
||||||
|
field_from_json(Obj,"id", id);
|
||||||
|
field_from_json(Obj,"entity", entity);
|
||||||
|
field_from_json(Obj,"creator", creator);
|
||||||
|
field_from_json(Obj,"name", name);
|
||||||
|
field_from_json(Obj,"description", description);
|
||||||
|
field_from_json(Obj,"manufacturer", manufacturer);
|
||||||
|
field_from_json(Obj,"model", model);
|
||||||
|
field_from_json(Obj,"redirector", redirector);
|
||||||
|
field_from_json(Obj,"commonNames", commonNames);
|
||||||
|
field_from_json(Obj,"jobHistory", jobHistory);
|
||||||
|
field_from_json(Obj,"notes", notes);
|
||||||
|
field_from_json(Obj,"submitted", submitted);
|
||||||
|
field_from_json(Obj,"started", started);
|
||||||
|
field_from_json(Obj,"completed", completed);
|
||||||
|
field_from_json(Obj,"modified", modified);
|
||||||
|
return true;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JobEntry::to_json(Poco::JSON::Object &Obj) const {
|
||||||
|
field_to_json(Obj,"id", id);
|
||||||
|
field_to_json(Obj,"entity", entity);
|
||||||
|
field_to_json(Obj,"creator", creator);
|
||||||
|
field_to_json(Obj,"batch", batch);
|
||||||
|
field_to_json(Obj,"commonNames", commonNames);
|
||||||
|
field_to_json(Obj,"completedNames", completedNames);
|
||||||
|
field_to_json(Obj,"errorNames", errorNames);
|
||||||
|
field_to_json(Obj,"status", status);
|
||||||
|
field_to_json(Obj,"command", command);
|
||||||
|
field_to_json(Obj,"parameters", parameters);
|
||||||
|
field_to_json(Obj,"submitted", submitted);
|
||||||
|
field_to_json(Obj,"started", started);
|
||||||
|
field_to_json(Obj,"completed", completed);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JobEntry::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||||
|
try {
|
||||||
|
field_from_json(Obj,"id", id);
|
||||||
|
field_from_json(Obj,"entity", entity);
|
||||||
|
field_from_json(Obj,"creator", creator);
|
||||||
|
field_from_json(Obj,"batch", batch);
|
||||||
|
field_from_json(Obj,"commonNames", commonNames);
|
||||||
|
field_from_json(Obj,"completedNames", completedNames);
|
||||||
|
field_from_json(Obj,"errorNames", errorNames);
|
||||||
|
field_from_json(Obj,"status", status);
|
||||||
|
field_from_json(Obj,"command", command);
|
||||||
|
field_from_json(Obj,"parameters", parameters);
|
||||||
|
field_from_json(Obj,"submitted", submitted);
|
||||||
|
field_from_json(Obj,"started", started);
|
||||||
|
field_from_json(Obj,"completed", completed);
|
||||||
|
return true;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
101
src/RESTObjects/RESTAPI_CertObjects.h
Normal file
101
src/RESTObjects/RESTAPI_CertObjects.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
//
|
||||||
|
// Created by stephane bourque on 2021-12-07.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "framework/MicroService.h"
|
||||||
|
#include "framework/OpenWifiTypes.h"
|
||||||
|
#include "RESTObjects/RESTAPI_SecurityObjects.h"
|
||||||
|
|
||||||
|
namespace OpenWifi {
|
||||||
|
|
||||||
|
namespace CertObjects {
|
||||||
|
|
||||||
|
struct CertificateEntry {
|
||||||
|
OpenWifi::Types::UUID_t id;
|
||||||
|
OpenWifi::Types::UUID_t entity;
|
||||||
|
OpenWifi::Types::UUID_t creator;
|
||||||
|
std::string type;
|
||||||
|
std::string status;
|
||||||
|
std::string certificate;
|
||||||
|
std::string key;
|
||||||
|
std::string devid;
|
||||||
|
std::string cas;
|
||||||
|
std::string manufacturer;
|
||||||
|
std::string model;
|
||||||
|
std::string redirector;
|
||||||
|
std::string commonName;
|
||||||
|
std::string certificateId;
|
||||||
|
OpenWifi::Types::UUID_t batch;
|
||||||
|
uint64_t created = 0;
|
||||||
|
uint64_t modified = 0;
|
||||||
|
uint64_t revoked = 0;
|
||||||
|
uint64_t revokeCount = 0;
|
||||||
|
|
||||||
|
void to_json(Poco::JSON::Object &Obj) const;
|
||||||
|
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EntityEntry {
|
||||||
|
OpenWifi::Types::UUID_t id;
|
||||||
|
OpenWifi::Types::UUID_t creator;
|
||||||
|
std::string name;
|
||||||
|
std::string description;
|
||||||
|
std::string defaultRedirector;
|
||||||
|
std::string apiKey;
|
||||||
|
std::string serverEnrollmentProfile;
|
||||||
|
std::string clientEnrollmentProfile;
|
||||||
|
std::string organization;
|
||||||
|
SecurityObjects::NoteInfoVec notes;
|
||||||
|
bool suspended=false;
|
||||||
|
bool deleted=false;
|
||||||
|
uint64_t created = 0 ;
|
||||||
|
uint64_t modified = 0 ;
|
||||||
|
|
||||||
|
void to_json(Poco::JSON::Object &Obj) const;
|
||||||
|
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BatchEntry {
|
||||||
|
OpenWifi::Types::UUID_t id;
|
||||||
|
OpenWifi::Types::UUID_t entity;
|
||||||
|
OpenWifi::Types::UUID_t creator;
|
||||||
|
std::string name;
|
||||||
|
std::string description;
|
||||||
|
std::string manufacturer;
|
||||||
|
std::string model;
|
||||||
|
std::string redirector;
|
||||||
|
std::vector<std::string> commonNames;
|
||||||
|
std::vector<std::string> jobHistory;
|
||||||
|
SecurityObjects::NoteInfoVec notes;
|
||||||
|
uint64_t submitted = 0 ;
|
||||||
|
uint64_t started = 0 ;
|
||||||
|
uint64_t completed = 0 ;
|
||||||
|
uint64_t modified = 0 ;
|
||||||
|
|
||||||
|
void to_json(Poco::JSON::Object &Obj) const;
|
||||||
|
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JobEntry {
|
||||||
|
OpenWifi::Types::UUID_t id;
|
||||||
|
OpenWifi::Types::UUID_t entity;
|
||||||
|
OpenWifi::Types::UUID_t creator;
|
||||||
|
OpenWifi::Types::UUID_t batch;
|
||||||
|
std::string command;
|
||||||
|
OpenWifi::Types::StringVec commonNames;
|
||||||
|
OpenWifi::Types::StringVec completedNames;
|
||||||
|
OpenWifi::Types::StringVec errorNames;
|
||||||
|
Types::StringPairVec parameters;
|
||||||
|
std::string status;
|
||||||
|
uint64_t submitted=0;
|
||||||
|
uint64_t started=0;
|
||||||
|
uint64_t completed=0;
|
||||||
|
|
||||||
|
void to_json(Poco::JSON::Object &Obj) const;
|
||||||
|
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1526,7 +1526,8 @@ namespace OpenWifi {
|
|||||||
public:
|
public:
|
||||||
struct QueryBlock {
|
struct QueryBlock {
|
||||||
uint64_t StartDate = 0 , EndDate = 0 , Offset = 0 , Limit = 0, LogType = 0 ;
|
uint64_t StartDate = 0 , EndDate = 0 , Offset = 0 , Limit = 0, LogType = 0 ;
|
||||||
std::string SerialNumber, Filter, Select;
|
std::string SerialNumber, Filter;
|
||||||
|
std::vector<std::string> Select;
|
||||||
bool Lifetime=false, LastOnly=false, Newest=false, CountOnly=false, AdditionalInfo=false;
|
bool Lifetime=false, LastOnly=false, Newest=false, CountOnly=false, AdditionalInfo=false;
|
||||||
};
|
};
|
||||||
typedef std::map<std::string, std::string> BindingMap;
|
typedef std::map<std::string, std::string> BindingMap;
|
||||||
@@ -1607,7 +1608,7 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool NeedAdditionalInfo() const { return QB_.AdditionalInfo; }
|
inline bool NeedAdditionalInfo() const { return QB_.AdditionalInfo; }
|
||||||
inline const std::string & SelectedRecords() const { return QB_.Select; }
|
inline const std::vector<std::string> & SelectedRecords() const { return QB_.Select; }
|
||||||
|
|
||||||
inline const Poco::JSON::Object::Ptr & ParseStream() {
|
inline const Poco::JSON::Object::Ptr & ParseStream() {
|
||||||
return IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>();
|
return IncomingParser_.parse(Request->stream()).extract<Poco::JSON::Object::Ptr>();
|
||||||
@@ -1845,6 +1846,22 @@ namespace OpenWifi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void SendCompressedTarFile(const std::string & FileName, const std::string & Content) {
|
||||||
|
Response->set("Content-Type","application/gzip");
|
||||||
|
Response->set("Content-Disposition", "attachment; filename=" + FileName );
|
||||||
|
Response->set("Content-Transfer-Encoding","binary");
|
||||||
|
Response->set("Accept-Ranges", "bytes");
|
||||||
|
Response->set("Cache-Control", "private");
|
||||||
|
Response->set("Pragma", "private");
|
||||||
|
Response->set("Expires", "Mon, 26 Jul 2027 05:00:00 GMT");
|
||||||
|
Response->setStatus(Poco::Net::HTTPResponse::HTTP_OK);
|
||||||
|
AddCORS();
|
||||||
|
Response->setContentLength(Content.size());
|
||||||
|
Response->setChunkedTransferEncoding(true);
|
||||||
|
std::ostream& OutputStream = Response->send();
|
||||||
|
OutputStream << Content;
|
||||||
|
}
|
||||||
|
|
||||||
inline void SendFile(Poco::File & File, const std::string & UUID) {
|
inline void SendFile(Poco::File & File, const std::string & UUID) {
|
||||||
Response->set("Content-Type","application/octet-stream");
|
Response->set("Content-Type","application/octet-stream");
|
||||||
Response->set("Content-Disposition", "attachment; filename=" + UUID );
|
Response->set("Content-Disposition", "attachment; filename=" + UUID );
|
||||||
@@ -1947,7 +1964,6 @@ namespace OpenWifi {
|
|||||||
QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 0);
|
QB_.Offset = GetParameter(RESTAPI::Protocol::OFFSET, 0);
|
||||||
QB_.Limit = GetParameter(RESTAPI::Protocol::LIMIT, 100);
|
QB_.Limit = GetParameter(RESTAPI::Protocol::LIMIT, 100);
|
||||||
QB_.Filter = GetParameter(RESTAPI::Protocol::FILTER, "");
|
QB_.Filter = GetParameter(RESTAPI::Protocol::FILTER, "");
|
||||||
QB_.Select = GetParameter(RESTAPI::Protocol::SELECT, "");
|
|
||||||
QB_.Lifetime = GetBoolParameter(RESTAPI::Protocol::LIFETIME,false);
|
QB_.Lifetime = GetBoolParameter(RESTAPI::Protocol::LIFETIME,false);
|
||||||
QB_.LogType = GetParameter(RESTAPI::Protocol::LOGTYPE,0);
|
QB_.LogType = GetParameter(RESTAPI::Protocol::LOGTYPE,0);
|
||||||
QB_.LastOnly = GetBoolParameter(RESTAPI::Protocol::LASTONLY,false);
|
QB_.LastOnly = GetBoolParameter(RESTAPI::Protocol::LASTONLY,false);
|
||||||
@@ -1955,6 +1971,11 @@ namespace OpenWifi {
|
|||||||
QB_.CountOnly = GetBoolParameter(RESTAPI::Protocol::COUNTONLY,false);
|
QB_.CountOnly = GetBoolParameter(RESTAPI::Protocol::COUNTONLY,false);
|
||||||
QB_.AdditionalInfo = GetBoolParameter(RESTAPI::Protocol::WITHEXTENDEDINFO,false);
|
QB_.AdditionalInfo = GetBoolParameter(RESTAPI::Protocol::WITHEXTENDEDINFO,false);
|
||||||
|
|
||||||
|
auto RawSelect = GetParameter(RESTAPI::Protocol::SELECT, "");
|
||||||
|
|
||||||
|
auto Entries = Poco::StringTokenizer(RawSelect,",");
|
||||||
|
for(const auto &i:Entries)
|
||||||
|
QB_.Select.emplace_back(i);
|
||||||
if(QB_.Offset<1)
|
if(QB_.Offset<1)
|
||||||
QB_.Offset=0;
|
QB_.Offset=0;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ fi
|
|||||||
|
|
||||||
token=""
|
token=""
|
||||||
result_file=result.json
|
result_file=result.json
|
||||||
username="tip@ucentral.com"
|
# username="tip@ucentral.com"
|
||||||
password="Ninja650!!!"
|
# password="Ninja650!!!"
|
||||||
|
username="stephane.bourque@gmail.com"
|
||||||
|
password="Snoopy99!!!"
|
||||||
browser_list=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
browser_list=(firefox sensible-browser xdg-open w3m links links2 lynx youtube-dl)
|
||||||
browser=""
|
browser=""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user