Add option for restricting non-printer connections

This commit is contained in:
Anton Thomasson 2022-05-15 21:21:32 +02:00
parent f30f40683e
commit b4aaa85a2d
12 changed files with 98 additions and 4 deletions

View file

@ -160,5 +160,12 @@ ApplicationWindow
defaultValue: SeaPrintSettings.debugLogDefault defaultValue: SeaPrintSettings.debugLogDefault
} }
ConfigurationValue
{
id: allowExternalConnectionsSetting
key: SeaPrintSettings.allowExternalConnectionsPath
defaultValue: SeaPrintSettings.allowExternalConnectionsDefault
}
} }

View file

@ -62,6 +62,14 @@ Page {
} }
} }
TextSwitch {
text: qsTr("Allow external connections")
description: qsTr("Allow SeaPrint to fetch recources like icons and option name dictionaries from addresses that are not the printer itself. Some printer makers store icons on their website as opposed to locally on the printer.")
checked: allowExternalConnectionsSetting.value
onCheckedChanged: {
allowExternalConnectionsSetting.value = checked
}
}
} }
} }
} }

View file

@ -126,8 +126,11 @@ void IppPrinter::MaybeGetStrings()
if(_attrs.contains("printer-strings-uri") && _strings.empty()) if(_attrs.contains("printer-strings-uri") && _strings.empty())
{ {
QUrl url(_attrs["printer-strings-uri"].toObject()["value"].toString()); QUrl url(_attrs["printer-strings-uri"].toObject()["value"].toString());
IppDiscovery::instance()->resolve(url); if(isAllowedAddress(url))
emit doGetStrings(url); {
IppDiscovery::instance()->resolve(url);
emit doGetStrings(url);
}
} }
} }
@ -157,7 +160,7 @@ void IppPrinter::MaybeGetIcon(bool retry)
} }
} }
if(!url.isEmpty()) if(isAllowedAddress(url))
{ {
IppDiscovery::instance()->resolve(url); IppDiscovery::instance()->resolve(url);
emit doGetImage(url); emit doGetImage(url);
@ -821,6 +824,13 @@ void IppPrinter::setProgress(qint64 sent, qint64 total)
emit progressChanged(); emit progressChanged();
} }
bool IppPrinter::isAllowedAddress(QUrl url)
{
bool allowed = ((url.host() == _url.host()) || Settings::instance()->allowExternalConnections());
qDebug() << url << " is allowed: " << allowed;
return allowed;
}
QJsonValue IppPrinter::getAttrOrDefault(QJsonObject jobAttrs, QString name, QString subkey) QJsonValue IppPrinter::getAttrOrDefault(QJsonObject jobAttrs, QString name, QString subkey)
{ {
if(subkey == "") if(subkey == "")

View file

@ -106,6 +106,8 @@ private:
void setBusyMessage(QString msg); void setBusyMessage(QString msg);
void setProgress(qint64 sent, qint64 total); void setProgress(qint64 sent, qint64 total);
bool isAllowedAddress(QUrl addr);
QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name, QString subkey = ""); QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name, QString subkey = "");
IppMsg mk_msg(QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject()); IppMsg mk_msg(QJsonObject opAttrs, QJsonObject jobAttrs=QJsonObject());

View file

@ -3,7 +3,8 @@
Settings::Settings() : _ignoreSslErrorsSetting("/apps/harbour-seaprint/settings/ignore-ssl-errors", this), Settings::Settings() : _ignoreSslErrorsSetting("/apps/harbour-seaprint/settings/ignore-ssl-errors", this),
_debugLogSetting("/apps/harbour-seaprint/settings/debug-log", this) _debugLogSetting("/apps/harbour-seaprint/settings/debug-log", this),
_allowExternalConnectionsSetting("/apps/harbour-seaprint/settings/allow-external-connections", this)
{ {
} }
@ -48,3 +49,13 @@ QString Settings::debugLogPath()
{ {
return _debugLogSetting.key(); return _debugLogSetting.key();
} }
bool Settings::allowExternalConnections()
{
return _allowExternalConnectionsSetting.value(_allowExternalConnectionsDefault).toBool();
}
QString Settings::allowExternalConnectionsPath()
{
return _allowExternalConnectionsSetting.key();
}

View file

@ -10,14 +10,19 @@ public:
Q_PROPERTY(QString ignoreSslErrorsPath READ ignoreSslErrorsPath CONSTANT) Q_PROPERTY(QString ignoreSslErrorsPath READ ignoreSslErrorsPath CONSTANT)
Q_PROPERTY(bool ignoreSslErrorsDefault MEMBER _ignoreSslErrorsDefault CONSTANT) Q_PROPERTY(bool ignoreSslErrorsDefault MEMBER _ignoreSslErrorsDefault CONSTANT)
Q_PROPERTY(QString debugLogPath READ debugLogPath CONSTANT) Q_PROPERTY(QString debugLogPath READ debugLogPath CONSTANT)
Q_PROPERTY(bool debugLogDefault MEMBER _debugLogDefault CONSTANT) Q_PROPERTY(bool debugLogDefault MEMBER _debugLogDefault CONSTANT)
Q_PROPERTY(QString allowExternalConnectionsPath READ allowExternalConnectionsPath CONSTANT)
Q_PROPERTY(bool allowExternalConnectionsDefault MEMBER _allowExternalConnectionsDefault CONSTANT)
public: public:
static Settings* instance(); static Settings* instance();
bool ignoreSslErrors(); bool ignoreSslErrors();
bool debugLog(); bool debugLog();
bool allowExternalConnections();
private: private:
Settings(); Settings();
@ -29,12 +34,15 @@ private:
MGConfItem _ignoreSslErrorsSetting; MGConfItem _ignoreSslErrorsSetting;
MGConfItem _debugLogSetting; MGConfItem _debugLogSetting;
MGConfItem _allowExternalConnectionsSetting;
QString ignoreSslErrorsPath(); QString ignoreSslErrorsPath();
QString debugLogPath(); QString debugLogPath();
QString allowExternalConnectionsPath();
bool _ignoreSslErrorsDefault = true; bool _ignoreSslErrorsDefault = true;
bool _debugLogDefault = false; bool _debugLogDefault = false;
bool _allowExternalConnectionsDefault = false;
}; };

View file

@ -569,6 +569,14 @@ auf diesem Drucker</translation>
<source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source> <source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source>
<translation>Druckt das Debug-Protokoll in die Konsole (falls von hier ausgeführt) oder journal wenn normal gestartet wurde. Wird erst nach einem Neustart der App wirksam.</translation> <translation>Druckt das Debug-Protokoll in die Konsole (falls von hier ausgeführt) oder journal wenn normal gestartet wurde. Wird erst nach einem Neustart der App wirksam.</translation>
</message> </message>
<message>
<source>Allow external connections</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow SeaPrint to fetch recources like icons and option name dictionaries from addresses that are not the printer itself. Some printer makers store icons on their website as opposed to locally on the printer.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SupplyItem</name> <name>SupplyItem</name>

View file

@ -568,6 +568,14 @@
<source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source> <source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Allow external connections</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow SeaPrint to fetch recources like icons and option name dictionaries from addresses that are not the printer itself. Some printer makers store icons on their website as opposed to locally on the printer.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SupplyItem</name> <name>SupplyItem</name>

View file

@ -569,6 +569,14 @@ sur cette imprimante</translation>
<source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source> <source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source>
<translation>Afficher les messages du journal de débogage vers le terminal (si exécuté à partir de ) ou dans le journal si exécuté normalement. Nécessite de (re)démarrer l&apos;application.</translation> <translation>Afficher les messages du journal de débogage vers le terminal (si exécuté à partir de ) ou dans le journal si exécuté normalement. Nécessite de (re)démarrer l&apos;application.</translation>
</message> </message>
<message>
<source>Allow external connections</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow SeaPrint to fetch recources like icons and option name dictionaries from addresses that are not the printer itself. Some printer makers store icons on their website as opposed to locally on the printer.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SupplyItem</name> <name>SupplyItem</name>

View file

@ -568,6 +568,14 @@
<source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source> <source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Allow external connections</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow SeaPrint to fetch recources like icons and option name dictionaries from addresses that are not the printer itself. Some printer makers store icons on their website as opposed to locally on the printer.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SupplyItem</name> <name>SupplyItem</name>

View file

@ -568,6 +568,14 @@
<source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source> <source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Allow external connections</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow SeaPrint to fetch recources like icons and option name dictionaries from addresses that are not the printer itself. Some printer makers store icons on their website as opposed to locally on the printer.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SupplyItem</name> <name>SupplyItem</name>

View file

@ -568,6 +568,14 @@
<source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source> <source>Print debug log messages to console (if launched from there) or journal if launched normally. Takes effect on app (re-)start.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Allow external connections</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow SeaPrint to fetch recources like icons and option name dictionaries from addresses that are not the printer itself. Some printer makers store icons on their website as opposed to locally on the printer.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>SupplyItem</name> <name>SupplyItem</name>