From d8bf59b600b6a08eeb963d8ad0c28db3e3f78980 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 5 Aug 2013 13:14:25 +0200 Subject: add imap service --- src/leap/services/mail/imap.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/leap/services/mail/imap.py (limited to 'src/leap') diff --git a/src/leap/services/mail/imap.py b/src/leap/services/mail/imap.py new file mode 100644 index 00000000..65fbe3b5 --- /dev/null +++ b/src/leap/services/mail/imap.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# imap.py +# Copyright (C) 2013 LEAP +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +""" +Initialization of imap service +""" +import logging +import sys + +from leap.mail.imap.service import imap +from twisted.python import log + +logger = logging.getLogger(__name__) + + +def start_imap_service(*args, **kwargs): + """ + Initializes and run imap service. + """ + logger.debug('Launching imap service') + + # XXX handle this in a more appropriate manner + log.startLogging(open('/tmp/leap-imap.log', 'w')) + log.startLogging(sys.stdout) + + imap.run_service(*args, **kwargs) -- cgit v1.2.3 From 9ede79b2d3a6172bcc5d458e70508b06d0033323 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 5 Aug 2013 13:14:54 +0200 Subject: comment out common service initialization --- src/leap/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/leap') diff --git a/src/leap/app.py b/src/leap/app.py index 6ba27813..774ae41f 100644 --- a/src/leap/app.py +++ b/src/leap/app.py @@ -210,8 +210,10 @@ def main(): if IS_MAC: window.raise_() - tx_app = leap_services() - assert(tx_app) + # This was a good idea, but for this to work as intended we + # should centralize the start of all services in there. + #tx_app = leap_services() + #assert(tx_app) # Run main loop twisted_main.start(app) -- cgit v1.2.3 From 485d3cf64e5102aeafcefed775b99f850cdf6686 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 5 Aug 2013 13:15:55 +0200 Subject: catch errors during soledad initialization --- src/leap/services/soledad/soledadbootstrapper.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/leap') diff --git a/src/leap/services/soledad/soledadbootstrapper.py b/src/leap/services/soledad/soledadbootstrapper.py index ac3243c1..d53aeadb 100644 --- a/src/leap/services/soledad/soledadbootstrapper.py +++ b/src/leap/services/soledad/soledadbootstrapper.py @@ -23,6 +23,7 @@ import logging import os from PySide import QtCore +from u1db import errors as u1db_errors from leap.common.check import leap_assert, leap_assert_type from leap.common.files import get_mtime @@ -103,15 +104,18 @@ class SoledadBootstrapper(AbstractBootstrapper): # TODO: If selected server fails, retry with another host # (issue #3309) - self._soledad = Soledad(uuid, - self._password.encode("utf-8"), - secrets_path=secrets_path, - local_db_path=local_db_path, - server_url=server_url, - cert_file=cert_file, - auth_token=srp_auth.get_token()) - - self._soledad.sync() + try: + self._soledad = Soledad( + uuid, + self._password.encode("utf-8"), + secrets_path=secrets_path, + local_db_path=local_db_path, + server_url=server_url, + cert_file=cert_file, + auth_token=srp_auth.get_token()) + self._soledad.sync() + except u1db_errors.Unauthorized: + logger.error("Error while initializing soledad.") else: raise Exception("No soledad server found") -- cgit v1.2.3 From 63d1e561c7d3705196216e11dd8bf267de8fb8ff Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 5 Aug 2013 13:29:03 +0200 Subject: reindent for clarity --- src/leap/gui/mainwindow.py | 89 ++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'src/leap') diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py index 87dd4f5c..c938a064 100644 --- a/src/leap/gui/mainwindow.py +++ b/src/leap/gui/mainwindow.py @@ -942,29 +942,32 @@ class MainWindow(QtGui.QMainWindow): passed = data[self._soledad_bootstrapper.PASSED_KEY] if not passed: logger.error(data[self._soledad_bootstrapper.ERROR_KEY]) - else: - logger.debug("Done bootstrapping Soledad") + return - self._soledad = self._soledad_bootstrapper.soledad - self._keymanager = self._soledad_bootstrapper.keymanager + logger.debug("Done bootstrapping Soledad") - if self._provider_config.provides_mx() and \ - self._enabled_services.count(self.MX_SERVICE) > 0: - self._smtp_bootstrapper.run_smtp_setup_checks( - self._provider_config, - self._smtp_config, - True) + self._soledad = self._soledad_bootstrapper.soledad + self._keymanager = self._soledad_bootstrapper.keymanager + + if self._provider_config.provides_mx() and \ + self._enabled_services.count(self.MX_SERVICE) > 0: + self._smtp_bootstrapper.run_smtp_setup_checks( + self._provider_config, + self._smtp_config, + True) + else: + if self._enabled_services.count(self.MX_SERVICE) > 0: + pass # TODO: show MX status + #self._status_panel.set_eip_status( + # self.tr("%s does not support MX") % + # (self._provider_config.get_domain(),), + # error=True) else: - if self._enabled_services.count(self.MX_SERVICE) > 0: - pass # TODO: show MX status - #self._status_panel.set_eip_status( - # self.tr("%s does not support MX") % - # (self._provider_config.get_domain(),), - # error=True) - else: - pass # TODO: show MX status - #self._status_panel.set_eip_status( - # self.tr("MX is disabled")) + pass # TODO: show MX status + #self._status_panel.set_eip_status( + # self.tr("MX is disabled")) + + # Service control methods: eip def _smtp_bootstrapped_stage(self, data): """ @@ -982,29 +985,29 @@ class MainWindow(QtGui.QMainWindow): passed = data[self._smtp_bootstrapper.PASSED_KEY] if not passed: logger.error(data[self._smtp_bootstrapper.ERROR_KEY]) - else: - logger.debug("Done bootstrapping SMTP") - - hosts = self._smtp_config.get_hosts() - # TODO: handle more than one host and define how to choose - if len(hosts) > 0: - hostname = hosts.keys()[0] - logger.debug("Using hostname %s for SMTP" % (hostname,)) - host = hosts[hostname][self.IP_KEY].encode("utf-8") - port = hosts[hostname][self.PORT_KEY] - # TODO: pick local smtp port in a better way - # TODO: Make the encrypted_only configurable - - from leap.mail.smtp import setup_smtp_relay - client_cert = self._eip_config.get_client_cert_path( - self._provider_config) - setup_smtp_relay(port=1234, - keymanager=self._keymanager, - smtp_host=host, - smtp_port=port, - smtp_cert=client_cert, - smtp_key=client_cert, - encrypted_only=False) + return + logger.debug("Done bootstrapping SMTP") + + hosts = self._smtp_config.get_hosts() + # TODO: handle more than one host and define how to choose + if len(hosts) > 0: + hostname = hosts.keys()[0] + logger.debug("Using hostname %s for SMTP" % (hostname,)) + host = hosts[hostname][self.IP_KEY].encode("utf-8") + port = hosts[hostname][self.PORT_KEY] + # TODO: pick local smtp port in a better way + # TODO: Make the encrypted_only configurable + + from leap.mail.smtp import setup_smtp_relay + client_cert = self._eip_config.get_client_cert_path( + self._provider_config) + setup_smtp_relay(port=1234, + keymanager=self._keymanager, + smtp_host=host, + smtp_port=port, + smtp_cert=client_cert, + smtp_key=client_cert, + encrypted_only=False) def _get_socket_host(self): """ -- cgit v1.2.3 From f757e73a4d2fb05e90dba306c4d918f6aa7f1413 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 5 Aug 2013 13:38:12 +0200 Subject: start imap service --- src/leap/gui/mainwindow.py | 61 +++++++++++++++++++++++++++++++++--------- src/leap/services/mail/imap.py | 4 ++- 2 files changed, 52 insertions(+), 13 deletions(-) (limited to 'src/leap') diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py index c938a064..07ad9b9a 100644 --- a/src/leap/gui/mainwindow.py +++ b/src/leap/gui/mainwindow.py @@ -45,6 +45,7 @@ from leap.services.eip.providerbootstrapper import ProviderBootstrapper # XXX: Soledad might not work out of the box in Windows, issue #2932 from leap.services.soledad.soledadbootstrapper import SoledadBootstrapper from leap.services.mail.smtpbootstrapper import SMTPBootstrapper +from leap.services.mail import imap from leap.platform_init import IS_WIN, IS_MAC from leap.platform_init.initializers import init_platform @@ -94,6 +95,7 @@ class MainWindow(QtGui.QMainWindow): # Signals new_updates = QtCore.Signal(object) raise_window = QtCore.Signal([]) + soledad_ready = QtCore.Signal([]) # We use this flag to detect abnormal terminations user_stopped_eip = False @@ -140,6 +142,9 @@ class MainWindow(QtGui.QMainWindow): self.ui.stackedWidget.widget(self.LOGIN_INDEX)) self.ui.loginLayout.addWidget(self._login_widget) + # Signals + # TODO separate logic from ui signals. + self._login_widget.login.connect(self._login) self._login_widget.cancel_login.connect(self._cancel_login) self._login_widget.show_wizard.connect( @@ -260,7 +265,9 @@ class MainWindow(QtGui.QMainWindow): self.ui.lblNewUpdates.setVisible(False) self.ui.btnMore.setVisible(False) self.ui.btnMore.clicked.connect(self._updates_details) + self.new_updates.connect(self._react_to_new_updates) + self.soledad_ready.connect(self._start_imap_service) init_platform() @@ -273,6 +280,7 @@ class MainWindow(QtGui.QMainWindow): self._soledad = None self._keymanager = None + self._imap_service = None self._login_defer = None self._download_provider_defer = None @@ -949,6 +957,15 @@ class MainWindow(QtGui.QMainWindow): self._soledad = self._soledad_bootstrapper.soledad self._keymanager = self._soledad_bootstrapper.keymanager + # Ok, now soledad is ready, so we can allow other things that + # depend on soledad to start. + + # this will trigger start_imap_service + self.soledad_ready.emit() + + # TODO connect all these activations to the soledad_ready + # signal so the logic is clearer to follow. + if self._provider_config.provides_mx() and \ self._enabled_services.count(self.MX_SERVICE) > 0: self._smtp_bootstrapper.run_smtp_setup_checks( @@ -967,7 +984,7 @@ class MainWindow(QtGui.QMainWindow): #self._status_panel.set_eip_status( # self.tr("MX is disabled")) - # Service control methods: eip + # Service control methods: smtp def _smtp_bootstrapped_stage(self, data): """ @@ -1009,6 +1026,19 @@ class MainWindow(QtGui.QMainWindow): smtp_key=client_cert, encrypted_only=False) + def _start_imap_service(self): + """ + SLOT + TRIGGERS: + soledad_ready + """ + logger.debug('Starting imap service') + logger.debug('DEBUG: NOT STARTING IT REALLY ----------------') + + #self._imap_service = imap.start_imap_service( + #self._soledad, + #self._keymanager) + def _get_socket_host(self): """ Returns the socket and port to be used for VPN @@ -1398,6 +1428,9 @@ class MainWindow(QtGui.QMainWindow): """ logger.debug('About to quit, doing cleanup...') + if self._imap_service is not None: + self._imap_service.stop() + if self._srp_auth is not None: if self._srp_auth.get_session_id() is not None or \ self._srp_auth.get_token() is not None: @@ -1410,16 +1443,28 @@ class MainWindow(QtGui.QMainWindow): else: logger.error("No instance of soledad was found.") - logger.debug('Cleaning pidfiles') - self._cleanup_pidfiles() - logger.debug('Terminating vpn') self._vpn.terminate(shutdown=True) + if self._login_defer: + logger.debug("Cancelling login defer.") + self._login_defer.cancel() + + if self._download_provider_defer: + logger.debug("Cancelling download provider defer.") + self._download_provider_defer.cancel() + + # TODO missing any more cancels? + + logger.debug('Cleaning pidfiles') + self._cleanup_pidfiles() + def quit(self): """ Cleanup and tidely close the main window before quitting. """ + # TODO: separate the shutting down of services from the + # UI stuff. self._cleanup_and_quit() self._really_quit = True @@ -1430,14 +1475,6 @@ class MainWindow(QtGui.QMainWindow): if self._logger_window: self._logger_window.close() - if self._login_defer: - logger.debug("Cancelling login defer.") - self._login_defer.cancel() - - if self._download_provider_defer: - logger.debug("Cancelling download provider defer.") - self._download_provider_defer.cancel() - self.close() if self._quit_callback: diff --git a/src/leap/services/mail/imap.py b/src/leap/services/mail/imap.py index 65fbe3b5..5fdc7492 100644 --- a/src/leap/services/mail/imap.py +++ b/src/leap/services/mail/imap.py @@ -29,6 +29,8 @@ logger = logging.getLogger(__name__) def start_imap_service(*args, **kwargs): """ Initializes and run imap service. + + :returns: twisted.internet.task.LoopingCall instance """ logger.debug('Launching imap service') @@ -36,4 +38,4 @@ def start_imap_service(*args, **kwargs): log.startLogging(open('/tmp/leap-imap.log', 'w')) log.startLogging(sys.stdout) - imap.run_service(*args, **kwargs) + return imap.run_service(*args, **kwargs) -- cgit v1.2.3 From 512acc5b039f4ba76db3e1ec4abe4c002d4dc0ea Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 2 Aug 2013 11:10:01 +0200 Subject: Properly shutdown soledad instance. --- src/leap/gui/mainwindow.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/leap') diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py index 07ad9b9a..73354684 100644 --- a/src/leap/gui/mainwindow.py +++ b/src/leap/gui/mainwindow.py @@ -1033,11 +1033,10 @@ class MainWindow(QtGui.QMainWindow): soledad_ready """ logger.debug('Starting imap service') - logger.debug('DEBUG: NOT STARTING IT REALLY ----------------') - #self._imap_service = imap.start_imap_service( - #self._soledad, - #self._keymanager) + self._imap_service = imap.start_imap_service( + self._soledad, + self._keymanager) def _get_socket_host(self): """ -- cgit v1.2.3 From 3fd9833f3392050068b42e9fd3f7b982b1040d64 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 8 Aug 2013 14:01:18 +0200 Subject: remove separate logging --- src/leap/services/mail/imap.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/leap') diff --git a/src/leap/services/mail/imap.py b/src/leap/services/mail/imap.py index 5fdc7492..4dceb2ad 100644 --- a/src/leap/services/mail/imap.py +++ b/src/leap/services/mail/imap.py @@ -34,8 +34,9 @@ def start_imap_service(*args, **kwargs): """ logger.debug('Launching imap service') - # XXX handle this in a more appropriate manner - log.startLogging(open('/tmp/leap-imap.log', 'w')) - log.startLogging(sys.stdout) + # Uncomment the next two lines to get a separate debugging log + # TODO handle this by a separate flag. + #log.startLogging(open('/tmp/leap-imap.log', 'w')) + #log.startLogging(sys.stdout) return imap.run_service(*args, **kwargs) -- cgit v1.2.3