settings.py 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
  6. # Copyright (C) 2012 Marek Marczykowski-Górecki
  7. # <marmarek@invisiblethingslab.com>
  8. # Copyright (C) 2017 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Lesser General Public License along
  21. # with this program; if not, see <http://www.gnu.org/licenses/>.
  22. #
  23. #
  24. import collections
  25. import functools
  26. import re
  27. import subprocess
  28. import traceback
  29. from qubesadmin.tools import QubesArgumentParser
  30. from qubesadmin import devices
  31. from qubesadmin import utils as admin_utils
  32. import qubesadmin.exc
  33. from . import utils
  34. from . import multiselectwidget
  35. from . import common_threads
  36. from . import device_list
  37. from .appmenu_select import AppmenuSelectManager
  38. from . import firewall
  39. from PyQt5 import QtCore, QtWidgets, QtGui # pylint: disable=import-error
  40. from . import ui_settingsdlg # pylint: disable=no-name-in-module
  41. # pylint: disable=too-few-public-methods
  42. class RenameVMThread(common_threads.QubesThread):
  43. def __init__(self, vm, new_vm_name, dependencies):
  44. super(RenameVMThread, self).__init__(vm)
  45. self.new_vm_name = new_vm_name
  46. self.dependencies = dependencies
  47. def run(self):
  48. try:
  49. new_vm = self.vm.app.clone_vm(self.vm, self.new_vm_name)
  50. failed_props = []
  51. for (holder, prop) in self.dependencies:
  52. try:
  53. if holder is None:
  54. setattr(self.vm.app, prop, new_vm)
  55. else:
  56. setattr(holder, prop, new_vm)
  57. except qubesadmin.exc.QubesException:
  58. failed_props += [(holder, prop)]
  59. if not failed_props:
  60. del self.vm.app.domains[self.vm.name]
  61. else:
  62. list_text = utils.format_dependencies_list(failed_props)
  63. self.msg = (self.tr("Warning: rename partially unsuccessful!"),
  64. self.tr("Some properties could not be changed to "
  65. "the new name. The system has now both {} "
  66. "and {} qubes. To resolve this, please "
  67. "check and change the following properties "
  68. "and remove the qube {} manually.<br>"
  69. ).format(self.vm.name, self.vm.name,
  70. self.vm.name) + list_text)
  71. except qubesadmin.exc.QubesException as ex:
  72. self.msg = (self.tr("Rename error!"), str(ex))
  73. except Exception as ex: # pylint: disable=broad-except
  74. self.msg = (self.tr("Rename error!"), repr(ex))
  75. # pylint: disable=too-few-public-methods
  76. class RefreshAppsVMThread(common_threads.QubesThread):
  77. def __init__(self, vm, button):
  78. super(RefreshAppsVMThread, self).__init__(vm)
  79. self.button = button
  80. def run(self):
  81. vms_to_refresh = [self.vm]
  82. template = getattr(self.vm, 'template', None)
  83. if template:
  84. vms_to_refresh.append(template)
  85. for vm in vms_to_refresh:
  86. self.button.setText(
  87. self.tr('Refresh in progress (refreshing applications '
  88. 'from {})').format(vm.name))
  89. try:
  90. if not vm.is_running():
  91. not_running = True
  92. vm.start()
  93. else:
  94. not_running = False
  95. subprocess.check_call(['qvm-sync-appmenus', vm.name])
  96. if not_running:
  97. vm.shutdown()
  98. except Exception as ex: # pylint: disable=broad-except
  99. self.msg = (self.tr("Refresh failed!"), str(ex))
  100. # pylint: disable=too-many-instance-attributes
  101. class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
  102. tabs_indices = collections.OrderedDict((
  103. ('basic', 0),
  104. ('advanced', 1),
  105. ('firewall', 2),
  106. ('devices', 3),
  107. ('applications', 4),
  108. ('services', 5),
  109. ))
  110. def __init__(self, vm, init_page="basic", qapp=None, qubesapp=None,
  111. parent=None):
  112. super(VMSettingsWindow, self).__init__(parent)
  113. self.vm = vm
  114. self.qapp = qapp
  115. self.qubesapp = qubesapp
  116. self.threads_list = []
  117. self.progress = None
  118. self.thread_closes = False
  119. try:
  120. self.source_vm = self.vm.template
  121. except AttributeError:
  122. self.source_vm = self.vm
  123. self.setupUi(self)
  124. self.setWindowTitle(self.tr("Settings: {vm}").format(vm=self.vm.name))
  125. if init_page in self.tabs_indices:
  126. idx = self.tabs_indices[init_page]
  127. assert idx in range(self.tabWidget.count())
  128. self.tabWidget.setCurrentIndex(idx)
  129. self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply).clicked.connect(
  130. self.apply)
  131. self.tabWidget.currentChanged.connect(self.current_tab_changed)
  132. # Initialize several auxillary variables for pylint's sake
  133. self.netvm_idx = None
  134. self.kernel_idx = None
  135. self.label_idx = None
  136. self.template_idx = None
  137. self.root_img_size = None
  138. self.priv_img_size = None
  139. self.default_dispvm_idx = None
  140. self.virt_mode_idx = None
  141. self.virt_mode_list = None
  142. ###### basic tab
  143. self.__init_basic_tab__()
  144. self.rename_vm_button.clicked.connect(self.rename_vm)
  145. self.delete_vm_button.clicked.connect(self.remove_vm)
  146. self.clone_vm_button.clicked.connect(self.clone_vm)
  147. ###### advanced tab
  148. self.__init_advanced_tab__()
  149. self.include_in_balancing.stateChanged.connect(
  150. self.include_in_balancing_changed)
  151. self.init_mem.editingFinished.connect(self.check_mem_changes)
  152. self.max_mem_size.editingFinished.connect(self.check_mem_changes)
  153. self.boot_from_device_button.clicked.connect(
  154. self.boot_from_cdrom_button_pressed)
  155. ###### firewall tab
  156. if self.tabWidget.isTabEnabled(self.tabs_indices['firewall']):
  157. model = firewall.QubesFirewallRulesModel()
  158. try:
  159. model.set_vm(vm)
  160. self.set_fw_model(model)
  161. self.firewall_modified_outside_label.setVisible(False)
  162. except firewall.FirewallModifiedOutsideError:
  163. self.disable_all_fw_conf()
  164. self.new_rule_button.clicked.connect(self.new_rule_button_pressed)
  165. self.edit_rule_button.clicked.connect(self.edit_rule_button_pressed)
  166. self.delete_rule_button.clicked.connect(
  167. self.delete_rule_button_pressed)
  168. self.policy_deny_radio_button.clicked.connect(self.policy_changed)
  169. self.policy_allow_radio_button.clicked.connect(self.policy_changed)
  170. if init_page == 'firewall':
  171. self.check_network_availability()
  172. ####### devices tab
  173. self.__init_devices_tab__()
  174. self.dev_list.selectedChanged.connect(self.devices_selection_changed)
  175. self.no_strict_reset_button.clicked.connect(
  176. self.strict_reset_button_pressed)
  177. self.current_strict_reset_list = []
  178. self.new_strict_reset_list = []
  179. self.define_strict_reset_devices()
  180. ####### services tab
  181. self.__init_services_tab__()
  182. self.add_srv_button.clicked.connect(self.__add_service__)
  183. self.remove_srv_button.clicked.connect(self.__remove_service__)
  184. ####### apps tab
  185. if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
  186. self.app_list = multiselectwidget.MultiSelectWidget(self)
  187. self.apps_layout.addWidget(self.app_list)
  188. self.app_list_manager = AppmenuSelectManager(self.vm, self.app_list)
  189. self.refresh_apps_button.clicked.connect(
  190. self.refresh_apps_button_pressed)
  191. # template change
  192. if self.template_name.isEnabled():
  193. self.template_name.currentIndexChanged.connect(
  194. self.template_apps_change)
  195. self.warn_template_missing_apps.setVisible(
  196. self.app_list_manager.has_missing)
  197. def setup_application(self):
  198. self.qapp.setApplicationName(self.tr("Qube Settings"))
  199. self.qapp.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
  200. def clear_threads(self):
  201. for thread in self.threads_list:
  202. if thread.isFinished():
  203. if self.progress:
  204. self.progress.hide()
  205. self.progress = None
  206. if thread.msg:
  207. (title, msg) = thread.msg
  208. QtWidgets.QMessageBox.warning(
  209. self,
  210. title,
  211. msg)
  212. self.threads_list.remove(thread)
  213. if self.thread_closes:
  214. self.done(0)
  215. return
  216. raise RuntimeError(self.tr('No finished thread found'))
  217. def keyPressEvent(self, event): # pylint: disable=invalid-name
  218. if event.key() == QtCore.Qt.Key_Enter \
  219. or event.key() == QtCore.Qt.Key_Return:
  220. return
  221. super(VMSettingsWindow, self).keyPressEvent(event)
  222. def accept(self):
  223. self.save_and_apply()
  224. def save_changes(self):
  225. with common_threads.busy_cursor():
  226. error = self.__save_changes__()
  227. if error:
  228. QtWidgets.QMessageBox.warning(
  229. self,
  230. self.tr("Error while changing settings for {0}!"
  231. ).format(self.vm.name),
  232. self.tr("ERROR: {0}").format('\n'.join(error)))
  233. def apply(self):
  234. self.save_changes()
  235. # these signals must be disconnected to avoid unintended behavior
  236. # on refreshing the drop-downs
  237. self.netVM.currentIndexChanged.disconnect()
  238. self.kernel.currentIndexChanged.disconnect()
  239. self.default_dispvm.currentIndexChanged.disconnect()
  240. self.__init_basic_tab__()
  241. self.__init_advanced_tab__()
  242. def save_and_apply(self):
  243. self.save_changes()
  244. self.done(0)
  245. def __save_changes__(self):
  246. ret = []
  247. try:
  248. ret_tmp = self.__apply_basic_tab__()
  249. if ret_tmp:
  250. ret += [self.tr("Basic tab:")] + ret_tmp
  251. ret_tmp = self.__apply_advanced_tab__()
  252. if ret_tmp:
  253. ret += [self.tr("Advanced tab:")] + ret_tmp
  254. ret_tmp = self.__apply_devices_tab__()
  255. if ret_tmp:
  256. ret += [self.tr("Devices tab:")] + ret_tmp
  257. ret_tmp = self.__apply_services_tab__()
  258. if ret_tmp:
  259. ret += [self.tr("Sevices tab:")] + ret_tmp
  260. except qubesadmin.exc.QubesException as qex:
  261. ret.append(self.tr('Error while saving changes: ') + str(qex))
  262. except Exception as ex: # pylint: disable=broad-except
  263. ret.append(repr(ex))
  264. try:
  265. if self.policy_allow_radio_button.isEnabled():
  266. self.fw_model.apply_rules(
  267. self.policy_allow_radio_button.isChecked(),
  268. self.temp_full_access.isChecked(),
  269. self.temp_full_access_time.value())
  270. except qubesadmin.exc.QubesException as qex:
  271. ret += [self.tr("Firewall tab:"), str(qex)]
  272. except Exception as ex: # pylint: disable=broad-except
  273. ret += [self.tr("Firewall tab:"), repr(ex)]
  274. try:
  275. if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
  276. self.app_list_manager.save_appmenu_select_changes()
  277. except qubesadmin.exc.QubesException as qex:
  278. ret += [self.tr("Applications tab:"), str(qex)]
  279. except Exception as ex: # pylint: disable=broad-except
  280. ret += [self.tr("Applications tab:"), repr(ex)]
  281. utils.debug('\n'.join(ret))
  282. return ret
  283. def check_network_availability(self):
  284. netvm = self.vm.netvm
  285. try:
  286. provides_network = self.vm.provides_network
  287. except AttributeError:
  288. provides_network = False
  289. self.no_netvm_label.setVisible(netvm is None and not provides_network)
  290. self.netvm_no_firewall_label.setVisible(
  291. netvm is not None and
  292. not netvm.features.check_with_template('qubes-firewall', False))
  293. self.sysnet_warning_label.setVisible(netvm is None and provides_network)
  294. def current_tab_changed(self, idx):
  295. if idx == self.tabs_indices["firewall"]:
  296. self.check_network_availability()
  297. ######### basic tab
  298. # TODO LISTENERS
  299. # - vm start/shutdown -> setEnabled on fields: template labels
  300. # - vm create/delete -> choices lists, whole window deactiv (if self.vm)
  301. # - property-set -> individual fields
  302. # TODO INTERACTIONS
  303. # netvm -> networking_groupbox
  304. # hvm -> include_in_balancing
  305. # TODO REMOVE
  306. # other_groupbox
  307. def __init_basic_tab__(self):
  308. self.vmname.setText(self.vm.name)
  309. self.vmname.setValidator(
  310. QtGui.QRegExpValidator(
  311. QtCore.QRegExp("[a-zA-Z0-9_-]*",
  312. QtCore.Qt.CaseInsensitive), None))
  313. self.vmname.setEnabled(False)
  314. self.rename_vm_button.setEnabled(not self.vm.is_running())
  315. self.delete_vm_button.setEnabled(not self.vm.is_running())
  316. if self.vm.is_running():
  317. self.delete_vm_button.setText(
  318. self.tr('Delete qube (cannot delete a running qube)'))
  319. if self.vm.qid == 0:
  320. self.vmlabel.setVisible(False)
  321. else:
  322. self.label_list, self.label_idx = utils.prepare_label_choice(
  323. self.vmlabel,
  324. self.vm, 'label',
  325. None,
  326. allow_default=False
  327. )
  328. self.vmlabel.setVisible(True)
  329. self.vmlabel.setEnabled(not self.vm.is_running())
  330. if self.vm.klass == 'AppVM':
  331. self.template_list, self.template_idx = utils.prepare_vm_choice(
  332. self.template_name,
  333. self.vm, 'template',
  334. self.vm.app.default_template,
  335. (lambda vm: vm.klass == 'TemplateVM'),
  336. allow_default=False, allow_none=False)
  337. elif self.vm.klass == 'DispVM':
  338. self.template_list, self.template_idx = utils.prepare_vm_choice(
  339. self.template_name,
  340. self.vm, 'template',
  341. self.vm.app.default_dispvm,
  342. (lambda vm: getattr(vm, 'template_for_dispvms', False)),
  343. allow_default=False, allow_none=False)
  344. else:
  345. self.template_name.setEnabled(False)
  346. self.template_idx = -1
  347. if self.vm.is_running():
  348. self.template_name.setEnabled(False)
  349. self.netvm_list, self.netvm_idx = utils.prepare_vm_choice(
  350. self.netVM,
  351. self.vm, 'netvm',
  352. self.vm.app.default_netvm,
  353. (lambda vm: vm.provides_network),
  354. allow_default=True, allow_none=True)
  355. self.netVM.currentIndexChanged.connect(self.check_warn_dispvmnetvm)
  356. self.include_in_backups.setChecked(self.vm.include_in_backups)
  357. try:
  358. self.autostart_vm.setChecked(self.vm.autostart)
  359. self.autostart_vm.setVisible(True)
  360. except AttributeError:
  361. self.autostart_vm.setVisible(False)
  362. # type
  363. self.type_label.setText(self.vm.klass)
  364. # installed by rpm
  365. self.rpm_label.setText('Yes' if self.vm.installed_by_rpm else 'No')
  366. # networking info
  367. if self.vm.netvm:
  368. self.networking_groupbox.setEnabled(True)
  369. self.ip_label.setText(self.vm.ip or "none")
  370. self.netmask_label.setText(self.vm.visible_netmask or "none")
  371. self.gateway_label.setText(self.vm.visible_gateway or "none")
  372. dns_list = getattr(self.vm, 'dns', ['10.139.1.1', '10.139.1.2'])
  373. self.dns_label.setText(", ".join(dns_list))
  374. else:
  375. self.networking_groupbox.setEnabled(False)
  376. # max priv storage
  377. self.priv_img_size = self.vm.volumes['private'].size // 1024**2
  378. self.max_priv_storage.setMinimum(self.priv_img_size)
  379. self.max_priv_storage.setValue(self.priv_img_size)
  380. self.root_img_size = self.vm.volumes['root'].size // 1024**2
  381. self.root_resize.setValue(self.root_img_size)
  382. self.root_resize.setMinimum(self.root_img_size)
  383. self.root_resize.setEnabled(self.vm.volumes['root'].save_on_stop)
  384. if not self.root_resize.isEnabled():
  385. self.root_resize.setToolTip(
  386. self.tr("To change system storage size, change properties "
  387. "of the underlying template."))
  388. self.root_resize_label.setEnabled(self.root_resize.isEnabled())
  389. self.warn_template_missing_apps.setVisible(False)
  390. def __apply_basic_tab__(self):
  391. msg = []
  392. # vm label changed
  393. try:
  394. if self.vmlabel.isVisible():
  395. if self.vmlabel.currentIndex() != self.label_idx:
  396. label = self.label_list[self.vmlabel.currentIndex()]
  397. self.vm.label = label
  398. self.label_idx = self.vmlabel.currentIndex()
  399. except qubesadmin.exc.QubesException as ex:
  400. msg.append(str(ex))
  401. # vm template changed
  402. try:
  403. if self.template_name.currentIndex() != self.template_idx:
  404. self.vm.template = \
  405. self.template_list[self.template_name.currentIndex()]
  406. self.template_idx = self.template_name.currentIndex()
  407. except qubesadmin.exc.QubesException as ex:
  408. msg.append(str(ex))
  409. # vm netvm changed
  410. try:
  411. if self.netVM.currentIndex() != self.netvm_idx:
  412. self.vm.netvm = self.netvm_list[self.netVM.currentIndex()]
  413. self.netvm_idx = self.netVM.currentIndex()
  414. except qubesadmin.exc.QubesException as ex:
  415. msg.append(str(ex))
  416. # include in backups
  417. try:
  418. if self.vm.include_in_backups != \
  419. self.include_in_backups.isChecked():
  420. self.vm.include_in_backups = self.include_in_backups.isChecked()
  421. except qubesadmin.exc.QubesException as ex:
  422. msg.append(str(ex))
  423. # autostart_vm
  424. try:
  425. if self.autostart_vm.isVisible():
  426. if self.vm.autostart != self.autostart_vm.isChecked():
  427. self.vm.autostart = self.autostart_vm.isChecked()
  428. except qubesadmin.exc.QubesException as ex:
  429. msg.append(str(ex))
  430. # max priv storage
  431. priv_size = self.max_priv_storage.value()
  432. if self.priv_img_size != priv_size:
  433. try:
  434. self.vm.volumes['private'].resize(priv_size * 1024**2)
  435. self.priv_img_size = priv_size
  436. except qubesadmin.exc.QubesException as ex:
  437. msg.append(str(ex))
  438. # max sys storage
  439. sys_size = self.root_resize.value()
  440. if self.root_img_size != sys_size:
  441. try:
  442. self.vm.volumes['root'].resize(sys_size * 1024**2)
  443. self.root_img_size = sys_size
  444. except qubesadmin.exc.QubesException as ex:
  445. msg.append(str(ex))
  446. return msg
  447. def check_mem_changes(self):
  448. if not self.include_in_balancing.isChecked():
  449. # do not interfere with settings if the VM is not included in memory
  450. # balancing
  451. return
  452. if self.max_mem_size.value() < self.init_mem.value():
  453. QtWidgets.QMessageBox.warning(
  454. self,
  455. self.tr("Warning!"),
  456. self.tr("Max memory can not be less than initial memory.<br>"
  457. "Setting max memory to equal initial memory."))
  458. self.max_mem_size.setValue(self.init_mem.value())
  459. # Linux specific limit: init memory must not be below
  460. # max_mem_size/10.79 in order to allow scaling up to
  461. # max_mem_size (or else "add_memory() failed: -17" problem)
  462. if self.vm.features.check_with_template('os', None) == 'Linux' and \
  463. self.init_mem.value() * 10 < self.max_mem_size.value():
  464. self.init_mem.setValue((self.max_mem_size.value() + 9) // 10)
  465. QtWidgets.QMessageBox.warning(
  466. self,
  467. self.tr("Warning!"),
  468. self.tr("For Linux qubes, Initial memory can not be less than "
  469. "one tenth Max memory.<br>Setting initial memory "
  470. "to the minimum allowed value."))
  471. def check_warn_dispvmnetvm(self):
  472. if not hasattr(self.vm, 'default_dispvm'):
  473. self.warn_netvm_dispvm.setVisible(False)
  474. return
  475. dispvm = self.default_dispvm_list[
  476. self.default_dispvm.currentIndex()]
  477. own_netvm = self.netvm_list[self.netVM.currentIndex()]
  478. if dispvm == qubesadmin.DEFAULT:
  479. dispvm = self.vm.property_get_default('default_dispvm')
  480. if dispvm == self.vm:
  481. self.warn_netvm_dispvm.setVisible(False)
  482. return
  483. dispvm_netvm = getattr(dispvm, 'netvm', None)
  484. if own_netvm == qubesadmin.DEFAULT:
  485. own_netvm = self.vm.property_get_default('netvm')
  486. if dispvm_netvm and dispvm_netvm != own_netvm:
  487. self.warn_netvm_dispvm.setVisible(True)
  488. else:
  489. self.warn_netvm_dispvm.setVisible(False)
  490. def rename_vm(self):
  491. dependencies = admin_utils.vm_dependencies(self.vm.app, self.vm)
  492. running_dependencies = [vm.name for (vm, prop) in dependencies
  493. if vm and prop == 'template'
  494. and vm.is_running()]
  495. if running_dependencies:
  496. QtWidgets.QMessageBox.warning(
  497. self,
  498. self.tr("Qube cannot be renamed!"),
  499. self.tr(
  500. "The following qubes using this qube as a template are "
  501. "running: <br> {}. <br> In order to rename this qube, you "
  502. "must first shut them down.").format(
  503. ", ".join(running_dependencies)))
  504. return
  505. new_vm_name, ok = QtWidgets.QInputDialog.getText(
  506. self,
  507. self.tr('Rename qube'),
  508. self.tr('New name: (WARNING: all other changes will be discarded)'),
  509. text=self.vm.name)
  510. if ok:
  511. thread = RenameVMThread(self.vm, new_vm_name, dependencies)
  512. self.threads_list.append(thread)
  513. thread.finished.connect(self.clear_threads)
  514. self.progress = QtWidgets.QProgressDialog(
  515. self.tr("Renaming Qube..."), "", 0, 0)
  516. self.progress.setCancelButton(None)
  517. self.progress.setModal(True)
  518. self.thread_closes = True
  519. self.progress.show()
  520. thread.start()
  521. def remove_vm(self):
  522. dependencies = admin_utils.vm_dependencies(self.vm.app, self.vm)
  523. if dependencies:
  524. list_text = utils.format_dependencies_list(dependencies)
  525. QtWidgets.QMessageBox.warning(
  526. self,
  527. self.tr("Qube cannot be removed!"),
  528. self.tr("This qube cannot be removed. It is used as:"
  529. " <br> {} <small>If you want to remove this qube, "
  530. "you should remove or change settings of each qube "
  531. "or setting that uses it.</small>").format(list_text))
  532. return
  533. answer, ok = QtWidgets.QInputDialog.getText(
  534. self,
  535. self.tr('Delete qube'),
  536. self.tr('Are you absolutely sure you want to delete this qube? '
  537. '<br/> All qube settings and data will be irrevocably'
  538. ' deleted. <br/> If you are sure, please enter this '
  539. 'qube\'s name below.'))
  540. if ok and answer == self.vm.name:
  541. thread = common_threads.RemoveVMThread(self.vm)
  542. thread.finished.connect(self.clear_threads)
  543. self.threads_list.append(thread)
  544. self.progress = QtWidgets.QProgressDialog(
  545. self.tr("Deleting Qube..."), "", 0, 0)
  546. self.progress.setCancelButton(None)
  547. self.progress.setModal(True)
  548. self.thread_closes = True
  549. self.progress.show()
  550. thread.start()
  551. elif ok:
  552. QtWidgets.QMessageBox.warning(
  553. self,
  554. self.tr("Removal cancelled"),
  555. self.tr("The qube will not be removed."))
  556. def clone_vm(self):
  557. cloned_vm_name, ok = QtWidgets.QInputDialog.getText(
  558. self,
  559. self.tr('Clone qube'),
  560. self.tr('Name for the cloned qube:'))
  561. if ok:
  562. thread = common_threads.CloneVMThread(self.vm, cloned_vm_name)
  563. thread.finished.connect(self.clear_threads)
  564. self.threads_list.append(thread)
  565. self.progress = QtWidgets.QProgressDialog(
  566. self.tr("Cloning Qube..."), "", 0, 0)
  567. self.progress.setCancelButton(None)
  568. self.progress.setModal(True)
  569. self.thread_closes = True
  570. self.progress.show()
  571. thread.start()
  572. ######### advanced tab
  573. def __init_advanced_tab__(self):
  574. self.init_mem.setValue(int(self.vm.memory))
  575. if self.vm.maxmem > 0:
  576. self.max_mem_size.setValue(int(self.vm.maxmem))
  577. else:
  578. maxmem = self.vm.property_get_default('maxmem')
  579. if maxmem == 0:
  580. maxmem = self.vm.memory
  581. self.max_mem_size.setValue(int(
  582. self.vm.features.get('qubesmanager.maxmem_value', maxmem)))
  583. self.vcpus.setMinimum(1)
  584. self.vcpus.setValue(int(self.vm.vcpus))
  585. self.include_in_balancing.setEnabled(True)
  586. self.include_in_balancing.setChecked(int(self.vm.maxmem) > 0)
  587. self.max_mem_size.setEnabled(self.include_in_balancing.isChecked())
  588. # in case VM is HVM
  589. if hasattr(self.vm, "kernel"):
  590. self.kernel_groupbox.setVisible(True)
  591. self.kernel_list, self.kernel_idx = utils.prepare_kernel_choice(
  592. self.kernel, self.vm, 'kernel',
  593. None,
  594. allow_default=True, allow_none=True)
  595. self.kernel.currentIndexChanged.connect(self.kernel_changed)
  596. self.kernel_opts.setText(getattr(self.vm, 'kernelopts', '-'))
  597. else:
  598. self.kernel_groupbox.setVisible(False)
  599. self.other_groupbox.setVisible(False)
  600. if not hasattr(self.vm, 'default_dispvm'):
  601. self.other_groupbox.setVisible(False)
  602. else:
  603. self.other_groupbox.setVisible(True)
  604. self.default_dispvm_list, self.default_dispvm_idx = \
  605. utils.prepare_vm_choice(
  606. self.default_dispvm,
  607. self.vm, 'default_dispvm',
  608. None,
  609. (lambda vm: getattr(vm, 'template_for_dispvms', False)),
  610. allow_default=True, allow_none=True)
  611. self.default_dispvm.currentIndexChanged.connect(
  612. self.check_warn_dispvmnetvm)
  613. self.check_warn_dispvmnetvm()
  614. self.update_virt_mode_list()
  615. windows_running = \
  616. self.vm.features.check_with_template('os', None) == 'Windows' \
  617. and self.vm.is_running()
  618. self.seamless_on_button.setEnabled(windows_running)
  619. self.seamless_off_button.setEnabled(windows_running)
  620. self.seamless_on_button.clicked.connect(self.enable_seamless)
  621. self.seamless_off_button.clicked.connect(self.disable_seamless)
  622. if hasattr(self.vm, "template_for_dispvms"):
  623. self.dvm_template_checkbox.setChecked(self.vm.template_for_dispvms)
  624. else:
  625. self.dvm_template_checkbox.setVisible(False)
  626. self.provides_network_checkbox.setChecked(
  627. getattr(self.vm, 'provides_network', False))
  628. if self.provides_network_checkbox.isChecked():
  629. domains_using = [vm.name for vm in self.vm.connected_vms]
  630. if domains_using:
  631. self.provides_network_checkbox.setEnabled(False)
  632. self.provides_network_checkbox.setToolTip(self.tr(
  633. "Cannot change this setting while this qube is used as a "
  634. "NetVM by the following qubes:\n") +
  635. "\n".join(domains_using))
  636. try:
  637. self.run_in_debug_mode.setChecked(self.vm.debug)
  638. self.run_in_debug_mode.setVisible(True)
  639. except AttributeError:
  640. self.run_in_debug_mode.setVisible(False)
  641. def enable_seamless(self):
  642. self.vm.run_service_for_stdio("qubes.SetGuiMode", input=b'SEAMLESS')
  643. def disable_seamless(self):
  644. self.vm.run_service_for_stdio("qubes.SetGuiMode", input=b'FULLSCREEN')
  645. def __apply_advanced_tab__(self):
  646. msg = []
  647. # mem/cpu
  648. try:
  649. if self.init_mem.value() != int(self.vm.memory):
  650. self.vm.memory = self.init_mem.value()
  651. curr_maxmem = int(self.vm.maxmem)
  652. if not self.include_in_balancing.isChecked():
  653. maxmem = 0
  654. else:
  655. maxmem = self.max_mem_size.value()
  656. if maxmem != curr_maxmem:
  657. if curr_maxmem > 0:
  658. self.vm.features['qubesmanager.maxmem_value'] = curr_maxmem
  659. self.vm.maxmem = maxmem
  660. if self.vcpus.value() != int(self.vm.vcpus):
  661. self.vm.vcpus = self.vcpus.value()
  662. except qubesadmin.exc.QubesException as ex:
  663. msg.append(str(ex))
  664. # in case VM is not Linux
  665. if hasattr(self.vm, "kernel") and self.kernel_groupbox.isVisible():
  666. try:
  667. if self.kernel.currentIndex() != self.kernel_idx:
  668. self.vm.kernel = self.kernel_list[
  669. self.kernel.currentIndex()]
  670. self.kernel_idx = self.kernel.currentIndex()
  671. except qubesadmin.exc.QubesException as ex:
  672. msg.append(str(ex))
  673. # vm default_dispvm changed
  674. try:
  675. if self.default_dispvm.currentIndex() != self.default_dispvm_idx:
  676. self.vm.default_dispvm = \
  677. self.default_dispvm_list[self.default_dispvm.currentIndex()]
  678. self.default_dispvm_idx = self.default_dispvm.currentIndex()
  679. except qubesadmin.exc.QubesException as ex:
  680. msg.append(str(ex))
  681. try:
  682. if self.virt_mode.currentIndex() != self.virt_mode_idx:
  683. self.vm.virt_mode = self.selected_virt_mode()
  684. self.virt_mode_idx = self.virt_mode.currentIndex()
  685. except Exception as ex: # pylint: disable=broad-except
  686. msg.append(str(ex))
  687. if getattr(self.vm, "template_for_dispvms", False) != \
  688. self.dvm_template_checkbox.isChecked():
  689. try:
  690. self.vm.template_for_dispvms = \
  691. self.dvm_template_checkbox.isChecked()
  692. if self.dvm_template_checkbox.isChecked():
  693. self.vm.features["appmenus-dispvm"] = True
  694. else:
  695. del self.vm.features["appmenus-dispvm"]
  696. except Exception as ex: # pylint: disable=broad-except
  697. msg.append(str(ex))
  698. if getattr(self.vm, 'provides_network', False) != \
  699. self.provides_network_checkbox.isChecked():
  700. try:
  701. self.vm.provides_network = \
  702. self.provides_network_checkbox.isChecked()
  703. except Exception as ex: # pylint: disable=broad-except
  704. msg.append(str(ex))
  705. # run_in_debug_mode
  706. try:
  707. if self.run_in_debug_mode.isVisible():
  708. if self.vm.debug != self.run_in_debug_mode.isChecked():
  709. self.vm.debug = self.run_in_debug_mode.isChecked()
  710. except qubesadmin.exc.QubesException as ex:
  711. msg.append(str(ex))
  712. return msg
  713. def include_in_balancing_changed(self, state):
  714. if self.dev_list.selected_list.count() > 0:
  715. if state == ui_settingsdlg.QtCore.Qt.Checked:
  716. self.dmm_warning_adv.show()
  717. self.dmm_warning_dev.show()
  718. else:
  719. self.dmm_warning_adv.hide()
  720. self.dmm_warning_dev.hide()
  721. self.max_mem_size.setEnabled(self.include_in_balancing.isChecked())
  722. if self.include_in_balancing.isChecked():
  723. self.check_mem_changes()
  724. def boot_from_cdrom_button_pressed(self):
  725. self.save_and_apply()
  726. subprocess.check_call(['qubes-vm-boot-from-device', self.vm.name])
  727. def selected_virt_mode(self):
  728. return self.virt_mode_list[self.virt_mode.currentIndex()]
  729. def virt_mode_changed(self, new_idx): # pylint: disable=unused-argument
  730. self.update_pv_warning()
  731. self.update_pvh_dont_support_devs()
  732. self.update_pvh_kernel_ver_warning()
  733. def update_pv_warning(self):
  734. if self.selected_virt_mode() == 'PV':
  735. self.pv_warning.show()
  736. else:
  737. self.pv_warning.hide()
  738. def update_virt_mode_list(self):
  739. choices = ['HVM', 'PV']
  740. if hasattr(self, "dev_list"):
  741. devs_attached = self.dev_list.selected_list.count() != 0
  742. else:
  743. devs_attached = bool(list(self.vm.devices['pci'].persistent()))
  744. if devs_attached:
  745. self.pvh_mode_hidden.show()
  746. else:
  747. choices.insert(0, 'PVH')
  748. self.pvh_mode_hidden.hide()
  749. if self.virt_mode_list:
  750. old_mode = self.selected_virt_mode()
  751. self.virt_mode.currentIndexChanged.disconnect()
  752. else:
  753. old_mode = None
  754. self.virt_mode.clear()
  755. self.virt_mode_list, self.virt_mode_idx = utils.prepare_choice(
  756. self.virt_mode, self.vm, 'virt_mode', choices, None,
  757. allow_default=True, transform=(lambda x: str(x).upper()))
  758. if old_mode is not None:
  759. self.virt_mode.setCurrentIndex(self.virt_mode_list.index(old_mode))
  760. self.virt_mode.currentIndexChanged.connect(self.virt_mode_changed)
  761. self.update_pv_warning()
  762. self.update_pvh_kernel_ver_warning()
  763. def update_pvh_kernel_ver_warning(self):
  764. if self.selected_virt_mode() != 'PVH':
  765. self.pvh_kernel_version_warning.hide()
  766. return
  767. kernel = self.kernel_list[self.kernel.currentIndex()]
  768. if self.pvh_kernel_version_ok(kernel):
  769. self.pvh_kernel_version_warning.hide()
  770. else:
  771. self.pvh_kernel_version_warning.show()
  772. def kernel_changed(self):
  773. self.update_pvh_kernel_ver_warning()
  774. def pvh_kernel_version_ok(self, name):
  775. # There are nearly no limitaions on kernel names (only file system and
  776. # general qvm-prefs rules). So we just look if we see something which
  777. # looks like a version number. It's just a warning to help the user
  778. # anyways.
  779. if name is None:
  780. return False
  781. if name is qubesadmin.DEFAULT:
  782. name = self.vm.app.default_kernel
  783. m = re.search(r'(\d+)\.(\d+)', name)
  784. if m is None:
  785. return False
  786. return (int(m.group(1)), int(m.group(2))) >= (4, 11)
  787. ######## devices tab
  788. def __init_devices_tab__(self):
  789. self.dev_list = multiselectwidget.MultiSelectWidget(self)
  790. self.dev_list.add_all_button.setVisible(False)
  791. self.devices_layout.addWidget(self.dev_list)
  792. dom0_devs = list(self.vm.app.domains['dom0'].devices['pci'].available())
  793. attached_devs = list(self.vm.devices['pci'].persistent())
  794. # pylint: disable=too-few-public-methods
  795. class DevListWidgetItem(QtWidgets.QListWidgetItem):
  796. def __init__(self, dev, unknown=False, parent=None):
  797. super(DevListWidgetItem, self).__init__(parent)
  798. name = dev.ident.replace('_', ":") + ' ' + dev.description
  799. if unknown:
  800. name += ' (unknown)'
  801. self.setText(name)
  802. self.dev = dev
  803. for dev in dom0_devs:
  804. if dev in attached_devs:
  805. self.dev_list.selected_list.addItem(DevListWidgetItem(dev))
  806. else:
  807. self.dev_list.available_list.addItem(DevListWidgetItem(dev))
  808. for dev in attached_devs:
  809. if dev not in dom0_devs:
  810. self.dev_list.selected_list.addItem(
  811. DevListWidgetItem(dev, unknown=True))
  812. if self.dev_list.selected_list.count() > 0\
  813. and self.include_in_balancing.isChecked():
  814. self.dmm_warning_adv.show()
  815. self.dmm_warning_dev.show()
  816. else:
  817. self.dmm_warning_adv.hide()
  818. self.dmm_warning_dev.hide()
  819. if self.vm.is_running():
  820. self.dev_list.setEnabled(False)
  821. self.turn_off_vm_to_modify_devs.setVisible(True)
  822. self.no_strict_reset_button.setEnabled(False)
  823. else:
  824. self.dev_list.setEnabled(True)
  825. self.turn_off_vm_to_modify_devs.setVisible(False)
  826. self.update_pvh_dont_support_devs()
  827. self.dev_list.setEnabled(not self.vm.is_running())
  828. def __apply_devices_tab__(self):
  829. msg = []
  830. try:
  831. old_devs = list(self.vm.devices['pci'].persistent())
  832. new_devs = [self.dev_list.selected_list.item(i).dev
  833. for i in range(self.dev_list.selected_list.count())]
  834. for dev in new_devs:
  835. if dev not in old_devs:
  836. options = {}
  837. if dev.ident in self.new_strict_reset_list:
  838. options['no-strict-reset'] = True
  839. ass = devices.DeviceAssignment(
  840. self.vm.app.domains['dom0'],
  841. dev.ident, persistent=True, options=options)
  842. self.vm.devices['pci'].attach(ass)
  843. elif (dev.ident in self.current_strict_reset_list) != \
  844. (dev.ident in self.new_strict_reset_list):
  845. current_assignment = None
  846. for assignment in self.vm.devices['pci'].assignments(
  847. persistent=True):
  848. if assignment.ident == dev.ident:
  849. current_assignment = assignment
  850. break
  851. if current_assignment is None:
  852. # it would be very weird if this happened
  853. msg.append(self.tr("Error re-assigning device ") +
  854. dev.ident)
  855. continue
  856. self.vm.devices['pci'].detach(current_assignment)
  857. current_assignment.options['no-strict-reset'] = \
  858. (dev.ident in self.new_strict_reset_list)
  859. self.vm.devices['pci'].attach(current_assignment)
  860. for ass in self.vm.devices['pci'].assignments(persistent=True):
  861. if ass.device not in new_devs:
  862. self.vm.devices['pci'].detach(ass)
  863. except qubesadmin.exc.QubesException as ex:
  864. if utils.is_debug():
  865. traceback.print_exc()
  866. msg.append(str(ex))
  867. return msg
  868. def devices_selection_changed(self):
  869. if self.include_in_balancing.isChecked():
  870. if self.dev_list.selected_list.count() > 0:
  871. self.dmm_warning_adv.show()
  872. self.dmm_warning_dev.show()
  873. else:
  874. self.dmm_warning_adv.hide()
  875. self.dmm_warning_dev.hide()
  876. self.update_virt_mode_list()
  877. def update_pvh_dont_support_devs(self):
  878. if self.selected_virt_mode() == 'PVH':
  879. self.dev_list.setEnabled(False)
  880. self.pvh_dont_support_devs.setVisible(True)
  881. else:
  882. self.dev_list.setEnabled(True)
  883. self.pvh_dont_support_devs.setVisible(False)
  884. def define_strict_reset_devices(self):
  885. for assignment in self.vm.devices['pci'].assignments():
  886. if assignment.options.get('no-strict-reset', False):
  887. self.current_strict_reset_list.append(
  888. assignment.ident.replace('_', ':'))
  889. self.new_strict_reset_list = self.current_strict_reset_list.copy()
  890. def strict_reset_button_pressed(self):
  891. device_list_window = device_list.PCIDeviceListWindow(
  892. self.vm, self.qapp, self.dev_list, self.new_strict_reset_list, self)
  893. device_list_window.exec()
  894. ######## applications tab
  895. def refresh_apps_button_pressed(self):
  896. self.refresh_apps_button.setEnabled(False)
  897. self.refresh_apps_button.setText(self.tr('Refresh in progress...'))
  898. thread = RefreshAppsVMThread(self.vm, self.refresh_apps_button)
  899. thread.finished.connect(self.clear_threads)
  900. thread.finished.connect(self.refresh_finished)
  901. self.threads_list.append(thread)
  902. thread.start()
  903. def refresh_finished(self):
  904. self.app_list_manager = AppmenuSelectManager(self.vm, self.app_list)
  905. self.refresh_apps_button.setEnabled(True)
  906. self.refresh_apps_button.setText(self.tr('Refresh Applications'))
  907. def template_apps_change(self):
  908. if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
  909. self.app_list_manager.fill_apps_list(
  910. template=self.template_list[self.template_name.currentIndex()])
  911. # add a label to show
  912. self.warn_template_missing_apps.setVisible(
  913. self.app_list_manager.has_missing)
  914. ######## services tab
  915. def __init_services_tab__(self):
  916. self.new_srv_dict = {}
  917. for feature in self.vm.features:
  918. if not feature.startswith('service.'):
  919. continue
  920. service = feature[len('service.'):]
  921. item = QtWidgets.QListWidgetItem(service)
  922. item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked
  923. if self.vm.features[feature]
  924. else ui_settingsdlg.QtCore.Qt.Unchecked)
  925. self.services_list.addItem(item)
  926. self.new_srv_dict[service] = self.vm.features[feature]
  927. self.service_line_edit.addItem("")
  928. supported_services = set()
  929. service_prefix = "supported-service."
  930. for feature in self.vm.features:
  931. if feature.startswith(service_prefix):
  932. supported_services.add(feature[len(service_prefix):])
  933. if getattr(self.vm, "template", None):
  934. for feature in self.vm.template.features:
  935. if feature.startswith(service_prefix):
  936. supported_services.add(feature[len(service_prefix):])
  937. for service in sorted(supported_services):
  938. self.service_line_edit.addItem(service)
  939. self.service_line_edit.addItem(self.tr('(custom...)'))
  940. self.service_line_edit.setEditText("")
  941. def __add_service__(self):
  942. srv = str(self.service_line_edit.currentText()).strip()
  943. if srv != "":
  944. if self.service_line_edit.currentIndex() == \
  945. len(self.service_line_edit) - 1:
  946. (custom_name, ok) = QtWidgets.QInputDialog.getText(
  947. self, self.tr("Custom service name"),
  948. self.tr(
  949. "Name of the service:"))
  950. if ok:
  951. srv = custom_name.strip()
  952. else:
  953. return
  954. if srv in self.new_srv_dict:
  955. QtWidgets.QMessageBox.information(
  956. self,
  957. '',
  958. self.tr('Service already on the list!'))
  959. return
  960. item = QtWidgets.QListWidgetItem(srv)
  961. item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked)
  962. self.services_list.addItem(item)
  963. self.new_srv_dict[srv] = True
  964. def __remove_service__(self):
  965. item = self.services_list.currentItem()
  966. if not item:
  967. return
  968. row = self.services_list.currentRow()
  969. item = self.services_list.takeItem(row)
  970. del self.new_srv_dict[str(item.text())]
  971. def __apply_services_tab__(self):
  972. msg = []
  973. try:
  974. for i in range(self.services_list.count()):
  975. item = self.services_list.item(i)
  976. self.new_srv_dict[str(item.text())] = \
  977. (item.checkState() == ui_settingsdlg.QtCore.Qt.Checked)
  978. for service, v in self.new_srv_dict.items():
  979. feature = 'service.' + service
  980. if v != self.vm.features.get(feature, object()):
  981. self.vm.features[feature] = v
  982. for feature in self.vm.features:
  983. if not feature.startswith('service.'):
  984. continue
  985. service = feature[len('service.'):]
  986. if service not in self.new_srv_dict:
  987. del self.vm.features[feature]
  988. except qubesadmin.exc.QubesException as ex:
  989. msg.append(str(ex))
  990. return msg
  991. ######### firewall tab related
  992. def set_fw_model(self, model):
  993. self.fw_model = model
  994. self.rulesTreeView.setModel(model)
  995. self.rulesTreeView.header().setSectionResizeMode(
  996. QtWidgets.QHeaderView.ResizeToContents)
  997. self.rulesTreeView.header().setSectionResizeMode(
  998. 0, QtWidgets.QHeaderView.Stretch)
  999. self.set_allow(model.allow)
  1000. if model.temp_full_access_expire_time:
  1001. self.temp_full_access.setChecked(True)
  1002. self.temp_full_access_time.setValue(
  1003. (model.temp_full_access_expire_time -
  1004. int(firewall.datetime.datetime.now().strftime("%s"))) / 60)
  1005. def disable_all_fw_conf(self):
  1006. self.firewall_modified_outside_label.setVisible(True)
  1007. self.policy_allow_radio_button.setEnabled(False)
  1008. self.policy_deny_radio_button.setEnabled(False)
  1009. self.rulesTreeView.setEnabled(False)
  1010. self.new_rule_button.setEnabled(False)
  1011. self.edit_rule_button.setEnabled(False)
  1012. self.delete_rule_button.setEnabled(False)
  1013. self.firewal_rules_label.setEnabled(False)
  1014. self.tempFullAccessWidget.setEnabled(False)
  1015. def set_allow(self, allow):
  1016. self.policy_allow_radio_button.setChecked(allow)
  1017. self.policy_deny_radio_button.setChecked(not allow)
  1018. self.policy_changed()
  1019. def policy_changed(self):
  1020. self.rulesTreeView.setEnabled(
  1021. self.policy_deny_radio_button.isChecked())
  1022. self.new_rule_button.setEnabled(
  1023. self.policy_deny_radio_button.isChecked())
  1024. self.edit_rule_button.setEnabled(
  1025. self.policy_deny_radio_button.isChecked())
  1026. self.delete_rule_button.setEnabled(
  1027. self.policy_deny_radio_button.isChecked())
  1028. self.firewal_rules_label.setEnabled(
  1029. self.policy_deny_radio_button.isChecked())
  1030. self.tempFullAccessWidget.setEnabled(
  1031. self.policy_deny_radio_button.isChecked())
  1032. def new_rule_button_pressed(self):
  1033. dialog = firewall.NewFwRuleDlg()
  1034. self.fw_model.run_rule_dialog(dialog)
  1035. def edit_rule_button_pressed(self):
  1036. selected = self.rulesTreeView.selectedIndexes()
  1037. if selected:
  1038. dialog = firewall.NewFwRuleDlg()
  1039. dialog.set_ok_state(True)
  1040. row = self.rulesTreeView.selectedIndexes().pop().row()
  1041. self.fw_model.populate_edit_dialog(dialog, row)
  1042. self.fw_model.run_rule_dialog(dialog, row)
  1043. def delete_rule_button_pressed(self):
  1044. for i in {index.row() for index
  1045. in self.rulesTreeView.selectedIndexes()}:
  1046. self.fw_model.remove_child(i)
  1047. parser = QubesArgumentParser(vmname_nargs=1)
  1048. parser.add_argument('--tab', metavar='TAB',
  1049. action='store',
  1050. choices=VMSettingsWindow.tabs_indices.keys())
  1051. parser.set_defaults(
  1052. tab='basic',
  1053. )
  1054. def main(args=None):
  1055. args = parser.parse_args(args)
  1056. vm = args.domains.pop()
  1057. utils.run_synchronous(functools.partial(VMSettingsWindow, vm, args.tab))
  1058. if __name__ == "__main__":
  1059. main()
  1060. # vim:sw=4:et: