From: Eric Bollengier Date: Sat, 3 Mar 2007 11:14:02 +0000 (+0000) Subject: Merge trunk into branch-2.0 gui/bweb X-Git-Tag: Release-2.0.3~10 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=178f4beb34a9f00f792fd68fb63b2246323490e4;p=bacula%2Fbacula Merge trunk into branch-2.0 gui/bweb git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.0@4305 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/gui/bweb/INSTALL b/gui/bweb/INSTALL index 4ef27bc559..e80e9fce43 100644 --- a/gui/bweb/INSTALL +++ b/gui/bweb/INSTALL @@ -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 index 0000000000..8c0eecd02e --- /dev/null +++ b/gui/bweb/MANIFEST @@ -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 index 0000000000..45833d1c1a --- /dev/null +++ b/gui/bweb/Makefile.PL @@ -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 ", + 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", +); diff --git a/gui/bweb/ReleaseNotes b/gui/bweb/ReleaseNotes index c334dfbda5..0c516ea5b3 100644 --- a/gui/bweb/ReleaseNotes +++ b/gui/bweb/ReleaseNotes @@ -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 index 0000000000..520e273324 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 index 0000000000..099312de6c --- /dev/null +++ b/gui/bweb/install_bweb @@ -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 < '/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 ! diff --git a/gui/bweb/lang/fr/tpl/display_client_stats.tpl b/gui/bweb/lang/fr/tpl/display_client_stats.tpl index 2f736d51aa..4cd2c141ef 100644 --- a/gui/bweb/lang/fr/tpl/display_client_stats.tpl +++ b/gui/bweb/lang/fr/tpl/display_client_stats.tpl @@ -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 } ); diff --git a/gui/bweb/lang/fr/tpl/move_media.tpl b/gui/bweb/lang/fr/tpl/move_media.tpl index 4be8a338d4..baca0f4604 100644 --- a/gui/bweb/lang/fr/tpl/move_media.tpl +++ b/gui/bweb/lang/fr/tpl/move_media.tpl @@ -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 } ); diff --git a/gui/bweb/lang/fr/tpl/stats.tpl b/gui/bweb/lang/fr/tpl/stats.tpl index bf4301d709..de1d03624b 100644 --- a/gui/bweb/lang/fr/tpl/stats.tpl +++ b/gui/bweb/lang/fr/tpl/stats.tpl @@ -3,7 +3,7 @@ diff --git a/gui/bweb/lib/Bconsole.pm b/gui/bweb/lib/Bconsole.pm index 9379657ce9..8fbe1de763 100644 --- a/gui/bweb/lib/Bconsole.pm +++ b/gui/bweb/lib/Bconsole.pm @@ -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"); } } diff --git a/gui/bweb/lib/Bweb.pm b/gui/bweb/lib/Bweb.pm index 8676a3f8a5..76388266b0 100644 --- a/gui/bweb/lib/Bweb.pm +++ b/gui/bweb/lib/Bweb.pm @@ -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"); diff --git a/gui/bweb/script/bweb-postgresql.sql b/gui/bweb/script/bweb-postgresql.sql index ab49789243..626333a5fa 100644 --- a/gui/bweb/script/bweb-postgresql.sql +++ b/gui/bweb/script/bweb-postgresql.sql @@ -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 index 0000000000..abd9962665 --- /dev/null +++ b/gui/bweb/script/update_job_old.sql @@ -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) ); +