-
-sub floppybox {
- print <<END
-<hr />
-<form method = 'post'>
-<table width='100%'>
-<tr>
- <td>
- <b>$Lang::tr{'backup to floppy'}</b>
- </td>
-</tr>
-<tr>
- <td width='50%'>
- $Lang::tr{'insert floppy'}
- </td>
- <td align='center'>
- <input type='submit' name='ACTION' value='$Lang::tr{'backup to floppy'}' />
- </td>
-</tr>
-</table>
-</form>
-END
-;
- print "<b>$Lang::tr{'alt information'}</b><pre>" .
- `/usr/local/bin/ipfirebackup -savecfg floppy` .
- ' </pre>' if ($settings{'ACTION'} eq $Lang::tr{'backup to floppy'} );
-}
-
-# Return device name of what is mounted under 'backup'
-sub findmounted() {
- my $mounted = `mount|grep ' /home/httpd/html/backup '`;
- if ($mounted) { # extract device name
- $mounted =~ m!^/dev/(.*) on!; # device on mountmoint options
- return $1;
- } else { # it's the normal subdir
- return $Lang::tr{'local hard disk'};
- }
-}
-# read and return a date/time string from a time file
-sub read_timefile() {
- my $fname = shift; # name of file to read from
- my $fname2 = shift; # if first file doesn't exist, get date of this file
-
- my $dt;
- if (defined(open(FH, "<$fname"))) {
- $dt = <FH>;
- chomp $dt;
- close(FH);
- } else {
- $dt = &get_fdate($fname2); # get file date/time
- write_timefile($fname, $dt); # write to expected time file
- }
- return $dt;
-}
-# write a date/time string to a time file
-sub write_timefile() {
- my $fname = shift; # name of file to write to
- my $dt = shift; # date/time string to write
-
- if (open(FH, ">$fname")) {
- print FH "$dt\n";
- close(FH);
- }
-}
-# move a dat file without time stamp to subdir
-sub import_set() {
- my $dt = get_fdate("$setdir/$datafile") . shift;
- &write_timefile("$setdir/$datefile", $dt);
-
- # create set directory
- my $setname = "$setdir/" . get_ddate("$setdir/$datafile");
- mkdir($setname);
-
- # move files to the new set directory
- copy_files($setdir, $setname);
- erase_files ($setdir);
-}
-
-# get date/time string from file
-sub get_fdate() {
- my $fname = shift;
- open(DT, "/bin/date -r $fname|");
- my $dt = <DT>;
- close(DT);
- chomp $dt;
- $dt =~ s/\s+/ /g; # remove duplicate spaces
- return $dt;
-}
-# get date/time string from file for use as directory name
-sub get_ddate() {
- my $fname = shift;
- open(DT, "/bin/date -r $fname +%Y%m%d_%H%M%S|");
- my $dt = <DT>;
- close(DT);
- chomp $dt;
- return $dt;
-}
-# copy archive files from source directory to destination directory
-sub copy_files() {
- my $src_dir = shift;
- my $dest_dir = shift;
- map (copy ("$src_dir/$_", "$dest_dir/$_"), ($datafile, $datefile) );
-}
-# erase set files
-sub erase_files() {
- my $src_dir = shift;
- map (unlink ("$src_dir/$_"), ($datafile, $datefile));
-}
-# get backup error text
-sub get_bk_error() {
- my $exit_code = shift || return '';
- if ($exit_code == 0) {
- return '';
- } elsif ($exit_code == 2) {
- return $Lang::tr{'err bk 2 key'};
- } elsif ($exit_code == 3) {
- return $Lang::tr{'err bk 3 tar'};
- } elsif ($exit_code == 4) {
- return $Lang::tr{'err bk 4 gz'};
- } elsif ($exit_code == 5) {
- return $Lang::tr{'err bk 5 encrypt'};
- } else {
- return $Lang::tr{'err bk 1'};
- }
-}
-# show any restore errors
-sub get_rs_error() {
-
- my $exit_code = shift || return '';
- if ($exit_code == 0) {
- return '';
- } elsif ($exit_code == 6) {
- return $Lang::tr{'err rs 6 decrypt'};
- } elsif ($exit_code == 7) {
- return $Lang::tr{'err rs 7 untartst'};
- } elsif ($exit_code == 8) {
- return $Lang::tr{'err rs 8 untar'};
- } elsif ($exit_code == 9) {
- return $Lang::tr{'missing dat'};
- } else {
- return $Lang::tr{'err rs 1'}."($exit_code)";
- }
-}
-sub kmgt {
- my ($value,$length,$opt_U) = @_;
- if ( $value > 10**( $length + 8 ) or $opt_U eq 'T' ) {
- return sprintf( "%d%s", int( ( $value / 1024**4 ) + .5 ), 'T' );
- } elsif ( $value > 10**( $length + 5 ) or $opt_U eq 'G' ) {
- return sprintf( "%d%s", int( ( $value / 1024**3 ) + .5 ), 'G' );
- } elsif ( $value > 10**( $length + 2 ) or $opt_U eq 'M' ) {
- return sprintf( "%d%s", int( ( $value / 1024**2 ) + .5 ), 'M' );
- } elsif ( $value > 10**($length) or $opt_U eq 'K' ) {
- return sprintf( "%d%s", int( ( $value / 1024 ) + .5 ), 'K' );
- } else {
- return $value;
- }
-}
-
-1;