Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ecpp/alert_rules_list.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ if (streq (part, "LIST")) {
http_die ("internal-error", err.c_str ());
}
part = zmsg_popstr (recv_msg);

cxxtools::SerializationInfo si;
si.setCategory(cxxtools::SerializationInfo::Category::Array);

Expand All @@ -199,7 +199,7 @@ if (streq (part, "LIST")) {
log_debug ("Collecting the data:");

while (part) {

const char *internalCat = "\"CAT_INTERNAL\"";
const char *automationCat = "\"CAT_AUTOMATION\"";

Expand Down Expand Up @@ -295,7 +295,7 @@ if (streq (part, "LIST")) {
{
//ignore the change and continue
log_error ("Error during replacement of ename: %s", e.what());
}
}
}

//deserialize the new data to add it in the answer json
Expand Down
10 changes: 4 additions & 6 deletions ecpp/average.ecpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,10 @@ bool database_ready;
http_die ("internal-error", err.c_str ());
}

const int RECV_TIMEOUT_S = 60;
zmsg_t *recv_msg = client->recv (zuuid_str_canonical (uuid), RECV_TIMEOUT_S);
zmsg_t *recv_msg = client->recv (zuuid_str_canonical (uuid), 30);
zuuid_destroy (&uuid);
if (!recv_msg) {
log_fatal ("client->recv (timeout = '%d') returned NULL", RECV_TIMEOUT_S);
log_fatal ("client->recv (timeout = '30') returned NULL");
std::string err = TRANSLATE_ME ("client->recv () returned NULL");
http_die ("internal-error", err.c_str ());
}
Expand Down Expand Up @@ -391,11 +390,10 @@ bool database_ready;
http_die ("internal-error", err.c_str ());
}

const int RECV_TIMEOUT_S = 60;
zmsg_t *recv_msg = client->recv (zuuid_str_canonical (uuid), RECV_TIMEOUT_S);
zmsg_t *recv_msg = client->recv (zuuid_str_canonical (uuid), 30);
zuuid_destroy (&uuid);
if (!recv_msg) {
log_fatal ("client->recv (timeout = '%d') returned NULL", RECV_TIMEOUT_S);
log_fatal ("client->recv (timeout = '30') returned NULL");
std::string err = TRANSLATE_ME ("client->recv () returned NULL");
http_die ("internal-error", err.c_str ());
}
Expand Down
64 changes: 59 additions & 5 deletions ecpp/email_feedback.ecpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
#
# Copyright (C) 2016 - 2020 Eaton
# Copyright (C) 2016 - 2022 Eaton
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -21,6 +21,7 @@
* \file email_feedback.ecpp
* \author Barbora Stepankova <BarboraStepankova@Eaton.com>
* \author Michal Vyskocil <MichalVyskocil@Eaton.com>
* \author Arnaud Quette <ArnaudQuette@Eaton.com>
* \brief Sends feedback email.
*/
#><%pre>
Expand All @@ -36,6 +37,47 @@
#include <fstream>
#include <libgen.h> //POSIX version of basename!!
#include <fty_common_rest_audit_log.h>
#include <cxxtools/jsondeserializer.h>

// TODO: put in fty-common-rest
static const char* BRANDING_INFO = "/etc/etn-ipm2-branding.conf";

static cxxtools::SerializationInfo* s_load_branding_info()
{
cxxtools::SerializationInfo* si = new cxxtools::SerializationInfo();
try {
std::ifstream f(BRANDING_INFO);
std::string json_string(std::istreambuf_iterator<char>(f), {});
std::stringstream s(json_string);
cxxtools::JsonDeserializer json(s);
json.deserialize(*si);
log_info("email_feedback: load %s OK", BRANDING_INFO);
} catch (const std::exception& e) {
log_error("Error while parsing JSON: %s", e.what());
}
return si;
}

static char* s_get_branding_info(cxxtools::SerializationInfo* si, const char* key, const char* dfl)
{
std::string value;
try {
si->getMember(key) >>= value;
} catch (const std::exception& e) {
log_info("Problem with getting %s in JSON: %s", key, e.what());
if (dfl) {
return strdup(dfl);
} else {
return NULL;
}
}
if (value.empty() && dfl) {
log_debug("%s: can't get value. Using default '%s'", __func__, dfl);
return strdup(dfl);
}
return strdup(value.c_str());
}
// end-of TODO: put in fty-common-rest

// encode GET message for smtp agent
static zmsg_t*
Expand Down Expand Up @@ -129,15 +171,26 @@ UserInfo user;
bool attach_system_state = false;
bool participate = false;
unsigned _timeout = 60;
char *feedback_email = NULL;
{

std::string to = qparam.param ("to");
if (to.empty ()) {
const char* c_to = getenv ("BIOS_FEEDBACK_EMAIL");
if (c_to)
to = std::string {c_to};
else
to = std::string {"EatonProductFeedback@Eaton.com"};
else {
// Get Product feedback mail from branding info
cxxtools::SerializationInfo* bi = s_load_branding_info();
feedback_email = s_get_branding_info(bi, "feedback_email", "EatonProductFeedback@Eaton.com");
if (bi) {
delete bi;
bi = nullptr;
}
if (feedback_email) {
to = std::string {feedback_email};
zstr_free (&feedback_email);
}
}
}

if (to.find ('@', 0) == std::string::npos) {
Expand All @@ -147,6 +200,7 @@ UserInfo user;
}

checked_to = to;
logInfo("Using Product Feedback email address '{}'", checked_to.c_str());

std::string _reply = qparam.param ("reply");

Expand Down Expand Up @@ -322,7 +376,7 @@ UserInfo user;
log_error_audit ("Request CREATE email_feedback FAILED");
http_die ("internal-error", err.c_str ());
}
log_info_audit ("Request CREATE email_feedback SUCCESS");
log_info_audit ("Request CREATE email_feedback SUCCESS (using %s)", checked_to.c_str());

</%cpp>
{
Expand Down
83 changes: 69 additions & 14 deletions ecpp/email_vote.ecpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
#
# Copyright (C) 2016 - 2020 Eaton
# Copyright (C) 2016 - 2022 Eaton
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -21,6 +21,7 @@
* \file email_vote.ecpp
* \author Barbora Stepankova <BarboraStepankova@Eaton.com>
* \author Michal Vyskocil <MichalVyskocil@Eaton.com>
* \author Arnaud Quette <ArnaudQuette@Eaton.com>
* \brief Sends voting email.
*/
#><%pre>
Expand All @@ -36,6 +37,48 @@
#include <libgen.h> //POSIX version of basename!!
#include <fty_common_rest_audit_log.h>

#include <cxxtools/jsondeserializer.h>

// TODO: put in fty-common-rest
static const char* BRANDING_INFO = "/etc/etn-ipm2-branding.conf";

static cxxtools::SerializationInfo* s_load_branding_info()
{
cxxtools::SerializationInfo* si = new cxxtools::SerializationInfo();
try {
std::ifstream f(BRANDING_INFO);
std::string json_string(std::istreambuf_iterator<char>(f), {});
std::stringstream s(json_string);
cxxtools::JsonDeserializer json(s);
json.deserialize(*si);
log_info("email_feedback: load %s OK", BRANDING_INFO);
} catch (const std::exception& e) {
log_error("Error while parsing JSON: %s", e.what());
}
return si;
}

static char* s_get_branding_info(cxxtools::SerializationInfo* si, const char* key, const char* dfl)
{
std::string value;
try {
si->getMember(key) >>= value;
} catch (const std::exception& e) {
log_info("Problem with getting %s in JSON: %s", key, e.what());
if (dfl) {
return strdup(dfl);
} else {
return NULL;
}
}
if (value.empty() && dfl) {
log_debug("%s: can't get value. Using default '%s'", __func__, dfl);
return strdup(dfl);
}
return strdup(value.c_str());
}
// end-of TODO: put in fty-common-rest

// encode GET message for smtp agent
static zmsg_t*
s_smtp_GET_message (
Expand Down Expand Up @@ -90,33 +133,45 @@ UserInfo user;
{BiosProfile::Admin, "C"},
{BiosProfile::Dashboard, "C"}
};
std::string audit_msg = std::string ("Request CREATE email_test FAILED");
std::string audit_msg = std::string ("Request CREATE email_vote FAILED");
CHECK_USER_PERMISSIONS_OR_DIE_AUDIT (PERMISSIONS, audit_msg.empty () ? nullptr : audit_msg.c_str ());

std::string checked_to;
unsigned vote = 0;
std::string checked_context;
bool attach_system_state = false;
unsigned _timeout = 60;
char *feedback_email = NULL;
{
std::string to = qparam.param ("to");
if (to.empty ()) {
const char* c_to = getenv ("BIOS_FEEDBACK_EMAIL");
if (c_to)
to = std::string {c_to};
else
to = std::string {"EatonProductFeedback@Eaton.com"};
else {
// Get Product feedback mail from branding info
cxxtools::SerializationInfo* bi = s_load_branding_info();
feedback_email = s_get_branding_info(bi, "feedback_email", "EatonProductFeedback@Eaton.com");
if (bi) {
delete bi;
bi = nullptr;
}
if (feedback_email) {
to = std::string {feedback_email};
zstr_free (&feedback_email);
}
}
}
checked_to = to;

if (to.find ('@', 0) == std::string::npos) {
std::string expected = TRANSLATE_ME ("valid email address");
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("request-param-bad", "to", to.c_str (), expected.c_str ());
}
std::string value = qparam.param ("value");
if (value.empty ()) {
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("request-param-required", "value");
}

Expand All @@ -125,13 +180,13 @@ UserInfo user;
}
catch (const std::exception& e) {
std::string expected = TRANSLATE_ME ("number 1-3");
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("request-param-bad", "value", value.c_str (), expected.c_str ());
}

std::string context = qparam.param ("context");
if (context.empty ()) {
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("request-param-required", "context");
}

Expand All @@ -156,7 +211,7 @@ UserInfo user;
if (!client) {
log_fatal ("Error: mlm_pool.get () failed.");
std::string err = TRANSLATE_ME ("mlm_pool.get () failed.");
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("internal-error", err.c_str ());
}

Expand All @@ -177,7 +232,7 @@ UserInfo user;
AGENT_FTY_EMAIL_SENDMAIL_ONLY, "SENDMAIL");
std::string err = TRANSLATE_ME ("client->sendto () failed");
zmsg_destroy (&send);
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("internal-error", err.c_str ());
}

Expand All @@ -186,7 +241,7 @@ UserInfo user;
{
std::string msg = TRANSLATE_ME ("Error: client-> recv (timeout = '%d') returned NULL", _timeout);
log_error ("%s", msg.c_str ());
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("internal-error", msg.c_str ());
}

Expand All @@ -203,18 +258,18 @@ UserInfo user;
if (streq (msg_subject, "SENDMAIL-ERR"))
{
status = "Failed";
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("upstream-err", err_message.get ());
}
else
{
status = "Failed";
log_fatal ("Error: message recieved with invalid subject.");
std::string err = TRANSLATE_ME ("client->recv () invalid message subject");
log_error_audit ("Request CREATE email_test FAILED");
log_error_audit ("Request CREATE email_vote FAILED");
http_die ("internal-error", err.c_str ());
}
log_info_audit ("Request CREATE email_test SUCCESS");
log_info_audit ("Request CREATE email_vote SUCCESS (using %s)", checked_to.c_str());

</%cpp>
{
Expand Down
Loading