#include "AdminHederaAccountPage.h" #include "Poco/Net/HTTPServerRequest.h" #include "Poco/Net/HTTPServerResponse.h" #include "Poco/Net/HTMLForm.h" #include "Poco/DeflatingStream.h" #line 7 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp" #include "../controller/HederaAccount.h" #include "../controller/HederaId.h" #include "../controller/CryptoKey.h" #include "../lib/DataTypeConverter.h" #include "../SingletonManager/SessionManager.h" #include "../ServerConfig.h" #include "Poco/URI.h" #line 1 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\header_large.cpsp" #include "../ServerConfig.h" AdminHederaAccountPage::AdminHederaAccountPage(Session* arg): SessionHTTPRequestHandler(arg) { } void AdminHederaAccountPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { response.setChunkedTransferEncoding(true); response.setContentType("text/html"); bool _compressResponse(request.hasToken("Accept-Encoding", "gzip")); if (_compressResponse) response.set("Content-Encoding", "gzip"); Poco::Net::HTMLForm form(request, request.stream()); #line 20 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\adminHederaAccount.cpsp" const char* pageName = "Hedera Account"; auto sm = SessionManager::getInstance(); auto mm = MemoryManager::getInstance(); auto user = mSession->getNewUser(); Poco::URI uri(request.getURI()); auto uri_query = uri.getQueryParameters(); std::string action = ""; std::string account_id_from_query; if(uri_query.size() >= 2) { if(uri_query[0].first == "action") { action = uri_query[0].second; } if(uri_query[1].first == "account_id") { account_id_from_query = uri_query[1].second; } } if(action == "updateBalance") { int account_id = 0; if(DataTypeConverter::strToInt(account_id_from_query, account_id) != DataTypeConverter::NUMBER_PARSE_OKAY) { addError(new Error("Int Convert Error", "Error converting account_id_from_query to int")); } else { auto hedera_account = controller::HederaAccount::load("id", account_id); if(!hedera_account.size() || hedera_account[0].isNull()) { addError(new Error("Action Update Balance", "hedera id not found")); } else { hedera_account[0]->updateBalanceFromHedera(user, this); } } } // add else if(!form.empty()) { // collect auto shardNumString = form.get("account-shard-num", "0"); auto realmNumString = form.get("account-realm-num", "0"); auto numString = form.get("account-num", "0"); auto privateKeyString = form.get("account-private-key", ""); auto publicKeyString = form.get("account-public-key", ""); auto networkTypeString = form.get("account-network-type", "0"); int shardNum = 0; int realmNum = 0; int num = 0; int networkType = 0; MemoryBin* private_key = nullptr; MemoryBin* public_key = nullptr; // validate if(!sm->isValid(shardNumString, VALIDATE_ONLY_INTEGER)) { addError(new Error("Account ID", "shard num not integer")); } else { if(DataTypeConverter::strToInt(shardNumString, shardNum) != DataTypeConverter::NUMBER_PARSE_OKAY) { addError(new Error("Int Convert Error", "Error converting shardNumString to int")); } } if(!sm->isValid(realmNumString, VALIDATE_ONLY_INTEGER)) { addError(new Error("Account ID", "realm num not integer")); } else { if(DataTypeConverter::strToInt(realmNumString, realmNum) != DataTypeConverter::NUMBER_PARSE_OKAY) { addError(new Error("Int Convert Error", "Error converting realmNumString to int")); } } if(!sm->isValid(numString, VALIDATE_ONLY_INTEGER)) { addError(new Error("Account ID", "num not integer")); } else { if(DataTypeConverter::strToInt(numString, num) != DataTypeConverter::NUMBER_PARSE_OKAY) { addError(new Error("Int Convert Error", "Error converting num to int")); } } if(!sm->isValid(privateKeyString, VALIDATE_ONLY_HEX)) { addError(new Error("Account Keys", "private key not hex")); } if(!sm->isValid(publicKeyString, VALIDATE_ONLY_HEX)) { addError(new Error("Account Keys", "public key not hex")); } if(!sm->isValid(networkTypeString, VALIDATE_ONLY_INTEGER)) { addError(new Error("Network Type", "not integer")); } else { if(DataTypeConverter::strToInt(networkTypeString, networkType) != DataTypeConverter::NUMBER_PARSE_OKAY) { addError(new Error("Int Convert Error", "Error converting network type to int")); } if(networkType < 0 || networkType >= (int)model::table::HEDERA_NET_COUNT) { addError(new Error("Network Type", "invalid value")); } } if(0 == errorCount()) { auto hedera_id = controller::HederaId::create(shardNum, realmNum, num); private_key = DataTypeConverter::hexToBin(privateKeyString); public_key = DataTypeConverter::hexToBin(publicKeyString); KeyPairHedera key_pair(private_key, public_key); auto crypto_key = controller::CryptoKey::load(key_pair.getPublicKey(), ed25519_pubkey_SIZE); if(crypto_key.isNull()) { crypto_key = controller::CryptoKey::create(&key_pair, user); if(!crypto_key->getModel()->insertIntoDB(true)) { addError(new Error("DB Error", "Error saving crypto key in DB")); } } else { printf("crypto key found in db\n"); } if(0 == errorCount()) { auto hedera_account = controller::HederaAccount::create( user->getModel()->getID(), hedera_id->getModel()->getID(), crypto_key->getModel()->getID(), 0, (model::table::HederaNetworkType)networkType ); if(!hedera_account->getModel()->insertIntoDB(false)) { addError(new Error("DB Error", "Error saving hedera account into DB")); } } mm->releaseMemory(private_key); mm->releaseMemory(public_key); } } // list accounts auto hedera_accounts = controller::HederaAccount::load("user_id", user->getModel()->getID()); #line 3 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\header_large.cpsp" bool withMaterialIcons = false; std::ostream& _responseStream = response.send(); Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1); std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream; responseStream << "\n"; // begin include header_large.cpsp responseStream << "\n"; responseStream << "\n"; responseStream << "\n"; responseStream << "
\n"; responseStream << "\n"; responseStream << "\n"; responseStream << "Copyright © Gradido 2020
\n"; responseStream << "Login Server in Entwicklung
\n"; responseStream << "Alpha "; #line 10 "F:\\Gradido\\gradido_login_server\\src\\cpsp\\footer.cpsp" responseStream << ( ServerConfig::g_versionString ); responseStream << "
\n"; responseStream << "