keepassxc

Форк
0
/
BrowserEntryConfig.cpp 
112 строк · 2.8 Кб
1
/*
2
 *  Copyright (C) 2013 Francois Ferrand
3
 *  Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation, either version 3 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
#include "BrowserEntryConfig.h"
20

21
#include "core/Entry.h"
22
#include "core/Tools.h"
23

24
#include <QJsonDocument>
25
#include <QJsonObject>
26
#include <QVariant>
27

28
static const char KEEPASSXCBROWSER_NAME[] = "KeePassXC-Browser Settings";
29

30
BrowserEntryConfig::BrowserEntryConfig(QObject* parent)
31
    : QObject(parent)
32
{
33
}
34

35
QStringList BrowserEntryConfig::allowedHosts() const
36
{
37
    return m_allowedHosts.toList();
38
}
39

40
void BrowserEntryConfig::setAllowedHosts(const QStringList& allowedHosts)
41
{
42
    m_allowedHosts = allowedHosts.toSet();
43
}
44

45
QStringList BrowserEntryConfig::deniedHosts() const
46
{
47
    return m_deniedHosts.toList();
48
}
49

50
void BrowserEntryConfig::setDeniedHosts(const QStringList& deniedHosts)
51
{
52
    m_deniedHosts = deniedHosts.toSet();
53
}
54

55
bool BrowserEntryConfig::isAllowed(const QString& host) const
56
{
57
    return m_allowedHosts.contains(host);
58
}
59

60
void BrowserEntryConfig::allow(const QString& host)
61
{
62
    m_allowedHosts.insert(host);
63
    m_deniedHosts.remove(host);
64
}
65

66
bool BrowserEntryConfig::isDenied(const QString& host) const
67
{
68
    return m_deniedHosts.contains(host);
69
}
70

71
void BrowserEntryConfig::deny(const QString& host)
72
{
73
    m_deniedHosts.insert(host);
74
    m_allowedHosts.remove(host);
75
}
76

77
QString BrowserEntryConfig::realm() const
78
{
79
    return m_realm;
80
}
81

82
void BrowserEntryConfig::setRealm(const QString& realm)
83
{
84
    m_realm = realm;
85
}
86

87
bool BrowserEntryConfig::load(const Entry* entry)
88
{
89
    QString s = entry->customData()->value(KEEPASSXCBROWSER_NAME);
90
    if (s.isEmpty()) {
91
        return false;
92
    }
93

94
    QJsonDocument doc = QJsonDocument::fromJson(s.toUtf8());
95
    if (doc.isNull()) {
96
        return false;
97
    }
98

99
    QVariantMap map = doc.object().toVariantMap();
100
    for (QVariantMap::const_iterator iter = map.cbegin(); iter != map.cend(); ++iter) {
101
        setProperty(iter.key().toLatin1(), iter.value());
102
    }
103
    return true;
104
}
105

106
void BrowserEntryConfig::save(Entry* entry)
107
{
108
    QVariantMap v = Tools::qo2qvm(this);
109
    QJsonObject o = QJsonObject::fromVariantMap(v);
110
    QByteArray json = QJsonDocument(o).toJson(QJsonDocument::Compact);
111
    entry->customData()->set(KEEPASSXCBROWSER_NAME, json);
112
}
113

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.