/[BackupPC]/trunk/lib/BackupPC/SearchLib.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/BackupPC/SearchLib.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 127 by dpavlin, Thu Sep 22 09:27:17 2005 UTC revision 188 by dpavlin, Wed Oct 12 16:49:02 2005 UTC
# Line 8  use DBI; Line 8  use DBI;
8  use DateTime;  use DateTime;
9  use vars qw(%In $MyURL);  use vars qw(%In $MyURL);
10  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
11    use XML::Writer;
12    use IO::File;
13    
14  my $on_page = 100;  my $on_page = 100;
15  my $pager_pages = 10;  my $pager_pages = 10;
# Line 68  sub dates_from_form($) { Line 70  sub dates_from_form($) {
70                  $mm =~ s/\D//g;                  $mm =~ s/\D//g;
71                  $dd =~ s/\D//g;                  $dd =~ s/\D//g;
72    
73                    my $h = my $m = my $s = 0;
74                    if ($suffix eq 'to') {
75                            $h = 23;
76                            $m = 59;
77                            $s = 59;
78                    }
79    
80                  my $dt = new DateTime(                  my $dt = new DateTime(
81                          year => $yyyy,                          year => $yyyy,
82                          month => $mm,                          month => $mm,
83                          day => $dd                          day => $dd,
84                            hour => $h,
85                            minute => $m,
86                            second => $s,
87                  );                  );
88                  print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";                  print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n";
89                  return $dt->epoch || 'NULL';                  return $dt->epoch || 'NULL';
# Line 100  sub getWhere($) { Line 112  sub getWhere($) {
112          push @conditions, qq{ files.date >= $files_from } if ($files_from);          push @conditions, qq{ files.date >= $files_from } if ($files_from);
113          push @conditions, qq{ files.date <= $files_to } if ($files_to);          push @conditions, qq{ files.date <= $files_to } if ($files_to);
114    
115          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" | ",@conditions);          print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:" . join(" and ",@conditions);
116    
117          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});          push( @conditions, ' files.shareid = ' . $param->{'search_share'} ) if ($param->{'search_share'});
118          push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});          push (@conditions, " upper(files.path) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'});
# Line 288  sub getGzipName($$$) Line 300  sub getGzipName($$$)
300          $ret =~ s/\\h/$host/ge;          $ret =~ s/\\h/$host/ge;
301          $ret =~ s/\\s/$share/ge;          $ret =~ s/\\s/$share/ge;
302          $ret =~ s/\\n/$backupnum/ge;          $ret =~ s/\\n/$backupnum/ge;
303            
304            $ret =~ s/__+/_/g;
305    
306          return $ret;          return $ret;
307                    
308  }  }
309    
310    sub getGzipSize($$)
311    {
312            my ($hostID, $backupNum) = @_;
313            my $sql;
314            my $dbh = get_dbh();
315            
316            $sql = q{
317                                    SELECT hosts.name  as host,
318                                               shares.name as share,
319                                               backups.num as backupnum
320                                    FROM hosts, backups, shares
321                                    WHERE shares.id=backups.shareid AND
322                                              hosts.id =backups.hostid AND
323                                              hosts.id=? AND
324                                              backups.num=?
325                            };
326            my $sth = $dbh->prepare($sql);
327            $sth->execute($hostID, $backupNum);
328    
329            my $row = $sth->fetchrow_hashref();
330            
331            my (undef,undef,undef,undef,undef,undef,undef,$ret,undef,undef,undef,undef,undef) =
332                            stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.
333                                    getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));
334            
335            return $ret;    
336    }
337    
338  sub getBackupsNotBurned() {  sub getBackupsNotBurned() {
339    
340          my $dbh = get_dbh();          my $dbh = get_dbh();
# Line 302  sub getBackupsNotBurned() { Line 344  sub getBackupsNotBurned() {
344                          backups.hostID AS hostID,                          backups.hostID AS hostID,
345                          hosts.name AS host,                          hosts.name AS host,
346                          shares.name AS share,                          shares.name AS share,
347                          backups.id AS backupnum,                          backups.num AS backupnum,
348                          backups.type AS type,                          backups.type AS type,
349                          backups.date AS date,                          backups.date AS date,
350                          backups.size AS size                          backups.size AS size,
351                            backups.id AS id,
352                            backups.inc_size AS inc_size
353                  FROM backups                  FROM backups
354                  INNER JOIN shares       ON backups.shareID=shares.ID                  INNER JOIN shares       ON backups.shareID=shares.ID
355                  INNER JOIN hosts        ON backups.hostID = hosts.ID                  INNER JOIN hosts        ON backups.hostID = hosts.ID
356                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id AND archive_backup.backup_id IS NULL                  LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id
357                  WHERE backups.size > 0                  WHERE backups.inc_size > 0 AND backups.inc_deleted is false AND archive_backup.backup_id IS NULL
358                  GROUP BY                  GROUP BY
359                          backups.hostID,                          backups.hostID,
360                          hosts.name,                          hosts.name,
# Line 320  sub getBackupsNotBurned() { Line 364  sub getBackupsNotBurned() {
364                          backups.id,                          backups.id,
365                          backups.type,                          backups.type,
366                          backups.date,                          backups.date,
367                          backups.size                          backups.size,
368                            backups.inc_size
369                  ORDER BY backups.date                  ORDER BY backups.date
370          };          };
371          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
# Line 330  sub getBackupsNotBurned() { Line 375  sub getBackupsNotBurned() {
375          while ( my $row = $sth->fetchrow_hashref() ) {          while ( my $row = $sth->fetchrow_hashref() ) {
376                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );                  $row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) );
377                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);                  $row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024);
378                  my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) =  
379                          stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'.                  # do some cluster calculation (approximate) and convert to kB
380                                  getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'}));                  $row->{'inc_size'} = int(($row->{'inc_size'} + 1023 ) / ( 2 * 1024 ) * 2);
                 $row->{'fs_size'} = $fs_size;  
381                  push @ret, $row;                  push @ret, $row;
382          }          }
383                
# Line 343  sub getBackupsNotBurned() { Line 387  sub getBackupsNotBurned() {
387  sub displayBackupsGrid() {  sub displayBackupsGrid() {
388    
389          my $retHTML .= q{          my $retHTML .= q{
390                  <form id="forma" method="POST" action=};                  <form id="forma" method="POST" action="}.$MyURL.q{?action=burn">
                 $retHTML .= "\"".$MyURL."\"";  
                 $retHTML .= q{?action=burn>  
391          };          };
392    
393          $retHTML .= <<'EOF3';          $retHTML .= <<'EOF3';
394  <style>  <style type="text/css">
395  <!--  <!--
396    DIV#fixedBox {
397            position: absolute;
398            top: 50em;
399            left: -24%;
400            padding: 0.5em;
401            width: 20%;
402            background-color: #E0F0E0;
403            border: 1px solid #00C000;
404    }
405    
406  div#fixedBox  DIV#fixedBox, DIV#fixedBox INPUT, DIV#fixedBox TEXTAREA {
407    {          font-size: 10pt;
408    position: absolute;  }
409    bottom: 1em;  
410    left: 0.5em;  FORM>DIV#fixedBox {
411    padding: 0.5em;          position: fixed !important;
412    width: 10em;          left: 0.5em !important;
413    background: #e0f0e0;          top: auto !important;
414    border: 1px solid #00ff00;          bottom: 1em !important;
415    }          width: 15% !important;
416  @media screen  }
417    {  
418    div#fixedBox  DIV#fixedBox INPUT[type=text], DIV#fixedBox TEXTAREA {
419      {          border: 1px solid #00C000;
420      position: fixed;  }
421      }  
422    /* Don't do this at home */  DIV#fixedBox #note {
423    * html          display: block;
424      {          width: 100%;
425      overflow-y: hidden;  }
426      }  
427    * html body  DIV#fixedBox #submitBurner {
428      {          display: block;
429      overflow-y: auto;          width: 100%;
430      height: 100%;          margin-top: 0.5em;
431      padding: 0 1em 0 12em;          cursor: pointer;
432      font-size: 100%;  }
     }  
   * html div#fixedBox  
     {  
     position: absolute;    
     }  
   /* All done. */  
   }  
433    
434    * HTML {
435            overflow-y: hidden;
436    }
437    
438    * HTML BODY {
439            overflow-y: auto;
440            height: 100%;
441            font-size: 100%;
442    }
443    
444    * HTML DIV#fixedBox {
445            position: absolute;
446    }
447    
448    #mContainer, #gradient, #mask, #progressIndicator {
449            display: block;
450            width: 100%;
451            font-size: 10pt;
452            font-weight: bold;
453            text-align: center;
454            vertical-align: middle;
455            padding: 1px;
456    }
457    
458    #gradient, #mask, #progressIndicator {
459            left: 0;
460            border-width: 1px;
461            border-style: solid;
462            border-color: #000000;
463            color: #404040;
464            margin: 0.4em;
465            position: absolute;
466            margin-left: -1px;
467            margin-top: -1px;
468            margin-bottom: -1px;
469            overflow: hidden;
470    }
471    
472    #mContainer {
473            display: block;
474            position: relative;
475            padding: 0px;
476            margin-top: 0.4em;
477            margin-bottom: 0.5em;
478    }
479    
480    #gradient {
481            z-index: 1;
482            background-color: #FFFF00;
483    }
484    
485    #mask {
486            z-index: 2;
487            background-color: #FFFFFF;
488    }
489    
490    #progressIndicator {
491            z-index: 3;
492            background-color: transparent;
493    }
494  -->  -->
495  </style>  </style>
496  <script language="javascript" type="text/javascript">  <script type="text/javascript">
497  <!--  <!--
498    
499  var debug_div = null;  var debug_div = null;
500    EOF3
501    
502            # take maximum archive size from configuration
503            $retHTML .= 'var media_size = '. $Conf{MaxArchiveSize} .';';
504    
505            $retHTML .= <<'EOF3';
506    
507  function debug(msg) {  function debug(msg) {
508  //      return; // Disable debugging  //      return; // Disable debugging
# Line 422  function element_id(name,element) { Line 532  function element_id(name,element) {
532  }  }
533    
534  function checkAll(location) {  function checkAll(location) {
535          var len = element_id('forma').elements.length;          var f = element_id('forma') || null;
536            if (!f) return false;
537    
538            var len = f.elements.length;
539          var check_all = element_id('allFiles');          var check_all = element_id('allFiles');
540            var suma = check_all.checked ? (parseInt(f.elements['totalsize'].value) || 0) : 0;
541    
542          for (var i = 0; i < len; i++) {          for (var i = 0; i < len; i++) {
543                    var e = f.elements[i];
544                  var e = element_id('forma').elements[i];                  if (e.name != 'all' && e.name.substr(0, 3) == 'fcb') {
                 if ((e.checked || !e.checked) && e.name != 'all') {  
545                          if (check_all.checked) {                          if (check_all.checked) {
546                                  e.checked = true;                                  if (e.checked) continue;
547                                    var el = element_id("fss" + e.name.substr(3));
548                                    var size = parseInt(el.value) || 0;
549                                    debug('suma: '+suma+' size: '+size);
550                                    if ((suma + size) < media_size) {
551                                            suma += size;
552                                            e.checked = true;
553                                    } else {
554                                            break;
555                                    }
556                          } else {                          } else {
557                                  e.checked = false;                                  e.checked = false;
558                          }                          }
559                  }                  }
560          }          }
561            update_sum(suma);
562    }
563    
564          sumiraj();  function update_sum(suma) {
565            element_id('forma').elements['totalsize'].value = suma;
566            pbar_set(suma, media_size);
567            debug('total size: ' + suma);
568  }  }
569        
570  function sumiraj(e) {  function sumiraj(e) {
571          var suma = parseInt(element_id('forma').totalsize.value) || 0;          var suma = parseInt(element_id('forma').elements['totalsize'].value) || 0;
572          var len = element_id('forma').elements.length;          var len = element_id('forma').elements.length;
573          if (e) {          if (e) {
574                  var size = parseInt( element_id("fss" + e.name.substr(3)).value );                  var size = parseInt( element_id("fss" + e.name.substr(3)).value);
575                  if (e.checked) {                  if (e.checked) {
576                          suma += size;                          suma += size;
577                  } else {                  } else {
# Line 460  function sumiraj(e) { Line 587  function sumiraj(e) {
587                          }                          }
588                  }                  }
589          }          }
590          element_id('forma').totalsize.value = suma;          update_sum(suma);
         debug('total size: '+suma);  
591          return suma;          return suma;
592  }  }
593    
594    /* progress bar */
595    
596    var _pbar_width = null;
597    var _pbar_warn = 10;    // change color in last 10%
598    
599    function pbar_reset() {
600            element_id("mask").style.left = "0px";
601            _pbar_width = element_id("mContainer").offsetWidth - 2;
602            element_id("mask").style.width = _pbar_width + "px";
603            element_id("mask").style.display = "block";
604            element_id("progressIndicator").style.zIndex  = 10;
605            element_id("progressIndicator").innerHTML = "0";
606    }
607    
608    function dec2hex(d) {
609            var hch = '0123456789ABCDEF';
610            var a = d % 16;
611            var q = (d - a) / 16;
612            return hch.charAt(q) + hch.charAt(a);
613    }
614    
615    function pbar_set(amount, max) {
616            debug('pbar_set('+amount+', '+max+')');
617    
618            if (_pbar_width == null) {
619                    var _mc = element_id("mContainer");
620                    if (_pbar_width == null) _pbar_width = parseInt(_mc.offsetWidth ? (_mc.offsetWidth - 2) : 0) || null;
621                    if (_pbar_width == null) _pbar_width = parseInt(_mc.clientWidth ? (_mc.clientWidth + 2) : 0) || null;
622                    if (_pbar_width == null) _pbar_width = 0;
623            }
624    
625            var pcnt = Math.floor(amount * 100 / max);
626            var p90 = 100 - _pbar_warn;
627            var pcol = pcnt - p90;
628            if (Math.round(pcnt) <= 100) {
629                    if (pcol < 0) pcol = 0;
630                    var e = element_id("submitBurner");
631                    debug('enable_button');
632                    e.disabled = false;
633                    var a = e.getAttributeNode('disabled') || null;
634                    if (a) e.removeAttributeNode(a);
635            } else {
636                    debug('disable button');
637                    pcol = _pbar_warn;
638                    var e = element_id("submitBurner");
639                    if (!e.disabled) e.disabled = true;
640            }
641            var col_g = Math.floor((_pbar_warn - pcol) * 255 / _pbar_warn);
642            var col = '#FF' + dec2hex(col_g) + '00';
643    
644            //debug('pcol: '+pcol+' g:'+col_g+' _pbar_warn:'+ _pbar_warn + ' color: '+col);
645            element_id("gradient").style.backgroundColor = col;
646    
647            element_id("progressIndicator").innerHTML = pcnt + '%';
648            //element_id("progressIndicator").innerHTML = amount;
649    
650            element_id("mask").style.clip = 'rect(' + Array(
651                    '0px',
652                    element_id("mask").offsetWidth + 'px',
653                    element_id("mask").offsetHeight + 'px',
654                    Math.round(_pbar_width * amount / max) + 'px'
655            ).join(' ') + ')';
656    }
657    
658  if (!self.body) self.body = new Object();  if (!self.body) self.body = new Object();
659  self.onload = self.document.onload = self.body.onload = function() {  self.onload = self.document.onload = self.body.onload = function() {
660            //pbar_reset();
661          sumiraj();          sumiraj();
662  }  };
663    
664  //-->  // -->
665  </script>  </script>
666  <div id="fixedBox">  <div id="fixedBox">
667    
668  Size:  Size: <input type="text" name="totalsize" size="7" readonly="readonly" style="text-align:right;" value="0" /> kB
669  <input type="text" name="totalsize" size="7" readonly>  
670    <div id="mContainer">
671            <div id="gradient">&nbsp;</div>
672            <div id="mask">&nbsp;</div>
673            <div id="progressIndicator">0%</div>
674    </div>
675  <br/>  <br/>
676    
677  Note:  Note:
678  <br/>  <textarea name="note" cols="10" rows="5" id="note"></textarea>
679  <textarea name="note" cols="10" rows="5">  
680  </textarea>  <input type="submit" id="submitBurner" value="Burn selected" name="submitBurner" />
 <br/>  
 <input type="submit" value="Burn selected" name="submitBurner">  
681    
682  </div>  </div>
683    <!--
684  <div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">  <div id="debug" style="float: right; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;">
685  no debug output yet  no debug output yet
686  </div>  </div>
687    -->
688  EOF3  EOF3
689          $retHTML .= q{          $retHTML .= q{
690                          <input type="hidden" value="burn" name="action">                          <input type="hidden" value="burn" name="action">
# Line 503  EOF3 Line 700  EOF3
700                          <td align="center">date</td>                          <td align="center">date</td>
701                          <td align="center">age/days</td>                          <td align="center">age/days</td>
702                          <td align="center">size/MB</td>                          <td align="center">size/MB</td>
703                          <td align="center">gzip size</td>                          <td align="center">gzip size/kB</td>
704                          </tr>                          </tr>
705    
706          };          };
# Line 521  EOF3 Line 718  EOF3
718                  }                  }
719                  my $ftype = "";                  my $ftype = "";
720    
721                    my $checkbox_key = $backup->{'hostid'}. '_' .$backup->{'backupnum'} . '_' . $backup->{'id'};
722    
723                  $retHTML .=                  $retHTML .=
724                          '<tr' . $color[$i %2 ] . '>                          '<tr' . $color[$i %2 ] . '>
725                          <td class="fview">';                          <td class="fview">';
726                  # FIXME  
727                  #$backup->{'fs_size'} = int($backup->{'size'} * 1024);                  if (($backup->{'inc_size'} || 0) > 0) {
                 if (($backup->{'fs_size'} || 0) > 0) {  
728                          $retHTML .= '                          $retHTML .= '
729                          <input type="checkbox" name="fcb' .                          <input type="checkbox" name="fcb' . $checkbox_key . '" value="' . $checkbox_key . '" onClick="sumiraj(this);">';
                         $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                         '" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} .  
                         '" onClick="sumiraj(this);">';  
730                  }                  }
731    
732                  $retHTML .=                  $retHTML .=
733                          '</td>' .                          '</td>' .
734                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .                          '<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' .
# Line 541  EOF3 Line 737  EOF3
737                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .                          '<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' .
738                          '<td align="center">' . $backup->{'age'} . '</td>' .                          '<td align="center">' . $backup->{'age'} . '</td>' .
739                          '<td align="right">' . $backup->{'size'} . '</td>' .                          '<td align="right">' . $backup->{'size'} . '</td>' .
740                          '<td align="right">' . $backup->{'fs_size'} .                          '<td align="right">' . $backup->{'inc_size'} .
741                          '<input type="hidden" iD="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '" value="'. $backup->{'fs_size'} .'"></td>' .                          '<input type="hidden" iD="fss'.$checkbox_key .'" value="'. $backup->{'inc_size'} .'"></td>' .
742    
743                          "</tr>\n";                          "</tr>\n";
744          }          }

Legend:
Removed from v.127  
changed lines
  Added in v.188

  ViewVC Help
Powered by ViewVC 1.1.26