From 178f4beb34a9f00f792fd68fb63b2246323490e4 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sat, 3 Mar 2007 11:14:02 +0000 Subject: [PATCH] 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 --- gui/bweb/INSTALL | 14 +- gui/bweb/MANIFEST | 7 + gui/bweb/Makefile.PL | 26 ++++ gui/bweb/ReleaseNotes | 3 + gui/bweb/html/doc.png | Bin 0 -> 1022 bytes gui/bweb/install_bweb | 126 ++++++++++++++++++ gui/bweb/lang/fr/tpl/display_client_stats.tpl | 4 +- gui/bweb/lang/fr/tpl/move_media.tpl | 4 +- gui/bweb/lang/fr/tpl/stats.tpl | 2 +- gui/bweb/lib/Bconsole.pm | 27 ++-- gui/bweb/lib/Bweb.pm | 8 +- gui/bweb/script/bweb-postgresql.sql | 3 +- gui/bweb/script/update_job_old.sql | 8 ++ 13 files changed, 214 insertions(+), 18 deletions(-) create mode 100644 gui/bweb/MANIFEST create mode 100644 gui/bweb/Makefile.PL create mode 100644 gui/bweb/html/doc.png create mode 100755 gui/bweb/install_bweb create mode 100644 gui/bweb/script/update_job_old.sql 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 0000000000000000000000000000000000000000..520e273324c683847e07c11ba8c9db9c4cce4daa GIT binary patch literal 1022 zcmVz@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZn=;9%B>$fglDBx`O!sZ(68@o@Q@Nqk)hn8ORUbj&iw^ zPtw%EPp($1`^{;<9AYwfEHOk9)roW>+dGNHolma-f*WkC!U!ap8JHQF89?U30V5Ys z6OdvMW&j1-f1r2%0qMU$gZ~5ZzkeVx5SxL4hl`V8!90jIfB=FU%*u!`i;W2_&{*NN zKrsW@5fJd7;rFj!3?MDcYzQp?0R%Vr%$YL`EG#Tw%*es?OzbZ(2te$g zKYucCa&j_gYik384;WO8h@b!nAh^M@va$?9LP8ABo;_pu{P{Bj7Z(@9j~_q4nn8yA z1AF&B!yljlyu7?%{QdiPhR2T|gXKV$v9q(o4F(7xxWRmUd-v_hLo;}N; zuCC6YqM`ye4CZPkCMK|jAPf=%IRGRE4k$)Mcmf0vJTzf~AX~qF{mM{PRmE`O!UYBq z5fKIn2?+)%DJd`pvHAJ=8Gir%4Yu&($Bzs*ZrlL-3}yic00a=61q(lr0!2kdhW7S$ z1_uWRtQi30ZIHnrwV*fw@!!08gQ5l?fLM@S3^H6Vh{jD z8q8HN7lVQV+4Ufog7_dB-C%$Kf*TC-5=i5{d-oWanVG?wuV23orePRl7%ZG&=^8|X zk{(D8G5`o57G#d3q$D`D@c~dIgA882d^w8vg9i^#_y7R}wsrdS>HmR>fn~`*f*1sV z!Sf%a2k83$$N(e;G*b>_CO`nOpj$!=fT;ud4i*H!%7P&?GgBMLd<5bH1Q6U{^uWgl zU}|A$dj9*D(ID{l?OTRz+qPjC3IYHD#6n5k1~pU|$b5$` s2M|DTgF#_LDgYWP1f ${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) ); + -- 2.39.5