settings.py 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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.max_priv_storage.setMaximum(
  381. max(self.priv_img_size,
  382. self.qubesapp.pools[self.vm.volumes['private'].pool].size
  383. // 1024**2))
  384. self.root_img_size = self.vm.volumes['root'].size // 1024**2
  385. self.root_resize.setValue(self.root_img_size)
  386. self.root_resize.setMinimum(self.root_img_size)
  387. self.root_resize.setMaximum(
  388. max(self.root_img_size,
  389. self.qubesapp.pools[self.vm.volumes['root'].pool].size
  390. // 1024**2))
  391. self.root_resize.setEnabled(self.vm.volumes['root'].save_on_stop)
  392. if not self.root_resize.isEnabled():
  393. self.root_resize.setToolTip(
  394. self.tr("To change system storage size, change properties "
  395. "of the underlying template."))
  396. self.root_resize_label.setEnabled(self.root_resize.isEnabled())
  397. self.warn_template_missing_apps.setVisible(False)
  398. def __apply_basic_tab__(self):
  399. msg = []
  400. # vm label changed
  401. try:
  402. if self.vmlabel.isVisible():
  403. if self.vmlabel.currentIndex() != self.label_idx:
  404. label = self.label_list[self.vmlabel.currentIndex()]
  405. self.vm.label = label
  406. self.label_idx = self.vmlabel.currentIndex()
  407. except qubesadmin.exc.QubesException as ex:
  408. msg.append(str(ex))
  409. # vm template changed
  410. try:
  411. if self.template_name.currentIndex() != self.template_idx:
  412. self.vm.template = \
  413. self.template_list[self.template_name.currentIndex()]
  414. self.template_idx = self.template_name.currentIndex()
  415. except qubesadmin.exc.QubesException as ex:
  416. msg.append(str(ex))
  417. # vm netvm changed
  418. try:
  419. if self.netVM.currentIndex() != self.netvm_idx:
  420. self.vm.netvm = self.netvm_list[self.netVM.currentIndex()]
  421. self.netvm_idx = self.netVM.currentIndex()
  422. except qubesadmin.exc.QubesException as ex:
  423. msg.append(str(ex))
  424. # include in backups
  425. try:
  426. if self.vm.include_in_backups != \
  427. self.include_in_backups.isChecked():
  428. self.vm.include_in_backups = self.include_in_backups.isChecked()
  429. except qubesadmin.exc.QubesException as ex:
  430. msg.append(str(ex))
  431. # autostart_vm
  432. try:
  433. if self.autostart_vm.isVisible():
  434. if self.vm.autostart != self.autostart_vm.isChecked():
  435. self.vm.autostart = self.autostart_vm.isChecked()
  436. except qubesadmin.exc.QubesException as ex:
  437. msg.append(str(ex))
  438. # max priv storage
  439. priv_size = self.max_priv_storage.value()
  440. if self.priv_img_size != priv_size:
  441. try:
  442. self.vm.volumes['private'].resize(priv_size * 1024**2)
  443. self.priv_img_size = priv_size
  444. except qubesadmin.exc.QubesException as ex:
  445. msg.append(str(ex))
  446. # max sys storage
  447. sys_size = self.root_resize.value()
  448. if self.root_img_size != sys_size:
  449. try:
  450. self.vm.volumes['root'].resize(sys_size * 1024**2)
  451. self.root_img_size = sys_size
  452. except qubesadmin.exc.QubesException as ex:
  453. msg.append(str(ex))
  454. return msg
  455. def check_mem_changes(self):
  456. if not self.include_in_balancing.isChecked():
  457. # do not interfere with settings if the VM is not included in memory
  458. # balancing
  459. return
  460. if self.max_mem_size.value() < self.init_mem.value():
  461. QtWidgets.QMessageBox.warning(
  462. self,
  463. self.tr("Warning!"),
  464. self.tr("Max memory can not be less than initial memory.<br>"
  465. "Setting max memory to equal initial memory."))
  466. self.max_mem_size.setValue(self.init_mem.value())
  467. # Linux specific limit: init memory must not be below
  468. # max_mem_size/10.79 in order to allow scaling up to
  469. # max_mem_size (or else "add_memory() failed: -17" problem)
  470. if self.vm.features.check_with_template('os', None) == 'Linux' and \
  471. self.init_mem.value() * 10 < self.max_mem_size.value():
  472. self.init_mem.setValue((self.max_mem_size.value() + 9) // 10)
  473. QtWidgets.QMessageBox.warning(
  474. self,
  475. self.tr("Warning!"),
  476. self.tr("For Linux qubes, Initial memory can not be less than "
  477. "one tenth Max memory.<br>Setting initial memory "
  478. "to the minimum allowed value."))
  479. def check_warn_dispvmnetvm(self):
  480. if not hasattr(self.vm, 'default_dispvm'):
  481. self.warn_netvm_dispvm.setVisible(False)
  482. return
  483. dispvm = self.default_dispvm_list[
  484. self.default_dispvm.currentIndex()]
  485. own_netvm = self.netvm_list[self.netVM.currentIndex()]
  486. if dispvm == qubesadmin.DEFAULT:
  487. dispvm = self.vm.property_get_default('default_dispvm')
  488. if dispvm == self.vm:
  489. self.warn_netvm_dispvm.setVisible(False)
  490. return
  491. dispvm_netvm = getattr(dispvm, 'netvm', None)
  492. if own_netvm == qubesadmin.DEFAULT:
  493. own_netvm = self.vm.property_get_default('netvm')
  494. if dispvm_netvm and dispvm_netvm != own_netvm:
  495. self.warn_netvm_dispvm.setVisible(True)
  496. else:
  497. self.warn_netvm_dispvm.setVisible(False)
  498. def rename_vm(self):
  499. dependencies = admin_utils.vm_dependencies(self.vm.app, self.vm)
  500. running_dependencies = [vm.name for (vm, prop) in dependencies
  501. if vm and prop == 'template'
  502. and vm.is_running()]
  503. if running_dependencies:
  504. QtWidgets.QMessageBox.warning(
  505. self,
  506. self.tr("Qube cannot be renamed!"),
  507. self.tr(
  508. "The following qubes using this qube as a template are "
  509. "running: <br> {}. <br> In order to rename this qube, you "
  510. "must first shut them down.").format(
  511. ", ".join(running_dependencies)))
  512. return
  513. new_vm_name, ok = QtWidgets.QInputDialog.getText(
  514. self,
  515. self.tr('Rename qube'),
  516. self.tr('New name: (WARNING: all other changes will be discarded)'),
  517. text=self.vm.name)
  518. if ok:
  519. thread = RenameVMThread(self.vm, new_vm_name, dependencies)
  520. self.threads_list.append(thread)
  521. thread.finished.connect(self.clear_threads)
  522. self.progress = QtWidgets.QProgressDialog(
  523. self.tr("Renaming Qube..."), "", 0, 0)
  524. self.progress.setCancelButton(None)
  525. self.progress.setModal(True)
  526. self.thread_closes = True
  527. self.progress.show()
  528. thread.start()
  529. def remove_vm(self):
  530. dependencies = admin_utils.vm_dependencies(self.vm.app, self.vm)
  531. if dependencies:
  532. list_text = utils.format_dependencies_list(dependencies)
  533. QtWidgets.QMessageBox.warning(
  534. self,
  535. self.tr("Qube cannot be removed!"),
  536. self.tr("This qube cannot be removed. It is used as:"
  537. " <br> {} <small>If you want to remove this qube, "
  538. "you should remove or change settings of each qube "
  539. "or setting that uses it.</small>").format(list_text))
  540. return
  541. answer, ok = QtWidgets.QInputDialog.getText(
  542. self,
  543. self.tr('Delete qube'),
  544. self.tr('Are you absolutely sure you want to delete this qube? '
  545. '<br/> All qube settings and data will be irrevocably'
  546. ' deleted. <br/> If you are sure, please enter this '
  547. 'qube\'s name below.'))
  548. if ok and answer == self.vm.name:
  549. thread = common_threads.RemoveVMThread(self.vm)
  550. thread.finished.connect(self.clear_threads)
  551. self.threads_list.append(thread)
  552. self.progress = QtWidgets.QProgressDialog(
  553. self.tr("Deleting Qube..."), "", 0, 0)
  554. self.progress.setCancelButton(None)
  555. self.progress.setModal(True)
  556. self.thread_closes = True
  557. self.progress.show()
  558. thread.start()
  559. elif ok:
  560. QtWidgets.QMessageBox.warning(
  561. self,
  562. self.tr("Removal cancelled"),
  563. self.tr("The qube will not be removed."))
  564. def clone_vm(self):
  565. cloned_vm_name, ok = QtWidgets.QInputDialog.getText(
  566. self,
  567. self.tr('Clone qube'),
  568. self.tr('Name for the cloned qube:'))
  569. if ok:
  570. thread = common_threads.CloneVMThread(self.vm, cloned_vm_name)
  571. thread.finished.connect(self.clear_threads)
  572. self.threads_list.append(thread)
  573. self.progress = QtWidgets.QProgressDialog(
  574. self.tr("Cloning Qube..."), "", 0, 0)
  575. self.progress.setCancelButton(None)
  576. self.progress.setModal(True)
  577. self.thread_closes = True
  578. self.progress.show()
  579. thread.start()
  580. ######### advanced tab
  581. def __init_advanced_tab__(self):
  582. self.init_mem.setValue(int(self.vm.memory))
  583. if self.vm.maxmem > 0:
  584. self.max_mem_size.setValue(int(self.vm.maxmem))
  585. else:
  586. maxmem = self.vm.property_get_default('maxmem')
  587. if maxmem == 0:
  588. maxmem = self.vm.memory
  589. self.max_mem_size.setValue(int(
  590. self.vm.features.get('qubesmanager.maxmem_value', maxmem)))
  591. self.vcpus.setMinimum(1)
  592. self.vcpus.setValue(int(self.vm.vcpus))
  593. self.include_in_balancing.setEnabled(True)
  594. self.include_in_balancing.setChecked(int(self.vm.maxmem) > 0)
  595. self.max_mem_size.setEnabled(self.include_in_balancing.isChecked())
  596. # in case VM is HVM
  597. if hasattr(self.vm, "kernel"):
  598. self.kernel_groupbox.setVisible(True)
  599. self.kernel_list, self.kernel_idx = utils.prepare_kernel_choice(
  600. self.kernel, self.vm, 'kernel',
  601. None,
  602. allow_default=True, allow_none=True)
  603. self.kernel.currentIndexChanged.connect(self.kernel_changed)
  604. self.kernel_opts.setText(getattr(self.vm, 'kernelopts', '-'))
  605. else:
  606. self.kernel_groupbox.setVisible(False)
  607. self.other_groupbox.setVisible(False)
  608. if not hasattr(self.vm, 'default_dispvm'):
  609. self.other_groupbox.setVisible(False)
  610. else:
  611. self.other_groupbox.setVisible(True)
  612. self.default_dispvm_list, self.default_dispvm_idx = \
  613. utils.prepare_vm_choice(
  614. self.default_dispvm,
  615. self.vm, 'default_dispvm',
  616. None,
  617. (lambda vm: getattr(vm, 'template_for_dispvms', False)),
  618. allow_default=True, allow_none=True)
  619. self.default_dispvm.currentIndexChanged.connect(
  620. self.check_warn_dispvmnetvm)
  621. self.check_warn_dispvmnetvm()
  622. self.update_virt_mode_list()
  623. windows_running = \
  624. self.vm.features.check_with_template('os', None) == 'Windows' \
  625. and self.vm.is_running()
  626. self.seamless_on_button.setEnabled(windows_running)
  627. self.seamless_off_button.setEnabled(windows_running)
  628. self.seamless_on_button.clicked.connect(self.enable_seamless)
  629. self.seamless_off_button.clicked.connect(self.disable_seamless)
  630. if hasattr(self.vm, "template_for_dispvms"):
  631. self.dvm_template_checkbox.setChecked(self.vm.template_for_dispvms)
  632. else:
  633. self.dvm_template_checkbox.setVisible(False)
  634. self.provides_network_checkbox.setChecked(
  635. getattr(self.vm, 'provides_network', False))
  636. if self.provides_network_checkbox.isChecked():
  637. domains_using = [vm.name for vm in self.vm.connected_vms]
  638. if domains_using:
  639. self.provides_network_checkbox.setEnabled(False)
  640. self.provides_network_checkbox.setToolTip(self.tr(
  641. "Cannot change this setting while this qube is used as a "
  642. "NetVM by the following qubes:\n") +
  643. "\n".join(domains_using))
  644. try:
  645. self.run_in_debug_mode.setChecked(self.vm.debug)
  646. self.run_in_debug_mode.setVisible(True)
  647. except AttributeError:
  648. self.run_in_debug_mode.setVisible(False)
  649. def enable_seamless(self):
  650. self.vm.run_service_for_stdio("qubes.SetGuiMode", input=b'SEAMLESS')
  651. def disable_seamless(self):
  652. self.vm.run_service_for_stdio("qubes.SetGuiMode", input=b'FULLSCREEN')
  653. def __apply_advanced_tab__(self):
  654. msg = []
  655. # mem/cpu
  656. try:
  657. if self.init_mem.value() != int(self.vm.memory):
  658. self.vm.memory = self.init_mem.value()
  659. curr_maxmem = int(self.vm.maxmem)
  660. if not self.include_in_balancing.isChecked():
  661. maxmem = 0
  662. else:
  663. maxmem = self.max_mem_size.value()
  664. if maxmem != curr_maxmem:
  665. if curr_maxmem > 0:
  666. self.vm.features['qubesmanager.maxmem_value'] = curr_maxmem
  667. self.vm.maxmem = maxmem
  668. if self.vcpus.value() != int(self.vm.vcpus):
  669. self.vm.vcpus = self.vcpus.value()
  670. except qubesadmin.exc.QubesException as ex:
  671. msg.append(str(ex))
  672. # in case VM is not Linux
  673. if hasattr(self.vm, "kernel") and self.kernel_groupbox.isVisible():
  674. try:
  675. if self.kernel.currentIndex() != self.kernel_idx:
  676. self.vm.kernel = self.kernel_list[
  677. self.kernel.currentIndex()]
  678. self.kernel_idx = self.kernel.currentIndex()
  679. except qubesadmin.exc.QubesException as ex:
  680. msg.append(str(ex))
  681. # vm default_dispvm changed
  682. try:
  683. if self.default_dispvm.currentIndex() != self.default_dispvm_idx:
  684. self.vm.default_dispvm = \
  685. self.default_dispvm_list[self.default_dispvm.currentIndex()]
  686. self.default_dispvm_idx = self.default_dispvm.currentIndex()
  687. except qubesadmin.exc.QubesException as ex:
  688. msg.append(str(ex))
  689. try:
  690. if self.virt_mode.currentIndex() != self.virt_mode_idx:
  691. self.vm.virt_mode = self.selected_virt_mode()
  692. self.virt_mode_idx = self.virt_mode.currentIndex()
  693. except Exception as ex: # pylint: disable=broad-except
  694. msg.append(str(ex))
  695. if getattr(self.vm, "template_for_dispvms", False) != \
  696. self.dvm_template_checkbox.isChecked():
  697. try:
  698. self.vm.template_for_dispvms = \
  699. self.dvm_template_checkbox.isChecked()
  700. if self.dvm_template_checkbox.isChecked():
  701. self.vm.features["appmenus-dispvm"] = True
  702. else:
  703. del self.vm.features["appmenus-dispvm"]
  704. except Exception as ex: # pylint: disable=broad-except
  705. msg.append(str(ex))
  706. if getattr(self.vm, 'provides_network', False) != \
  707. self.provides_network_checkbox.isChecked():
  708. try:
  709. self.vm.provides_network = \
  710. self.provides_network_checkbox.isChecked()
  711. except Exception as ex: # pylint: disable=broad-except
  712. msg.append(str(ex))
  713. # run_in_debug_mode
  714. try:
  715. if self.run_in_debug_mode.isVisible():
  716. if self.vm.debug != self.run_in_debug_mode.isChecked():
  717. self.vm.debug = self.run_in_debug_mode.isChecked()
  718. except qubesadmin.exc.QubesException as ex:
  719. msg.append(str(ex))
  720. return msg
  721. def include_in_balancing_changed(self, state):
  722. if self.dev_list.selected_list.count() > 0:
  723. if state == ui_settingsdlg.QtCore.Qt.Checked:
  724. self.dmm_warning_adv.show()
  725. self.dmm_warning_dev.show()
  726. else:
  727. self.dmm_warning_adv.hide()
  728. self.dmm_warning_dev.hide()
  729. self.max_mem_size.setEnabled(self.include_in_balancing.isChecked())
  730. if self.include_in_balancing.isChecked():
  731. self.check_mem_changes()
  732. def boot_from_cdrom_button_pressed(self):
  733. self.save_and_apply()
  734. subprocess.check_call(['qubes-vm-boot-from-device', self.vm.name])
  735. def selected_virt_mode(self):
  736. return self.virt_mode_list[self.virt_mode.currentIndex()]
  737. def virt_mode_changed(self, new_idx): # pylint: disable=unused-argument
  738. self.update_pv_warning()
  739. self.update_pvh_dont_support_devs()
  740. self.update_pvh_kernel_ver_warning()
  741. def update_pv_warning(self):
  742. if self.selected_virt_mode() == 'PV':
  743. self.pv_warning.show()
  744. else:
  745. self.pv_warning.hide()
  746. def update_virt_mode_list(self):
  747. choices = ['HVM', 'PV']
  748. if hasattr(self, "dev_list"):
  749. devs_attached = self.dev_list.selected_list.count() != 0
  750. else:
  751. devs_attached = bool(list(self.vm.devices['pci'].persistent()))
  752. if devs_attached:
  753. self.pvh_mode_hidden.show()
  754. else:
  755. choices.insert(0, 'PVH')
  756. self.pvh_mode_hidden.hide()
  757. if self.virt_mode_list:
  758. old_mode = self.selected_virt_mode()
  759. self.virt_mode.currentIndexChanged.disconnect()
  760. else:
  761. old_mode = None
  762. self.virt_mode.clear()
  763. self.virt_mode_list, self.virt_mode_idx = utils.prepare_choice(
  764. self.virt_mode, self.vm, 'virt_mode', choices, None,
  765. allow_default=True, transform=(lambda x: str(x).upper()))
  766. if old_mode is not None:
  767. self.virt_mode.setCurrentIndex(self.virt_mode_list.index(old_mode))
  768. self.virt_mode.currentIndexChanged.connect(self.virt_mode_changed)
  769. self.update_pv_warning()
  770. self.update_pvh_kernel_ver_warning()
  771. def update_pvh_kernel_ver_warning(self):
  772. if self.selected_virt_mode() != 'PVH':
  773. self.pvh_kernel_version_warning.hide()
  774. return
  775. kernel = self.kernel_list[self.kernel.currentIndex()]
  776. if self.pvh_kernel_version_ok(kernel):
  777. self.pvh_kernel_version_warning.hide()
  778. else:
  779. self.pvh_kernel_version_warning.show()
  780. def kernel_changed(self):
  781. self.update_pvh_kernel_ver_warning()
  782. def pvh_kernel_version_ok(self, name):
  783. # There are nearly no limitaions on kernel names (only file system and
  784. # general qvm-prefs rules). So we just look if we see something which
  785. # looks like a version number. It's just a warning to help the user
  786. # anyways.
  787. if name is None:
  788. return False
  789. if name is qubesadmin.DEFAULT:
  790. name = self.vm.app.default_kernel
  791. m = re.search(r'(\d+)\.(\d+)', name)
  792. if m is None:
  793. return False
  794. return (int(m.group(1)), int(m.group(2))) >= (4, 11)
  795. ######## devices tab
  796. def __init_devices_tab__(self):
  797. self.dev_list = multiselectwidget.MultiSelectWidget(self)
  798. self.dev_list.add_all_button.setVisible(False)
  799. self.devices_layout.addWidget(self.dev_list)
  800. dom0_devs = list(self.vm.app.domains['dom0'].devices['pci'].available())
  801. attached_devs = list(self.vm.devices['pci'].persistent())
  802. # pylint: disable=too-few-public-methods
  803. class DevListWidgetItem(QtWidgets.QListWidgetItem):
  804. def __init__(self, dev, unknown=False, parent=None):
  805. super(DevListWidgetItem, self).__init__(parent)
  806. name = dev.ident.replace('_', ":") + ' ' + dev.description
  807. if unknown:
  808. name += ' (unknown)'
  809. self.setText(name)
  810. self.dev = dev
  811. for dev in dom0_devs:
  812. if dev in attached_devs:
  813. self.dev_list.selected_list.addItem(DevListWidgetItem(dev))
  814. else:
  815. self.dev_list.available_list.addItem(DevListWidgetItem(dev))
  816. for dev in attached_devs:
  817. if dev not in dom0_devs:
  818. self.dev_list.selected_list.addItem(
  819. DevListWidgetItem(dev, unknown=True))
  820. if self.dev_list.selected_list.count() > 0\
  821. and self.include_in_balancing.isChecked():
  822. self.dmm_warning_adv.show()
  823. self.dmm_warning_dev.show()
  824. else:
  825. self.dmm_warning_adv.hide()
  826. self.dmm_warning_dev.hide()
  827. if self.vm.is_running():
  828. self.dev_list.setEnabled(False)
  829. self.turn_off_vm_to_modify_devs.setVisible(True)
  830. self.no_strict_reset_button.setEnabled(False)
  831. else:
  832. self.dev_list.setEnabled(True)
  833. self.turn_off_vm_to_modify_devs.setVisible(False)
  834. self.update_pvh_dont_support_devs()
  835. self.dev_list.setEnabled(not self.vm.is_running())
  836. def __apply_devices_tab__(self):
  837. msg = []
  838. try:
  839. old_devs = list(self.vm.devices['pci'].persistent())
  840. new_devs = [self.dev_list.selected_list.item(i).dev
  841. for i in range(self.dev_list.selected_list.count())]
  842. for dev in new_devs:
  843. if dev not in old_devs:
  844. options = {}
  845. if dev.ident in self.new_strict_reset_list:
  846. options['no-strict-reset'] = True
  847. ass = devices.DeviceAssignment(
  848. self.vm.app.domains['dom0'],
  849. dev.ident, persistent=True, options=options)
  850. self.vm.devices['pci'].attach(ass)
  851. elif (dev.ident in self.current_strict_reset_list) != \
  852. (dev.ident in self.new_strict_reset_list):
  853. current_assignment = None
  854. for assignment in self.vm.devices['pci'].assignments(
  855. persistent=True):
  856. if assignment.ident == dev.ident:
  857. current_assignment = assignment
  858. break
  859. if current_assignment is None:
  860. # it would be very weird if this happened
  861. msg.append(self.tr("Error re-assigning device ") +
  862. dev.ident)
  863. continue
  864. self.vm.devices['pci'].detach(current_assignment)
  865. current_assignment.options['no-strict-reset'] = \
  866. (dev.ident in self.new_strict_reset_list)
  867. self.vm.devices['pci'].attach(current_assignment)
  868. for ass in self.vm.devices['pci'].assignments(persistent=True):
  869. if ass.device not in new_devs:
  870. self.vm.devices['pci'].detach(ass)
  871. except qubesadmin.exc.QubesException as ex:
  872. if utils.is_debug():
  873. traceback.print_exc()
  874. msg.append(str(ex))
  875. return msg
  876. def devices_selection_changed(self):
  877. if self.include_in_balancing.isChecked():
  878. if self.dev_list.selected_list.count() > 0:
  879. self.dmm_warning_adv.show()
  880. self.dmm_warning_dev.show()
  881. else:
  882. self.dmm_warning_adv.hide()
  883. self.dmm_warning_dev.hide()
  884. self.update_virt_mode_list()
  885. def update_pvh_dont_support_devs(self):
  886. if self.selected_virt_mode() == 'PVH':
  887. self.dev_list.setEnabled(False)
  888. self.pvh_dont_support_devs.setVisible(True)
  889. else:
  890. self.dev_list.setEnabled(True)
  891. self.pvh_dont_support_devs.setVisible(False)
  892. def define_strict_reset_devices(self):
  893. for assignment in self.vm.devices['pci'].assignments():
  894. if assignment.options.get('no-strict-reset', False):
  895. self.current_strict_reset_list.append(
  896. assignment.ident.replace('_', ':'))
  897. self.new_strict_reset_list = self.current_strict_reset_list.copy()
  898. def strict_reset_button_pressed(self):
  899. device_list_window = device_list.PCIDeviceListWindow(
  900. self.vm, self.qapp, self.dev_list, self.new_strict_reset_list, self)
  901. device_list_window.exec()
  902. ######## applications tab
  903. def refresh_apps_button_pressed(self):
  904. self.refresh_apps_button.setEnabled(False)
  905. self.refresh_apps_button.setText(self.tr('Refresh in progress...'))
  906. thread = RefreshAppsVMThread(self.vm, self.refresh_apps_button)
  907. thread.finished.connect(self.clear_threads)
  908. thread.finished.connect(self.refresh_finished)
  909. self.threads_list.append(thread)
  910. thread.start()
  911. def refresh_finished(self):
  912. self.app_list_manager = AppmenuSelectManager(self.vm, self.app_list)
  913. self.refresh_apps_button.setEnabled(True)
  914. self.refresh_apps_button.setText(self.tr('Refresh Applications'))
  915. def template_apps_change(self):
  916. if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
  917. self.app_list_manager.fill_apps_list(
  918. template=self.template_list[self.template_name.currentIndex()])
  919. # add a label to show
  920. self.warn_template_missing_apps.setVisible(
  921. self.app_list_manager.has_missing)
  922. ######## services tab
  923. def __init_services_tab__(self):
  924. self.new_srv_dict = {}
  925. for feature in self.vm.features:
  926. if not feature.startswith('service.'):
  927. continue
  928. service = feature[len('service.'):]
  929. item = QtWidgets.QListWidgetItem(service)
  930. item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked
  931. if self.vm.features[feature]
  932. else ui_settingsdlg.QtCore.Qt.Unchecked)
  933. self.services_list.addItem(item)
  934. self.new_srv_dict[service] = self.vm.features[feature]
  935. self.service_line_edit.addItem("")
  936. supported_services = set()
  937. service_prefix = "supported-service."
  938. for feature in self.vm.features:
  939. if feature.startswith(service_prefix):
  940. supported_services.add(feature[len(service_prefix):])
  941. if getattr(self.vm, "template", None):
  942. for feature in self.vm.template.features:
  943. if feature.startswith(service_prefix):
  944. supported_services.add(feature[len(service_prefix):])
  945. for service in sorted(supported_services):
  946. self.service_line_edit.addItem(service)
  947. self.service_line_edit.addItem(self.tr('(custom...)'))
  948. self.service_line_edit.setEditText("")
  949. def __add_service__(self):
  950. srv = str(self.service_line_edit.currentText()).strip()
  951. if srv != "":
  952. if self.service_line_edit.currentIndex() == \
  953. len(self.service_line_edit) - 1:
  954. (custom_name, ok) = QtWidgets.QInputDialog.getText(
  955. self, self.tr("Custom service name"),
  956. self.tr(
  957. "Name of the service:"))
  958. if ok:
  959. srv = custom_name.strip()
  960. else:
  961. return
  962. if srv in self.new_srv_dict:
  963. QtWidgets.QMessageBox.information(
  964. self,
  965. '',
  966. self.tr('Service already on the list!'))
  967. return
  968. item = QtWidgets.QListWidgetItem(srv)
  969. item.setCheckState(ui_settingsdlg.QtCore.Qt.Checked)
  970. self.services_list.addItem(item)
  971. self.new_srv_dict[srv] = True
  972. def __remove_service__(self):
  973. item = self.services_list.currentItem()
  974. if not item:
  975. return
  976. row = self.services_list.currentRow()
  977. item = self.services_list.takeItem(row)
  978. del self.new_srv_dict[str(item.text())]
  979. def __apply_services_tab__(self):
  980. msg = []
  981. try:
  982. for i in range(self.services_list.count()):
  983. item = self.services_list.item(i)
  984. self.new_srv_dict[str(item.text())] = \
  985. (item.checkState() == ui_settingsdlg.QtCore.Qt.Checked)
  986. for service, v in self.new_srv_dict.items():
  987. feature = 'service.' + service
  988. if v != self.vm.features.get(feature, object()):
  989. self.vm.features[feature] = v
  990. for feature in self.vm.features:
  991. if not feature.startswith('service.'):
  992. continue
  993. service = feature[len('service.'):]
  994. if service not in self.new_srv_dict:
  995. del self.vm.features[feature]
  996. except qubesadmin.exc.QubesException as ex:
  997. msg.append(str(ex))
  998. return msg
  999. ######### firewall tab related
  1000. def set_fw_model(self, model):
  1001. self.fw_model = model
  1002. self.rulesTreeView.setModel(model)
  1003. self.rulesTreeView.header().setSectionResizeMode(
  1004. QtWidgets.QHeaderView.ResizeToContents)
  1005. self.rulesTreeView.header().setSectionResizeMode(
  1006. 0, QtWidgets.QHeaderView.Stretch)
  1007. self.set_allow(model.allow)
  1008. if model.temp_full_access_expire_time:
  1009. self.temp_full_access.setChecked(True)
  1010. self.temp_full_access_time.setValue(
  1011. (model.temp_full_access_expire_time -
  1012. int(firewall.datetime.datetime.now().strftime("%s"))) / 60)
  1013. def disable_all_fw_conf(self):
  1014. self.firewall_modified_outside_label.setVisible(True)
  1015. self.policy_allow_radio_button.setEnabled(False)
  1016. self.policy_deny_radio_button.setEnabled(False)
  1017. self.rulesTreeView.setEnabled(False)
  1018. self.new_rule_button.setEnabled(False)
  1019. self.edit_rule_button.setEnabled(False)
  1020. self.delete_rule_button.setEnabled(False)
  1021. self.firewal_rules_label.setEnabled(False)
  1022. self.tempFullAccessWidget.setEnabled(False)
  1023. def set_allow(self, allow):
  1024. self.policy_allow_radio_button.setChecked(allow)
  1025. self.policy_deny_radio_button.setChecked(not allow)
  1026. self.policy_changed()
  1027. def policy_changed(self):
  1028. self.rulesTreeView.setEnabled(
  1029. self.policy_deny_radio_button.isChecked())
  1030. self.new_rule_button.setEnabled(
  1031. self.policy_deny_radio_button.isChecked())
  1032. self.edit_rule_button.setEnabled(
  1033. self.policy_deny_radio_button.isChecked())
  1034. self.delete_rule_button.setEnabled(
  1035. self.policy_deny_radio_button.isChecked())
  1036. self.firewal_rules_label.setEnabled(
  1037. self.policy_deny_radio_button.isChecked())
  1038. self.tempFullAccessWidget.setEnabled(
  1039. self.policy_deny_radio_button.isChecked())
  1040. def new_rule_button_pressed(self):
  1041. dialog = firewall.NewFwRuleDlg()
  1042. self.fw_model.run_rule_dialog(dialog)
  1043. def edit_rule_button_pressed(self):
  1044. selected = self.rulesTreeView.selectedIndexes()
  1045. if selected:
  1046. dialog = firewall.NewFwRuleDlg()
  1047. dialog.set_ok_state(True)
  1048. row = self.rulesTreeView.selectedIndexes().pop().row()
  1049. self.fw_model.populate_edit_dialog(dialog, row)
  1050. self.fw_model.run_rule_dialog(dialog, row)
  1051. def delete_rule_button_pressed(self):
  1052. for i in {index.row() for index
  1053. in self.rulesTreeView.selectedIndexes()}:
  1054. self.fw_model.remove_child(i)
  1055. parser = QubesArgumentParser(vmname_nargs=1)
  1056. parser.add_argument('--tab', metavar='TAB',
  1057. action='store',
  1058. choices=VMSettingsWindow.tabs_indices.keys())
  1059. parser.set_defaults(
  1060. tab='basic',
  1061. )
  1062. def main(args=None):
  1063. args = parser.parse_args(args)
  1064. vm = args.domains.pop()
  1065. utils.run_synchronous(functools.partial(VMSettingsWindow, vm, args.tab))
  1066. if __name__ == "__main__":
  1067. main()
  1068. # vim:sw=4:et: