diff --git a/spec/spec.md b/spec/spec.md index f9a4570..3282c04 100644 --- a/spec/spec.md +++ b/spec/spec.md @@ -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". must start with -+configstart+ +#configstart# and end with -+configend+ +#configend# -comment + +comment # Close variable with ; @@ -233,6 +233,9 @@ mandatory: emailPassword emailServerAddress databaseConnectionString={postgresql://{user}:{password}@{host}:{port}/{database}} + sslCrtPath + sslKeyPath + optional:{default} emailServerPort={587} diff --git a/src/database.cpp b/src/database.cpp index 455cebb..3d980a9 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -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 */ pqxx::result executeStatement_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE(pqxx::connection &connection) { diff --git a/src/default-cavecomm.conf b/src/default-cavecomm.conf index 5b7ed9e..d8119b5 100644 --- a/src/default-cavecomm.conf +++ b/src/default-cavecomm.conf @@ -5,6 +5,9 @@ # emailAddress= # emailPassword= # emailServerAddress= +# sslCrtPath= +# sslKeyPath= + # Optional: {default} # emailServerPort={587} @@ -25,4 +28,9 @@ emailServerPort=587; emailAddressDisplay=Cavecomm Automated Management System; +sslCrtPath=/media/sf_cavecommRemote/example.crt; + +sslKeyPath=/media/sf_cavecommRemote/example.key; + + #configend# diff --git a/src/main.cpp b/src/main.cpp index 47d4aba..1734085 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) { cout << "Aborting Startup!" << endl; return 1; } - + return 0; // Create app with Middleware crow::App 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 - //todo:properly setup SSL - app.ssl_file("/media/sf_cavecommRemote/example.crt", "/media/sf_cavecommRemote/example.key"); + app.ssl_file(configuration.sslCrtPath, configuration.sslKeyPath); app.port(18080).multithreaded().run(); } diff --git a/src/utilities.cpp b/src/utilities.cpp index c5934b8..ceb2fed 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -37,7 +37,7 @@ namespace Utilities { } 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) return stringToTrim.substr(0, position); return stringToTrim; @@ -54,16 +54,22 @@ namespace Utilities { std::string emailServerAddress; int emailServerPort = 587; std::string emailAddressDisplay = "Cavecomm Automated Management System"; + std::string sslCrtPath; + std::string sslKeyPath; /* * validates existence of mandatory variables in config * returns 0 if successful else 1 */ int checkMandatoryVariables() const { - if (emailAddress.compare("") == 0 - || emailPassword.compare("") == 0 - || emailServerAddress.compare("") == 0 - || databaseConnectionString.compare("") == 0) + if ( + emailAddress.empty() + || emailPassword.empty() + || emailServerAddress.empty() + || databaseConnectionString.empty() + || sslCrtPath.empty() + || sslCrtPath.empty() + ) return 1; return 0; @@ -113,30 +119,38 @@ namespace Utilities { if (lineVector.size() == 2) { 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), ';'); continue; } - if (lineVector.at(0).compare("emailPassword") == 0) { + if (lineVector.at(0) == "emailPassword") { emailPassword = trimFromDelimiter(lineVector.at(1), ';'); continue; } - if (lineVector.at(0).compare("emailServerAddress") == 0) { + if (lineVector.at(0) == "emailServerAddress") { emailServerAddress = trimFromDelimiter(lineVector.at(1), ';'); continue; } - if (lineVector.at(0).compare("emailServerPort") == 0) { + if (lineVector.at(0) == "emailServerPort") { emailServerPort = std::stoi(trimFromDelimiter(lineVector.at(1), ';')); continue; } - if (lineVector.at(0).compare("emailAddressDisplay") == 0) { + if (lineVector.at(0) == "emailAddressDisplay") { emailAddressDisplay = trimFromDelimiter(lineVector.at(1), ';'); continue; } - if (lineVector.at(0).compare("databaseConnectionString") == 0) { + if (lineVector.at(0) == "databaseConnectionString") { databaseConnectionString = trimFromDelimiter(lineVector.at(1), ';'); 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 */ 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) { stringToProcess.replace(stringToProcess.find(from), std::string(from).size(), to); stringPosition = stringToProcess.find(from); @@ -200,7 +214,7 @@ namespace Utilities { int err_no = client.sendMail(msg); if (err_no != 0) { 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 << " (error no: " << err_no << ")" << '\n'; return 1;