Configuration file readout

specification of the format in the spec
This commit is contained in:
Tina_Azure
2023-04-12 00:26:47 +02:00
parent bfa49c2281
commit 1965b06868
5 changed files with 186 additions and 29 deletions

View File

@ -72,6 +72,7 @@ $completed - marker to set if the request has been completed
## email delivery
email is sent via email server given by the admin, while the software functions as a client to it.
https://hackernoon.com/how-to-implement-smtp-client-on-c
# Interface
@ -206,3 +207,21 @@ Monetary payouts will be handled through the payment gateways provided. For now,
This means that, in the case of BTCPayServer, the [payout system](https://docs.btcpayserver.org/Payouts/) should be used. In the case of Stripe, the transaction should use the [multiparty payout system](https://stripe.com/docs/connect/add-and-pay-out-guide). Both will require a central, authoritative set of accounts respectively to shuffle money between client and freelancer.
This authoritative account, by default, should give 97% of a commission's value to the freelancer, with the 3% being reserved for itself as a service fee. This ratio should be able to be edited by the system's administrator.
+ configuration file can be given as a parameter at startup else it is "cavecomm.conf".
must start with
+configstart+
and end with
+configend+
comment +
mandatory:
emailAddress=
emailPassword=
emailServerAddress=
optional:{default}
emailServerPort={587}
emailAddressDisplay={Cavecomm Automated Management System}

View File

@ -100,6 +100,9 @@ namespace Database {
bool onDeliverPaid = false;
bool completed = false;
/*
* outputs request item in a JSON String
*/
std::string toJSONString(){
std::string outputString = "{\"requestItem:\":{";
outputString += "\"id\": " + std::to_string(id) + ",";
@ -122,6 +125,9 @@ namespace Database {
return outputString;
}
/*
* prints request item into standard out
*/
void outputItem(){
std::cout << "id = " << id << std::endl;
std::cout << "customerName = " << customerName << std::endl;

27
src/default-cavecomm.conf Normal file
View File

@ -0,0 +1,27 @@
#configstart#
# Mandatory:
# emailAddress=
# emailPassword=
# emailServerAddress=
# Optional: {default}
# emailServerPort={587}
# emailAddressDisplay={Cavecomm Automated Management System}
emailAddress=testuser0ed6e@waifu.club
emailPassword=Ve4m6GSjJ
emailServerAddress=mail.cock.li
emailServerPort=587
emailAddressDisplay=Cavecomm Automated Management System
#configend#

View File

@ -8,9 +8,16 @@
using namespace std;
int main() {
int main(int argc, char *argv[]) {
Utilities::config configuration;
configuration.readConfigFile();
if (argc > 0)
configuration.configPath = argv[1];
if (configuration.readConfigFile()) {
std::cout << "ERROR: Unable to read configuration file: " << configuration.configPath << endl;
std::cout << "Aborting Startup!" << endl;
return 1;
}
crow::SimpleApp app;
@ -126,6 +133,17 @@ int main() {
auto page = crow::mustache::load(templateHTML);
crow::mustache::context ctx(resultJsonTemplate);
bool commissionState = false;
if (resultTemplate.size() > 0) {
//use freelancerID based on SQL_STATEMENT_SELECT_TEMPLATE
pqxx::result resultCommissionState = Database::executePreparedStatement_SELECT_FREELANCER_COMMISSION_STATE(databaseConnection, stoi(resultTemplate.at(0).at(2).c_str()));
//the commissionstate
if (resultCommissionState.size() == 0 || stoi(resultCommissionState.at(0).at(0).c_str()) == 1)
commissionState = true;
}
ctx["ERROR_COMMISSIONS_CLOSED"] = commissionState;
return page.render(ctx);
});
@ -202,7 +220,7 @@ int main() {
pqxx::result resultCommissionState = Database::executePreparedStatement_SELECT_FREELANCER_COMMISSION_STATE(databaseConnection, newRequest.freelancerID);
//the commissionstate
if (resultCommissionState.size() == 0 || stoi(resultTemplate.at(0).at(0).c_str()) == 1) {
if (resultCommissionState.size() == 0 || stoi(resultCommissionState.at(0).at(0).c_str()) == 1) {
ctx["ERROR_COMMISSIONS_CLOSED"] = true;
}
else {

View File

@ -2,6 +2,9 @@
#include <list>
#include <map>
#include <iostream>
#include <fstream>
#include <locale>
#include <codecvt>
#include <regex>
#include <vector>
#include <pqxx/pqxx>
@ -19,32 +22,6 @@ using namespace jed_utils::cpp;
namespace Utilities {
const static std::map<std::string, std::string> HTML_URL_CODES = {{"%20", " "}, {"%21", "!"}, {"%22", "\""}, {"%23", "#"}, {"%24", "$"}, {"%25", "%"}, {"%26", "&"}, {"%27", "'"}, {"%28", "("}, {"%29", ")"}, {"%2A", "*"}, {"%2B", "+"}, {"%2C", ","}, {"%2D", "-"}, {"%2E", "."}, {"%2F", "/"}, {"%30", "0"}, {"%31", "1"}, {"%32", "2"}, {"%33", "3"}, {"%34", "4"}, {"%35", "5"}, {"%36", "6"}, {"%37", "7"}, {"%38", "8"}, {"%39", "9"}, {"%3A", ":"}, {"%3B", ";"}, {"%3C", "<"}, {"%3D", "="}, {"%3E", ">"}, {"%3F", "?"}, {"%40", "@"}, {"%5B", "["}, {"%5C", "\\"}, {"%5D", "]"}, {"%5E", "^"}, {"%5F", "_"}, {"%60", "`"}, {"%7B", "{"}, {"%7C", "|"}, {"%7D", "}"}, {"%7E", "~"}, {"%7F", " "}, {"%80", ""}, {"%82", ""}, {"%83", "ƒ"}, {"%84", ""}, {"%85", ""}, {"%86", ""}, {"%87", ""}, {"%88", "ˆ"}, {"%89", ""}, {"%8A", "Š"}, {"%8B", ""}, {"%8C", "Œ"}, {"%8E", "Ž"}, {"%91", ""}, {"%92", ""}, {"%93", ""}, {"%94", ""}, {"%95", ""}, {"%96", ""}, {"%97", ""}, {"%98", "˜"}, {"%99", ""}, {"%9A", "š"}, {"%9B", ""}, {"%9C", "œ"}, {"%9E", "ž"}, {"%9F", "Ÿ"}, {"%A1", "¡"}, {"%A2", "¢"}, {"%A3", "£"}, {"%A4", "¤"}, {"%A5", "¥"}, {"%A6", "¦"}, {"%A7", "§"}, {"%A8", "¨"}, {"%A9", "©"}, {"%AA", "ª"}, {"%AB", "«"}, {"%AC", "¬"}, {"%AE", "®"}, {"%AF", "¯"}, {"%B0", "°"}, {"%B1", "±"}, {"%B2", "²"}, {"%B3", "³"}, {"%B4", "´"}, {"%B5", "µ"}, {"%B6", ""}, {"%B7", "·"}, {"%B8", "¸"}, {"%B9", "¹"}, {"%BA", "º"}, {"%BB", "»"}, {"%BC", "¼"}, {"%BD", "½"}, {"%BE", "¾"}, {"%BF", "¿"}, {"%C0", "À"}, {"%C1", "Á"}, {"%C2", "Â"}, {"%C3", "Ã"}, {"%C4", "Ä"}, {"%C5", "Å"}, {"%C6", "Æ"}, {"%C7", "Ç"}, {"%C8", "È"}, {"%C9", "É"}, {"%CA", "Ê"}, {"%CB", "Ë"}, {"%CC", "Ì"}, {"%CD", "Í"}, {"%CE", "Î"}, {"%CF", "Ï"}, {"%D0", "Ð"}, {"%D1", "Ñ"}, {"%D2", "Ò"}, {"%D3", "Ó"}, {"%D4", "Ô"}, {"%D5", "Õ"}, {"%D6", "Ö"}, {"%D7", "×"}, {"%D8", "Ø"}, {"%D9", "Ù"}, {"%DA", "Ú"}, {"%DB", "Û"}, {"%DC", "Ü"}, {"%DD", "Ý"}, {"%DE", "Þ"}, {"%DF", "ß"}, {"%E0", "à"}, {"%E1", "á"}, {"%E2", "â"}, {"%E3", "ã"}, {"%E4", "ä"}, {"%E5", "å"}, {"%E6", "æ"}, {"%E7", "ç"}, {"%E8", "è"}, {"%E9", "é"}, {"%EA", "ê"}, {"%EB", "ë"}, {"%EC", "ì"}, {"%ED", "í"}, {"%EE", "î"}, {"%EF", "ï"}, {"%F0", "ð"}, {"%F1", "ñ"}, {"%F2", "ò"}, {"%F3", "ó"}, {"%F4", "ô"}, {"%F5", "õ"}, {"%F6", "ö"}, {"%F7", "÷"}, {"%F8", "ø"}, {"%F9", "ù"}, {"%FA", "ú"}, {"%FB", "û"}, {"%FC", "ü"}, {"%FD", "ý"}, {"%FE", "þ"}, {"%FF", "ÿ"}};
/*
* Struct representing the configuration file
*/
struct config {
std::string configPath = "cavecomm.conf";
std::string emailAddress = "testuser0ed6e@waifu.club";
std::string emailPassword = "Ve4m6GSjJ";
std::string emailServerAddress = "mail.cock.li";
int emailServerPort = 587;
std::string emailAddressDisplay = "Cavecomm Automated Management System";
/*
* Parses the config file and fills the struct.
*/
void readConfigFile(){
}
};
/*
* Takes String and cuts from the start-up to the length of valueName
*/
std::string extractSingleValueFromRequestBody(std::string responseBody, std::string valueName) {
return responseBody.substr(valueName.length() + 1, responseBody.length());
}
/*
* Takes string to split it into a vector based on a given delimiter
*/
@ -59,6 +36,116 @@ namespace Utilities {
return splitVector;
}
/*
* Struct representing the configuration file
*/
struct config {
std::string configPath = "cavecomm.conf";
std::string emailAddress;
std::string emailPassword;
std::string emailServerAddress;
int emailServerPort = 587;
std::string emailAddressDisplay = "Cavecomm Automated Management System";
/*
* validates existence of mandatory variables in config
* returns 0 if successful else 1
*/
int checkMandatoryVariables() {
if (emailAddress.compare("") == 0
|| emailPassword.compare("") == 0
|| emailServerAddress.compare("") == 0)
return 1;
return 0;
}
/*
* Parses the config file and fills the struct.
* returns 0 if successful else 1
*/
int readConfigFile(){
bool errorLevel = 0;
std::ifstream configFile(configPath);
std::cout << "Loading Configuration: " << configPath << std::endl;
if (configFile.good()) {
bool sanityCheckStart = true;
std::string line;
while (std::getline(configFile, line))
{
if (sanityCheckStart) {
if (line.find("#configstart#") != std::string::npos) {
sanityCheckStart = false;
continue;
}
else {
errorLevel = 1;
std::cout << "ERROR: Config file is invalid" << std::endl;
break;
}
}
else {
if (line.size() <= 1)
continue;
}
if (line.find("#configend#") != std::string::npos)
break;
if (line.at(0) == '#') {
std::cout << "COMMENT: ";
std::cout << line << std::endl;
}
else {
std::cout << "CONFIG: ";
std::vector<std::string> lineVector = Utilities::splitStringIntoVector(line, '=');
if (lineVector.size() == 2) {
std::cout << lineVector.at(0) << " - " << lineVector.at(1) << std::endl;
if (lineVector.at(0).compare("emailAddress") == 0) {
emailAddress = lineVector.at(1);
continue;
}
if (lineVector.at(0).compare("emailPassword") == 0) {
emailPassword = lineVector.at(1);
continue;
}
if (lineVector.at(0).compare("emailServerAddress") == 0) {
emailServerAddress = lineVector.at(1);
continue;
}
if (lineVector.at(0).compare("emailServerPort") == 0) {
emailServerPort = std::stoi(lineVector.at(1));
continue;
}
if (lineVector.at(0).compare("emailAddressDisplay") == 0) {
emailAddressDisplay = lineVector.at(1);
continue;
}
}
}
}
}
else {
errorLevel = 1;
}
if (errorLevel == 0)
errorLevel = checkMandatoryVariables();
return errorLevel;
}
};
/*
* Takes String and cuts from the start-up to the length of valueName
*/
std::string extractSingleValueFromRequestBody(std::string responseBody, std::string valueName) {
return responseBody.substr(valueName.length() + 1, responseBody.length());
}
/*
* replaces a string with another string within a string
*/