Commit 90950d01 authored by Efthymia Bika's avatar Efthymia Bika Committed by Giorgos Korfiatis

Refactor backup, restore and timeview sections

Also escape and quote various arguments
parent 8a3861c8
......@@ -74,86 +74,61 @@ function parse_cloud_error(restore, stderr, backup) {
return false;
}
function build_extra_args(field_value, type) {
var args = field_value.split(",");
var result = "";
$.each(args, function(i, value) {
if(process.platform == 'win32') {
var args = ["-c", "usr/bin/cygpath " + escape_quote_str(value)];
execFile(CYGWIN_BASH, args,
function(error, stdout, stderr) {
toggle_error(error, stderr);
var win_value = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
result += " --" + type + " " + escape_quote_str(win_value) + " ";
});
} else {
result += " --" + type + " " + escape_quote_str(value.trim()) + " ";
}
});
return result;
}
function run_duplicity(restore, force) {
var container_name = "";
if(restore) {
container_name = $("#res-backup-name").val();
} else {
container_name = $("#backup-name").val();
}
var cloud = "";
if(restore) {
cloud = $("#res-cloud").val();
} else {
cloud = $("#cloud").val();
}
if(!restore) {
backups[cloud + "/" + container_name].last_status = "Running";
}
var time_arg = "";
var file_arg = "";
if(restore) {
var file_to_restore = $("#res-file").val();
if(file_to_restore) {
file_arg = " --file-to-restore '" + file_to_restore + "' ";
}
}
var file_to_restore = $("#res-file").val();
var exclude_arg = "";
var include_arg = "";
var type_arg = "";
var time_arg = "";
if(restore) {
container_name = $("#res-backup-name").val();
cloud = $("#res-cloud").val();
var timestamp = $("#timestamp").val();
if(timestamp) {
time_arg = " --time " + timestamp;
}
}
var type_arg = "";
if(!restore) {
var backup_type = $("input[name=backup-type]:checked").val();
type_arg = " " + backup_type + " ";
}
var exclude_arg = "";
if(!restore) {
if(file_to_restore) {
file_arg = " --file-to-restore " + escape_quote_str(file_to_restore) + " ";
}
} else {
container_name = $("#backup-name").val();
cloud = $("#cloud").val();
var exclude = $("#exclude").val();
if(exclude) {
var args = exclude.split(",");
$.each(args, function(i, value) {
if(process.platform == 'win32') {
exec(CYGWIN_BASH + " -c \"/usr/bin/cygpath '" + value + "' \"",
function(error, stdout, stderr) {
toggle_error(error, stderr);
var win_value = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
exclude_arg += " --exclude '" + win_value + "' ";
});
} else {
exclude_arg += " --exclude '" + value + "' ";
}
});
exclude_arg = build_extra_args(exclude, "exclude");
}
}
var include_arg = "";
if(!restore) {
var include = $("#include").val();
if(include) {
var args = include.split(",");
$.each(args, function(i, value) {
if(process.platform == 'win32') {
exec(CYGWIN_BASH + " -c \"/usr/bin/cygpath '" + value + "' \"",
function(error, stdout, stderr) {
toggle_error(error, stderr);
var win_value = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
include_arg += " --include '" + win_value + "' ";
});
} else {
include_arg += " --include '" + value + "' ";
}
});
include_arg = build_extra_args(include, "include");
}
var backup_type = $("input[name=backup-type]:checked").val();
type_arg = " " + backup_type + " ";
backups[cloud + "/" + container_name].last_status = "Running";
}
var directory = "";
......@@ -253,9 +228,9 @@ function run_duplicity(restore, force) {
directory = String(stdout).replace(/(\r\n|\n|\r)/gm, "");
toggle_error(error, stderr);
var dirs = "'" + directory + "' swift://" + container_name;
var dirs = escape_quote_str(directory) + " swift://" + container_name;
if(restore) {
dirs = " swift://" + container_name + " '" + directory + "'";
dirs = " swift://" + container_name + " " + escape_quote_str(directory);
}
var cmd = build_win_commands();
var dup_cmd = DUPLICITY_PATH + " " + type_arg + force_arg + exclude_device_files_arg
......@@ -267,9 +242,9 @@ function run_duplicity(restore, force) {
} else {
set_envs();
var dirs = "'" + directory + "' swift://" + container_name;
var dirs = escape_quote_str(directory) + " swift://" + container_name;
if(restore) {
dirs = " swift://" + container_name + " '" + directory + "'";
dirs = " swift://" + container_name + " " + escape_quote_str(directory);
}
var dup_cmd = DUPLICITY_PATH + " " + type_arg + force_arg + exclude_device_files_arg +
dup_verbosity + log_arg + include_arg + exclude_arg + file_arg + time_arg + dirs + ";";
......
......@@ -25,6 +25,11 @@ function go_to_restore_single(name) {
$("#restore-tab-link").trigger("click");
}
function escape_illegal_chars(s) {
if(!s) return "";
return s.replace(/("|'|;|{|}|\\|\.|:|\[|\]|,)/g, "\\$1");
}
function show_contents_by_date(error, stdout, stderr) {
toggle_error(error, stderr);
$("#time-contents").empty();
......@@ -34,7 +39,7 @@ function show_contents_by_date(error, stdout, stderr) {
.attr("id", "timeview-contents-list");
var contents = JSON.parse(stdout);
$.each(contents, function(i, el) {
var f = "open_folder('" + el.name + "')";
var f = "open_folder('" + escape_illegal_chars(el.name) + "')";
var restore_f = "show_rest_icon('" + i + "')";
var title = (el.name.length > 30) ? el.name : "";
var el_link = $("<a></a>")
......@@ -60,7 +65,7 @@ function show_contents_by_date(error, stdout, stderr) {
.attr("id", "rest_icon_" + i)
.attr("title", "Restore")
.attr("class", "hide")
.attr("onclick", "go_to_restore_single('" + el.name + "')");
.attr("onclick", "go_to_restore_single('" + escape_illegal_chars(el.name) + "')");
li.append(icon);
li.append(rest_icon);
......@@ -114,7 +119,7 @@ function fill_breadcrumbs(path) {
}
var a_crumb = $("<a>" + value + "</a>")
.attr("href", "#")
.attr("onclick", "go_to_path('" + cur_path + "')");
.attr("onclick", "go_to_path('" + escape_illegal_chars(cur_path) + "')");
li_crumb.append(a_crumb);
$(".breadcrumbs").append(li_crumb);
});
......@@ -124,10 +129,10 @@ var selected_date = "";
function get_contents_by_date(value) {
$("#loader").show();
if(selected_date) {
$("#" + selected_date.replace( /(:|\.|\[|\]|,)/g, "\\$1" )).
$("#" + escape_illegal_chars(selected_date)).
removeClass("active-li");
}
$("#" + value.replace( /(:|\.|\[|\]|,)/g, "\\$1" )).
$("#" + escape_illegal_chars(value)).
addClass("active-li");
var time_path = $("#time-path").val();
if(!time_path) {
......@@ -148,7 +153,7 @@ function get_contents_by_date(value) {
var datapath = path.join(BAAS_CACHE_DIR, 'timeviews');
var time_cmd = "python " + TIMEVIEW_PATH + " " + datapath + " swift://" +
container + " get " + value + " '" + time_path + "'"
container + " get " + value + " " + escape_quote_str(time_path);
if(process.platform == 'win32') {
var cmd = build_win_commands();
var args = ["-c", cmd + time_cmd];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment