]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
Correct registered trademark notice
[bacula/bacula] / gui / bweb / cgi / bweb.pl
1 #!/usr/bin/perl -w
2 use strict ;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula® - The Network Backup Solution
8
9    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10
11    The main author of Bweb is Eric Bollengier.
12    The main author of Bacula is Kern Sibbald, with contributions from
13    many others, a complete list can be found in the file AUTHORS.
14
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of Kern Sibbald.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
33    Switzerland, email:ftf@fsfeurope.org.
34
35 =head1 VERSION
36
37     $Id$
38
39 =cut
40
41 use Data::Dumper;
42 use Bweb;
43 use CGI;
44
45 my $client_re = qr/^([\w\d\.-]+)$/;
46
47 my $action = CGI::param('action') || 'begin';
48
49 if ($action eq 'restore') {
50     print CGI::header('text/brestore'); # specialy to run brestore.pl
51
52 } else {
53     print CGI::header('text/html');
54 }
55
56 # loading config file
57 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
58 $conf->load();
59
60 my $bweb = new Bweb(info => $conf);
61
62 # just send data with text/brestore content
63 if ($action eq 'restore') {
64     $bweb->restore();
65     exit 0;
66 }
67
68 my $arg = $bweb->get_form('jobid', 'limit', 'offset', 'age');
69
70 $bweb->display_begin();
71
72 # if no configuration, we send edit_conf
73 if ($action ne 'apply_conf' and !$bweb->{info}->{dbi}) {
74     $action = 'edit_conf';
75 }
76
77 if ($action eq 'begin') {               # main display
78     print "<div style='left=0;'><table border='0'><tr><td valign='top' width='100%'>\n";
79     $bweb->display_general(age => $arg->{age});
80     $bweb->display_running_jobs(0);
81     print "</td><td valign='top'>";
82     $bweb->display({}, "stats.tpl");
83     print "</td></tr></table></div>";
84     $bweb->display_job(limit => 10); 
85
86 } elsif ($action eq 'view_conf') {
87     $bweb->can_do('r_configure');
88     $conf->view()
89
90 } elsif ($action eq 'edit_conf') {
91     $bweb->can_do('r_configure');
92     $conf->edit();
93
94 } elsif ($action eq 'apply_conf') {
95     $bweb->can_do('r_configure');
96     $conf->modify();
97
98 } elsif ($action eq 'user_del') {
99     $bweb->users_del();
100
101 } elsif ($action eq 'user_add') {
102     $bweb->users_add();
103
104 } elsif ($action eq 'user_edit') {
105     $bweb->display_user();
106
107 } elsif ($action eq 'user_save') {
108     $bweb->users_add();
109
110 } elsif ($action eq 'users') {
111     $bweb->display_users();
112
113 } elsif ($action eq 'client') { 
114     $bweb->display_clients();
115
116 } elsif ($action eq 'client_edit') {
117     $bweb->client_edit();
118
119 } elsif ($action eq 'client_save') {
120     $bweb->client_save();
121
122 } elsif ($action eq 'pool') {
123     $bweb->display_pool();
124
125 } elsif ($action eq 'location_edit') {
126     $bweb->location_edit();
127
128 } elsif ($action eq 'location_save') {
129     $bweb->location_save();
130
131 } elsif ($action eq 'location_add') {
132     $bweb->location_add();
133
134 } elsif ($action eq 'location_del') {
135     $bweb->location_del();
136
137 } elsif ($action eq 'cmd_storage') {
138     $bweb->cmd_storage();
139
140 } elsif ($action eq 'media') {
141     $bweb->can_do('r_view_media');
142
143     print "<div><table border='0'><tr><td valign='top'>\n";
144     my $fields = $bweb->get_form(qw/db_locations db_pools expired
145                                     qlocations qpools volstatus qre_media
146                                     limit  qmediatypes db_mediatypes/);
147     $bweb->display($fields, "display_form_media.tpl");
148
149     print "</td><td valign='top'>";
150     $bweb->display_media(offset => $arg->{offset},
151                          limit => $arg->{limit});
152     print "</td></tr></table></div>";
153
154 } elsif ($action eq 'allmedia') {
155     $bweb->display_allmedia();
156
157 } elsif ($action eq 'eject') {
158     $bweb->can_do('r_autochanger_mgnt');
159
160     my $arg = $bweb->get_form("ach");
161     my $a = $bweb->ach_get($arg->{ach});
162     
163     if ($a) {
164         $a->status();
165         foreach my $slot (CGI::param('slot')) {
166             print $a->{error} unless $a->send_to_io($slot);
167         }
168
169         foreach my $media (CGI::param('media')) {
170             my $slot = $a->get_media_slot($media);
171             print $a->{error} unless $a->send_to_io($slot);
172         }
173
174         $a->display_content();
175     }
176 } elsif ($action eq 'add_media') {
177     $bweb->add_media();
178
179 } elsif ($action eq 'eject_media') {
180     $bweb->eject_media();
181
182 } elsif ($action eq 'clear_io') {
183     $bweb->can_do('r_autochanger_mgnt');
184
185     my $arg = $bweb->get_form('ach');
186
187     my $a = $bweb->ach_get($arg->{ach});
188     if (defined $a) {
189         $a->status();
190         $a->clear_io();
191         $a->display_content();
192     }
193
194 } elsif ($action eq 'ach_edit') {
195     $bweb->ach_edit();
196
197 } elsif ($action eq 'ach_del') {
198     $bweb->ach_del();
199
200 } elsif ($action eq 'ach_view') {
201     $bweb->can_do('r_autochanger_mgnt');
202
203     # TODO : get autochanger name and create it
204     $bweb->connect_db();
205     my $arg = $bweb->get_form('ach');
206
207     my $a = $bweb->ach_get($arg->{ach});
208     if ($a) {
209         $a->status();
210         $a->display_content();
211     }
212
213 } elsif ($action eq 'ach_add') {
214     $bweb->ach_add();
215
216 } elsif ($action eq 'ach_load') {
217     $bweb->can_do('r_autochanger_mgnt');
218
219     my $arg = $bweb->get_form('ach', 'drive', 'slot');
220     
221     my $a = $bweb->ach_get($arg->{ach});
222
223     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
224     {
225         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
226         # TODO : use template here
227         print "<pre>\n";
228         $b->send_cmd("mount slot=$arg->{slot} drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
229         print "</pre>\n";
230     } else {
231         $bweb->error("Can't get drive, slot or ach");
232     }
233     
234 } elsif ($action eq 'ach_unload') {
235     $bweb->can_do('r_autochanger_mgnt');
236
237     my $arg = $bweb->get_form('drive', 'slot', 'ach');
238
239     my $a = $bweb->ach_get($arg->{ach});
240
241     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
242     {
243         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
244         # TODO : use template here
245         print "<pre>\n";
246         $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
247         print "</pre>\n";
248
249     } else {
250         $bweb->error("Can't get drive, slot or ach");
251     }   
252 } elsif ($action eq 'intern_media') {
253     $bweb->help_intern();
254
255 } elsif ($action eq 'compute_intern_media') {
256     $bweb->help_intern_compute();
257
258 } elsif ($action eq 'extern_media') {
259     $bweb->help_extern();
260
261 } elsif ($action eq 'compute_extern_media') {
262     $bweb->help_extern_compute();
263
264 } elsif ($action eq 'extern') {
265     $bweb->can_do('r_media_mgnt');
266     $bweb->can_do('r_autochanger_mgnt');
267
268     print "<div style='float: left;'>";
269     my @achs = $bweb->eject_media();
270     for my $ach (@achs) {
271         CGI::param('ach', $ach);
272         $bweb->update_slots();
273     }
274     print "</div><div style='float: left;margin-left: 20px;'>";
275     $bweb->move_media('yes');   # pb with enabled = no for restore
276     print "</div>";
277
278 } elsif ($action eq 'move_email') {
279     $bweb->move_email();
280
281 } elsif ($action eq 'change_location') {
282     $bweb->location_change();
283
284 } elsif ($action eq 'location') {
285     $bweb->location_display();
286
287 } elsif ($action eq 'about') {
288     $bweb->display($bweb, 'about.tpl');
289
290 } elsif ($action eq 'intern') {
291     $bweb->move_media('yes'); # TODO : remove that
292
293 } elsif ($action eq 'move_media') {
294     my $a = $bweb->get_form('enabled');
295     $bweb->move_media($a->{enabled}); 
296
297 } elsif ($action eq 'save_location') {
298     $bweb->save_location();
299
300 } elsif ($action eq 'update_location') {
301     $bweb->update_location();
302
303 } elsif ($action eq 'update_media') {
304     $bweb->update_media();
305
306 } elsif ($action eq 'do_update_media') {
307     $bweb->do_update_media();
308
309 } elsif ($action eq 'update_slots') {
310     $bweb->update_slots();
311
312 } elsif ($action eq 'graph') {
313     $bweb->display_graph();
314
315 } elsif ($action eq 'next_job') {
316     $bweb->director_show_sched();
317
318 } elsif ($action eq 'enable_job') {
319     $bweb->enable_disable_job(1);
320
321 } elsif ($action eq 'disable_job') {
322     $bweb->enable_disable_job(0);
323
324 } elsif ($action eq 'groups') {
325     $bweb->display_groups();
326
327 } elsif ($action eq 'groups_edit') {
328     $bweb->groups_edit();
329
330 } elsif ($action eq 'groups_save') {
331     $bweb->groups_save();
332
333 } elsif ($action eq 'groups_del') {
334     $bweb->groups_del();
335
336 } elsif ($action eq 'job') {
337     $bweb->can_do('r_view_job');
338     print "<div><table border='0'><tr><td valign='top'>\n";
339     my $fields = $bweb->get_form(qw/status level filter db_clients
340                                     db_filesets since
341                                     limit age offset qclients qfilesets
342                                     jobtype qpools db_pools
343                                     db_client_groups qclient_groups/); # drop this to hide 
344     if (!CGI::param('since')) {
345         $fields->{hide_since}=1 ;
346         delete $fields->{since};
347     }
348     $bweb->display($fields, "display_form_job.tpl");
349
350     print "</td><td valign='top'>";
351     $bweb->display_job(age => $fields->{age},  # last 7 days
352                        since => $fields->{since},
353                        offset => $fields->{offset},
354                        limit => $fields->{limit});
355     print "</td></tr></table></div>";
356 } elsif ($action eq 'job_group') {
357     $bweb->can_do('r_view_job');
358     print "<div><table border='0'><tr><td valign='top'>\n";
359     my $fields = $bweb->get_form(qw/limit level age filter 
360                                     db_client_groups qclient_groups/); # drop this to hide 
361
362     $fields->{hide_status} = 1;
363     $fields->{hide_type} = 1;
364     $fields->{hide_since}=1;
365     $fields->{action} = 'job_group';
366
367     $bweb->display($fields, "display_form_job.tpl");
368
369     print "</td><td valign='top'>";
370     $bweb->display_job_group(age => $arg->{age},  # last 7 days
371                              limit => $arg->{limit});
372     print "</td></tr></table></div>";
373 } elsif ($action eq 'client_stats') {
374
375     foreach my $client (CGI::param('client')) {
376         if ($client =~ $client_re) {
377             $bweb->display_client_stats(clientname => $1,
378                                         age => $arg->{age});
379         }
380     }
381 } elsif ($action eq 'group_stats') {
382     $bweb->can_do('r_view_stat');
383     print "<div><table border='0'><tr><td valign='top'>\n";
384     my $fields = $bweb->get_form(qw/since age 
385                                     db_client_groups qclient_groups/); 
386     $fields->{action}='group_stats';
387     $fields->{hide_level}=1;
388     $fields->{hide_type}=1;
389     $fields->{hide_status}=1;
390
391     $bweb->display($fields, "display_form_job.tpl");
392
393     print "</td><td valign='top'>";
394     $bweb->display_group_stats();
395
396     print "</td></tr></table></div>"
397
398 } elsif ($action eq 'running') {
399     $bweb->display_running_jobs(1);
400
401 } elsif ($action eq 'dsp_cur_job') {
402     $bweb->display_running_job();
403
404 } elsif ($action eq 'update_from_pool') {
405     $bweb->can_do('r_media_mgnt');
406     my $elt = $bweb->get_form(qw/media pool/);
407     unless ($elt->{media} || $elt->{pool}) {
408         $bweb->error("Can't get media or pool param");
409     } else {
410         my $b = new Bconsole(pref => $conf) ;
411
412         $bweb->display({
413  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
414  title => "Update pool",
415  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
416         }, "command.tpl");      
417     }
418     
419     $bweb->update_media();
420
421 } elsif ($action eq 'client_status') {
422     $bweb->can_do('r_client_status');
423     my $b;
424     foreach my $client (CGI::param('client')) {
425         if ($client =~ $client_re) {
426             $client = $1;
427             $b = new Bconsole(pref => $conf) 
428                 unless ($b) ;
429
430             $bweb->display({
431                 content => $b->send_cmd("st client=$client"),
432                 title => "Client status",
433                 name => $client,
434             }, "command.tpl");
435             
436         } else {
437             $bweb->error("Can't get client selection");
438         }
439     }
440
441 } elsif ($action eq 'cancel_job') {
442     $bweb->cancel_job();
443
444 } elsif ($action eq 'cancel_future_job') {
445     $bweb->cancel_future_job();
446
447 } elsif  ($action eq 'media_zoom') {
448     $bweb->display_media_zoom();
449
450 } elsif  ($action eq 'job_zoom') {
451     if ($arg->{jobid}) {
452         $bweb->display_job_zoom($arg->{jobid});
453         $bweb->get_job_log();
454     } 
455 } elsif ($action eq 'job_log') {
456     $bweb->get_job_log();
457
458 } elsif ($action eq 'prune') {
459     $bweb->prune();
460
461 } elsif ($action eq 'purge') {
462     $bweb->purge();
463
464 } elsif ($action eq 'run_job') {
465     $bweb->run_job();
466
467 } elsif ($action eq 'run_job_mod') {
468     $bweb->run_job_mod();
469
470 } elsif ($action eq 'run_job_now') {
471     $bweb->run_job_now();
472
473 } elsif ($action eq 'label_barcodes') {
474     $bweb->label_barcodes();
475
476 } elsif ($action eq 'delete') {
477     $bweb->delete();
478
479 } elsif ($action eq 'fileset_view') {
480     $bweb->fileset_view();
481
482 } elsif ($action eq 'next_job2') {
483     $bweb->display_next_job();
484
485 } elsif ($action eq 'missing') {
486     $bweb->display_missing_job();
487
488 } elsif ($action eq 'overview') {
489     $bweb->can_do('r_view_job');
490     print "<div><table border='0'><tr><td valign='top'>\n";
491     my $fields = $bweb->get_form(qw/level filter age jobtype since type
492                                     db_client_groups qclient_groups/); # drop this to hide 
493     $fields->{hide_status}=1;
494     $fields->{view_time_slice}=1;
495     $fields->{action}='overview';
496     $bweb->display($fields, "display_form_job.tpl");
497
498     print "</td><td valign='top'>";
499     $bweb->display_overview();
500     print "</td></tr></table></div>";
501
502 } elsif ($action eq 'overview_zoom') {
503     $bweb->can_do('r_view_job');
504     print "<div><table border='0'><tr><td valign='top'>\n";
505     my $fields = $bweb->get_form(qw/level filter age jobtype since type
506                                  db_client_groups qclient_groups/); # drop this to hide 
507     $fields->{hide_status}=1;
508     $fields->{view_time_slice}=1;
509     $fields->{action}='overview_zoom';
510     $bweb->display($fields, "display_form_job.tpl");
511     print "</td><td valign='top'>";
512     $bweb->display_overview_zoom();
513     print "</td></tr></table></div>";
514
515 } else {
516     $bweb->error("Sorry, this action doesn't exist");
517 }
518
519 $bweb->display_end();
520
521 $bweb->dbh_disconnect();
522
523 __END__
524
525 TODO :
526
527  o Affichage des medias qui ont besoin d'etre change
528  o Affichage des infos de query.sql
529
530  - Affichage des du TapeAlert sur le site
531  - Recuperation des erreurs SCSI de /var/log/kern.log