Skip to content

[CLOYSTER-96] Implement Postfix #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
18 changes: 18 additions & 0 deletions example.answerfile.ini
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,21 @@ bmc_address=10.0.0.2
#bmc_password=admin
#bmc_serialport=0
#bmc_serialspeed=9600

#[postfix]
# Profile must be 'local', 'relay' or 'sasl'.
# You must fill the SMTP values in their subsections
#profile=local
#destination=example.com
#smtpd_tls_cert_file = /etc/pki/tls/certs/cluster.example.com.cer
#smtpd_tls_key_file = /etc/pki/tls/private/cluster.example.com.key

#[postfix.sasl]
#server=smtp.example.com
#port=587
#username=relayUser
#password=examplePassword

#[postfix.relay]
#server=mx.example.com
#port=25
23 changes: 23 additions & 0 deletions include/cloysterhpc/answerfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <boost/asio.hpp>
#include <cloysterhpc/inifile.h>
#include <cloysterhpc/mailsystem/postfix.h>
#include <optional>
#include <vector>

Expand Down Expand Up @@ -72,6 +73,26 @@ class AnswerFile {
std::vector<AFNode> nodes;
};

struct AFPostfix {
struct SASL {
std::string username;
std::string password;
};
struct SMTP {
std::string server;
int port;
std::optional<SASL> sasl;
// Relay doesn't need to have a specific struct because it only
// needs 'server' and 'port'.
};
bool enabled = false;
std::vector<std::string> destination;
Postfix::Profile profile;
std::optional<SMTP> smtp;
std::filesystem::path cert_file;
std::filesystem::path key_file;
};

std::filesystem::path m_path;
inifile m_ini;

Expand All @@ -85,6 +106,7 @@ class AnswerFile {
void loadHostnameSettings();
void loadSystemSettings();
void loadNodes();
void loadPostfix();
AFNode loadNode(const std::string& section);
AFNode validateNode(AFNode node);

Expand All @@ -97,6 +119,7 @@ class AnswerFile {
AFHostname hostname;
AFSystem system;
AFNodes nodes;
AFPostfix postfix;

explicit AnswerFile(const std::filesystem::path& path);
};
Expand Down
2 changes: 2 additions & 0 deletions include/cloysterhpc/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ void backupFile(std::string_view filename);
void changeValueInConfigurationFile(
const std::string&, const std::string&, std::string_view);
void addStringToFile(std::string_view filename, std::string_view string);
std::string findAndReplace(const std::string& source, const std::string& find,
const std::string& replace);

} /* namespace cloyster */

Expand Down
1 change: 1 addition & 0 deletions include/cloysterhpc/inifile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class inifile {
CSimpleIniA ini;

public:
void loadData(const std::string& data);
void loadFile(const std::string& filepath);
void loadFile(std::string_view filepath);
void loadFile(const std::filesystem::path& filepath);
Expand Down
36 changes: 35 additions & 1 deletion include/cloysterhpc/mailsystem/postfix.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,33 @@ class Postfix {
private:
Profile m_profile;
std::optional<std::string> m_hostname {};
std::optional<std::string> m_domain {};
std::optional<std::string> m_smtp_server {};
std::optional<std::vector<std::string>> m_destination {};
std::optional<std::uint16_t> m_port {};
std::optional<std::string> m_username {};
std::optional<std::string> m_password {};
std::optional<std::filesystem::path> m_cert_file {};
std::optional<std::filesystem::path> m_key_file {};
void install();
void createFiles();
void configureSASL();
void configureRelay();

public:
[[nodiscard]] const Profile& getProfile() const;
[[maybe_unused]] void setProfile(Profile profile);

[[nodiscard]] const std::optional<std::string>& getHostname() const;

void setHostname(const std::optional<std::string>& hostname);

const std::optional<std::vector<std::string>>& getDestination() const;
void setDestination(
const std::optional<std::vector<std::string>>& destination);

[[nodiscard]] const std::optional<std::string>& getDomain() const;
void setDomain(const std::optional<std::string>& domain);

[[nodiscard]] const std::optional<std::uint16_t>& getPort() const;
void setPort(const std::optional<std::uint16_t>& port);

Expand All @@ -36,6 +52,24 @@ class Postfix {
[[nodiscard]] const std::optional<std::string>& getPassword() const;
void setPassword(const std::optional<std::string>& password);

[[nodiscard]] const std::optional<std::string>& getSMTPServer() const;
void setSMTPServer(const std::optional<std::string>& smtp_server);

[[nodiscard]] const std::optional<std::filesystem::path>&
getCertFile() const;
void setCertFile(const std::optional<std::filesystem::path>& cert_file);

[[nodiscard]] const std::optional<std::filesystem::path>&
getKeyFile() const;
void setKeyFile(const std::optional<std::filesystem::path>& cert_file);

void setup();
void enable();
void disable();
void start();
void restart();
void stop();

explicit Postfix(Profile profile);
};

Expand Down
1 change: 1 addition & 0 deletions include/cloysterhpc/services/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Shell : public Execution {
void configureTimeService(const std::list<Connection>&);
void configureQueueSystem();
void configureInfiniband();
void configureMailSystem();

void removeMemlockLimits();
void installDevelopmentComponents();
Expand Down
Loading