]> git.sur5r.net Git - bacula/bacula/commitdiff
Merge trunk into branch-2.0 gui/bweb
authorEric Bollengier <eric@eb.homelinux.org>
Sat, 3 Mar 2007 11:14:02 +0000 (11:14 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Sat, 3 Mar 2007 11:14:02 +0000 (11:14 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.0@4305 91ce42f0-d328-0410-95d8-f526ca767f89

13 files changed:
gui/bweb/INSTALL
gui/bweb/MANIFEST [new file with mode: 0644]
gui/bweb/Makefile.PL [new file with mode: 0644]
gui/bweb/ReleaseNotes
gui/bweb/html/doc.png [new file with mode: 0644]
gui/bweb/install_bweb [new file with mode: 0755]
gui/bweb/lang/fr/tpl/display_client_stats.tpl
gui/bweb/lang/fr/tpl/move_media.tpl
gui/bweb/lang/fr/tpl/stats.tpl
gui/bweb/lib/Bconsole.pm
gui/bweb/lib/Bweb.pm
gui/bweb/script/bweb-postgresql.sql
gui/bweb/script/update_job_old.sql [new file with mode: 0644]

index 4ef27bc559da3b34f7c0639ffb8e805d33657de6..e80e9fce4314d9782b36e0906493eeb11c8c936a 100644 (file)
@@ -7,7 +7,7 @@ Bweb works well with 1.39 release or later.
 1) install Perl lib
 2) copy your files
 3) initialize your configuration file
-4) do some sql stuff (for postgresql users)
+4) do some sql stuff (for postgresql or mysql 5 users)
 5) use the -n option on bconsole so that it works with Expect
 6) get bacula log more useful
 7) bweb limitation
@@ -180,16 +180,24 @@ If you want to use brestore with bweb, you must associate a mime type
 text/brestore with your brestore.pl, and you must install brestore.
 See gui/brestore/README for instructions on installing brestore.pl.
 
-################ POSTGRESQL NOTES ##############################
+################ POSTGRESQL AND MYSQL5 NOTES ####################
 
 If you want to use PostgreSQL instead of MySQL, you must add
 a function to the PostgreSQL Bacula database to get Bweb to work.
 
 psql -U bacula bacula < script/bweb-postgresql.sql
 
-Tips: PL must be enable in your cluster, you can do this with postgres user
+Tips: PL must be enabled in your cluster, you can do this with postgres user
 postgres:~$ echo 'CREATE PROCEDURAL LANGUAGE plpgsql;' | psql bacula 
 
+
+To get database size with mysql5, edit Bweb.pm and change the DB_SIZE macro
+
+ # with mysql < 5, you have to play with the ugly SHOW command
+ DB_SIZE => " SELECT 0 ",
+ # works only with mysql 5
+ # DB_SIZE => " SELECT sum(DATA_LENGTH) FROM INFORMATION_SCHEMA.TABLES ",
+
 ################ BCONSOLE NOTES ################################
 
 You must use bconsole without conio/readline support. For that, use
diff --git a/gui/bweb/MANIFEST b/gui/bweb/MANIFEST
new file mode 100644 (file)
index 0000000..8c0eecd
--- /dev/null
@@ -0,0 +1,7 @@
+lib/Bweb.pm
+lib/Bconsole.pm
+lib/CCircle.pm
+Makefile.PL
+INSTALL
+COPYING
+MANIFEST
diff --git a/gui/bweb/Makefile.PL b/gui/bweb/Makefile.PL
new file mode 100644 (file)
index 0000000..45833d1
--- /dev/null
@@ -0,0 +1,26 @@
+use Test::More tests => 7;
+
+require_ok('DBI');
+require_ok('GD::Graph');
+require_ok('GD');
+require_ok('HTML::Template');
+require_ok('CGI');
+require_ok('Expect');
+require_ok('Time::ParseDate');
+
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ ABSTRACT => "An other Bacula WEB interface",
+ AUTHOR   => "Eric Bollengier <eric@eb.homelinux.org>",
+ NAME     => 'Bweb',
+ VERSION  => "lib/Bweb.pm",
+
+ #INST_BIN => "cgi",
+ # setup your cgi installation
+ # debian      : /usr/lib/cgi-bin/bweb
+ # redhat/suse : /var/www/cgi-bin/bweb
+ # 
+ #INSTALLSITEBIN => "/usr/lib/cgi-bin/bweb",
+);
index c334dfbda59bdbe37c0a5154d1c5f28ffd74bbed..0c516ea5b343969158cbd444e6ae605c910f120f 100644 (file)
@@ -1,5 +1,8 @@
           Release Notes for bweb 2.0
 
+2007/03/02
+ - Add Postgresql and Mysql5 database size information (See INSTALL for mysql)
+
 2007/03/01
  - Add display_time_log option to get timestamp in display_log
  - Add Warning filter on display_job (see jobstatus=T and joberrors > 0)
diff --git a/gui/bweb/html/doc.png b/gui/bweb/html/doc.png
new file mode 100644 (file)
index 0000000..520e273
Binary files /dev/null and b/gui/bweb/html/doc.png differ
diff --git a/gui/bweb/install_bweb b/gui/bweb/install_bweb
new file mode 100755 (executable)
index 0000000..099312d
--- /dev/null
@@ -0,0 +1,126 @@
+#!/bin/sh
+#
+# Change the following four environment variables to suit your system
+#   Note, the configuration below works on a stock SuSE 10.2 system
+#
+# You can, in general, execute this file multiple times.  However, if
+#   you edit certain of the installed files, your changes might be lost.
+#   This script will not overwrite any installed /etc/bacula/bweb.conf
+#
+# Configuration directory for bweb
+CONF_DIR=/etc/bacula
+#
+# Root directory of web files       
+#
+WEB_DIR=/srv/www/htdocs 
+#
+# share directory for programs
+#
+SHARE_DIR=/usr/share
+#
+# cgi_bin location for web server
+#
+CGI_BIN=/srv/www/cgi-bin
+#
+# Userid the web server is running under
+#
+HTTP_USER=wwwrun
+HTTP_GROUP=www
+
+# Bacula database name and password
+DB=bacula
+DB_PW=""
+EMAIL_ADDR="xxx@localhost"
+MTX="/sbin/mtx"
+
+if [ `whoami` != "root" ] ; then
+  echo "You must be root to run this script."
+  exit 1
+fi
+
+#
+# Normally you should not need to change the following
+#
+# first, copy the bweb perl library into your PERL5 INC path
+sed -i "s!/etc/bacula!${CONF_DIR}!" lib/Bweb.conf
+perl Makefile.PL
+make install
+
+# copy the bweb perl program to your cgi location
+if [ ! -d ${CGI_BIN}/bweb ] ; then
+   mkdir -m 755 ${CGI_BIN}/bweb
+fi
+install -m 755 -o root -g root  cgi/*.pl ${CGI_BIN}/bweb
+
+# get a config file
+if [ ! -d ${CONF_DIR} ] ; then
+   mkdir -m 755 ${CONF_DIR}
+   chown root:bacula ${CONF_DIR}
+fi
+
+# Setup a default ${CONF_DIR}/bweb.conf
+if [ ! -e ${CONF_DIR}/bweb.conf ] ; then
+cat > ${CONF_DIR}/bweb.conf <<END_OF_DATA
+\$VAR1 = bless( {
+  'graph_font' => '/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf',
+  'name' => undef,
+  'config_file' => '${CONF_DIR}/bweb.conf',
+  'bconsole' => '/usr/sbin/bconsole -n -c /etc/bacula/bconsole.conf',
+  'ach_list' => {
+     'S1_L80' => bless( {
+         'info' => {
+                     'drive' => 0,
+                     'io' => 0,
+                     'slot' => 0
+                   },
+         'name' => 'S1_L80',
+         'bweb' => undef,
+         'device' => '/dev/changer',
+         'drive' => [],
+         'debug' => 0,
+         'label' => {},
+         'precmd' => 'sudo',
+         'io' => [],
+         'mtxcmd' => '${MTX}',
+         'drive_name' => [
+                           'S1_L80_SDLT0',
+                           'S1_L80_SDLT1'
+                         ],
+         'slot' => []
+       }, 'Bweb::Autochanger' )
+   },
+  'password' => '${DB_PW}',
+  'template_dir' => '${SHARE_DIR}/bweb/tpl',
+  'dbi' => 'DBI:mysql:database=bacula',
+  'error' => '',
+  'debug' => 0,
+  'user' => '${DB}',
+  'email_media' => '${EMAIL_ADDR}'
+}, 'Bweb::Config' );
+END_OF_DATA
+fi
+
+chown ${HTTP_USER} ${CONF_DIR}/bweb.conf
+
+# copy the bweb template file
+if [ ! -d ${SHARE_DIR}/bweb/tpl ] ; then
+   mkdir -p ${SHARE_DIR}/bweb/tpl
+fi
+install -m 644 -o root -g root  tpl/*.tpl ${SHARE_DIR}/bweb/tpl
+
+# copy the bweb graphics elements (bweb elements must reside in /bweb)
+if [ ! -d ${WEB_DIR} ] ; then
+   mkdir ${WEB_DIR}/bweb
+fi
+install -m 644 -o root -g root  html/*.{js,png,css,gif,ico,html} ${WEB_DIR}/bweb
+
+echo " "
+echo "Please edit /etc/bweb.conf and ensure that all the paths to"
+echo "  the various programs and files such as bconsole, bconsole.conf"
+echo "  are correct, and that the DBI driver is correct (default mysql)"
+echo "  and has the right password for your DB"
+echo " "
+
+
+# done !
index 2f736d51aafa84c5e9619eb25da65a6c0725afa9..4cd2c141ef9f774471306b7d84f72c61fffb1e70 100644 (file)
@@ -52,8 +52,8 @@ nrsTable.setup(
  odd_cell_color: odd_cell_color, 
  header_color: header_color,
  page_nav: true,
- rows_per_page: rows_per_page,
-// disable_sorting: new Array(1)
+// disable_sorting: new Array(1),
+ rows_per_page: rows_per_page
 }
 );
 </script>
index 4be8a338d44bd1b016759993ea589825a96c3dd0..baca0f4604664670cf9219a41549200870183868 100644 (file)
@@ -78,8 +78,8 @@ nrsTable.setup(
  header_color: header_color,
  page_nav: true,
  padding: 3,
- rows_per_page: rows_per_page,
-// disable_sorting: new Array(5,6)
+// disable_sorting: new Array(5,6),
+ rows_per_page: rows_per_page
 }
 );
 </script>
index bf4301d709e18d1945e320aa53a28debae311726..de1d03624b0495422279dab9f972a90a78f3bdd9 100644 (file)
@@ -3,7 +3,7 @@
 </div>
 <div class='bodydiv'>
 <a href='?action=job;age=172800;jobtype=B'>
-<img src='bgraph.pl?age=2678400;width=450;height=200;graph=job_sum_day;limit=500;action=graph;legend=off' alt='Rien a afficher'>
+<img width='450' height='200' src='bgraph.pl?age=2678400;width=450;height=200;graph=job_sum_day;limit=500;action=graph;legend=off' alt='Rien a afficher'>
 </a>
 </div>
 
index 9379657ce9969feced4f940eb6cae6641fe13c39..8fbe1de763948140f33fb7abc89041abe19d594e 100644 (file)
@@ -122,6 +122,16 @@ sub log_stdout
     $self->{log_stdout} = $how;
 }
 
+sub error
+{
+    my ($self, $error) = @_;
+    $self->{error} = $!;
+    if ($self->{debug}) {
+       print "E: bconsole (", $self->{pref}->{bconsole}, ") $!\n";
+    }
+    return 0;
+}
+
 sub connect
 {
     my ($self) = @_;
@@ -133,8 +143,7 @@ sub connect
     unless ($self->{bconsole}) {
        my @cmd = split(/\s+/, $self->{pref}->{bconsole}) ;
        unless (@cmd) {
-           $self->{error} = "bconsole string not found";
-           return 0;
+           return $self->error("bconsole string not found");
        }
        $self->{bconsole} = new Expect;
        $self->{bconsole}->raw_pty(0);
@@ -147,13 +156,16 @@ sub connect
        { 
            my $sav = $SIG{__DIE__};
            $SIG{__DIE__} = sub {  _exit 1 ;};
+            my $old = $ENV{COLUMNS};
+            $ENV{COLUMNS} = 300;
            $ret = $self->{bconsole}->spawn(@cmd) ;
+           delete $ENV{COLUMNS};
+           $ENV{COLUMNS} = $old if ($old) ;
            $SIG{__DIE__} = $sav;
        }
 
        unless ($ret) {
-           $self->{error} = $!;
-           return 0;
+           return $self->error($ret);
        }
        
        # TODO : we must verify that expect return the good value
@@ -228,7 +240,7 @@ sub label_barcodes
     }
 
     $self->send("$cmd\n");
-    $self->expect_it('-re', '[?].+\)\s*:');
+    $self->expect_it('-re', '[?].+\).*:');
     my $res = $self->before();
     $self->send("yes\n");
     $self->expect_it("yes");
@@ -349,7 +361,7 @@ sub _get_volume
            $sel .= " volume=$1";
 
        } else {
-           $self->{error} = "Sorry media is bad";
+           $self->error("Sorry media is bad");
            return '';
        }
     }
@@ -397,8 +409,7 @@ sub purge_job
            $sel .= " jobid=$1";
 
        } else {
-           $self->{error} = "Sorry jobid is bad";
-           return 0;
+           return $self->error("Sorry jobid is bad");
        }
     }
 
index 8676a3f8a542ae39ed999eb2fcf9b7773a236aa8..76388266b08123e5e2e5f3564964210b07ab66d1 100644 (file)
@@ -1049,6 +1049,7 @@ our %sql_func = (
              STARTTIME_PHOUR=> " date_part('hour', Job.StartTime) ",
              STARTTIME_PDAY => " date_part('day', Job.StartTime) ",
              STARTTIME_PMONTH => " date_part('month', Job.StartTime) ",
+             DB_SIZE => " SELECT pg_database_size(current_database()) ",
          },
          mysql => {
              UNIX_TIMESTAMP => 'UNIX_TIMESTAMP',
@@ -1063,6 +1064,10 @@ our %sql_func = (
              STARTTIME_PHOUR=> " DATE_FORMAT(StartTime, '%H') ",
              STARTTIME_PDAY => " DATE_FORMAT(StartTime, '%d') ",
              STARTTIME_PMONTH => " DATE_FORMAT(StartTime, '%m') ",
+             # with mysql < 5, you have to play with the ugly SHOW command
+             DB_SIZE => " SELECT 0 ",
+             # works only with mysql 5
+             # DB_SIZE => " SELECT sum(DATA_LENGTH) FROM INFORMATION_SCHEMA.TABLES ",
          },
         );
 
@@ -1758,6 +1763,7 @@ SELECT
     (SELECT count(Media.MediaId) FROM Media)  AS nb_media,
     (SELECT count(Job.JobId)     FROM Job)    AS nb_job,
     (SELECT sum(VolBytes)        FROM Media)  AS nb_bytes,
+    ($self->{sql}->{DB_SIZE})                 AS db_size,
     (SELECT count(Job.JobId)
       FROM Job
       WHERE Job.JobStatus IN ('E','e','f','A')
@@ -1770,7 +1776,7 @@ SELECT
 
     $row->{nb_bytes} = human_size($row->{nb_bytes});
 
-    $row->{db_size} = '???';
+    $row->{db_size} = human_size($row->{db_size});
     $row->{label} = $label;
 
     $self->display($row, "general.tpl");
index ab49789243f9408d9c9369c068448e8bd6b065ba..626333a5fadbf30aaff51b2daaee4a3f0643afc3 100644 (file)
@@ -1,3 +1,4 @@
+CREATE PROCEDURAL LANGUAGE plpgsql;
 BEGIN;
 
 CREATE FUNCTION SEC_TO_TIME(timestamp with time zone)
@@ -37,4 +38,4 @@ RETURN val;
 END;
 $$ language 'plpgsql';
 
-COMMIT;
\ No newline at end of file
+COMMIT;
diff --git a/gui/bweb/script/update_job_old.sql b/gui/bweb/script/update_job_old.sql
new file mode 100644 (file)
index 0000000..abd9962
--- /dev/null
@@ -0,0 +1,8 @@
+-- First, create job_old table
+-- CREATE TABLE job_old (LIKE Job);
+-- 
+-- then put this on your crontab
+-- */20 * * * * psql -f /opt/bacula/etc/update_job_old.sql > /home/bacula/update_job_old.log
+INSERT INTO job_old
+  (SELECT * FROM Job WHERE JobId NOT IN (SELECT JobId FROM job_old) );
+