Password protected backup restore to luci2 and web gui.

This commit is contained in:
Martin Schröder 2015-04-16 13:24:48 +02:00 committed by Martin Schröder
parent 501bd3f487
commit 9868ae47e5
5 changed files with 66 additions and 32 deletions

View file

@ -20,7 +20,8 @@ L.ui.view.extend({
restoreBackup: L.rpc.declare({
object: 'luci2.system',
method: 'backup_restore'
method: 'backup_restore',
params: [ 'password' ]
}),
cleanBackup: L.rpc.declare({
@ -149,10 +150,13 @@ L.ui.view.extend({
.append(info.checksum))
.append($('<li />')
.append($('<strong />').text(L.tr('Size') + ': '))
.append('%1024mB'.format(info.size)))
.append('%1024mB'.format(info.size))),
$('<label/>').text(L.tr("Password") + ": ")
.append($("<input class='form-element' type='password' id='backup_password'/>"))
], {
style: 'confirm',
confirm: function() {
self.backup_password = $('#backup_password').val();
self.handleBackupRestore();
}
}
@ -161,7 +165,7 @@ L.ui.view.extend({
handleBackupRestore: function() {
var self = this;
self.restoreBackup().then(function(res) {
self.restoreBackup(self.backup_password).then(function(res) {
if (res.code == 0)
{
L.ui.dialog(

View file

@ -582,7 +582,7 @@ main_backup(int argc, char **argv)
char datestr[16] = { 0 };
char hostname[64] = { 0 };
char *fields[] = { "sessionid", NULL };
if (!postdecode(fields, 1) || !session_access(fields[1], "backup", "read"))
return failure(0, "Backup permission denied");

View file

@ -83,6 +83,15 @@ static const struct blobmsg_policy rpc_data_policy[__RPC_D_MAX] = {
[RPC_D_DATA] = { .name = "data", .type = BLOBMSG_TYPE_STRING },
};
enum {
RPC_BACKUP_PASSWORD,
__RPC_BACKUP_MAX
};
static const struct blobmsg_policy rpc_backup_policy[__RPC_BACKUP_MAX] = {
[RPC_BACKUP_PASSWORD] = { .name = "password", .type = BLOBMSG_TYPE_STRING },
};
enum {
RPC_K_KEYS,
__RPC_K_MAX
@ -1014,8 +1023,22 @@ rpc_luci2_backup_restore(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
const char *cmd[4] = { "sysupgrade", "--restore-backup",
"/tmp/backup.tar.gz", NULL };
struct blob_attr *tb[__RPC_BACKUP_MAX];
blobmsg_parse(rpc_backup_policy, __RPC_BACKUP_MAX, tb,
blob_data(msg), blob_len(msg));
struct blob_attr *pass = tb[RPC_BACKUP_PASSWORD];
if (pass && blobmsg_data_len(pass) > 0 && blobmsg_data(pass) && strlen(blobmsg_data(pass)) > 0){
const char *cmd[] = { "sysupgrade", "--restore-backup",
"/tmp/backup.tar.gz", "--password", blobmsg_data(pass), NULL };
return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req);
}
const char *cmd[] = { "sysupgrade", "--restore-backup",
"/tmp/backup.tar.gz", NULL };
return ops->exec(cmd, NULL, NULL, NULL, NULL, NULL, ctx, req);
}
@ -2777,7 +2800,8 @@ rpc_luci2_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx)
UBUS_METHOD("upgrade_start", rpc_luci2_upgrade_start,
rpc_upgrade_policy),
UBUS_METHOD_NOARG("upgrade_clean", rpc_luci2_upgrade_clean),
UBUS_METHOD_NOARG("backup_restore", rpc_luci2_backup_restore),
UBUS_METHOD("backup_restore", rpc_luci2_backup_restore,
rpc_backup_policy),
UBUS_METHOD_NOARG("backup_clean", rpc_luci2_backup_clean),
UBUS_METHOD_NOARG("backup_config_get", rpc_luci2_backup_config_get),
UBUS_METHOD("backup_config_set", rpc_luci2_backup_config_set,

View file

@ -1,20 +1,23 @@
/*
* dslstats.c - Quest U-bus daemon IOPSYS
* dslstats -- collects adsl information for questd
*
* Author: Martin K. Schröder, martin.schroder@inteno.se
* Copyright (C) 2012-2013 Inteno Broadband Technology AB. All rights reserved.
*
* Copyright © 2004-2007 Rémi Denis-Courmont.
* This program is free software: you can redistribute and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, versions 2 of the license.
* Author: martin.schroder@inteno.se
*
* 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.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* 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 St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "questd.h"
@ -48,10 +51,10 @@ void dslstats_load(struct dsl_stats *self){
if(!(fp = popen("xdslctl info --stats", "r"))) return;
while(!done && fgets(line, sizeof(line), fp) != NULL) {
DSLDEBUG("LINE: %d, %s, args:%d\n", strlen(line), line, narg);
name[0] = 0; arg1[0] = 0; arg2[0] = 0;
remove_newline(line);
int narg = sscanf(line, "%[^\t]%[\t ]%[^\t]%[\t]%[^\t]", name, sep, arg1, sep, arg2);
//DSLDEBUG("LINE: %s, args:%d\n", line, narg);
switch(narg){
case 0: { // sections
if(strstr(line, "Bearer")){

View file

@ -1,20 +1,23 @@
/*
* dslstats.c - Quest U-bus daemon IOPSYS
* dslstats -- collects adsl information for questd
*
* Author: Martin K. Schröder, martin.schroder@inteno.se
* Copyright (C) 2012-2013 Inteno Broadband Technology AB. All rights reserved.
*
* Copyright © 2004-2007 Rémi Denis-Courmont.
* This program is free software: you can redistribute and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, versions 2 of the license.
* Author: martin.schroder@inteno.se
*
* 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.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* 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 St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#pragma once