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