Skip to content

Commit

Permalink
BackupConfig module Beta
Browse files Browse the repository at this point in the history
Beta version of the BackupConfig module.
Changes:
Added script that moves the uploaded backup archive from the UI to the
backups folder
Added the used scripts to the sudoers
Modified the info div to keep the list of actions performed. Now it
behaves somewhat like a log file

No known issues were found at this time.

If there are no issues reported with this module it will become final V
1.0
  • Loading branch information
c-tek committed Mar 25, 2016
1 parent 3346eab commit 0712634
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 12 deletions.
1 change: 1 addition & 0 deletions root/etc/e-smith/templates/etc/sudoers/20backup_config
Expand Up @@ -7,6 +7,7 @@
/sbin/e-smith/restore-config
/sbin/e-smith/delete-config
/sbin/e-smith/backup-config-rotate
/sbin/e-smith/upload-config
);
'';
}
53 changes: 53 additions & 0 deletions root/sbin/e-smith/upload-config
@@ -0,0 +1,53 @@
#! /usr/bin/perl -w
#
# Copyright (C) 2013 Nethesis S.r.l.
# http://www.nethesis.it - support@nethesis.it
#
# This script is part of NethServer.
#
# NethServer 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 3 of the License,
# or any later version.
#
# NethServer 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 NethServer. If not, see <http://www.gnu.org/licenses/>.
#

###
# must be added to sudo!
###

use strict;
use File::Copy;
use NethServer::BackupConfig;

my $bkp_file=$ARGV[0];
my $dest_bkp_file=$ARGV[1];

my $backup = new NethServer::BackupConfig();



if (not defined $bkp_file) { print "TMP backup file not specified \n"; exit 0; };

if ( ! -f $bkp_file ) {
print "Tmp Backup file not found! Or can't copy the tmp backup ".$bkp_file." \n";
exit 0;
} else {
copy($bkp_file, NethServer::BackupConfig::DESTINATION_DIR.$dest_bkp_file) or warn " Error copying ".$bkp_file." \n";
if ( ! -f $bkp_file ) { print "Can't create MD5 file for the backup ".$dest_bkp_file." \n"; exit 0; }
else {
exec "/usr/libexec/nethserver/backup-config-md5 ".NethServer::BackupConfig::DESTINATION_DIR.$dest_bkp_file;
};


};


exit 0;
Expand Up @@ -219,11 +219,18 @@
}
#debug_div{
width:99%;
height:150px;
float:left;
padding:0 5px 0 5px;
position:relative;
float:left;
overflow-y:auto;
}
/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
/* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */
");


Expand Down Expand Up @@ -337,7 +344,10 @@ function table_backup() {

// DEBUG //

echo '<div id="extra_module_warning" class="ui-state-highlight"><span class="fa fa-info-circle"> </span><span id="debug_div" ></span></div>';
echo '<div id="extra_module_warning" class="ui-state-highlight" style="height:162px;">
<span class="fa fa-info-circle"> </span>
<span id="debug_div"></span>
</div>';
// END DEBUG //

$view->includeJavascript("
Expand All @@ -346,8 +356,9 @@ function table_backup() {
function update_info(msj){
$('#debug_div').empty().html(msj);
$('#debug_div').append('</br>');
$('#debug_div').append(msj+'</br>');
$('#debug_div').animate({scrollTop: $('#debug_div').prop()}, 400);
}
Expand Down Expand Up @@ -596,8 +607,9 @@ function(event)
if (yes){
$.post( '/bkp_jlib_ajax.php', {act:'delete_backup', p1:fname}, function(delete_data)
{
update_table();
update_info(delete_data);
update_table();
});
}
Expand Down
25 changes: 20 additions & 5 deletions root/usr/share/nethesis/nethserver-manager/bkp_jlib_ajax.php
Expand Up @@ -239,22 +239,37 @@ function restore_backup($backup_file) {
function upload_backup(){
if(isset($_POST['submit_file']))
{
$out=array();
$err=array();

$check=get_file_extension($_FILES['upload_file']['name']);
if ( $check == "xz") {
$uploadfile=$_FILES["upload_file"]["tmp_name"];
$target= $_SERVER['DOCUMENT_ROOT'] . "/backup/" . basename($_FILES["upload_file"]["name"]);
move_uploaded_file($uploadfile, $target);
return 'Success: '.$_FILES["upload_file"]["name"].' uploaded';

$target=sanitize($_FILES['upload_file']['name']);


if (file_exists('/../../../..'.$uploadfile)){
$command='/usr/bin/sudo /sbin/e-smith/upload-config '.$uploadfile.' '.$target;
$rezult = exec($command, $out, $err);
$msj = 'Completed: Backup '.$_FILES["upload_file"]["name"].' uploaded <br/> '.print_r($out).' <br/>'.print_r($err);

} else
{
$msj = "Error: TEMP File not found !". '/../../../..'.$uploadfile;
};

}
else {
return "Error: Filetype not allowed (".$check.")";
$msj = "Error: Filetype not allowed (".$check.")";
};


}else {
return "Error: Not posible to upload file";
$msj = "Error: Not posible to upload file";
};

return $msj;
};


Expand Down

0 comments on commit 0712634

Please sign in to comment.