Allow the user to specify a fixed port number in the runtime to aid cookie whitelisting etc. Fixes #3506

This commit is contained in:
Dave Page 2018-07-19 12:54:53 +01:00
parent 2ce41e77f2
commit a86604160a
6 changed files with 244 additions and 56 deletions

View File

@ -11,6 +11,7 @@ Features
********
| `Feature #3397 <https://redmine.postgresql.org/issues/3397>`_ - Add support for Trigger and JIT stats in the graphical query plan viewer.
| `Feature #3506 <https://redmine.postgresql.org/issues/3506>`_ - Allow the user to specify a fixed port number in the runtime to aid cookie whitelisting etc.
| `Feature #3510 <https://redmine.postgresql.org/issues/3510>`_ - Add a menu option to the runtime to copy the appserver URL to the clipboard.
Bug fixes

View File

@ -34,11 +34,29 @@ void ConfigWindow::on_buttonBox_rejected()
this->close();
}
void ConfigWindow::on_chkFixedPort_stateChanged(int state)
{
if (state == Qt::Checked)
ui->spinPortNumber->setEnabled(true);
else
ui->spinPortNumber->setEnabled(false);
}
QString ConfigWindow::getBrowserCommand()
{
return ui->browserCommandLineEdit->text();
}
bool ConfigWindow::getFixedPort()
{
return ui->chkFixedPort->isChecked();
}
int ConfigWindow::getPortNumber()
{
return ui->spinPortNumber->value();
}
QString ConfigWindow::getPythonPath()
{
return ui->pythonPathLineEdit->text();
@ -55,6 +73,25 @@ void ConfigWindow::setBrowserCommand(QString command)
ui->browserCommandLineEdit->setText(command);
}
void ConfigWindow::setFixedPort(bool fixedPort)
{
if (fixedPort)
{
ui->chkFixedPort->setCheckState(Qt::Checked);
ui->spinPortNumber->setEnabled(true);
}
else
{
ui->chkFixedPort->setCheckState(Qt::Unchecked);
ui->spinPortNumber->setEnabled(false);
}
}
void ConfigWindow::setPortNumber(int port)
{
ui->spinPortNumber->setValue(port);
}
void ConfigWindow::setPythonPath(QString path)
{
ui->pythonPathLineEdit->setText(path);

View File

@ -27,16 +27,21 @@ public:
~ConfigWindow();
QString getBrowserCommand();
bool getFixedPort();
int getPortNumber();
QString getPythonPath();
QString getApplicationPath();
void setBrowserCommand(QString command);
void setFixedPort(bool fixedPort);
void setPortNumber(int port);
void setPythonPath(QString path);
void setApplicationPath(QString path);
private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_chkFixedPort_stateChanged(int state);
private:
Ui::ConfigWindow *ui;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>731</width>
<height>328</height>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
@ -63,22 +63,6 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
@ -87,11 +71,23 @@
<item>
<widget class="QLabel" name="pythonPathLabel_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Browser Command</string>
</property>
@ -107,7 +103,7 @@
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -119,6 +115,119 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>By default the runtime uses a random port number to ensure it can always run successfully. If you need to use a predictable port number, you can set one here. Note that if the port is already in use, the application will be unable start.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Fixed Port Number?</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkFixedPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Port number</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinPortNumber">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>5050</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
@ -151,14 +260,28 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="applicationPathLineEdit">
<property name="placeholderText">
<string>/usr/pgadmin4/web</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="pythonPathLineEdit">
<property name="placeholderText">
<string>/usr/pgadmin4/lib/python2.7;/usr/pgadmin4/lib/python2.7/site-packages</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Enter the path to the directory containing pgAdmin.py if desired.</string>
@ -172,14 +295,14 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="pythonPathLineEdit">
<property name="placeholderText">
<string>/usr/pgadmin4/lib/python2.7;/usr/pgadmin4/lib/python2.7/site-packages</string>
<item row="5" column="0">
<widget class="QLabel" name="applicationPathLabel">
<property name="text">
<string>Application Path</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Enter a PYTHONPATH if desired. Path elements should be semi-colon delimited.</string>
@ -189,35 +312,24 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="applicationPathLabel">
<property name="text">
<string>Application Path</string>
<item row="3" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="applicationPathLineEdit">
<property name="placeholderText">
<string>/usr/pgadmin4/web</string>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>60</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
@ -270,5 +382,24 @@
</hint>
</hints>
</connection>
<connection>
<sender>chkFixedPort</sender>
<signal>stateChanged(int)</signal>
<receiver>ConfigWindow</receiver>
<slot>on_chkFixedPort_stateChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>202</x>
<y>213</y>
</hint>
<hint type="destinationlabel">
<x>365</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>on_chkFixedPort_stateChanged(int)</slot>
</slots>
</ui>

View File

@ -77,21 +77,29 @@ void MenuActions::onConfig()
ConfigWindow *dlg = new ConfigWindow();
dlg->setWindowTitle(QString(tr("%1 Configuration")).arg(PGA_APP_NAME));
dlg->setBrowserCommand(settings.value("BrowserCommand").toString());
dlg->setFixedPort(settings.value("FixedPort").toBool());
dlg->setPortNumber(settings.value("PortNumber").toInt());
dlg->setPythonPath(settings.value("PythonPath").toString());
dlg->setApplicationPath(settings.value("ApplicationPath").toString());
dlg->setModal(true);
ok = dlg->exec();
QString browsercommand = dlg->getBrowserCommand();
bool fixedport = dlg->getFixedPort();
int portnumber = dlg->getPortNumber();
QString pythonpath = dlg->getPythonPath();
QString applicationpath = dlg->getApplicationPath();
if (ok)
{
bool needRestart = (settings.value("PythonPath").toString() != pythonpath ||
bool needRestart = (settings.value("FixedPort").toBool() != fixedport ||
settings.value("PortNumber").toInt() != portnumber ||
settings.value("PythonPath").toString() != pythonpath ||
settings.value("ApplicationPath").toString() != applicationpath);
settings.setValue("BrowserCommand", browsercommand);
settings.setValue("FixedPort", fixedport);
settings.setValue("PortNumber", portnumber);
settings.setValue("PythonPath", pythonpath);
settings.setValue("ApplicationPath", applicationpath);

View File

@ -180,12 +180,18 @@ int main(int argc, char * argv[])
quint16 port = 0L;
// Find an unused port number. Essentially, we're just reserving one
// here that Flask will use when we start up the server.
// In order to use the socket, we need to free this socket ASAP.
// Hence - putting this code in a code block so the scope of the socket
// variable vanishes to make that socket available.
if (settings.value("FixedPort", false).toBool())
{
// Use the fixed port number
port = settings.value("PortNumber", 5050).toInt();
}
else
{
// Find an unused port number. Essentially, we're just reserving one
// here that Flask will use when we start up the server.
// In order to use the socket, we need to free this socket ASAP.
// Hence - putting this code in a code block so the scope of the socket
// variable vanishes to make that socket available.
#if QT_VERSION >= 0x050000
QTcpSocket socket;