Add ssl certificate crt and key to config
This commit is contained in:
@@ -220,11 +220,11 @@ This authoritative account, by default, should give 97% of a commission's value
|
|||||||
+ configuration file can be given as a parameter at startup else it is "cavecomm.conf".
|
+ configuration file can be given as a parameter at startup else it is "cavecomm.conf".
|
||||||
|
|
||||||
must start with
|
must start with
|
||||||
+configstart+
|
#configstart#
|
||||||
and end with
|
and end with
|
||||||
+configend+
|
#configend#
|
||||||
|
|
||||||
comment +
|
comment #
|
||||||
|
|
||||||
Close variable with ;
|
Close variable with ;
|
||||||
|
|
||||||
@@ -233,6 +233,9 @@ mandatory:
|
|||||||
emailPassword
|
emailPassword
|
||||||
emailServerAddress
|
emailServerAddress
|
||||||
databaseConnectionString={postgresql://{user}:{password}@{host}:{port}/{database}}
|
databaseConnectionString={postgresql://{user}:{password}@{host}:{port}/{database}}
|
||||||
|
sslCrtPath
|
||||||
|
sslKeyPath
|
||||||
|
|
||||||
|
|
||||||
optional:{default}
|
optional:{default}
|
||||||
emailServerPort={587}
|
emailServerPort={587}
|
||||||
|
@@ -284,7 +284,7 @@ namespace Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Executes the prepared statement SELECT_ITEM_BY_ID
|
* Executes the SELECT_FREELANCERS_WITHCOMMISSIONSSTATE statement
|
||||||
* Takes an open pqxx::connection
|
* Takes an open pqxx::connection
|
||||||
*/
|
*/
|
||||||
pqxx::result executeStatement_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE(pqxx::connection &connection) {
|
pqxx::result executeStatement_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE(pqxx::connection &connection) {
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
# emailAddress=
|
# emailAddress=
|
||||||
# emailPassword=
|
# emailPassword=
|
||||||
# emailServerAddress=
|
# emailServerAddress=
|
||||||
|
# sslCrtPath=
|
||||||
|
# sslKeyPath=
|
||||||
|
|
||||||
|
|
||||||
# Optional: {default}
|
# Optional: {default}
|
||||||
# emailServerPort={587}
|
# emailServerPort={587}
|
||||||
@@ -25,4 +28,9 @@ emailServerPort=587;
|
|||||||
|
|
||||||
emailAddressDisplay=Cavecomm Automated Management System;
|
emailAddressDisplay=Cavecomm Automated Management System;
|
||||||
|
|
||||||
|
sslCrtPath=/media/sf_cavecommRemote/example.crt;
|
||||||
|
|
||||||
|
sslKeyPath=/media/sf_cavecommRemote/example.key;
|
||||||
|
|
||||||
|
|
||||||
#configend#
|
#configend#
|
||||||
|
@@ -19,7 +19,7 @@ int main(int argc, char *argv[]) {
|
|||||||
cout << "Aborting Startup!" << endl;
|
cout << "Aborting Startup!" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
// Create app with Middleware
|
// Create app with Middleware
|
||||||
crow::App<crow::CookieParser> app;
|
crow::App<crow::CookieParser> app;
|
||||||
|
|
||||||
@@ -508,7 +508,6 @@ int main(int argc, char *argv[]) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//set the port, set the app to run on multiple threads, and run the app
|
//set the port, set the app to run on multiple threads, and run the app
|
||||||
//todo:properly setup SSL
|
app.ssl_file(configuration.sslCrtPath, configuration.sslKeyPath);
|
||||||
app.ssl_file("/media/sf_cavecommRemote/example.crt", "/media/sf_cavecommRemote/example.key");
|
|
||||||
app.port(18080).multithreaded().run();
|
app.port(18080).multithreaded().run();
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ namespace Utilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string trimFromDelimiter(std::string stringToTrim, char delimiter) {
|
std::string trimFromDelimiter(std::string stringToTrim, char delimiter) {
|
||||||
int position = stringToTrim.find(delimiter);
|
std::size_t position = stringToTrim.find(delimiter);
|
||||||
if (position != std::string::npos)
|
if (position != std::string::npos)
|
||||||
return stringToTrim.substr(0, position);
|
return stringToTrim.substr(0, position);
|
||||||
return stringToTrim;
|
return stringToTrim;
|
||||||
@@ -54,16 +54,22 @@ namespace Utilities {
|
|||||||
std::string emailServerAddress;
|
std::string emailServerAddress;
|
||||||
int emailServerPort = 587;
|
int emailServerPort = 587;
|
||||||
std::string emailAddressDisplay = "Cavecomm Automated Management System";
|
std::string emailAddressDisplay = "Cavecomm Automated Management System";
|
||||||
|
std::string sslCrtPath;
|
||||||
|
std::string sslKeyPath;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* validates existence of mandatory variables in config
|
* validates existence of mandatory variables in config
|
||||||
* returns 0 if successful else 1
|
* returns 0 if successful else 1
|
||||||
*/
|
*/
|
||||||
int checkMandatoryVariables() const {
|
int checkMandatoryVariables() const {
|
||||||
if (emailAddress.compare("") == 0
|
if (
|
||||||
|| emailPassword.compare("") == 0
|
emailAddress.empty()
|
||||||
|| emailServerAddress.compare("") == 0
|
|| emailPassword.empty()
|
||||||
|| databaseConnectionString.compare("") == 0)
|
|| emailServerAddress.empty()
|
||||||
|
|| databaseConnectionString.empty()
|
||||||
|
|| sslCrtPath.empty()
|
||||||
|
|| sslCrtPath.empty()
|
||||||
|
)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -113,30 +119,38 @@ namespace Utilities {
|
|||||||
|
|
||||||
if (lineVector.size() == 2) {
|
if (lineVector.size() == 2) {
|
||||||
std::cout << lineVector.at(0) << " - " << lineVector.at(1) << std::endl;
|
std::cout << lineVector.at(0) << " - " << lineVector.at(1) << std::endl;
|
||||||
if (lineVector.at(0).compare("emailAddress") == 0) {
|
if (lineVector.at(0) == "emailAddress") {
|
||||||
emailAddress = trimFromDelimiter(lineVector.at(1), ';');
|
emailAddress = trimFromDelimiter(lineVector.at(1), ';');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lineVector.at(0).compare("emailPassword") == 0) {
|
if (lineVector.at(0) == "emailPassword") {
|
||||||
emailPassword = trimFromDelimiter(lineVector.at(1), ';');
|
emailPassword = trimFromDelimiter(lineVector.at(1), ';');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lineVector.at(0).compare("emailServerAddress") == 0) {
|
if (lineVector.at(0) == "emailServerAddress") {
|
||||||
emailServerAddress = trimFromDelimiter(lineVector.at(1), ';');
|
emailServerAddress = trimFromDelimiter(lineVector.at(1), ';');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lineVector.at(0).compare("emailServerPort") == 0) {
|
if (lineVector.at(0) == "emailServerPort") {
|
||||||
emailServerPort = std::stoi(trimFromDelimiter(lineVector.at(1), ';'));
|
emailServerPort = std::stoi(trimFromDelimiter(lineVector.at(1), ';'));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lineVector.at(0).compare("emailAddressDisplay") == 0) {
|
if (lineVector.at(0) == "emailAddressDisplay") {
|
||||||
emailAddressDisplay = trimFromDelimiter(lineVector.at(1), ';');
|
emailAddressDisplay = trimFromDelimiter(lineVector.at(1), ';');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lineVector.at(0).compare("databaseConnectionString") == 0) {
|
if (lineVector.at(0) == "databaseConnectionString") {
|
||||||
databaseConnectionString = trimFromDelimiter(lineVector.at(1), ';');
|
databaseConnectionString = trimFromDelimiter(lineVector.at(1), ';');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (lineVector.at(0) == "sslCrtPath") {
|
||||||
|
sslCrtPath = trimFromDelimiter(lineVector.at(1), ';');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (lineVector.at(0) == "sslKeyPath") {
|
||||||
|
sslKeyPath = trimFromDelimiter(lineVector.at(1), ';');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +177,7 @@ namespace Utilities {
|
|||||||
* replaces a string with another string within a string
|
* replaces a string with another string within a string
|
||||||
*/
|
*/
|
||||||
void replaceString(std::string &stringToProcess, const std::string& from, const std::string& to) {
|
void replaceString(std::string &stringToProcess, const std::string& from, const std::string& to) {
|
||||||
int stringPosition = stringToProcess.find(from);
|
std::size_t stringPosition = stringToProcess.find(from);
|
||||||
while (stringPosition != std::string::npos) {
|
while (stringPosition != std::string::npos) {
|
||||||
stringToProcess.replace(stringToProcess.find(from), std::string(from).size(), to);
|
stringToProcess.replace(stringToProcess.find(from), std::string(from).size(), to);
|
||||||
stringPosition = stringToProcess.find(from);
|
stringPosition = stringToProcess.find(from);
|
||||||
@@ -200,7 +214,7 @@ namespace Utilities {
|
|||||||
int err_no = client.sendMail(msg);
|
int err_no = client.sendMail(msg);
|
||||||
if (err_no != 0) {
|
if (err_no != 0) {
|
||||||
std::cerr << client.getCommunicationLog() << '\n';
|
std::cerr << client.getCommunicationLog() << '\n';
|
||||||
std::string errorMessage = client.getErrorMessage(err_no);
|
std::string errorMessage = OpportunisticSecureSMTPClient::getErrorMessage(err_no);
|
||||||
std::cerr << "An error occurred: " << errorMessage
|
std::cerr << "An error occurred: " << errorMessage
|
||||||
<< " (error no: " << err_no << ")" << '\n';
|
<< " (error no: " << err_no << ")" << '\n';
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user