]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
ebl Display configuration when dbi is not found
[bacula/bacula] / gui / bweb / cgi / bweb.pl
1 #!/usr/bin/perl -w
2 use strict ;
3
4 =head1 LICENSE
5
6     Copyright (C) 2006 Eric Bollengier
7         All rights reserved.
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     any later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
23 =head1 VERSION
24
25     $Id$
26
27 =cut
28
29 use Data::Dumper;
30 use Bweb;
31 use CGI;
32
33 my $client_re = qr/^([\w\d\.-]+)$/;
34 my $pool_re   = $client_re; 
35
36 my $action = CGI::param('action') || 'begin';
37
38 if ($action eq 'restore') {
39     print CGI::header('text/brestore'); # specialy to run brestore.pl
40
41 } else {
42     print CGI::header('text/html');
43 }
44
45 # loading config file
46 my $conf = new Bweb::Config(config_file => '/etc/bweb/config');
47 $conf->load();
48
49 my $bweb = new Bweb(info => $conf);
50
51 # just send data with text/brestore content
52 if ($action eq 'restore') {
53     $bweb->restore();
54     exit 0;
55 }
56
57 my $arg = $bweb->get_form('jobid', 'limit', 'offset', 'age');
58
59 $bweb->display_begin();
60
61 # if no configuration, we send edit_conf
62 unless ($bweb->{info}->{dbi}) {
63     $action = 'edit_conf';
64 }
65
66 if ($action eq 'begin') {               # main display
67     print "<table border='0'><td valign='top' width='100%'>\n";
68     $bweb->display_general(age => $arg->{age});
69     $bweb->display_running_jobs(0);
70     print "</td><td valign='top'>";
71     print "
72 <div class='titlediv'>
73   <h1 class='newstitle'> Statistics (last 48 hours)</h1>
74 </div>
75 <div class='bodydiv'>
76 <a href='?action=job;age=172800;jobtype=B'>
77 <img src='bgraph.pl?age=172800;width=450;height=250;graph=job_size;limit=100;action=graph;legend=off' alt='Nothing to display'>
78 </a>
79 </div>";
80     print "</td></table>";
81     $bweb->display_job(limit => 10); 
82
83 } elsif ($action eq 'view_conf') {
84     $conf->view()
85
86 } elsif ($action eq 'edit_conf') {
87     $conf->edit();
88
89 } elsif ($action eq 'apply_conf') {
90     $conf->modify();
91
92 } elsif ($action eq 'client') { 
93     $bweb->display_clients();
94
95 } elsif ($action eq 'pool') {
96     $bweb->display_pool();
97
98 } elsif ($action eq 'location_edit') {
99     $bweb->location_edit();
100
101 } elsif ($action eq 'location_save') {
102     $bweb->location_save();
103
104 } elsif ($action eq 'location_add') {
105     $bweb->location_add();
106
107 #} elsif ($action eq 'del_location') {
108 #    $bweb->del_location();
109 #
110 } elsif ($action eq 'media') {
111     $bweb->display_media();
112
113 } elsif ($action eq 'medias') {
114     $bweb->display_medias();
115
116 } elsif ($action eq 'eject') {
117     my $a = Bweb::Autochanger::get('S1_L80', $bweb);
118
119     $a->status();
120     foreach my $slot (CGI::param('slot')) {
121         print $a->{error} unless $a->send_to_io($slot);
122     }
123
124     foreach my $media (CGI::param('media')) {
125         my $slot = $a->get_media_slot($media);
126         print $a->{error} unless $a->send_to_io($slot);
127     }
128
129     $a->display_content();
130
131 } elsif ($action eq 'eject_media') {
132     $bweb->eject_media();
133
134 } elsif ($action eq 'clear_io') {
135     my $a = Bweb::Autochanger::get('S1_L80', $bweb);
136     $a->status();
137     $a->clear_io();
138     $a->display_content();
139    
140 } elsif ($action eq 'ach_view') {
141     # TODO : get autochanger name and create it
142     $bweb->connect_db();
143     my $a = Bweb::Autochanger::get('S1_L80', $bweb);
144     $a->status();
145     $a->display_content();
146
147 } elsif ($action eq 'ach_load') {
148     my $arg = $bweb->get_form('ach', 'drive', 'slot');
149
150     if (defined $arg->{ach} and defined $arg->{drive} and defined $arg->{slot})
151     {
152         my $b = new Bconsole(pref => $conf, log_stdout => 1) ;
153         # TODO : use template here
154         print "<pre>\n";
155         $b->send_cmd_with_drive("mount slot=$arg->{slot} storage='$arg->{ach}'",
156                                 $arg->{drive});
157         print "</pre>\n";
158     } else {
159         $bweb->error("Can't get drive, slot or ach");
160     }
161     
162 } elsif ($action eq 'ach_unload') {
163     my $arg = $bweb->get_form('drive', 'slot', 'ach');
164     if (defined $arg->{ach} and defined $arg->{drive} and defined $arg->{slot})
165     {
166         my $b = new Bconsole(pref => $conf, log_stdout => 1) ;
167         # TODO : use template here
168         print "<pre>\n";
169         $b->send_cmd_with_drive("umount storage='$arg->{ach}'",
170                                 $arg->{drive});
171         print "</pre>\n";
172
173     } else {
174         $bweb->error("Can't get drive, slot or ach");
175     }   
176 } elsif ($action eq 'intern_media') {
177     $bweb->help_intern();
178
179 } elsif ($action eq 'compute_intern_media') {
180     $bweb->help_intern_compute();
181
182 } elsif ($action eq 'extern_media') {
183     $bweb->help_extern();
184
185 } elsif ($action eq 'compute_extern_media') {
186     $bweb->help_extern_compute();
187
188 } elsif ($action eq 'extern') {
189     print "TODO : Eject ", join(",", CGI::param('media'));
190     $bweb->move_media();
191
192 } elsif ($action eq 'change_location') {
193     $bweb->change_location();
194
195 } elsif ($action eq 'location') {
196     $bweb->display_location();
197
198 } elsif ($action eq 'about') {
199     $bweb->display($bweb, 'about.tpl');
200
201 } elsif ($action eq 'intern') {
202     $bweb->move_media(); # TODO : remove that
203
204 } elsif ($action eq 'move_media') {
205     $bweb->move_media(); 
206
207 } elsif ($action eq 'save_location') {
208     $bweb->save_location();
209
210 } elsif ($action eq 'update_location') {
211     $bweb->update_location();
212
213 } elsif ($action eq 'update_media') {
214     $bweb->update_media();
215
216 } elsif ($action eq 'do_update_media') {
217     $bweb->do_update_media();
218
219 } elsif ($action eq 'update_slots') {
220     $bweb->update_slots();
221
222 } elsif ($action eq 'graph') {
223     $bweb->display_graph();
224
225 } elsif ($action eq 'next_job') {
226     $bweb->director_show_sched();
227
228 } elsif ($action eq 'enable_job') {
229     $bweb->enable_disable_job(1);
230
231 } elsif ($action eq 'disable_job') {
232     $bweb->enable_disable_job(0);
233
234 } elsif ($action eq 'job') {
235
236     print "<table border='0'><td valign='top'>\n";
237     my $fields = $bweb->get_form(qw/status level db_clients db_filesets
238                                     limit age offset qclients qfilesets
239                                     jobtype/);
240     $bweb->display($fields, "display_form_job.tpl");
241
242     print "</td><td valign='top'>";
243     $bweb->display_job(age => $arg->{age},  # last 7 days
244                        offset => $arg->{offset},
245                        limit => $arg->{limit});
246     print "</td></table>";
247 } elsif ($action eq 'client_stats') {
248
249     foreach my $client (CGI::param('client')) {
250         if ($client =~ m/$client_re/) {
251             $bweb->display_client_stats(clientname => $1,
252                                         age => $arg->{age});
253         }
254     }
255
256   
257
258 } elsif ($action eq 'running') {
259     $bweb->display_running_jobs(1);
260
261 } elsif ($action eq 'dsp_cur_job') {
262     $bweb->display_running_job();
263
264 } elsif ($action eq 'update_from_pool') {
265     my $elt = $bweb->get_form(qw/media pool/);
266     unless ($elt->{media} || $elt->{pool}) {
267         $bweb->error("Can't get media or pool param");
268     } else {
269         my $b = new Bconsole(pref => $conf) ;
270
271         $bweb->display({
272  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
273  title => "Update pool",
274  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
275         }, "command.tpl");      
276     }
277     
278     $bweb->update_media();
279
280 } elsif ($action eq 'client_status') {
281     my $b;
282     foreach my $client (CGI::param('client')) {
283         if ($client =~ m/$client_re/) {
284             $client = $1;
285             $b = new Bconsole(pref => $conf) 
286                 unless ($b) ;
287
288             $bweb->display({
289                 content => $b->send_cmd("st client=$client"),
290                 title => "Client status",
291                 name => $client,
292             }, "command.tpl");
293             
294         } else {
295             $bweb->error("Can't get client selection");
296         }
297     }
298
299 } elsif ($action eq 'cancel_job') {
300     $bweb->cancel_job();
301
302 } elsif  ($action eq 'media_zoom') {
303     $bweb->display_media_zoom();
304
305 } elsif  ($action eq 'job_zoom') {
306     if ($arg->{jobid}) {
307         $bweb->display_job_zoom($arg->{jobid});
308         $bweb->get_job_log();
309     } 
310 } elsif ($action eq 'job_log') {
311     $bweb->get_job_log();
312
313 } elsif ($action eq 'prune') {
314     $bweb->prune();
315
316 } elsif ($action eq 'purge') {
317     $bweb->purge();
318
319 } elsif ($action eq 'run_job') {
320     $bweb->run_job();
321
322 } elsif ($action eq 'run_job_mod') {
323     $bweb->run_job_mod();
324
325 } elsif ($action eq 'run_job_now') {
326     $bweb->run_job_now();
327
328 } elsif ($action eq 'label_barcodes') {
329     $bweb->label_barcodes();
330
331 } elsif ($action eq 'delete') {
332     $bweb->delete();
333
334 } else {
335     $bweb->error("Sorry, this action don't exist");
336 }
337
338 $bweb->display_end();
339
340
341 __END__
342
343 TODO :
344
345  o Affichage des job en cours, termines
346  o Affichage du detail d'un job (status client)
347  o Acces aux log d'une sauvegarde
348  o Cancel d'un job
349  o Lancement d'un job
350
351  o Affichage des medias (pool, cf bacweb)
352  o Affichage de la liste des cartouches
353  o Affichage d'un autochangeur
354  o Mise a jour des slots
355  o Label barcodes
356  o Affichage des medias qui ont besoin d'etre change
357
358  o Affichage des stats sur les dernieres sauvegardes (cf bacula-web)
359  o Affichage des stats sur un type de job
360  o Affichage des infos de query.sql
361
362  - Affichage des du TapeAlert sur le site
363  - Recuperation des erreurs SCSI de /var/log/kern.log
364
365  o update d'un volume
366  o update d'un pool
367
368  - Configuration des autochanger a la main dans un hash dumper
369
370  {
371    L10 => {
372      name => 'L10',
373      drive_name => ['SDLT-1', 'STLD-2'],
374      login => 'bacula',
375      host  => 'storehost',
376      device => '/dev/changer',
377    },
378  }