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