summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2020-10-27 13:23:01 +0100
committerSimon Rettberg2020-10-27 13:23:01 +0100
commit43965eb877ed24d94b8cfa09f948b7877bcffc24 (patch)
tree3796e1a3d59b5df91007df6ab11b84405e5ef705 /src
parentFix triggering "go back" on blocked URL (diff)
downloadslxbrowser-43965eb877ed24d94b8cfa09f948b7877bcffc24.tar.gz
slxbrowser-43965eb877ed24d94b8cfa09f948b7877bcffc24.tar.xz
slxbrowser-43965eb877ed24d94b8cfa09f948b7877bcffc24.zip
Allow blacklist and whitelist at the same time.
Whitelist takes precedence.
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp16
-rw-r--r--src/nam.cpp9
-rw-r--r--src/nam.h7
-rw-r--r--src/slxbrowser.cpp11
-rw-r--r--src/slxbrowser.h3
5 files changed, 24 insertions, 22 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 6bd0897..2213913 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -40,8 +40,8 @@ int main(int argc, char** argv)
QCommandLineOption fullscreen("fullscreen", "Run browser in full screen.");
QCommandLineOption maximized("maximized", "Maximize window on startup");
QCommandLineOption reloadInterval("reload-interval", "Reload displayed page every X seconds.", "seconds");
- QCommandLineOption whitelist("whitelist", "Path to a file of allowed URLs. Mutually exclusive with blacklist.", "file");
- QCommandLineOption blacklist("blacklist", "Path to a file of disallowed URLs. Mutually exclusive with whitelist.", "file");
+ QCommandLineOption whitelist("whitelist", "Path to a file of allowed URLs.", "file");
+ QCommandLineOption blacklist("blacklist", "Path to a file of disallowed URLs.", "file");
parser.addOption(ignoreSsl);
parser.addOption(fullscreen);
parser.addOption(maximized);
@@ -54,10 +54,6 @@ int main(int argc, char** argv)
QMessageBox::critical(nullptr, "Error", "Need one argument: file name");
return 1;
}
- if (parser.isSet(whitelist) && parser.isSet(blacklist)) {
- QMessageBox::critical(nullptr, "Error", "Need either blacklist or whitelist, not both");
- return 2;
- }
BrowserSettings settings;
settings.url = list[0];
settings.fullscreen = parser.isSet(fullscreen);
@@ -65,11 +61,11 @@ int main(int argc, char** argv)
settings.ignoreSslErrors = parser.isSet(ignoreSsl);
settings.reloadInterval = parser.value(reloadInterval).toInt();
if (parser.isSet(whitelist)) {
- settings.urlList = loadUrlList(parser.value(whitelist));
- } else if (parser.isSet(blacklist)) {
- settings.urlList = loadUrlList(parser.value(blacklist));
+ settings.whiteList = loadUrlList(parser.value(whitelist));
+ }
+ if (parser.isSet(blacklist)) {
+ settings.blackList = loadUrlList(parser.value(blacklist));
}
- settings.isWhitelist = parser.isSet(whitelist);
SlxBrowser main(settings);
main.show();
app.installEventFilter(new KeyHandler(&main));
diff --git a/src/nam.cpp b/src/nam.cpp
index 2f3fdd1..798a8e6 100644
--- a/src/nam.cpp
+++ b/src/nam.cpp
@@ -33,7 +33,14 @@ QNetworkReply* SlxNetworkAccessManager::createRequest(QNetworkAccessManager::Ope
} else if (url.host().isEmpty()) {
ok = true;
} else {
- ok = (_list.match(url.toDisplayString(QUrl::NormalizePathSegments)).hasMatch() == _isWhitelist);
+ auto str = url.toDisplayString(QUrl::NormalizePathSegments);
+ if (_white.isValid() && _white.match(str).hasMatch()) {
+ ok = true;
+ } else if (_black.isValid() && _black.match(str).hasMatch()) {
+ ok = false;
+ } else {
+ ok = true;
+ }
}
if (!ok) {
return new SlxDisabledNetworkReply(this, req, op);
diff --git a/src/nam.h b/src/nam.h
index 0036904..ec2bb17 100644
--- a/src/nam.h
+++ b/src/nam.h
@@ -12,14 +12,13 @@ class SlxNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
public:
- SlxNetworkAccessManager(QRegularExpression list, bool isWhitelist, QObject *parent = nullptr)
- : QNetworkAccessManager(parent), _list(list), _isWhitelist(isWhitelist) {}
+ SlxNetworkAccessManager(QRegularExpression blackList, QRegularExpression whiteList, QObject *parent = nullptr)
+ : QNetworkAccessManager(parent), _black(blackList), _white(whiteList) {}
protected:
QNetworkReply* createRequest(QNetworkAccessManager::Operation op,
const QNetworkRequest &originalReq, QIODevice *outgoingData = nullptr) override;
private:
- QRegularExpression _list;
- bool _isWhitelist;
+ QRegularExpression _black, _white;
};
diff --git a/src/slxbrowser.cpp b/src/slxbrowser.cpp
index c4c2067..8cc8749 100644
--- a/src/slxbrowser.cpp
+++ b/src/slxbrowser.cpp
@@ -51,14 +51,15 @@ SlxBrowser::SlxBrowser(BrowserSettings settings)
//
QWebPage *page = _browser->page();
QNetworkAccessManager *nam;
- if (_settings.urlList.isEmpty()) {
+ if (_settings.whiteList.isEmpty() && _settings.blackList.isEmpty()) {
nam = new QNetworkAccessManager(this);
} else {
- if (_settings.isWhitelist) {
- // Just to be safe
- _settings.urlList << _settings.url;
+ if (_settings.blackList.isEmpty()) {
+ _settings.blackList << "*";
}
- nam = new SlxNetworkAccessManager(urlListToRegExp(_settings.urlList), _settings.isWhitelist);
+ // Just to be safe
+ _settings.whiteList << _settings.url;
+ nam = new SlxNetworkAccessManager(urlListToRegExp(_settings.blackList), urlListToRegExp(_settings.whiteList));
}
connect(nam, &QNetworkAccessManager::sslErrors, this, &SlxBrowser::sslErrors);
connect(nam, &QNetworkAccessManager::finished, this, &SlxBrowser::requestFinished);
diff --git a/src/slxbrowser.h b/src/slxbrowser.h
index ae1356c..fd0cf06 100644
--- a/src/slxbrowser.h
+++ b/src/slxbrowser.h
@@ -18,8 +18,7 @@ struct BrowserSettings
bool maximized;
bool ignoreSslErrors;
int reloadInterval;
- bool isWhitelist;
- QStringList urlList;
+ QStringList blackList, whiteList;
};
class SlxBrowser : public QMainWindow