2018-01-08 20:31:12 +01:00
|
|
|
#!/usr/bin/python3
|
2012-01-31 11:17:09 +01:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
|
2017-06-26 17:54:35 +02:00
|
|
|
# Copyright (C) 2012 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2017 Wojtek Porczyk <woju@invisiblethingslab.com>
|
2012-01-31 11:17:09 +01:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2017-11-06 21:06:30 +01:00
|
|
|
# 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/>.
|
2012-01-31 11:17:09 +01:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2017-06-26 17:54:35 +02:00
|
|
|
import collections
|
2019-09-26 22:31:39 +02:00
|
|
|
import functools
|
2017-10-12 17:06:17 +02:00
|
|
|
import re
|
2012-01-31 11:17:09 +01:00
|
|
|
import subprocess
|
2017-07-12 14:35:59 +02:00
|
|
|
import traceback
|
2017-11-06 22:46:35 +01:00
|
|
|
from qubesadmin.tools import QubesArgumentParser
|
2017-11-17 17:34:38 +01:00
|
|
|
from qubesadmin import devices
|
2018-07-20 00:03:37 +02:00
|
|
|
from qubesadmin import utils as admin_utils
|
2017-11-08 15:40:35 +01:00
|
|
|
import qubesadmin.exc
|
2017-06-26 17:54:35 +02:00
|
|
|
|
2017-07-12 14:08:34 +02:00
|
|
|
from . import utils
|
2017-07-12 14:09:07 +02:00
|
|
|
from . import multiselectwidget
|
2018-10-20 18:34:15 +02:00
|
|
|
from . import common_threads
|
2018-01-10 00:51:05 +01:00
|
|
|
from . import device_list
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2017-07-12 14:09:07 +02:00
|
|
|
from .appmenu_select import AppmenuSelectManager
|
2017-11-06 20:36:09 +01:00
|
|
|
from . import firewall
|
2019-05-22 23:10:09 +02:00
|
|
|
from PyQt5 import QtCore, QtWidgets, QtGui # pylint: disable=import-error
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
from . import ui_settingsdlg # pylint: disable=no-name-in-module
|
2017-07-12 14:35:59 +02:00
|
|
|
|
2019-06-14 21:13:56 +02:00
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-06-14 21:13:56 +02:00
|
|
|
class RenameVMThread(common_threads.QubesThread):
|
2018-10-20 18:34:15 +02:00
|
|
|
def __init__(self, vm, new_vm_name, dependencies):
|
2019-06-14 21:13:56 +02:00
|
|
|
super(RenameVMThread, self).__init__(vm)
|
2018-10-20 18:34:15 +02:00
|
|
|
self.new_vm_name = new_vm_name
|
|
|
|
self.dependencies = dependencies
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
try:
|
|
|
|
new_vm = self.vm.app.clone_vm(self.vm, self.new_vm_name)
|
|
|
|
|
|
|
|
failed_props = []
|
|
|
|
|
|
|
|
for (holder, prop) in self.dependencies:
|
|
|
|
try:
|
|
|
|
if holder is None:
|
|
|
|
setattr(self.vm.app, prop, new_vm)
|
|
|
|
else:
|
|
|
|
setattr(holder, prop, new_vm)
|
2018-10-21 00:06:37 +02:00
|
|
|
except qubesadmin.exc.QubesException:
|
2018-10-20 18:34:15 +02:00
|
|
|
failed_props += [(holder, prop)]
|
|
|
|
if not failed_props:
|
|
|
|
del self.vm.app.domains[self.vm.name]
|
|
|
|
else:
|
|
|
|
list_text = utils.format_dependencies_list(failed_props)
|
2019-02-26 21:05:42 +01:00
|
|
|
self.msg = (self.tr("Warning: rename partially unsuccessful!"),
|
|
|
|
self.tr("Some properties could not be changed to "
|
|
|
|
"the new name. The system has now both {} "
|
|
|
|
"and {} qubes. To resolve this, please "
|
|
|
|
"check and change the following properties "
|
|
|
|
"and remove the qube {} manually.<br>"
|
|
|
|
).format(self.vm.name, self.vm.name,
|
|
|
|
self.vm.name) + list_text)
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2018-10-21 00:06:37 +02:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2019-10-23 18:18:39 +02:00
|
|
|
self.msg = (self.tr("Rename error!"), str(ex))
|
2018-10-20 18:34:15 +02:00
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
2019-10-23 18:18:39 +02:00
|
|
|
self.msg = (self.tr("Rename error!"), repr(ex))
|
2018-10-20 18:34:15 +02:00
|
|
|
|
|
|
|
|
2018-10-22 10:14:26 +02:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-06-14 21:13:56 +02:00
|
|
|
class RefreshAppsVMThread(common_threads.QubesThread):
|
2018-11-30 21:47:15 +01:00
|
|
|
def __init__(self, vm, button):
|
2019-06-14 21:13:56 +02:00
|
|
|
super(RefreshAppsVMThread, self).__init__(vm)
|
2018-11-30 21:47:15 +01:00
|
|
|
self.button = button
|
2018-10-20 18:34:15 +02:00
|
|
|
|
|
|
|
def run(self):
|
2018-11-30 21:47:15 +01:00
|
|
|
vms_to_refresh = [self.vm]
|
|
|
|
template = getattr(self.vm, 'template', None)
|
|
|
|
if template:
|
|
|
|
vms_to_refresh.append(template)
|
|
|
|
|
|
|
|
for vm in vms_to_refresh:
|
|
|
|
self.button.setText(
|
|
|
|
self.tr('Refresh in progress (refreshing applications '
|
|
|
|
'from {})').format(vm.name))
|
2018-10-20 18:34:15 +02:00
|
|
|
try:
|
2018-11-30 21:47:15 +01:00
|
|
|
if not vm.is_running():
|
|
|
|
not_running = True
|
|
|
|
vm.start()
|
|
|
|
else:
|
|
|
|
not_running = False
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2018-11-30 21:47:15 +01:00
|
|
|
subprocess.check_call(['qvm-sync-appmenus', vm.name])
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2018-11-30 21:47:15 +01:00
|
|
|
if not_running:
|
|
|
|
vm.shutdown()
|
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
2019-10-23 18:18:39 +02:00
|
|
|
self.msg = (self.tr("Refresh failed!"), str(ex))
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2017-07-12 14:35:59 +02:00
|
|
|
|
2017-11-09 17:32:40 +01:00
|
|
|
# pylint: disable=too-many-instance-attributes
|
2019-05-22 23:10:09 +02:00
|
|
|
class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
|
2017-06-26 17:54:35 +02:00
|
|
|
tabs_indices = collections.OrderedDict((
|
2018-10-21 22:38:41 +02:00
|
|
|
('basic', 0),
|
|
|
|
('advanced', 1),
|
|
|
|
('firewall', 2),
|
|
|
|
('devices', 3),
|
|
|
|
('applications', 4),
|
|
|
|
('services', 5),
|
2017-06-26 17:54:35 +02:00
|
|
|
))
|
|
|
|
|
2019-09-26 22:31:39 +02:00
|
|
|
def __init__(self, vm, init_page="basic", qapp=None, qubesapp=None,
|
|
|
|
parent=None):
|
2012-01-31 11:17:09 +01:00
|
|
|
super(VMSettingsWindow, self).__init__(parent)
|
|
|
|
|
2012-02-10 00:30:45 +01:00
|
|
|
self.vm = vm
|
2017-06-26 17:54:35 +02:00
|
|
|
self.qapp = qapp
|
2019-09-26 22:31:39 +02:00
|
|
|
self.qubesapp = qubesapp
|
2018-10-20 18:34:15 +02:00
|
|
|
self.threads_list = []
|
2018-10-20 22:09:39 +02:00
|
|
|
self.progress = None
|
|
|
|
self.thread_closes = False
|
2017-07-28 16:47:11 +02:00
|
|
|
try:
|
2012-03-12 12:53:07 +01:00
|
|
|
self.source_vm = self.vm.template
|
2017-07-28 16:47:11 +02:00
|
|
|
except AttributeError:
|
2012-02-10 00:30:45 +01:00
|
|
|
self.source_vm = self.vm
|
2014-02-17 00:35:45 +01:00
|
|
|
|
2012-01-31 11:17:09 +01:00
|
|
|
self.setupUi(self)
|
2017-06-28 12:25:28 +02:00
|
|
|
self.setWindowTitle(self.tr("Settings: {vm}").format(vm=self.vm.name))
|
2012-02-09 19:47:21 +01:00
|
|
|
if init_page in self.tabs_indices:
|
|
|
|
idx = self.tabs_indices[init_page]
|
2017-11-09 17:30:22 +01:00
|
|
|
assert idx in range(self.tabWidget.count())
|
2012-02-09 19:47:21 +01:00
|
|
|
self.tabWidget.setCurrentIndex(idx)
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).clicked.connect(
|
2018-02-20 20:32:00 +01:00
|
|
|
self.apply)
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2012-02-10 00:30:45 +01:00
|
|
|
self.tabWidget.currentChanged.connect(self.current_tab_changed)
|
|
|
|
|
2019-02-23 18:19:58 +01:00
|
|
|
# Initialize several auxillary variables for pylint's sake
|
|
|
|
self.netvm_idx = None
|
|
|
|
self.kernel_idx = None
|
|
|
|
self.label_idx = None
|
|
|
|
self.template_idx = None
|
|
|
|
self.root_img_size = None
|
|
|
|
self.priv_img_size = None
|
|
|
|
self.default_dispvm_idx = None
|
|
|
|
self.virt_mode_idx = None
|
|
|
|
self.virt_mode_list = None
|
|
|
|
|
2012-02-13 13:50:30 +01:00
|
|
|
###### basic tab
|
|
|
|
self.__init_basic_tab__()
|
2017-07-29 12:49:02 +02:00
|
|
|
self.rename_vm_button.clicked.connect(self.rename_vm)
|
2017-11-03 22:20:34 +01:00
|
|
|
self.delete_vm_button.clicked.connect(self.remove_vm)
|
2017-11-03 23:50:04 +01:00
|
|
|
self.clone_vm_button.clicked.connect(self.clone_vm)
|
2012-02-13 13:50:30 +01:00
|
|
|
|
2012-03-12 21:08:32 +01:00
|
|
|
###### advanced tab
|
|
|
|
self.__init_advanced_tab__()
|
2017-11-06 23:18:18 +01:00
|
|
|
self.include_in_balancing.stateChanged.connect(
|
2017-11-08 16:53:49 +01:00
|
|
|
self.include_in_balancing_changed)
|
2019-05-22 23:10:09 +02:00
|
|
|
self.init_mem.editingFinished.connect(self.check_mem_changes)
|
|
|
|
self.max_mem_size.editingFinished.connect(self.check_mem_changes)
|
2017-11-08 16:53:49 +01:00
|
|
|
self.boot_from_device_button.clicked.connect(
|
2017-11-06 23:18:18 +01:00
|
|
|
self.boot_from_cdrom_button_pressed)
|
2012-03-12 21:08:32 +01:00
|
|
|
|
2012-02-10 00:30:45 +01:00
|
|
|
###### firewall tab
|
2017-07-12 14:47:37 +02:00
|
|
|
if self.tabWidget.isTabEnabled(self.tabs_indices['firewall']):
|
2017-11-06 20:36:09 +01:00
|
|
|
model = firewall.QubesFirewallRulesModel()
|
2017-10-13 18:04:49 +02:00
|
|
|
try:
|
|
|
|
model.set_vm(vm)
|
|
|
|
self.set_fw_model(model)
|
2017-11-08 16:53:49 +01:00
|
|
|
self.firewall_modified_outside_label.setVisible(False)
|
2017-11-09 16:26:05 +01:00
|
|
|
except firewall.FirewallModifiedOutsideError:
|
2017-10-13 18:04:49 +02:00
|
|
|
self.disable_all_fw_conf()
|
2012-02-10 00:30:45 +01:00
|
|
|
|
2017-11-08 16:53:49 +01:00
|
|
|
self.new_rule_button.clicked.connect(self.new_rule_button_pressed)
|
|
|
|
self.edit_rule_button.clicked.connect(self.edit_rule_button_pressed)
|
|
|
|
self.delete_rule_button.clicked.connect(
|
2017-11-06 23:18:18 +01:00
|
|
|
self.delete_rule_button_pressed)
|
2017-11-08 16:53:49 +01:00
|
|
|
self.policy_deny_radio_button.clicked.connect(self.policy_changed)
|
|
|
|
self.policy_allow_radio_button.clicked.connect(self.policy_changed)
|
2018-01-12 04:30:47 +01:00
|
|
|
if init_page == 'firewall':
|
|
|
|
self.check_network_availability()
|
2012-02-10 00:30:45 +01:00
|
|
|
|
|
|
|
####### devices tab
|
2012-03-13 20:06:41 +01:00
|
|
|
self.__init_devices_tab__()
|
2019-05-22 23:10:09 +02:00
|
|
|
self.dev_list.selectedChanged.connect(self.devices_selection_changed)
|
2018-01-10 00:51:05 +01:00
|
|
|
self.no_strict_reset_button.clicked.connect(
|
|
|
|
self.strict_reset_button_pressed)
|
2018-01-12 23:56:48 +01:00
|
|
|
self.current_strict_reset_list = []
|
|
|
|
self.new_strict_reset_list = []
|
|
|
|
self.define_strict_reset_devices()
|
2014-02-17 00:35:45 +01:00
|
|
|
|
2012-03-14 11:54:50 +01:00
|
|
|
####### services tab
|
|
|
|
self.__init_services_tab__()
|
2018-07-16 01:14:33 +02:00
|
|
|
self.service_line_edit.lineEdit().returnPressed.connect(
|
|
|
|
self.__add_service__)
|
2012-03-14 11:54:50 +01:00
|
|
|
self.add_srv_button.clicked.connect(self.__add_service__)
|
|
|
|
self.remove_srv_button.clicked.connect(self.__remove_service__)
|
|
|
|
|
2012-02-10 00:30:45 +01:00
|
|
|
####### apps tab
|
2012-03-08 15:40:02 +01:00
|
|
|
if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
|
2017-07-12 14:09:07 +02:00
|
|
|
self.app_list = multiselectwidget.MultiSelectWidget(self)
|
2012-02-13 13:50:30 +01:00
|
|
|
self.apps_layout.addWidget(self.app_list)
|
2017-11-08 16:53:49 +01:00
|
|
|
self.app_list_manager = AppmenuSelectManager(self.vm, self.app_list)
|
2017-11-06 23:18:18 +01:00
|
|
|
self.refresh_apps_button.clicked.connect(
|
|
|
|
self.refresh_apps_button_pressed)
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2019-11-08 23:35:26 +01:00
|
|
|
def setup_application(self):
|
2019-11-28 15:44:54 +01:00
|
|
|
self.qapp.setApplicationName(self.tr("Qube Settings"))
|
|
|
|
self.qapp.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
|
2019-11-08 23:35:26 +01:00
|
|
|
|
2018-10-20 18:34:15 +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-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
|
|
|
self,
|
2019-10-23 18:18:39 +02:00
|
|
|
title,
|
|
|
|
msg)
|
2018-10-20 18:34:15 +02:00
|
|
|
|
|
|
|
self.threads_list.remove(thread)
|
|
|
|
|
2018-10-20 22:09:39 +02:00
|
|
|
if self.thread_closes:
|
|
|
|
self.done(0)
|
|
|
|
|
2018-11-25 19:33:16 +01:00
|
|
|
return
|
|
|
|
|
2019-10-23 18:18:39 +02:00
|
|
|
raise RuntimeError(self.tr('No finished thread found'))
|
2018-11-25 18:37:34 +01:00
|
|
|
|
2018-05-17 19:58:44 +02:00
|
|
|
def keyPressEvent(self, event): # pylint: disable=invalid-name
|
2018-05-17 19:41:20 +02:00
|
|
|
if event.key() == QtCore.Qt.Key_Enter \
|
|
|
|
or event.key() == QtCore.Qt.Key_Return:
|
|
|
|
return
|
2018-07-16 02:00:28 +02:00
|
|
|
super(VMSettingsWindow, self).keyPressEvent(event)
|
2018-05-17 19:41:20 +02:00
|
|
|
|
2012-02-09 19:47:21 +01:00
|
|
|
def accept(self):
|
2019-02-16 15:54:22 +01:00
|
|
|
self.save_and_apply()
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2018-02-20 20:32:00 +01:00
|
|
|
def save_changes(self):
|
2019-03-31 20:04:04 +02:00
|
|
|
with common_threads.busy_cursor():
|
|
|
|
error = self.__save_changes__()
|
2012-02-09 19:47:21 +01:00
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
if error:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2018-06-12 22:50:03 +02:00
|
|
|
self,
|
2019-05-22 23:10:09 +02:00
|
|
|
self.tr("Error while changing settings for {0}!"
|
|
|
|
).format(self.vm.name),
|
2018-10-20 23:01:35 +02:00
|
|
|
self.tr("ERROR: {0}").format('\n'.join(error)))
|
2012-02-09 19:47:21 +01:00
|
|
|
|
2018-02-20 20:32:00 +01:00
|
|
|
def apply(self):
|
2019-03-31 20:04:04 +02:00
|
|
|
self.save_changes()
|
2018-02-20 20:32:00 +01:00
|
|
|
|
|
|
|
def save_and_apply(self):
|
2019-03-31 20:04:04 +02:00
|
|
|
self.save_changes()
|
2012-02-09 19:47:21 +01:00
|
|
|
self.done(0)
|
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
def __save_changes__(self):
|
2013-02-23 06:44:06 +01:00
|
|
|
ret = []
|
2018-10-20 18:34:15 +02:00
|
|
|
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
|
|
|
ret_tmp = self.__apply_basic_tab__()
|
2017-11-14 15:29:57 +01:00
|
|
|
if ret_tmp:
|
2019-10-23 18:18:39 +02:00
|
|
|
ret += [self.tr("Basic tab:")] + ret_tmp
|
2013-02-23 06:44:06 +01:00
|
|
|
ret_tmp = self.__apply_advanced_tab__()
|
2017-11-14 15:29:57 +01:00
|
|
|
if ret_tmp:
|
2019-10-23 18:18:39 +02:00
|
|
|
ret += [self.tr("Advanced tab:")] + ret_tmp
|
2013-02-23 06:44:06 +01:00
|
|
|
ret_tmp = self.__apply_devices_tab__()
|
2017-11-14 15:29:57 +01:00
|
|
|
if ret_tmp:
|
2019-10-23 18:18:39 +02:00
|
|
|
ret += [self.tr("Devices tab:")] + ret_tmp
|
2013-02-23 06:44:06 +01:00
|
|
|
ret_tmp = self.__apply_services_tab__()
|
2017-11-14 15:29:57 +01:00
|
|
|
if ret_tmp:
|
2019-10-23 18:18:39 +02:00
|
|
|
ret += [self.tr("Sevices tab:")] + ret_tmp
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as qex:
|
|
|
|
ret.append(self.tr('Error while saving changes: ') + str(qex))
|
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
|
|
|
ret.append(repr(ex))
|
2012-03-12 15:54:16 +01:00
|
|
|
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
2017-11-08 16:53:49 +01:00
|
|
|
if self.policy_allow_radio_button.isEnabled():
|
2017-11-06 23:18:18 +01:00
|
|
|
self.fw_model.apply_rules(
|
2017-11-08 16:53:49 +01:00
|
|
|
self.policy_allow_radio_button.isChecked(),
|
|
|
|
self.temp_full_access.isChecked(),
|
|
|
|
self.temp_full_access_time.value())
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as qex:
|
2017-11-09 17:30:22 +01:00
|
|
|
ret += [self.tr("Firewall tab:"), str(qex)]
|
2017-11-08 15:40:35 +01:00
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
|
|
|
ret += [self.tr("Firewall tab:"), repr(ex)]
|
2013-02-23 06:44:06 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
|
2017-11-08 16:53:49 +01:00
|
|
|
self.app_list_manager.save_appmenu_select_changes()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as qex:
|
|
|
|
ret += [self.tr("Applications tab:"), str(qex)]
|
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
|
|
|
ret += [self.tr("Applications tab:"), repr(ex)]
|
2012-03-12 15:54:16 +01:00
|
|
|
|
2017-07-12 14:08:34 +02:00
|
|
|
utils.debug('\n'.join(ret))
|
2018-10-20 18:34:15 +02:00
|
|
|
return ret
|
2012-03-01 22:50:32 +01:00
|
|
|
|
2018-01-12 04:30:47 +01:00
|
|
|
def check_network_availability(self):
|
|
|
|
netvm = self.vm.netvm
|
2019-10-29 11:53:44 +01:00
|
|
|
try:
|
|
|
|
provides_network = self.vm.provides_network
|
|
|
|
except AttributeError:
|
|
|
|
provides_network = False
|
|
|
|
self.no_netvm_label.setVisible(netvm is None and not provides_network)
|
2018-01-12 04:30:47 +01:00
|
|
|
self.netvm_no_firewall_label.setVisible(
|
|
|
|
netvm is not None and
|
|
|
|
not netvm.features.check_with_template('qubes-firewall', False))
|
2019-10-29 11:53:44 +01:00
|
|
|
self.sysnet_warning_label.setVisible(netvm is None and provides_network)
|
2012-02-10 00:30:45 +01:00
|
|
|
|
2018-01-12 04:30:47 +01:00
|
|
|
def current_tab_changed(self, idx):
|
|
|
|
if idx == self.tabs_indices["firewall"]:
|
|
|
|
self.check_network_availability()
|
2012-02-10 00:30:45 +01:00
|
|
|
|
2012-02-13 13:50:30 +01:00
|
|
|
######### basic tab
|
|
|
|
|
2017-06-26 17:54:35 +02:00
|
|
|
# TODO LISTENERS
|
2017-07-12 14:08:34 +02:00
|
|
|
# - vm start/shutdown -> setEnabled on fields: template labels
|
2017-06-26 17:54:35 +02:00
|
|
|
# - vm create/delete -> choices lists, whole window deactiv (if self.vm)
|
|
|
|
# - property-set -> individual fields
|
|
|
|
|
|
|
|
# TODO INTERACTIONS
|
|
|
|
# netvm -> networking_groupbox
|
|
|
|
# hvm -> include_in_balancing
|
|
|
|
|
2017-07-12 14:08:34 +02:00
|
|
|
# TODO REMOVE
|
|
|
|
# other_groupbox
|
2017-06-26 17:54:35 +02:00
|
|
|
|
2012-02-13 13:50:30 +01:00
|
|
|
def __init_basic_tab__(self):
|
|
|
|
self.vmname.setText(self.vm.name)
|
2017-11-06 23:18:18 +01:00
|
|
|
self.vmname.setValidator(
|
|
|
|
QtGui.QRegExpValidator(
|
2018-07-13 20:40:17 +02:00
|
|
|
QtCore.QRegExp("[a-zA-Z0-9_-]*",
|
2017-11-06 23:18:18 +01:00
|
|
|
QtCore.Qt.CaseInsensitive), None))
|
2017-06-26 17:54:35 +02:00
|
|
|
self.vmname.setEnabled(False)
|
2017-07-29 12:49:02 +02:00
|
|
|
self.rename_vm_button.setEnabled(not self.vm.is_running())
|
2017-11-03 22:20:34 +01:00
|
|
|
self.delete_vm_button.setEnabled(not self.vm.is_running())
|
|
|
|
|
|
|
|
if self.vm.is_running():
|
2018-01-08 20:56:22 +01:00
|
|
|
self.delete_vm_button.setText(
|
2018-01-28 20:26:29 +01:00
|
|
|
self.tr('Delete qube (cannot delete a running qube)'))
|
2014-02-17 00:35:45 +01:00
|
|
|
|
2012-04-27 11:54:53 +02:00
|
|
|
if self.vm.qid == 0:
|
|
|
|
self.vmlabel.setVisible(False)
|
2014-02-17 00:35:45 +01:00
|
|
|
else:
|
2017-07-12 14:08:34 +02:00
|
|
|
self.label_list, self.label_idx = utils.prepare_label_choice(
|
|
|
|
self.vmlabel,
|
|
|
|
self.vm, 'label',
|
|
|
|
None,
|
|
|
|
allow_default=False
|
|
|
|
)
|
2012-04-27 11:54:53 +02:00
|
|
|
self.vmlabel.setVisible(True)
|
2017-07-12 14:08:34 +02:00
|
|
|
self.vmlabel.setEnabled(not self.vm.is_running())
|
2012-02-13 13:50:30 +01:00
|
|
|
|
2017-10-07 00:22:41 +02:00
|
|
|
if self.vm.klass == 'AppVM':
|
2017-07-12 14:08:34 +02:00
|
|
|
self.template_list, self.template_idx = utils.prepare_vm_choice(
|
|
|
|
self.template_name,
|
|
|
|
self.vm, 'template',
|
|
|
|
self.vm.app.default_template,
|
2017-10-07 00:22:41 +02:00
|
|
|
(lambda vm: vm.klass == 'TemplateVM'),
|
2018-02-06 15:38:20 +01:00
|
|
|
allow_default=False, allow_none=False)
|
2012-02-13 13:50:30 +01:00
|
|
|
else:
|
|
|
|
self.template_name.setEnabled(False)
|
2012-03-12 21:08:32 +01:00
|
|
|
self.template_idx = -1
|
2012-02-13 13:50:30 +01:00
|
|
|
|
2017-07-12 14:08:34 +02:00
|
|
|
self.netvm_list, self.netvm_idx = utils.prepare_vm_choice(
|
|
|
|
self.netVM,
|
|
|
|
self.vm, 'netvm',
|
|
|
|
self.vm.app.default_netvm,
|
|
|
|
(lambda vm: vm.provides_network),
|
|
|
|
allow_default=True, allow_none=True)
|
2012-02-13 13:50:30 +01:00
|
|
|
|
2019-02-19 22:15:03 +01:00
|
|
|
self.netVM.currentIndexChanged.connect(self.check_warn_dispvmnetvm)
|
|
|
|
|
2012-03-07 20:42:18 +01:00
|
|
|
self.include_in_backups.setChecked(self.vm.include_in_backups)
|
|
|
|
|
2017-06-26 17:54:35 +02:00
|
|
|
try:
|
2012-04-24 14:27:28 +02:00
|
|
|
self.run_in_debug_mode.setChecked(self.vm.debug)
|
2017-06-26 17:54:35 +02:00
|
|
|
self.run_in_debug_mode.setVisible(True)
|
|
|
|
except AttributeError:
|
2012-04-24 14:27:28 +02:00
|
|
|
self.run_in_debug_mode.setVisible(False)
|
|
|
|
|
2017-06-26 17:54:35 +02:00
|
|
|
try:
|
2014-05-17 19:21:00 +02:00
|
|
|
self.autostart_vm.setChecked(self.vm.autostart)
|
2017-06-26 17:54:35 +02:00
|
|
|
self.autostart_vm.setVisible(True)
|
|
|
|
except AttributeError:
|
2014-05-17 19:21:00 +02:00
|
|
|
self.autostart_vm.setVisible(False)
|
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# type
|
2017-10-16 03:10:19 +02:00
|
|
|
self.type_label.setText(self.vm.klass)
|
2012-03-07 20:42:18 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# installed by rpm
|
2017-06-26 17:54:35 +02:00
|
|
|
self.rpm_label.setText('Yes' if self.vm.installed_by_rpm else 'No')
|
2012-03-07 20:42:18 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# networking info
|
2017-06-26 17:54:35 +02:00
|
|
|
if self.vm.netvm:
|
2014-02-23 00:44:08 +01:00
|
|
|
self.networking_groupbox.setEnabled(True)
|
2017-07-12 14:47:37 +02:00
|
|
|
self.ip_label.setText(self.vm.ip or "none")
|
|
|
|
self.netmask_label.setText(self.vm.visible_netmask or "none")
|
|
|
|
self.gateway_label.setText(self.vm.visible_gateway or "none")
|
2019-05-29 22:24:24 +02:00
|
|
|
dns_list = getattr(self.vm, 'dns', ['10.139.1.1', '10.139.1.2'])
|
|
|
|
self.dns_label.setText(", ".join(dns_list))
|
2012-03-09 08:43:42 +01:00
|
|
|
else:
|
2014-02-23 00:44:08 +01:00
|
|
|
self.networking_groupbox.setEnabled(False)
|
2012-03-09 08:43:42 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# max priv storage
|
2017-07-30 18:56:35 +02:00
|
|
|
self.priv_img_size = self.vm.volumes['private'].size // 1024**2
|
2017-07-12 14:50:40 +02:00
|
|
|
self.max_priv_storage.setMinimum(self.priv_img_size)
|
|
|
|
self.max_priv_storage.setValue(self.priv_img_size)
|
2012-03-09 08:43:42 +01:00
|
|
|
|
2017-07-30 18:56:35 +02:00
|
|
|
self.root_img_size = self.vm.volumes['root'].size // 1024**2
|
2017-07-12 14:50:40 +02:00
|
|
|
self.root_resize.setValue(self.root_img_size)
|
|
|
|
self.root_resize.setMinimum(self.root_img_size)
|
2017-07-30 18:56:35 +02:00
|
|
|
self.root_resize.setEnabled(self.vm.volumes['root'].save_on_stop)
|
2018-12-28 17:13:39 +01:00
|
|
|
if not self.root_resize.isEnabled():
|
|
|
|
self.root_resize.setToolTip(
|
|
|
|
self.tr("To change system storage size, change properties "
|
|
|
|
"of the underlying template."))
|
2017-07-12 14:50:40 +02:00
|
|
|
self.root_resize_label.setEnabled(self.root_resize.isEnabled())
|
2012-02-13 13:50:30 +01:00
|
|
|
|
|
|
|
def __apply_basic_tab__(self):
|
|
|
|
msg = []
|
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# vm label changed
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
|
|
|
if self.vmlabel.isVisible():
|
|
|
|
if self.vmlabel.currentIndex() != self.label_idx:
|
|
|
|
label = self.label_list[self.vmlabel.currentIndex()]
|
|
|
|
self.vm.label = label
|
2019-02-23 18:19:58 +01:00
|
|
|
self.label_idx = self.vmlabel.currentIndex()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
2012-02-13 13:50:30 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# vm template changed
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
|
|
|
if self.template_name.currentIndex() != self.template_idx:
|
2017-06-26 17:54:35 +02:00
|
|
|
self.vm.template = \
|
|
|
|
self.template_list[self.template_name.currentIndex()]
|
2019-02-23 18:19:58 +01:00
|
|
|
self.template_idx = self.template_name.currentIndex()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
2012-02-13 13:50:30 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# vm netvm changed
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
|
|
|
if self.netVM.currentIndex() != self.netvm_idx:
|
2017-06-26 17:54:35 +02:00
|
|
|
self.vm.netvm = self.netvm_list[self.netVM.currentIndex()]
|
2019-02-23 18:19:58 +01:00
|
|
|
self.netvm_idx = self.netVM.currentIndex()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
2012-03-07 20:42:18 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# include in backups
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
2017-11-06 23:18:18 +01:00
|
|
|
if self.vm.include_in_backups != \
|
|
|
|
self.include_in_backups.isChecked():
|
2013-02-23 06:44:06 +01:00
|
|
|
self.vm.include_in_backups = self.include_in_backups.isChecked()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
2012-04-24 14:27:28 +02:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# run_in_debug_mode
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
|
|
|
if self.run_in_debug_mode.isVisible():
|
|
|
|
if self.vm.debug != self.run_in_debug_mode.isChecked():
|
|
|
|
self.vm.debug = self.run_in_debug_mode.isChecked()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
2012-03-07 18:15:59 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# autostart_vm
|
2014-05-17 19:21:00 +02:00
|
|
|
try:
|
|
|
|
if self.autostart_vm.isVisible():
|
|
|
|
if self.vm.autostart != self.autostart_vm.isChecked():
|
|
|
|
self.vm.autostart = self.autostart_vm.isChecked()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2014-05-17 19:21:00 +02:00
|
|
|
msg.append(str(ex))
|
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# max priv storage
|
2012-03-14 12:51:11 +01:00
|
|
|
priv_size = self.max_priv_storage.value()
|
|
|
|
if self.priv_img_size != priv_size:
|
|
|
|
try:
|
2017-07-30 18:56:35 +02:00
|
|
|
self.vm.volumes['private'].resize(priv_size * 1024**2)
|
2019-02-23 18:19:58 +01:00
|
|
|
self.priv_img_size = priv_size
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2012-03-14 12:51:11 +01:00
|
|
|
msg.append(str(ex))
|
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# max sys storage
|
2014-03-21 18:40:23 +01:00
|
|
|
sys_size = self.root_resize.value()
|
|
|
|
if self.root_img_size != sys_size:
|
|
|
|
try:
|
2017-10-08 16:57:08 +02:00
|
|
|
self.vm.volumes['root'].resize(sys_size * 1024**2)
|
2019-02-23 18:19:58 +01:00
|
|
|
self.root_img_size = sys_size
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2014-03-21 18:40:23 +01:00
|
|
|
msg.append(str(ex))
|
2012-03-07 21:21:14 +01:00
|
|
|
|
2012-03-07 18:15:59 +01:00
|
|
|
return msg
|
2012-03-12 21:08:32 +01:00
|
|
|
|
2014-09-16 21:25:52 +02:00
|
|
|
def check_mem_changes(self):
|
2013-10-29 13:41:46 +01:00
|
|
|
if self.max_mem_size.value() < self.init_mem.value():
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2018-06-12 22:50:03 +02:00
|
|
|
self,
|
2017-01-22 05:42:38 +01:00
|
|
|
self.tr("Warning!"),
|
|
|
|
self.tr("Max memory can not be less than initial memory.<br>"
|
|
|
|
"Setting max memory to equal initial memory."))
|
2013-10-29 13:41:46 +01:00
|
|
|
self.max_mem_size.setValue(self.init_mem.value())
|
2017-11-06 23:18:18 +01:00
|
|
|
# Linux specific limit: init memory must not be below
|
|
|
|
# max_mem_size/10.79 in order to allow scaling up to
|
|
|
|
# max_mem_size (or else "add_memory() failed: -17" problem)
|
2014-09-16 21:25:52 +02:00
|
|
|
if self.init_mem.value() * 10 < self.max_mem_size.value():
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2018-06-12 22:50:03 +02:00
|
|
|
self,
|
2017-01-22 05:42:38 +01:00
|
|
|
self.tr("Warning!"),
|
|
|
|
self.tr("Initial memory can not be less than one tenth "
|
|
|
|
"Max memory.<br>Setting initial memory to the minimum "
|
|
|
|
"allowed value."))
|
2019-08-17 15:42:36 +02:00
|
|
|
self.init_mem.setValue((self.max_mem_size.value() + 9) // 10)
|
2014-09-16 21:25:52 +02:00
|
|
|
|
2019-02-19 22:15:03 +01:00
|
|
|
def check_warn_dispvmnetvm(self):
|
|
|
|
if not hasattr(self.vm, 'default_dispvm'):
|
|
|
|
self.warn_netvm_dispvm.setVisible(False)
|
|
|
|
return
|
|
|
|
dispvm = self.default_dispvm_list[
|
|
|
|
self.default_dispvm.currentIndex()]
|
|
|
|
own_netvm = self.netvm_list[self.netVM.currentIndex()]
|
|
|
|
|
|
|
|
if dispvm == qubesadmin.DEFAULT:
|
|
|
|
dispvm = self.vm.property_get_default('default_dispvm')
|
2019-02-26 19:31:41 +01:00
|
|
|
|
|
|
|
if dispvm == self.vm:
|
|
|
|
self.warn_netvm_dispvm.setVisible(False)
|
|
|
|
return
|
|
|
|
|
2019-02-19 22:15:03 +01:00
|
|
|
dispvm_netvm = getattr(dispvm, 'netvm', None)
|
|
|
|
|
|
|
|
if own_netvm == qubesadmin.DEFAULT:
|
|
|
|
own_netvm = self.vm.property_get_default('netvm')
|
|
|
|
|
|
|
|
if dispvm_netvm and dispvm_netvm != own_netvm:
|
|
|
|
self.warn_netvm_dispvm.setVisible(True)
|
|
|
|
else:
|
|
|
|
self.warn_netvm_dispvm.setVisible(False)
|
|
|
|
|
2017-07-29 12:49:02 +02:00
|
|
|
def rename_vm(self):
|
2018-07-20 00:03:37 +02:00
|
|
|
|
|
|
|
dependencies = admin_utils.vm_dependencies(self.vm.app, self.vm)
|
|
|
|
|
|
|
|
running_dependencies = [vm.name for (vm, prop) in dependencies
|
|
|
|
if vm and prop == 'template'
|
|
|
|
and vm.is_running()]
|
|
|
|
|
|
|
|
if running_dependencies:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2018-07-20 00:03:37 +02:00
|
|
|
self,
|
|
|
|
self.tr("Qube cannot be renamed!"),
|
|
|
|
self.tr(
|
|
|
|
"The following qubes using this qube as a template are "
|
|
|
|
"running: <br> {}. <br> In order to rename this qube, you "
|
2018-07-20 17:48:39 +02:00
|
|
|
"must first shut them down.").format(
|
|
|
|
", ".join(running_dependencies)))
|
2018-07-20 00:03:37 +02:00
|
|
|
return
|
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
new_vm_name, ok = QtWidgets.QInputDialog.getText(
|
2017-11-06 23:18:18 +01:00
|
|
|
self,
|
2018-01-28 20:26:29 +01:00
|
|
|
self.tr('Rename qube'),
|
2019-09-27 03:29:31 +02:00
|
|
|
self.tr('New name: (WARNING: all other changes will be discarded)'),
|
|
|
|
text=self.vm.name)
|
2017-07-29 12:49:02 +02:00
|
|
|
|
|
|
|
if ok:
|
2018-10-20 18:34:15 +02:00
|
|
|
thread = RenameVMThread(self.vm, new_vm_name, dependencies)
|
|
|
|
self.threads_list.append(thread)
|
2018-10-20 23:01:35 +02:00
|
|
|
thread.finished.connect(self.clear_threads)
|
2017-07-29 12:49:02 +02:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.progress = QtWidgets.QProgressDialog(
|
2019-10-23 18:18:39 +02:00
|
|
|
self.tr("Renaming Qube..."), "", 0, 0)
|
2018-10-20 22:09:39 +02:00
|
|
|
self.progress.setCancelButton(None)
|
|
|
|
self.progress.setModal(True)
|
|
|
|
self.thread_closes = True
|
|
|
|
self.progress.show()
|
2017-07-29 12:49:02 +02:00
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
thread.start()
|
2013-10-29 13:41:46 +01:00
|
|
|
|
2017-11-03 22:20:34 +01:00
|
|
|
def remove_vm(self):
|
|
|
|
|
2018-07-20 00:03:37 +02:00
|
|
|
dependencies = admin_utils.vm_dependencies(self.vm.app, self.vm)
|
|
|
|
|
|
|
|
if dependencies:
|
|
|
|
list_text = utils.format_dependencies_list(dependencies)
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2018-07-20 00:03:37 +02:00
|
|
|
self,
|
|
|
|
self.tr("Qube cannot be removed!"),
|
|
|
|
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 "
|
2018-07-20 17:48:39 +02:00
|
|
|
"or setting that uses it.</small>").format(list_text))
|
2018-07-20 00:03:37 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
answer, ok = QtWidgets.QInputDialog.getText(
|
2017-11-06 19:45:36 +01:00
|
|
|
self,
|
2018-01-28 20:26:29 +01:00
|
|
|
self.tr('Delete qube'),
|
|
|
|
self.tr('Are you absolutely sure you want to delete this qube? '
|
|
|
|
'<br/> All qube settings and data will be irrevocably'
|
2018-01-08 20:56:22 +01:00
|
|
|
' deleted. <br/> If you are sure, please enter this '
|
2018-01-28 20:26:29 +01:00
|
|
|
'qube\'s name below.'))
|
2017-11-03 22:20:34 +01:00
|
|
|
|
|
|
|
if ok and answer == self.vm.name:
|
2018-10-20 18:34:15 +02:00
|
|
|
thread = common_threads.RemoveVMThread(self.vm)
|
|
|
|
thread.start()
|
2017-07-29 12:49:02 +02:00
|
|
|
self.done(0)
|
2012-05-19 09:33:29 +02:00
|
|
|
|
2017-11-06 19:45:36 +01:00
|
|
|
elif ok:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2018-06-12 22:50:03 +02:00
|
|
|
self,
|
2017-11-06 19:45:36 +01:00
|
|
|
self.tr("Removal cancelled"),
|
2018-01-28 20:26:29 +01:00
|
|
|
self.tr("The qube will not be removed."))
|
2017-11-03 22:20:34 +01:00
|
|
|
|
2017-11-03 23:50:04 +01:00
|
|
|
def clone_vm(self):
|
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
cloned_vm_name, ok = QtWidgets.QInputDialog.getText(
|
2017-11-06 19:45:36 +01:00
|
|
|
self,
|
2018-01-28 20:26:29 +01:00
|
|
|
self.tr('Clone qube'),
|
|
|
|
self.tr('Name for the cloned qube:'))
|
2017-11-03 23:50:04 +01:00
|
|
|
|
|
|
|
if ok:
|
2018-10-20 18:34:15 +02:00
|
|
|
thread = common_threads.CloneVMThread(self.vm, cloned_vm_name)
|
2018-10-20 23:01:35 +02:00
|
|
|
thread.finished.connect(self.clear_threads)
|
2018-10-20 18:34:15 +02:00
|
|
|
self.threads_list.append(thread)
|
2018-10-20 22:09:39 +02:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.progress = QtWidgets.QProgressDialog(
|
2019-10-23 18:18:39 +02:00
|
|
|
self.tr("Cloning Qube..."), "", 0, 0)
|
2018-10-20 22:09:39 +02:00
|
|
|
self.progress.setCancelButton(None)
|
|
|
|
self.progress.setModal(True)
|
|
|
|
self.thread_closes = True
|
|
|
|
self.progress.show()
|
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
thread.start()
|
2017-11-03 23:50:04 +01:00
|
|
|
|
2012-03-12 21:08:32 +01:00
|
|
|
######### advanced tab
|
|
|
|
|
|
|
|
def __init_advanced_tab__(self):
|
|
|
|
|
2012-03-14 12:51:11 +01:00
|
|
|
self.init_mem.setValue(int(self.vm.memory))
|
2012-03-13 22:05:50 +01:00
|
|
|
|
2018-12-17 02:26:11 +01:00
|
|
|
if self.vm.maxmem > 0:
|
|
|
|
self.max_mem_size.setValue(int(self.vm.maxmem))
|
|
|
|
else:
|
|
|
|
maxmem = self.vm.property_get_default('maxmem')
|
|
|
|
if maxmem == 0:
|
|
|
|
maxmem = self.vm.memory
|
|
|
|
self.max_mem_size.setValue(int(
|
|
|
|
self.vm.features.get('qubesmanager.maxmem_value', maxmem)))
|
2012-03-13 22:05:50 +01:00
|
|
|
|
2014-02-23 00:44:08 +01:00
|
|
|
self.vcpus.setMinimum(1)
|
2012-03-13 22:05:50 +01:00
|
|
|
self.vcpus.setValue(int(self.vm.vcpus))
|
|
|
|
|
2017-07-14 02:19:24 +02:00
|
|
|
self.include_in_balancing.setEnabled(True)
|
2018-12-17 02:26:11 +01:00
|
|
|
self.include_in_balancing.setChecked(int(self.vm.maxmem) > 0)
|
2013-10-29 13:41:46 +01:00
|
|
|
self.max_mem_size.setEnabled(self.include_in_balancing.isChecked())
|
2012-04-18 19:33:53 +02:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# in case VM is HVM
|
2017-07-12 14:08:34 +02:00
|
|
|
if hasattr(self.vm, "kernel"):
|
2014-02-17 00:40:28 +01:00
|
|
|
self.kernel_groupbox.setVisible(True)
|
2017-07-12 14:08:34 +02:00
|
|
|
self.kernel_list, self.kernel_idx = utils.prepare_kernel_choice(
|
|
|
|
self.kernel, self.vm, 'kernel',
|
2018-02-10 22:54:00 +01:00
|
|
|
None,
|
2017-07-12 14:08:34 +02:00
|
|
|
allow_default=True, allow_none=True)
|
2017-10-12 17:06:17 +02:00
|
|
|
self.kernel.currentIndexChanged.connect(self.kernel_changed)
|
2018-09-27 21:34:56 +02:00
|
|
|
self.kernel_opts.setText(getattr(self.vm, 'kernelopts', '-'))
|
2017-07-12 14:08:34 +02:00
|
|
|
else:
|
|
|
|
self.kernel_groupbox.setVisible(False)
|
2012-03-12 21:08:32 +01:00
|
|
|
|
2017-07-12 14:47:37 +02:00
|
|
|
self.other_groupbox.setVisible(False)
|
|
|
|
|
2017-07-14 02:19:24 +02:00
|
|
|
if not hasattr(self.vm, 'default_dispvm'):
|
|
|
|
self.other_groupbox.setVisible(False)
|
|
|
|
else:
|
|
|
|
self.other_groupbox.setVisible(True)
|
|
|
|
self.default_dispvm_list, self.default_dispvm_idx = \
|
|
|
|
utils.prepare_vm_choice(
|
|
|
|
self.default_dispvm,
|
|
|
|
self.vm, 'default_dispvm',
|
2018-02-10 22:54:00 +01:00
|
|
|
None,
|
|
|
|
(lambda vm: getattr(vm, 'template_for_dispvms', False)),
|
2017-07-14 02:19:24 +02:00
|
|
|
allow_default=True, allow_none=True)
|
2019-02-19 22:15:03 +01:00
|
|
|
self.default_dispvm.currentIndexChanged.connect(
|
|
|
|
self.check_warn_dispvmnetvm)
|
2015-04-06 00:59:15 +02:00
|
|
|
|
2019-02-19 22:15:03 +01:00
|
|
|
self.check_warn_dispvmnetvm()
|
2017-10-12 17:06:17 +02:00
|
|
|
self.update_virt_mode_list()
|
|
|
|
|
2019-02-12 22:23:38 +01:00
|
|
|
windows_running = \
|
|
|
|
self.vm.features.check_with_template('os', None) == 'Windows' \
|
|
|
|
and self.vm.is_running()
|
2018-10-23 22:51:28 +02:00
|
|
|
|
|
|
|
self.seamless_on_button.setEnabled(windows_running)
|
|
|
|
self.seamless_off_button.setEnabled(windows_running)
|
|
|
|
|
|
|
|
self.seamless_on_button.clicked.connect(self.enable_seamless)
|
|
|
|
self.seamless_off_button.clicked.connect(self.disable_seamless)
|
|
|
|
|
2019-02-06 14:35:29 +01:00
|
|
|
if hasattr(self.vm, "template_for_dispvms"):
|
|
|
|
self.dvm_template_checkbox.setChecked(self.vm.template_for_dispvms)
|
|
|
|
else:
|
|
|
|
self.dvm_template_checkbox.setVisible(False)
|
|
|
|
|
2019-06-05 18:22:31 +02:00
|
|
|
self.provides_network_checkbox.setChecked(
|
|
|
|
getattr(self.vm, 'provides_network', False))
|
|
|
|
if self.provides_network_checkbox.isChecked():
|
|
|
|
domains_using = [vm.name for vm in self.vm.connected_vms]
|
|
|
|
if domains_using:
|
|
|
|
self.provides_network_checkbox.setEnabled(False)
|
2019-10-23 18:18:39 +02:00
|
|
|
self.provides_network_checkbox.setToolTip(self.tr(
|
2019-06-05 18:22:31 +02:00
|
|
|
"Cannot change this setting while this qube is used as a "
|
2019-10-23 18:18:39 +02:00
|
|
|
"NetVM by the following qubes:\n") +
|
2019-06-05 18:22:31 +02:00
|
|
|
"\n".join(domains_using))
|
|
|
|
|
2018-10-23 22:51:28 +02:00
|
|
|
def enable_seamless(self):
|
|
|
|
self.vm.run_service_for_stdio("qubes.SetGuiMode", input=b'SEAMLESS')
|
|
|
|
|
|
|
|
def disable_seamless(self):
|
|
|
|
self.vm.run_service_for_stdio("qubes.SetGuiMode", input=b'FULLSCREEN')
|
|
|
|
|
2012-03-12 21:08:32 +01:00
|
|
|
def __apply_advanced_tab__(self):
|
2013-02-23 06:44:06 +01:00
|
|
|
msg = []
|
2012-03-12 21:08:32 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# mem/cpu
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
|
|
|
if self.init_mem.value() != int(self.vm.memory):
|
|
|
|
self.vm.memory = self.init_mem.value()
|
2012-03-14 12:51:11 +01:00
|
|
|
|
2018-12-17 02:26:11 +01:00
|
|
|
curr_maxmem = int(self.vm.maxmem)
|
|
|
|
|
|
|
|
if not self.include_in_balancing.isChecked():
|
|
|
|
maxmem = 0
|
|
|
|
else:
|
|
|
|
maxmem = self.max_mem_size.value()
|
|
|
|
|
|
|
|
if maxmem != curr_maxmem:
|
|
|
|
if curr_maxmem > 0:
|
|
|
|
self.vm.features['qubesmanager.maxmem_value'] = curr_maxmem
|
|
|
|
self.vm.maxmem = maxmem
|
2012-03-13 22:05:50 +01:00
|
|
|
|
2013-02-23 06:44:06 +01:00
|
|
|
if self.vcpus.value() != int(self.vm.vcpus):
|
|
|
|
self.vm.vcpus = self.vcpus.value()
|
2018-12-17 02:26:11 +01:00
|
|
|
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
2012-03-13 22:05:50 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# in case VM is not Linux
|
2014-02-17 00:40:28 +01:00
|
|
|
if hasattr(self.vm, "kernel") and self.kernel_groupbox.isVisible():
|
|
|
|
try:
|
|
|
|
if self.kernel.currentIndex() != self.kernel_idx:
|
2017-11-06 23:18:18 +01:00
|
|
|
self.vm.kernel = self.kernel_list[
|
|
|
|
self.kernel.currentIndex()]
|
2019-02-23 18:19:58 +01:00
|
|
|
self.kernel_idx = self.kernel.currentIndex()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2014-02-17 00:40:28 +01:00
|
|
|
msg.append(str(ex))
|
2013-02-23 06:44:06 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
# vm default_dispvm changed
|
2017-07-14 02:19:24 +02:00
|
|
|
try:
|
|
|
|
if self.default_dispvm.currentIndex() != self.default_dispvm_idx:
|
|
|
|
self.vm.default_dispvm = \
|
|
|
|
self.default_dispvm_list[self.default_dispvm.currentIndex()]
|
2019-02-23 18:19:58 +01:00
|
|
|
self.default_dispvm_idx = self.default_dispvm.currentIndex()
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2017-07-14 02:19:24 +02:00
|
|
|
msg.append(str(ex))
|
|
|
|
|
2017-10-12 17:06:17 +02:00
|
|
|
try:
|
|
|
|
if self.virt_mode.currentIndex() != self.virt_mode_idx:
|
2018-02-06 15:31:17 +01:00
|
|
|
self.vm.virt_mode = self.selected_virt_mode()
|
2019-02-23 18:19:58 +01:00
|
|
|
self.virt_mode_idx = self.virt_mode.currentIndex()
|
2018-01-17 12:01:26 +01:00
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
2017-10-12 17:06:17 +02:00
|
|
|
msg.append(str(ex))
|
|
|
|
|
2019-02-06 14:35:29 +01:00
|
|
|
if getattr(self.vm, "template_for_dispvms", False) != \
|
|
|
|
self.dvm_template_checkbox.isChecked():
|
|
|
|
try:
|
|
|
|
self.vm.template_for_dispvms = \
|
|
|
|
self.dvm_template_checkbox.isChecked()
|
|
|
|
if self.dvm_template_checkbox.isChecked():
|
|
|
|
self.vm.features["appmenus-dispvm"] = True
|
|
|
|
else:
|
|
|
|
del self.vm.features["appmenus-dispvm"]
|
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
|
|
|
msg.append(str(ex))
|
|
|
|
|
2019-06-05 18:22:31 +02:00
|
|
|
if getattr(self.vm, 'provides_network', False) != \
|
|
|
|
self.provides_network_checkbox.isChecked():
|
|
|
|
try:
|
|
|
|
self.vm.provides_network = \
|
|
|
|
self.provides_network_checkbox.isChecked()
|
|
|
|
except Exception as ex: # pylint: disable=broad-except
|
|
|
|
msg.append(str(ex))
|
|
|
|
|
2013-02-23 06:44:06 +01:00
|
|
|
return msg
|
2012-03-12 21:08:32 +01:00
|
|
|
|
2018-12-17 02:26:11 +01:00
|
|
|
def include_in_balancing_changed(self, state):
|
|
|
|
if self.dev_list.selected_list.count() > 0:
|
|
|
|
if state == ui_settingsdlg.QtCore.Qt.Checked:
|
|
|
|
self.dmm_warning_adv.show()
|
|
|
|
self.dmm_warning_dev.show()
|
|
|
|
else:
|
|
|
|
self.dmm_warning_adv.hide()
|
|
|
|
self.dmm_warning_dev.hide()
|
|
|
|
self.max_mem_size.setEnabled(self.include_in_balancing.isChecked())
|
|
|
|
|
2017-09-08 22:43:43 +02:00
|
|
|
def boot_from_cdrom_button_pressed(self):
|
|
|
|
self.save_and_apply()
|
|
|
|
subprocess.check_call(['qubes-vm-boot-from-device', self.vm.name])
|
|
|
|
|
2017-10-12 17:06:17 +02:00
|
|
|
def selected_virt_mode(self):
|
|
|
|
return self.virt_mode_list[self.virt_mode.currentIndex()]
|
|
|
|
|
2018-01-17 12:01:26 +01:00
|
|
|
def virt_mode_changed(self, new_idx): # pylint: disable=unused-argument
|
2017-10-12 17:06:17 +02:00
|
|
|
self.update_pv_warning()
|
|
|
|
self.update_pvh_dont_support_devs()
|
2018-01-17 12:01:26 +01:00
|
|
|
self.update_pvh_kernel_ver_warning()
|
2017-10-12 17:06:17 +02:00
|
|
|
|
|
|
|
def update_pv_warning(self):
|
2018-01-16 19:56:45 +01:00
|
|
|
if self.selected_virt_mode() == 'PV':
|
2017-10-12 17:06:17 +02:00
|
|
|
self.pv_warning.show()
|
|
|
|
else:
|
|
|
|
self.pv_warning.hide()
|
|
|
|
|
|
|
|
def update_virt_mode_list(self):
|
2018-01-16 19:56:45 +01:00
|
|
|
choices = ['HVM', 'PV']
|
2017-10-12 17:06:17 +02:00
|
|
|
|
2019-03-11 22:02:32 +01:00
|
|
|
if hasattr(self, "dev_list"):
|
2017-10-12 17:06:17 +02:00
|
|
|
devs_attached = self.dev_list.selected_list.count() != 0
|
|
|
|
else:
|
2018-01-17 12:01:26 +01:00
|
|
|
devs_attached = bool(list(self.vm.devices['pci'].persistent()))
|
2017-10-12 17:06:17 +02:00
|
|
|
|
|
|
|
if devs_attached:
|
|
|
|
self.pvh_mode_hidden.show()
|
|
|
|
else:
|
2018-01-16 19:56:45 +01:00
|
|
|
choices.insert(0, 'PVH')
|
2017-10-12 17:06:17 +02:00
|
|
|
self.pvh_mode_hidden.hide()
|
|
|
|
|
2019-03-09 16:45:22 +01:00
|
|
|
if self.virt_mode_list:
|
2017-10-12 17:06:17 +02:00
|
|
|
old_mode = self.selected_virt_mode()
|
|
|
|
self.virt_mode.currentIndexChanged.disconnect()
|
|
|
|
else:
|
|
|
|
old_mode = None
|
|
|
|
|
|
|
|
self.virt_mode.clear()
|
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.virt_mode_list, self.virt_mode_idx = utils.prepare_choice(
|
|
|
|
self.virt_mode, self.vm, 'virt_mode', choices, None,
|
|
|
|
allow_default=True, transform=(lambda x: str(x).upper()))
|
2017-10-12 17:06:17 +02:00
|
|
|
|
|
|
|
if old_mode is not None:
|
|
|
|
self.virt_mode.setCurrentIndex(self.virt_mode_list.index(old_mode))
|
|
|
|
|
|
|
|
self.virt_mode.currentIndexChanged.connect(self.virt_mode_changed)
|
|
|
|
|
|
|
|
self.update_pv_warning()
|
2018-01-17 12:01:26 +01:00
|
|
|
self.update_pvh_kernel_ver_warning()
|
2017-10-12 17:06:17 +02:00
|
|
|
|
2018-01-17 12:01:26 +01:00
|
|
|
def update_pvh_kernel_ver_warning(self):
|
2018-01-16 19:56:45 +01:00
|
|
|
if self.selected_virt_mode() != 'PVH':
|
2017-10-12 17:06:17 +02:00
|
|
|
self.pvh_kernel_version_warning.hide()
|
|
|
|
return
|
|
|
|
|
|
|
|
kernel = self.kernel_list[self.kernel.currentIndex()]
|
|
|
|
|
|
|
|
if self.pvh_kernel_version_ok(kernel):
|
|
|
|
self.pvh_kernel_version_warning.hide()
|
|
|
|
else:
|
|
|
|
self.pvh_kernel_version_warning.show()
|
|
|
|
|
|
|
|
def kernel_changed(self):
|
2018-01-17 12:01:26 +01:00
|
|
|
self.update_pvh_kernel_ver_warning()
|
2017-10-12 17:06:17 +02:00
|
|
|
|
|
|
|
def pvh_kernel_version_ok(self, name):
|
|
|
|
# There are nearly no limitaions on kernel names (only file system and
|
|
|
|
# general qvm-prefs rules). So we just look if we see something which
|
|
|
|
# looks like a version number. It's just a warning to help the user
|
|
|
|
# anyways.
|
|
|
|
|
|
|
|
if name is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if name is qubesadmin.DEFAULT:
|
|
|
|
name = self.vm.app.default_kernel
|
|
|
|
|
2018-01-17 12:01:26 +01:00
|
|
|
m = re.search(r'(\d+)\.(\d+)', name)
|
2017-10-12 17:06:17 +02:00
|
|
|
|
|
|
|
if m is None:
|
|
|
|
return False
|
|
|
|
|
2018-01-17 12:01:26 +01:00
|
|
|
return (int(m.group(1)), int(m.group(2))) >= (4, 11)
|
2017-10-12 17:06:17 +02:00
|
|
|
|
2012-03-13 20:06:41 +01:00
|
|
|
######## devices tab
|
|
|
|
def __init_devices_tab__(self):
|
2017-07-12 14:52:56 +02:00
|
|
|
self.dev_list = multiselectwidget.MultiSelectWidget(self)
|
2014-11-01 19:57:17 +01:00
|
|
|
self.dev_list.add_all_button.setVisible(False)
|
2012-03-13 20:06:41 +01:00
|
|
|
self.devices_layout.addWidget(self.dev_list)
|
2014-02-17 00:35:45 +01:00
|
|
|
|
2019-04-02 22:05:51 +02:00
|
|
|
dom0_devs = list(self.vm.app.domains['dom0'].devices['pci'].available())
|
|
|
|
|
|
|
|
attached_devs = list(self.vm.devices['pci'].persistent())
|
2012-03-13 20:06:41 +01:00
|
|
|
|
2017-11-09 17:23:23 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2019-05-22 23:10:09 +02:00
|
|
|
class DevListWidgetItem(QtWidgets.QListWidgetItem):
|
2019-04-02 22:05:51 +02:00
|
|
|
def __init__(self, dev, unknown=False, parent=None):
|
|
|
|
super(DevListWidgetItem, self).__init__(parent)
|
|
|
|
name = dev.ident.replace('_', ":") + ' ' + dev.description
|
|
|
|
if unknown:
|
|
|
|
name += ' (unknown)'
|
|
|
|
self.setText(name)
|
|
|
|
self.dev = dev
|
|
|
|
|
|
|
|
for dev in dom0_devs:
|
|
|
|
if dev in attached_devs:
|
|
|
|
self.dev_list.selected_list.addItem(DevListWidgetItem(dev))
|
2012-03-13 20:06:41 +01:00
|
|
|
else:
|
2019-04-02 22:05:51 +02:00
|
|
|
self.dev_list.available_list.addItem(DevListWidgetItem(dev))
|
|
|
|
for dev in attached_devs:
|
|
|
|
if dev not in dom0_devs:
|
|
|
|
self.dev_list.selected_list.addItem(
|
|
|
|
DevListWidgetItem(dev, unknown=True))
|
2012-03-13 20:06:41 +01:00
|
|
|
|
2017-11-06 23:18:18 +01:00
|
|
|
if self.dev_list.selected_list.count() > 0\
|
|
|
|
and self.include_in_balancing.isChecked():
|
2012-03-19 21:07:27 +01:00
|
|
|
self.dmm_warning_adv.show()
|
|
|
|
self.dmm_warning_dev.show()
|
|
|
|
else:
|
|
|
|
self.dmm_warning_adv.hide()
|
|
|
|
self.dmm_warning_dev.hide()
|
|
|
|
|
2012-04-17 13:15:18 +02:00
|
|
|
if self.vm.is_running():
|
|
|
|
self.dev_list.setEnabled(False)
|
|
|
|
self.turn_off_vm_to_modify_devs.setVisible(True)
|
2018-01-12 23:56:48 +01:00
|
|
|
self.no_strict_reset_button.setEnabled(False)
|
2012-04-17 13:15:18 +02:00
|
|
|
else:
|
|
|
|
self.dev_list.setEnabled(True)
|
|
|
|
self.turn_off_vm_to_modify_devs.setVisible(False)
|
|
|
|
|
2017-10-12 17:06:17 +02:00
|
|
|
self.update_pvh_dont_support_devs()
|
|
|
|
|
2019-04-02 22:16:55 +02:00
|
|
|
self.dev_list.setEnabled(not self.vm.is_running())
|
|
|
|
|
2012-03-13 20:06:41 +01:00
|
|
|
def __apply_devices_tab__(self):
|
2013-02-23 06:44:06 +01:00
|
|
|
msg = []
|
2012-03-13 20:06:41 +01:00
|
|
|
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
2019-04-02 22:05:51 +02:00
|
|
|
old_devs = list(self.vm.devices['pci'].persistent())
|
|
|
|
|
2019-04-05 21:35:46 +02:00
|
|
|
new_devs = [self.dev_list.selected_list.item(i).dev
|
|
|
|
for i in range(self.dev_list.selected_list.count())]
|
2017-07-12 14:52:56 +02:00
|
|
|
|
2019-04-02 22:05:51 +02:00
|
|
|
for dev in new_devs:
|
|
|
|
if dev not in old_devs:
|
2018-01-10 00:51:05 +01:00
|
|
|
options = {}
|
2019-04-02 22:05:51 +02:00
|
|
|
if dev.ident in self.new_strict_reset_list:
|
2018-01-10 00:51:05 +01:00
|
|
|
options['no-strict-reset'] = True
|
2017-11-17 17:34:38 +01:00
|
|
|
ass = devices.DeviceAssignment(
|
2017-07-12 14:52:56 +02:00
|
|
|
self.vm.app.domains['dom0'],
|
2019-04-02 22:05:51 +02:00
|
|
|
dev.ident, persistent=True, options=options)
|
2017-07-12 14:52:56 +02:00
|
|
|
self.vm.devices['pci'].attach(ass)
|
2019-04-02 22:05:51 +02:00
|
|
|
elif (dev.ident in self.current_strict_reset_list) != \
|
|
|
|
(dev.ident in self.new_strict_reset_list):
|
2018-01-12 23:56:48 +01:00
|
|
|
current_assignment = None
|
|
|
|
for assignment in self.vm.devices['pci'].assignments(
|
|
|
|
persistent=True):
|
2019-04-02 22:05:51 +02:00
|
|
|
if assignment.ident == dev.ident:
|
2018-01-12 23:56:48 +01:00
|
|
|
current_assignment = assignment
|
|
|
|
break
|
|
|
|
if current_assignment is None:
|
|
|
|
# it would be very weird if this happened
|
2018-01-19 01:24:11 +01:00
|
|
|
msg.append(self.tr("Error re-assigning device ") +
|
2019-04-02 22:05:51 +02:00
|
|
|
dev.ident)
|
2018-01-19 02:50:04 +01:00
|
|
|
continue
|
2018-01-19 01:24:11 +01:00
|
|
|
|
2018-01-12 23:56:48 +01:00
|
|
|
self.vm.devices['pci'].detach(current_assignment)
|
|
|
|
|
2018-01-19 01:24:11 +01:00
|
|
|
current_assignment.options['no-strict-reset'] = \
|
2019-04-02 22:05:51 +02:00
|
|
|
(dev.ident in self.new_strict_reset_list)
|
2018-01-19 01:24:11 +01:00
|
|
|
|
|
|
|
self.vm.devices['pci'].attach(current_assignment)
|
2018-01-12 23:56:48 +01:00
|
|
|
|
2017-07-12 14:52:56 +02:00
|
|
|
for ass in self.vm.devices['pci'].assignments(persistent=True):
|
2019-04-02 22:05:51 +02:00
|
|
|
if ass.device not in new_devs:
|
2017-07-12 14:52:56 +02:00
|
|
|
self.vm.devices['pci'].detach(ass)
|
|
|
|
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2017-07-12 14:08:34 +02:00
|
|
|
if utils.is_debug():
|
|
|
|
traceback.print_exc()
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
|
|
|
|
|
|
|
return msg
|
2012-03-13 20:06:41 +01:00
|
|
|
|
2012-03-19 16:02:05 +01:00
|
|
|
def devices_selection_changed(self):
|
2012-03-19 21:07:27 +01:00
|
|
|
if self.include_in_balancing.isChecked():
|
2017-11-06 23:54:33 +01:00
|
|
|
if self.dev_list.selected_list.count() > 0:
|
2012-03-19 21:07:27 +01:00
|
|
|
self.dmm_warning_adv.show()
|
|
|
|
self.dmm_warning_dev.show()
|
|
|
|
else:
|
|
|
|
self.dmm_warning_adv.hide()
|
|
|
|
self.dmm_warning_dev.hide()
|
2012-03-14 11:54:50 +01:00
|
|
|
|
2017-10-12 17:06:17 +02:00
|
|
|
self.update_virt_mode_list()
|
|
|
|
|
|
|
|
def update_pvh_dont_support_devs(self):
|
2018-01-16 19:56:45 +01:00
|
|
|
if self.selected_virt_mode() == 'PVH':
|
2017-10-12 17:06:17 +02:00
|
|
|
self.dev_list.setEnabled(False)
|
|
|
|
self.pvh_dont_support_devs.setVisible(True)
|
|
|
|
else:
|
|
|
|
self.dev_list.setEnabled(True)
|
|
|
|
self.pvh_dont_support_devs.setVisible(False)
|
|
|
|
|
2018-01-12 23:56:48 +01:00
|
|
|
def define_strict_reset_devices(self):
|
|
|
|
for assignment in self.vm.devices['pci'].assignments():
|
2018-01-19 01:24:11 +01:00
|
|
|
if assignment.options.get('no-strict-reset', False):
|
2018-01-12 23:56:48 +01:00
|
|
|
self.current_strict_reset_list.append(
|
|
|
|
assignment.ident.replace('_', ':'))
|
|
|
|
self.new_strict_reset_list = self.current_strict_reset_list.copy()
|
|
|
|
|
2018-01-10 00:51:05 +01:00
|
|
|
def strict_reset_button_pressed(self):
|
|
|
|
device_list_window = device_list.PCIDeviceListWindow(
|
2018-01-12 23:56:48 +01:00
|
|
|
self.vm, self.qapp, self.dev_list, self.new_strict_reset_list, self)
|
|
|
|
device_list_window.exec()
|
2018-01-10 00:51:05 +01:00
|
|
|
|
2017-07-28 16:47:11 +02:00
|
|
|
######## applications tab
|
|
|
|
|
|
|
|
def refresh_apps_button_pressed(self):
|
|
|
|
|
|
|
|
self.refresh_apps_button.setEnabled(False)
|
|
|
|
self.refresh_apps_button.setText(self.tr('Refresh in progress...'))
|
|
|
|
|
2018-11-30 21:47:15 +01:00
|
|
|
thread = RefreshAppsVMThread(self.vm, self.refresh_apps_button)
|
2018-10-20 23:01:35 +02:00
|
|
|
thread.finished.connect(self.clear_threads)
|
|
|
|
thread.finished.connect(self.refresh_finished)
|
2018-10-20 18:34:15 +02:00
|
|
|
self.threads_list.append(thread)
|
2017-07-28 16:47:11 +02:00
|
|
|
thread.start()
|
|
|
|
|
2018-10-20 18:34:15 +02:00
|
|
|
def refresh_finished(self):
|
2017-11-08 16:53:49 +01:00
|
|
|
self.app_list_manager = AppmenuSelectManager(self.vm, self.app_list)
|
2017-07-28 16:47:11 +02:00
|
|
|
self.refresh_apps_button.setEnabled(True)
|
|
|
|
self.refresh_apps_button.setText(self.tr('Refresh Applications'))
|
|
|
|
|
2012-03-14 11:54:50 +01:00
|
|
|
######## services tab
|
|
|
|
|
|
|
|
def __init_services_tab__(self):
|
2017-07-12 14:52:05 +02:00
|
|
|
self.new_srv_dict = {}
|
|
|
|
for feature in self.vm.features:
|
|
|
|
if not feature.startswith('service.'):
|
|
|
|
continue
|
|
|
|
service = feature[len('service.'):]
|
2019-05-22 23:10:09 +02:00
|
|
|
item = QtWidgets.QListWidgetItem(service)
|
2017-11-06 20:36:09 +01:00
|
|
|
item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked
|
2018-01-08 20:56:22 +01:00
|
|
|
if self.vm.features[feature]
|
2017-11-06 23:18:18 +01:00
|
|
|
else ui_settingsdlg.QtCore.Qt.Unchecked)
|
2012-03-14 11:54:50 +01:00
|
|
|
self.services_list.addItem(item)
|
2017-07-12 14:52:05 +02:00
|
|
|
self.new_srv_dict[service] = self.vm.features[feature]
|
2013-02-23 06:44:06 +01:00
|
|
|
|
2018-07-16 01:14:33 +02:00
|
|
|
# add suggested services
|
|
|
|
self.service_line_edit.addItem('clocksync')
|
|
|
|
self.service_line_edit.addItem('crond')
|
|
|
|
self.service_line_edit.addItem('cups')
|
|
|
|
self.service_line_edit.addItem('disable-default-route')
|
|
|
|
self.service_line_edit.addItem('disable-dns-server')
|
|
|
|
self.service_line_edit.addItem('network-manager')
|
|
|
|
self.service_line_edit.addItem('qubes-firewall')
|
|
|
|
self.service_line_edit.addItem('qubes-network')
|
|
|
|
self.service_line_edit.addItem('qubes-update-check')
|
|
|
|
self.service_line_edit.addItem('qubes-updates-proxy')
|
|
|
|
self.service_line_edit.addItem('qubes-yum-proxy')
|
|
|
|
self.service_line_edit.addItem('updates-proxy-setup')
|
|
|
|
self.service_line_edit.addItem('yum-proxy-setup')
|
|
|
|
self.service_line_edit.setEditText("")
|
|
|
|
|
2012-03-14 11:54:50 +01:00
|
|
|
def __add_service__(self):
|
2018-07-16 01:14:33 +02:00
|
|
|
srv = str(self.service_line_edit.currentText()).strip()
|
2012-03-30 21:46:23 +02:00
|
|
|
if srv != "":
|
|
|
|
if srv in self.new_srv_dict:
|
2019-05-22 23:10:09 +02:00
|
|
|
QtWidgets.QMessageBox.information(
|
2018-06-12 22:50:03 +02:00
|
|
|
self,
|
2017-11-06 23:18:18 +01:00
|
|
|
'',
|
2017-07-12 14:52:05 +02:00
|
|
|
self.tr('Service already on the list!'))
|
2012-03-30 21:46:23 +02:00
|
|
|
else:
|
2019-05-22 23:10:09 +02:00
|
|
|
item = QtWidgets.QListWidgetItem(srv)
|
2017-11-06 20:36:09 +01:00
|
|
|
item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked)
|
2012-03-30 21:46:23 +02:00
|
|
|
self.services_list.addItem(item)
|
|
|
|
self.new_srv_dict[srv] = True
|
2012-03-14 11:54:50 +01:00
|
|
|
|
|
|
|
def __remove_service__(self):
|
2012-03-30 21:46:23 +02:00
|
|
|
item = self.services_list.currentItem()
|
2014-09-04 21:59:05 +02:00
|
|
|
|
|
|
|
if not item:
|
|
|
|
return
|
|
|
|
|
|
|
|
row = self.services_list.currentRow()
|
|
|
|
item = self.services_list.takeItem(row)
|
|
|
|
del self.new_srv_dict[str(item.text())]
|
2012-03-14 11:54:50 +01:00
|
|
|
|
|
|
|
def __apply_services_tab__(self):
|
2013-02-23 06:44:06 +01:00
|
|
|
msg = []
|
2012-03-30 21:46:23 +02:00
|
|
|
|
2013-02-23 06:44:06 +01:00
|
|
|
try:
|
2017-11-08 16:53:49 +01:00
|
|
|
for i in range(self.services_list.count()):
|
|
|
|
item = self.services_list.item(i)
|
2017-11-06 23:18:18 +01:00
|
|
|
self.new_srv_dict[str(item.text())] = \
|
|
|
|
(item.checkState() == ui_settingsdlg.QtCore.Qt.Checked)
|
2012-03-30 21:46:23 +02:00
|
|
|
|
2017-07-12 14:52:05 +02:00
|
|
|
for service, v in self.new_srv_dict.items():
|
|
|
|
feature = 'service.' + service
|
|
|
|
if v != self.vm.features.get(feature, object()):
|
|
|
|
self.vm.features[feature] = v
|
|
|
|
|
|
|
|
for feature in self.vm.features:
|
|
|
|
if not feature.startswith('service.'):
|
|
|
|
continue
|
|
|
|
service = feature[len('service.'):]
|
|
|
|
if service not in self.new_srv_dict:
|
|
|
|
del self.vm.features[feature]
|
2017-11-08 15:40:35 +01:00
|
|
|
except qubesadmin.exc.QubesException as ex:
|
2013-02-23 06:44:06 +01:00
|
|
|
msg.append(str(ex))
|
|
|
|
|
|
|
|
return msg
|
2012-03-14 11:54:50 +01:00
|
|
|
|
2012-02-10 00:30:45 +01:00
|
|
|
######### firewall tab related
|
|
|
|
def set_fw_model(self, model):
|
|
|
|
self.fw_model = model
|
|
|
|
self.rulesTreeView.setModel(model)
|
2019-05-22 23:10:09 +02:00
|
|
|
self.rulesTreeView.header().setSectionResizeMode(
|
|
|
|
QtWidgets.QHeaderView.ResizeToContents)
|
|
|
|
self.rulesTreeView.header().setSectionResizeMode(
|
|
|
|
0, QtWidgets.QHeaderView.Stretch)
|
2012-02-10 00:30:45 +01:00
|
|
|
self.set_allow(model.allow)
|
2017-11-08 16:53:49 +01:00
|
|
|
if model.temp_full_access_expire_time:
|
|
|
|
self.temp_full_access.setChecked(True)
|
|
|
|
self.temp_full_access_time.setValue(
|
|
|
|
(model.temp_full_access_expire_time -
|
2017-11-06 20:36:09 +01:00
|
|
|
int(firewall.datetime.datetime.now().strftime("%s"))) / 60)
|
2012-02-10 00:30:45 +01:00
|
|
|
|
2017-10-13 18:04:49 +02:00
|
|
|
def disable_all_fw_conf(self):
|
2017-11-08 16:53:49 +01:00
|
|
|
self.firewall_modified_outside_label.setVisible(True)
|
|
|
|
self.policy_allow_radio_button.setEnabled(False)
|
|
|
|
self.policy_deny_radio_button.setEnabled(False)
|
2017-10-13 18:04:49 +02:00
|
|
|
self.rulesTreeView.setEnabled(False)
|
2017-11-08 16:53:49 +01:00
|
|
|
self.new_rule_button.setEnabled(False)
|
|
|
|
self.edit_rule_button.setEnabled(False)
|
|
|
|
self.delete_rule_button.setEnabled(False)
|
|
|
|
self.firewal_rules_label.setEnabled(False)
|
2017-10-13 18:04:49 +02:00
|
|
|
self.tempFullAccessWidget.setEnabled(False)
|
2012-02-10 00:30:45 +01:00
|
|
|
|
|
|
|
def set_allow(self, allow):
|
2017-11-08 16:53:49 +01:00
|
|
|
self.policy_allow_radio_button.setChecked(allow)
|
|
|
|
self.policy_deny_radio_button.setChecked(not allow)
|
2017-11-09 16:08:16 +01:00
|
|
|
self.policy_changed()
|
2014-03-28 05:19:07 +01:00
|
|
|
|
2017-11-08 16:53:49 +01:00
|
|
|
def policy_changed(self):
|
|
|
|
self.rulesTreeView.setEnabled(
|
|
|
|
self.policy_deny_radio_button.isChecked())
|
|
|
|
self.new_rule_button.setEnabled(
|
|
|
|
self.policy_deny_radio_button.isChecked())
|
|
|
|
self.edit_rule_button.setEnabled(
|
|
|
|
self.policy_deny_radio_button.isChecked())
|
|
|
|
self.delete_rule_button.setEnabled(
|
|
|
|
self.policy_deny_radio_button.isChecked())
|
|
|
|
self.firewal_rules_label.setEnabled(
|
|
|
|
self.policy_deny_radio_button.isChecked())
|
2017-10-13 18:04:49 +02:00
|
|
|
self.tempFullAccessWidget.setEnabled(
|
2017-11-08 16:53:49 +01:00
|
|
|
self.policy_deny_radio_button.isChecked())
|
2014-02-17 00:35:45 +01:00
|
|
|
|
2012-02-10 00:30:45 +01:00
|
|
|
def new_rule_button_pressed(self):
|
2017-11-06 20:36:09 +01:00
|
|
|
dialog = firewall.NewFwRuleDlg()
|
2017-10-13 18:04:49 +02:00
|
|
|
self.fw_model.run_rule_dialog(dialog)
|
2012-02-10 00:30:45 +01:00
|
|
|
|
|
|
|
def edit_rule_button_pressed(self):
|
2017-10-13 18:04:49 +02:00
|
|
|
|
2012-02-10 00:30:45 +01:00
|
|
|
selected = self.rulesTreeView.selectedIndexes()
|
2012-03-04 17:36:25 +01:00
|
|
|
|
2017-11-14 15:29:57 +01:00
|
|
|
if selected:
|
2017-11-06 20:36:09 +01:00
|
|
|
dialog = firewall.NewFwRuleDlg()
|
2017-11-08 16:53:49 +01:00
|
|
|
dialog.set_ok_state(True)
|
2012-02-10 00:30:45 +01:00
|
|
|
row = self.rulesTreeView.selectedIndexes().pop().row()
|
2017-10-13 18:04:49 +02:00
|
|
|
self.fw_model.populate_edit_dialog(dialog, row)
|
|
|
|
self.fw_model.run_rule_dialog(dialog, row)
|
2012-02-10 00:30:45 +01:00
|
|
|
|
|
|
|
def delete_rule_button_pressed(self):
|
2018-07-16 02:00:28 +02:00
|
|
|
for i in {index.row() for index
|
|
|
|
in self.rulesTreeView.selectedIndexes()}:
|
2017-11-08 16:53:49 +01:00
|
|
|
self.fw_model.remove_child(i)
|
2012-02-10 00:30:45 +01:00
|
|
|
|
2012-02-09 19:47:21 +01:00
|
|
|
|
2017-11-06 22:46:35 +01:00
|
|
|
parser = QubesArgumentParser(vmname_nargs=1)
|
2017-06-28 13:41:10 +02:00
|
|
|
|
2017-06-26 17:54:35 +02:00
|
|
|
parser.add_argument('--tab', metavar='TAB',
|
2018-01-08 20:56:22 +01:00
|
|
|
action='store',
|
|
|
|
choices=VMSettingsWindow.tabs_indices.keys())
|
2017-06-28 13:41:10 +02:00
|
|
|
|
|
|
|
parser.set_defaults(
|
|
|
|
tab='basic',
|
|
|
|
)
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2018-01-08 20:56:22 +01:00
|
|
|
|
2017-06-26 17:54:35 +02:00
|
|
|
def main(args=None):
|
|
|
|
args = parser.parse_args(args)
|
|
|
|
vm = args.domains.pop()
|
2012-01-31 11:17:09 +01:00
|
|
|
|
2019-11-08 23:35:26 +01:00
|
|
|
utils.run_synchronous(functools.partial(VMSettingsWindow, vm, args.tab))
|
2012-01-31 11:17:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
2012-05-19 09:33:29 +02:00
|
|
|
|
|
|
|
# vim:sw=4:et:
|