]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
ebl user can be restricted to a client_group
[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 John Walker.
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 'pool') {
117     $bweb->display_pool();
118
119 } elsif ($action eq 'location_edit') {
120     $bweb->location_edit();
121
122 } elsif ($action eq 'location_save') {
123     $bweb->location_save();
124
125 } elsif ($action eq 'location_add') {
126     $bweb->location_add();
127
128 } elsif ($action eq 'location_del') {
129     $bweb->location_del();
130
131 } elsif ($action eq 'media') {
132     print "<div><table border='0'><tr><td valign='top'>\n";
133     my $fields = $bweb->get_form(qw/db_locations db_pools expired
134                                     qlocations qpools volstatus qre_media
135                                     limit  qmediatypes db_mediatypes/);
136     $bweb->display($fields, "display_form_media.tpl");
137
138     print "</td><td valign='top'>";
139     $bweb->display_media(offset => $arg->{offset},
140                          limit => $arg->{limit});
141     print "</td></tr></table></div>";
142
143 } elsif ($action eq 'allmedia') {
144     $bweb->display_allmedia();
145
146 } elsif ($action eq 'eject') {
147     $bweb->can_do('r_autochanger_mgnt');
148
149     my $arg = $bweb->get_form("ach");
150     my $a = $bweb->ach_get($arg->{ach});
151     
152     if ($a) {
153         $a->status();
154         foreach my $slot (CGI::param('slot')) {
155             print $a->{error} unless $a->send_to_io($slot);
156         }
157
158         foreach my $media (CGI::param('media')) {
159             my $slot = $a->get_media_slot($media);
160             print $a->{error} unless $a->send_to_io($slot);
161         }
162
163         $a->display_content();
164     }
165
166 } elsif ($action eq 'eject_media') {
167     $bweb->eject_media();
168
169 } elsif ($action eq 'clear_io') {
170     $bweb->can_do('r_autochanger_mgnt');
171
172     my $arg = $bweb->get_form('ach');
173
174     my $a = $bweb->ach_get($arg->{ach});
175     if (defined $a) {
176         $a->status();
177         $a->clear_io();
178         $a->display_content();
179     }
180
181 } elsif ($action eq 'ach_edit') {
182     $bweb->ach_edit();
183
184 } elsif ($action eq 'ach_del') {
185     $bweb->ach_del();
186
187 } elsif ($action eq 'ach_view') {
188     $bweb->can_do('r_autochanger_mgnt');
189
190     # TODO : get autochanger name and create it
191     $bweb->connect_db();
192     my $arg = $bweb->get_form('ach');
193
194     my $a = $bweb->ach_get($arg->{ach});
195     if ($a) {
196         $a->status();
197         $a->display_content();
198     }
199
200 } elsif ($action eq 'ach_add') {
201     $bweb->ach_add();
202
203 } elsif ($action eq 'ach_load') {
204     $bweb->can_do('r_autochanger_mgnt');
205
206     my $arg = $bweb->get_form('ach', 'drive', 'slot');
207     
208     my $a = $bweb->ach_get($arg->{ach});
209
210     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
211     {
212         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
213         # TODO : use template here
214         print "<pre>\n";
215         $b->send_cmd("mount slot=$arg->{slot} drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
216         print "</pre>\n";
217     } else {
218         $bweb->error("Can't get drive, slot or ach");
219     }
220     
221 } elsif ($action eq 'ach_unload') {
222     $bweb->can_do('r_autochanger_mgnt');
223
224     my $arg = $bweb->get_form('drive', 'slot', 'ach');
225
226     my $a = $bweb->ach_get($arg->{ach});
227
228     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
229     {
230         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
231         # TODO : use template here
232         print "<pre>\n";
233         $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
234         print "</pre>\n";
235
236     } else {
237         $bweb->error("Can't get drive, slot or ach");
238     }   
239 } elsif ($action eq 'intern_media') {
240     $bweb->help_intern();
241
242 } elsif ($action eq 'compute_intern_media') {
243     $bweb->help_intern_compute();
244
245 } elsif ($action eq 'extern_media') {
246     $bweb->help_extern();
247
248 } elsif ($action eq 'compute_extern_media') {
249     $bweb->help_extern_compute();
250
251 } elsif ($action eq 'extern') {
252     $bweb->can_do('r_media_mgnt');
253     $bweb->can_do('r_autochanger_mgnt');
254
255     print "<div style='float: left;'>";
256     my @achs = $bweb->eject_media();
257     for my $ach (@achs) {
258         CGI::param('ach', $ach);
259         $bweb->update_slots();
260     }
261     print "</div><div style='float: left;margin-left: 20px;'>";
262     $bweb->move_media('no');    # enabled = no
263     print "</div>";
264
265 } elsif ($action eq 'move_email') {
266     $bweb->move_email();
267
268 } elsif ($action eq 'change_location') {
269     $bweb->location_change();
270
271 } elsif ($action eq 'location') {
272     $bweb->location_display();
273
274 } elsif ($action eq 'about') {
275     $bweb->display($bweb, 'about.tpl');
276
277 } elsif ($action eq 'intern') {
278     $bweb->move_media('yes'); # TODO : remove that
279
280 } elsif ($action eq 'move_media') {
281     my $a = $bweb->get_form('enabled');
282     $bweb->move_media($a->{enabled}); 
283
284 } elsif ($action eq 'save_location') {
285     $bweb->save_location();
286
287 } elsif ($action eq 'update_location') {
288     $bweb->update_location();
289
290 } elsif ($action eq 'update_media') {
291     $bweb->update_media();
292
293 } elsif ($action eq 'do_update_media') {
294     $bweb->do_update_media();
295
296 } elsif ($action eq 'update_slots') {
297     $bweb->update_slots();
298
299 } elsif ($action eq 'graph') {
300     $bweb->display_graph();
301
302 } elsif ($action eq 'next_job') {
303     $bweb->director_show_sched();
304
305 } elsif ($action eq 'enable_job') {
306     $bweb->enable_disable_job(1);
307
308 } elsif ($action eq 'disable_job') {
309     $bweb->enable_disable_job(0);
310
311 } elsif ($action eq 'groups') {
312     $bweb->display_groups();
313
314 } elsif ($action eq 'groups_edit') {
315     $bweb->groups_edit();
316
317 } elsif ($action eq 'groups_save') {
318     $bweb->groups_save();
319
320 } elsif ($action eq 'groups_add') {
321     $bweb->groups_add();
322
323 } elsif ($action eq 'groups_del') {
324     $bweb->groups_del();
325
326 } elsif ($action eq 'job') {
327     $bweb->can_do('r_view_job');
328     print "<div><table border='0'><tr><td valign='top'>\n";
329     my $fields = $bweb->get_form(qw/status level filter db_clients
330                                     db_filesets 
331                                     limit age offset qclients qfilesets
332                                     jobtype qpools db_pools
333                                     db_client_groups qclient_groups/); # drop this to hide 
334
335     $bweb->display($fields, "display_form_job.tpl");
336
337     print "</td><td valign='top'>";
338     $bweb->display_job(age => $arg->{age},  # last 7 days
339                        offset => $arg->{offset},
340                        limit => $arg->{limit});
341     print "</td></tr></table></div>";
342 } elsif ($action eq 'job_group') {
343     $bweb->can_do('r_view_job');
344     print "<div><table border='0'><tr><td valign='top'>\n";
345     my $fields = $bweb->get_form(qw/limit level age filter 
346                                     db_client_groups qclient_groups/); # drop this to hide 
347
348     $fields->{hide_status} = 1;
349     $fields->{hide_type} = 1;
350     $fields->{action} = 'job_group';
351
352     $bweb->display($fields, "display_form_job.tpl");
353
354     print "</td><td valign='top'>";
355     $bweb->display_job_group(age => $arg->{age},  # last 7 days
356                              limit => $arg->{limit});
357     print "</td></tr></table></div>";
358 } elsif ($action eq 'client_stats') {
359
360     foreach my $client (CGI::param('client')) {
361         if ($client =~ m/$client_re/) {
362             $bweb->display_client_stats(clientname => $1,
363                                         age => $arg->{age});
364         }
365     }
366
367 } elsif ($action eq 'group_stats') {
368     $bweb->display_group_stats(age => $arg->{age});
369
370 } elsif ($action eq 'running') {
371     $bweb->display_running_jobs(1);
372
373 } elsif ($action eq 'dsp_cur_job') {
374     $bweb->display_running_job();
375
376 } elsif ($action eq 'update_from_pool') {
377     $bweb->can_do('r_media_mgnt');
378     my $elt = $bweb->get_form(qw/media pool/);
379     unless ($elt->{media} || $elt->{pool}) {
380         $bweb->error("Can't get media or pool param");
381     } else {
382         my $b = new Bconsole(pref => $conf) ;
383
384         $bweb->display({
385  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
386  title => "Update pool",
387  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
388         }, "command.tpl");      
389     }
390     
391     $bweb->update_media();
392
393 } elsif ($action eq 'client_status') {
394     $bweb->can_do('r_client_status');
395     my $b;
396     foreach my $client (CGI::param('client')) {
397         if ($client =~ m/$client_re/) {
398             $client = $1;
399             $b = new Bconsole(pref => $conf) 
400                 unless ($b) ;
401
402             $bweb->display({
403                 content => $b->send_cmd("st client=$client"),
404                 title => "Client status",
405                 name => $client,
406             }, "command.tpl");
407             
408         } else {
409             $bweb->error("Can't get client selection");
410         }
411     }
412
413 } elsif ($action eq 'cancel_job') {
414     $bweb->cancel_job();
415
416 } elsif  ($action eq 'media_zoom') {
417     $bweb->display_media_zoom();
418
419 } elsif  ($action eq 'job_zoom') {
420     if ($arg->{jobid}) {
421         $bweb->display_job_zoom($arg->{jobid});
422         $bweb->get_job_log();
423     } 
424 } elsif ($action eq 'job_log') {
425     $bweb->get_job_log();
426
427 } elsif ($action eq 'prune') {
428     $bweb->prune();
429
430 } elsif ($action eq 'purge') {
431     $bweb->purge();
432
433 } elsif ($action eq 'run_job') {
434     $bweb->run_job();
435
436 } elsif ($action eq 'run_job_mod') {
437     $bweb->run_job_mod();
438
439 } elsif ($action eq 'run_job_now') {
440     $bweb->run_job_now();
441
442 } elsif ($action eq 'label_barcodes') {
443     $bweb->label_barcodes();
444
445 } elsif ($action eq 'delete') {
446     $bweb->delete();
447
448 } elsif ($action eq 'fileset_view') {
449     $bweb->fileset_view();
450
451 } else {
452     $bweb->error("Sorry, this action doesn't exist");
453 }
454
455 $bweb->display_end();
456
457 $bweb->dbh_disconnect();
458
459 __END__
460
461 TODO :
462
463  o Affichage des job en cours, termines
464  o Affichage du detail d'un job (status client)
465  o Acces aux log d'une sauvegarde
466  o Cancel d'un job
467  o Lancement d'un job
468
469  o Affichage des medias (pool, cf bacweb)
470  o Affichage de la liste des cartouches
471  o Affichage d'un autochangeur
472  o Mise a jour des slots
473  o Label barcodes
474  o Affichage des medias qui ont besoin d'etre change
475
476  o Affichage des stats sur les dernieres sauvegardes (cf bacula-web)
477  o Affichage des stats sur un type de job
478  o Affichage des infos de query.sql
479
480  - Affichage des du TapeAlert sur le site
481  - Recuperation des erreurs SCSI de /var/log/kern.log
482
483  o update d'un volume
484  o update d'un pool
485
486  o Configuration des autochanger a la main dans un hash dumper