diff options
author | eportnov <eportnov@ibs.ru> | 2022-10-10 17:57:31 +0300 |
---|---|---|
committer | eportnov <eportnov@ibs.ru> | 2022-10-10 17:57:31 +0300 |
commit | 58804e96888b0167311d2820b705d66956230d4c (patch) | |
tree | b83791141f3c083b37c3f736bc22c5f00dcadcf8 /meta-ibs | |
parent | 49ae57e0aa4602263d25f292942f9df21c6a2f8d (diff) | |
download | openbmc-58804e96888b0167311d2820b705d66956230d4c.tar.xz |
set smtp post send mail
Diffstat (limited to 'meta-ibs')
-rw-r--r-- | meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0020-set-smtp-send-post-request.patch | 154 | ||||
-rw-r--r-- | meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend | 1 |
2 files changed, 155 insertions, 0 deletions
diff --git a/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0020-set-smtp-send-post-request.patch b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0020-set-smtp-send-post-request.patch new file mode 100644 index 0000000000..557607ecf0 --- /dev/null +++ b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb/0020-set-smtp-send-post-request.patch @@ -0,0 +1,154 @@ +From 9a477a7f1c8c7fcb8a4206fd6b8be3c6cb52d2b7 Mon Sep 17 00:00:00 2001 +From: claiff <claiff@mail.ru> +Date: Mon, 10 Oct 2022 17:42:28 +0300 +Subject: [PATCH] set smtp send post request + +--- + redfish-core/include/redfish.hpp | 3 +- + redfish-core/lib/smtp.hpp | 72 ++++++++++++++++++++++++-------- + 2 files changed, 56 insertions(+), 19 deletions(-) + +diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp +index ebaabdfa..494d6709 100644 +--- a/redfish-core/include/redfish.hpp ++++ b/redfish-core/include/redfish.hpp +@@ -229,7 +229,8 @@ class RedfishService + requestRoutesTriggerCollection(app); + requestRoutesTrigger(app); + requestRoutesSmtp(app); +- requestSmtpFunctions(app); ++ requestSmtpGetFunctions(app); ++ requestSmtpPostFunctions(app); + + requestRoutesSyslog(app); + requestRoutesSyslogUpdateConfig(app); +diff --git a/redfish-core/lib/smtp.hpp b/redfish-core/lib/smtp.hpp +index 49ac9340..83bbf9b5 100644 +--- a/redfish-core/lib/smtp.hpp ++++ b/redfish-core/lib/smtp.hpp +@@ -33,9 +33,10 @@ namespace redfish + return function_with_parameters.substr( ZERO_POSITION, position ); + } + +- inline void SendMail( std::string const& function_with_parameters, std::shared_ptr<bmcweb::AsyncResp> const& asyncResp ) ++ inline void SendMail( std::string const& from, std::string const& subject, ++ std::string const& text, std::shared_ptr<bmcweb::AsyncResp> const& asyncResp ) + { +- auto parsing_result = parser::SendMessage{function_with_parameters}; ++ static const std::string SEND_MAIL_METHOD_NAME = "SendMail"; + + crow::connections::systemBus->async_method_call([asyncResp](const boost::system::error_code& error_code, bool result){ + if (error_code.value() == EBADR || +@@ -54,10 +55,10 @@ namespace redfish + asyncResp->res.jsonValue["result"] = result; + }, + SERVICE_PATH, OBJECT_MESSENGER_PATH, INTERFACE_MESSENGER_PATH, +- parsing_result.GetMethodName(), +- parsing_result.GetFrom(), +- parsing_result.GetSubject(), +- parsing_result.GetText()); ++ SEND_MAIL_METHOD_NAME, ++ from, ++ subject, ++ text); + } + + inline void SetSettings( std::string const& function_with_parameters, std::shared_ptr<bmcweb::AsyncResp> const& asyncResp ) +@@ -236,18 +237,56 @@ namespace redfish + }); + } + ++ inline void requestSmtpPostFunctions(App& app) ++ { ++ BMCWEB_ROUTE(app, "/redfish/v1/Smtp/<str>/") ++ .privileges(redfish::privileges::getSmtpCollection) ++ .methods(boost::beast::http::verb::post)( ++ [&app](const crow::Request& req, ++ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, ++ const std::string& params) ++ { ++ static constexpr std::string_view SEND_MAIL_METHOD_NAME = "SendMail"; ++ static constexpr std::string_view FROM_FIELD = "from"; ++ static constexpr std::string_view SUBJECT_FIELD = "subject"; ++ static constexpr std::string_view TEXT_FIELD = "text"; ++ ++ if (!redfish::setUpRedfishRoute(app, req, asyncResp)) ++ { ++ return; ++ } ++ ++ if(params != SEND_MAIL_METHOD_NAME) ++ { ++ asyncResp->res.jsonValue["result"] = false; ++ return; ++ } ++ ++ std::string from, subject, text; ++ if (!json_util::readJsonPatch(req, asyncResp->res, ++ FROM_FIELD, from, ++ SUBJECT_FIELD, subject, ++ TEXT_FIELD, text)) ++ { ++ asyncResp->res.jsonValue["result"] = false; ++ return; ++ } ++ smtp::SendMail(from, subject, text, asyncResp); ++ return; + ++ }); ++ } + +- inline void requestSmtpFunctions(App& app) ++ inline void requestSmtpGetFunctions(App& app) + { + BMCWEB_ROUTE(app, "/redfish/v1/Smtp/<str>/") + .privileges(redfish::privileges::getSmtpCollection) + .methods(boost::beast::http::verb::get)( + [&app](const crow::Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, +- const std::string& function_with_parameters) ++ const std::string& params) + { +- static constexpr std::string_view SEND_MAIL_METHOD_NAME = "SendMail"; ++ + + static constexpr std::string_view GET_SETTINGS_METHOD_NAME = "GetSettings"; + static constexpr std::string_view SET_SETTINGS_METHOD_NAME = "SetSettings"; +@@ -260,19 +299,16 @@ namespace redfish + { + return; + } +- auto function_name = smtp::GetFunctionName(function_with_parameters); ++ ++ auto function_name = smtp::GetFunctionName( params ); + + asyncResp->res.jsonValue["@odata.type"] ="#SmtpCollection"; + asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Smtp/" + function_name; + asyncResp->res.jsonValue["Name"] = "Smtp Collection"; + +- if(function_name == SEND_MAIL_METHOD_NAME) +- { +- smtp::SendMail(function_with_parameters, asyncResp); +- } +- else if(function_name == SET_SETTINGS_METHOD_NAME) ++ if(function_name == SET_SETTINGS_METHOD_NAME) + { +- smtp::SetSettings(function_with_parameters, asyncResp); ++ smtp::SetSettings(params, asyncResp); + } + else if(function_name == GET_SETTINGS_METHOD_NAME) + { +@@ -284,11 +320,11 @@ namespace redfish + } + else if(function_name == ADD_MAILS_METHOD_NAME) + { +- smtp::AddMails(function_with_parameters, asyncResp); ++ smtp::AddMails(params, asyncResp); + } + else if(function_name == DELETE_MAILS_METHOD_NAME) + { +- smtp::DeleteMails(function_with_parameters, asyncResp); ++ smtp::DeleteMails(params, asyncResp); + } + }); + } diff --git a/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend index d363d76474..c131a95f77 100644 --- a/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend +++ b/meta-ibs/meta-cp2-5422/recipes-phosphor/interfaces/bmcweb_%.bbappend @@ -16,6 +16,7 @@ SRC_URI += "\ file://0017-update-smtp.patch \ file://0018-add-timezone.patch \ file://0019-add-smtp-logging.patch \ + file://0020-set-smtp-send-post-request.patch \ " EXTRA_OEMESON += "\ |