diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b82cec..8851871 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,10 @@ add_executable( owsec src/RESTAPI_avatarHandler.cpp src/RESTAPI_avatarHandler.h src/storage_avatar.cpp src/storage_avatar.h src/storage_users.h src/OpenWifiTypes.h src/RESTAPI_email_handler.cpp src/RESTAPI_email_handler.h - src/storage_tokens.cpp) + src/storage_tokens.cpp + src/RESTAPI_GenericServer.h src/RESTAPI_GenericServer.cpp + src/RESTAPI_errors.h + ) if(NOT SMALL_BUILD) target_link_libraries(owsec PUBLIC diff --git a/build b/build index 19c7bdb..25bf17f 100644 --- a/build +++ b/build @@ -1 +1 @@ -16 \ No newline at end of file +18 \ No newline at end of file diff --git a/src/RESTAPI_AssetServer.h b/src/RESTAPI_AssetServer.h index b0c7c5f..45b1782 100644 --- a/src/RESTAPI_AssetServer.h +++ b/src/RESTAPI_AssetServer.h @@ -10,7 +10,7 @@ namespace OpenWifi { class RESTAPI_AssetServer : public RESTAPIHandler { public: - RESTAPI_AssetServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_AssetServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector {Poco::Net::HTTPRequest::HTTP_POST, @@ -18,6 +18,7 @@ namespace OpenWifi { Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {} static const std::list PathName() { return std::list{"/wwwassets/{id}" , "/favicon.ico"}; }; diff --git a/src/RESTAPI_GenericServer.cpp b/src/RESTAPI_GenericServer.cpp new file mode 100644 index 0000000..6dc9356 --- /dev/null +++ b/src/RESTAPI_GenericServer.cpp @@ -0,0 +1,5 @@ +// +// Created by stephane bourque on 2021-09-15. +// + +#include "RESTAPI_GenericServer.h" diff --git a/src/RESTAPI_GenericServer.h b/src/RESTAPI_GenericServer.h new file mode 100644 index 0000000..a97d0e1 --- /dev/null +++ b/src/RESTAPI_GenericServer.h @@ -0,0 +1,78 @@ +// +// Created by stephane bourque on 2021-09-15. +// + +#ifndef OWPROV_RESTAPI_GENERICSERVER_H +#define OWPROV_RESTAPI_GENERICSERVER_H + +#include +#include + +#include "Daemon.h" +#include "Poco/StringTokenizer.h" +#include "Poco/Net/HTTPRequest.h" + +namespace OpenWifi { + + class RESTAPI_GenericServer { + public: + + enum { + LOG_GET=0, + LOG_DELETE, + LOG_PUT, + LOG_POST + }; + + void inline SetFlags(bool External, const std::string &Methods) { + Poco::StringTokenizer Tokens(Methods,","); + auto Offset = (External ? 0 : 4); + for(const auto &i:Tokens) { + if(Poco::icompare(i,Poco::Net::HTTPRequest::HTTP_DELETE)==0) + LogFlags_[Offset+LOG_DELETE]=true; + else if(Poco::icompare(i,Poco::Net::HTTPRequest::HTTP_PUT)==0) + LogFlags_[Offset+LOG_PUT]=true; + else if(Poco::icompare(i,Poco::Net::HTTPRequest::HTTP_POST)==0) + LogFlags_[Offset+LOG_POST]=true; + else if(Poco::icompare(i,Poco::Net::HTTPRequest::HTTP_GET)==0) + LogFlags_[Offset+LOG_GET]=true; + } + } + inline void InitLogging() { + std::string Public = Daemon()->ConfigGetString("apilogging.public.methods","PUT,POST,DELETE"); + SetFlags(true, Public); + std::string Private = Daemon()->ConfigGetString("apilogging.private.methods","PUT,POST,DELETE"); + SetFlags(false, Private); + + std::string PublicBadTokens = Daemon()->ConfigGetString("apilogging.public.badtokens.methods",""); + LogBadTokens_[0] = (Poco::icompare(PublicBadTokens,"true")==0); + std::string PrivateBadTokens = Daemon()->ConfigGetString("apilogging.private.badtokens.methods",""); + LogBadTokens_[1] = (Poco::icompare(PrivateBadTokens,"true")==0); + } + + [[nodiscard]] inline bool LogIt(const std::string &Method, bool External) const { + auto Offset = (External ? 0 : 4); + if(Method == Poco::Net::HTTPRequest::HTTP_GET) + return LogFlags_[Offset+LOG_GET]; + if(Method == Poco::Net::HTTPRequest::HTTP_POST) + return LogFlags_[Offset+LOG_POST]; + if(Method == Poco::Net::HTTPRequest::HTTP_PUT) + return LogFlags_[Offset+LOG_PUT]; + if(Method == Poco::Net::HTTPRequest::HTTP_DELETE) + return LogFlags_[Offset+LOG_DELETE]; + return false; + }; + + [[nodiscard]] inline bool LogBadTokens(bool External) const { + return LogBadTokens_[ (External ? 0 : 1) ]; + }; + + private: + std::array LogFlags_{false}; + std::array LogBadTokens_{false}; + }; + +} + + +#endif //OWPROV_RESTAPI_GENERICSERVER_H diff --git a/src/RESTAPI_InternalServer.cpp b/src/RESTAPI_InternalServer.cpp index 269d193..31ffee3 100644 --- a/src/RESTAPI_InternalServer.cpp +++ b/src/RESTAPI_InternalServer.cpp @@ -25,6 +25,7 @@ namespace OpenWifi { int RESTAPI_InternalServer::Start() { Logger_.information("Starting."); + Server_.InitLogging(); for(const auto & Svr: ConfigServersList_) { Logger_.information(Poco::format("Starting: %s:%s Keyfile:%s CertFile: %s", Svr.Address(), std::to_string(Svr.Port()), @@ -41,7 +42,7 @@ namespace OpenWifi { Params->setMaxQueued(200); Params->setKeepAlive(true); - auto NewServer = std::make_unique(new InternalRequestHandlerFactory, Pool_, Sock, Params); + auto NewServer = std::make_unique(new InternalRequestHandlerFactory(Server_), Pool_, Sock, Params); NewServer->start(); RESTServers_.push_back(std::move(NewServer)); } @@ -70,7 +71,7 @@ namespace OpenWifi { RESTAPI_system_command, RESTAPI_action_links, RESTAPI_validateToken_handler - >(Path,Bindings,Logger_); + >(Path,Bindings,Logger_, Server_); } } \ No newline at end of file diff --git a/src/RESTAPI_InternalServer.h b/src/RESTAPI_InternalServer.h index d01a810..9c256a5 100644 --- a/src/RESTAPI_InternalServer.h +++ b/src/RESTAPI_InternalServer.h @@ -11,6 +11,7 @@ #include "Poco/Net/HTTPRequestHandlerFactory.h" #include "Poco/Net/HTTPServerRequest.h" #include "Poco/Net/NetException.h" +#include "RESTAPI_GenericServer.h" namespace OpenWifi { @@ -31,19 +32,22 @@ namespace OpenWifi { private: static RESTAPI_InternalServer *instance_; std::vector> RESTServers_; - Poco::ThreadPool Pool_; + Poco::ThreadPool Pool_; + RESTAPI_GenericServer Server_; }; inline RESTAPI_InternalServer * RESTAPI_InternalServer() { return RESTAPI_InternalServer::instance(); }; class InternalRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { public: - InternalRequestHandlerFactory() : - Logger_(RESTAPI_InternalServer()->Logger()){} + explicit InternalRequestHandlerFactory(RESTAPI_GenericServer & Server) : + Logger_(RESTAPI_InternalServer()->Logger()), + Server_(Server){} Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &request) override; private: Poco::Logger & Logger_; + RESTAPI_GenericServer & Server_; }; diff --git a/src/RESTAPI_action_links.h b/src/RESTAPI_action_links.h index e456d23..1a71862 100644 --- a/src/RESTAPI_action_links.h +++ b/src/RESTAPI_action_links.h @@ -18,13 +18,14 @@ namespace OpenWifi { class RESTAPI_action_links : public RESTAPIHandler { public: - RESTAPI_action_links(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_action_links(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, - std::vector{ - Poco::Net::HTTPRequest::HTTP_GET, - Poco::Net::HTTPRequest::HTTP_POST, - Poco::Net::HTTPRequest::HTTP_OPTIONS}, - Internal) {} + std::vector{ + Poco::Net::HTTPRequest::HTTP_GET, + Poco::Net::HTTPRequest::HTTP_POST, + Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, + Internal) {} static const std::list PathName() { return std::list{"/api/v1/actionLink"}; }; void RequestResetPassword(std::string &Id); void CompleteResetPassword(std::string &Id); diff --git a/src/RESTAPI_avatarHandler.h b/src/RESTAPI_avatarHandler.h index cd06f89..8438714 100644 --- a/src/RESTAPI_avatarHandler.h +++ b/src/RESTAPI_avatarHandler.h @@ -33,13 +33,14 @@ namespace OpenWifi { class RESTAPI_avatarHandler : public RESTAPIHandler { public: - RESTAPI_avatarHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_avatarHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {} static const std::list PathName() { return std::list{"/api/v1/avatar/{id}"}; }; diff --git a/src/RESTAPI_email_handler.h b/src/RESTAPI_email_handler.h index ced91a9..a5264c8 100644 --- a/src/RESTAPI_email_handler.h +++ b/src/RESTAPI_email_handler.h @@ -11,10 +11,11 @@ namespace OpenWifi { class RESTAPI_email_handler : public RESTAPIHandler { public: - RESTAPI_email_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_email_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {} static const std::list PathName() { return std::list{"/api/v1/email"};} void DoGet() final {}; diff --git a/src/RESTAPI_errors.h b/src/RESTAPI_errors.h new file mode 100644 index 0000000..8fd131b --- /dev/null +++ b/src/RESTAPI_errors.h @@ -0,0 +1,42 @@ +// +// Created by stephane bourque on 2021-09-12. +// + +#ifndef OWPROV_RESTAPI_ERRORS_H +#define OWPROV_RESTAPI_ERRORS_H + +namespace OpenWifi::RESTAPI::Errors { + static const std::string MissingUUID{"Missing UUID."}; + static const std::string MissingSerialNumber{"Missing Serial Number."}; + static const std::string InternalError{"Internal error. Please try later."}; + static const std::string InvalidJSONDocument{"Invalid JSON document."}; + static const std::string UnsupportedHTTPMethod{"Unsupported HTTP Method"}; + static const std::string StillInUse{"Element still in use."}; + static const std::string CouldNotBeDeleted{"Element could not be deleted."}; + static const std::string NameMustBeSet{"The name property must be set."}; + static const std::string ConfigBlockInvalid{"Configuration block type invalid."}; + static const std::string UnknownId{"Unknown management policy."}; + static const std::string InvalidDeviceTypes{"Unknown or invalid device type(s)."}; + static const std::string RecordNotCreated{"Record could not be created."}; + static const std::string RecordNotUpdated{"Record could not be updated."}; + static const std::string UnknownManagementPolicyUUID{"Unknown management policy UUID."}; + static const std::string CannotDeleteRoot{"Root Entity cannot be removed, only modified."}; + static const std::string MustCreateRootFirst{"Root entity must be created first."}; + static const std::string ParentUUIDMustExist{"Parent UUID must exist."}; + static const std::string ConfigurationMustExist{"Configuration must exist."}; + static const std::string MissingOrInvalidParameters{"Invalid or missing parameters."}; + static const std::string UnknownSerialNumber{"Unknown Serial Number."}; + static const std::string InvalidSerialNumber{"Invalid Serial Number."}; + static const std::string SerialNumberExists{"Serial Number already exists."}; + static const std::string ValidNonRootUUID{"Must be a non-root, and valid UUID."}; + static const std::string VenueMustExist{"Venue does not exist."}; + static const std::string NotBoth{"You cannot specify both Entity and Venue"}; + static const std::string EntityMustExist{"Entity must exist."}; + static const std::string ParentOrEntityMustBeSet{"Parent or Entity must be set."}; + static const std::string ContactMustExist{"Contact must exist."}; + static const std::string LocationMustExist{"Location must exist."}; + static const std::string OnlyWSSupported{"This endpoint only supports WebSocket."}; + +} + +#endif //OWPROV_RESTAPI_ERRORS_H diff --git a/src/RESTAPI_handler.cpp b/src/RESTAPI_handler.cpp index 72818d3..c7f008e 100644 --- a/src/RESTAPI_handler.cpp +++ b/src/RESTAPI_handler.cpp @@ -17,6 +17,8 @@ #include "Poco/URI.h" #include "Poco/Net/OAuth20Credentials.h" +#include "RESTAPI_errors.h" + #ifdef TIP_SECURITY_SERVICE #include "AuthService.h" #else @@ -52,11 +54,11 @@ namespace OpenWifi { else if (Request->getMethod() == Poco::Net::HTTPRequest::HTTP_PUT) DoPut(); else - BadRequest("Unsupported HTTP Method"); + BadRequest(RESTAPI::Errors::UnsupportedHTTPMethod); return; } catch (const Poco::Exception &E) { Logger_.log(E); - BadRequest("Internal error."); + BadRequest(RESTAPI::Errors::InternalError); } } @@ -355,7 +357,22 @@ namespace OpenWifi { bool RESTAPIHandler::IsAuthorized() { if(Internal_) { - return Daemon()->IsValidAPIKEY(*Request); + auto Allowed = Daemon()->IsValidAPIKEY(*Request); + if(!Allowed) { + if(Server_.LogBadTokens(false)) { + Logger_.debug(Poco::format("I-REQ-DENIED(%s): Method='%s' Path='%s", + Utils::FormatIPv6(Request->clientAddress().toString()), + Request->getMethod(), Request->getURI())); + } + } else { + auto Id = Request->get("X-INTERNAL-NAME", "unknown"); + if(Server_.LogIt(Request->getMethod(),true)) { + Logger_.debug(Poco::format("I-REQ-ALLOWED(%s): User='%s' Method='%s' Path='%s", + Utils::FormatIPv6(Request->clientAddress().toString()), Id, + Request->getMethod(), Request->getURI())); + } + } + return Allowed; } else { if (SessionToken_.empty()) { try { @@ -372,8 +389,18 @@ namespace OpenWifi { #else if (AuthClient()->IsAuthorized(*Request, SessionToken_, UserInfo_)) { #endif + if(Server_.LogIt(Request->getMethod(),true)) { + Logger_.debug(Poco::format("X-REQ-ALLOWED(%s): User='%s' Method='%s' Path='%s", + Utils::FormatIPv6(Request->clientAddress().toString()), UserInfo_.userinfo.email, + Request->getMethod(), Request->getURI())); + } return true; } else { + if(Server_.LogBadTokens(true)) { + Logger_.debug(Poco::format("X-REQ-DENIED(%s): Method='%s' Path='%s", + Utils::FormatIPv6(Request->clientAddress().toString()), + Request->getMethod(), Request->getURI())); + } UnAuthorized(); } return false; diff --git a/src/RESTAPI_handler.h b/src/RESTAPI_handler.h index d348735..ed27282 100644 --- a/src/RESTAPI_handler.h +++ b/src/RESTAPI_handler.h @@ -26,6 +26,7 @@ #include "RESTAPI_SecurityObjects.h" #include "RESTAPI_utils.h" +#include "RESTAPI_GenericServer.h" namespace OpenWifi { @@ -92,8 +93,8 @@ namespace OpenWifi { typedef std::map BindingMap; - RESTAPIHandler(BindingMap map, Poco::Logger &l, std::vector Methods, bool Internal=false, bool AlwaysAuthorize=true) - : Bindings_(std::move(map)), Logger_(l), Methods_(std::move(Methods)), Internal_(Internal), AlwaysAuthorize_(AlwaysAuthorize) {} + RESTAPIHandler(BindingMap map, Poco::Logger &l, std::vector Methods, RESTAPI_GenericServer & Server, bool Internal=false, bool AlwaysAuthorize=true) + : Bindings_(std::move(map)), Logger_(l), Methods_(std::move(Methods)), Server_(Server), Internal_(Internal), AlwaysAuthorize_(AlwaysAuthorize) {} static bool ParseBindings(const std::string & Request, const std::list & EndPoints, BindingMap &Keys); void PrintBindings(); @@ -173,12 +174,13 @@ namespace OpenWifi { Poco::Net::HTTPServerResponse *Response= nullptr; bool AlwaysAuthorize_=true; Poco::JSON::Parser IncomingParser_; + RESTAPI_GenericServer & Server_; }; class RESTAPI_UnknownRequestHandler : public RESTAPIHandler { public: - RESTAPI_UnknownRequestHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L) - : RESTAPIHandler(bindings, L, std::vector{}) {} + RESTAPI_UnknownRequestHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server) + : RESTAPIHandler(bindings, L, std::vector{}, Server) {} inline void DoGet() override {}; inline void DoPost() override {}; inline void DoPut() override {}; @@ -197,30 +199,30 @@ namespace OpenWifi { } template - RESTAPIHandler * RESTAPI_Router(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger ) { + RESTAPIHandler * RESTAPI_Router(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server) { static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method."); if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) { - return new T(Bindings, Logger, false); + return new T(Bindings, Logger, Server, false); } if constexpr (sizeof...(Args) == 0) { - return new RESTAPI_UnknownRequestHandler(Bindings,Logger); + return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server); } else { - return RESTAPI_Router(RequestedPath, Bindings, Logger); + return RESTAPI_Router(RequestedPath, Bindings, Logger, Server); } } template - RESTAPIHandler * RESTAPI_Router_I(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger) { + RESTAPIHandler * RESTAPI_Router_I(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server) { static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method."); if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) { - return new T(Bindings, Logger, true); + return new T(Bindings, Logger, Server, true); } if constexpr (sizeof...(Args) == 0) { - return new RESTAPI_UnknownRequestHandler(Bindings,Logger); + return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server); } else { - return RESTAPI_Router_I(RequestedPath, Bindings, Logger); + return RESTAPI_Router_I(RequestedPath, Bindings, Logger, Server); } } diff --git a/src/RESTAPI_oauth2Handler.h b/src/RESTAPI_oauth2Handler.h index b4a3d49..192de34 100644 --- a/src/RESTAPI_oauth2Handler.h +++ b/src/RESTAPI_oauth2Handler.h @@ -14,12 +14,13 @@ namespace OpenWifi { class RESTAPI_oauth2Handler : public RESTAPIHandler { public: - RESTAPI_oauth2Handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_oauth2Handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal, false) {} static const std::list PathName() { return std::list{"/api/v1/oauth2/{token}","/api/v1/oauth2"}; }; void DoGet() final; diff --git a/src/RESTAPI_server.cpp b/src/RESTAPI_server.cpp index 2f7dd79..7f4764d 100644 --- a/src/RESTAPI_server.cpp +++ b/src/RESTAPI_server.cpp @@ -30,6 +30,7 @@ namespace OpenWifi { int RESTAPI_Server::Start() { Logger_.information("Starting."); + Server_.InitLogging(); AsserDir_ = Daemon()->ConfigPath("openwifi.restapi.wwwassets"); AccessPolicy_ = Daemon()->ConfigGetString("openwifi.document.policy.access", "/wwwassets/access_policy.html"); @@ -50,7 +51,7 @@ namespace OpenWifi { Params->setMaxQueued(200); Params->setKeepAlive(true); - auto NewServer = std::make_unique(new RequestHandlerFactory, Pool_, Sock, Params); + auto NewServer = std::make_unique(new RequestHandlerFactory(Server_), Pool_, Sock, Params); NewServer->start(); RESTServers_.push_back(std::move(NewServer)); } @@ -75,7 +76,7 @@ namespace OpenWifi { RESTAPI_action_links, RESTAPI_avatarHandler, RESTAPI_email_handler - >(Path,Bindings,Logger_); + >(Path,Bindings,Logger_,Server_); } void RESTAPI_Server::Stop() { diff --git a/src/RESTAPI_server.h b/src/RESTAPI_server.h index 1bde7f8..5052632 100644 --- a/src/RESTAPI_server.h +++ b/src/RESTAPI_server.h @@ -15,6 +15,7 @@ #include "Poco/Net/HTTPRequestHandlerFactory.h" #include "Poco/Net/HTTPServerRequest.h" #include "Poco/Net/NetException.h" +#include "RESTAPI_GenericServer.h" namespace OpenWifi { @@ -40,6 +41,7 @@ namespace OpenWifi { std::string AsserDir_; std::string PasswordPolicy_; std::string AccessPolicy_; + RESTAPI_GenericServer Server_; RESTAPI_Server() noexcept: SubSystemServer("RESTAPIServer", "REST-SRV", "openwifi.restapi") @@ -51,12 +53,14 @@ namespace OpenWifi { class RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { public: - RequestHandlerFactory() : - Logger_(RESTAPI_Server()->Logger()){} + RequestHandlerFactory(RESTAPI_GenericServer &Server) : + Logger_(RESTAPI_Server()->Logger()), + Server_(Server){} Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &request) override; private: Poco::Logger & Logger_; + RESTAPI_GenericServer &Server_; }; diff --git a/src/RESTAPI_systemEndpoints_handler.h b/src/RESTAPI_systemEndpoints_handler.h index 77e5bd6..0b8f0e7 100644 --- a/src/RESTAPI_systemEndpoints_handler.h +++ b/src/RESTAPI_systemEndpoints_handler.h @@ -9,10 +9,11 @@ namespace OpenWifi { class RESTAPI_systemEndpoints_handler : public RESTAPIHandler { public: - RESTAPI_systemEndpoints_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_systemEndpoints_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {} static const std::list PathName() { return std::list{"/api/v1/systemEndpoints"}; }; void DoGet() final; diff --git a/src/RESTAPI_system_command.cpp b/src/RESTAPI_system_command.cpp index 2ef6ae5..5da9f62 100644 --- a/src/RESTAPI_system_command.cpp +++ b/src/RESTAPI_system_command.cpp @@ -12,6 +12,7 @@ #include "Daemon.h" #include "RESTAPI_protocol.h" +#include "RESTAPI_errors.h" namespace OpenWifi { void RESTAPI_system_command::DoPost() { diff --git a/src/RESTAPI_system_command.h b/src/RESTAPI_system_command.h index 08e8168..060a3e6 100644 --- a/src/RESTAPI_system_command.h +++ b/src/RESTAPI_system_command.h @@ -14,11 +14,12 @@ namespace OpenWifi { class RESTAPI_system_command : public RESTAPIHandler { public: - RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {} static const std::list PathName() { return std::list{"/api/v1/system"};} diff --git a/src/RESTAPI_user_handler.h b/src/RESTAPI_user_handler.h index 5862e11..f2c79b0 100644 --- a/src/RESTAPI_user_handler.h +++ b/src/RESTAPI_user_handler.h @@ -10,7 +10,7 @@ namespace OpenWifi { class RESTAPI_user_handler : public RESTAPIHandler { public: - RESTAPI_user_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_user_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector {Poco::Net::HTTPRequest::HTTP_POST, @@ -18,6 +18,7 @@ namespace OpenWifi { Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {} static const std::list PathName() { return std::list{"/api/v1/user/{id}"}; }; void DoGet() final; diff --git a/src/RESTAPI_users_handler.h b/src/RESTAPI_users_handler.h index 3feb844..87a767f 100644 --- a/src/RESTAPI_users_handler.h +++ b/src/RESTAPI_users_handler.h @@ -10,11 +10,12 @@ namespace OpenWifi { class RESTAPI_users_handler : public RESTAPIHandler { public: - RESTAPI_users_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_users_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector {Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {} static const std::list PathName() { return std::list{"/api/v1/users"}; }; void DoGet() final; diff --git a/src/RESTAPI_validateToken_handler.h b/src/RESTAPI_validateToken_handler.h index 3060947..e8dc9ba 100644 --- a/src/RESTAPI_validateToken_handler.h +++ b/src/RESTAPI_validateToken_handler.h @@ -10,11 +10,12 @@ namespace OpenWifi { class RESTAPI_validateToken_handler : public RESTAPIHandler { public: - RESTAPI_validateToken_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, bool Internal) + RESTAPI_validateToken_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) : RESTAPIHandler(bindings, L, std::vector {Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, + Server, Internal) {}; static const std::list PathName() { return std::list{"/api/v1/validateToken"}; }; void DoGet() final;