Mercurial > hg > RemoteViewer
changeset 28:fb7442228526
if configured, prompt for password before connecting
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 03 Oct 2014 03:04:57 +0200 |
parents | c0ef1794e275 |
children | 56b2e8f9846e |
files | RemoteViewer/Connection.py RemoteViewer/ConnectionDialog.py RemoteViewer/ConnectionDialog.ui RemoteViewer/PasswordDialog.py RemoteViewer/PasswordDialog.ui RemoteViewer/Viewer.py |
diffstat | 6 files changed, 157 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/RemoteViewer/Connection.py Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/Connection.py Fri Oct 03 03:04:57 2014 +0200 @@ -1,7 +1,7 @@ from uuid import uuid4 from .Viewer import VncViewer, FreeRdp -KEYS = ['geometry', 'id', 'host', 'lowColor', 'title', 'type', 'user'] +KEYS = ['geometry', 'id', 'host', 'lowColor', 'promptForPassword', 'title', 'type', 'user'] def filter_string(func): """decorator function to filter turn empty strings into None""" @@ -23,12 +23,13 @@ def __init__(self): self.geometry = None + self.host = None self.id = str(uuid4()) - self.host = None + self.lowColor = False + self.promptForPassword = False self.title = None self.type = 'vnc' self.user = None - self.lowColor = False def __str__(self): return 'connection@{} "{}" of type {} to {} with user {} and geometry {}'.format(self.title, id(self), self.type, self.host, self.user, self.geometry) @@ -52,6 +53,10 @@ """This is a slot that is connected to a signal in the GUI""" self.user = user + def setPromptForPassword(self, flag): + """This is a slot that is connected to a signal in the GUI""" + self.promptForPassword = flag + @filter_string def setGeometry(self, geometry): """This is a slot that is connected to a signal in the GUI"""
--- a/RemoteViewer/ConnectionDialog.py Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/ConnectionDialog.py Fri Oct 03 03:04:57 2014 +0200 @@ -30,17 +30,22 @@ self.ui.type.setCurrentIndex(index) self.ui.hostname.setText(self.connection.host) self.ui.username.setText(self.connection.user) + self.__initCheckbox(self.ui.promptForPassword, self.connection.promptForPassword) self.ui.geometry.setText(self.connection.geometry) + self.__initCheckbox(self.ui.lowColor, self.connection.lowColor) + + def __initCheckbox(self, checkbox, value): checkState = Qt.Unchecked - if self.connection.lowColor is True: + if value is True: checkState = Qt.Checked - self.ui.lowColor.setCheckState(checkState) + checkbox.setCheckState(checkState) def __connectWidgetSlots(self): self.ui.title.textChanged.connect(self.connection.setTitle) self.ui.type.activated[str].connect(self.connection.setType) self.ui.hostname.textChanged.connect(self.connection.setHost) self.ui.username.textChanged.connect(self.connection.setUser) + self.ui.promptForPassword.clicked[bool].connect(self.connection.setPromptForPassword) self.ui.geometry.textChanged.connect(self.connection.setGeometry) self.ui.lowColor.clicked[bool].connect(self.connection.setLowColor)
--- a/RemoteViewer/ConnectionDialog.ui Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/ConnectionDialog.ui Fri Oct 03 03:04:57 2014 +0200 @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>400</width> - <height>233</height> + <height>263</height> </rect> </property> <property name="windowTitle"> @@ -54,7 +54,7 @@ </property> </widget> </item> - <item row="4" column="0"> + <item row="5" column="0"> <widget class="QLabel" name="label_4"> <property name="text"> <string>Geometry:</string> @@ -67,7 +67,7 @@ <item row="3" column="1"> <widget class="QLineEdit" name="username"/> </item> - <item row="6" column="1"> + <item row="7" column="1"> <widget class="QDialogButtonBox" name="buttonBox"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -77,7 +77,7 @@ </property> </widget> </item> - <item row="4" column="1"> + <item row="5" column="1"> <widget class="QLineEdit" name="geometry"/> </item> <item row="0" column="0"> @@ -93,20 +93,34 @@ <item row="0" column="1"> <widget class="QLineEdit" name="title"/> </item> - <item row="5" column="1"> + <item row="6" column="1"> <widget class="QCheckBox" name="lowColor"> <property name="text"> <string/> </property> </widget> </item> - <item row="5" column="0"> + <item row="6" column="0"> <widget class="QLabel" name="label_6"> <property name="text"> <string>Low Color:</string> </property> </widget> </item> + <item row="4" column="1"> + <widget class="QCheckBox" name="promptForPassword"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string><html><head/><body><p>Password:</p></body></html></string> + </property> + </widget> + </item> </layout> </widget> <tabstops>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RemoteViewer/PasswordDialog.py Fri Oct 03 03:04:57 2014 +0200 @@ -0,0 +1,25 @@ +from PyQt4.QtGui import QDialog +from .Ui_PasswordDialog import Ui_PasswordDialog + +class PasswordDialog(QDialog): + def __init__(self, connection): + super(PasswordDialog, self).__init__() + self.__initUi() + self.__setTitle(connection) + self.__setUserLabel(connection) + + def __initUi(self): + self.ui = Ui_PasswordDialog() + self.ui.setupUi(self) + + def __setTitle(self, connection): + title = 'Password for ' + connection.displayString() + self.setWindowTitle(title) + + def __setUserLabel(self, connection): + label = 'User: ' + connection.user + self.ui.user.setText(label) + + def accept(self): + self.password = self.ui.password.text() + super(PasswordDialog, self).accept()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RemoteViewer/PasswordDialog.ui Fri Oct 03 03:04:57 2014 +0200 @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PasswordDialog</class> + <widget class="QDialog" name="PasswordDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>103</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="user"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="password"> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>PasswordDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>PasswordDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>
--- a/RemoteViewer/Viewer.py Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/Viewer.py Fri Oct 03 03:04:57 2014 +0200 @@ -2,6 +2,7 @@ from threading import Thread from .LogViewer import LogViewer +from .PasswordDialog import PasswordDialog class ReadThread(Thread): def __init__(self, process, viewer): @@ -27,11 +28,26 @@ self.process = None def open(self, parent): + if not self.__runPasswordDialog(): + return self.buildCommand() - self.process = subprocess.Popen(self.command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + self.process = subprocess.Popen(self.command, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) self.__startLogThread() self.process.wait() + def __runPasswordDialog(self): + if self.connection.promptForPassword: + dialog = PasswordDialog(self.connection) + success = dialog.exec_() + if success: + self.connection.password = dialog.password + return True + else: + return False + else: + return True + def __startLogThread(self): logViewer = self.__createLogViewer() readThread = ReadThread(self.process, logViewer) @@ -66,6 +82,8 @@ self.append('/v:', self.connection.host) self.append('/t:', self.connection.displayString()) self.append('/u:', self.connection.user) + if self.connection.password is not None: + self.append('/p:', self.connection.password) self.append('/size:', self.connection.geometry) if self.connection.lowColor: self.command.append('/bpp:8')