Merge pull request #256 from layters/backup

backup
main
layters 1 month ago committed by GitHub
commit 93c680a614
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -437,11 +437,8 @@ set(neroshop_protocol_src
set(neroshop_tools_src
${NEROSHOP_CORE_SRC_DIR}/tools/base64.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/downloader.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/extractor.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/logger.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/process.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/regex.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/process.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/script.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/timestamp.cpp
${NEROSHOP_CORE_SRC_DIR}/tools/updater.cpp
@ -482,7 +479,7 @@ endif()
# neroshop-daemon
set(daemon_executable "neromon")
set(daemon_src ${neroshop_crypto_src} ${neroshop_database_src} ${neroshop_network_src} ${NEROSHOP_CORE_SRC_DIR}/protocol/messages/msgpack.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/p2p/mapper.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/p2p/node.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/p2p/routing_table.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/rpc/json_rpc.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/transport/client.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/transport/ip_address.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/transport/server.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/transport/zmq_client.cpp ${NEROSHOP_CORE_SRC_DIR}/protocol/transport/zmq_server.cpp ${NEROSHOP_CORE_SRC_DIR}/tools/base64.cpp ${NEROSHOP_CORE_SRC_DIR}/tools/logger.cpp ${NEROSHOP_CORE_SRC_DIR}/tools/timestamp.cpp)
add_executable(${daemon_executable} src/daemon/main.cpp ${daemon_src})#target_link_libraries(daemon ${curl_src} ${OPENSSL_LIBRARIES}) # curl requires both openssl(used in monero) and zlib(used in dokun-ui)
add_executable(${daemon_executable} src/daemon/main.cpp ${daemon_src})#target_link_libraries(daemon ${curl_src} ${OPENSSL_LIBRARIES}) # curl requires both openssl(used in monero) and zlib(used in libi2pd)
install(TARGETS ${daemon_executable} DESTINATION bin)
target_compile_definitions(${daemon_executable} PRIVATE NEROSHOP_DEBUG)
target_include_directories(${daemon_executable} PRIVATE #[[${CMAKE_CURRENT_SOURCE_DIR}/src/]] ${monero_include_dirs} ${monero_cpp_include_dir} ${sqlite_include_dir} ${json_include_dir} ${zlib_include_dir} ${i2pd_include_dirs} ${cxxopts_include_dir})

@ -145,6 +145,10 @@ Page {
if(avatarImage.status === Image.Ready) {
Backend.saveAvatarImage(Backend.urlToLocalFile(avatarImage.source), account_key)
}
/*// Save lastOpenedWallet
let folder = Backend.urlToLocalFile(walletFolderDialog.folder);
settingsDialog.lastOpenedWallet = (walletNameField.text) ? qsTr(folder + "/%1.keys").arg(walletNameField.text) : qsTr(folder + "/%1.keys").arg(walletNameField.placeholderText)
settingsDialog.save()*/
// Switch to HomePage
pageStack.pushPage("qrc:/qml/pages/HomePage.qml", StackView.Immediate)//stack.push(home_page)
//console.log("Primary address: ", Wallet.getPrimaryAddress())

@ -17,7 +17,6 @@ static void print_commands() {
{"monero_nodes", "Display a list of monero nodes"},
{"query ", "Execute an SQLite query"},
{"curl_version", "Show libcurl version"},
{"download_tor", "Download Tor"},
{"send ", "Send a test message to the local daemon IPC server"}
/*,
{"", ""}*/
@ -98,12 +97,6 @@ int main(int argc, char** argv) {
"." + std::to_string(curl_version->version_num & 0xff);
std::cout << "libcurl version " << curl_version_str << std::endl;
}
else if(command == "download_tor") {
std::packaged_task<void(void)> download_task([&]() -> void {
neroshop_tools::downloader::download_tor();
});
std::thread { std::move(download_task) }.detach();
}
else if(command == "send") { // This is only a test command
#if !defined(NEROSHOP_USE_LIBZMQ)
if (client->is_connected()) {

@ -5,7 +5,8 @@
#include "settings.hpp" // neroshop::lua_state
#include "database/database.hpp"
#include "tools/logger.hpp"
#include "tools/tools.hpp" // neroshop::uuid::generate()
#include "tools/string.hpp"
#include "tools/uuid.hpp" // neroshop::uuid::generate()
#include "protocol/p2p/serializer.hpp"
#include "protocol/transport/client.hpp"
#include "tools/timestamp.hpp"

@ -18,7 +18,7 @@
#include <map>
#include "../currency_map.hpp"
#include "../../../core/tools/tools.hpp" // neroshop::string::lower
#include "../../../core/tools/string.hpp" // neroshop::string::lower
std::optional<double> CoinCodexApi::price(neroshop::Currency from, neroshop::Currency to) const
{

@ -18,7 +18,7 @@
#include <map>
#include "../currency_map.hpp"
#include "../../../core/tools/tools.hpp" // neroshop::string::lower
#include "../../../core/tools/string.hpp" // neroshop::string::lower
std::optional<double> CoinGeckoApi::price(neroshop::Currency from, neroshop::Currency to) const
{

@ -18,7 +18,7 @@
#include <map>
#include "../currency_map.hpp"
#include "../../../core/tools/tools.hpp" // neroshop::string::upper
#include "../../../core/tools/string.hpp" // neroshop::string::upper
std::optional<double> CryptoRankApi::price(neroshop::Currency from, neroshop::Currency to) const
{

@ -18,7 +18,7 @@
#include <map>
#include "../currency_map.hpp"
#include "../../../core/tools/tools.hpp" // neroshop::string::lower
#include "../../../core/tools/string.hpp" // neroshop::string::lower
std::optional<double> CryptoWatchApi::price(neroshop::Currency from, neroshop::Currency to) const
{

@ -10,7 +10,7 @@
#include "kraken/kraken.hpp"
#include "../tools/logger.hpp"
#include "../tools/tools.hpp"
#include "../tools/string.hpp"
#include "currency_map.hpp" // neroshop::CurrencyMap
//-------------------------------------------------------
//-------------------------------------------------------

@ -18,7 +18,7 @@
#include <map>
#include "../currency_map.hpp"
#include "../../../core/tools/tools.hpp" // neroshop::string::lower
#include "../../../core/tools/string.hpp" // neroshop::string::lower
std::optional<double> Fawazahmed0CurrencyApi::price(neroshop::Currency from, neroshop::Currency to) const
{

@ -18,7 +18,7 @@
#include <map>
#include "../currency_map.hpp"
#include "../../../core/tools/tools.hpp" // neroshop::string::upper
#include "../../../core/tools/string.hpp" // neroshop::string::upper
std::optional<double> KrakenApi::price(neroshop::Currency from, neroshop::Currency to) const
{

@ -2,7 +2,7 @@
#include "cart.hpp"
#include "tools/logger.hpp"
#include "tools/tools.hpp" // uuid
#include "tools/uuid.hpp"
#include "database/database.hpp"
#include "product.hpp"
#include "wallet/wallet.hpp"

@ -2,7 +2,6 @@
#include "../neroshop_config.hpp"
#include "tools/logger.hpp"
#include "tools/tools.hpp"
#if defined(NEROSHOP_USE_QT)
#include <QDir>

@ -1,106 +0,0 @@
#include "downloader.hpp"
#if defined(NEROSHOP_USE_QT)
#include <QUrl>
#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QString>
#else
#include <curl/curl.h>
/* For older cURL versions you will also need
#include <curl/types.h>
#include <curl/easy.h>
*/
#endif
#include "../../neroshop_config.hpp" // for config path
#include "extractor.hpp" // ../tools/tools.hpp included here
#include "../tools/tools.hpp"
namespace {
const std::string tor_archive_url { "https://archive.torproject.org/tor-package-archive/torbrowser" };
const std::string tor_browser_version { "12.0.4" }; // tor 0.4.7.13
const std::string tor_expert_bundle { "tor-expert-bundle-" + tor_browser_version + "-" +
neroshop::device::get_os() + "-" +
neroshop::device::get_architecture() + ".tar.gz" };
}
#if !defined(NEROSHOP_USE_QT)
size_t neroshop::tools::downloader::write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
#endif
void neroshop::tools::downloader::download_tor() {
std::string config_path = NEROSHOP_DEFAULT_CONFIGURATION_PATH;
// check if tor already exists, if so then exit function
if(neroshop::filesystem::is_file(config_path + "/" + "tor/tor")) {
std::cout << "Tor has already been installed at " << (config_path + "/" + "tor/tor") << "\n"; return;
}
std::string tor { tor_archive_url + "/" + tor_browser_version + "/" + tor_expert_bundle };
std::string save_as { config_path + "/" + tor_expert_bundle };//"tor.tar.gz" };
std::cout << "downloading " << tor << " to " << config_path << "\n\n";
#if defined(NEROSHOP_USE_QT)
QNetworkAccessManager * manager = new QNetworkAccessManager(nullptr);
QNetworkReply * reply = manager->get(QNetworkRequest(QUrl(QString::fromStdString(tor))));
QObject::connect(reply, &QNetworkReply::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal) {
qInfo() << "Download progress:" << bytesReceived << "/" << bytesTotal;
});
QFile* file = new QFile(QString::fromStdString(save_as));
if (!file->open(QIODevice::WriteOnly | QIODevice::Truncate)) {
qDebug() << "Failed to open file for writing:" << file->errorString();
delete file;
delete manager;
return;
}
// Connect to the finished signal to write the file
QObject::connect(reply, &QNetworkReply::finished, [=]() {
if (reply->error() == QNetworkReply::NoError) {
file->write(reply->readAll());
qInfo() << "Download succeeded";
} else {
qWarning() << "Download failed:" << reply->errorString();
}
file->flush();
file->close();
delete file;
reply->deleteLater();
manager->deleteLater();// or delete manager;
// Extract the file
if(!neroshop::filesystem::is_file(save_as)) { std::cout << "Error downloading tor\n"; return; }
neroshop::tools::extractor::extract_tar(save_as);
});
#else
CURL *curl;
FILE *fp;
CURLcode res;
const char * outfilename = save_as.c_str();
assert(save_as.length() <= FILENAME_MAX); // FILENAME_MAX=4096
curl = curl_easy_init();
if (curl) {
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, tor.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(fp);
}
// Extract the file
if(!neroshop::filesystem::is_file(save_as)) { std::cout << "Error downloading tor\n"; return; }
neroshop::tools::extractor::extract_tar(save_as);
#endif
}
void neroshop::tools::downloader::download_i2pd() {
// TODO: use libi2pd instead
}

@ -1,24 +0,0 @@
#pragma once
#ifndef DOWNLOADER_HPP_NEROSHOP
#define DOWNLOADER_HPP_NEROSHOP
#include <iostream>
#include <string>
namespace neroshop {
namespace tools {
struct downloader {
static void download_tor();
static void download_i2pd();
private:
#if !defined(NEROSHOP_USE_QT)
static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
#endif
};
}
}
#endif

@ -1,54 +0,0 @@
#include "extractor.hpp"
#include "../tools/tools.hpp" // neroshop::filesystem::
#if defined(NEROSHOP_USE_QT)
#include <QDebug>
#include <QProcess>
#include <QString>
#else
#include <cstdlib> // std::system
#include <cstdio> // std::remove, FILE
#endif
#include <cassert> // assert
void neroshop::tools::extractor::extract_tar(const std::string& filename) {
std::cout << "extracting " << "tor/ from " << filename << "\n";
std::string folder = filename.substr(0, filename.find_last_of("\\/")); // get path from filename
assert(neroshop::filesystem::is_directory(folder));
#if defined(NEROSHOP_USE_QT)
QString fileName = QString::fromStdString(filename);
QString extractDir = QString::fromStdString(folder);
QString wildcards = "tor/*";
QProcess process;
process.setProgram("tar");
QStringList arguments;
arguments << "-xzf" << fileName << "-C" << extractDir << "--wildcards" << wildcards;
process.setArguments(arguments);
process.start();
process.waitForFinished();
if(process.exitCode() != 0) {
qDebug() << process.readAllStandardError();
}
#elif defined(__gnu_linux__) && !defined(NEROSHOP_USE_QT)
std::system(std::string("tar -xzf " + filename + " -C " + folder + " --wildcards tor/*").c_str());
#endif
// Check if tor/tor file was extracted or not
std::string out_file { folder + "/" + "tor/tor" };
if(!neroshop::filesystem::is_file(out_file)) {
std::cout << "Error extracting tar\n"; return;// or try a different method?
}
std::cout << "Extraction completed!\n";
std::remove(filename.c_str()); // Delete the tar.gz file after we're done extracting
}
void neroshop::tools::extractor::extract_zip(const std::string& filename) {
}

@ -1,17 +0,0 @@
#pragma once
#include <iostream>
#include <string>
namespace neroshop {
namespace tools {
namespace extractor {
void extract_tar(const std::string& filename);
void extract_zip(const std::string& filename);
}
}
}

@ -14,7 +14,8 @@
#include <fstream>
#include "logger.hpp"
#include "tools.hpp" // neroshop::filesystem
#include "filesystem.hpp" // neroshop::filesystem
#include "string.hpp"
neroshop::Process::Process()
{

@ -1,105 +0,0 @@
#include "regex.hpp"
#include "../tools/logger.hpp" // neroshop::print
bool neroshop::string_tools::is_email(const std::string& email) {
const std::regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
return std::regex_match(email, pattern);
}
bool neroshop::string_tools::is_strong_password(const std::string& password) {
// Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character:
const std::regex pattern("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"); // source: https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a
return std::regex_match(password, pattern);
}
/**
The username must begin with a letter (uppercase or lowercase), represented by [a-zA-Z].
The username can contain any combination of letters (uppercase or lowercase), numbers, period . , underscore _ or hyphen -, represented by [a-zA-Z0-9._-].
The username must be between 2 and 30 characters long, which is enforced by {0,28} in the regex. The total length includes the starting and ending letter, hence 0 to 28 characters are allowed between them.
The username must end with a letter or number, which is enforced by [a-zA-Z0-9]$.
**/
bool neroshop::string_tools::is_valid_username(const std::string& username) {
const std::regex pattern("^[a-zA-Z][a-zA-Z0-9._-]{0,28}[a-zA-Z0-9]$");
return std::regex_match(username, pattern);
}
// untested
bool is_product_code(const std::string& code) {
// Define regular expressions for each product code type
std::regex upc("^\\d{12}$");
std::regex ean("^\\d{13}$");
std::regex jan("^49\\d{10}$");
std::regex isbn("^(\\d{9}(\\d|X)|978\\d{10}|979\\d{10})$"); // validates both ISBN-10 and ISBN-13 codes
std::regex issn("^\\d{8}$");
std::regex gtin("^\\d{8,14}$");
std::regex sku("^\\w+$"); // Assumes SKU can contain alphanumeric characters
std::regex mpn("^\\w+$"); // Assumes MPN can contain alphanumeric characters
std::regex ndc("^\\d{10}$");
// Check if the code matches any of the regular expressions
return std::regex_match(code, upc) || std::regex_match(code, ean) || std::regex_match(code, isbn) ||
std::regex_match(code, issn) || std::regex_match(code, gtin) || std::regex_match(code, sku) ||
std::regex_match(code, mpn) || std::regex_match(code, ndc);
}
/*int main() {
std::string email = "mail@neroshop.org";
if(!neroshop::string_tools::is_email(email)) {
neroshop::print("Email address is not valid", 1);
return 1;
}
std::string password = "supersecretpassword123";
if(!neroshop::string_tools::is_strong_password(password))
{
// Figure out the specific reason why password failed to follow the regex rules //if(password.empty()) { std::cout << "Please enter a valid password" << std::endl; return false; }
if(!std::regex_search(password.c_str(), std::regex("(?=.*?[A-Z])"))) {
neroshop::print("Password must have at least one upper case letter", 1);
}
if(!std::regex_search(password.c_str(), std::regex("(?=.*?[a-z])"))) {
neroshop::print("Password must have at least one lower case letter", 1);
}
if(!std::regex_search(password.c_str(), std::regex("(?=.*?[0-9])"))) {
neroshop::print("Password must have at least one digit", 1);
}
if(!std::regex_search(password.c_str(), std::regex("(?=.*?[#?!@$%^&*-])"))) {
neroshop::print("Password must have at least one special character", 1);
}
if(password.length() < 8) {
neroshop::print("Password must be at least 8 characters long", 1);
}
////neroshop::print("Please enter a stronger password (at least 1 upper case letter, 1 lower case letter, 1 digit, and 1 special character)", 1);
////return 1;
}
std::string username = "Jack_ass-wipe.dude";//"k_u_n";
if(!neroshop::string_tools::is_valid_username(username)) {
neroshop::print("Invalid username: " + username, 1);
if (username.length() < 2) {
std::cout << "must be at least 2 characters in length\n";
}
if (username.length() > 30) {
std::cout << "cannot exceed 30 characters in length\n";
}
if (std::regex_search(username, std::regex("\\s"))) {
std::cout << "cannot contain spaces\n";
}
if (!std::regex_search(username, std::regex("^[a-zA-Z]"))) {
std::cout << "must begin with a letter (cannot start with a symbol or number)\n";
}
if (!std::regex_search(username, std::regex("[a-zA-Z0-9]$"))) {
std::cout << "must end with a letter or number (cannot end with a symbol)\n";
}
if (std::regex_search(username, std::regex("[^a-zA-Z0-9._-]"))) {
std::cout << "contains invalid symbol(s) (only '.', '_', and '-' are allowed in between the username)\n";
}
if (username == "Guest") {
std::cout << "name \"Guest\" is reserved for guests only and cannot be used by any other user\n";
}
////return 1;
}
return 0;
} // g++ regex.cpp logger.cpp -std=c++17 -I.
*/

@ -1,18 +0,0 @@
#pragma once
#include <iostream>
#include <regex>
#include <string>
namespace neroshop {
namespace string_tools {
bool is_email(const std::string& email);
bool is_strong_password(const std::string& password);
bool is_valid_username(const std::string& username);
bool is_product_code(const std::string& code);
}
}

@ -8,9 +8,53 @@
#include <sstream> // std::ostringstream
#include <algorithm> // std::transform, std::remove
#include <cctype> // std::tolower
#include <regex>
namespace neroshop {
namespace string_tools {
static bool is_email(const std::string& email) {
const std::regex pattern("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+");
return std::regex_match(email, pattern);
}
static bool is_strong_password(const std::string& password) {
// Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character:
const std::regex pattern("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"); // source: https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a
return std::regex_match(password, pattern);
}
/**
The username must begin with a letter (uppercase or lowercase), represented by [a-zA-Z].
The username can contain any combination of letters (uppercase or lowercase), numbers, period . , underscore _ or hyphen -, represented by [a-zA-Z0-9._-].
The username must be between 2 and 30 characters long, which is enforced by {0,28} in the regex. The total length includes the starting and ending letter, hence 0 to 28 characters are allowed between them.
The username must end with a letter or number, which is enforced by [a-zA-Z0-9]$.
**/
static bool is_valid_username(const std::string& username) {
const std::regex pattern("^[a-zA-Z][a-zA-Z0-9._-]{0,28}[a-zA-Z0-9]$");
return std::regex_match(username, pattern);
}
// untested
static bool is_product_code(const std::string& code) {
// Define regular expressions for each product code type
std::regex upc("^\\d{12}$");
std::regex ean("^\\d{13}$");
std::regex jan("^49\\d{10}$");
std::regex isbn("^(\\d{9}(\\d|X)|978\\d{10}|979\\d{10})$"); // validates both ISBN-10 and ISBN-13 codes
std::regex issn("^\\d{8}$");
std::regex gtin("^\\d{8,14}$");
std::regex sku("^\\w+$"); // Assumes SKU can contain alphanumeric characters
std::regex mpn("^\\w+$"); // Assumes MPN can contain alphanumeric characters
std::regex ndc("^\\d{10}$");
// Check if the code matches any of the regular expressions
return std::regex_match(code, upc) || std::regex_match(code, ean) || std::regex_match(code, isbn) ||
std::regex_match(code, issn) || std::regex_match(code, gtin) || std::regex_match(code, sku) ||
std::regex_match(code, mpn) || std::regex_match(code, ndc);
}
}
namespace string {
static std::string lower(const std::string& str)
{

@ -1,11 +0,0 @@
#pragma once
#ifndef TOOLS_HPP_NEROSHOP
#define TOOLS_HPP_NEROSHOP
#include "device.hpp"
#include "filesystem.hpp"
#include "string.hpp"
#include "uuid.hpp"
#endif

@ -1,7 +1,7 @@
#include "wallet.hpp"
#include "../tools/logger.hpp"
#include "../tools/tools.hpp"
#include "../tools/string.hpp"
#include "../tools/process.hpp" // for monerod daemon process
#include <cmath>

@ -35,11 +35,11 @@
#include "../core/tools/script.hpp"
#include "../core/settings.hpp"
#include "script_manager.hpp" // neroshop::Script::get_table_string
#include "../core/tools/tools.hpp"
#include "../core/tools/filesystem.hpp"
#include "../core/tools/logger.hpp"
#include "../core/tools/process.hpp"
#include "../core/category.hpp"
#include "../core/tools/regex.hpp"
#include "../core/tools/string.hpp"
#include "../core/crypto/rsa.hpp"
#include "enum_wrapper.hpp"

@ -44,16 +44,12 @@
// tools (utilities)
#include "core/tools/base64.hpp"
#include "core/tools/device.hpp"
#include "core/tools/downloader.hpp"
#include "core/tools/extractor.hpp"
#include "core/tools/filesystem.hpp"
#include "core/tools/logger.hpp"
#include "core/tools/process.hpp"
#include "core/tools/regex.hpp"
#include "core/tools/script.hpp"
#include "core/tools/string.hpp"
#include "core/tools/timestamp.hpp"
#include "core/tools/tools.hpp"
#include "core/tools/updater.hpp"
#include "core/tools/uuid.hpp"
// wallet

Loading…
Cancel
Save