2013-01-23 15:55:14 +01:00
|
|
|
#!/usr/bin/python2
|
2012-02-22 06:09:25 +01:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
#
|
2014-01-13 05:20:54 +01:00
|
|
|
import re
|
2012-02-22 06:09:25 +01:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import time
|
2014-01-13 05:19:06 +01:00
|
|
|
from qubes.qubes import QubesException
|
2012-02-22 06:09:25 +01:00
|
|
|
|
|
|
|
from thread_monitor import *
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from string import replace
|
|
|
|
|
2014-01-13 05:20:54 +01:00
|
|
|
path_re = re.compile(r"[a-zA-Z0-9/:.,_+=() -]*")
|
|
|
|
path_max_len = 512
|
2014-01-12 05:42:19 +01:00
|
|
|
|
2013-09-27 09:19:38 +02:00
|
|
|
def fill_appvms_list(dialog):
|
|
|
|
dialog.appvm_combobox.clear()
|
2013-11-28 03:52:02 +01:00
|
|
|
dialog.appvm_combobox.addItem("dom0")
|
2013-09-27 09:19:38 +02:00
|
|
|
|
|
|
|
dialog.appvm_combobox.setCurrentIndex(0) #current selected is null ""
|
2013-11-28 03:45:22 +01:00
|
|
|
|
2013-09-27 09:19:38 +02:00
|
|
|
for vm in dialog.qvm_collection.values():
|
|
|
|
if vm.is_appvm() and vm.internal:
|
|
|
|
continue
|
|
|
|
if vm.is_template() and vm.installed_by_rpm:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if vm.is_running() and vm.qid != 0:
|
|
|
|
dialog.appvm_combobox.addItem(vm.name)
|
2012-02-22 06:09:25 +01:00
|
|
|
|
|
|
|
def enable_dir_line_edit(dialog, boolean):
|
|
|
|
dialog.dir_line_edit.setEnabled(boolean)
|
2013-11-28 03:45:22 +01:00
|
|
|
dialog.select_path_button.setEnabled(boolean)
|
2012-02-22 06:09:25 +01:00
|
|
|
|
2014-01-13 05:20:54 +01:00
|
|
|
def get_path_for_vm(vm, service_name):
|
|
|
|
if not vm:
|
|
|
|
return None
|
|
|
|
proc = vm.run("QUBESRPC %s dom0" % service_name, passio_popen=True)
|
|
|
|
proc.stdin.close()
|
|
|
|
untrusted_path = proc.stdout.readline(path_max_len)
|
|
|
|
if len(untrusted_path) == 0:
|
|
|
|
return None
|
|
|
|
if path_re.match(untrusted_path):
|
2014-05-19 15:41:37 +02:00
|
|
|
assert '../' not in untrusted_path
|
|
|
|
assert '\0' not in untrusted_path
|
2014-02-17 00:12:28 +01:00
|
|
|
return untrusted_path.strip()
|
2014-01-13 05:20:54 +01:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2013-11-28 03:50:17 +01:00
|
|
|
def select_path_button_clicked(dialog, select_file = False):
|
2014-01-11 22:57:34 +01:00
|
|
|
backup_location = str(dialog.dir_line_edit.text())
|
2012-02-22 06:09:25 +01:00
|
|
|
file_dialog = QFileDialog()
|
|
|
|
file_dialog.setReadOnly(True)
|
2012-03-02 02:50:12 +01:00
|
|
|
|
2013-11-28 03:50:17 +01:00
|
|
|
if select_file:
|
|
|
|
file_dialog_function = file_dialog.getOpenFileName
|
|
|
|
else:
|
|
|
|
file_dialog_function = file_dialog.getExistingDirectory
|
|
|
|
|
2013-09-27 09:19:38 +02:00
|
|
|
new_appvm = None
|
|
|
|
new_path = None
|
2013-11-28 03:50:17 +01:00
|
|
|
if dialog.appvm_combobox.currentIndex() != 0: #An existing appvm chosen
|
2013-09-27 09:19:38 +02:00
|
|
|
new_appvm = str(dialog.appvm_combobox.currentText())
|
2014-01-13 05:20:54 +01:00
|
|
|
vm = dialog.qvm_collection.get_vm_by_name(new_appvm)
|
|
|
|
if vm:
|
|
|
|
new_path = get_path_for_vm(vm, "qubes.SelectFile" if select_file
|
|
|
|
else "qubes.SelectDirectory")
|
2012-03-02 02:50:12 +01:00
|
|
|
else:
|
2017-01-22 05:42:38 +01:00
|
|
|
new_path = file_dialog_function(dialog,
|
|
|
|
dialog.tr("Select backup location."),
|
|
|
|
backup_location if backup_location else '/')
|
2013-11-28 03:50:17 +01:00
|
|
|
|
2013-09-27 09:19:38 +02:00
|
|
|
if new_path != None:
|
2014-02-05 06:54:22 +01:00
|
|
|
new_path = unicode(new_path)
|
2013-12-29 04:31:20 +01:00
|
|
|
if os.path.basename(new_path) == 'qubes.xml':
|
2014-01-11 22:57:34 +01:00
|
|
|
backup_location = os.path.dirname(new_path)
|
2013-12-29 04:31:20 +01:00
|
|
|
else:
|
2014-01-11 22:57:34 +01:00
|
|
|
backup_location = new_path
|
|
|
|
dialog.dir_line_edit.setText(backup_location)
|
2012-02-22 06:09:25 +01:00
|
|
|
|
2014-01-11 22:57:34 +01:00
|
|
|
if (new_path or new_appvm) and len(backup_location) > 0:
|
2013-09-27 09:19:38 +02:00
|
|
|
dialog.select_dir_page.emit(SIGNAL("completeChanged()"))
|
2012-02-22 06:09:25 +01:00
|
|
|
|
|
|
|
def simulate_long_lasting_proces(period, progress_callback):
|
|
|
|
for i in range(period):
|
|
|
|
progress_callback((i*100)/period)
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
progress_callback(100)
|
2015-03-31 05:40:53 +02:00
|
|
|
return 0
|