@@ -6056,11 +6056,32 @@ void QgisApp::runScript( const QString &filePath )
6056
6056
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
6057
6057
return;
6058
6058
6059
- mPythonUtils->runString(
6060
- QString( "import sys\n"
6061
- "from qgis.utils import iface\n"
6062
- "exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read())\n" ).arg( filePath )
6063
- , tr( "Failed to run Python script:" ), false );
6059
+ QgsSettings settings;
6060
+ bool showScriptWarning = settings.value( QStringLiteral( "UI/showScriptWarning" ), true ).toBool();
6061
+
6062
+ QMessageBox msgbox;
6063
+ if ( showScriptWarning )
6064
+ {
6065
+ msgbox.setText( tr( "Security warning: executing a script from an untrusted source can lead to data loss and/or leak. Continue?" ) );
6066
+ msgbox.setIcon( QMessageBox::Icon::Warning );
6067
+ msgbox.addButton( QMessageBox::Yes );
6068
+ msgbox.addButton( QMessageBox::No );
6069
+ msgbox.setDefaultButton( QMessageBox::No );
6070
+ QCheckBox *cb = new QCheckBox( tr( "Don't show this again." ) );
6071
+ msgbox.setCheckBox( cb );
6072
+ msgbox.exec();
6073
+ settings.setValue( QStringLiteral( "UI/showScriptWarning" ), !msgbox.checkBox()->isChecked() );
6074
+ }
6075
+
6076
+ if ( !showScriptWarning || msgbox.result() == QMessageBox::Yes )
6077
+ {
6078
+ mPythonUtils->runString(
6079
+ QString( "import sys\n"
6080
+ "from qgis.utils import iface\n"
6081
+ "exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read())\n" ).arg( filePath )
6082
+ , tr( "Failed to run Python script:" ), false );
6083
+ }
6084
+
6064
6085
#else
6065
6086
Q_UNUSED( filePath );
6066
6087
#endif
0 commit comments