mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
118 lines
3.6 KiB
Plaintext
118 lines
3.6 KiB
Plaintext
<%@ page class="AdminCheckUserBackupPage" %>
|
|
<%@ page form="true" %>
|
|
<%@ page baseClass="SessionHTTPRequestHandler" %>
|
|
<%@ page ctorArg="Session*" %>
|
|
<%@ header include="HTTPInterface/SessionHTTPRequestHandler.h" %>
|
|
<%!
|
|
#include "Crypto/KeyPairEd25519.h"
|
|
#include "Crypto/Passphrase.h"
|
|
#include "SingletonManager/ConnectionManager.h"
|
|
|
|
#include "controller/UserBackup.h"
|
|
|
|
#include "Poco/Data/Binding.h"
|
|
using namespace Poco::Data::Keywords;
|
|
|
|
typedef Poco::Tuple<int, Poco::Nullable<Poco::Data::BLOB>, std::string> UserBackupTuple;
|
|
|
|
struct SListEntry
|
|
{
|
|
Poco::AutoPtr<controller::User> user;
|
|
std::vector<Poco::AutoPtr<controller::UserBackup>> backups;
|
|
};
|
|
|
|
%>
|
|
<%%
|
|
const char* pageName = "Admin Check User Backups";
|
|
auto cm = ConnectionManager::getInstance();
|
|
|
|
std::list<SListEntry> notMatchingEntrys;
|
|
|
|
auto con = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
|
|
Poco::Data::Statement select(con);
|
|
std::list<UserBackupTuple> userBackupEntrys;
|
|
select << "SELECT u.id, u.pubkey, b.passphrase FROM users as u LEFT JOIN user_backups as b on(u.id = b.user_id) order by u.id"
|
|
, into(userBackupEntrys);
|
|
|
|
size_t resultCount = 0;
|
|
try {
|
|
resultCount = select.execute();
|
|
int last_user_id = 0;
|
|
for(auto it = userBackupEntrys.begin(); it != userBackupEntrys.end(); it++) {
|
|
auto tuple = *it;
|
|
auto pubkey = tuple.get<1>();
|
|
if(pubkey.isNull()) {
|
|
continue;
|
|
}
|
|
auto passphrase = Passphrase::filter(tuple.get<2>());
|
|
auto user_id = tuple.get<0>();
|
|
KeyPairEd25519 key_pair(pubkey.value().content().data());
|
|
|
|
auto wordSource = Passphrase::detectMnemonic(passphrase);
|
|
if(!wordSource) {
|
|
addError(new Error("admin Check user backup", "invalid passphrase"), false);
|
|
addError(new ParamError("admin Check user backup", "passphrase", passphrase.data()), false);
|
|
addError(new ParamError("admin Check user backup", "user id", user_id), false);
|
|
continue;
|
|
}
|
|
auto passphrase_object = Passphrase::create(passphrase, wordSource);
|
|
auto key_pair_from_passhrase = KeyPairEd25519::create(passphrase_object);
|
|
bool matching = false;
|
|
if(key_pair_from_passhrase)
|
|
{
|
|
if(key_pair_from_passhrase->isTheSame(key_pair)) {
|
|
matching = true;
|
|
}
|
|
delete key_pair_from_passhrase;
|
|
if(user_id != last_user_id) {
|
|
last_user_id = user_id;
|
|
if(matching) continue;
|
|
} else {
|
|
auto lastEntry = notMatchingEntrys.back();
|
|
if(lastEntry.user->getModel()->getID() == user_id && matching == true) {
|
|
notMatchingEntrys.pop_back();
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
SListEntry entry;
|
|
entry.user = controller::User::create();
|
|
entry.user->load(user_id);
|
|
entry.backups = controller::UserBackup::load(user_id);
|
|
|
|
notMatchingEntrys.push_back(entry);
|
|
|
|
}
|
|
}
|
|
catch (Poco::Exception& ex) {
|
|
addError(new ParamError("adminCheckUserBackup", "mysql error", ex.displayText().data()), false);
|
|
}
|
|
|
|
|
|
|
|
%><%@ include file="include/header_old.cpsp" %>
|
|
<div class="grd_container">
|
|
<h1>Admin Check User Backup</h1>
|
|
<%= getErrorsHtml() %>
|
|
<p><b>Unmatching count: <%= notMatchingEntrys.size() %></b></p>
|
|
<table>
|
|
<thead>
|
|
<tr><th>id</th><th>Vorname</th><th>Nachname</th><th>E-Mail</th><th>backups count</tr>
|
|
</thead>
|
|
<tbody>
|
|
<% for(auto it = notMatchingEntrys.begin(); it != notMatchingEntrys.end(); it++) {
|
|
auto userModel = (*it).user->getModel();
|
|
%>
|
|
<tr>
|
|
<td><%= userModel->getID() %></td>
|
|
<td><%= userModel->getFirstName() %></td>
|
|
<td><%= userModel->getLastName() %></td>
|
|
<td><%= userModel->getEmail() %></td>
|
|
<td><%= (*it).backups.size() %></td>
|
|
</tr>
|
|
<% } %>
|
|
</tbody>
|
|
</div>
|
|
<%@ include file="include/footer.cpsp" %>
|