diff -Nur -x '*.orig' -x '*.rej' e-smith-backup-1.15.0/root/etc/e-smith/events/actions/workstation-backup-dar mezzanine_patched_e-smith-backup-1.15.0/root/etc/e-smith/events/actions/workstation-backup-dar --- e-smith-backup-1.15.0/root/etc/e-smith/events/actions/workstation-backup-dar 2007-09-07 14:38:19.000000000 -0400 +++ mezzanine_patched_e-smith-backup-1.15.0/root/etc/e-smith/events/actions/workstation-backup-dar 2007-09-05 17:03:55.000000000 -0400 @@ -2,6 +2,7 @@ #---------------------------------------------------------------------- # copyright (C) 2006 Jean-Paul Leclere +# copyright (C) 2007 Charlie Brady # # 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 @@ -38,10 +39,16 @@ my $tm = localtime(time); my $bkname = $tm->year+1900; - if (($tm->mon) < 9) {$bkname .= ("0".($tm->mon+1))} else {$bkname .= ($tm->mon+1)} - if (($tm->mday) < 10) {$bkname .= ("0".$tm->mday)} else {$bkname .= $tm->mday} + +$bkname .= "0" if ($tm->mon < 9); +$bkname .= $tm->mon + 1; + +$bkname .= "0" if ($tm->mday < 10); +$bkname .= $tm->mday; + my $dow = $tm->wday; -my $id = $backupwk->prop('Id') || $confdb->get('SystemName')->value . "." . $confdb->get('DomainName')->value; +my $id = $backupwk->prop('Id') || + $confdb->get('SystemName')->value . "." . $confdb->get('DomainName')->value; my $err; my $ref = ""; my $mntdone = 0; @@ -77,42 +84,58 @@ # verify backup directory not already mounted -if ( $VFSType ne 'usb' ) { +if ( $VFSType eq 'usb' ) +{ + $mntdir = "/$smbshare"; +} +else +{ open FD, '/proc/mounts'; - while () { + while () + { next unless /$smbhost(.*)\/$smbshare/; next unless /$mntdir/; $err++ - } + } close FD; - if ($err) { - ldie("Seems backup directory is already mounted. It should not happen \ -and maybe there is a zombie process you must kill, or another backup in progress. \n") - } - if ($VFSType eq 'cifs'){ - $err = qx(/bin/mount -t cifs $smbhost:$smbshare $mntdir -o user=$login,pass=$password); - if ($err) {ldie("Error while mounting $smbhost:$smbshare : \n" . $err)}; - } - elsif ($VFSType eq 'smbfs'){ - $err = qx(/bin/mount -t smbfs //$smbhost/$smbshare $mntdir -o username=$login,password=$password,dmask=777,fmask=777,ip=$smbhost 2>&1); - if ($err) {ldie("Error while mounting //$smbhost/$smbshare : \n" . $err)}; - } - elsif ($VFSType eq 'nfs'){ + if ($err) + { + ldie("Seems backup directory is already mounted. " . + "It should not happen and maybe there is a zombie process " . + "you must kill, or another backup in progress. \n"); + } + if ($VFSType eq 'cifs') + { + $err = qx(/bin/mount -t cifs $smbhost:$smbshare $mntdir -o user=$login,pass=$password 2>&1); + ldie("Error while mounting $smbhost:$smbshare : \n" . $err) if $err; + } + elsif ($VFSType eq 'smbfs') + { + $err = + qx(/bin/mount -t smbfs //$smbhost/$smbshare $mntdir + -o username=$login,password=$password,dmask=777,fmask=777,ip=$smbhost 2>&1); + ldie("Error while mounting //$smbhost/$smbshare : \n" . $err) if $err; + } + elsif ($VFSType eq 'nfs') + { $err = qx(/bin/mount -t nfs -o nolock $smbhost:/$smbshare $mntdir 2>&1); - if ($err) {ldie("Error while mounting $smbhost:/$smbshare : \n" . $err)}; - } - else {ldie("Error while mounting $smbhost/$smbshare : $VFSType not supported.\n")} - - $mntdone = 1; + ldie("Error while mounting $smbhost:/$smbshare : \n" . $err) if $err; + } + else + { + ldie("Error while mounting $smbhost/$smbshare : $VFSType not supported.\n"); } -else { $mntdir = "/".$smbshare } + $mntdone = 1; +} -if (-d "$tmpdir/$id") { +if (-d "$tmpdir/$id") +{ eval {rmtree("$tmpdir/$id")}; - if ($@) {ldie("Error while deleting $tmpdir/$id : $@.\n")} - } + ldie("Error while deleting $tmpdir/$id : $@.\n") if $@; +} eval {mkpath("$tmpdir/$id")}; -if ($@) {ldie("Error while creating $tmpdir/$id : $@. Maybe insufficient rights on backup directory.\n")} +ldie("Error while creating $tmpdir/$id : $@. Maybe insufficient rights on backup directory.\n") + if $@; # we know right backup directory is in line and we can write on it. $report .= "Backup temp directory $tmpdir/$id is mounted and is writable \n"; @@ -121,63 +144,69 @@ ++$incnum; $incnum %= $daysinset; -if ( $incnum == 0 ) { +if ($incnum == 0) +{ ++$setnum; $setnum %= $setsmax; - } +} $report .= "Using set number $setnum of $setsmax\n"; -if ($incnum == 0) { - $report .= "Attempt to full backup \n"; - } -else { - $report .= "Attempt to incremental backup number $incnum of $daysinset\n"; - } +$report .= "Attempt to " . + ($incnum == 0) ? + "full backup \n" : + "incremental backup number $incnum of $daysinset\n"; # if no set directory, make it - my $setname = "set" . $setnum; my $setdirname = $mntdir . "/$id/" . $setname; -unless ( -d $setdirname ) { +unless ( -d $setdirname ) +{ eval {mkpath($setdirname)}; - if ($@) {ldie("Can't create $setdirname : $@.\n")} + ldie("Can't create $setdirname : $@.\n") if $@; $report .= "Backup directory $id/$setname created \n"; - } +} -# if $incnum <> 0 backup should be incremental -# we find correct reference backup for incremental - -if ( $incnum != 0 ) { +if ( $incnum == 0 ) +{ + $bkname = "full-" . $bkname; +} +else +{ + # if $incnum <> 0 backup should be incremental + # we find correct reference backup for incremental my $file; opendir(DIR, $setdirname) or ldie("Can't open dir $setdirname $!"); - while (defined($file = readdir(DIR))) { + while (defined($file = readdir(DIR))) + { next if $file =~ /^\.\.?$/; - if ( $file =~ /dar$/) { + if ($file =~ /dar$/) + { $ref = $file; - } } + } closedir (DIR); # if no reference do full backup - if ($ref eq "") { + if ($ref eq "") + { $incnum = 0; $report .= "No existing reference backup, will make full backup \n"; $bkname = "full-" . $bkname; - } - else { # removing .dar extension + } + else + { + # removing .dar extension $ref =~ s/\..*\.dar$//; $ref = "--ref " . $setdirname . "/" . $ref; $bkname = "inc-" . sprintf("%03d", $incnum) . "-". $bkname; - } - } -else { - $bkname = "full-" . $bkname; } +} -unless ( ( $incnum != 0 ) || ( $fullday == 7 ) || ( $dow == $fullday ) ) { +unless ( ( $incnum != 0 ) || ( $fullday == 7 ) || ( $dow == $fullday ) ) +{ my $delay = ($fullday - $dow) % 7; ldie("Not a permitted day for full backup. Aborting...\nNext full backup in $delay days.\n"); - } +} $report .= "Backup base file name is $bkname \n"; $report .= "Making backup on temporary dir... \n"; @@ -185,9 +214,10 @@ # calculate real timeout if we timeout incrementals only. # timeout of 88500 is a security for aborting backup within 24h -if ( ($ref eq "") && ($inconly eq "yes")) { +if ( ($ref eq "") && ($inconly eq "yes")) +{ $timeout = 88500; - } +} $report .= "using a backup session timeout of : $timeout seconds\n"; # expanding backup configuration file template @@ -198,40 +228,52 @@ # launching dar backup -$err = system("/usr/bin/timeout -s TERM $timeout /usr/bin/dar -c $tmpdir/$id/$bkname $ref -B /etc/dar/$job.dcf"); +$err = system("/usr/bin/timeout", + "-s", + "TERM", + "$timeout", + "/usr/bin/dar", + "-c", + "$tmpdir/$id/$bkname", + "$ref", + "-B", + "/etc/dar/$job.dcf"); if ($err == 0) { -$report .= "Backup completed successfully on temporary dir \n"; + $report .= "Backup completed successfully on temporary dir \n"; } elsif ($err == 15) { -$report .= "Partial backup stored on temp dir.\n" - . " Session closed by timeout after $timeout seconds.\n" - . "Not an error, backup process will continue next night.\n"; + $report .= "Partial backup stored on temp dir.\n" + . " Session closed by timeout after $timeout seconds.\n" + . "Not an error, backup process will continue next night.\n"; } else { -$err = $err >> 8; -ldie("Dar error during backup : $err \n"); + $err = $err >> 8; + ldie("Dar error during backup : $err \n"); } -if ($incnum == 0) { +if ($incnum == 0) +{ $report .= "Rotating backups in a new set $setdirname. \n"; eval {rmtree($setdirname)}; - if ($@) {ldie("Error while deleting $setdirname : $@.\n")} + ldie("Error while deleting $setdirname : $@.\n") if $@; eval {mkpath("$setdirname")}; - if ($@) {ldie("Error while creating $setdirname : $@.\n")} - } + ldie("Error while creating $setdirname : $@.\n") if $@; +} + $report .= "Moving backup files to target directory $setdirname \n"; -foreach (<$tmpdir/$id/$bkname*>) { - unless ( move($_, $setdirname) ) - {ldie("Error while moving backup file $_ from temporary dir $tmpdir/$id to $setdirname : $!")}; - } -# unmount shared folder +foreach (<$tmpdir/$id/$bkname*>) +{ + ldie("Error while moving backup file $_ from temporary dir $tmpdir/$id to $setdirname : $!") + unless move($_, $setdirname); +} -if ( $VFSType ne 'usb' ) {system("/bin/umount -f $mntdir")} +# unmount shared folder +system("/bin/umount -f $mntdir") unless ($VFSType ne 'usb'); # time now to update backup configuration @@ -242,26 +284,28 @@ $tim = ctime(); $report .= "Backup successfully terminated at : $tim \n"; -if ($mail eq 'yes') { +if ($mail eq 'yes') +{ open (MAIL, "|/var/qmail/bin/qmail-inject -a admin") || die "Cannot start mail program: $!\n"; print MAIL $report; close(MAIL); - } +} exit (0); sub ldie { -my $errmsg = shift; -$report .= "*** No backup allowed or error during backup ***\n"; -$report .= $errmsg; -if (($mail eq 'yes') || ($mail eq 'error')) { - open (MAIL, "|/var/qmail/bin/qmail-inject -a admin") - || die "Cannot start mail program: $!\n"; - print MAIL $report; - close(MAIL); + my $errmsg = shift; + $report .= "*** No backup allowed or error during backup ***\n"; + $report .= $errmsg; + if (($mail eq 'yes') || ($mail eq 'error')) + { + open (MAIL, "|/var/qmail/bin/qmail-inject -a admin") + || die "Cannot start mail program: $!: message was $errmsg\n"; + print MAIL $report; + close(MAIL); } -if (($mntdone) && ($VFSType ne 'usb')) {system("/bin/umount $mntdir")}; -die($errmsg); + system("/bin/umount $mntdir") if $mntdone; + die($errmsg); } diff -Nur -x '*.orig' -x '*.rej' e-smith-backup-1.15.0/root/etc/e-smith/web/functions/backup mezzanine_patched_e-smith-backup-1.15.0/root/etc/e-smith/web/functions/backup --- e-smith-backup-1.15.0/root/etc/e-smith/web/functions/backup 2007-09-07 14:38:19.000000000 -0400 +++ mezzanine_patched_e-smith-backup-1.15.0/root/etc/e-smith/web/functions/backup 2007-09-07 14:37:54.000000000 -0400 @@ -2192,47 +2192,53 @@ my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb'; my $mounted; my $key; - my $id = $backupwkrec->prop('Id') || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; + my $id = $backupwkrec->prop('Id') || + $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; my $err; my $VFSType = $backupwkrec->prop('VFSType') || 'smbfs'; # Mounting backup shared folder - if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) ) - { + if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) + { esmith::cgi::genResult( $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err ); return; - } - elsif ( $VFSType ne 'usb' ) {$mounted = 1} + } + elsif ( $VFSType ne 'usb' ) + { + $mounted = 1; + } # Test if backup subdirectory for our server my $mntbkdir = $mntdir . "/$id"; - unless ( -d $mntbkdir) - { - if ($mounted) { + unless (-d $mntbkdir) + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } - esmith::cgi::genResult( - $q, $fm->localise('ERR_NO_HOST_DIR'.$id) - ); - return; } + esmith::cgi::genResult($q, $fm->localise('ERR_NO_HOST_DIR'.$id)); + return; + } my $backupkey = $q->param ('backupset'); - if ($backupkey =~ /^(.*)$/) { + if ($backupkey =~ /^(.*)$/) + { $backupkey = $1; - } - else { - if ($mounted) { + } + else + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } - die('Unsecure data : ' . $backupkey); } + die('Unsecure data : ' . $backupkey); + } if (open(RD, "-|")) { @@ -2300,14 +2306,16 @@ my $mounted; my %backupfiles = (); my $key; - my $id = $rec->prop('Id') || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; + my $id = $rec->prop('Id') || + $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; my $VFSType = $rec->prop('VFSType') || 'smbfs'; my $smbhost = $rec->prop('SmbHost'); my $smbshare = $rec->prop('SmbShare'); my $err; my $setbackupflist = sub { - if ( $_ =~ /\.dar/ ) { + if ( $_ =~ /\.dar/ ) + { my $dir = $File::Find::dir; my $backupref; $dir =~ s/$mntbkdir\///; @@ -2320,38 +2328,38 @@ }; # Mounting backup shared folder - unless (-d $mntdir) { - mkdir -p $mntdir; + mkdir -p $mntdir; } my $login = $rec->prop('Login') || 'backup'; my $password = $rec->prop('Password') || 'backup'; - if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) ) - { - esmith::cgi::genResult( - $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err - ); + if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) + { + esmith::cgi::genResult($q, + $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err); return; - } - elsif ( $VFSType ne 'usb' ) {$mounted = 1} + } + elsif ($VFSType ne 'usb') + { + $mounted = 1; + } # Test if backup subdirectory for our server $mntbkdir = $mntdir . "/$id"; unless ( -d $mntbkdir) - { - if ($mounted) { + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } - esmith::cgi::genResult( - $q, $fm->localise('ERR_NO_HOST_DIR'.$id) - ); - return; } + esmith::cgi::genResult($q, $fm->localise('ERR_NO_HOST_DIR'.$id)); + return; + } # Finding existing backups @@ -2361,18 +2369,21 @@ my @blabels; my $backups = 0; - foreach $key (sort keys %backupfiles) { + foreach $key (sort keys %backupfiles) + { my $labkey = $mntbkdir . '/' . $backupfiles{$key}[0] . '/' . $backupfiles{$key}[1]; $blabels{$labkey} = $backupfiles{$key}[1] . ' (' . $backupfiles{$key}[0] . ')'; $backups = push @blabels, $labkey; - } + } - if ($mounted) { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } - if ( $backups == 0 ) { + if ( $backups == 0 ) + { esmith::cgi::genResult( $q, $fm->localise('NO_BACKUPS_TO_RESTORE')); return; @@ -2430,7 +2441,8 @@ my @restorefiles; my $backupsetlist = sub { - if ( $_ =~ /\.dar/ ) { + if ( $_ =~ /\.dar/ ) + { my $backupref = $File::Find::name; $backupref =~ s/\.[0-9]+\.dar//; $_ =~ s/\..*\.dar//; @@ -2464,7 +2476,8 @@ my $backupwkrec = $conf->get('backupwk'); my $login = $backupwkrec->prop('Login'); my $password = $backupwkrec->prop('Password'); - my $id = $backupwkrec->prop('Id') || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; + my $id = $backupwkrec->prop('Id') + || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb'; my $mounted; my $VFSType = $backupwkrec->prop('VFSType') || 'smbfs'; @@ -2472,8 +2485,8 @@ my $smbshare = $backupwkrec->prop('SmbShare'); my $err; - if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) ) - { + if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) + { esmith::cgi::genHeaderNonCacheable( $q, undef, $fm->localise('RESTORE_CANNOT_PROCEED') @@ -2482,33 +2495,38 @@ $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err ); return; - } - elsif ( $VFSType ne 'usb' ) {$mounted = 1} + } + elsif ($VFSType ne 'usb') + { + $mounted = 1; + } # Test if backup subdirectory for our server my $mntbkdir = $mntdir . "/$id"; unless ( -d $mntbkdir) - { - if ($mounted) { + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } esmith::cgi::genResult( $q, $fm->localise('ERR_NO_HOST_DIR'.$id) ); return; - } + } # finding list of available backups find { wanted => \&$backupsetlist, untaint => 1 }, $set ; my $key; - foreach $key (sort keys %backupsetfiles) { + foreach $key (sort keys %backupsetfiles) + { push @restorefiles, $backupsetfiles{$key}; last if ( $backupsetfiles{$key} eq $restoreref ); - } + } # backup is online, restoring now @@ -2622,24 +2640,29 @@ $| = 1; my $file; - foreach $file (@restorefiles) { - if ($file =~ /^(.*)$/) { + foreach $file (@restorefiles) + { + if ($file =~ /^(.*)$/) + { $file = $1; - } - else { - if ($mounted) { + } + else + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } - die('Unsecure data : ' . $file); } - system ("/usr/bin/dar -x $file --verbose --noconf --no-warn=all"); + die('Unsecure data : ' . $file); } + system ("/usr/bin/dar -x $file --verbose --noconf --no-warn=all"); + } - if ($mounted) { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } exit(0); } @@ -2665,7 +2688,8 @@ my $mntbkdir; my $mounted; my $key; - my $id = $rec->prop('Id') || $conf->get('SystemName')->value . '.' . $conf->get('DomainName')->value; + my $id = $rec->prop('Id') || + $conf->get('SystemName')->value . '.' . $conf->get('DomainName')->value; my %blabels = (); my @blabels; my $backups = 0; @@ -2676,7 +2700,8 @@ my $err; my $setbackuplist = sub { - if ( $_ =~ /\.dar/ ) { + if ( $_ =~ /\.dar/ ) + { my $dir = $File::Find::dir; my $backupref; $dir =~ s/$mntbkdir\///; @@ -2692,42 +2717,46 @@ unless (-d $mntdir) { - mkdir -p $mntdir; + mkdir -p $mntdir; } my $login = $rec->prop('Login') || 'backup'; my $password = $rec->prop('Password') || 'backup'; - if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) ) - { + if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) + { esmith::cgi::genResult( $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err ); return; - } - elsif ( $VFSType ne 'usb' ) {$mounted = 1} + } + elsif ($VFSType ne 'usb') + { + $mounted = 1; + } # Test if backup subdirectory for our server $mntbkdir = $mntdir . '/' . $id; unless ( -d $mntbkdir) - { - if ($mounted) { + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } esmith::cgi::genResult( $q, $fm->localise('ERR_NO_HOST_DIR'.$id) ); return; - } + } my $catalog = "$mntbkdir/dar-catalog"; unless ( -e $catalog) - { + { system("/usr/bin/dar_manager -C $catalog") == 0 or die($fm->localise('ERR_DAR_CATALOG'),"\n"); - } + } # find available backups for the server @@ -2740,59 +2769,68 @@ my @setd; my @bkname; open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |"); - while () { + while () + { next unless ($_ =~ /set/); chomp; ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); $i++; - } + } close (DAR_LIST); # delete from catalog old removed backups my $j = $i; - while ($j) { - unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") { + while ($j) + { + unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") + { my $del = $bknum[$j-1]; - if ($del =~ /^(.*)$/) { + if ($del =~ /^(.*)$/) + { $del = $1; - } - system("/usr/bin/dar_manager -B $catalog -D $del 1>&2") == 0 + } + system("/usr/bin/dar_manager -B $catalog -D $del 1>&2") == 0 or die($fm->localise('ERR_DAR_CATALOG'),"\n"); } $j--; - } + } # add to catalog new backups - foreach $key (sort keys %backupfiles) { + foreach $key (sort keys %backupfiles) + { my $exists = 0; my $rf; - foreach $rf (@bkname) { + foreach $rf (@bkname) + { $exists = 1 if ($rf eq $backupfiles{$key}[1]); last if $exists; - } - do { + } + do + { my $add = "$mntbkdir/$backupfiles{$key}[0]/$backupfiles{$key}[1]"; - if ($add =~ /^(.*)$/) { + if ($add =~ /^(.*)$/) + { $add = $1; - } + } system("/usr/bin/dar_manager -B $catalog -A $add") == 0 or die($fm->localise('ERR_DAR_CATALOG'),"\n"); - } unless $exists; - } + } unless $exists; + } # update backups list from current catalog open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |") ; $i = 0; - while () { + while () + { next unless m/set/; chomp; ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); $i++; - } + } close (DAR_LIST); # set drop down list of backups @@ -2800,11 +2838,12 @@ push @blabels, "0"; $blabels{"0"} = $fm->localise('ALL_BACKUPS'); $j = 0; - while ($j < $i) { + while ($j < $i) + { push @blabels, $bknum[$j]; $blabels{$bknum[$j]} = $bkname[$j]; $j++ - } + } print $q->p ($fm->localise('WORKSTN_SEL_REST_DESC') . " $smbhost/$smbshare/$id"); @@ -2857,10 +2896,11 @@ esmith::cgi::genFooter ($q); - if ($mounted) { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } } sub performWorkstnSelRestore @@ -2869,10 +2909,13 @@ my $rgfilter; my $filterexp = $q->param ('filterexp'); - if ($filterexp =~ /^(.*)$/) { + if ($filterexp =~ /^(.*)$/) + { $filterexp = $1; $rgfilter = qr/$filterexp/; - } else { + } + else + { $filterexp = ""; } my $seldatebf; @@ -2889,45 +2932,52 @@ my $mntbkdir; my $mounted; my $key; - my $id = $backupwkrec->prop('Id') || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; + my $id = $backupwkrec->prop('Id') || + $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; my @flabels; my %flabels = (); my $VFSType = $backupwkrec->prop('VFSType') || 'smbfs'; my $err; my $backupkey = $q->param ('backupset'); - if ($backupkey =~ /^(.*)$/) { + if ($backupkey =~ /^(.*)$/) + { $backupkey = $1; - } - else { + } + else + { die('Unsecure data : ' . $backupkey); - } + } # Mounting backup shared folder - if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) ) - { + if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) + { esmith::cgi::genResult( $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err ); return; - } - elsif ( $VFSType ne 'usb' ) {$mounted = 1} + } + elsif ($VFSType ne 'usb') + { + $mounted = 1; + } # Test if backup subdirectory for our server $mntbkdir = $mntdir . "/$id"; - unless ( -d $mntbkdir) - { - if ($mounted) { + unless (-d $mntbkdir) + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } esmith::cgi::genResult( $q, $fm->localise('ERR_NO_HOST_DIR'.$id) ); return; - } + } # Read wanted file list from selected backup @@ -2955,10 +3005,11 @@ system ("/usr/bin/dar_manager -B $mntbkdir/dar-catalog -u $backupkey") == 0 or die ($fm->localise('ERR_EXTRACT')." : ".$!); - if ($mounted) { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } exit(0); } @@ -3024,35 +3075,43 @@ my @restorelist; my $when = $q->param ('seldatebefore'); - if ($when =~ /^(.*)$/) { + if ($when =~ /^(.*)$/) + { $when = $1; - } - else { + } + else + { die('Unsecure data : ' . $when); - } - my $tymd = qr/((19|20)\d\d\/(?=\d\d\/\d\d-))?((0?[1-9]|1[0-2])\/(?=\d\d-))?((31|[123]0|[012]?[1-9])-)?/; - my $thms = qr/([01]?[0-9]|2[0-3]):([0-5][0-9])(:[0-5][0-9])?/; + } + my $tymd = + qr/((19|20)\d\d\/(?=\d\d\/\d\d-))?((0?[1-9]|1[0-2])\/(?=\d\d-))?((31|[123]0|[012]?[1-9])-)?/; + my $thms = + qr/([01]?[0-9]|2[0-3]):([0-5][0-9])(:[0-5][0-9])?/; - unless (($when =~ m/^$tymd$thms$/) || ($when eq "")) { + unless (($when =~ m/^$tymd$thms$/) || ($when eq "")) + { esmith::cgi::genResult( $q, "$when : " . $fm->localise('ERR_INVALID_SELDATE') ); return; - } + } my $f; - foreach $f ($q->param ('restorefiles')) { - if ($f =~ /^(.*)$/) { + foreach $f ($q->param ('restorefiles')) + { + if ($f =~ /^(.*)$/) + { push @restorelist, "\"".$1."\""; - } } + } # mounting backup shared folder my $backupwkrec = $conf->get('backupwk'); my $login = $backupwkrec->prop('Login'); my $password = $backupwkrec->prop('Password'); - my $id = $backupwkrec->prop('Id') || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; + my $id = $backupwkrec->prop('Id') || + $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value; my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb'; my $mounted; my $VFSType = $backupwkrec->prop('VFSType') || 'smbfs'; @@ -3060,29 +3119,33 @@ my $smbshare = $backupwkrec->prop('SmbShare'); my $err; - if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) ) - { + if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType)) + { esmith::cgi::genResult( $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err ); return; - } - elsif ( $VFSType ne 'usb' ) {$mounted = 1} + } + elsif ($VFSType ne 'usb') + { + $mounted = 1; + } # Test if backup subdirectory for our server my $mntbkdir = $mntdir . "/$id"; - unless ( -d $mntbkdir) - { - if ($mounted) { + unless (-d $mntbkdir) + { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } esmith::cgi::genResult( $q, $fm->localise('ERR_NO_HOST_DIR'.$id) ); return; - } + } # backup is online, restoring now @@ -3140,16 +3203,15 @@ $restorerr = system ("/usr/bin/dar_manager -B $mntbkdir/dar-catalog -e '-N -R / -w' -r @restorelist"); } - if ($mounted) { + if ($mounted) + { system("/bin/umount $mntdir") == 0 or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n"); - } + } exit(0); } - return; - } sub performReboot () @@ -3320,21 +3382,27 @@ my ($host,$share,$mountdir,$login,$password,$VFSType) = @_; - if ($VFSType eq 'cifs'){ + if ($VFSType eq 'cifs') + { return ( qx(/bin/mount -t cifs $host:$share $mountdir -o user=$login,pass=$password) ); - } - elsif ($VFSType eq 'smbfs'){ + } + elsif ($VFSType eq 'smbfs') + { return ( qx(/bin/mount -t smbfs //$host/$share $mountdir -o username=$login,password=$password,dmask=777,fmask=777,ip=$host 2>&1) ); - } - elsif ($VFSType eq 'nfs'){ + } + elsif ($VFSType eq 'nfs') + { return ( qx(/bin/mount -t nfs -o nolock $host:/$share $mountdir 2>&1) ); - } - elsif ($VFSType eq 'usb'){ + } + elsif ($VFSType eq 'usb') + { $_[2] = "/" . $share; return - } - else {return ("Error while mounting $host/$share : $VFSType not supported.\n")} - + } + else + { + return ("Error while mounting $host/$share : $VFSType not supported.\n"); + } } __DATA__