mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
make SSL mode of PostgreSQL connections configuable
git-svn-id: http://svn.osgeo.org/qgis/trunk@10456 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
e1d952749b
commit
1e64ed34c6
@ -12,6 +12,7 @@ class QgsDataSourceURI
|
|||||||
%End
|
%End
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
|
||||||
|
|
||||||
//! default constructor
|
//! default constructor
|
||||||
QgsDataSourceURI();
|
QgsDataSourceURI();
|
||||||
@ -33,7 +34,8 @@ public:
|
|||||||
const QString& aPort,
|
const QString& aPort,
|
||||||
const QString& aDatabase,
|
const QString& aDatabase,
|
||||||
const QString& aUsername,
|
const QString& aUsername,
|
||||||
const QString& aPassword);
|
const QString& aPassword,
|
||||||
|
SSLmode sslmode );
|
||||||
|
|
||||||
//! Set all data source related members at once
|
//! Set all data source related members at once
|
||||||
void setDataSource(const QString& aSchema,
|
void setDataSource(const QString& aSchema,
|
||||||
|
@ -240,6 +240,7 @@ void QgsDbSourceSelect::deleteConnection()
|
|||||||
settings.remove( key + "/username" );
|
settings.remove( key + "/username" );
|
||||||
settings.remove( key + "/password" );
|
settings.remove( key + "/password" );
|
||||||
settings.remove( key + "/port" );
|
settings.remove( key + "/port" );
|
||||||
|
settings.remove( key + "/sslmode" );
|
||||||
settings.remove( key + "/save" );
|
settings.remove( key + "/save" );
|
||||||
settings.remove( key );
|
settings.remove( key );
|
||||||
//if(!success){
|
//if(!success){
|
||||||
@ -373,7 +374,10 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
|
|||||||
settings.value( key + "/port" ).toString(),
|
settings.value( key + "/port" ).toString(),
|
||||||
database,
|
database,
|
||||||
settings.value( key + "/username" ).toString(),
|
settings.value( key + "/username" ).toString(),
|
||||||
password );
|
password,
|
||||||
|
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
|
bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
|
||||||
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
|
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
|
||||||
@ -410,7 +414,8 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
|
|||||||
settings.value( key + "/port" ).toString(),
|
settings.value( key + "/port" ).toString(),
|
||||||
database,
|
database,
|
||||||
settings.value( key + "/username" ).toString(),
|
settings.value( key + "/username" ).toString(),
|
||||||
password );
|
password,
|
||||||
|
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
|
||||||
|
|
||||||
m_connectionInfo = uri.connectionInfo();
|
m_connectionInfo = uri.connectionInfo();
|
||||||
PQfinish( pd );
|
PQfinish( pd );
|
||||||
|
@ -61,6 +61,12 @@ QgsNewConnection::QgsNewConnection( QWidget *parent, const QString& connName, Qt
|
|||||||
// Ensure that cb_plublicSchemaOnly is set correctly
|
// Ensure that cb_plublicSchemaOnly is set correctly
|
||||||
on_cb_geometryColumnsOnly_clicked();
|
on_cb_geometryColumnsOnly_clicked();
|
||||||
|
|
||||||
|
cbxSSLmode->insertItem( QgsDataSourceURI::SSLprefer, tr("prefer") );
|
||||||
|
cbxSSLmode->insertItem( QgsDataSourceURI::SSLrequire, tr("require") );
|
||||||
|
cbxSSLmode->insertItem( QgsDataSourceURI::SSLallow, tr("allow") );
|
||||||
|
cbxSSLmode->insertItem( QgsDataSourceURI::SSLdisable, tr("disable") );
|
||||||
|
cbxSSLmode->setCurrentIndex( settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
|
||||||
|
|
||||||
if ( settings.value( key + "/save" ).toString() == "true" )
|
if ( settings.value( key + "/save" ).toString() == "true" )
|
||||||
{
|
{
|
||||||
txtPassword->setText( settings.value( key + "/password" ).toString() );
|
txtPassword->setText( settings.value( key + "/password" ).toString() );
|
||||||
@ -108,7 +114,7 @@ QgsNewConnection::~QgsNewConnection()
|
|||||||
void QgsNewConnection::testConnection()
|
void QgsNewConnection::testConnection()
|
||||||
{
|
{
|
||||||
QgsDataSourceURI uri;
|
QgsDataSourceURI uri;
|
||||||
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
|
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text(), (QgsDataSourceURI::SSLmode) cbxSSLmode->currentIndex() );
|
||||||
|
|
||||||
QgsLogger::debug( "PQconnectdb(" + uri.connectionInfo() + ");" );
|
QgsLogger::debug( "PQconnectdb(" + uri.connectionInfo() + ");" );
|
||||||
|
|
||||||
@ -142,6 +148,7 @@ void QgsNewConnection::saveConnection()
|
|||||||
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
|
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
|
||||||
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
|
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
|
||||||
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
|
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
|
||||||
|
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
|
||||||
QgsDataSourceURI::QgsDataSourceURI()
|
QgsDataSourceURI::QgsDataSourceURI() : mSSLmode(SSLprefer)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsDataSourceURI::QgsDataSourceURI( QString uri )
|
QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode(SSLprefer)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ( i < uri.length() )
|
while ( i < uri.length() )
|
||||||
@ -146,7 +146,21 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
|
|||||||
}
|
}
|
||||||
else if ( pname == "sslmode" )
|
else if ( pname == "sslmode" )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "sslmode ignored" );
|
if( pval == "disable" )
|
||||||
|
mSSLmode = SSLdisable;
|
||||||
|
else if( pval == "allow" )
|
||||||
|
mSSLmode = SSLallow;
|
||||||
|
else if( pval == "prefer" )
|
||||||
|
mSSLmode = SSLprefer;
|
||||||
|
else if( pval == "require" )
|
||||||
|
mSSLmode = SSLrequire;
|
||||||
|
}
|
||||||
|
else if ( pname == "requiressl" )
|
||||||
|
{
|
||||||
|
if( pval == "0" )
|
||||||
|
mSSLmode = SSLdisable;
|
||||||
|
else
|
||||||
|
mSSLmode = SSLprefer;
|
||||||
}
|
}
|
||||||
else if ( pname == "krbsrvname" )
|
else if ( pname == "krbsrvname" )
|
||||||
{
|
{
|
||||||
@ -293,6 +307,15 @@ QString QgsDataSourceURI::connectionInfo() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( mSSLmode == SSLdisable )
|
||||||
|
connectionInfo += " sslmode=disable";
|
||||||
|
else if ( mSSLmode == SSLallow )
|
||||||
|
connectionInfo += " sslmode=allow";
|
||||||
|
else if ( mSSLmode == SSLrequire )
|
||||||
|
connectionInfo += " sslmode=require";
|
||||||
|
else if ( mSSLmode == SSLprefer )
|
||||||
|
connectionInfo += " sslmode=prefer";
|
||||||
|
|
||||||
return connectionInfo;
|
return connectionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,13 +340,15 @@ void QgsDataSourceURI::setConnection( const QString &host,
|
|||||||
const QString &port,
|
const QString &port,
|
||||||
const QString &database,
|
const QString &database,
|
||||||
const QString &username,
|
const QString &username,
|
||||||
const QString &password )
|
const QString &password,
|
||||||
|
SSLmode sslmode )
|
||||||
{
|
{
|
||||||
mHost = host;
|
mHost = host;
|
||||||
mDatabase = database;
|
mDatabase = database;
|
||||||
mPort = port;
|
mPort = port;
|
||||||
mUsername = username;
|
mUsername = username;
|
||||||
mPassword = password;
|
mPassword = password;
|
||||||
|
mSSLmode = sslmode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsDataSourceURI::setDataSource( const QString &schema,
|
void QgsDataSourceURI::setDataSource( const QString &schema,
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
*/
|
*/
|
||||||
class CORE_EXPORT QgsDataSourceURI
|
class CORE_EXPORT QgsDataSourceURI
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
|
||||||
|
|
||||||
//! default constructor
|
//! default constructor
|
||||||
QgsDataSourceURI();
|
QgsDataSourceURI();
|
||||||
@ -52,7 +52,8 @@ class CORE_EXPORT QgsDataSourceURI
|
|||||||
const QString& aPort,
|
const QString& aPort,
|
||||||
const QString& aDatabase,
|
const QString& aDatabase,
|
||||||
const QString& aUsername,
|
const QString& aUsername,
|
||||||
const QString& aPassword );
|
const QString& aPassword,
|
||||||
|
SSLmode sslmode );
|
||||||
|
|
||||||
//! Set all data source related members at once
|
//! Set all data source related members at once
|
||||||
void setDataSource( const QString& aSchema,
|
void setDataSource( const QString& aSchema,
|
||||||
@ -60,11 +61,13 @@ class CORE_EXPORT QgsDataSourceURI
|
|||||||
const QString& aGeometryColumn,
|
const QString& aGeometryColumn,
|
||||||
const QString& aSql = QString() );
|
const QString& aSql = QString() );
|
||||||
|
|
||||||
|
|
||||||
QString username() const;
|
QString username() const;
|
||||||
QString schema() const;
|
QString schema() const;
|
||||||
QString table() const;
|
QString table() const;
|
||||||
QString sql() const;
|
QString sql() const;
|
||||||
QString geometryColumn() const;
|
QString geometryColumn() const;
|
||||||
|
enum SSLmode sslMode() const;
|
||||||
|
|
||||||
void clearSchema();
|
void clearSchema();
|
||||||
void setSql( QString sql );
|
void setSql( QString sql );
|
||||||
@ -93,6 +96,8 @@ class CORE_EXPORT QgsDataSourceURI
|
|||||||
QString mUsername;
|
QString mUsername;
|
||||||
//! password
|
//! password
|
||||||
QString mPassword;
|
QString mPassword;
|
||||||
|
//! ssl mode
|
||||||
|
enum SSLmode mSSLmode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //QGSDATASOURCEURI_H
|
#endif //QGSDATASOURCEURI_H
|
||||||
|
@ -413,7 +413,8 @@ void QgsSpit::dbConnect()
|
|||||||
settings.value( key + "/port" ).toString(),
|
settings.value( key + "/port" ).toString(),
|
||||||
database,
|
database,
|
||||||
settings.value( key + "/username" ).toString(),
|
settings.value( key + "/username" ).toString(),
|
||||||
password );
|
password,
|
||||||
|
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
|
||||||
|
|
||||||
conn = PQconnectdb( uri.connectionInfo().toUtf8() );
|
conn = PQconnectdb( uri.connectionInfo().toUtf8() );
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,11 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>509</width>
|
<width>509</width>
|
||||||
<height>335</height>
|
<height>402</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy>
|
<sizepolicy vsizetype="MinimumExpanding" hsizetype="MinimumExpanding" >
|
||||||
<hsizetype>3</hsizetype>
|
|
||||||
<vsizetype>3</vsizetype>
|
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -93,12 +91,12 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="1" column="1" >
|
<item row="1" column="1" >
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout" >
|
||||||
<property name="margin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="margin" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="chkStorePassword" >
|
<widget class="QCheckBox" name="chkStorePassword" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
@ -117,20 +115,20 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" >
|
<item row="0" column="1" >
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout" >
|
||||||
<property name="margin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="margin" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout" >
|
||||||
<property name="margin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="margin" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="TextLabel1_2" >
|
<widget class="QLabel" name="TextLabel1_2" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
@ -191,16 +189,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="TextLabel3_3" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>SSL mode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout" >
|
||||||
<property name="margin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="margin" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="txtName" >
|
<widget class="QLineEdit" name="txtName" >
|
||||||
<property name="toolTip" >
|
<property name="toolTip" >
|
||||||
@ -231,6 +236,9 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cbxSSLmode" />
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -240,12 +248,12 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" >
|
<item row="0" column="1" >
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout" >
|
||||||
<property name="margin" >
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
<property name="spacing" >
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="margin" >
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnOk" >
|
<widget class="QPushButton" name="btnOk" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
@ -299,7 +307,7 @@
|
|||||||
<property name="sizeType" >
|
<property name="sizeType" >
|
||||||
<enum>QSizePolicy::Expanding</enum>
|
<enum>QSizePolicy::Expanding</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" >
|
<property name="sizeHint" stdset="0" >
|
||||||
<size>
|
<size>
|
||||||
<width>87</width>
|
<width>87</width>
|
||||||
<height>150</height>
|
<height>150</height>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user