diff -urN e-smith-backup-2.6.0.old/root/etc/e-smith/events/actions/workstation-backup-dar e-smith-backup-2.6.0/root/etc/e-smith/events/actions/workstation-backup-dar --- e-smith-backup-2.6.0.old/root/etc/e-smith/events/actions/workstation-backup-dar 2021-02-09 21:26:24.961634134 +0000 +++ e-smith-backup-2.6.0/root/etc/e-smith/events/actions/workstation-backup-dar 2021-02-09 21:29:49.256523741 +0000 @@ -31,6 +31,7 @@ use File::Glob qw(bsd_glob); use esmith::ConfigDB; use esmith::Backup; +use esmith::BlockDevices; sub ldie; sub start_dar_killer; @@ -312,77 +313,60 @@ return $code; } - +# Copied from /etc/e-smith/web/functions/backup +# TODO: Move to a shared module sub checkMount { # check if $mountdir is mounted my $mountdir = shift; $|=1; # Auto-flush - - # copy STDOUT to another filehandle - open (my $STDOLD, '>&', STDOUT); - - open(STDOUT, ">/dev/null"); - if ( open(MOUNTDIR, "|-", "/bin/findmnt", $mountdir)){;} - # restore STDOUT - open (STDOUT, '>&', $STDOLD); - - return (!close(MOUNTDIR)); + my @res = qx( findmnt $mountdir ); + return ( !@res ); } -# dmount is copied from /etc/e-smith/web/functions/backup -# it could become a common function later +# Copied from /etc/e-smith/web/functions/backup +# TODO: Move to a shared module sub dmount { # mount dar unit according to dar-workstation configuration # return nothing if mount successfull my ($host,$share,$mountdir,$login,$password,$VFSType) = @_; - + if ($VFSType eq 'cifs') { - return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); + return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); } elsif ($VFSType eq 'nfs') { - return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); + return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); } elsif ($VFSType eq 'usb') { my $device = ""; - my $blkdev = ""; my $vollbl = ""; - foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) - { - $udi =~ m/^(\S+)/; - my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - if ($is_mounted eq "false\n") - { - $blkdev = qx(hal-get-property --udi $1 --key block.device); - if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} - } - if ($is_mounted eq "false\n") - { - $vollbl = qx(hal-get-property --udi $1 --key volume.label); - $vollbl =~ m/^(\S+)/; - if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - } + my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + my ($valid, $invalid) = $devices->checkBackupDrives(0); - chomp $vollbl; - chomp $blkdev; - $vollbl = "media/$vollbl"; - if ($vollbl eq $share) {$device = $blkdev;} + if ( ${$valid}[0] ) { + foreach ( @{$valid} ) { + $vollbl = $devices->label($_); + if ( $share eq "media/$vollbl" ) { + $device = "/dev/$_"; + } + } } - return ( qx(/bin/mount $device "/$share" 2>&1) ); + $devices->destroy; + return ( qx (mount $device /$share 2>&1) ); } else { - return ("Mount of type $VFSType not supported.\n"); + return ("Error while mounting $host/$share : $VFSType not supported.\n"); } -} +} sub removeTree diff -urN e-smith-backup-2.6.0.old/root/etc/e-smith/web/functions/backup e-smith-backup-2.6.0/root/etc/e-smith/web/functions/backup --- e-smith-backup-2.6.0.old/root/etc/e-smith/web/functions/backup 2021-02-09 21:26:24.926635870 +0000 +++ e-smith-backup-2.6.0/root/etc/e-smith/web/functions/backup 2021-02-09 21:29:21.581890670 +0000 @@ -27,6 +27,7 @@ use esmith::ConfigDB; use esmith::Backup; use esmith::BackupHistoryDB; +use esmith::BlockDevices; use esmith::AccountsDB; use esmith::cgi; use esmith::util; @@ -697,9 +698,9 @@ if (defined $status && $status eq "on") { - #-------------------------------------------------- - # Untaint parameters and check for validity - #-------------------------------------------------- + #-------------------------------------------------- + # Untaint parameters and check for validity + #-------------------------------------------------- my $backupHour = $q->param ('backupHour'); if ($backupHour =~ /^(.*)$/) { @@ -1237,23 +1238,20 @@ $q, undef, $fm->localise('CONFIGURE_WORKSTN_BACKUP')); if ( $VFSType eq 'usb' ) { - foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { - $udi =~ m/^(\S+)/; + my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + my ($valid, $invalid) = $devices->checkBackupDrives(0); - my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - - if ($is_mounted eq "false\n") { - my $vollbl = qx(hal-get-property --udi $1 --key volume.label); - $vollbl =~ m/^(\S+)/; - if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - chomp $vollbl; - push @usbdisks, $vollbl; + if ( ${$valid}[0] ) { + foreach ( @{$valid} ) { + push @usbdisks, $devices->label($_); } } - unless ($usbdisks[0]){ + else + { push @usbdisks, $fm->localise('ERR_NO_USB_DISK'); $error='nousb'; } + $devices->destroy; } if ( $VFSType eq 'mnt' ) { @@ -1509,9 +1507,9 @@ return; } - #-------------------------------------------------- - # Untaint parameters and check for validity - #-------------------------------------------------- + #-------------------------------------------------- + # Untaint parameters and check for validity + #-------------------------------------------------- my $VFSType = $q->param ('VFSType'); if ( $VFSType eq 'nousb') @@ -3007,7 +3005,7 @@ my $dumpsize = 0; open(DF, "-|") - or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4'; + or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4', '-t', 'xfs'; while () { @@ -3034,7 +3032,7 @@ my $halffree = 0; open(DF, "-|") - or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4', '/tmp'; + or exec '/bin/df', '-P', '-t', 'ext3', '-t', 'ext4', '-t', 'xfs', '/tmp'; while () { @@ -3106,30 +3104,21 @@ elsif ($VFSType eq 'usb') { my $device = ""; - my $blkdev = ""; my $vollbl = ""; - foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { - $udi =~ m/^(\S+)/; - my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - - if ($is_mounted eq "false\n") { - $blkdev = qx(hal-get-property --udi $1 --key block.device); - if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} - } - if ($is_mounted eq "false\n") { - $vollbl = qx(hal-get-property --udi $1 --key volume.label); - $vollbl =~ m/^(\S+)/; - if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} - } - - chomp $vollbl; - chomp $blkdev; - $vollbl = "media/$vollbl"; - if ($vollbl eq $share) { - $device = $blkdev; - } + + my $devices = esmith::BlockDevices->new ('allowmount' => 'disabled'); + my ($valid, $invalid) = $devices->checkBackupDrives(0); + + if ( ${$valid}[0] ) { + foreach ( @{$valid} ) { + $vollbl = $devices->label($_); + if ( $share eq "media/$vollbl" ) { + $device = "/dev/$_"; + } + } } - return ( qx(/bin/mount $device "/$share" 2>&1) ); + $devices->destroy; + return ( qx (mount $device /$share 2>&1) ); } else { @@ -3142,17 +3131,9 @@ # check if $mountdir is mounted my $mountdir = shift; $|=1; # Auto-flush - - # copy STDOUT to another filehandle - open (my $STDOLD, '>&', STDOUT); - - open(STDOUT, ">/dev/null"); - if ( open(MOUNTDIR, "|-", "/bin/findmnt", $mountdir)){;} - - # restore STDOUT - open (STDOUT, '>&', $STDOLD); - - return (!close(MOUNTDIR)); + + my @res = qx( findmnt $mountdir ); + return ( !@res ); } sub bmount