Fixed mail
This commit is contained in:
		@@ -38,20 +38,6 @@ std::string create_totp_qrcode(const db::User& user, const std::string& b32_secr
 | 
			
		||||
 | 
			
		||||
    lodepng::encode(secret, image, row_size, row_size, LCT_GREY, 8);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    png::image<png::gray_pixel> image(mod_count*qrcode_pixel_size, mod_count*qrcode_pixel_size);
 | 
			
		||||
    for (int x = 0; x < mod_count; x++) for (int y = 0; y < mod_count; y++) {
 | 
			
		||||
        const bool mod = code.getModule(x, y);
 | 
			
		||||
        const int x_img_start = x * qrcode_pixel_size, y_img_start = y * qrcode_pixel_size;
 | 
			
		||||
        for (int x_img = x_img_start; x_img < x_img_start + qrcode_pixel_size; x_img++) for (int y_img = y_img_start; y_img < y_img_start + qrcode_pixel_size; y_img++)
 | 
			
		||||
            image[x_img][y_img] = mod ? 0 : 0xff;
 | 
			
		||||
    }
 | 
			
		||||
    std::stringstream image_ss;
 | 
			
		||||
    image.write_stream(image_ss);
 | 
			
		||||
 | 
			
		||||
    std::string image_str = image_ss.str();
 | 
			
		||||
    std::vector<uint8_t> secret(image_str.data(), image_str.data()+image_str.size());
 | 
			
		||||
*/
 | 
			
		||||
    return "data:image/png;base64," + Botan::base64_encode(secret);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,16 +17,12 @@
 | 
			
		||||
 | 
			
		||||
#include <jwt-cpp/traits/kazuho-picojson/traits.h>
 | 
			
		||||
#include <jwt-cpp/jwt.h>
 | 
			
		||||
#include <curl/curl.h>
 | 
			
		||||
#include <mailio/smtp.hpp>
 | 
			
		||||
 | 
			
		||||
#include "controllers/controllers.h"
 | 
			
		||||
#include "db/db.h"
 | 
			
		||||
#include "dto/dto.h"
 | 
			
		||||
 | 
			
		||||
size_t payload_source(char* ptr, size_t size, size_t nmemb, void* userp) {
 | 
			
		||||
    auto* ss = (std::stringstream*)userp;
 | 
			
		||||
    return ss->readsome(ptr, (long)(size*nmemb));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace api {
 | 
			
		||||
#if defined(BOTAN_HAS_SYSTEM_RNG)
 | 
			
		||||
@@ -42,33 +38,20 @@ namespace api {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void auth::send_mail(const db::User& user) {
 | 
			
		||||
        std::stringstream ss;
 | 
			
		||||
        std::time_t t = std::time(nullptr);
 | 
			
		||||
        const auto& totp_secret = (const std::vector<uint8_t>&) user.getValueOfTfaSecret();
 | 
			
		||||
        char totp[16];
 | 
			
		||||
        std::snprintf(totp, 16, "%06d", Botan::TOTP(Botan::OctetString(totp_secret)).generate_totp(t));
 | 
			
		||||
        ss.imbue(std::locale("en_US.utf8"));
 | 
			
		||||
        ss << "Date: " << std::put_time(std::localtime(&t), "%a, %d %b %Y %T %z") << "\r\n";
 | 
			
		||||
        ss << "To: " << user.getValueOfName() << "\r\n";
 | 
			
		||||
        ss << "From: fileserver@mattv.de\r\n";
 | 
			
		||||
        ss << "Message-ID: " << Botan::UUID(*rng).to_string() << "@mattv.de>\r\n";
 | 
			
		||||
        ss << "Subject: Fileserver - EMail 2fa code\r\n";
 | 
			
		||||
        ss << "Your code is: " << totp << "\r\n";
 | 
			
		||||
        ss << "It is valid for 5 Minutes\r\n";
 | 
			
		||||
 | 
			
		||||
        CURL* curl = curl_easy_init();
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_USERNAME, "no-reply@mattv.de");
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "noreplyLONGPASS123");
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.mattv.de:587");
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
 | 
			
		||||
        auto recp = curl_slist_append(nullptr, user.getValueOfName().c_str());
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recp);
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, &payload_source);
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_READDATA, &ss);
 | 
			
		||||
        curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
 | 
			
		||||
        curl_easy_perform(curl);
 | 
			
		||||
        curl_slist_free_all(recp);
 | 
			
		||||
        curl_easy_cleanup(curl);
 | 
			
		||||
        mailio::message msg;
 | 
			
		||||
        msg.from(mailio::mail_address("Fileserver", "fileserver@mattv.de"));
 | 
			
		||||
        msg.add_recipient(mailio::mail_address(user.getValueOfName(), user.getValueOfName()));
 | 
			
		||||
        msg.subject("Subject: Fileserver - Email 2fa code");
 | 
			
		||||
        msg.content("Your code is: " + std::string(totp) +"\r\nIt is valid for 5 Minutes");
 | 
			
		||||
 | 
			
		||||
        mailio::smtps conn("mail.mattv.de", 587);
 | 
			
		||||
        conn.authenticate("no-reply@mattv.de", "noreplyLONGPASS123", mailio::smtps::auth_method_t::START_TLS);
 | 
			
		||||
        conn.submit(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::string auth::get_token(const db::User& user) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,6 @@
 | 
			
		||||
#include <fstream>
 | 
			
		||||
 | 
			
		||||
#include <drogon/drogon.h>
 | 
			
		||||
#include <curl/curl.h>
 | 
			
		||||
 | 
			
		||||
#include "dto/dto.h"
 | 
			
		||||
 | 
			
		||||
@@ -38,9 +37,6 @@ int main(int argc, char* argv[]) {
 | 
			
		||||
    if (std::find(args.begin(), args.end(), "--dev") != args.end()) dev_mode = true;
 | 
			
		||||
    if (dev_mode) std::cout << "Starting in development mode" << std::endl;
 | 
			
		||||
    std::cout << "Setting up..." << std::endl;
 | 
			
		||||
    std::cout << "Initializing curl..." << std::flush;
 | 
			
		||||
    curl_global_init(CURL_GLOBAL_ALL);
 | 
			
		||||
    std::cout << " [Done]" << std::endl;
 | 
			
		||||
    if (!std::filesystem::exists("files")) {
 | 
			
		||||
        std::cout << "Creating files..." << std::flush;
 | 
			
		||||
        std::filesystem::create_directory("files");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user