2017-09-08 22:43:43 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
2017-11-06 21:06:30 +01:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
2017-09-08 22:43:43 +02:00
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2017-11-06 22:46:35 +01:00
|
|
|
import sys
|
2017-09-08 22:43:43 +02:00
|
|
|
import subprocess
|
|
|
|
from . import utils
|
2017-11-14 15:29:57 +01:00
|
|
|
from . import ui_bootfromdevice # pylint: disable=no-name-in-module
|
|
|
|
from PyQt4 import QtGui, QtCore # pylint: disable=import-error
|
2017-11-17 17:34:38 +01:00
|
|
|
from qubesadmin import tools
|
2018-01-08 20:00:55 +01:00
|
|
|
from qubesadmin.tools import qvm_start
|
2017-09-08 22:43:43 +02:00
|
|
|
|
|
|
|
|
2017-11-06 22:46:35 +01:00
|
|
|
class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog, QtGui.QDialog):
|
2017-09-08 22:43:43 +02:00
|
|
|
def __init__(self, vm, qapp, parent=None):
|
|
|
|
super(VMBootFromDeviceWindow, self).__init__(parent)
|
|
|
|
|
|
|
|
self.vm = vm
|
|
|
|
self.qapp = qapp
|
|
|
|
|
|
|
|
self.setupUi(self)
|
2017-11-06 23:18:18 +01:00
|
|
|
self.setWindowTitle(
|
|
|
|
self.tr("Boot {vm} from device").format(vm=self.vm.name))
|
2017-09-08 22:43:43 +02:00
|
|
|
|
2017-11-06 23:18:18 +01:00
|
|
|
self.connect(
|
|
|
|
self.buttonBox,
|
|
|
|
QtCore.SIGNAL("accepted()"),
|
|
|
|
self.save_and_apply)
|
2017-11-06 22:46:35 +01:00
|
|
|
self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
|
2017-09-08 22:43:43 +02:00
|
|
|
|
|
|
|
# populate buttons and such
|
|
|
|
self.__init_buttons__()
|
2018-01-08 20:05:25 +01:00
|
|
|
# warn user if the VM is currently running
|
|
|
|
self.__warn_if_running__()
|
2017-09-08 22:43:43 +02:00
|
|
|
|
|
|
|
def reject(self):
|
|
|
|
self.done(0)
|
|
|
|
|
|
|
|
def save_and_apply(self):
|
|
|
|
if self.blockDeviceRadioButton.isChecked():
|
|
|
|
cdrom_location = self.blockDeviceComboBox.currentText()
|
|
|
|
elif self.fileRadioButton.isChecked():
|
2017-11-06 23:18:18 +01:00
|
|
|
cdrom_location = str(
|
|
|
|
self.vm_list[self.fileVM.currentIndex()]) + \
|
|
|
|
":" + self.pathText.text()
|
2017-09-08 22:43:43 +02:00
|
|
|
else:
|
2017-11-06 23:18:18 +01:00
|
|
|
QtGui.QMessageBox.warning(
|
|
|
|
None,
|
|
|
|
self.tr("ERROR!"),
|
|
|
|
self.tr("No file or block device selected; please select one."))
|
2017-09-08 22:43:43 +02:00
|
|
|
return
|
2018-01-08 20:05:25 +01:00
|
|
|
|
|
|
|
# warn user if the VM is currently running
|
|
|
|
self.__warn_if_running__()
|
|
|
|
|
2018-01-08 20:00:55 +01:00
|
|
|
qvm_start.main(['--cdrom', cdrom_location, self.vm.name])
|
2017-09-08 22:43:43 +02:00
|
|
|
|
2018-01-08 20:05:25 +01:00
|
|
|
def __warn_if_running__(self):
|
|
|
|
if self.vm.is_running():
|
|
|
|
QtGui.QMessageBox.warning(
|
|
|
|
None,
|
|
|
|
self.tr("Warning!"),
|
2018-01-08 20:06:57 +01:00
|
|
|
self.tr("Qube must be turned off before booting it from"
|
|
|
|
"device. Please turn off the qube.")
|
2018-01-08 20:05:25 +01:00
|
|
|
)
|
|
|
|
|
2017-09-08 22:43:43 +02:00
|
|
|
def __init_buttons__(self):
|
|
|
|
self.fileVM.setEnabled(False)
|
|
|
|
self.selectFileButton.setEnabled(False)
|
|
|
|
self.blockDeviceComboBox.setEnabled(False)
|
|
|
|
|
|
|
|
self.blockDeviceRadioButton.clicked.connect(self.radio_button_clicked)
|
|
|
|
self.fileRadioButton.clicked.connect(self.radio_button_clicked)
|
|
|
|
self.selectFileButton.clicked.connect(self.select_file_dialog)
|
|
|
|
|
|
|
|
self.vm_list, self.vm_idx = utils.prepare_vm_choice(
|
|
|
|
self.fileVM,
|
|
|
|
self.vm, None,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
allow_default=False, allow_none=False)
|
|
|
|
|
|
|
|
self.block_list, self.block_idx = utils.prepare_choice(
|
|
|
|
self.blockDeviceComboBox,
|
|
|
|
self.vm,
|
|
|
|
None,
|
|
|
|
[device for domain in self.vm.app.domains
|
|
|
|
for device in domain.devices["block"]],
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
allow_default=False, allow_none=False
|
|
|
|
)
|
|
|
|
|
|
|
|
def radio_button_clicked(self):
|
2017-11-06 23:18:18 +01:00
|
|
|
self.blockDeviceComboBox.setEnabled(
|
|
|
|
self.blockDeviceRadioButton.isChecked())
|
2017-09-08 22:43:43 +02:00
|
|
|
self.fileVM.setEnabled(self.fileRadioButton.isChecked())
|
|
|
|
self.selectFileButton.setEnabled(self.fileRadioButton.isChecked())
|
|
|
|
self.pathText.setEnabled(self.fileRadioButton.isChecked())
|
|
|
|
|
|
|
|
def select_file_dialog(self):
|
|
|
|
backend_vm = self.vm_list[self.fileVM.currentIndex()]
|
|
|
|
|
|
|
|
try:
|
|
|
|
new_path = utils.get_path_from_vm(backend_vm, "qubes.SelectFile")
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
new_path = None
|
|
|
|
|
|
|
|
if new_path:
|
|
|
|
self.pathText.setText(new_path)
|
|
|
|
|
|
|
|
|
2017-11-17 17:34:38 +01:00
|
|
|
parser = tools.QubesArgumentParser(vmname_nargs=1)
|
2017-09-08 22:43:43 +02:00
|
|
|
|
2018-01-08 20:00:55 +01:00
|
|
|
|
2017-09-08 22:43:43 +02:00
|
|
|
def main(args=None):
|
|
|
|
args = parser.parse_args(args)
|
|
|
|
vm = args.domains.pop()
|
|
|
|
|
2017-11-06 22:46:35 +01:00
|
|
|
qapp = QtGui.QApplication(sys.argv)
|
2017-09-08 22:43:43 +02:00
|
|
|
qapp.setOrganizationName('Invisible Things Lab')
|
|
|
|
qapp.setOrganizationDomain("https://www.qubes-os.org/")
|
2018-01-08 20:06:57 +01:00
|
|
|
qapp.setApplicationName("Boot Qube From Device")
|
2017-09-08 22:43:43 +02:00
|
|
|
|
|
|
|
# if not utils.is_debug(): #FIXME
|
|
|
|
# sys.excepthook = handle_exception
|
|
|
|
|
|
|
|
bootfromdevice_window = VMBootFromDeviceWindow(vm, qapp)
|
|
|
|
bootfromdevice_window.show()
|
|
|
|
|
|
|
|
qapp.exec_()
|
|
|
|
qapp.exit()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|