summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-11-07 06:06:40 +0900
committerkali <kali@leap.se>2012-11-07 06:06:40 +0900
commit63fc5b19e39072f4bda26f2649e83832d68b5000 (patch)
tree3d5cf060e4cecb1effcacdaceb9d8e3c6582acb9 /src/leap
parent6032f776cabcd04aa7f4e1f55a34ecfec2775e85 (diff)
fix issue with refresh timing
using end_sentinel as a workaround for the lack of refresh. doing a pause so user gets some feedback about what's going on. error messages on select provider page should be all covered now.
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/gui/firstrun/providerinfo.py126
-rw-r--r--src/leap/gui/firstrun/selectprovider.py95
-rw-r--r--src/leap/gui/progress.py14
3 files changed, 150 insertions, 85 deletions
diff --git a/src/leap/gui/firstrun/providerinfo.py b/src/leap/gui/firstrun/providerinfo.py
index 52b4873f..5cc34927 100644
--- a/src/leap/gui/firstrun/providerinfo.py
+++ b/src/leap/gui/firstrun/providerinfo.py
@@ -1,14 +1,27 @@
"""
Provider Info Page, used in First run Wizard
"""
+import logging
+import time
from PyQt4 import QtCore
from PyQt4 import QtGui
+import requests
+
+from leap.base import exceptions as baseexceptions
+from leap.crypto import certs
+from leap.eip import exceptions as eipexceptions
+
from leap.gui.progress import ValidationPage
from leap.gui.constants import APP_LOGO
+logger = logging.getLogger(__name__)
+
+GUI_PAUSE_FOR_USER_SECONDS = 1
+pause_for_user = lambda: time.sleep(GUI_PAUSE_FOR_USER_SECONDS)
+
class ProviderInfoPage(ValidationPage):
def __init__(self, parent=None):
@@ -70,15 +83,95 @@ class ProviderInfoPage(ValidationPage):
"""
executes actual checks in a separate thread
"""
- import time
+ def pause_and_finish():
+ update_signal.emit("end_sentinel", 100)
+ pause_for_user()
+
+ wizard = self.wizard()
+ prevpage = "providerselection"
+ netchecker = wizard.netchecker()
+ providercertchecker = wizard.providercertchecker()
+ eipconfigchecker = wizard.eipconfigchecker()
+
+ domain = self.field('provider_domain')
+
update_signal.emit("head_sentinel", 0)
- time.sleep(0.5)
- update_signal.emit("something", 10)
- time.sleep(0.5)
- update_signal.emit("done", 90)
- time.sleep(1)
- update_signal.emit("end_sentinel", 100)
- time.sleep(1)
+ pause_for_user()
+
+ # 1) try name resolution
+ update_signal.emit("Checking that server is reachable", 20)
+ logger.debug('checking name resolution')
+ try:
+ netchecker.check_name_resolution(
+ domain)
+
+ except baseexceptions.LeapException as exc:
+ logger.debug('exception')
+ wizard.set_validation_error(
+ prevpage, exc.usermessage)
+ pause_and_finish()
+ return False
+
+ # 2) try https connection
+ update_signal.emit("Checking secure connection to provider", 40)
+ logger.debug('checking https connection')
+ try:
+ providercertchecker.is_https_working(
+ "https://%s" % domain,
+ verify=True)
+
+ except eipexceptions.HttpsBadCertError as exc:
+ logger.debug('exception')
+ # XXX skipping for now...
+ ##############################################
+ # We had this validation logic
+ # in the provider selection page before
+ ##############################################
+ #if self.trustProviderCertCheckBox.isChecked():
+ #pass
+ #else:
+ wizard.set_validation_error(
+ prevpage, exc.usermessage)
+ #fingerprint = certs.get_cert_fingerprint(
+ #domain=domain, sep=" ")
+
+ # it's ok if we've trusted this fgprt before
+ #trustedcrts = wizard.trusted_certs
+ #if trustedcrts and fingerprint.replace(' ', '') in trustedcrts:
+ #pass
+ #else:
+ # let your user face panick :P
+ #self.add_cert_info(fingerprint)
+ #self.did_cert_check = True
+ #self.completeChanged.emit()
+ #return False
+ pause_and_finish()
+ return False
+
+ except baseexceptions.LeapException as exc:
+ wizard.set_validation_error(
+ prevpage, exc.usermessage)
+ pause_and_finish()
+ return False
+
+ # try download provider info...
+ update_signal.emit("Downloading provider info", 70)
+ try:
+ eipconfigchecker.fetch_definition(domain=domain)
+ wizard.set_providerconfig(
+ eipconfigchecker.defaultprovider.config)
+ # XXX catch errors...
+ except requests.exceptions.SSLError:
+ # XXX we should have catched this before.
+ # but cert checking is broken.
+ wizard.set_validation_error(
+ prevpage,
+ "Could not get info from provider.")
+ pause_and_finish()
+ return False
+
+ # We're done
+ pause_and_finish()
def _do_validation(self):
"""
@@ -86,10 +179,19 @@ class ProviderInfoPage(ValidationPage):
(connected to checker thread finished signal)
"""
print 'validation...'
- self.progress.hide()
- self.stepsTableWidget.hide()
- self.create_info_panel()
- self.show_provider_info()
+ prevpage = "providerselection"
+ errors = self.wizard().get_validation_error(prevpage)
+
+ if not errors:
+ self.progress.hide()
+ self.stepsTableWidget.hide()
+ self.create_info_panel()
+ self.show_provider_info()
+
+ else:
+ logger.debug('going back with errors')
+ logger.debug('ERRORS: %s' % errors)
+ self.go_back()
def nextId(self):
wizard = self.wizard()
diff --git a/src/leap/gui/firstrun/selectprovider.py b/src/leap/gui/firstrun/selectprovider.py
index d26fdbbb..e95a4af2 100644
--- a/src/leap/gui/firstrun/selectprovider.py
+++ b/src/leap/gui/firstrun/selectprovider.py
@@ -1,6 +1,8 @@
"""
Select Provider Page, used in First Run Wizard
"""
+import logging
+
from PyQt4 import QtCore
from PyQt4 import QtGui
@@ -11,6 +13,8 @@ from leap.eip import exceptions as eipexceptions
from leap.gui.constants import APP_LOGO
from leap.gui.styles import ErrorLabelStyleSheet
+logger = logging.getLogger(__name__)
+
class SelectProviderPage(QtGui.QWizardPage):
def __init__(self, parent=None, providers=None):
@@ -136,77 +140,34 @@ class SelectProviderPage(QtGui.QWizardPage):
return True
return False
+ def populateErrors(self):
+ # XXX could move this to ValidationMixin
+
+ #logger.debug('getting errors')
+ errors = self.wizard().get_validation_error('providerselection')
+ if errors:
+ #logger.debug('errors! -> %s', errors)
+ self.validationMsg.setText(errors)
+
+ def paintEvent(self, event):
+ """
+ we hook our populate errors
+ on paintEvent because we need it to catch
+ when user enters the page coming from next,
+ and initializePage does not cover that case.
+ Maybe there's a better event to hook upon.
+ """
+ super(SelectProviderPage, self).paintEvent(event)
+ self.populateErrors()
+
def initializePage(self):
+ self.validationMsg.setText('')
self.certinfoGroup.hide()
def validatePage(self):
- ##################################
- # XXX FIXME!
- ##################################
- ##################################
- ##################################
- ##################################
- ##### validation skipped !!! #####
- ##################################
- ##################################
- return True
- ##################################
- ##################################
- ##################################
-
- # XXX move to ProviderInfo...
-
- wizard = self.wizard()
- netchecker = wizard.netchecker()
- providercertchecker = wizard.providercertchecker()
- eipconfigchecker = wizard.eipconfigchecker()
-
- domain = self.providerNameEdit.text()
-
- # try name resolution
- try:
- netchecker.check_name_resolution(
- domain)
-
- except baseexceptions.LeapException as exc:
- self.set_validation_status(exc.usermessage)
- return False
-
- # try https connection
- try:
- providercertchecker.is_https_working(
- "https://%s" % domain,
- verify=True)
-
- except eipexceptions.HttpsBadCertError as exc:
- if self.trustProviderCertCheckBox.isChecked():
- pass
- else:
- self.set_validation_status(exc.usermessage)
- fingerprint = certs.get_cert_fingerprint(
- domain=domain, sep=" ")
-
- # it's ok if we've trusted this fgprt before
- trustedcrts = self.wizard().trusted_certs
- if trustedcrts and fingerprint.replace(' ', '') in trustedcrts:
- pass
- else:
- # let your user face panick :P
- self.add_cert_info(fingerprint)
- self.did_cert_check = True
- self.completeChanged.emit()
- return False
-
- except baseexceptions.LeapException as exc:
- self.set_validation_status(exc.usermessage)
- return False
-
- # try download provider info...
- eipconfigchecker.fetch_definition(domain=domain)
- wizard.set_providerconfig(
- eipconfigchecker.defaultprovider.config)
-
- # all ok, go on...
+ """
+ we are doing validation in next page
+ """
return True
def nextId(self):
diff --git a/src/leap/gui/progress.py b/src/leap/gui/progress.py
index 16a55e3a..d6551939 100644
--- a/src/leap/gui/progress.py
+++ b/src/leap/gui/progress.py
@@ -7,7 +7,8 @@ try:
except ImportError:
# We must be in 2.6
from leap.util.dicts import OrderedDict
-#import time
+
+import logging
from PyQt4 import QtCore
from PyQt4 import QtGui
@@ -18,6 +19,8 @@ from leap.gui import mainwindow_rc
CHECKMARK_IMG = ":/images/checked.png"
+logger = logging.getLogger(__name__)
+
class ImgWidget(QtGui.QWidget):
@@ -116,7 +119,7 @@ class StepsTableWidget(QtGui.QTableWidget):
# but on populating is 456... :(
# XXX do we need this initial?
- print 'init table. width=%s' % width
+ logger.debug('init table. width=%s' % width)
self.horizontalHeader().resizeSection(0, width * 0.7)
# this disables the table grid.
@@ -212,7 +215,7 @@ class ValidationPage(QtGui.QWizardPage):
table = self.stepsTableWidget
FIRST_COLUMN_PERCENT = 0.75
width = table.width()
- print 'populate table. width=%s' % width
+ logger.debug('populate table. width=%s' % width)
table.horizontalHeader().resizeSection(0, width * FIRST_COLUMN_PERCENT)
def onStepStatusChanged(self, status, progress=None):
@@ -223,7 +226,6 @@ class ValidationPage(QtGui.QWizardPage):
self.progress.update()
def add_status_line(self, message):
- print 'adding status line...'
index = len(self.steps)
step = ProgressStep(message, False, index=index)
self.steps.addStep(step)
@@ -261,6 +263,6 @@ class ValidationPage(QtGui.QWizardPage):
self._do_checks(update_signal=signal))
self.checks.finished.connect(self._do_validation)
self.checks.begin()
- print 'check thread started!'
- print 'waiting for it to terminate...'
+ #logger.debug('check thread started!')
+ #logger.debug('waiting for it to terminate...')
self.checks.wait()