2017-12-20 22:33:39 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
|
|
|
|
# Copyright (C) 2012 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2017 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# 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 2
|
|
|
|
# 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 Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
import subprocess
|
|
|
|
from datetime import datetime, timedelta
|
2020-07-30 02:40:40 +02:00
|
|
|
from functools import partial
|
2020-12-11 00:53:57 +01:00
|
|
|
from os import path
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2018-06-11 02:46:31 +02:00
|
|
|
from qubesadmin import exc
|
2018-07-18 23:51:37 +02:00
|
|
|
from qubesadmin import utils
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
# pylint: disable=import-error
|
|
|
|
from PyQt5.QtCore import (Qt, QAbstractTableModel, QObject, pyqtSlot, QEvent,
|
|
|
|
QSettings, QRegExp, QSortFilterProxyModel, QSize, QPoint, QTimer)
|
|
|
|
|
|
|
|
# pylint: disable=import-error
|
|
|
|
from PyQt5.QtWidgets import (QLineEdit, QStyledItemDelegate, QToolTip,
|
|
|
|
QMenu, QInputDialog, QMainWindow, QProgressDialog, QStyleOptionViewItem,
|
2020-10-27 23:32:58 +01:00
|
|
|
QMessageBox)
|
2020-07-30 02:40:40 +02:00
|
|
|
|
|
|
|
# pylint: disable=import-error
|
|
|
|
from PyQt5.QtGui import (QIcon, QPixmap, QRegExpValidator, QFont, QColor)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-05-20 21:30:50 +02:00
|
|
|
from qubesmanager.about import AboutDialog
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
from . import ui_qubemanager # pylint: disable=no-name-in-module
|
2018-01-05 17:31:15 +01:00
|
|
|
from . import settings
|
|
|
|
from . import global_settings
|
|
|
|
from . import restore
|
|
|
|
from . import backup
|
2018-10-20 16:43:15 +02:00
|
|
|
from . import create_new_vm
|
2018-01-08 02:46:41 +01:00
|
|
|
from . import log_dialog
|
2018-07-20 00:03:37 +02:00
|
|
|
from . import utils as manager_utils
|
2018-10-20 18:34:15 +02:00
|
|
|
from . import common_threads
|
2020-06-02 19:58:21 +02:00
|
|
|
from . import clone_vm
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
class SearchBox(QLineEdit):
|
2017-12-20 22:33:39 +01:00
|
|
|
def __init__(self, parent=None):
|
2020-08-23 02:53:36 +02:00
|
|
|
super().__init__(parent)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.focusing = False
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
def focusInEvent(self, e): # pylint: disable=invalid-name
|
2020-08-23 02:53:36 +02:00
|
|
|
super().focusInEvent(e)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.selectAll()
|
|
|
|
self.focusing = True
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
def mousePressEvent(self, e): # pylint: disable=invalid-name
|
2020-08-23 02:53:36 +02:00
|
|
|
super().mousePressEvent(e)
|
2017-12-20 22:33:39 +01:00
|
|
|
if self.focusing:
|
|
|
|
self.selectAll()
|
|
|
|
self.focusing = False
|
|
|
|
|
2020-08-12 23:49:06 +02:00
|
|
|
icon_size = QSize(22, 22)
|
2020-07-30 02:40:40 +02:00
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
class StateIconDelegate(QStyledItemDelegate):
|
|
|
|
lastIndex = None
|
|
|
|
def __init__(self):
|
2020-08-23 02:53:36 +02:00
|
|
|
super().__init__()
|
2020-07-30 02:40:40 +02:00
|
|
|
self.stateIcons = {
|
|
|
|
"Running" : QIcon(":/on.png"),
|
|
|
|
"Paused" : QIcon(":/paused.png"),
|
|
|
|
"Suspended" : QIcon(":/paused.png"),
|
|
|
|
"Transient" : QIcon(":/transient.png"),
|
|
|
|
"Halting" : QIcon(":/transient.png"),
|
|
|
|
"Dying" : QIcon(":/transient.png"),
|
|
|
|
"Halted" : QIcon(":/off.png")
|
|
|
|
}
|
|
|
|
self.outdatedIcons = {
|
|
|
|
"update" : QIcon(":/update-recommended.png"),
|
|
|
|
"outdated" : QIcon(":/outdated.png"),
|
|
|
|
"to-be-outdated" : QIcon(":/to-be-outdated.png"),
|
|
|
|
}
|
|
|
|
self.outdatedTooltips = {
|
|
|
|
"update" : self.tr("Updates pending!"),
|
|
|
|
"outdated" : self.tr(
|
|
|
|
"The qube must be restarted for its filesystem to reflect"
|
|
|
|
" the template's recent committed changes."),
|
|
|
|
"to-be-outdated" : self.tr(
|
|
|
|
"The Template must be stopped before changes from its "
|
|
|
|
"current session can be picked up by this qube."),
|
|
|
|
}
|
|
|
|
|
|
|
|
def sizeHint(self, option, index):
|
2020-08-23 02:53:36 +02:00
|
|
|
hint = super().sizeHint(option, index)
|
2020-07-30 02:40:40 +02:00
|
|
|
option = QStyleOptionViewItem(option)
|
|
|
|
option.features |= option.HasDecoration
|
|
|
|
widget = option.widget
|
|
|
|
style = widget.style()
|
|
|
|
iconRect = style.subElementRect(style.SE_ItemViewItemDecoration,
|
|
|
|
option, widget)
|
|
|
|
width = iconRect.width() * 3 # Nº of possible icons
|
|
|
|
hint.setWidth(width)
|
|
|
|
return hint
|
|
|
|
|
|
|
|
def paint(self, qp, option, index):
|
|
|
|
# create a new QStyleOption (*never* use the one given in arguments)
|
|
|
|
option = QStyleOptionViewItem(option)
|
|
|
|
|
|
|
|
widget = option.widget
|
|
|
|
style = widget.style()
|
|
|
|
|
|
|
|
# paint the base item (borders, gradients, selection colors, etc)
|
|
|
|
style.drawControl(style.CE_ItemViewItem, option, qp, widget)
|
|
|
|
|
|
|
|
# "lie" about the decoration, to get a valid icon rectangle (even if we
|
|
|
|
# don't have any "real" icon set for the item)
|
|
|
|
option.features |= option.HasDecoration
|
|
|
|
iconRect = style.subElementRect(style.SE_ItemViewItemDecoration,
|
|
|
|
option, widget)
|
|
|
|
iconSize = iconRect.size()
|
|
|
|
margin = iconRect.left() - option.rect.left()
|
|
|
|
|
|
|
|
qp.save()
|
|
|
|
# ensure that we do not draw outside the item rectangle (and add some
|
|
|
|
# fancy margin on the right
|
|
|
|
qp.setClipRect(option.rect.adjusted(0, 0, -margin, 0))
|
|
|
|
|
|
|
|
# draw the main state icon, assuming all items have one
|
|
|
|
qp.drawPixmap(iconRect,
|
|
|
|
self.stateIcons[index.data()['power']].pixmap(iconSize))
|
|
|
|
|
|
|
|
left = delta = margin + iconRect.width()
|
|
|
|
if index.data()['outdated']:
|
|
|
|
qp.drawPixmap(iconRect.translated(left, 0),
|
|
|
|
self.outdatedIcons[index.data()['outdated']]\
|
|
|
|
.pixmap(iconSize))
|
|
|
|
left += delta
|
|
|
|
|
|
|
|
qp.restore()
|
|
|
|
|
|
|
|
def helpEvent(self, event, view, option, index):
|
|
|
|
if event.type() != QEvent.ToolTip:
|
2020-08-23 02:53:36 +02:00
|
|
|
return super().helpEvent(event, view,
|
2020-07-30 02:40:40 +02:00
|
|
|
option, index)
|
|
|
|
option = QStyleOptionViewItem(option)
|
|
|
|
widget = option.widget
|
|
|
|
style = widget.style()
|
|
|
|
option.features |= option.HasDecoration
|
|
|
|
|
|
|
|
iconRect = style.subElementRect(style.SE_ItemViewItemDecoration,
|
|
|
|
option, widget)
|
|
|
|
iconRect.setTop(option.rect.y())
|
|
|
|
iconRect.setHeight(option.rect.height())
|
|
|
|
|
|
|
|
# similar to what we do in the paint() method
|
|
|
|
if event.pos() in iconRect:
|
|
|
|
# (*) clear any existing tooltip; a single space is better , as
|
|
|
|
# sometimes it's not enough to use an empty string
|
|
|
|
if index != self.lastIndex:
|
|
|
|
QToolTip.showText(QPoint(), ' ')
|
|
|
|
QToolTip.showText(event.globalPos(),
|
|
|
|
index.data()['power'], view)
|
|
|
|
else:
|
|
|
|
margin = iconRect.left() - option.rect.left()
|
|
|
|
left = delta = margin + iconRect.width()
|
|
|
|
|
|
|
|
if index.data()['outdated']:
|
|
|
|
if event.pos() in iconRect.translated(left, 0):
|
|
|
|
# see above (*)
|
|
|
|
if index != self.lastIndex:
|
|
|
|
QToolTip.showText(QPoint(), ' ')
|
|
|
|
QToolTip.showText(event.globalPos(),
|
|
|
|
self.outdatedTooltips[index.data()['outdated']],
|
|
|
|
view)
|
|
|
|
# shift the left *only* if the role is True, otherwise we
|
|
|
|
# can assume that that icon doesn't exist at all
|
|
|
|
left += delta
|
|
|
|
self.lastIndex = index
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=too-many-instance-attributes
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
class VmInfo():
|
|
|
|
def __init__(self, vm):
|
2017-12-20 22:33:39 +01:00
|
|
|
self.vm = vm
|
2020-07-30 02:40:40 +02:00
|
|
|
self.qid = vm.qid
|
|
|
|
self.name = self.vm.name
|
2020-08-03 23:25:20 +02:00
|
|
|
|
|
|
|
self.label = getattr(self.vm, 'label', None)
|
|
|
|
self.klass = getattr(self.vm, 'klass', None)
|
2020-08-06 20:55:28 +02:00
|
|
|
self.icon = getattr(vm, 'icon', 'appvm-black')
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.state = {'power': "", 'outdated': ""}
|
|
|
|
self.updateable = getattr(vm, 'updateable', False)
|
|
|
|
self.update(True)
|
2018-05-07 21:10:15 +02:00
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
def update_power_state(self):
|
2018-07-12 01:17:48 +02:00
|
|
|
try:
|
2020-07-30 02:40:40 +02:00
|
|
|
self.state['power'] = self.vm.get_power_state()
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2020-08-03 23:25:20 +02:00
|
|
|
self.state['power'] = ""
|
2020-07-30 02:40:40 +02:00
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
self.state['outdated'] = ""
|
|
|
|
try:
|
2020-08-11 01:08:48 +02:00
|
|
|
if manager_utils.is_running(self.vm, False):
|
2020-07-30 02:40:40 +02:00
|
|
|
if hasattr(self.vm, 'template') and \
|
2020-08-11 01:08:48 +02:00
|
|
|
manager_utils.is_running(self.vm.template, False):
|
2020-07-30 02:40:40 +02:00
|
|
|
self.state['outdated'] = "to-be-outdated"
|
|
|
|
else:
|
2020-08-11 01:08:48 +02:00
|
|
|
try:
|
2020-08-23 02:53:36 +02:00
|
|
|
if any(vol.is_outdated()
|
|
|
|
for vol in self.vm.volumes.values()):
|
|
|
|
self.state['outdated'] = "outdated"
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
|
|
|
pass
|
2020-07-30 02:40:40 +02:00
|
|
|
|
|
|
|
if self.vm.klass in {'TemplateVM', 'StandaloneVM'} and \
|
2020-08-11 01:08:48 +02:00
|
|
|
manager_utils.get_feature(
|
|
|
|
self.vm, 'updates-available', False):
|
2020-07-30 02:40:40 +02:00
|
|
|
self.state['outdated'] = 'update'
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2020-08-03 23:25:20 +02:00
|
|
|
pass
|
2020-07-30 02:40:40 +02:00
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
def update(self, update_size_on_disk=False, event=None):
|
|
|
|
"""
|
|
|
|
Update VmInfo
|
|
|
|
:param update_size_on_disk: should disk utilization be updated?
|
|
|
|
:param event: name of the event that caused the update, to avoid
|
|
|
|
updating unnecessary properties; if event is none, update everything
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
self.update_power_state()
|
|
|
|
|
|
|
|
if not event or event.endswith(':label'):
|
|
|
|
self.label = getattr(self.vm, 'label', None)
|
2020-08-14 12:38:21 +02:00
|
|
|
self.icon = getattr(self.vm, 'icon', 'appvm-black')
|
2020-08-03 23:25:20 +02:00
|
|
|
|
|
|
|
if not event or event.endswith(':template'):
|
|
|
|
try:
|
|
|
|
self.template = self.vm.template.name
|
|
|
|
except AttributeError:
|
|
|
|
self.template = None
|
|
|
|
|
|
|
|
if not event or event.endswith(':netvm'):
|
|
|
|
self.netvm = getattr(self.vm, 'netvm', None)
|
|
|
|
if self.netvm:
|
|
|
|
self.netvm = str(self.netvm)
|
|
|
|
else:
|
|
|
|
self.netvm = "n/a"
|
|
|
|
try:
|
|
|
|
if hasattr(self.vm, 'netvm') \
|
|
|
|
and self.vm.property_is_default("netvm"):
|
2020-07-30 02:40:40 +02:00
|
|
|
self.netvm = "default (" + self.netvm + ")"
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2020-08-03 23:25:20 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
if not event or event.endswith(':internal'):
|
2020-08-11 01:08:48 +02:00
|
|
|
self.internal = manager_utils.get_boolean_feature(
|
|
|
|
self.vm, 'internal')
|
2020-08-03 23:25:20 +02:00
|
|
|
|
|
|
|
if not event or event.endswith(':ip'):
|
|
|
|
self.ip = getattr(self.vm, 'ip', "n/a")
|
|
|
|
|
|
|
|
if not event or event.endswith(':include_in_backups'):
|
|
|
|
self.inc_backup = getattr(self.vm, 'include_in_backups', None)
|
|
|
|
|
|
|
|
if not event or event.endswith(':backup_timestamp'):
|
|
|
|
self.last_backup = getattr(self.vm, 'backup_timestamp', None)
|
|
|
|
if self.last_backup:
|
|
|
|
self.last_backup = str(datetime.fromtimestamp(self.last_backup))
|
|
|
|
|
|
|
|
if not event or event.endswith(':default_dispvm'):
|
|
|
|
self.dvm = getattr(self.vm, 'default_dispvm', None)
|
|
|
|
try:
|
2020-07-30 02:40:40 +02:00
|
|
|
if self.vm.property_is_default("default_dispvm"):
|
|
|
|
self.dvm = "default (" + str(self.dvm) + ")"
|
|
|
|
elif self.dvm is not None:
|
2020-08-03 23:25:20 +02:00
|
|
|
self.dvm = str(self.dvm)
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
|
|
|
if self.dvm is not None:
|
|
|
|
self.dvm = str(self.dvm)
|
2020-08-03 23:25:20 +02:00
|
|
|
|
|
|
|
if not event or event.endswith(':template_for_dispvms'):
|
|
|
|
self.dvm_template = getattr(self.vm, 'template_for_dispvms', None)
|
|
|
|
|
|
|
|
if self.vm.klass != 'AdminVM' and update_size_on_disk:
|
|
|
|
try:
|
2020-07-30 02:40:40 +02:00
|
|
|
self.disk_float = float(self.vm.get_disk_utilization())
|
|
|
|
self.disk = str(round(self.disk_float/(1024*1024), 2)) + " MiB"
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2020-08-03 23:25:20 +02:00
|
|
|
self.disk_float = None
|
|
|
|
self.disk = None
|
|
|
|
|
|
|
|
if self.vm.klass != 'AdminVM':
|
|
|
|
self.virt_mode = getattr(self.vm, 'virt_mode', None)
|
|
|
|
else:
|
|
|
|
self.virt_mode = None
|
|
|
|
self.disk = "n/a"
|
2020-07-30 02:40:40 +02:00
|
|
|
|
2018-07-12 01:17:48 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
class QubesCache(QAbstractTableModel):
|
|
|
|
def __init__(self, qubes_app):
|
|
|
|
QAbstractTableModel.__init__(self)
|
|
|
|
self._qubes_app = qubes_app
|
|
|
|
self._info_list = []
|
|
|
|
self._info_by_id = {}
|
|
|
|
|
|
|
|
def add_vm(self, vm):
|
|
|
|
vm_info = VmInfo(vm)
|
|
|
|
self._info_list.append(vm_info)
|
|
|
|
self._info_by_id[vm.qid] = vm_info
|
|
|
|
|
|
|
|
def remove_vm(self, name):
|
|
|
|
vm_info = self.get_vm(name=name)
|
|
|
|
self._info_list.remove(vm_info)
|
|
|
|
del self._info_by_id[vm_info.qid]
|
|
|
|
|
|
|
|
def get_vm(self, row=None, qid=None, name=None):
|
|
|
|
if row is not None:
|
|
|
|
return self._info_list[row]
|
|
|
|
if qid is not None:
|
|
|
|
return self._info_by_id[qid]
|
|
|
|
return next(x for x in self._info_list if x.name == name)
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return len(self._info_list)
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return iter(self._info_list)
|
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
class QubesTableModel(QAbstractTableModel):
|
|
|
|
def __init__(self, qubes_cache):
|
|
|
|
QAbstractTableModel.__init__(self)
|
|
|
|
self.qubes_cache = qubes_cache
|
|
|
|
self.template = {}
|
|
|
|
self.klass_pixmap = {}
|
|
|
|
self.label_pixmap = {}
|
|
|
|
self.columns_indices = [
|
|
|
|
"Type",
|
|
|
|
"Label",
|
|
|
|
"Name",
|
|
|
|
"State",
|
|
|
|
"Template",
|
|
|
|
"NetVM",
|
|
|
|
"Disk Usage",
|
|
|
|
"Internal",
|
|
|
|
"IP",
|
2020-12-12 14:18:34 +01:00
|
|
|
"Backup",
|
2020-07-30 02:40:40 +02:00
|
|
|
"Last backup",
|
|
|
|
"Default DispVM",
|
|
|
|
"Is DVM Template",
|
|
|
|
"Virt Mode"
|
|
|
|
]
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def rowCount(self, _):
|
|
|
|
return len(self.qubes_cache)
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def columnCount(self, _):
|
|
|
|
return len(self.columns_indices)
|
|
|
|
|
|
|
|
# pylint: disable=too-many-return-statements
|
|
|
|
def data(self, index, role):
|
|
|
|
if not index.isValid():
|
|
|
|
return None
|
|
|
|
|
|
|
|
col = index.column()
|
|
|
|
row = index.row()
|
|
|
|
|
|
|
|
col_name = self.columns_indices[col]
|
|
|
|
vm = self.qubes_cache.get_vm(row)
|
|
|
|
|
|
|
|
if role == Qt.DisplayRole:
|
|
|
|
if col in [0, 1]:
|
|
|
|
return None
|
|
|
|
if col_name == "Name":
|
|
|
|
return vm.name
|
|
|
|
if col_name == "State":
|
|
|
|
return vm.state
|
|
|
|
if col_name == "Template":
|
|
|
|
if vm.template is None:
|
|
|
|
return vm.klass
|
|
|
|
return vm.template
|
|
|
|
if col_name == "NetVM":
|
|
|
|
return vm.netvm
|
|
|
|
if col_name == "Disk Usage":
|
|
|
|
return vm.disk
|
|
|
|
if col_name == "Internal":
|
|
|
|
return "Yes" if vm.internal else ""
|
|
|
|
if col_name == "IP":
|
|
|
|
return vm.ip
|
|
|
|
if col_name == "Last backup":
|
|
|
|
return vm.last_backup
|
|
|
|
if col_name == "Default DispVM":
|
|
|
|
return vm.dvm
|
|
|
|
if col_name == "Is DVM Template":
|
|
|
|
return "Yes" if vm.dvm_template else ""
|
|
|
|
if col_name == "Virt Mode":
|
|
|
|
return vm.virt_mode
|
|
|
|
if role == Qt.DecorationRole:
|
|
|
|
if col_name == "Type":
|
|
|
|
try:
|
|
|
|
return self.klass_pixmap[vm.klass]
|
|
|
|
except KeyError:
|
|
|
|
pixmap = QPixmap()
|
|
|
|
icon_name = ":/"+vm.klass.lower()+".png"
|
|
|
|
icon_name = icon_name.replace("adminvm", "dom0")
|
|
|
|
icon_name = icon_name.replace("dispvm", "appvm")
|
|
|
|
pixmap.load(icon_name)
|
|
|
|
self.klass_pixmap[vm.klass] = pixmap.scaled(icon_size)
|
|
|
|
return self.klass_pixmap[vm.klass]
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2020-08-03 23:25:20 +02:00
|
|
|
return None
|
2020-07-30 02:40:40 +02:00
|
|
|
if col_name == "Label":
|
|
|
|
try:
|
2020-08-06 20:55:28 +02:00
|
|
|
return self.label_pixmap[vm.icon]
|
|
|
|
except (KeyError, AttributeError):
|
|
|
|
icon = QIcon.fromTheme(vm.icon)
|
|
|
|
self.label_pixmap[vm.icon] = icon.pixmap(icon_size)
|
|
|
|
return self.label_pixmap[vm.icon]
|
2020-11-14 14:10:24 +01:00
|
|
|
if role == Qt.CheckStateRole:
|
2020-12-12 14:18:34 +01:00
|
|
|
if col_name == "Backup":
|
2020-11-14 14:10:24 +01:00
|
|
|
return Qt.Checked if vm.inc_backup else Qt.Unchecked
|
2020-07-30 02:40:40 +02:00
|
|
|
if role == Qt.FontRole:
|
|
|
|
if col_name == "Template":
|
|
|
|
if vm.template is None:
|
|
|
|
font = QFont()
|
|
|
|
font.setItalic(True)
|
|
|
|
return font
|
|
|
|
if role == Qt.ForegroundRole:
|
|
|
|
if col_name == "Template":
|
|
|
|
if vm.template is None:
|
|
|
|
return QColor("gray")
|
|
|
|
# Used for get VM Object
|
|
|
|
if role == Qt.UserRole:
|
|
|
|
return vm
|
|
|
|
# Used for sorting
|
|
|
|
if role == Qt.UserRole + 1:
|
2020-08-05 00:22:04 +02:00
|
|
|
if vm.klass == 'AdminVM':
|
2020-07-30 02:40:40 +02:00
|
|
|
return ""
|
|
|
|
if col_name == "Type":
|
|
|
|
return vm.klass
|
|
|
|
if col_name == "Label":
|
2020-08-03 23:25:20 +02:00
|
|
|
return str(vm.label)
|
2020-07-30 02:40:40 +02:00
|
|
|
if col_name == "State":
|
|
|
|
return str(vm.state)
|
|
|
|
if col_name == "Disk Usage":
|
|
|
|
return vm.disk_float
|
|
|
|
return self.data(index, Qt.DisplayRole)
|
|
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def headerData(self, col, orientation, role):
|
|
|
|
if col < 2:
|
|
|
|
return None
|
|
|
|
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
|
|
|
|
return self.columns_indices[col]
|
|
|
|
return None
|
|
|
|
|
2020-11-14 14:10:24 +01:00
|
|
|
def setData(self, index, value, role=Qt.EditRole):
|
|
|
|
if not index.isValid():
|
|
|
|
return False
|
2020-11-14 16:12:11 +01:00
|
|
|
|
2020-11-14 14:10:24 +01:00
|
|
|
if role == Qt.CheckStateRole:
|
|
|
|
col_name = self.columns_indices[index.column()]
|
2020-12-12 14:18:34 +01:00
|
|
|
if col_name == "Backup":
|
2020-11-14 14:10:24 +01:00
|
|
|
vm = self.qubes_cache.get_vm(index.row())
|
2020-12-12 14:22:15 +01:00
|
|
|
vm.vm.include_in_backups = (value == Qt.Checked)
|
|
|
|
vm.inc_backup = (value == Qt.Checked)
|
2020-11-14 14:10:24 +01:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def flags(self, index):
|
|
|
|
if not index.isValid():
|
|
|
|
return False
|
|
|
|
|
2020-11-15 19:08:22 +01:00
|
|
|
def_flags = QAbstractTableModel.flags(self, index)
|
2020-12-12 14:18:34 +01:00
|
|
|
if self.columns_indices[index.column()] == "Backup":
|
2020-11-15 19:08:22 +01:00
|
|
|
return def_flags | Qt.ItemIsUserCheckable
|
|
|
|
return def_flags
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-05 17:31:15 +01:00
|
|
|
vm_restart_check_timeout = 1000 # in msec
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
class VmShutdownMonitor(QObject):
|
2021-02-24 16:18:31 +01:00
|
|
|
def __init__(self, vm, check_time=vm_restart_check_timeout,
|
2018-01-05 17:31:15 +01:00
|
|
|
and_restart=False, caller=None):
|
2020-07-30 02:40:40 +02:00
|
|
|
QObject.__init__(self)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.vm = vm
|
2021-02-24 16:18:31 +01:00
|
|
|
self.shutdown_timeout = vm.shutdown_timeout
|
2017-12-20 22:33:39 +01:00
|
|
|
self.check_time = check_time
|
|
|
|
self.and_restart = and_restart
|
|
|
|
self.shutdown_started = datetime.now()
|
|
|
|
self.caller = caller
|
|
|
|
|
|
|
|
def restart_vm_if_needed(self):
|
|
|
|
if self.and_restart and self.caller:
|
|
|
|
self.caller.start_vm(self.vm)
|
|
|
|
|
|
|
|
def check_again_later(self):
|
|
|
|
# noinspection PyTypeChecker,PyCallByClass
|
2020-07-30 02:40:40 +02:00
|
|
|
QTimer.singleShot(self.check_time, self.check_if_vm_has_shutdown)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
def timeout_reached(self):
|
|
|
|
actual = datetime.now() - self.shutdown_started
|
2021-02-27 13:19:09 +01:00
|
|
|
allowed = timedelta(seconds=self.shutdown_timeout)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
return actual > allowed
|
|
|
|
|
|
|
|
def check_if_vm_has_shutdown(self):
|
|
|
|
vm = self.vm
|
2020-08-11 01:08:48 +02:00
|
|
|
vm_is_running = manager_utils.is_running(vm, False)
|
2018-01-10 01:54:30 +01:00
|
|
|
try:
|
|
|
|
vm_start_time = datetime.fromtimestamp(float(vm.start_time))
|
2018-02-09 22:08:07 +01:00
|
|
|
except (AttributeError, TypeError, ValueError):
|
2018-01-10 01:54:30 +01:00
|
|
|
vm_start_time = None
|
|
|
|
|
2018-01-05 17:31:15 +01:00
|
|
|
if vm_is_running and vm_start_time \
|
|
|
|
and vm_start_time < self.shutdown_started:
|
2017-12-20 22:33:39 +01:00
|
|
|
if self.timeout_reached():
|
2019-05-22 23:10:09 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
msgbox = QMessageBox(self.caller)
|
|
|
|
msgbox.setIcon(QMessageBox.Question)
|
2019-05-22 23:10:09 +02:00
|
|
|
msgbox.setWindowTitle(self.tr("Qube Shutdown"))
|
|
|
|
msgbox.setText(self.tr(
|
2018-01-08 03:01:02 +01:00
|
|
|
"The Qube <b>'{0}'</b> hasn't shutdown within the last "
|
2018-01-05 17:31:15 +01:00
|
|
|
"{1} seconds, do you want to kill it?<br>").format(
|
2021-02-24 16:18:31 +01:00
|
|
|
vm.name, self.shutdown_timeout))
|
2019-05-22 23:10:09 +02:00
|
|
|
kill_button = msgbox.addButton(
|
2020-07-30 02:40:40 +02:00
|
|
|
self.tr("Kill it!"), QMessageBox.YesRole)
|
2019-05-22 23:10:09 +02:00
|
|
|
wait_button = msgbox.addButton(
|
2017-12-20 22:33:39 +01:00
|
|
|
self.tr("Wait another {0} seconds...").format(
|
2021-02-24 16:18:31 +01:00
|
|
|
self.shutdown_timeout),
|
2020-07-30 02:40:40 +02:00
|
|
|
QMessageBox.NoRole)
|
2020-10-26 16:25:47 +01:00
|
|
|
ignore_button = msgbox.addButton(self.tr("Don't ask again"),
|
|
|
|
QMessageBox.RejectRole)
|
2019-05-22 23:10:09 +02:00
|
|
|
msgbox.setDefaultButton(wait_button)
|
2020-10-26 16:25:47 +01:00
|
|
|
msgbox.setEscapeButton(ignore_button)
|
|
|
|
msgbox.setWindowFlags(
|
|
|
|
msgbox.windowFlags() | Qt.CustomizeWindowHint)
|
|
|
|
msgbox.setWindowFlags(
|
|
|
|
msgbox.windowFlags() & ~Qt.WindowCloseButtonHint)
|
2019-05-22 23:10:09 +02:00
|
|
|
msgbox.exec_()
|
|
|
|
msgbox.deleteLater()
|
|
|
|
|
|
|
|
if msgbox.clickedButton() is kill_button:
|
2018-03-24 22:53:22 +01:00
|
|
|
try:
|
|
|
|
vm.kill()
|
|
|
|
except exc.QubesVMNotStartedError:
|
|
|
|
# the VM shut down while the user was thinking about
|
|
|
|
# shutting it down
|
|
|
|
pass
|
2017-12-20 22:33:39 +01:00
|
|
|
self.restart_vm_if_needed()
|
2020-10-26 16:25:47 +01:00
|
|
|
elif msgbox.clickedButton() is ignore_button:
|
|
|
|
return
|
2017-12-20 22:33:39 +01:00
|
|
|
else:
|
|
|
|
self.shutdown_started = datetime.now()
|
|
|
|
self.check_again_later()
|
|
|
|
else:
|
|
|
|
self.check_again_later()
|
|
|
|
else:
|
|
|
|
if vm_is_running:
|
|
|
|
# Due to unknown reasons, Xen sometimes reports that a domain
|
|
|
|
# is running even though its start-up timestamp is not valid.
|
|
|
|
# Make sure that "restart_vm_if_needed" is not called until
|
|
|
|
# the domain has been completely shut down according to Xen.
|
|
|
|
self.check_again_later()
|
|
|
|
return
|
|
|
|
|
|
|
|
self.restart_vm_if_needed()
|
|
|
|
|
2018-01-05 17:31:15 +01:00
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-04-03 20:34:01 +02:00
|
|
|
class StartVMThread(common_threads.QubesThread):
|
2018-10-18 14:11:25 +02:00
|
|
|
def run(self):
|
|
|
|
try:
|
|
|
|
self.vm.start()
|
|
|
|
except exc.QubesException as ex:
|
2018-10-22 20:00:37 +02:00
|
|
|
self.msg = ("Error starting Qube!", str(ex))
|
2018-10-18 14:11:25 +02:00
|
|
|
|
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-04-03 20:34:01 +02:00
|
|
|
class UpdateVMThread(common_threads.QubesThread):
|
2018-10-18 14:11:25 +02:00
|
|
|
def run(self):
|
|
|
|
try:
|
2020-08-05 00:22:04 +02:00
|
|
|
if self.vm.klass == 'AdminVM':
|
2018-10-18 14:11:25 +02:00
|
|
|
subprocess.check_call(
|
|
|
|
["/usr/bin/qubes-dom0-update", "--clean", "--gui"])
|
|
|
|
else:
|
2020-08-11 01:08:48 +02:00
|
|
|
if not manager_utils.is_running(self.vm, False):
|
|
|
|
try:
|
|
|
|
self.vm.start()
|
|
|
|
except exc.QubesDaemonAccessError:
|
|
|
|
# permission denied, let us hope for the best
|
|
|
|
pass
|
2019-01-23 05:05:03 +01:00
|
|
|
# apply DSA-4371
|
|
|
|
with open('/usr/libexec/qubes-manager/dsa-4371-update', 'rb') \
|
|
|
|
as dsa4371update:
|
|
|
|
stdout, stderr = self.vm.run_service_for_stdio(
|
|
|
|
"qubes.VMShell",
|
|
|
|
user="root",
|
|
|
|
input=dsa4371update.read())
|
|
|
|
if stdout == b'changed=yes\n':
|
2019-05-22 23:10:09 +02:00
|
|
|
subprocess.call(
|
|
|
|
['notify-send', '-i', 'dialog-information',
|
2019-10-23 18:18:39 +02:00
|
|
|
self.tr('Debian DSA-4371 fix installed in {}').format(
|
2019-01-23 05:05:03 +01:00
|
|
|
self.vm.name)])
|
|
|
|
elif stdout == b'changed=no\n':
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise exc.QubesException(
|
2019-10-23 18:18:39 +02:00
|
|
|
self.tr("Failed to apply DSA-4371 fix: {}").format(
|
2019-01-23 05:05:03 +01:00
|
|
|
stderr.decode('ascii')))
|
2019-05-22 23:10:09 +02:00
|
|
|
self.vm.run_service("qubes.InstallUpdatesGUI",
|
|
|
|
user="root", wait=False)
|
2018-10-18 14:11:25 +02:00
|
|
|
except (ChildProcessError, exc.QubesException) as ex:
|
2019-10-23 18:18:39 +02:00
|
|
|
self.msg = (self.tr("Error on qube update!"), str(ex))
|
2018-10-18 14:11:25 +02:00
|
|
|
|
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-04-03 20:34:01 +02:00
|
|
|
class RunCommandThread(common_threads.QubesThread):
|
2018-10-18 14:11:25 +02:00
|
|
|
def __init__(self, vm, command_to_run):
|
2020-08-23 02:53:36 +02:00
|
|
|
super().__init__(vm)
|
2018-10-18 14:11:25 +02:00
|
|
|
self.command_to_run = command_to_run
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
try:
|
|
|
|
self.vm.run(self.command_to_run)
|
|
|
|
except (ChildProcessError, exc.QubesException) as ex:
|
2019-10-23 18:18:39 +02:00
|
|
|
self.msg = (self.tr("Error while running command!"), str(ex))
|
2018-10-18 14:11:25 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
class QubesProxyModel(QSortFilterProxyModel):
|
2020-10-27 00:46:24 +01:00
|
|
|
def __init__(self, window):
|
|
|
|
super().__init__()
|
|
|
|
self.window = window
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
def lessThan(self, left, right):
|
|
|
|
if left.data(self.sortRole()) != right.data(self.sortRole()):
|
|
|
|
return super().lessThan(left, right)
|
|
|
|
|
|
|
|
left_vm = left.data(Qt.UserRole)
|
|
|
|
right_vm = right.data(Qt.UserRole)
|
|
|
|
|
|
|
|
return left_vm.name.lower() < right_vm.name.lower()
|
2018-10-18 14:11:25 +02:00
|
|
|
|
2020-10-27 00:46:24 +01:00
|
|
|
# pylint: disable=too-many-return-statements
|
|
|
|
def filterAcceptsRow(self, sourceRow, sourceParent):
|
|
|
|
if self.window.show_all.isChecked():
|
|
|
|
return super().filterAcceptsRow(sourceRow, sourceParent)
|
|
|
|
|
|
|
|
index = self.sourceModel().index(sourceRow, 0, sourceParent)
|
|
|
|
vm = self.sourceModel().data(index, Qt.UserRole)
|
|
|
|
|
|
|
|
if self.window.show_running.isChecked() and \
|
2021-02-17 10:55:20 +01:00
|
|
|
vm.state['power'] != 'Halted':
|
2020-10-27 00:46:24 +01:00
|
|
|
return super().filterAcceptsRow(sourceRow, sourceParent)
|
|
|
|
if self.window.show_halted.isChecked() and \
|
|
|
|
vm.state['power'] == 'Halted':
|
|
|
|
return super().filterAcceptsRow(sourceRow, sourceParent)
|
|
|
|
if self.window.show_network.isChecked() and \
|
|
|
|
getattr(vm.vm, 'provides_network', False):
|
|
|
|
return super().filterAcceptsRow(sourceRow, sourceParent)
|
|
|
|
if self.window.show_templates.isChecked() and vm.klass == 'TemplateVM':
|
|
|
|
return super().filterAcceptsRow(sourceRow, sourceParent)
|
|
|
|
if self.window.show_standalone.isChecked() \
|
|
|
|
and vm.klass == 'StandaloneVM':
|
|
|
|
return super().filterAcceptsRow(sourceRow, sourceParent)
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
|
2017-12-20 22:33:39 +01:00
|
|
|
# suppress saving settings while initializing widgets
|
|
|
|
settings_loaded = False
|
2020-07-30 02:40:40 +02:00
|
|
|
|
|
|
|
def __init__(self, qt_app, qubes_app, dispatcher, _parent=None):
|
2020-08-23 02:53:36 +02:00
|
|
|
super().__init__()
|
2017-12-20 22:33:39 +01:00
|
|
|
self.setupUi(self)
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.manager_settings = QSettings(self)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
self.qubes_app = qubes_app
|
|
|
|
self.qt_app = qt_app
|
2018-01-05 17:31:15 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
self.searchbox = SearchBox()
|
2020-07-30 02:40:40 +02:00
|
|
|
self.searchbox.setValidator(QRegExpValidator(
|
|
|
|
QRegExp("[a-zA-Z0-9_-]*", Qt.CaseInsensitive), None))
|
|
|
|
self.searchbox.textChanged.connect(self.do_search)
|
2020-10-27 00:46:24 +01:00
|
|
|
self.searchContainer.insertWidget(1, self.searchbox)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.settings_windows = {}
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
self.frame_width = 0
|
|
|
|
self.frame_height = 0
|
|
|
|
|
2020-11-10 00:12:13 +01:00
|
|
|
self.init_template_menu()
|
2020-11-10 00:50:43 +01:00
|
|
|
self.init_network_menu()
|
2020-10-27 00:46:24 +01:00
|
|
|
self.__init_context_menu()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.tools_context_menu = QMenu(self)
|
2017-12-20 22:33:39 +01:00
|
|
|
self.tools_context_menu.addAction(self.action_toolbar)
|
|
|
|
self.tools_context_menu.addAction(self.action_menubar)
|
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.menubar.customContextMenuRequested.connect(
|
2020-07-30 02:40:40 +02:00
|
|
|
lambda pos: self.open_tools_context_menu(self.menubar, pos))
|
2019-05-22 23:10:09 +02:00
|
|
|
self.toolbar.customContextMenuRequested.connect(
|
2020-07-30 02:40:40 +02:00
|
|
|
lambda pos: self.open_tools_context_menu(self.toolbar, pos))
|
|
|
|
self.action_menubar.toggled.connect(self.showhide_menubar)
|
|
|
|
self.action_toolbar.toggled.connect(self.showhide_toolbar)
|
2020-12-05 12:28:36 +01:00
|
|
|
self.action_show_logs.triggered.connect(self.show_log)
|
2020-11-04 23:37:21 +01:00
|
|
|
self.action_compact_view.toggled.connect(self.set_compactview)
|
2019-05-22 23:10:09 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.table.resizeColumnsToContents()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.update_size_on_disk = False
|
|
|
|
self.shutdown_monitor = {}
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.qubes_cache = QubesCache(qubes_app)
|
|
|
|
self.fill_cache()
|
|
|
|
self.qubes_model = QubesTableModel(self.qubes_cache)
|
|
|
|
|
2020-10-27 00:46:24 +01:00
|
|
|
self.proxy = QubesProxyModel(self)
|
2020-07-30 02:40:40 +02:00
|
|
|
self.proxy.setSourceModel(self.qubes_model)
|
|
|
|
self.proxy.setSortRole(Qt.UserRole + 1)
|
|
|
|
self.proxy.setSortCaseSensitivity(Qt.CaseInsensitive)
|
|
|
|
self.proxy.setFilterKeyColumn(2)
|
|
|
|
self.proxy.setFilterCaseSensitivity(Qt.CaseInsensitive)
|
|
|
|
self.proxy.layoutChanged.connect(self.save_sorting)
|
2020-11-07 16:04:11 +01:00
|
|
|
self.proxy.layoutChanged.connect(self.update_template_menu)
|
2020-11-13 23:52:49 +01:00
|
|
|
self.proxy.layoutChanged.connect(self.update_network_menu)
|
2020-07-30 02:40:40 +02:00
|
|
|
|
2020-10-27 00:46:24 +01:00
|
|
|
self.show_running.stateChanged.connect(self.invalidate)
|
|
|
|
self.show_halted.stateChanged.connect(self.invalidate)
|
|
|
|
self.show_network.stateChanged.connect(self.invalidate)
|
|
|
|
self.show_templates.stateChanged.connect(self.invalidate)
|
|
|
|
self.show_standalone.stateChanged.connect(self.invalidate)
|
|
|
|
self.show_all.stateChanged.connect(self.invalidate)
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.table.setModel(self.proxy)
|
|
|
|
self.table.setItemDelegateForColumn(3, StateIconDelegate())
|
|
|
|
self.table.resizeColumnsToContents()
|
|
|
|
selection_model = self.table.selectionModel()
|
|
|
|
selection_model.selectionChanged.connect(self.table_selection_changed)
|
|
|
|
|
|
|
|
self.table.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
|
|
self.table.customContextMenuRequested.connect(self.open_context_menu)
|
|
|
|
|
|
|
|
# Create view menu
|
|
|
|
for col_no in range(len(self.qubes_model.columns_indices)):
|
|
|
|
column = self.qubes_model.columns_indices[col_no]
|
|
|
|
action = self.menu_view.addAction(column)
|
|
|
|
action.setData(column)
|
|
|
|
action.setCheckable(True)
|
|
|
|
action.toggled.connect(partial(self.showhide_column, col_no))
|
|
|
|
|
|
|
|
self.menu_view.addSeparator()
|
|
|
|
self.menu_view.addAction(self.action_toolbar)
|
|
|
|
self.menu_view.addAction(self.action_menubar)
|
2020-11-04 23:37:21 +01:00
|
|
|
self.menu_view.addSeparator()
|
|
|
|
self.menu_view.addAction(self.action_compact_view)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2019-04-30 16:29:50 +02:00
|
|
|
try:
|
|
|
|
self.load_manager_settings()
|
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
2020-07-30 02:40:40 +02:00
|
|
|
QMessageBox.warning(
|
2019-05-22 23:10:09 +02:00
|
|
|
self,
|
2019-04-30 16:29:50 +02:00
|
|
|
self.tr("Manager settings unreadable"),
|
|
|
|
self.tr("Qube Manager settings cannot be parsed. Previously "
|
|
|
|
"saved display settings may not be restored "
|
|
|
|
"correctly.\nError: {}".format(str(ex))))
|
|
|
|
|
|
|
|
self.settings_loaded = True
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-09-12 16:32:37 +02:00
|
|
|
# Connect events
|
2018-09-10 17:48:14 +02:00
|
|
|
self.dispatcher = dispatcher
|
|
|
|
dispatcher.add_handler('domain-pre-start',
|
|
|
|
self.on_domain_status_changed)
|
|
|
|
dispatcher.add_handler('domain-start', self.on_domain_status_changed)
|
|
|
|
dispatcher.add_handler('domain-start-failed',
|
|
|
|
self.on_domain_status_changed)
|
|
|
|
dispatcher.add_handler('domain-stopped', self.on_domain_status_changed)
|
2018-10-20 23:01:35 +02:00
|
|
|
dispatcher.add_handler('domain-pre-shutdown',
|
2019-05-22 23:10:09 +02:00
|
|
|
self.on_domain_status_changed)
|
2018-09-10 17:48:14 +02:00
|
|
|
dispatcher.add_handler('domain-shutdown', self.on_domain_status_changed)
|
2018-10-20 18:34:15 +02:00
|
|
|
dispatcher.add_handler('domain-paused', self.on_domain_status_changed)
|
|
|
|
dispatcher.add_handler('domain-unpaused', self.on_domain_status_changed)
|
2018-09-10 17:48:14 +02:00
|
|
|
|
|
|
|
dispatcher.add_handler('domain-add', self.on_domain_added)
|
|
|
|
dispatcher.add_handler('domain-delete', self.on_domain_removed)
|
|
|
|
|
|
|
|
dispatcher.add_handler('property-set:*',
|
|
|
|
self.on_domain_changed)
|
|
|
|
dispatcher.add_handler('property-del:*',
|
|
|
|
self.on_domain_changed)
|
|
|
|
dispatcher.add_handler('property-load',
|
|
|
|
self.on_domain_changed)
|
2020-08-03 23:25:20 +02:00
|
|
|
dispatcher.add_handler('domain-feature-set:internal',
|
|
|
|
self.on_domain_changed)
|
|
|
|
dispatcher.add_handler('domain-feature-delete:internal',
|
|
|
|
self.on_domain_changed)
|
2018-05-07 21:10:15 +02:00
|
|
|
|
2019-12-05 22:32:55 +01:00
|
|
|
dispatcher.add_handler('domain-feature-set:updates-available',
|
|
|
|
self.on_domain_updates_available)
|
|
|
|
dispatcher.add_handler('domain-feature-delete:updates-available',
|
|
|
|
self.on_domain_updates_available)
|
|
|
|
|
2018-10-18 14:11:25 +02:00
|
|
|
# It needs to store threads until they finish
|
|
|
|
self.threads_list = []
|
2018-10-20 22:09:39 +02:00
|
|
|
self.progress = None
|
2018-10-18 14:11:25 +02:00
|
|
|
|
2018-05-31 00:11:30 +02:00
|
|
|
self.check_updates()
|
2018-05-09 14:36:39 +02:00
|
|
|
|
2020-11-14 12:40:23 +01:00
|
|
|
def change_template(self, template):
|
2020-11-18 12:22:48 +01:00
|
|
|
selected_vms = self.get_selected_vms()
|
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Template Change Confirmation"),
|
|
|
|
self.tr("Do you want to change '{0}'<br>"
|
|
|
|
"to Template <b>'{1}'</b>?").format(
|
|
|
|
', '.join(vm.name for vm in selected_vms), template),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
2020-12-11 23:48:16 +01:00
|
|
|
errors = []
|
2020-11-18 12:22:48 +01:00
|
|
|
for info in selected_vms:
|
2020-12-11 00:38:06 +01:00
|
|
|
try:
|
|
|
|
info.vm.template = template
|
2020-12-11 23:48:16 +01:00
|
|
|
except exc.QubesValueError as ex:
|
2020-12-12 00:19:30 +01:00
|
|
|
errors.append((info.name, str(ex)))
|
2020-12-11 00:38:06 +01:00
|
|
|
|
2020-12-11 23:48:16 +01:00
|
|
|
for error in errors:
|
2020-12-16 11:30:39 +01:00
|
|
|
QMessageBox.warning(self, self.tr("{0} template change failed!")
|
2020-12-12 00:19:30 +01:00
|
|
|
.format(error[0]), error[1])
|
|
|
|
|
2020-11-14 12:40:23 +01:00
|
|
|
|
|
|
|
def change_network(self, netvm_name):
|
2020-11-18 12:27:59 +01:00
|
|
|
selected_vms = self.get_selected_vms()
|
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Network Change Confirmation"),
|
|
|
|
self.tr("Do you want to change '{0}'<br>"
|
|
|
|
"to Network <b>'{1}'</b>?").format(
|
|
|
|
', '.join(vm.name for vm in selected_vms), netvm_name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
|
|
|
if reply != QMessageBox.Yes:
|
|
|
|
return
|
|
|
|
|
2021-01-09 00:42:47 +01:00
|
|
|
if netvm_name not in [None, 'default']:
|
2020-12-11 23:48:16 +01:00
|
|
|
check_power = any(info.state['power'] == 'Running' for info
|
|
|
|
in self.get_selected_vms())
|
|
|
|
netvm = self.qubes_cache.get_vm(name=netvm_name)
|
|
|
|
if check_power and netvm.state['power'] != 'Running':
|
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Qube Start Confirmation"),
|
|
|
|
self.tr("<br>Can not change netvm to a halted Qube.<br>"
|
|
|
|
"Do you want to start the Qube <b>'{0}'</b>?").format(
|
|
|
|
netvm_name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
2020-12-12 00:34:41 +01:00
|
|
|
self.start_vm(netvm.vm, True)
|
2020-12-11 23:48:16 +01:00
|
|
|
else:
|
|
|
|
return
|
2020-12-11 00:38:06 +01:00
|
|
|
|
2020-12-11 23:48:16 +01:00
|
|
|
errors = []
|
|
|
|
for info in self.get_selected_vms():
|
|
|
|
try:
|
2021-01-09 00:42:47 +01:00
|
|
|
if netvm_name == 'default':
|
|
|
|
delattr(info.vm, 'netvm')
|
|
|
|
else:
|
|
|
|
info.vm.netvm = netvm_name
|
2020-12-11 23:48:16 +01:00
|
|
|
except exc.QubesValueError as ex:
|
2020-12-12 00:19:30 +01:00
|
|
|
errors.append((info.name, str(ex)))
|
2020-12-11 23:48:16 +01:00
|
|
|
|
|
|
|
for error in errors:
|
2020-12-16 11:30:39 +01:00
|
|
|
QMessageBox.warning(self, self.tr("{0} network change failed!")
|
2020-12-12 00:19:30 +01:00
|
|
|
.format(error[0]), error[1])
|
2020-12-11 00:38:06 +01:00
|
|
|
|
2020-11-14 12:40:23 +01:00
|
|
|
|
2020-10-27 00:46:24 +01:00
|
|
|
def __init_context_menu(self):
|
|
|
|
self.context_menu = QMenu(self)
|
|
|
|
self.context_menu.addAction(self.action_settings)
|
2020-12-11 00:07:51 +01:00
|
|
|
self.context_menu.addAction(self.template_menu.menuAction())
|
|
|
|
self.context_menu.addAction(self.network_menu.menuAction())
|
2020-10-27 00:46:24 +01:00
|
|
|
self.context_menu.addAction(self.action_editfwrules)
|
|
|
|
self.context_menu.addAction(self.action_appmenus)
|
|
|
|
self.context_menu.addAction(self.action_set_keyboard_layout)
|
|
|
|
self.context_menu.addSeparator()
|
|
|
|
self.context_menu.addAction(self.action_updatevm)
|
|
|
|
self.context_menu.addAction(self.action_run_command_in_vm)
|
|
|
|
self.context_menu.addAction(self.action_open_console)
|
|
|
|
self.context_menu.addAction(self.action_resumevm)
|
|
|
|
self.context_menu.addAction(self.action_startvm_tools_install)
|
|
|
|
self.context_menu.addAction(self.action_pausevm)
|
|
|
|
self.context_menu.addAction(self.action_shutdownvm)
|
|
|
|
self.context_menu.addAction(self.action_restartvm)
|
|
|
|
self.context_menu.addAction(self.action_killvm)
|
|
|
|
self.context_menu.addSeparator()
|
|
|
|
self.context_menu.addAction(self.action_clonevm)
|
|
|
|
self.context_menu.addAction(self.action_removevm)
|
|
|
|
self.context_menu.addSeparator()
|
2020-12-10 23:39:34 +01:00
|
|
|
self.context_menu.addAction(self.action_show_logs)
|
2020-10-27 00:46:24 +01:00
|
|
|
|
2020-11-01 13:51:53 +01:00
|
|
|
def save_showing(self):
|
2020-11-01 14:02:57 +01:00
|
|
|
self.manager_settings.setValue('show/running',
|
|
|
|
self.show_running.isChecked())
|
|
|
|
self.manager_settings.setValue('show/halted',
|
|
|
|
self.show_halted.isChecked())
|
|
|
|
self.manager_settings.setValue('show/network',
|
|
|
|
self.show_network.isChecked())
|
|
|
|
self.manager_settings.setValue('show/templates',
|
|
|
|
self.show_templates.isChecked())
|
|
|
|
self.manager_settings.setValue('show/standalone',
|
|
|
|
self.show_standalone.isChecked())
|
2020-11-01 13:51:53 +01:00
|
|
|
self.manager_settings.setValue('show/all', self.show_all.isChecked())
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
def save_sorting(self):
|
|
|
|
self.manager_settings.setValue('view/sort_column',
|
|
|
|
self.proxy.sortColumn())
|
|
|
|
self.manager_settings.setValue('view/sort_order',
|
|
|
|
self.proxy.sortOrder())
|
|
|
|
|
2020-10-27 00:46:24 +01:00
|
|
|
def invalidate(self):
|
|
|
|
self.proxy.invalidate()
|
|
|
|
self.table.resizeColumnsToContents()
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
def fill_cache(self):
|
|
|
|
progress = QProgressDialog(
|
|
|
|
self.tr(
|
|
|
|
"Loading Qube Manager..."), "", 0,
|
|
|
|
len(self.qubes_app.domains.keys()))
|
|
|
|
progress.setWindowTitle(self.tr("Qube Manager"))
|
|
|
|
progress.setMinimumDuration(1000)
|
|
|
|
progress.setWindowModality(Qt.WindowModal)
|
|
|
|
progress.setCancelButton(None)
|
|
|
|
|
|
|
|
row_no = 0
|
|
|
|
for vm in self.qubes_app.domains:
|
|
|
|
progress.setValue(row_no)
|
|
|
|
self.qubes_cache.add_vm(vm)
|
|
|
|
row_no += 1
|
|
|
|
|
|
|
|
progress.setValue(row_no)
|
2019-05-22 23:10:09 +02:00
|
|
|
|
2020-11-10 00:12:13 +01:00
|
|
|
def init_template_menu(self):
|
|
|
|
self.template_menu.clear()
|
|
|
|
for vm in self.qubes_app.domains:
|
|
|
|
if vm.klass == 'TemplateVM':
|
|
|
|
action = self.template_menu.addAction(vm.name)
|
|
|
|
action.setData(vm.name)
|
|
|
|
action.triggered.connect(partial(self.change_template, vm.name))
|
|
|
|
|
2021-01-09 00:42:47 +01:00
|
|
|
def _get_default_netvm(self):
|
|
|
|
for vm in self.qubes_app.domains:
|
|
|
|
if vm.klass == 'AppVM':
|
|
|
|
return vm.property_get_default('netvm')
|
|
|
|
|
2020-11-10 00:50:43 +01:00
|
|
|
def init_network_menu(self):
|
2021-01-10 23:39:33 +01:00
|
|
|
default = self._get_default_netvm()
|
2020-11-10 00:50:43 +01:00
|
|
|
self.network_menu.clear()
|
2020-11-10 00:55:55 +01:00
|
|
|
action = self.network_menu.addAction("None")
|
|
|
|
action.triggered.connect(partial(self.change_network, None))
|
2021-01-09 00:42:47 +01:00
|
|
|
action = self.network_menu.addAction("default ({0})".format(default))
|
|
|
|
action.triggered.connect(partial(self.change_network, 'default'))
|
|
|
|
|
2020-11-10 00:50:43 +01:00
|
|
|
for vm in self.qubes_app.domains:
|
|
|
|
if vm.qid != 0 and vm.provides_network:
|
|
|
|
action = self.network_menu.addAction(vm.name)
|
|
|
|
action.setData(vm.name)
|
|
|
|
action.triggered.connect(partial(self.change_network, vm.name))
|
|
|
|
|
2019-11-08 23:35:26 +01:00
|
|
|
def setup_application(self):
|
|
|
|
self.qt_app.setApplicationName(self.tr("Qube Manager"))
|
2020-07-30 02:40:40 +02:00
|
|
|
self.qt_app.setWindowIcon(QIcon.fromTheme("qubes-manager"))
|
2019-11-08 23:35:26 +01:00
|
|
|
|
2018-11-25 19:28:07 +01:00
|
|
|
def keyPressEvent(self, event): # pylint: disable=invalid-name
|
2020-07-30 02:40:40 +02:00
|
|
|
if event.key() == Qt.Key_Escape:
|
2018-11-25 19:28:07 +01:00
|
|
|
self.searchbox.clear()
|
2020-08-23 02:53:36 +02:00
|
|
|
super().keyPressEvent(event)
|
2018-11-25 19:28:07 +01:00
|
|
|
|
2018-10-18 14:13:06 +02:00
|
|
|
def clear_threads(self):
|
|
|
|
for thread in self.threads_list:
|
|
|
|
if thread.isFinished():
|
2018-10-20 22:09:39 +02:00
|
|
|
if self.progress:
|
|
|
|
self.progress.hide()
|
|
|
|
self.progress = None
|
|
|
|
|
2018-10-22 20:00:37 +02:00
|
|
|
if thread.msg:
|
|
|
|
(title, msg) = thread.msg
|
2019-04-03 20:34:01 +02:00
|
|
|
if thread.msg_is_success:
|
2020-07-30 02:40:40 +02:00
|
|
|
QMessageBox.information(
|
2019-05-22 23:10:09 +02:00
|
|
|
self,
|
2019-10-23 18:18:39 +02:00
|
|
|
title,
|
|
|
|
msg)
|
2019-03-29 17:01:15 +01:00
|
|
|
else:
|
2020-07-30 02:40:40 +02:00
|
|
|
QMessageBox.warning(
|
2019-05-22 23:10:09 +02:00
|
|
|
self,
|
2019-10-23 18:18:39 +02:00
|
|
|
title,
|
|
|
|
msg)
|
2018-10-20 22:09:39 +02:00
|
|
|
|
2018-10-18 14:13:06 +02:00
|
|
|
self.threads_list.remove(thread)
|
2018-11-25 18:37:34 +01:00
|
|
|
return
|
|
|
|
|
2019-10-23 18:18:39 +02:00
|
|
|
raise RuntimeError(self.tr('No finished thread found'))
|
2018-10-18 14:13:06 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def resizeEvent(self, event):
|
|
|
|
self.manager_settings.setValue("window_size", event.size())
|
|
|
|
|
|
|
|
def check_updates(self, info=None):
|
|
|
|
if info is None:
|
|
|
|
for info_iter in self.qubes_cache:
|
|
|
|
self.check_updates(info_iter)
|
2019-12-05 22:32:55 +01:00
|
|
|
return
|
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
try:
|
|
|
|
if info.vm.klass in {'TemplateVM', 'StandaloneVM'} and \
|
2020-08-11 01:08:48 +02:00
|
|
|
manager_utils.get_feature(
|
|
|
|
info.vm, 'updates-available', False):
|
2020-08-03 23:25:20 +02:00
|
|
|
info.state['outdated'] = 'update'
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2020-08-03 23:25:20 +02:00
|
|
|
return
|
2018-05-09 14:36:39 +02:00
|
|
|
|
2018-09-12 16:23:14 +02:00
|
|
|
def on_domain_added(self, _submitter, _event, vm, **_kwargs):
|
2018-11-25 19:15:56 +01:00
|
|
|
try:
|
|
|
|
domain = self.qubes_app.domains[vm]
|
2020-07-30 02:40:40 +02:00
|
|
|
self.qubes_cache.add_vm(domain)
|
|
|
|
self.proxy.invalidate()
|
2020-11-10 00:12:13 +01:00
|
|
|
if domain.klass == 'TemplateVM':
|
|
|
|
self.init_template_menu()
|
2018-11-25 19:15:56 +01:00
|
|
|
except (exc.QubesException, KeyError):
|
2020-07-30 02:40:40 +02:00
|
|
|
pass
|
2018-05-07 21:10:15 +02:00
|
|
|
|
2018-09-12 16:23:14 +02:00
|
|
|
def on_domain_removed(self, _submitter, _event, **kwargs):
|
2020-07-30 02:40:40 +02:00
|
|
|
self.qubes_cache.remove_vm(name=kwargs['vm'])
|
|
|
|
self.proxy.invalidate()
|
2020-11-10 00:12:13 +01:00
|
|
|
self.init_template_menu()
|
2021-02-09 21:11:35 +01:00
|
|
|
self.init_network_menu()
|
2020-07-30 02:40:40 +02:00
|
|
|
|
|
|
|
def on_domain_status_changed(self, vm, event, **_kwargs):
|
2018-09-21 12:43:59 +02:00
|
|
|
try:
|
2020-07-30 02:40:40 +02:00
|
|
|
self.qubes_cache.get_vm(qid=vm.qid).update(event=event)
|
|
|
|
if vm.klass in {'TemplateVM'}:
|
|
|
|
for appvm in vm.appvms:
|
|
|
|
self.qubes_cache.get_vm(qid=appvm.qid).\
|
|
|
|
update(event="outdated")
|
|
|
|
self.proxy.invalidate()
|
|
|
|
self.table_selection_changed()
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2018-09-21 12:43:59 +02:00
|
|
|
return # the VM was deleted before its status could be updated
|
2019-06-03 21:21:48 +02:00
|
|
|
except KeyError: # adding the VM failed for some reason
|
|
|
|
self.on_domain_added(None, None, vm)
|
2018-05-09 11:31:44 +02:00
|
|
|
|
2019-12-05 22:32:55 +01:00
|
|
|
def on_domain_updates_available(self, vm, _event, **_kwargs):
|
2020-07-30 02:40:40 +02:00
|
|
|
self.check_updates(self.qubes_cache.get_vm(qid=vm.qid))
|
2019-12-05 22:32:55 +01:00
|
|
|
|
2019-01-11 15:15:08 +01:00
|
|
|
def on_domain_changed(self, vm, event, **_kwargs):
|
2018-10-19 20:06:30 +02:00
|
|
|
if not vm: # change of global properties occured
|
2019-09-19 01:27:34 +02:00
|
|
|
if event.endswith(':default_netvm'):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.qubes_cache:
|
|
|
|
vm_info.update(event='property-set:netvm')
|
2019-09-19 01:27:34 +02:00
|
|
|
if event.endswith(':default_dispvm'):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.qubes_cache:
|
|
|
|
vm_info.update(event='property-set:default_dispvm')
|
2018-10-19 20:06:30 +02:00
|
|
|
return
|
2019-09-19 01:27:34 +02:00
|
|
|
|
2018-09-21 12:43:59 +02:00
|
|
|
try:
|
2021-02-09 21:11:35 +01:00
|
|
|
if event.endswith(':provides_network'):
|
|
|
|
self.init_network_menu()
|
2020-07-30 02:40:40 +02:00
|
|
|
self.qubes_cache.get_vm(qid=vm.qid).update(event=event)
|
|
|
|
self.proxy.invalidate()
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2018-09-21 12:43:59 +02:00
|
|
|
return # the VM was deleted before its status could be updated
|
2018-05-09 11:31:44 +02:00
|
|
|
|
2018-01-05 17:31:15 +01:00
|
|
|
def load_manager_settings(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
# Load view menu settings
|
|
|
|
for action in self.menu_view.actions():
|
|
|
|
column = action.data()
|
|
|
|
if column is not None:
|
|
|
|
col_no = self.qubes_model.columns_indices.index(column)
|
|
|
|
if column == 'Name':
|
|
|
|
# 'Name' column should be always visible
|
|
|
|
action.setChecked(True)
|
|
|
|
else:
|
|
|
|
visible = self.manager_settings.value('columns/%s' % column,
|
|
|
|
defaultValue="true")
|
|
|
|
action.setChecked(visible == "true")
|
|
|
|
self.showhide_column(col_no, visible == "true")
|
|
|
|
|
|
|
|
# Restore sorting
|
|
|
|
sort_column = int(self.manager_settings.value("view/sort_column",
|
|
|
|
defaultValue=2))
|
|
|
|
order = Qt.SortOrder(self.manager_settings.value("view/sort_order",
|
|
|
|
defaultValue=Qt.AscendingOrder))
|
|
|
|
|
|
|
|
if not sort_column: # Default sort by name
|
|
|
|
self.table.sortByColumn(2, Qt.AscendingOrder)
|
|
|
|
else:
|
|
|
|
self.table.sortByColumn(sort_column, order)
|
2019-04-03 20:39:40 +02:00
|
|
|
|
2018-01-05 17:31:15 +01:00
|
|
|
if not self.manager_settings.value("view/menubar_visible",
|
|
|
|
defaultValue=True):
|
|
|
|
self.action_menubar.setChecked(False)
|
|
|
|
if not self.manager_settings.value("view/toolbar_visible",
|
|
|
|
defaultValue=True):
|
|
|
|
self.action_toolbar.setChecked(False)
|
2020-11-04 23:51:31 +01:00
|
|
|
if self.manager_settings.value("view/compactview",
|
|
|
|
defaultValue="false") != "false":
|
|
|
|
self.action_compact_view.setChecked(True)
|
2018-07-16 17:55:56 +02:00
|
|
|
|
2020-11-01 13:51:53 +01:00
|
|
|
# Restore show checkboxes
|
|
|
|
self.show_running.setChecked(self.manager_settings.value(
|
|
|
|
'show/running', "true") == "true")
|
|
|
|
self.show_halted.setChecked(self.manager_settings.value(
|
|
|
|
'show/halted', "true") == "true")
|
|
|
|
self.show_network.setChecked(self.manager_settings.value(
|
|
|
|
'show/network', "true") == "true")
|
|
|
|
self.show_templates.setChecked(self.manager_settings.value(
|
2020-11-01 14:02:57 +01:00
|
|
|
'show/templates', "true") == "true")
|
2020-11-01 13:51:53 +01:00
|
|
|
self.show_standalone.setChecked(self.manager_settings.value(
|
|
|
|
'show/standalone', "true") == "true")
|
|
|
|
self.show_all.setChecked(self.manager_settings.value(
|
|
|
|
'show/all', "true") == "true")
|
2018-07-16 17:55:56 +02:00
|
|
|
|
|
|
|
# load last window size
|
|
|
|
self.resize(self.manager_settings.value("window_size",
|
2020-07-30 02:40:40 +02:00
|
|
|
QSize(1100, 600)))
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(str)
|
2017-12-20 22:33:39 +01:00
|
|
|
def do_search(self, search):
|
2020-07-30 02:40:40 +02:00
|
|
|
self.proxy.setFilterFixedString(search)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_search_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_search_triggered(self):
|
|
|
|
self.searchbox.setFocus()
|
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
def get_selected_vms(self):
|
|
|
|
vms = []
|
|
|
|
|
|
|
|
selection = self.table.selectionModel().selection()
|
|
|
|
indexes = self.proxy.mapSelectionToSource(selection).indexes()
|
|
|
|
|
|
|
|
for index in indexes:
|
|
|
|
if index.column() != 0:
|
|
|
|
continue
|
|
|
|
vms.append(index.data(Qt.UserRole))
|
|
|
|
|
|
|
|
return vms
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
def table_selection_changed(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
# Since selection could have multiple domains
|
|
|
|
# enable all first and then filter them
|
2020-11-07 16:04:11 +01:00
|
|
|
self.template_menu.setEnabled(True)
|
2020-11-13 23:52:49 +01:00
|
|
|
self.network_menu.setEnabled(True)
|
2020-07-30 02:40:40 +02:00
|
|
|
for action in self.toolbar.actions() + self.context_menu.actions():
|
|
|
|
action.setEnabled(True)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm in self.get_selected_vms():
|
2018-01-08 02:46:41 +01:00
|
|
|
# TODO: add boot from device to menu and add windows tools there
|
2017-12-20 22:33:39 +01:00
|
|
|
# Update available actions:
|
2020-07-30 02:40:40 +02:00
|
|
|
if vm.state['power'] in \
|
|
|
|
['Running', 'Transient', 'Halting', 'Dying']:
|
|
|
|
self.action_resumevm.setEnabled(False)
|
|
|
|
self.action_removevm.setEnabled(False)
|
2020-11-07 16:04:11 +01:00
|
|
|
self.template_menu.setEnabled(False)
|
2020-07-30 02:40:40 +02:00
|
|
|
elif vm.state['power'] == 'Paused':
|
|
|
|
self.action_removevm.setEnabled(False)
|
|
|
|
self.action_pausevm.setEnabled(False)
|
|
|
|
self.action_set_keyboard_layout.setEnabled(False)
|
|
|
|
self.action_restartvm.setEnabled(False)
|
|
|
|
self.action_open_console.setEnabled(False)
|
2020-11-07 16:04:11 +01:00
|
|
|
self.template_menu.setEnabled(False)
|
2020-07-30 02:40:40 +02:00
|
|
|
elif vm.state['power'] == 'Suspend':
|
|
|
|
self.action_set_keyboard_layout.setEnabled(False)
|
|
|
|
self.action_removevm.setEnabled(False)
|
|
|
|
self.action_pausevm.setEnabled(False)
|
|
|
|
self.action_open_console.setEnabled(False)
|
2020-11-07 16:04:11 +01:00
|
|
|
self.template_menu.setEnabled(False)
|
2020-07-30 02:40:40 +02:00
|
|
|
elif vm.state['power'] == 'Halted':
|
|
|
|
self.action_set_keyboard_layout.setEnabled(False)
|
|
|
|
self.action_pausevm.setEnabled(False)
|
|
|
|
self.action_shutdownvm.setEnabled(False)
|
|
|
|
self.action_restartvm.setEnabled(False)
|
|
|
|
self.action_killvm.setEnabled(False)
|
|
|
|
self.action_open_console.setEnabled(False)
|
|
|
|
|
|
|
|
if vm.klass == 'AdminVM':
|
|
|
|
self.action_open_console.setEnabled(False)
|
|
|
|
self.action_settings.setEnabled(False)
|
|
|
|
self.action_resumevm.setEnabled(False)
|
|
|
|
self.action_removevm.setEnabled(False)
|
|
|
|
self.action_clonevm.setEnabled(False)
|
|
|
|
self.action_pausevm.setEnabled(False)
|
|
|
|
self.action_restartvm.setEnabled(False)
|
|
|
|
self.action_killvm.setEnabled(False)
|
|
|
|
self.action_shutdownvm.setEnabled(False)
|
|
|
|
self.action_appmenus.setEnabled(False)
|
|
|
|
self.action_editfwrules.setEnabled(False)
|
|
|
|
self.action_set_keyboard_layout.setEnabled(False)
|
|
|
|
self.action_run_command_in_vm.setEnabled(False)
|
2020-11-07 16:04:11 +01:00
|
|
|
self.template_menu.setEnabled(False)
|
2020-11-13 23:52:49 +01:00
|
|
|
self.network_menu.setEnabled(False)
|
2020-07-30 02:40:40 +02:00
|
|
|
elif vm.klass == 'DispVM':
|
|
|
|
self.action_appmenus.setEnabled(False)
|
|
|
|
self.action_restartvm.setEnabled(False)
|
2020-11-07 16:04:11 +01:00
|
|
|
self.template_menu.setEnabled(False)
|
|
|
|
elif vm.klass == 'TemplateVM':
|
|
|
|
self.template_menu.setEnabled(False)
|
2021-02-03 00:04:30 +01:00
|
|
|
self.network_menu.setEnabled(False)
|
2020-07-30 02:40:40 +02:00
|
|
|
|
|
|
|
if vm.vm.features.get('internal', False):
|
|
|
|
self.action_appmenus.setEnabled(False)
|
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
if not vm.updateable and vm.klass != 'AdminVM':
|
2020-07-30 02:40:40 +02:00
|
|
|
self.action_updatevm.setEnabled(False)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-11-07 16:04:11 +01:00
|
|
|
self.update_template_menu()
|
2020-11-13 23:52:49 +01:00
|
|
|
self.update_network_menu()
|
2020-11-07 16:04:11 +01:00
|
|
|
|
|
|
|
def update_template_menu(self):
|
|
|
|
if not self.template_menu.isEnabled():
|
|
|
|
return
|
|
|
|
|
|
|
|
for entry in self.template_menu.actions():
|
2020-11-26 00:04:10 +01:00
|
|
|
entry.setIcon(QIcon())
|
2020-11-07 16:04:11 +01:00
|
|
|
|
2020-11-26 00:04:10 +01:00
|
|
|
vms = self.get_selected_vms()
|
|
|
|
for vm in vms:
|
2020-11-07 16:04:11 +01:00
|
|
|
for entry in self.template_menu.actions():
|
|
|
|
if entry.data() == vm.template:
|
2020-11-26 00:04:10 +01:00
|
|
|
if len(vms) == 1:
|
|
|
|
entry.setIcon(QIcon(":/on.png"))
|
|
|
|
else:
|
|
|
|
entry.setIcon(QIcon(":/transient.png"))
|
2019-04-30 16:35:54 +02:00
|
|
|
|
2020-11-13 23:52:49 +01:00
|
|
|
def update_network_menu(self):
|
|
|
|
if not self.network_menu.isEnabled():
|
|
|
|
return
|
|
|
|
|
|
|
|
for entry in self.network_menu.actions():
|
2020-11-26 00:04:10 +01:00
|
|
|
entry.setIcon(QIcon())
|
|
|
|
|
|
|
|
if len(self.get_selected_vms()) == 1:
|
|
|
|
icon = QIcon(":/on.png")
|
|
|
|
else:
|
|
|
|
icon = QIcon(":/transient.png")
|
2020-11-13 23:52:49 +01:00
|
|
|
|
|
|
|
for vm in self.get_selected_vms():
|
|
|
|
if vm.netvm == "n/a":
|
2020-11-26 00:04:10 +01:00
|
|
|
self.network_menu.actions()[0].setIcon(QIcon(icon))
|
2021-01-25 21:27:50 +01:00
|
|
|
elif vm.vm.property_is_default("netvm"):
|
|
|
|
self.network_menu.actions()[1].setIcon(QIcon(icon))
|
2020-11-13 23:52:49 +01:00
|
|
|
else:
|
|
|
|
for entry in self.network_menu.actions():
|
|
|
|
if entry.data() == vm.netvm:
|
2020-11-26 00:04:10 +01:00
|
|
|
entry.setIcon(icon)
|
2020-11-13 23:52:49 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_createvm_triggered')
|
|
|
|
def action_createvm_triggered(self):
|
2019-03-31 19:56:01 +02:00
|
|
|
with common_threads.busy_cursor():
|
2021-03-15 21:12:59 +01:00
|
|
|
create_window = create_new_vm.NewVmDlg(
|
|
|
|
self.qt_app, self.qubes_app, self)
|
2018-10-20 16:43:15 +02:00
|
|
|
create_window.exec_()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_removevm_triggered')
|
2018-01-08 02:46:41 +01:00
|
|
|
def action_removevm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
remove_vms = []
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
dependencies = utils.vm_dependencies(self.qubes_app, vm)
|
2018-07-18 23:51:37 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
if dependencies:
|
|
|
|
list_deps = manager_utils.format_dependencies_list(dependencies)
|
|
|
|
list_text = "<br>" + list_deps + "<br>"
|
2018-07-18 23:51:37 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
info_dialog = QMessageBox(self)
|
|
|
|
info_dialog.setWindowTitle(self.tr("Warning!"))
|
|
|
|
info_dialog.setText(
|
|
|
|
self.tr("This qube cannot be removed. It is used as: <br> "
|
|
|
|
"{} <small>If you want to remove this qube, you "
|
|
|
|
"should remove or change settings of each qube or "
|
|
|
|
"setting that uses it.</small>").format(list_text))
|
|
|
|
info_dialog.setModal(False)
|
|
|
|
info_dialog.show()
|
2018-07-18 23:51:37 +02:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
return
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
(requested_name, ok) = QInputDialog.getText(
|
|
|
|
self, self.tr("Qube Removal Confirmation"),
|
|
|
|
self.tr("Are you sure you want to remove the Qube <b>'{0}'</b>"
|
|
|
|
"?<br> All data on this Qube's private storage will be "
|
|
|
|
"lost!<br><br>Type the name of the Qube (<b>{1}</b>) be"
|
|
|
|
"low to confirm:").format(vm.name, vm.name))
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
if not ok:
|
|
|
|
# user clicked cancel
|
|
|
|
continue
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
if requested_name == vm.name:
|
|
|
|
remove_vms.append(vm)
|
|
|
|
else:
|
|
|
|
# name did not match
|
|
|
|
QMessageBox.warning(
|
|
|
|
self,
|
|
|
|
self.tr("Qube removal confirmation failed"),
|
|
|
|
self.tr(
|
|
|
|
"Entered name did not match! Not removing "
|
|
|
|
"{0}.").format(vm.name))
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
# remove the VMs
|
|
|
|
for vm in remove_vms:
|
2018-10-20 18:34:15 +02:00
|
|
|
thread = common_threads.RemoveVMThread(vm)
|
2018-10-18 14:11:25 +02:00
|
|
|
self.threads_list.append(thread)
|
|
|
|
thread.finished.connect(self.clear_threads)
|
2017-12-20 22:33:39 +01:00
|
|
|
thread.start()
|
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_clonevm_triggered')
|
2018-01-08 02:46:41 +01:00
|
|
|
def action_clonevm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
2020-06-02 19:58:21 +02:00
|
|
|
with common_threads.busy_cursor():
|
|
|
|
clone_window = clone_vm.CloneVMDlg(
|
|
|
|
self.qt_app, self.qubes_app, src_vm=vm)
|
|
|
|
clone_window.exec_()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_resumevm_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_resumevm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
2020-08-11 01:08:48 +02:00
|
|
|
try:
|
|
|
|
if vm.get_power_state() in ["Paused", "Suspended"]:
|
2020-07-30 02:40:40 +02:00
|
|
|
vm.unpause()
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesException as ex:
|
|
|
|
QMessageBox.warning(
|
|
|
|
self, self.tr("Error unpausing Qube!"),
|
|
|
|
self.tr("ERROR: {0}").format(ex))
|
2020-07-30 02:40:40 +02:00
|
|
|
return
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
self.start_vm(vm)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-12-12 00:34:41 +01:00
|
|
|
def start_vm(self, vm, wait=False):
|
2020-08-11 01:08:48 +02:00
|
|
|
if manager_utils.is_running(vm, False):
|
2018-01-08 02:46:41 +01:00
|
|
|
return
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-10-18 14:11:25 +02:00
|
|
|
thread = StartVMThread(vm)
|
|
|
|
self.threads_list.append(thread)
|
|
|
|
thread.finished.connect(self.clear_threads)
|
|
|
|
thread.start()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-12-12 00:34:41 +01:00
|
|
|
if wait:
|
|
|
|
with common_threads.busy_cursor():
|
|
|
|
thread.wait()
|
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_startvm_tools_install_triggered')
|
2018-01-05 17:31:15 +01:00
|
|
|
# TODO: replace with boot from device
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_startvm_tools_install_triggered(self):
|
2018-01-08 03:06:42 +01:00
|
|
|
# pylint: disable=invalid-name
|
2018-01-08 02:46:41 +01:00
|
|
|
pass
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_pausevm_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_pausevm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
try:
|
|
|
|
vm_info.vm.pause()
|
|
|
|
except exc.QubesException as ex:
|
|
|
|
QMessageBox.warning(
|
|
|
|
self,
|
|
|
|
self.tr("Error pausing Qube!"),
|
|
|
|
self.tr("ERROR: {0}").format(ex))
|
|
|
|
return
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_shutdownvm_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_shutdownvm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Qube Shutdown Confirmation"),
|
|
|
|
self.tr("Are you sure you want to power down the Qube <b>'{0}'"
|
|
|
|
"</b>?<br><small>This will shutdown all the running"
|
|
|
|
" applications within this Qube.</small>").format(
|
|
|
|
vm.name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
self.shutdown_vm(vm)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2021-02-16 21:28:32 +01:00
|
|
|
def get_connected_vms(self, vm, connected_vms):
|
|
|
|
for connected_vm in vm.connected_vms:
|
|
|
|
if connected_vm.is_running():
|
|
|
|
connected_vms.append(connected_vm)
|
|
|
|
self.get_connected_vms(connected_vm, connected_vms)
|
|
|
|
|
2021-02-24 16:18:31 +01:00
|
|
|
def shutdown_vm(self, vm, force=False, check_time=vm_restart_check_timeout,
|
|
|
|
and_restart=False):
|
2017-12-20 22:33:39 +01:00
|
|
|
try:
|
2021-02-16 21:28:32 +01:00
|
|
|
connected_vms = []
|
2021-02-16 22:08:51 +01:00
|
|
|
|
|
|
|
if not and_restart:
|
|
|
|
self.get_connected_vms(vm, connected_vms)
|
2021-01-26 23:47:14 +01:00
|
|
|
|
2021-01-10 19:10:36 +01:00
|
|
|
if len(connected_vms) > 0:
|
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Qube Shutdown Confirmation"),
|
|
|
|
self.tr("There are some qubes connected to <b>'{0}'</b>!"
|
|
|
|
"<br><small>Do you want to shutdown: </small>"
|
2021-01-10 20:43:26 +01:00
|
|
|
"<b>'{1}'</b>?").format(vm.name,
|
|
|
|
", ".join([x.name for x in connected_vms])),
|
2021-01-10 19:10:36 +01:00
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
2021-01-26 23:47:14 +01:00
|
|
|
if reply != QMessageBox.Yes:
|
2021-01-10 20:54:03 +01:00
|
|
|
return False
|
2021-01-10 19:10:36 +01:00
|
|
|
|
2021-02-17 10:56:29 +01:00
|
|
|
force = True
|
2021-01-26 23:47:14 +01:00
|
|
|
for connected_vm in connected_vms:
|
2021-02-16 22:08:51 +01:00
|
|
|
connected_vm.shutdown(force=force)
|
2021-01-26 23:47:14 +01:00
|
|
|
|
2021-02-16 22:08:51 +01:00
|
|
|
vm.shutdown(force=force)
|
2018-01-08 03:06:42 +01:00
|
|
|
except exc.QubesException as ex:
|
2020-07-30 02:40:40 +02:00
|
|
|
QMessageBox.warning(
|
2019-05-22 23:10:09 +02:00
|
|
|
self,
|
2018-01-08 03:01:02 +01:00
|
|
|
self.tr("Error shutting down Qube!"),
|
2018-01-05 17:31:15 +01:00
|
|
|
self.tr("ERROR: {0}").format(ex))
|
2021-01-10 20:54:03 +01:00
|
|
|
return False
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2021-02-24 16:18:31 +01:00
|
|
|
self.shutdown_monitor[vm.qid] = VmShutdownMonitor(vm, check_time,
|
2018-01-05 17:31:15 +01:00
|
|
|
and_restart, self)
|
2017-12-20 22:33:39 +01:00
|
|
|
# noinspection PyCallByClass,PyTypeChecker
|
2020-07-30 02:40:40 +02:00
|
|
|
QTimer.singleShot(check_time, self.shutdown_monitor[
|
2017-12-20 22:33:39 +01:00
|
|
|
vm.qid].check_if_vm_has_shutdown)
|
|
|
|
|
2021-01-10 20:54:03 +01:00
|
|
|
return True
|
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_restartvm_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_restartvm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Qube Restart Confirmation"),
|
|
|
|
self.tr("Are you sure you want to restart the Qube <b>'{0}'</b>"
|
|
|
|
"?<br><small>This will shutdown all the running applica"
|
|
|
|
"tions within this Qube.</small>").format(vm.name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
# in case the user shut down the VM in the meantime
|
2020-08-11 01:08:48 +02:00
|
|
|
try:
|
|
|
|
if manager_utils.is_running(vm, False):
|
2021-02-16 22:08:51 +01:00
|
|
|
self.shutdown_vm(vm, force=True, and_restart=True)
|
2020-08-11 01:08:48 +02:00
|
|
|
else:
|
|
|
|
self.start_vm(vm)
|
|
|
|
except exc.QubesException as ex:
|
|
|
|
QMessageBox.warning(
|
|
|
|
self,
|
|
|
|
self.tr("Error restarting Qube!"),
|
|
|
|
self.tr("ERROR: {0}").format(ex))
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_killvm_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_killvm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
2020-08-11 01:08:48 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
vm_not_running = not (vm.is_running() or vm.is_paused())
|
|
|
|
except exc.QubesDaemonAccessError:
|
|
|
|
vm_not_running = False
|
|
|
|
|
|
|
|
if vm_not_running:
|
2020-07-30 02:40:40 +02:00
|
|
|
info = self.tr("Qube <b>'{0}'</b> is not running. Are you "
|
|
|
|
"absolutely sure you want to try to kill it?<br>"
|
|
|
|
"<small>This will end <b>(not shutdown!)</b> "
|
|
|
|
"all the running applications within this "
|
|
|
|
"Qube.</small>").format(vm.name)
|
|
|
|
else:
|
|
|
|
info = self.tr("Are you sure you want to kill the Qube "
|
|
|
|
"<b>'{0}'</b>?<br><small>This will end <b>(not "
|
|
|
|
"shutdown!)</b> all the running applications "
|
|
|
|
"within this Qube.</small>").format(vm.name)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Qube Kill Confirmation"), info,
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel,
|
|
|
|
QMessageBox.Cancel)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
try:
|
|
|
|
vm.kill()
|
|
|
|
except exc.QubesException as ex:
|
|
|
|
QMessageBox.critical(
|
|
|
|
self, self.tr("Error while killing Qube!"),
|
|
|
|
self.tr(
|
2020-08-11 01:08:48 +02:00
|
|
|
"<b>An exception occurred while killing {0}.</b>"
|
|
|
|
"<br>ERROR: {1}").format(vm.name, ex))
|
2020-07-30 02:40:40 +02:00
|
|
|
return
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-05-15 08:21:03 +02:00
|
|
|
def open_settings(self, vm, tab='basic'):
|
|
|
|
try:
|
2019-03-31 19:56:01 +02:00
|
|
|
with common_threads.busy_cursor():
|
|
|
|
settings_window = settings.VMSettingsWindow(
|
2021-03-15 15:13:59 +01:00
|
|
|
vm, tab, self.qt_app, self.qubes_app, self)
|
2020-07-30 02:40:40 +02:00
|
|
|
settings_window.show()
|
|
|
|
self.settings_windows[vm.name] = settings_window
|
2020-05-15 08:21:03 +02:00
|
|
|
except exc.QubesException as ex:
|
2020-07-30 02:40:40 +02:00
|
|
|
QMessageBox.warning(
|
2020-05-15 08:21:03 +02:00
|
|
|
self,
|
|
|
|
self.tr("Qube settings unavailable"),
|
|
|
|
self.tr(
|
|
|
|
"Qube settings cannot be opened. The qube might have "
|
|
|
|
"been removed or unavailable due to policy settings."
|
|
|
|
"\nError: {}".format(str(ex))))
|
|
|
|
return
|
2018-05-31 00:04:46 +02:00
|
|
|
|
2020-11-01 14:02:57 +01:00
|
|
|
def closeEvent(self, _):
|
2020-11-01 13:51:53 +01:00
|
|
|
self.save_showing()
|
|
|
|
|
2020-05-15 08:21:03 +02:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_settings_triggered')
|
2020-05-15 08:21:03 +02:00
|
|
|
def action_settings_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
self.open_settings(vm_info.vm, "basic")
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_appmenus_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_appmenus_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
self.open_settings(vm_info.vm, "applications")
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_updatevm_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_updatevm_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
2020-08-11 01:08:48 +02:00
|
|
|
if not manager_utils.is_running(vm, True):
|
2020-07-30 02:40:40 +02:00
|
|
|
reply = QMessageBox.question(
|
|
|
|
self, self.tr("Qube Update Confirmation"),
|
|
|
|
self.tr(
|
|
|
|
"<b>{0}</b>"
|
|
|
|
"<br>The Qube has to be running to be updated."
|
|
|
|
"<br>Do you want to start it?<br>").format(vm.name),
|
|
|
|
QMessageBox.Yes | QMessageBox.Cancel)
|
|
|
|
if reply != QMessageBox.Yes:
|
|
|
|
return
|
|
|
|
|
|
|
|
thread = UpdateVMThread(vm)
|
|
|
|
self.threads_list.append(thread)
|
|
|
|
thread.finished.connect(self.clear_threads)
|
|
|
|
thread.start()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_run_command_in_vm_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_run_command_in_vm_triggered(self):
|
2018-01-08 03:06:42 +01:00
|
|
|
# pylint: disable=invalid-name
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
(command_to_run, ok) = QInputDialog.getText(
|
|
|
|
self, self.tr('Qubes command entry'),
|
|
|
|
self.tr('Run command in <b>{}</b>:').format(vm_info.name))
|
|
|
|
if not ok or command_to_run == "":
|
|
|
|
return
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-07-30 02:40:40 +02:00
|
|
|
thread = RunCommandThread(vm_info.vm, command_to_run)
|
|
|
|
self.threads_list.append(thread)
|
|
|
|
thread.finished.connect(self.clear_threads)
|
|
|
|
thread.start()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-03-24 16:51:54 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_open_console_triggered')
|
2020-03-24 16:51:54 +01:00
|
|
|
def action_open_console_triggered(self):
|
|
|
|
# pylint: disable=invalid-name
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm in self.get_selected_vms():
|
|
|
|
subprocess.Popen(['qvm-console-dispvm', vm.name],
|
|
|
|
stdout=subprocess.DEVNULL,
|
|
|
|
stderr=subprocess.DEVNULL)
|
2020-03-24 16:51:54 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_set_keyboard_layout_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_set_keyboard_layout_triggered(self):
|
2018-01-08 03:06:42 +01:00
|
|
|
# pylint: disable=invalid-name
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
2020-09-09 15:19:59 +02:00
|
|
|
if vm_info.vm.features.check_with_template(
|
|
|
|
"supported-feature.keyboard-layout", False):
|
|
|
|
vm_info.vm.run('qubes-change-keyboard-layout')
|
|
|
|
else:
|
|
|
|
QMessageBox.warning(
|
|
|
|
self,
|
|
|
|
self.tr("Keyboard layout change unsupported"),
|
|
|
|
self.tr(
|
|
|
|
"Please update the qube {} or its template to the "
|
|
|
|
"newest version of Qubes tools.").format(
|
|
|
|
str(vm_info.vm)))
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_editfwrules_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_editfwrules_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
self.open_settings(vm_info.vm, "firewall")
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_global_settings_triggered')
|
2018-01-08 03:06:42 +01:00
|
|
|
def action_global_settings_triggered(self): # pylint: disable=invalid-name
|
2019-03-31 19:56:01 +02:00
|
|
|
with common_threads.busy_cursor():
|
|
|
|
global_settings_window = global_settings.GlobalSettingsWindow(
|
|
|
|
self.qt_app,
|
2021-03-15 15:13:59 +01:00
|
|
|
self.qubes_app,
|
|
|
|
self)
|
2020-07-30 02:40:40 +02:00
|
|
|
global_settings_window.show()
|
|
|
|
self.settings_windows['global_settings_window'] = global_settings_window
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-11-09 15:51:22 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_manage_templates_triggered')
|
2018-11-09 15:51:22 +01:00
|
|
|
def action_manage_templates_triggered(self):
|
2020-07-30 02:40:40 +02:00
|
|
|
# pylint: disable=no-self-use
|
2018-11-09 15:51:22 +01:00
|
|
|
subprocess.check_call('qubes-template-manager')
|
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_show_network_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_show_network_triggered(self):
|
|
|
|
pass
|
2018-01-08 02:46:41 +01:00
|
|
|
# TODO: revive for 4.1
|
2017-12-20 22:33:39 +01:00
|
|
|
# network_notes_dialog = NetworkNotesDialog()
|
|
|
|
# network_notes_dialog.exec_()
|
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_restore_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_restore_triggered(self):
|
2019-03-31 19:56:01 +02:00
|
|
|
with common_threads.busy_cursor():
|
2019-05-22 23:10:09 +02:00
|
|
|
restore_window = restore.RestoreVMsWindow(self.qt_app,
|
2021-03-15 15:13:59 +01:00
|
|
|
self.qubes_app, self)
|
2018-01-05 17:31:15 +01:00
|
|
|
restore_window.exec_()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_backup_triggered')
|
2017-12-20 22:33:39 +01:00
|
|
|
def action_backup_triggered(self):
|
2019-03-31 19:56:01 +02:00
|
|
|
with common_threads.busy_cursor():
|
2019-05-22 23:10:09 +02:00
|
|
|
backup_window = backup.BackupVMsWindow(
|
|
|
|
self.qt_app, self.qubes_app, self.dispatcher, self)
|
2018-11-18 20:14:57 +01:00
|
|
|
backup_window.show()
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2018-03-10 20:04:57 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_exit_triggered')
|
2018-03-10 20:04:57 +01:00
|
|
|
def action_exit_triggered(self):
|
|
|
|
self.close()
|
|
|
|
|
2020-11-04 23:37:21 +01:00
|
|
|
def set_compactview(self, checked):
|
|
|
|
if checked:
|
|
|
|
self.toolbar.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
|
|
|
else:
|
|
|
|
self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
|
2020-11-04 23:51:31 +01:00
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('view/compactview', checked)
|
2020-11-04 23:37:21 +01:00
|
|
|
|
2017-12-20 22:33:39 +01:00
|
|
|
def showhide_menubar(self, checked):
|
|
|
|
self.menubar.setVisible(checked)
|
|
|
|
if not checked:
|
|
|
|
self.context_menu.addAction(self.action_menubar)
|
|
|
|
else:
|
|
|
|
self.context_menu.removeAction(self.action_menubar)
|
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('view/menubar_visible', checked)
|
|
|
|
|
|
|
|
def showhide_toolbar(self, checked):
|
|
|
|
self.toolbar.setVisible(checked)
|
|
|
|
if not checked:
|
|
|
|
self.context_menu.addAction(self.action_toolbar)
|
|
|
|
else:
|
|
|
|
self.context_menu.removeAction(self.action_toolbar)
|
|
|
|
if self.settings_loaded:
|
|
|
|
self.manager_settings.setValue('view/toolbar_visible', checked)
|
|
|
|
|
|
|
|
def showhide_column(self, col_num, show):
|
|
|
|
self.table.setColumnHidden(col_num, not show)
|
2020-07-30 02:40:40 +02:00
|
|
|
col_name = self.qubes_model.columns_indices[col_num]
|
|
|
|
self.manager_settings.setValue('columns/%s' % col_name, show)
|
2019-03-29 18:50:01 +01:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
# noinspection PyArgumentList
|
2020-07-30 02:40:40 +02:00
|
|
|
@pyqtSlot(name='on_action_about_qubes_triggered')
|
2018-01-08 03:06:42 +01:00
|
|
|
def action_about_qubes_triggered(self): # pylint: disable=no-self-use
|
2021-03-15 15:13:59 +01:00
|
|
|
about = AboutDialog(self)
|
2017-12-20 22:33:39 +01:00
|
|
|
about.exec_()
|
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
def createPopupMenu(self): # pylint: disable=invalid-name
|
2020-07-30 02:40:40 +02:00
|
|
|
menu = QMenu()
|
2017-12-20 22:33:39 +01:00
|
|
|
menu.addAction(self.action_toolbar)
|
|
|
|
menu.addAction(self.action_menubar)
|
|
|
|
return menu
|
|
|
|
|
|
|
|
def open_tools_context_menu(self, widget, point):
|
|
|
|
self.tools_context_menu.exec_(widget.mapToGlobal(point))
|
|
|
|
|
2020-12-05 12:28:36 +01:00
|
|
|
@pyqtSlot('const QPoint&')
|
|
|
|
def open_context_menu(self, point):
|
|
|
|
self.context_menu.exec_(self.table.mapToGlobal(
|
|
|
|
point + QPoint(10, 0)))
|
|
|
|
|
|
|
|
def show_log(self):
|
|
|
|
logfiles = []
|
2020-07-30 02:40:40 +02:00
|
|
|
|
2018-05-31 00:47:38 +02:00
|
|
|
try:
|
2020-12-05 12:28:36 +01:00
|
|
|
for vm_info in self.get_selected_vms():
|
|
|
|
vm = vm_info.vm
|
2017-12-20 22:33:39 +01:00
|
|
|
|
2020-08-03 23:25:20 +02:00
|
|
|
if vm.klass == 'AdminVM':
|
2020-12-05 12:28:36 +01:00
|
|
|
logfiles.append("/var/log/xen/console/hypervisor.log")
|
2020-07-30 02:40:40 +02:00
|
|
|
else:
|
2020-12-05 12:28:36 +01:00
|
|
|
logfiles.extend([
|
2020-07-30 02:40:40 +02:00
|
|
|
"/var/log/xen/console/guest-" + vm.name + ".log",
|
|
|
|
"/var/log/xen/console/guest-" + vm.name + "-dm.log",
|
|
|
|
"/var/log/qubes/guid." + vm.name + ".log",
|
|
|
|
"/var/log/qubes/qrexec." + vm.name + ".log",
|
2020-12-05 12:28:36 +01:00
|
|
|
])
|
2018-05-31 00:47:38 +02:00
|
|
|
|
2020-12-11 01:01:21 +01:00
|
|
|
logfiles = [x for x in logfiles if path.exists(x)]
|
2020-12-11 00:53:57 +01:00
|
|
|
|
|
|
|
if len(logfiles) > 0:
|
|
|
|
log_dlg = log_dialog.LogDialog(self.qt_app, logfiles)
|
|
|
|
log_dlg.exec_()
|
|
|
|
else:
|
|
|
|
QMessageBox.warning(
|
|
|
|
self,
|
|
|
|
self.tr("Error"),
|
|
|
|
self.tr(
|
2021-01-28 21:08:11 +01:00
|
|
|
"No log files were found for the selected qubes."))
|
2020-12-11 00:53:57 +01:00
|
|
|
|
2020-08-11 01:08:48 +02:00
|
|
|
except exc.QubesDaemonAccessError:
|
2018-05-31 00:47:38 +02:00
|
|
|
pass
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
def main():
|
2019-11-08 23:35:26 +01:00
|
|
|
manager_utils.run_asynchronous(VmManagerWindow)
|
2017-12-20 22:33:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|