summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorchiiph <chiiph@chiiphs-MacBook-Air.local>2013-06-19 12:56:16 -0300
committerchiiph <chiiph@chiiphs-MacBook-Air.local>2013-06-19 12:56:16 -0300
commit86a3fdea70aff978e7f5cf5446a1b7761f2e588a (patch)
tree7e3edc9dc6a8c4628f8dfdb6ffd38e882d19cf7a /src/leap
parent625a2d672885f5c86b1908c0b5a147188a82bb5d (diff)
parent0f43f3db34dd0262e298dd4431b1e971c77dfbdd (diff)
Merge remote-tracking branch 'kali/bug/2890-remove-tempdir-on-shutdown' into develop
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/gui/mainwindow.py2
-rw-r--r--src/leap/gui/statuspanel.py47
-rw-r--r--src/leap/services/eip/vpnprocess.py28
3 files changed, 61 insertions, 16 deletions
diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py
index 51b96463..9fd543bf 100644
--- a/src/leap/gui/mainwindow.py
+++ b/src/leap/gui/mainwindow.py
@@ -1209,7 +1209,7 @@ class MainWindow(QtGui.QMainWindow):
self._cleanup_pidfiles()
logger.debug('Terminating vpn')
- self._vpn.terminate()
+ self._vpn.terminate(shutdown=True)
def quit(self):
"""
diff --git a/src/leap/gui/statuspanel.py b/src/leap/gui/statuspanel.py
index 554903d8..19f84d4c 100644
--- a/src/leap/gui/statuspanel.py
+++ b/src/leap/gui/statuspanel.py
@@ -25,7 +25,7 @@ from PySide import QtCore, QtGui
from ui_statuspanel import Ui_StatusPanel
from leap.services.eip.vpnprocess import VPNManager
-from leap.platform_init import IS_MAC
+from leap.platform_init import IS_WIN, IS_LINUX
from leap.common.check import leap_assert_type
logger = logging.getLogger(__name__)
@@ -52,13 +52,35 @@ class StatusPanelWidget(QtGui.QWidget):
self.ui.btnEipStartStop.clicked.connect(
self.start_eip)
- if IS_MAC:
- EIP_ICONS = (
- ":/images/conn_connecting-light.png",
- ":/images/conn_connected-light.png",
- ":/images/conn_error-light.png")
- else:
- EIP_ICONS = (
+ # Set the EIP status icons
+ self.CONNECTING_ICON = None
+ self.CONNECTED_ICON = None
+ self.ERROR_ICON = None
+ self.CONNECTING_ICON_TRAY = None
+ self.CONNECTED_ICON_TRAY = None
+ self.ERROR_ICON_TRAY = None
+ self._set_eip_icons()
+
+ def _set_eip_icons(self):
+ """
+ Sets the EIP status icons for the main window and for the tray
+
+ MAC : dark icons
+ LINUX : dark icons in window, light icons in tray
+ WIN : light icons
+ """
+ EIP_ICONS = EIP_ICONS_TRAY = (
+ ":/images/conn_connecting-light.png",
+ ":/images/conn_connected-light.png",
+ ":/images/conn_error-light.png")
+
+ if IS_LINUX:
+ EIP_ICONS_TRAY = (
+ ":/images/conn_connecting.png",
+ ":/images/conn_connected.png",
+ ":/images/conn_error.png")
+ elif IS_WIN:
+ EIP_ICONS = EIP_ICONS_TRAY = (
":/images/conn_connecting.png",
":/images/conn_connected.png",
":/images/conn_error.png")
@@ -67,6 +89,10 @@ class StatusPanelWidget(QtGui.QWidget):
self.CONNECTED_ICON = QtGui.QPixmap(EIP_ICONS[1])
self.ERROR_ICON = QtGui.QPixmap(EIP_ICONS[2])
+ self.CONNECTING_ICON_TRAY = QtGui.QPixmap(EIP_ICONS_TRAY[0])
+ self.CONNECTED_ICON_TRAY = QtGui.QPixmap(EIP_ICONS_TRAY[1])
+ self.ERROR_ICON_TRAY = QtGui.QPixmap(EIP_ICONS_TRAY[2])
+
def set_systray(self, systray):
"""
Sets the systray object to use
@@ -199,17 +225,20 @@ class StatusPanelWidget(QtGui.QWidget):
:type status: str
"""
selected_pixmap = self.ERROR_ICON
+ selected_pixmap_tray = self.ERROR_ICON_TRAY
tray_message = self.tr("Encryption is OFF")
if status in ("WAIT", "AUTH", "GET_CONFIG",
"RECONNECTING", "ASSIGN_IP"):
selected_pixmap = self.CONNECTING_ICON
+ selected_pixmap_tray = self.CONNECTING_ICON_TRAY
tray_message = self.tr("Turning ON")
elif status in ("CONNECTED"):
tray_message = self.tr("Encryption is ON")
selected_pixmap = self.CONNECTED_ICON
+ selected_pixmap_tray = self.CONNECTED_ICON_TRAY
self.set_icon(selected_pixmap)
- self._systray.setIcon(QtGui.QIcon(selected_pixmap))
+ self._systray.setIcon(QtGui.QIcon(selected_pixmap_tray))
self._action_eip_status.setText(tray_message)
def set_provider(self, provider):
diff --git a/src/leap/services/eip/vpnprocess.py b/src/leap/services/eip/vpnprocess.py
index 162dc7f0..f3443533 100644
--- a/src/leap/services/eip/vpnprocess.py
+++ b/src/leap/services/eip/vpnprocess.py
@@ -20,8 +20,8 @@ VPN Manager, spawned in a custom processProtocol.
import logging
import os
import psutil
+import shutil
import socket
-import time
from PySide import QtCore
@@ -143,7 +143,7 @@ class VPN(object):
logger.debug("Process did not died. Sending a SIGKILL.")
self._vpnproc.killProcess()
- def terminate(self):
+ def terminate(self, shutdown=False):
"""
Stops the openvpn subprocess.
@@ -156,15 +156,13 @@ class VPN(object):
# First we try to be polite and send a SIGTERM...
if self._vpnproc:
self._sentterm = True
- self._vpnproc.terminate_openvpn()
+ self._vpnproc.terminate_openvpn(shutdown=shutdown)
# ...but we also trigger a countdown to be unpolite
# if strictly needed.
reactor.callLater(
self.TERMINATE_WAIT, self._kill_if_left_alive)
- # TODO: should also cleanup tempfiles!!!
-
def _start_pollers(self):
"""
Iterate through the registered observers
@@ -482,12 +480,30 @@ class VPNManager(object):
"""
return self._launcher.get_vpn_env(self._providerconfig)
- def terminate_openvpn(self):
+ def terminate_openvpn(self, shutdown=False):
"""
Attempts to terminate openvpn by sending a SIGTERM.
"""
if self.is_connected():
self._send_command("signal SIGTERM")
+ if shutdown:
+ self._cleanup_tempfiles()
+
+ def _cleanup_tempfiles(self):
+ """
+ Remove all temporal files we might have left behind.
+
+ Iif self.port is 'unix', we have created a temporal socket path that,
+ under normal circumstances, we should be able to delete.
+ """
+ if self._socket_port == "unix":
+ logger.debug('cleaning socket file temp folder')
+ tempfolder = os.path.split(self._socket_host)[0] # XXX use `first`
+ if os.path.isdir(tempfolder):
+ try:
+ shutil.rmtree(tempfolder)
+ except OSError:
+ logger.error('could not delete tmpfolder %s' % tempfolder)
# ---------------------------------------------------
# XXX old methods, not adapted to twisted process yet