mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-11-02 03:37:51 +00:00
ADMIN missing in userroles.
This commit is contained in:
@@ -45,8 +45,7 @@ find_package(ZLIB REQUIRED)
|
||||
find_package(CppKafka REQUIRED)
|
||||
find_package(PostgreSQL REQUIRED)
|
||||
find_package(MySQL REQUIRED)
|
||||
find_package(ODBC REQUIRED)
|
||||
find_package(Poco REQUIRED COMPONENTS JSON Crypto JWT Net Util NetSSL Data DataSQLite DataPostgreSQL DataMySQL DataODBC)
|
||||
find_package(Poco REQUIRED COMPONENTS JSON Crypto JWT Net Util NetSSL Data DataSQLite DataPostgreSQL DataMySQL)
|
||||
|
||||
add_executable( ucentralsec
|
||||
build
|
||||
@@ -63,18 +62,18 @@ add_executable( ucentralsec
|
||||
src/KafkaManager.h src/KafkaManager.cpp
|
||||
src/StorageService.cpp src/StorageService.h
|
||||
src/Utils.cpp src/Utils.h
|
||||
src/storage_sqlite.cpp src/storage_odbc.cpp src/storage_sqlite.cpp src/storage_pgql.cpp src/storage_mysql.cpp
|
||||
src/storage_sqlite.cpp src/storage_sqlite.cpp src/storage_pgql.cpp src/storage_mysql.cpp
|
||||
src/storage_tables.cpp src/SMTPMailerService.cpp src/SMTPMailerService.h
|
||||
src/RESTAPI_users_handler.cpp src/RESTAPI_users_handler.h
|
||||
src/RESTAPI_user_handler.cpp src/RESTAPI_user_handler.h
|
||||
src/RESTAPI_action_links.cpp src/RESTAPI_action_links.h src/storage_users.cpp
|
||||
src/RESTAPI_InternalServer.cpp src/RESTAPI_InternalServer.h
|
||||
src/RESTAPI_validateToken_handler.cpp src/RESTAPI_validateToken_handler.h
|
||||
src/RESTAPI_systemEndpoints_handler.cpp src/RESTAPI_systemEndpoints_handler.h src/RESTAPI_AssetServer.cpp src/RESTAPI_AssetServer.h)
|
||||
src/RESTAPI_systemEndpoints_handler.cpp src/RESTAPI_systemEndpoints_handler.h src/RESTAPI_AssetServer.cpp src/RESTAPI_AssetServer.h src/RESTAPI_avatarHandler.cpp src/RESTAPI_avatarHandler.h src/storage_avatar.cpp src/storage_avatar.h src/storage_users.h)
|
||||
|
||||
if(NOT SMALL_BUILD)
|
||||
target_link_libraries(ucentralsec PUBLIC
|
||||
${Poco_LIBRARIES} ${Boost_LIBRARIES} ${MySQL_LIBRARIES} ${ODBC_LIBRARIES} ${ZLIB_LIBRARIES} ${LUA_LIBRARIES}
|
||||
${Poco_LIBRARIES} ${Boost_LIBRARIES} ${MySQL_LIBRARIES} ${ZLIB_LIBRARIES}
|
||||
CppKafka::cppkafka
|
||||
)
|
||||
if(UNIX AND NOT APPLE)
|
||||
|
||||
@@ -465,6 +465,12 @@ paths:
|
||||
schema:
|
||||
type: boolean
|
||||
required: false
|
||||
-in: query
|
||||
name: requirements
|
||||
description: A user forgot her password. She needs to present her e-mail address in the userId and set this to true
|
||||
schema:
|
||||
type: boolean
|
||||
required: false
|
||||
requestBody:
|
||||
description: User id and password
|
||||
required: true
|
||||
|
||||
@@ -87,6 +87,13 @@ namespace uCentral {
|
||||
}
|
||||
}
|
||||
|
||||
void KafkaManager::PartitionAssignment(const cppkafka::TopicPartitionList& partitions) {
|
||||
Logger_.information(Poco::format("Partition assigned: %Lu...",(uint64_t )partitions.front().get_partition()));
|
||||
}
|
||||
void KafkaManager::PartitionRevocation(const cppkafka::TopicPartitionList& partitions) {
|
||||
Logger_.information(Poco::format("Partition revocation: %Lu...",(uint64_t )partitions.front().get_partition()));
|
||||
}
|
||||
|
||||
void KafkaManager::ConsumerThr() {
|
||||
cppkafka::Configuration Config({
|
||||
{ "client.id", Daemon()->ConfigGetString("ucentral.kafka.client.id") },
|
||||
@@ -105,13 +112,20 @@ namespace uCentral {
|
||||
Config.set_default_topic_configuration(topic_config);
|
||||
|
||||
cppkafka::Consumer Consumer(Config);
|
||||
Consumer.set_assignment_callback([this](const cppkafka::TopicPartitionList& partitions) {
|
||||
Logger_.information(Poco::format("Partition assigned: %Lu...",(uint64_t )partitions.front().get_partition()));
|
||||
Consumer.set_assignment_callback([this](cppkafka::TopicPartitionList& partitions) {
|
||||
if(partitions.size()>0) {
|
||||
Logger_.information(Poco::format("Partition assigned: %Lu...",
|
||||
(uint64_t)partitions.front().get_partition()));
|
||||
}
|
||||
});
|
||||
Consumer.set_revocation_callback([this](const cppkafka::TopicPartitionList& partitions) {
|
||||
Logger_.information(Poco::format("Partition revocation: %Lu...",(uint64_t )partitions.front().get_partition()));
|
||||
if(partitions.size()>0) {
|
||||
Logger_.information(Poco::format("Partition revocation: %Lu...",
|
||||
(uint64_t)partitions.front().get_partition()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Types::StringVec Topics;
|
||||
for(const auto &i:Notifiers_)
|
||||
Topics.push_back(i.first);
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace uCentral {
|
||||
int RegisterTopicWatcher(const std::string &Topic, Types::TopicNotifyFunction & F);
|
||||
void UnregisterTopicWatcher(const std::string &Topic, int FunctionId);
|
||||
void WakeUp();
|
||||
void PartitionAssignment(const cppkafka::TopicPartitionList& partitions);
|
||||
void PartitionRevocation(const cppkafka::TopicPartitionList& partitions);
|
||||
|
||||
private:
|
||||
static KafkaManager *instance_;
|
||||
|
||||
123
src/RESTAPI_avatarHandler.cpp
Normal file
123
src/RESTAPI_avatarHandler.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-07-15.
|
||||
//
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "RESTAPI_avatarHandler.h"
|
||||
#include "StorageService.h"
|
||||
#include "Daemon.h"
|
||||
#include "Poco/Net/HTMLForm.h"
|
||||
#include "Utils.h"
|
||||
|
||||
namespace uCentral {
|
||||
|
||||
void AvatarPartHandler::handlePart(const Poco::Net::MessageHeader &Header, std::istream &Stream) {
|
||||
FileType_ = Header.get("Content-Type", "(unspecified)");
|
||||
if (Header.has("Content-Disposition")) {
|
||||
std::string Disposition;
|
||||
Poco::Net::NameValueCollection Parameters;
|
||||
Poco::Net::MessageHeader::splitParameters(Header["Content-Disposition"], Disposition, Parameters);
|
||||
Name_ = Parameters.get("name", "(unnamed)");
|
||||
}
|
||||
Poco::CountingInputStream InputStream(Stream);
|
||||
std::ofstream OutputStream(TempFile_.path(), std::ofstream::out);
|
||||
Poco::StreamCopier::copyStream(InputStream, OutputStream);
|
||||
Length_ = InputStream.chars();
|
||||
};
|
||||
|
||||
void RESTAPI_avatarHandler::handleRequest(Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response) {
|
||||
DBGLINE
|
||||
if (!ContinueProcessing(Request, Response))
|
||||
return;
|
||||
DBGLINE
|
||||
|
||||
if (!IsAuthorized(Request, Response))
|
||||
return;
|
||||
DBGLINE
|
||||
|
||||
ParseParameters(Request);
|
||||
DBGLINE
|
||||
if (Request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET)
|
||||
DoGet(Request, Response);
|
||||
else if (Request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST)
|
||||
DoPost(Request, Response);
|
||||
else if (Request.getMethod() == Poco::Net::HTTPRequest::HTTP_DELETE)
|
||||
DoDelete(Request, Response);
|
||||
else
|
||||
BadRequest(Request, Response);
|
||||
}
|
||||
|
||||
void RESTAPI_avatarHandler::DoPost(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
|
||||
try {
|
||||
std::string Id = GetBinding("id", "");
|
||||
SecurityObjects::UserInfo UInfo;
|
||||
if (Id.empty() || !Storage()->GetUserById(Id, UInfo)) {
|
||||
NotFound(Request, Response);
|
||||
return;
|
||||
}
|
||||
Poco::TemporaryFile TmpFile;
|
||||
AvatarPartHandler partHandler(Id, Logger_, TmpFile);
|
||||
|
||||
Poco::Net::HTMLForm form(Request, Request.stream(), partHandler);
|
||||
Poco::JSON::Object Answer;
|
||||
if (!partHandler.Name().empty()) {
|
||||
Answer.set("avatarId", Id);
|
||||
Answer.set("errorCode", 0);
|
||||
Logger_.information(Poco::format("Uploaded avatar: %s Type: %s", partHandler.Name(), partHandler.ContentType()));
|
||||
Storage()->SetAvatar(UserInfo_.userinfo.email,
|
||||
Id, TmpFile, partHandler.ContentType(), partHandler.Name());
|
||||
} else {
|
||||
Answer.set("avatarId", Id);
|
||||
Answer.set("errorCode", 13);
|
||||
Answer.set("ErrorText", "Avatar upload could not complete.");
|
||||
}
|
||||
ReturnObject(Request, Answer, Response);
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
BadRequest(Request, Response);
|
||||
}
|
||||
|
||||
void RESTAPI_avatarHandler::DoGet(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
|
||||
try {
|
||||
std::string Id = GetBinding("id", "");
|
||||
if (Id.empty()) {
|
||||
NotFound(Request, Response);
|
||||
return;
|
||||
}
|
||||
Poco::TemporaryFile TempAvatar;
|
||||
std::string Type, Name;
|
||||
if (!Storage()->GetAvatar(UserInfo_.userinfo.email, Id, TempAvatar, Type, Name)) {
|
||||
NotFound(Request, Response);
|
||||
return;
|
||||
}
|
||||
SendFile(TempAvatar, Type, Name, Request, Response);
|
||||
return;
|
||||
} catch (const Poco::Exception&E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
BadRequest(Request, Response);
|
||||
}
|
||||
|
||||
void RESTAPI_avatarHandler::DoDelete(Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
|
||||
try {
|
||||
std::string Id = GetBinding("id", "");
|
||||
if (Id.empty()) {
|
||||
NotFound(Request, Response);
|
||||
return;
|
||||
}
|
||||
if (!Storage()->DeleteAvatar(UserInfo_.userinfo.email, Id)) {
|
||||
NotFound(Request, Response);
|
||||
return;
|
||||
}
|
||||
OK(Request, Response);
|
||||
return;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
BadRequest(Request, Response);
|
||||
}
|
||||
}
|
||||
57
src/RESTAPI_avatarHandler.h
Normal file
57
src/RESTAPI_avatarHandler.h
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-07-15.
|
||||
//
|
||||
|
||||
#ifndef UCENTRALSEC_RESTAPI_AVATARHANDLER_H
|
||||
#define UCENTRALSEC_RESTAPI_AVATARHANDLER_H
|
||||
|
||||
|
||||
#include "RESTAPI_handler.h"
|
||||
|
||||
namespace uCentral {
|
||||
|
||||
class AvatarPartHandler : public Poco::Net::PartHandler {
|
||||
public:
|
||||
AvatarPartHandler(std::string Id, Poco::Logger &Logger, Poco::TemporaryFile &TmpFile) :
|
||||
Id_(std::move(Id)),
|
||||
Logger_(Logger),
|
||||
TempFile_(TmpFile){
|
||||
}
|
||||
void handlePart(const Poco::Net::MessageHeader &Header, std::istream &Stream);
|
||||
[[nodiscard]] uint64_t Length() const { return Length_; }
|
||||
[[nodiscard]] std::string &Name() { return Name_; }
|
||||
[[nodiscard]] std::string &ContentType() { return FileType_; }
|
||||
[[nodiscard]] std::string FileName() const { return TempFile_.path(); }
|
||||
private:
|
||||
uint64_t Length_ = 0;
|
||||
std::string FileType_;
|
||||
std::string Name_;
|
||||
std::string Id_;
|
||||
Poco::Logger &Logger_;
|
||||
Poco::TemporaryFile &TempFile_;
|
||||
};
|
||||
|
||||
class RESTAPI_avatarHandler : public RESTAPIHandler {
|
||||
public:
|
||||
RESTAPI_avatarHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L)
|
||||
: RESTAPIHandler(bindings, L,
|
||||
std::vector<std::string>{
|
||||
Poco::Net::HTTPRequest::HTTP_GET,
|
||||
Poco::Net::HTTPRequest::HTTP_POST,
|
||||
Poco::Net::HTTPRequest::HTTP_DELETE,
|
||||
Poco::Net::HTTPRequest::HTTP_OPTIONS}) {}
|
||||
|
||||
void handleRequest(Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response) override;
|
||||
|
||||
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/avatar/{id}"}; };
|
||||
|
||||
void DoGet( Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response);
|
||||
void DoPost( Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response);
|
||||
void DoDelete( Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response);
|
||||
};
|
||||
}
|
||||
#endif //UCENTRALSEC_RESTAPI_AVATARHANDLER_H
|
||||
@@ -257,12 +257,23 @@ namespace uCentral {
|
||||
Response.set("Expires", "Mon, 26 Jul 2027 05:00:00 GMT");
|
||||
AddCORS(Request, Response);
|
||||
Response.sendFile(File.path(),MT.ContentType);
|
||||
/* for(auto const &i:Response) {
|
||||
std::cout << "Name: " << i.first << " Value: " << i.second << std::endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void RESTAPIHandler::SendFile(Poco::TemporaryFile &TempAvatar, const std::string &Type, const std::string & Name, Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response) {
|
||||
auto MT = Utils::FindMediaType(Name);
|
||||
if(MT.Encoding==Utils::BINARY) {
|
||||
Response.set("Content-Transfer-Encoding","binary");
|
||||
Response.set("Accept-Ranges", "bytes");
|
||||
}
|
||||
Response.set("Content-Disposition", "attachment; filename=" + Name );
|
||||
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");
|
||||
AddCORS(Request, Response);
|
||||
Response.sendFile(TempAvatar.path(),MT.ContentType);
|
||||
}
|
||||
|
||||
void RESTAPIHandler::SendHTMLFileBack(Poco::File & File,
|
||||
Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response ,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/TemporaryFile.h"
|
||||
#include "Poco/JSON/Object.h"
|
||||
#include "Poco/CountingStream.h"
|
||||
#include "Poco/NullStream.h"
|
||||
@@ -136,6 +137,7 @@ namespace uCentral {
|
||||
Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response ,
|
||||
const Types::StringPairVec & FormVars);
|
||||
void SendFile(Poco::TemporaryFile &TempAvatar, const std::string &Type, const std::string & Name, Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response);
|
||||
|
||||
void SendFile(Poco::File & File, Poco::Net::HTTPServerRequest &Request, Poco::Net::HTTPServerResponse &Response);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "RESTAPI_action_links.h"
|
||||
#include "RESTAPI_systemEndpoints_handler.h"
|
||||
#include "RESTAPI_AssetServer.h"
|
||||
#include "RESTAPI_avatarHandler.h"
|
||||
|
||||
#include "Daemon.h"
|
||||
#include "Utils.h"
|
||||
@@ -70,7 +71,8 @@ namespace uCentral {
|
||||
RESTAPI_system_command,
|
||||
RESTAPI_AssetServer,
|
||||
RESTAPI_systemEndpoints_handler,
|
||||
RESTAPI_action_links
|
||||
RESTAPI_action_links,
|
||||
RESTAPI_avatarHandler
|
||||
>(Path,Bindings,Logger_);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,6 @@ namespace uCentral {
|
||||
Setup_PostgreSQL();
|
||||
} else if (DBType == "mysql") {
|
||||
Setup_MySQL();
|
||||
} else if (DBType == "odbc") {
|
||||
Setup_ODBC();
|
||||
}
|
||||
|
||||
Create_Tables();
|
||||
|
||||
@@ -12,11 +12,12 @@
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/SessionPool.h"
|
||||
#include "Poco/Data/SQLite/Connector.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/TemporaryFile.h"
|
||||
|
||||
#ifndef SMALL_BUILD
|
||||
#include "Poco/Data/PostgreSQL/Connector.h"
|
||||
#include "Poco/Data/MySQL/Connector.h"
|
||||
#include "Poco/Data/ODBC/Connector.h"
|
||||
#endif
|
||||
|
||||
#include "AuthService.h"
|
||||
@@ -25,116 +26,6 @@
|
||||
|
||||
namespace uCentral {
|
||||
|
||||
static const std::string AllUsersFieldsForCreation{
|
||||
"Id varchar(36),"
|
||||
"name varchar,"
|
||||
"description varchar,"
|
||||
"avatar varchar,"
|
||||
"email varchar,"
|
||||
"validated int,"
|
||||
"validationEmail varchar,"
|
||||
"validationDate bigint,"
|
||||
"creationDate bigint,"
|
||||
"validationURI varchar,"
|
||||
"changePassword int,"
|
||||
"lastLogin bigint,"
|
||||
"currentLoginURI varchar,"
|
||||
"lastPasswordChange bigint,"
|
||||
"lastEmailCheck bigint,"
|
||||
"waitingForEmailCheck int,"
|
||||
"locale varchar,"
|
||||
"notes text,"
|
||||
"location varchar,"
|
||||
"owner varchar,"
|
||||
"suspended int,"
|
||||
"blackListed int,"
|
||||
"userRole varchar,"
|
||||
"userTypeProprietaryInfo text,"
|
||||
"securityPolicy text,"
|
||||
"securityPolicyChange bigint,"
|
||||
"currentPassword varchar,"
|
||||
"lastPasswords varchar,"
|
||||
"oauthType varchar,"
|
||||
"oauthUserInfo text"};
|
||||
|
||||
static const std::string AllUsersFieldsForSelect{
|
||||
"Id,"
|
||||
"name,"
|
||||
"description,"
|
||||
"avatar,"
|
||||
"email,"
|
||||
"validated,"
|
||||
"validationEmail,"
|
||||
"validationDate,"
|
||||
"creationDate,"
|
||||
"validationURI,"
|
||||
"changePassword,"
|
||||
"lastLogin,"
|
||||
"currentLoginURI,"
|
||||
"lastPasswordChange,"
|
||||
"lastEmailCheck,"
|
||||
"waitingForEmailCheck,"
|
||||
"locale,"
|
||||
"notes,"
|
||||
"location,"
|
||||
"owner,"
|
||||
"suspended,"
|
||||
"blackListed,"
|
||||
"userRole,"
|
||||
"userTypeProprietaryInfo,"
|
||||
"securityPolicy,"
|
||||
"securityPolicyChange,"
|
||||
"currentPassword,"
|
||||
"lastPasswords,"
|
||||
"oauthType,"
|
||||
"oauthUserInfo"};
|
||||
|
||||
static const std::string AllUsersFieldsForUpdate{
|
||||
" Id=?, "
|
||||
"name=?, "
|
||||
"description=?, "
|
||||
"avatar=?, "
|
||||
"email=?, "
|
||||
"validated=?, "
|
||||
"validationEmail=?, "
|
||||
"validationDate=?, "
|
||||
"creationDate=?, "
|
||||
"validationURI=?, "
|
||||
"changePassword=?, "
|
||||
"lastLogin=?, "
|
||||
"currentLoginURI=?, "
|
||||
"lastPasswordChange=?, "
|
||||
"lastEmailCheck=?, "
|
||||
"waitingForEmailCheck=?, "
|
||||
"locale=?, "
|
||||
"notes=?, "
|
||||
"location=?, "
|
||||
"owner=?, "
|
||||
"suspended=?, "
|
||||
"blackListed=?, "
|
||||
"userRole=?, "
|
||||
"userTypeProprietaryInfo=?, "
|
||||
"securityPolicy=?, "
|
||||
"securityPolicyChange=?, "
|
||||
"currentPassword=?, "
|
||||
"lastPasswords=?, "
|
||||
"oauthType=?, "
|
||||
"oauthUserInfo=? "};
|
||||
|
||||
static const std::string AllActionLinksFieldsForCreation {
|
||||
"Id varchar(36),"
|
||||
"Action varchar,"
|
||||
"UserId varchar,"
|
||||
"template varchar,"
|
||||
"locale varchar,"
|
||||
"message text,"
|
||||
"sent bigint,"
|
||||
"created bigint,"
|
||||
"expires bigint,"
|
||||
"completed bigint,"
|
||||
"canceled bigint"
|
||||
};
|
||||
|
||||
static const std::string AllActionLinksFieldsForSelect {
|
||||
"Id, "
|
||||
"Action,"
|
||||
@@ -163,7 +54,6 @@ namespace uCentral {
|
||||
"canceled=?"
|
||||
};
|
||||
|
||||
|
||||
static const std::string AllEmailTemplatesFieldsForCreation {
|
||||
|
||||
};
|
||||
@@ -186,8 +76,7 @@ namespace uCentral {
|
||||
enum StorageType {
|
||||
sqlite,
|
||||
pgsql,
|
||||
mysql,
|
||||
odbc
|
||||
mysql
|
||||
};
|
||||
|
||||
enum AUTH_ERROR {
|
||||
@@ -261,6 +150,10 @@ namespace uCentral {
|
||||
bool GetUsers( uint64_t Offset, uint64_t Limit, SecurityObjects::UserInfoVec & Users);
|
||||
bool SetLastLogin(USER_ID_TYPE & Id);
|
||||
|
||||
bool SetAvatar(const std::string & Admin, std::string &Id, Poco::TemporaryFile &FileName, std::string &Type, std::string & Name);
|
||||
bool GetAvatar(const std::string & Admin, std::string &Id, Poco::TemporaryFile &FileName, std::string &Type, std::string & Name);
|
||||
bool DeleteAvatar(const std::string & Admin, std::string &Id);
|
||||
|
||||
/*
|
||||
* All ActionLinks functions
|
||||
*/
|
||||
@@ -278,12 +171,11 @@ namespace uCentral {
|
||||
#ifndef SMALL_BUILD
|
||||
std::unique_ptr<Poco::Data::PostgreSQL::Connector> PostgresConn_= nullptr;
|
||||
std::unique_ptr<Poco::Data::MySQL::Connector> MySQLConn_= nullptr;
|
||||
std::unique_ptr<Poco::Data::ODBC::Connector> ODBCConn_= nullptr;
|
||||
#endif
|
||||
|
||||
int Create_Tables();
|
||||
int Create_UserTable();
|
||||
int Create_APIKeyTable();
|
||||
int Create_AvatarTable();
|
||||
|
||||
int Setup_SQLite();
|
||||
[[nodiscard]] std::string ConvertParams(const std::string &S) const;
|
||||
@@ -291,7 +183,6 @@ namespace uCentral {
|
||||
#ifndef SMALL_BUILD
|
||||
int Setup_MySQL();
|
||||
int Setup_PostgreSQL();
|
||||
int Setup_ODBC();
|
||||
#endif
|
||||
Storage() noexcept;
|
||||
};
|
||||
|
||||
99
src/storage_avatar.cpp
Normal file
99
src/storage_avatar.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-07-15.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "storage_avatar.h"
|
||||
#include "StorageService.h"
|
||||
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Data/LOBStream.h"
|
||||
#include "Daemon.h"
|
||||
|
||||
namespace uCentral {
|
||||
|
||||
/*
|
||||
"Id VARCHAR(36) PRIMARY KEY, "
|
||||
"Type VARCHAR, "
|
||||
"Created BIGINT, "
|
||||
"Name VARCHAR, "
|
||||
"Avatar BLOB"
|
||||
*/
|
||||
|
||||
bool Storage::SetAvatar(const std::string & Admin, std::string &Id, Poco::TemporaryFile &FileName, std::string &Type, std::string & Name) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Insert(Sess);
|
||||
|
||||
Poco::Data::LOB<char> L;
|
||||
Poco::Data::LOBOutputStream OL(L);
|
||||
|
||||
std::ifstream f(FileName.path(), std::ios::binary);
|
||||
Poco::StreamCopier::copyStream(f, OL);
|
||||
|
||||
uint64_t Now = std::time(nullptr);
|
||||
|
||||
std::string St2{
|
||||
"INSERT INTO Avatars (Id,Type,Created,Name,Avatar) VALUES(?,?,?,?,?)"};
|
||||
|
||||
Insert << ConvertParams(St2),
|
||||
Poco::Data::Keywords::use(Id),
|
||||
Poco::Data::Keywords::use(Type),
|
||||
Poco::Data::Keywords::use(Now),
|
||||
Poco::Data::Keywords::use(Name),
|
||||
Poco::Data::Keywords::use(L);
|
||||
Insert.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Storage::GetAvatar(const std::string & Admin, std::string &Id, Poco::TemporaryFile &FileName, std::string & Type, std::string & Name) {
|
||||
try {
|
||||
Poco::Data::LOB<char> L;
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
std::string St2{"SELECT Avatar, Type, Name FROM Avatars WHERE Id=?"};
|
||||
|
||||
Poco::Data::Statement Select2(Sess);
|
||||
Select2 << ConvertParams(St2),
|
||||
Poco::Data::Keywords::into(L),
|
||||
Poco::Data::Keywords::into(Type),
|
||||
Poco::Data::Keywords::into(Name),
|
||||
Poco::Data::Keywords::use(Id);
|
||||
Select2.execute();
|
||||
|
||||
Poco::Data::LOBInputStream IL(L);
|
||||
std::ofstream f(FileName.path(), std::ios::binary);
|
||||
Poco::StreamCopier::copyStream(IL, f);
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Storage::DeleteAvatar(const std::string & Admin, std::string &Id) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Delete(Sess);
|
||||
|
||||
std::string St1{"delete from avatars where id=?"};
|
||||
|
||||
Delete << ConvertParams(St1),
|
||||
Poco::Data::Keywords::use(Id);
|
||||
Delete.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
15
src/storage_avatar.h
Normal file
15
src/storage_avatar.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-07-15.
|
||||
//
|
||||
|
||||
#ifndef WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H
|
||||
#define WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H
|
||||
|
||||
namespace uCentral {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif //WLAN_CLOUD_UCENTRALSEC_STORAGE_AVATAR_H
|
||||
@@ -1,47 +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 uCentral {
|
||||
|
||||
#ifdef SMALL_BUILD
|
||||
int Service::Setup_ODBC() { uCentral::instance()->exit(Poco::Util::Application::EXIT_CONFIG);}
|
||||
#else
|
||||
int Storage::Setup_ODBC() {
|
||||
|
||||
dbType_ = odbc ;
|
||||
|
||||
Logger_.notice("ODBC 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;
|
||||
|
||||
ODBCConn_ = std::make_unique<Poco::Data::ODBC::Connector>();
|
||||
ODBCConn_->registerConnector();
|
||||
Pool_ = std::make_unique<Poco::Data::SessionPool>(ODBCConn_->name(), ConnectionStr, 4, NumSessions, IdleTime);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -4,11 +4,14 @@
|
||||
|
||||
#include "StorageService.h"
|
||||
#include "Utils.h"
|
||||
#include "storage_users.h"
|
||||
#include "storage_avatar.h"
|
||||
|
||||
namespace uCentral {
|
||||
|
||||
int Storage::Create_Tables() {
|
||||
Create_UserTable();
|
||||
Create_AvatarTable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,8 +40,39 @@ namespace uCentral {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Storage::Create_APIKeyTable() {
|
||||
int Storage::Create_AvatarTable() {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
|
||||
return 0;
|
||||
}
|
||||
if(dbType_==sqlite) {
|
||||
Sess << "CREATE TABLE IF NOT EXISTS Avatars ("
|
||||
"Id VARCHAR(36) PRIMARY KEY, "
|
||||
"Type VARCHAR, "
|
||||
"Created BIGINT, "
|
||||
"Name VARCHAR, "
|
||||
"Avatar BLOB"
|
||||
") ", Poco::Data::Keywords::now;
|
||||
} else if(dbType_==mysql) {
|
||||
Sess << "CREATE TABLE IF NOT EXISTS Avatars ("
|
||||
"Id VARCHAR(36) PRIMARY KEY, "
|
||||
"Type VARCHAR, "
|
||||
"Created BIGINT, "
|
||||
"Name VARCHAR, "
|
||||
"Avatar LONGBLOB"
|
||||
") ", Poco::Data::Keywords::now;
|
||||
} else if(dbType_==pgsql) {
|
||||
Sess << "CREATE TABLE IF NOT EXISTS Avatars ("
|
||||
"Id VARCHAR(36) PRIMARY KEY, "
|
||||
"Type VARCHAR, "
|
||||
"Created BIGINT, "
|
||||
"Name VARCHAR, "
|
||||
"Avatar BYTEA"
|
||||
") ", Poco::Data::Keywords::now;
|
||||
}
|
||||
return 0;
|
||||
} catch(const Poco::Exception &E) {
|
||||
Logger_.log(E);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,43 +7,10 @@
|
||||
#include "Daemon.h"
|
||||
|
||||
#include "Poco/Tuple.h"
|
||||
#include "storage_users.h"
|
||||
|
||||
namespace uCentral {
|
||||
|
||||
typedef Poco::Tuple<
|
||||
std::string, // Id = 0;
|
||||
std::string, // name;
|
||||
std::string, // description;
|
||||
std::string, // avatar;
|
||||
std::string, // email;
|
||||
uint64_t, // bool validated = false;
|
||||
std::string, // validationEmail;
|
||||
uint64_t, // validationDate = 0;
|
||||
uint64_t, // creationDate = 0;
|
||||
std::string, // validationURI;
|
||||
uint64_t, // bool changePassword = true;
|
||||
uint64_t, // lastLogin = 0;
|
||||
std::string, // currentLoginURI;
|
||||
uint64_t, // lastPasswordChange = 0;
|
||||
uint64_t, // lastEmailCheck = 0;
|
||||
uint64_t , // bool waitingForEmailCheck = false;
|
||||
std::string, // locale;
|
||||
std::string, // notes;
|
||||
std::string, // location;
|
||||
std::string, // owner;
|
||||
uint64_t, // bool suspended = false;
|
||||
uint64_t, // bool blackListed = false;
|
||||
std::string, // userRole;
|
||||
std::string, // userTypeProprietaryInfo;
|
||||
std::string, // securityPolicy;
|
||||
uint64_t , // securityPolicyChange;
|
||||
std::string, // currentPassword;
|
||||
std::string, // lastPasswords;
|
||||
std::string, // oauthType;
|
||||
std::string // oauthUserInfo;
|
||||
> UserInfoRecord;
|
||||
typedef std::vector<UserInfoRecord> UserInfoRecordList;
|
||||
|
||||
bool Convert(const UserInfoRecord &T, SecurityObjects::UserInfo &U) {
|
||||
U.Id = T.get<0>();
|
||||
U.name = T.get<1>();
|
||||
|
||||
154
src/storage_users.h
Normal file
154
src/storage_users.h
Normal file
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-07-15.
|
||||
//
|
||||
|
||||
#ifndef UCENTRALSEC_STORAGE_USERS_H
|
||||
#define UCENTRALSEC_STORAGE_USERS_H
|
||||
|
||||
namespace uCentral {
|
||||
static const std::string AllUsersFieldsForCreation{
|
||||
"Id varchar(36),"
|
||||
"name varchar,"
|
||||
"description varchar,"
|
||||
"avatar varchar,"
|
||||
"email varchar,"
|
||||
"validated int,"
|
||||
"validationEmail varchar,"
|
||||
"validationDate bigint,"
|
||||
"creationDate bigint,"
|
||||
"validationURI varchar,"
|
||||
"changePassword int,"
|
||||
"lastLogin bigint,"
|
||||
"currentLoginURI varchar,"
|
||||
"lastPasswordChange bigint,"
|
||||
"lastEmailCheck bigint,"
|
||||
"waitingForEmailCheck int,"
|
||||
"locale varchar,"
|
||||
"notes text,"
|
||||
"location varchar,"
|
||||
"owner varchar,"
|
||||
"suspended int,"
|
||||
"blackListed int,"
|
||||
"userRole varchar,"
|
||||
"userTypeProprietaryInfo text,"
|
||||
"securityPolicy text,"
|
||||
"securityPolicyChange bigint,"
|
||||
"currentPassword varchar,"
|
||||
"lastPasswords varchar,"
|
||||
"oauthType varchar,"
|
||||
"oauthUserInfo text"};
|
||||
|
||||
static const std::string AllUsersFieldsForSelect{
|
||||
"Id,"
|
||||
"name,"
|
||||
"description,"
|
||||
"avatar,"
|
||||
"email,"
|
||||
"validated,"
|
||||
"validationEmail,"
|
||||
"validationDate,"
|
||||
"creationDate,"
|
||||
"validationURI,"
|
||||
"changePassword,"
|
||||
"lastLogin,"
|
||||
"currentLoginURI,"
|
||||
"lastPasswordChange,"
|
||||
"lastEmailCheck,"
|
||||
"waitingForEmailCheck,"
|
||||
"locale,"
|
||||
"notes,"
|
||||
"location,"
|
||||
"owner,"
|
||||
"suspended,"
|
||||
"blackListed,"
|
||||
"userRole,"
|
||||
"userTypeProprietaryInfo,"
|
||||
"securityPolicy,"
|
||||
"securityPolicyChange,"
|
||||
"currentPassword,"
|
||||
"lastPasswords,"
|
||||
"oauthType,"
|
||||
"oauthUserInfo"};
|
||||
|
||||
static const std::string AllUsersFieldsForUpdate{
|
||||
" Id=?, "
|
||||
"name=?, "
|
||||
"description=?, "
|
||||
"avatar=?, "
|
||||
"email=?, "
|
||||
"validated=?, "
|
||||
"validationEmail=?, "
|
||||
"validationDate=?, "
|
||||
"creationDate=?, "
|
||||
"validationURI=?, "
|
||||
"changePassword=?, "
|
||||
"lastLogin=?, "
|
||||
"currentLoginURI=?, "
|
||||
"lastPasswordChange=?, "
|
||||
"lastEmailCheck=?, "
|
||||
"waitingForEmailCheck=?, "
|
||||
"locale=?, "
|
||||
"notes=?, "
|
||||
"location=?, "
|
||||
"owner=?, "
|
||||
"suspended=?, "
|
||||
"blackListed=?, "
|
||||
"userRole=?, "
|
||||
"userTypeProprietaryInfo=?, "
|
||||
"securityPolicy=?, "
|
||||
"securityPolicyChange=?, "
|
||||
"currentPassword=?, "
|
||||
"lastPasswords=?, "
|
||||
"oauthType=?, "
|
||||
"oauthUserInfo=? "};
|
||||
|
||||
static const std::string AllActionLinksFieldsForCreation{
|
||||
"Id varchar(36),"
|
||||
"Action varchar,"
|
||||
"UserId varchar,"
|
||||
"template varchar,"
|
||||
"locale varchar,"
|
||||
"message text,"
|
||||
"sent bigint,"
|
||||
"created bigint,"
|
||||
"expires bigint,"
|
||||
"completed bigint,"
|
||||
"canceled bigint"
|
||||
};
|
||||
|
||||
typedef Poco::Tuple <
|
||||
std::string, // Id = 0;
|
||||
std::string, // name;
|
||||
std::string, // description;
|
||||
std::string, // avatar;
|
||||
std::string, // email;
|
||||
uint64_t, // bool validated = false;
|
||||
std::string, // validationEmail;
|
||||
uint64_t, // validationDate = 0;
|
||||
uint64_t, // creationDate = 0;
|
||||
std::string, // validationURI;
|
||||
uint64_t, // bool changePassword = true;
|
||||
uint64_t, // lastLogin = 0;
|
||||
std::string, // currentLoginURI;
|
||||
uint64_t, // lastPasswordChange = 0;
|
||||
uint64_t, // lastEmailCheck = 0;
|
||||
uint64_t, // bool waitingForEmailCheck = false;
|
||||
std::string, // locale;
|
||||
std::string, // notes;
|
||||
std::string, // location;
|
||||
std::string, // owner;
|
||||
uint64_t, // bool suspended = false;
|
||||
uint64_t, // bool blackListed = false;
|
||||
std::string, // userRole;
|
||||
std::string, // userTypeProprietaryInfo;
|
||||
std::string, // securityPolicy;
|
||||
uint64_t, // securityPolicyChange;
|
||||
std::string, // currentPassword;
|
||||
std::string, // lastPasswords;
|
||||
std::string, // oauthType;
|
||||
std::string // oauthUserInfo;
|
||||
> UserInfoRecord;
|
||||
typedef std::vector <UserInfoRecord> UserInfoRecordList;
|
||||
}
|
||||
|
||||
#endif //UCENTRALSEC_STORAGE_USERS_H
|
||||
@@ -208,6 +208,26 @@ policies() {
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
setavatar() {
|
||||
curl ${FLAGS} -F 'data=@open-wifi.svg' "https://${UCENTRALSEC}/api/v1/avatar/$1" \
|
||||
-H "Authorization: Bearer ${token}" > ${result_file};
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
getavatar() {
|
||||
curl ${FLAGS} -X GET "https://${UCENTRALSEC}/api/v1/avatar/$1" \
|
||||
-H "accept: application/octet-stream" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-o "user.svg"
|
||||
}
|
||||
|
||||
deleteavatar() {
|
||||
curl ${FLAGS} -X DELETE "https://${UCENTRALSEC}/api/v1/avatar/$1" \
|
||||
-H "Authorization: Bearer ${token}" \
|
||||
-H "Content-Type: application/json" > ${result_file}
|
||||
jq < ${result_file}
|
||||
}
|
||||
|
||||
help() {
|
||||
echo
|
||||
echo "listendpoints Get all the system endpoints."
|
||||
@@ -226,7 +246,11 @@ case "$1" in
|
||||
"emailtest") emailtest "$2";;
|
||||
"getlogo") getlogo ;;
|
||||
"policies") policies ;;
|
||||
"setavatar") login; setavatar "$2"; logout;;
|
||||
"getavatar") login; getavatar "$2"; logout;;
|
||||
"deleteavatar") login; deleteavatar "$2"; logout;;
|
||||
"help") login; help ; logout ;;
|
||||
|
||||
*) help ;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user